- if ($line->Deleted == false)
- {
- if ($loc_notification == 1 && is_inventory_item($line->stock_id))
- {
- $sql = "SELECT ".TB_PREF."loc_stock.*, ".TB_PREF."locations.location_name, ".TB_PREF."locations.email
- FROM ".TB_PREF."loc_stock, ".TB_PREF."locations
- WHERE ".TB_PREF."loc_stock.loc_code=".TB_PREF."locations.loc_code
- AND ".TB_PREF."loc_stock.stock_id = '" . $line->stock_id . "'
- AND ".TB_PREF."loc_stock.loc_code = '" . $order->Location . "'";
- $res = db_query($sql,"a location could not be retreived");
- $loc = db_fetch($res);
- if ($loc['email'] != "")
- {
- $qoh = get_qoh_on_date($line->stock_id, $order->Location);
- $qoh -= get_demand_qty($line->stock_id, $order->Location);
- $qoh -= get_demand_asm_qty($line->stock_id, $order->Location);
- $qoh -= $line->quantity;
- if ($qoh < $loc['reorder_level'])
- {
- $st_ids[] = $line->stock_id;
- $st_names[] = $line->item_description;
- $st_num[] = $qoh - $loc['reorder_level'];
- $st_reorder[] = $loc['reorder_level'];
- }
- }
- }
-
- $sql = "INSERT INTO ".TB_PREF."sales_order_details (order_no, stk_code, description, unit_price, quantity, discount_percent, qty_invoiced) VALUES (";
-
- $sql .= $order_no . ",'" . $line->stock_id . "','" . $line->item_description . "', " . $line->price . ", " . $line->quantity . ", " . $line->discount_percent . ", " . $line->qty_inv . " )";
-
- db_query($sql, "Old order Cannot be Inserted");
-
- } /* inserted line items into sales order details */
- }
+ if ($SysPrefs->loc_notification() == 1 && is_inventory_item($line->stock_id))
+ $loc = calculate_reorder_level($order->Location, $line, $st_ids, $st_names, $st_num, $st_reorder);
+
+ if (!$line->id) //new line
+ $sql = "INSERT INTO ".TB_PREF."sales_order_details
+ (order_no, trans_type, stk_code, description, unit_price, quantity,
+ discount_percent, qty_sent)
+ VALUES (".$order_no . ",".$order->trans_type.","
+ .db_escape($line->stock_id) . ","
+ .db_escape($line->item_description) . ", "
+ .db_escape($line->price) . ", "
+ .db_escape($line->quantity) . ", "
+ .db_escape($line->discount_percent) . ", "
+ .db_escape($line->qty_done) ." )";
+ else
+ $sql = "UPDATE ".TB_PREF."sales_order_details
+ SET id=".db_escape($line->id).",
+ order_no=$order_no,
+ trans_type=".$order->trans_type.",
+ stk_code=".db_escape($line->stock_id).",
+ description=".db_escape($line->item_description).",
+ unit_price=".db_escape($line->price).",
+ quantity=".db_escape($line->quantity).",
+ discount_percent=".db_escape($line->discount_percent).",
+ qty_sent=".db_escape($line->qty_done)."
+ WHERE id = ".db_escape($line->id);
+
+ db_query($sql, "Old order Cannot be updated");
+ } /* inserted line items into sales order details */
+
+ if ($order->trans_type == ST_SALESORDER)
+ reallocate_payments($order_no, ST_SALESORDER, $ord_date, $total, $allocs, $order->customer_id);
+ add_audit_trail($order->trans_type, $order_no, $order->document_date, _("Updated."));
+ $Refs->save($order->trans_type, $order_no, $order->reference, null, $order->fixed_asset);
+
+ hook_db_postwrite($order, $order->trans_type);