Bug 5510: fix of bug 0004530 is not correct. Has now been fixed and rerun.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Thu, 28 Oct 2021 10:10:20 +0000 (12:10 +0200)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Thu, 28 Oct 2021 10:10:20 +0000 (12:10 +0200)
sales/includes/db/cust_trans_db.inc
sales/includes/db/custalloc_db.inc
sales/inquiry/customer_inquiry.php

index a68063b8ff8f0cc315c0ddd09911e79b8c5bced5..e71ecad05543f872cd98aa9bb6b833865c437e69 100644 (file)
@@ -318,7 +318,7 @@ function get_sql_for_customer_inquiry($from, $to, $cust_id = ALL_TEXT, $filter =
                debtor.name, 
                branch.br_name,
                debtor.curr_code,
-               IF(prep_amount, prep_amount, trans.ov_amount + trans.ov_gst + trans.ov_freight 
+               IF(prep_amount, prep_amount, abs(trans.ov_amount) + trans.ov_gst + trans.ov_freight 
                        + trans.ov_freight_tax + trans.ov_discount)     AS TotalAmount,"
 //     if ($filter != ALL_TEXT)
 //             $sql .= "@bal := @bal+IF(prep_amount, prep_amount, trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount), ";
index 1fa6995acad11cb81def1701502f8518501f5adb..4633c7cef59f80d3402e3062e59bd25269fb74ad 100644 (file)
@@ -112,7 +112,7 @@ function get_allocatable_from_cust_sql($customer_id, $settled)
                trans.due_date,
                debtor.address,
                trans.version,
-               round(abs(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc),6) <= 0 AS settled,
+               round(abs(ov_amount)+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc,6) <= 0 AS settled,
                trans.debtor_no
 
         FROM "
@@ -121,10 +121,10 @@ function get_allocatable_from_cust_sql($customer_id, $settled)
        ." WHERE trans.debtor_no=debtor.debtor_no
                AND (((type=".ST_CUSTPAYMENT." OR type=".ST_BANKDEPOSIT.") AND (trans.ov_amount > 0))
                 OR (type=".ST_CUSTCREDIT. " AND (ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)>0)
-                OR (type=".ST_JOURNAL. " AND (trans.ov_amount > 0)))";
+                OR (type=".ST_JOURNAL. " AND (trans.ov_amount < 0)))";
 
        if (!$settled)
-               $sql .= " AND (round(abs(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc),6) > 0)";
+               $sql .= " AND round(abs(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)-alloc, 6) > 0";
 
        if ($customer_id != null)
                $sql .= " AND trans.debtor_no = ".db_escape($customer_id);
@@ -265,7 +265,7 @@ function get_allocatable_from_cust_transactions($customer_id, $trans_no=null, $t
        }
        else
        {
-               $sql .= " AND round(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc,6) > 0
+               $sql .= " AND round(abs(ov_amount)+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc,6) > 0
                        AND trans.type NOT IN (".implode(',',array(ST_CUSTPAYMENT,ST_BANKDEPOSIT,ST_CUSTCREDIT,ST_CUSTDELIVERY)).")";
                $sql .= " GROUP BY type, trans_no";
        }
index 2183dd1b2ae4b15c91d5d2ddd6ab38ddb7117b85..989e6ddd61467bbea0b0814fa932cedf384e9e43 100644 (file)
@@ -59,7 +59,7 @@ function gl_view($row)
 function fmt_amount($row)
 {
        $value =
-           $row['type']==ST_CUSTCREDIT || $row['type']==ST_CUSTPAYMENT || $row['type']==ST_BANKDEPOSIT ?
+           $row['type']==ST_CUSTCREDIT || $row['type']==ST_CUSTPAYMENT || $row['type']==ST_BANKDEPOSIT || $row['type']==ST_JOURNAL ?
                -$row["TotalAmount"] : $row["TotalAmount"];
     return price_format($value);
 }