X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=sales%2Fincludes%2Fdb%2Fsales_order_db.inc;h=386e3b86b2a1213d8d6419ab2ad9998d0efa4056;hb=9a98bb3bc7a94f1a8e47f8dab45a87c8b4212080;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..386e3b86 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 @@ -87,10 +87,17 @@ function add_sales_order(&$order) $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); 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 +126,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 +149,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 +187,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 +250,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) { @@ -280,7 +288,8 @@ function get_sales_order_header($order_no, $trans_type) ."stype.tax_included, " ."ship.shipper_name, " ."tax_group.name AS tax_group_name , " - ."tax_group.id AS tax_group_id " + ."tax_group.id AS tax_group_id, " + ."cust.tax_id " ."FROM ".TB_PREF."sales_orders sorder, " .TB_PREF."debtors_master cust," .TB_PREF."sales_types stype, " @@ -302,14 +311,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)."); } @@ -321,8 +330,9 @@ function get_sales_order_details($order_no, $trans_type) { .TB_PREF."sales_order_details.quantity, discount_percent, qty_sent as qty_done, " - .TB_PREF."stock_master.units, - ".TB_PREF."stock_master.material_cost + " + .TB_PREF."stock_master.units," + .TB_PREF."stock_master.mb_flag," + .TB_PREF."stock_master.material_cost + " .TB_PREF."stock_master.labour_cost + " .TB_PREF."stock_master.overhead_cost AS standard_cost FROM ".TB_PREF."sales_order_details, ".TB_PREF."stock_master @@ -336,6 +346,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 +396,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 +416,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"); } @@ -482,17 +493,17 @@ function get_branch_to_order($customer_id, $branch_id) { return db_query($sql,"Customer Branch Record Retreive"); } -function get_sql_for_sales_orders_view($selected_customer, $trans_type) +function get_sql_for_sales_orders_view($selected_customer, $trans_type, $trans_no, $filter, + $stock_item=null, $from='', $to='', $ref='', $location='', $customer_id=ALL_TEXT) { - global $selected_stock_item; - + $sql = "SELECT sorder.order_no, sorder.reference, debtor.name, branch.br_name," - .($_POST['order_view_mode']=='InvoiceTemplates' - || $_POST['order_view_mode']=='DeliveryTemplates' ? + .($filter=='InvoiceTemplates' + || $filter=='DeliveryTemplates' ? "sorder.comments, " : "sorder.customer_ref, ") ."sorder.ord_date, sorder.delivery_date, @@ -508,58 +519,64 @@ 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"; - if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "") + if (isset($trans_no) && $trans_no != "") { // search orders with number like - $number_like = "%".$_POST['OrderNumber']; - $sql .= " AND sorder.order_no LIKE ".db_escape($number_like) - ." GROUP BY sorder.order_no"; + $number_like = "%".$trans_no; + $sql .= " AND sorder.order_no LIKE ".db_escape($number_like); +// ." GROUP BY sorder.order_no"; } - elseif (isset($_POST['OrderReference']) && $_POST['OrderReference'] != "") + elseif ($ref != "") { // search orders with reference like - $number_like = "%".$_POST['OrderReference']."%"; - $sql .= " AND sorder.reference LIKE ".db_escape($number_like) - ." GROUP BY sorder.order_no"; + $number_like = "%".$ref."%"; + $sql .= " AND sorder.reference LIKE ".db_escape($number_like); +// ." GROUP BY sorder.order_no"; } else // ... or select inquiry constraints { - if ($_POST['order_view_mode']!='DeliveryTemplates' && $_POST['order_view_mode']!='InvoiceTemplates') + if ($filter!='DeliveryTemplates' && $filter!='InvoiceTemplates' && $filter!='OutstandingOnly') { - $date_after = date2sql($_POST['OrdersAfterDate']); - $date_before = date2sql($_POST['OrdersToDate']); + $date_after = date2sql($from); + $date_before = date2sql($to); $sql .= " AND sorder.ord_date >= '$date_after'" ." AND sorder.ord_date <= '$date_before'"; } + } if ($trans_type == ST_SALESQUOTE && !check_value('show_all')) - $sql .= " AND sorder.delivery_date >= '".date2sql(Today())."'"; + $sql .= " AND sorder.delivery_date >= '".date2sql(Today())."' AND line.qty_sent=0"; // show only outstanding, not realized quotes + if ($selected_customer != -1) $sql .= " AND sorder.debtor_no=".db_escape($selected_customer); - if (isset($selected_stock_item)) - $sql .= " AND line.stk_code=".db_escape($selected_stock_item); + if (isset($stock_item)) + $sql .= " AND line.stk_code=".db_escape($stock_item); - if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != ALL_TEXT) - $sql .= " AND sorder.from_stk_loc = ".db_escape($_POST['StockLocation']); + if ($location) + $sql .= " AND sorder.from_stk_loc = ".db_escape($location); - if ($_POST['order_view_mode']=='OutstandingOnly') + if ($filter=='OutstandingOnly') $sql .= " AND line.qty_sent < line.quantity"; - elseif ($_POST['order_view_mode']=='InvoiceTemplates' || $_POST['order_view_mode']=='DeliveryTemplates') + + elseif ($filter=='InvoiceTemplates' || $filter=='DeliveryTemplates') $sql .= " AND sorder.type=1"; + //Chaiatanya : New Filter + if ($customer_id != ALL_TEXT) + $sql .= " AND sorder.debtor_no = ".db_escape($customer_id); + $sql .= " GROUP BY sorder.order_no, sorder.debtor_no, sorder.branch_code, sorder.customer_ref, sorder.ord_date, sorder.deliver_to"; - } return $sql; } ?> \ No newline at end of file