function add_sales_order(&$order)
{
global $loc_notification, $path_to_root, $Refs;
begin_transaction();
hook_db_prewrite($order, $order->trans_type);
$order_no = get_next_trans_no($order->trans_type);
$del_date = date2sql($order->due_date);
$order_type = 0; // this is default on new order
$total = $order->get_trans_total();
$sql = "INSERT INTO ".TB_PREF."sales_orders (order_no, type, debtor_no, trans_type, branch_code, customer_ref, reference, comments, ord_date,
order_type, ship_via, deliver_to, delivery_address, contact_phone, shipper_address, ship_from,
freight_cost, from_stk_loc, delivery_date, payment_terms, total)
VALUES (" .db_escape($order_no) . "," .db_escape($order_type) . "," . db_escape($order->customer_id) .
", " .db_escape($order->trans_type) . "," .db_escape($order->Branch) . ", ".
db_escape($order->cust_ref) .",".
db_escape($order->reference) .",".
db_escape($order->Comments) .",'" .
date2sql($order->document_date) . "', " .
db_escape($order->sales_type) . ", " .
db_escape($order->ship_via)."," .
db_escape($order->deliver_to) . "," .
db_escape($order->delivery_address) . ", " .
db_escape($order->shipper_address) . ", ".
db_escape($order->ship_from) . ", ".
db_escape($order->phone) . ", " .
db_escape($order->freight_cost) .", " .
db_escape($order->Location) .", " .
db_escape($del_date) . "," .
db_escape($order->payment) . "," .
db_escape($total). ")";
db_query($sql, "order Cannot be Added");
$order->trans_no = array($order_no=>0);
if ($loc_notification == 1)
{
include_once($path_to_root . "/inventory/includes/inventory_db.inc");
$st_ids = array();
$st_names = array();
$st_num = array();
$st_reorder = array();
}
foreach ($order->line_items as $line)
{
if ($loc_notification == 1 && is_inventory_item($line->stock_id))
$loc = calculate_reorder_level($order->Location, $line, $st_ids, $st_names, $st_num, $st_reorder);
$sql = "INSERT INTO ".TB_PREF."sales_order_details (order_no, trans_type, stk_code, description, unit_price, quantity, discount_percent) VALUES (";
$sql .= $order_no . ",".$order->trans_type .
",".db_escape($line->stock_id).", "
.db_escape($line->item_description).", $line->price,
$line->quantity,
$line->discount_percent)";
db_query($sql, "order Details Cannot be Added");
// Now mark quotation line as processed
if ($order->trans_type == ST_SALESORDER && $line->src_id)
update_parent_line(ST_SALESORDER, $line->src_id, $line->qty_dispatched); // clear all the quote despite all or the part was ordered
} /* inserted line items into sales order details */
add_audit_trail($order->trans_type, $order_no, $order->document_date);
$Refs->save($order->trans_type, $order_no, $order->reference);
hook_db_postwrite($order, $order->trans_type);
commit_transaction();
if ($loc_notification == 1 && count($st_ids) > 0)
send_reorder_email($loc, $st_ids, $st_names, $st_num, $st_reorder);
return $order_no;
}