PHP 8 rerun of number_format fix.
[fa-stable.git] / reporting / rep102.php
index fe7ff84a206eae16c237684c3e39af4691c5855b..78d96c806a681c6ae230142dfdc6d6a5c6d56e18 100644 (file)
@@ -34,22 +34,24 @@ function get_invoices($customer_id, $to, $all=true)
        $PastDueDays2 = 2 * $PastDueDays1;
 
        $sign = "IF(`type` IN(".implode(',',  array(ST_CUSTCREDIT,ST_CUSTPAYMENT,ST_BANKDEPOSIT))."), -1, 1)";
+
        $value = "$sign*(IF(trans.prep_amount, trans.prep_amount,
                ABS(trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount)) ".($all ? '' : "- trans.alloc").")";
+
        $due = "IF (type=".ST_SALESINVOICE.", due_date, tran_date)";
 
        $sql = "SELECT type, reference, tran_date,
-               $sign*$value as Balance,
-               IF ((TO_DAYS('$todate') - TO_DAYS($due)) > 0,$sign*$value,0) AS Due,
-               IF ((TO_DAYS('$todate') - TO_DAYS($due)) > $PastDueDays1,$sign*$value,0) AS Overdue1,
-               IF ((TO_DAYS('$todate') - TO_DAYS($due)) > $PastDueDays2,$sign*$value,0) AS Overdue2
+               $value as Balance,
+               IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= 0,$value,0) AS Due,
+               IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= $PastDueDays1,$value,0) AS Overdue1,
+               IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= $PastDueDays2,$value,0) AS Overdue2
 
                FROM ".TB_PREF."debtor_trans trans
 
                WHERE type <> ".ST_CUSTDELIVERY."
                        AND debtor_no = $customer_id 
                        AND tran_date <= '$todate'
-                       AND ABS(IF(trans.prep_amount, trans.prep_amount, ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount) ".($all ? '' : '-trans.alloc').") > " . FLOAT_COMP_DELTA;
+                       AND ABS($value) > " . FLOAT_COMP_DELTA;
 
        $sql .= "ORDER BY tran_date";
 
@@ -138,7 +140,7 @@ function print_aged_customer_analysis()
 
        $total = array(0,0,0,0, 0);
 
-       $sql = "SELECT debtor_no, name, curr_code FROM ".TB_PREF."debtors_master";
+       $sql = "SELECT debtor_no, name, curr_code, inactive FROM ".TB_PREF."debtors_master";
        if ($fromcust != ALL_TEXT)
                $sql .= " WHERE debtor_no=".db_escape($fromcust);
        $sql .= " ORDER BY name";
@@ -166,7 +168,7 @@ function print_aged_customer_analysis()
                if ($no_zeros && floatcmp(array_sum($str), 0) == 0) continue;
 
                $rep->fontSize += 2;
-               $rep->TextCol(0, 2, $myrow["name"]);
+               $rep->TextCol(0, 2, $myrow["name"].($myrow['inactive']==1 ? " ("._("Inactive").")" : ""));
                if ($convert) $rep->TextCol(2, 3,       $myrow['curr_code']);
                $rep->fontSize -= 2;
                $total[0] += ($custrec["Balance"] - $custrec["Due"]);