Rerun of Supplier Inquiry Aging. Optimizing.
authorJoe <joe.hunt.consulting@gmail.com>
Fri, 28 Apr 2023 15:49:54 +0000 (17:49 +0200)
committerJoe <joe.hunt.consulting@gmail.com>
Fri, 28 Apr 2023 15:49:54 +0000 (17:49 +0200)
purchasing/includes/db/suppliers_db.inc
reporting/rep202.php

index c3a16d21488a9ac516eb55379e87a39b3f18f517..7c97b1c1c4d10b9f60eeb181227e6c349aefd136 100644 (file)
@@ -95,9 +95,9 @@ function get_supplier_details($supplier_id, $to=null, $all=true)
        if ($all)
        $value = "(trans.ov_amount + trans.ov_gst + trans.ov_discount)";
     else       
-       $value = "IF (trans.type=".ST_SUPPINVOICE." OR trans.type=".ST_BANKDEPOSIT."
-       OR (trans.type=".ST_JOURNAL." AND (trans.ov_amount + trans.ov_gst + trans.ov_discount)>0), 1, -1)*
-               ABS(trans.ov_amount + trans.ov_gst + trans.ov_discount) - trans.alloc";
+       $value = "IF (trans.type=".ST_SUPPINVOICE." OR trans.type=".ST_BANKDEPOSIT." OR (trans.type=".ST_JOURNAL." AND (trans.ov_amount + trans.ov_gst + trans.ov_discount)>0), 
+               (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,
@@ -119,7 +119,7 @@ function get_supplier_details($supplier_id, $to=null, $all=true)
                         supp.payment_terms = ".TB_PREF."payment_terms.terms_indicator
                         AND supp.supplier_id = $supplier_id ";
        if (!$all)
-               $sql .= "AND ABS(trans.ov_amount + trans.ov_gst + trans.ov_discount) - trans.alloc > ".FLOAT_COMP_DELTA." ";  
+               $sql .= "AND $value <> 0 ";  
        $sql .= "GROUP BY
                          supp.supp_name,
                          ".TB_PREF."payment_terms.terms,
index 0e122ab4f25a4f5c6bc9587a896dc14e030a3d06..e35e7ba01b8cb3c2947d5314680b45059c3d50ca 100644 (file)
@@ -39,9 +39,9 @@ function get_invoices($supplier_id, $to, $all=true)
        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))";
+       $value = "IF (trans.type=".ST_SUPPINVOICE." OR trans.type=".ST_BANKDEPOSIT." OR (trans.type=".ST_JOURNAL." AND (trans.ov_amount + trans.ov_gst + trans.ov_discount)>0),  
+               (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 trans.type,
                trans.reference,
@@ -59,7 +59,7 @@ function get_invoices($supplier_id, $to, $all=true)
                        AND trans.tran_date <= '$todate'
                        AND ABS(trans.ov_amount + trans.ov_gst + trans.ov_discount) > ".FLOAT_COMP_DELTA;
        if (!$all)
-               $sql .= " AND ABS(trans.ov_amount + trans.ov_gst + trans.ov_discount) - trans.alloc > ".FLOAT_COMP_DELTA;
+               $sql .= "AND $value <> 0 ";
        $sql .= " ORDER BY trans.tran_date";