X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=sales%2Fincludes%2Fdb%2Fsales_order_db.inc;h=eb5665ab71c46165a324d3da8c31661bc826855d;hb=0d0fd1bc61f435acf0d4e4bd6eba719e1b10e07b;hp=9a284032d8a680a26b89640ba13cc4bd3c28125c;hpb=2b0e5deaa17eeea0f339844f0c517c2ae9e46c62;p=fa-stable.git diff --git a/sales/includes/db/sales_order_db.inc b/sales/includes/db/sales_order_db.inc index 9a284032..eb5665ab 100644 --- a/sales/includes/db/sales_order_db.inc +++ b/sales/includes/db/sales_order_db.inc @@ -15,7 +15,7 @@ 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 @@ -91,6 +91,8 @@ function add_sales_order(&$order) 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) @@ -119,6 +121,7 @@ function add_sales_order(&$order) function delete_sales_order($order_no, $trans_type) { begin_transaction(); + hook_db_prevoid($trans_type, $order_no); $sql = "DELETE FROM ".TB_PREF."sales_orders WHERE order_no=" . db_escape($order_no) . " AND trans_type=".db_escape($trans_type); @@ -141,7 +144,7 @@ function delete_sales_order($order_no, $trans_type) function update_sales_order_version($order) { foreach ($order as $so_num => $so_ver) { - $sql= 'UPDATE '.TB_PREF.'sales_orders SET version=version+1 WHERE order_no='. $so_num. + $sql= 'UPDATE '.TB_PREF.'sales_orders SET version=version+1 WHERE order_no='. db_escape($so_num). ' AND version='.$so_ver . " AND trans_type=30"; db_query($sql, 'Concurrent editing conflict while sales order update'); } @@ -179,11 +182,11 @@ function update_sales_order($order) version = ".($version+1).", payment_terms = " .db_escape($order->payment). ", total = ". db_escape($total) ." - WHERE order_no=" . $order_no ." + WHERE order_no=" . db_escape($order_no) ." AND trans_type=".$order->trans_type." AND version=".$version; db_query($sql, "order Cannot be Updated, this can be concurrent edition conflict"); - $sql = "DELETE FROM ".TB_PREF."sales_order_details WHERE order_no =" . $order_no . " AND trans_type=".$order->trans_type; + $sql = "DELETE FROM ".TB_PREF."sales_order_details WHERE order_no =" . db_escape($order_no) . " AND trans_type=".$order->trans_type; db_query($sql, "Old order Cannot be Deleted"); @@ -242,7 +245,7 @@ function update_sales_order($order) } /* inserted line items into sales order details */ add_audit_trail($order->trans_type, $order_no, $order->document_date, _("Updated.")); - $Refs->update($order->trans_type, $order_no, $order->reference); + $Refs->save($order->trans_type, $order_no, $order->reference); commit_transaction(); if ($loc_notification == 1 && count($st_ids) > 0) { @@ -302,14 +305,14 @@ function get_sales_order_header($order_no, $trans_type) $num = db_num_rows($result); if ($num > 1) { - display_db_error("FATAL : sales order query returned a duplicate - " . db_num_rows($result), $sql, true); + display_warning("You have duplicate document in database: (type:$trans_type, number:$order_no)."); } else if ($num == 1) { return db_fetch($result); } else - display_db_error("FATAL : sales order return nothing - " . db_num_rows($result), $sql, true); + display_warning("You have missing or invalid sales document in database (type:$trans_type, number:$order_no)."); } @@ -336,6 +339,7 @@ function get_sales_order_details($order_no, $trans_type) { function read_sales_order($order_no, &$order, $trans_type) { + $myrow = get_sales_order_header($order_no, $trans_type); $order->trans_type = $myrow['trans_type']; @@ -385,7 +389,7 @@ function sales_order_has_deliveries($order_no) { $sql = "SELECT SUM(qty_sent) FROM ".TB_PREF. "sales_order_details WHERE order_no=".db_escape($order_no) - ." AND trans_type=".ST_SALESORDER.""; + ." AND trans_type=".ST_SALESORDER; $result = db_query($sql, "could not query for sales order usage"); @@ -405,7 +409,7 @@ function close_sales_order($order_no) // set the quantity of each item to the already sent quantity. this will mark item as closed. $sql = "UPDATE ".TB_PREF."sales_order_details SET quantity = qty_sent WHERE order_no = ".db_escape($order_no) - ." AND trans_type=".ST_SALESORDER.""; + ." AND trans_type=".ST_SALESORDER; db_query($sql, "The sales order detail record could not be updated"); } @@ -508,7 +512,7 @@ function get_sql_for_sales_orders_view($selected_customer, $trans_type) .TB_PREF."cust_branch as branch WHERE sorder.order_no = line.order_no AND sorder.trans_type = line.trans_type - AND sorder.trans_type = $trans_type + AND sorder.trans_type = ".db_escape($trans_type)." AND sorder.debtor_no = debtor.debtor_no AND sorder.branch_code = branch.branch_code AND debtor.debtor_no = branch.debtor_no";