Fixed incorect selection of invoices in Customer Payments/Payments To Supplier when...
[fa-stable.git] / sales / includes / db / sales_order_db.inc
index 34da078bed63acc19394682bd50cf50d15747151..c1e7ad52f623440999fe62edf267db364295750e 100644 (file)
@@ -283,22 +283,22 @@ function get_sales_order_header($order_no, $trans_type)
          ."stype.sales_type, "
          ."stype.id AS sales_type_id, "
          ."stype.tax_included, "
-         ."ship.shipper_name, "
+         ."stype.factor, "
+         ."ship.shipper_name, "
          ."tax_group.name AS tax_group_name , "
-         ."tax_group.id AS tax_group_id "
-       ."FROM ".TB_PREF."sales_orders sorder, "
+         ."tax_group.id AS tax_group_id, "
+         ."cust.tax_id "
+       ."FROM ".TB_PREF."sales_orders sorder LEFT JOIN ".TB_PREF."shippers ship ON  ship.shipper_id = sorder.ship_via,"
          .TB_PREF."debtors_master cust,"
          .TB_PREF."sales_types stype, "
          .TB_PREF."tax_groups tax_group, "
          .TB_PREF."cust_branch branch,"
-         .TB_PREF."locations loc, "
-         .TB_PREF."shippers ship
+         .TB_PREF."locations loc
        WHERE sorder.order_type=stype.id
                AND branch.branch_code = sorder.branch_code
                AND branch.tax_group_id = tax_group.id
                AND sorder.debtor_no = cust.debtor_no
                AND loc.loc_code = sorder.from_stk_loc
-               AND ship.shipper_id = sorder.ship_via
                AND sorder.trans_type = " . db_escape($trans_type) ."
                AND sorder.order_no = " . db_escape($order_no );
 
@@ -326,8 +326,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
@@ -355,7 +356,7 @@ function read_sales_order($order_no, &$order, $trans_type)
          $myrow["tax_group_name"], $myrow["contact_phone"]);
 
        $order->set_sales_type($myrow["sales_type_id"], $myrow["sales_type"], 
-           $myrow["tax_included"], 0); // no default price calculations on edit
+           $myrow["tax_included"], $myrow["factor"]); // no default price calculations on edit
 
        $order->set_location($myrow["from_stk_loc"], $myrow["location_name"]);
 
@@ -489,7 +490,7 @@ function get_branch_to_order($customer_id, $branch_id) {
 }
 
 function get_sql_for_sales_orders_view($selected_customer, $trans_type, $trans_no, $filter, 
-       $stock_item=null, $from='', $to='', $ref='', $location='')
+       $stock_item=null, $from='', $to='', $ref='', $location='', $customer_id=ALL_TEXT)
 {
 
        $sql = "SELECT 
@@ -561,6 +562,10 @@ function get_sql_for_sales_orders_view($selected_customer, $trans_type, $trans_n
 
                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,