From: Maxime Bourget Date: Sun, 23 Jun 2013 20:14:36 +0000 (+0100) Subject: Updating sales order use UPDATE instead of DELETE/INSERT to preserve extra data added... X-Git-Tag: 2.3-final~222 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=35b38e2decfb25fff94d9fcae48945a1f698f5d2;p=fa-stable.git Updating sales order use UPDATE instead of DELETE/INSERT to preserve extra data added by extensions (if any) --- diff --git a/sales/includes/db/sales_order_db.inc b/sales/includes/db/sales_order_db.inc index d72f10c8..a0cf3880 100644 --- a/sales/includes/db/sales_order_db.inc +++ b/sales/includes/db/sales_order_db.inc @@ -189,7 +189,14 @@ function update_sales_order($order) AND trans_type=".$order->trans_type." AND version=".$version; db_query($sql, "order Cannot be Updated, this can be concurrent edition conflict"); + $id_tokeep = array(); + foreach ($order->line_items as $line) { + array_push($id_tokeep , $line->id); + } + $id_list = implode(', ', $id_tokeep); + $sql = "DELETE FROM ".TB_PREF."sales_order_details WHERE order_no =" . db_escape($order_no) . " AND trans_type=".$order->trans_type; + $sql .= " AND id NOT IN ($id_list)"; db_query($sql, "Old order Cannot be Deleted"); @@ -230,6 +237,15 @@ function update_sales_order($order) } } } + if($line->id) { + $sql = "UPDATE ".TB_PREF."sales_order_details + SET description = ".db_escape($line->item_description) . ", + unit_price = ".db_escape($line->price) . ", + quantity = ".db_escape($line->quantity) . ", + discount_percent = ".db_escape($line->discount_percent) . " + WHERE id = {$line->id}"; + } + else { $sql = "INSERT INTO ".TB_PREF."sales_order_details (id, order_no, trans_type, stk_code, description, unit_price, quantity, discount_percent, qty_sent) @@ -242,6 +258,7 @@ function update_sales_order($order) .db_escape($line->quantity) . ", " .db_escape($line->discount_percent) . ", " .db_escape($line->qty_done) ." )"; + } db_query($sql, "Old order Cannot be Inserted"); @@ -579,4 +596,4 @@ function get_sql_for_sales_orders_view($selected_customer, $trans_type, $trans_n sorder.deliver_to"; return $sql; } -?> \ No newline at end of file +?>