Updating sales order use UPDATE instead of DELETE/INSERT to preserve extra data added...
authorMaxime Bourget <bmx007@gmail.com>
Sun, 23 Jun 2013 20:14:36 +0000 (21:14 +0100)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 16 Jul 2013 12:15:27 +0000 (14:15 +0200)
sales/includes/db/sales_order_db.inc

index d72f10c82135cf39816844d36fe9392817acfdf1..a0cf388046b4ca2e0f58bc11e1fe9d31e3b052b7 100644 (file)
@@ -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
+?>