Customer balances reports: fixed balance sums for prepayment invoices.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 29 Apr 2022 08:56:51 +0000 (10:56 +0200)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 29 Apr 2022 08:56:51 +0000 (10:56 +0200)
reporting/includes/doctext.inc
reporting/rep101.php
reporting/rep102.php
reporting/rep108.php
reporting/rep115.php

index 4b87fa6df229df98b78d41ccfc5c18e7b8276c29..16db8df5c0ab6f9d999043f371d4007ab6b59b3b 100644 (file)
                                _("Our Order No") => '',
                                _("Delivery Date") => '',
                        );
-                       $this->headers = array(_("Trans Type"), _("#"), _("Date"), _("DueDate"), _("Charges"),
+                       $this->headers = array(_("Trans Type"), _("#"), _("Date"), _("DueDate"), _("Debits"),
                                _("Credits"), _("Allocated"), _("Outstanding"));
        }
 
index fd87944f8631231ba43d783a99f3fc12be019b89..a9bd160952a62fd429b483cefb9f41c29a7515c0 100644 (file)
@@ -34,7 +34,7 @@ function get_open_balance($debtorno, $to)
        if($to)
                $to = date2sql($to);
        $sql = "SELECT SUM(IF(t.type = ".ST_SALESINVOICE." OR (t.type IN (".ST_JOURNAL." , ".ST_BANKPAYMENT.") AND t.ov_amount>0),
-             -abs(t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount), 0)) AS charges,";
+             -abs(IF(t.prep_amount, t.prep_amount, t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount)), 0)) AS charges,";
 
        $sql .= "SUM(IF(t.type != ".ST_SALESINVOICE." AND NOT(t.type IN (".ST_JOURNAL." , ".ST_BANKPAYMENT.") AND t.ov_amount>0),
              abs(t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount) * -1, 0)) AS credits,";             
@@ -42,7 +42,7 @@ function get_open_balance($debtorno, $to)
     $sql .= "SUM(IF(t.type != ".ST_SALESINVOICE." AND NOT(t.type IN (".ST_JOURNAL." , ".ST_BANKPAYMENT.")), t.alloc * -1, t.alloc)) AS Allocated,";
 
        $sql .= "SUM(IF(t.type = ".ST_SALESINVOICE." OR (t.type IN (".ST_JOURNAL." , ".ST_BANKPAYMENT.") AND t.ov_amount>0), 1, -1) *
-                       (abs(t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount) - abs(t.alloc))) AS OutStanding
+                       (IF(t.prep_amount, t.prep_amount, abs(t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount)) - abs(t.alloc))) AS OutStanding
                FROM ".TB_PREF."debtor_trans t
        WHERE t.debtor_no = ".db_escape($debtorno)
                ." AND t.type <> ".ST_CUSTDELIVERY;
@@ -73,7 +73,8 @@ function get_transactions($debtorno, $from, $to)
                                GROUP BY trans_type_to, trans_no_to) alloc_to";
 
      $sql = "SELECT trans.*,
-               (trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount) AS TotalAmount,
+               IF(trans.prep_amount, trans.prep_amount, trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount)
+                       AS TotalAmount,
                IFNULL(alloc_from.amount, alloc_to.amount) AS Allocated,
                ((trans.type = ".ST_SALESINVOICE.")     AND trans.due_date < '$to') AS OverDue
        FROM ".TB_PREF."debtor_trans trans
@@ -133,7 +134,7 @@ function print_customer_balances()
 
        $cols = array(0, 95, 140, 200,  250, 320, 385, 450,     515);
 
-       $headers = array(_('Trans Type'), _('#'), _('Date'), _('Due Date'), _('Charges'), _('Credits'),
+       $headers = array(_('Trans Type'), _('#'), _('Date'), _('Due Date'), _('Debits'), _('Credits'),
                _('Allocated'),         _('Outstanding'));
 
        if ($show_balance)
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)";
 
index 970d57248eba52ef220c04df93dfb21ae1759d5e..abb11e7f50227a8b386b6eeb940784eee48e37e1 100644 (file)
@@ -38,7 +38,8 @@ function getTransactions($debtorno, $date, $show_also_allocated)
         trans.reference,
         trans.tran_date,
         trans.due_date,
-        (ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount) AS TotalAmount, alloc AS Allocated,
+        IF(prep_amount, prep_amount, ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount) AS TotalAmount,
+        alloc AS Allocated,
                ((trans.type = ".ST_SALESINVOICE.") AND due_date < '$date') AS OverDue
                FROM ".TB_PREF."debtor_trans trans
                LEFT JOIN ".TB_PREF."voided as v
@@ -48,7 +49,7 @@ function getTransactions($debtorno, $date, $show_also_allocated)
                        AND ABS(ABS(ov_amount) + ov_gst + ov_freight + ov_freight_tax + ov_discount) > ". FLOAT_COMP_DELTA;
        
        if (!$show_also_allocated)
-               $sql .= " AND ABS(ABS(ov_amount) + ov_gst + ov_freight +        ov_freight_tax + ov_discount - alloc) > ". FLOAT_COMP_DELTA;
+               $sql .= " AND ABS(IF(prep_amount, prep_amount, ABS(ov_amount) + ov_gst + ov_freight + ov_freight_tax + ov_discount) - alloc) > ". FLOAT_COMP_DELTA;
        $sql .= " ORDER BY tran_date";
 
     return db_query($sql,"No transactions were returned");
index 0ed751930cfdc56ff19e56ce681facb8599c6c1a..484746b61c11ddb6c02acbd026f16efbf2af3eca 100644 (file)
@@ -35,7 +35,7 @@ function get_open_balance($debtorno, $to)
         $to = date2sql($to);
 
     $sql = "SELECT SUM(IF(t.type = ".ST_SALESINVOICE." OR (t.type IN (".ST_JOURNAL." , ".ST_BANKPAYMENT.") AND t.ov_amount>0),
-        -abs(t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount), 0)) AS charges,";
+        -abs(IF(prep_amount, prep_amount, ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount)), 0)) AS charges,";
        $sql .= "SUM(IF(t.type != ".ST_SALESINVOICE." AND NOT(t.type IN (".ST_JOURNAL." , ".ST_BANKPAYMENT.") AND t.ov_amount>0),
         abs(t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount) * -1, 0)) AS credits,";
     $sql .= "SUM(IF(t.type != ".ST_SALESINVOICE." AND NOT(t.type IN (".ST_JOURNAL." , ".ST_BANKPAYMENT.")),