conn,$cfg_theme,$cfg_currency_symbol,$lang); if(!$sec->isLoggedIn()) { header ("location: ../login.php"); exit(); } $table_bg=$display->sale_bg; $num_items=count($_SESSION['items_in_sale']); if($num_items==0) { echo "$lang->youMustSelectAtLeastOneItem
"; echo "$lang->refreshAndTryAgain"; exit(); } $customers_table=$cfg_tableprefix.'customers'; $items_table=$cfg_tableprefix.'items'; $sales_items_table=$cfg_tableprefix.'sales_items'; $sales_table=$cfg_tableprefix.'sales'; //general sale info $paid_with=isset($_POST['paid_with'])?$_POST['paid_with']:''; $comment=isset($_POST['comment'])?$_POST['comment']:''; $customer_name=$dbf->idToField($customers_table,'first_name',$_SESSION['current_sale_customer_id']).' '.$dbf->idToField($customers_table,'last_name',$_SESSION['current_sale_customer_id']); $customer_email=$dbf->idToField($customers_table,'email',$_SESSION['current_sale_customer_id']); //totals $finalTax=$_POST['totalTax']; $sale_total_cost=$_POST['finalTotal']; $temp_total_items_purchased=$_POST['totalItemsPurchased']; $amt_tendered=$_POST['amt_tendered']; $amt_change=$amt_tendered-$sale_total_cost; $amt_tendered=number_format($amt_tendered, 2,'.',''); $amt_change=number_format($amt_change, 2,'.',''); $now=date("F j, Y, g:i a"); $body.="
$now

Order For: $customer_name [$lang->paidWith $paid_with]

"; $todaysDate=date("Y-m-d"); $subtotal=number_format($sale_total_cost-$finalTax,2,'.', ''); $final_tax=number_format($finalTax,2,'.', ''); $field_names=array('date','customer_id','sale_sub_total','sale_total_cost','paid_with','items_purchased','sold_by','comment'); $field_data=array($todaysDate,$_SESSION['current_sale_customer_id'],$subtotal,$sale_total_cost,$paid_with,$temp_total_items_purchased,$_SESSION['session_user_id'],$comment); $dbf->insert($field_names,$field_data,$sales_table,false); $saleID=mysql_insert_id(); $field_names=array('sale_id','item_id','quantity_purchased','item_unit_price','item_buy_price','item_tax_percent','item_total_tax','item_total_cost'); $temp_item_id=''; $temp_item_name=''; $temp_quantity_purchased=0; $temp_item_unit_price=0; $temp_item_buy_price=0; $temp_item_tax_percent=0; $temp_item_tax=0; $temp_item_cost=0; $item_info=array(); //Add to sales_items table for($k=0;$k<$num_items;$k++) { $item_info=explode(' ',$_SESSION['items_in_sale'][$k]); $temp_item_id=$item_info[0]; $temp_item_name=$dbf->idToField($items_table,'item_name',$temp_item_id); $temp_quantity_purchased=$item_info[3]; $temp_item_unit_price=number_format($item_info[1],2,'.', ''); $temp_item_buy_price=number_format($dbf->idToField($items_table,'buy_price',$temp_item_id),2,'.', ''); $temp_item_tax_percent=$item_info[2]; $temp_item_tax=number_format($temp_item_tax_percent/100*$temp_item_unit_price*$temp_quantity_purchased,2,'.', ''); $temp_item_cost=number_format(($temp_item_unit_price*$temp_quantity_purchased)+$temp_item_tax,2,'.', ''); $field_data=array("$saleID","$temp_item_id","$temp_quantity_purchased","$temp_item_unit_price","$temp_item_buy_price","$temp_item_tax_percent","$temp_item_tax","$temp_item_cost"); $new_quantity=$dbf->idToField($items_table,'quantity',$temp_item_id)-$temp_quantity_purchased; $query="UPDATE $items_table SET quantity=\"$new_quantity\" WHERE $temp_item_id=id"; mysql_query($query,$dbf->conn); $dbf->insert($field_names,$field_data,$sales_items_table,false); $body .= ""; } $body .= "
$lang->itemOrdered || $lang->unitPrice || $lang->quantity || $lang->extendedPrice
$temp_item_name $cfg_currency_symbol$temp_item_unit_price $temp_quantity_purchased $cfg_currency_symbol$temp_item_cost

"; $body .= ""; $body .= ""; if($amt_tendered!=0) { $body .= ""; $body .= ""; } $body .= "
$lang->saleSubTotal: $cfg_currency_symbol$subtotal
$lang->tax: $cfg_currency_symbol$final_tax
$lang->saleTotalCost: $cfg_currency_symbol$sale_total_cost
$lang->amtTendered: $cfg_currency_symbol$amt_tendered

$lang->amtChange: $cfg_currency_symbol$amt_change
$lang->saleID: $saleID
"; $sec->closeSale(); $dbf->closeDBlink(); $body .= "

$lang->contact $cfg_company:

"; if($cfg_address!='') { $temp_address=nl2br($cfg_address); $body .= "$lang->address: $temp_address
"; } if($cfg_phone!='') { $body .= "$lang->phoneNumber: $cfg_phone
"; } if($cfg_email!='') { $body .= "$lang->email: $cfg_email
"; } if($cfg_fax!='') { $body .= "$lang->fax: $cfg_fax
"; } if($cfg_website!='') { $body .= "$lang->website $cfg_website
"; } if($cfg_other!='') { $body .= "$lang->other: $cfg_other
"; } echo "$body"; //EMAIL RECIEPT TO MEMBER! $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From: $cfg_emailFromAddress" . "\r\n"; $message = "

Please retain or print this receipt for your records
$body "; // In case any of our lines are larger than 70 characters, we should use wordwrap() $message = wordwrap($message, 70); // Send mail($customer_email, "Your E-receipt from $cfg_company", $message, $headers); echo "

E-Reciept has been sent to <$customer_email>

"; ?>