Customer balances reports: fixed balance sums for prepayment invoices.
[fa-stable.git] / reporting / rep102.php
index 92b56466b7cbd7f7dfdf0f6c734032d5f8b27749..a63ac9c5cd58f1b4b987a5f021159546d0e46dad 100644 (file)
@@ -35,9 +35,9 @@ function get_invoices($customer_id, $to, $all=true)
 
        // Revomed allocated from sql
        if ($all)
-       $value = "(ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount)";
+        $value = "IF(prep_amount, prep_amount, ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount)";
        else
-       $value = "(ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount - alloc)";
+        $value = "(IF(prep_amount, prep_amount, ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount)-alloc)";
        $sign = "IF(`type` IN(".implode(',',  array(ST_CUSTCREDIT,ST_CUSTPAYMENT,ST_BANKDEPOSIT,ST_JOURNAL))."), -1, 1)";
        $due = "IF (type=".ST_SALESINVOICE.", due_date, tran_date)";