Fixed get_sales_order_header and get_debtor_trans queries to avoid errors on empty...
authorJanusz Dobrowolski <janusz@frontaccouting.eu>
Thu, 6 Sep 2012 17:43:33 +0000 (19:43 +0200)
committerJanusz Dobrowolski <janusz@frontaccouting.eu>
Thu, 6 Sep 2012 17:43:33 +0000 (19:43 +0200)
sales/includes/db/cust_trans_db.inc
sales/includes/db/sales_order_db.inc
sales/sales_order_entry.php

index bf28fe604863b255ec56bd2ab67e3237bc4e1f90..c68d378a01b757c36a2f69c738e19a83e341718d 100644 (file)
@@ -140,7 +140,9 @@ function get_customer_trans($trans_id, $trans_type)
                .TB_PREF."tax_groups.id AS tax_group_id ";
        }
 
-       $sql .= " FROM ".TB_PREF."debtor_trans trans, ".TB_PREF."debtors_master cust";
+       $sql .= " FROM ".TB_PREF."debtor_trans trans LEFT JOIN ".TB_PREF."comments com ON trans.type=com.type AND trans.trans_no=com.id
+                                       LEFT JOIN ".TB_PREF."shippers ON ".TB_PREF."shippers.shipper_id=trans.ship_via, 
+                                       ".TB_PREF."debtors_master cust";
 
        if ($trans_type == ST_CUSTPAYMENT) {
                // it's a payment so also get the bank account
@@ -149,8 +151,7 @@ function get_customer_trans($trans_id, $trans_type)
 
        if ($trans_type == ST_SALESINVOICE || $trans_type == ST_CUSTCREDIT || $trans_type == ST_CUSTDELIVERY) {
                // it's an invoice so also get the shipper, salestypes
-               $sql .= ", ".TB_PREF."shippers, "
-               .TB_PREF."sales_types, "
+               $sql .= ", ".TB_PREF."sales_types, "
                .TB_PREF."cust_branch branch, "
                .TB_PREF."tax_groups ";
        }
@@ -168,8 +169,7 @@ function get_customer_trans($trans_id, $trans_type)
        }
        if ($trans_type == ST_SALESINVOICE || $trans_type == ST_CUSTCREDIT || $trans_type == ST_CUSTDELIVERY) {
                // it's an invoice so also get the shipper
-               $sql .= " AND ".TB_PREF."shippers.shipper_id=trans.ship_via
-                       AND ".TB_PREF."sales_types.id = trans.tpe
+               $sql .= " AND ".TB_PREF."sales_types.id = trans.tpe
                        AND branch.branch_code = trans.branch_code
                        AND branch.tax_group_id = ".TB_PREF."tax_groups.id ";
        }
index ab7f560035275b0317f6d2762647895102500f77..c1e7ad52f623440999fe62edf267db364295750e 100644 (file)
@@ -288,19 +288,17 @@ function get_sales_order_header($order_no, $trans_type)
          ."tax_group.name AS tax_group_name , "
          ."tax_group.id AS tax_group_id, "
          ."cust.tax_id "
-       ."FROM ".TB_PREF."sales_orders sorder"
+       ."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 );
 
index 309f60277ddd08b2b9590689e641e836f38fd941..23410132e3290a820e37c2f90061117ccb212609 100644 (file)
@@ -249,6 +249,7 @@ function copy_to_cart()
        $cart->document_date = $_POST['OrderDate'];
 
        $newpayment = false;
+
        if (isset($_POST['payment']) && ($cart->payment != $_POST['payment'])) {
                $cart->payment = $_POST['payment'];
                $cart->payment_terms = get_payment_terms($_POST['payment']);
@@ -258,7 +259,7 @@ function copy_to_cart()
                if ($newpayment) {
                        $cart->due_date = $cart->document_date;
                        $cart->phone = $cart->cust_ref = $cart->delivery_address = '';
-                       $cart->ship_via = 1;
+                       $cart->ship_via = 0;
                        $cart->deliver_to = '';
                }
        } else {
@@ -732,6 +733,7 @@ if ($customer_error == "") {
 } else {
        display_error($customer_error);
 }
+
 end_form();
 end_page();
 ?>
\ No newline at end of file