Fixed summation error in Aged customer/supplier Lists
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Fri, 29 Apr 2011 11:47:29 +0000 (13:47 +0200)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Fri, 29 Apr 2011 11:47:29 +0000 (13:47 +0200)
purchasing/includes/db/suppliers_db.inc
reporting/rep102.php
reporting/rep202.php
sales/includes/db/customers_db.inc

index 6630dd2a991de2bde0f3d3d12c8ad930173ab443..57256d4cc40688bd101ea7f2d5fa6ff79c4475e1 100644 (file)
@@ -88,7 +88,12 @@ function get_supplier_details($supplier_id, $to=null, $all=true)
        $past2 = 2 * $past1;
        // removed - supp_trans.alloc from all summations
 
-    $value = "(trans.ov_amount + trans.ov_gst + trans.ov_discount)";
+       if ($all)
+       $value = "(trans.ov_amount + trans.ov_gst + trans.ov_discount)";
+    else       
+       $value = "IF (trans.type=".ST_SUPPINVOICE." OR trans.type=".ST_BANKDEPOSIT.",
+               (trans.ov_amount + trans.ov_gst + trans.ov_discount - trans.alloc),
+               (trans.ov_amount + trans.ov_gst + trans.ov_discount + trans.alloc))";
        $due = "IF (trans.type=".ST_SUPPINVOICE." OR trans.type=".ST_SUPPCREDIT.",trans.due_date,trans.tran_date)";
     $sql = "SELECT supp.supp_name, supp.curr_code, ".TB_PREF."payment_terms.terms,
 
index b839b6b7e650c399eb5543749417abe998230278..2d00c063f1573e637498bb2e094892f1aa6ed8ac 100644 (file)
@@ -34,9 +34,14 @@ function get_invoices($customer_id, $to, $all=true)
        $PastDueDays2 = 2 * $PastDueDays1;
 
        // Revomed allocated from sql
-    $value = "(".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + "
-               .TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_freight_tax + "
-               .TB_PREF."debtor_trans.ov_discount)";
+       if ($all)
+       $value = "(".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + "
+                       .TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_freight_tax + "
+                       .TB_PREF."debtor_trans.ov_discount)";
+       else            
+       $value = "(".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + "
+                       .TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_freight_tax + "
+                       .TB_PREF."debtor_trans.ov_discount - ".TB_PREF."debtor_trans.alloc)";
        $due = "IF (".TB_PREF."debtor_trans.type=".ST_SALESINVOICE.",".TB_PREF."debtor_trans.due_date,".TB_PREF."debtor_trans.tran_date)";
        $sql = "SELECT ".TB_PREF."debtor_trans.type, ".TB_PREF."debtor_trans.reference,
                ".TB_PREF."debtor_trans.tran_date,
index 4cf9809560c55f0002a3ae25f580ab3f8d8b7cd5..f18abaec1b83da9634f048373b3257481bc6d80d 100644 (file)
@@ -36,7 +36,12 @@ function get_invoices($supplier_id, $to, $all=true)
        $PastDueDays2 = 2 * $PastDueDays1;
 
        // Revomed allocated from sql
-    $value = "(".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount)";
+       if ($all)
+       $value = "(".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount)";
+    else       
+       $value = "IF (".TB_PREF."supp_trans.type=".ST_SUPPINVOICE." OR ".TB_PREF."supp_trans.type=".ST_BANKDEPOSIT.", 
+       (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount - ".TB_PREF."supp_trans.alloc),
+       (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount + ".TB_PREF."supp_trans.alloc))";
        $due = "IF (".TB_PREF."supp_trans.type=".ST_SUPPINVOICE." OR ".TB_PREF."supp_trans.type=".ST_SUPPCREDIT.",".TB_PREF."supp_trans.due_date,".TB_PREF."supp_trans.tran_date)";
        $sql = "SELECT ".TB_PREF."supp_trans.type,
                ".TB_PREF."supp_trans.reference,
index f1aa87aee15eddaba8e98dac56c940dfcedb11de..1bbe767728731743f5df846fed2c229557fbd878 100644 (file)
@@ -71,10 +71,13 @@ function get_customer_details($customer_id, $to=null, $all=true)
        $past1 = get_company_pref('past_due_days');
        $past2 = 2 * $past1;
        // removed - debtor_trans.alloc from all summations
-
-    $value = "IFNULL(IF(trans.type=11 OR trans.type=12 OR trans.type=2, -1, 1) 
-       * (trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount),0)";
-
+       if ($all)
+       $value = "IFNULL(IF(trans.type=11 OR trans.type=12 OR trans.type=2, -1, 1) 
+               * (trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount),0)";
+    else               
+       $value = "IFNULL(IF(trans.type=11 OR trans.type=12 OR trans.type=2, -1, 1) 
+               * (trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount - 
+               trans.alloc),0)";
        $due = "IF (trans.type=10, trans.due_date, trans.tran_date)";
     $sql = "SELECT ".TB_PREF."debtors_master.name, ".TB_PREF."debtors_master.curr_code, ".TB_PREF."payment_terms.terms,
                ".TB_PREF."debtors_master.credit_limit, ".TB_PREF."credit_status.dissallow_invoices, ".TB_PREF."credit_status.reason_description,