[freeside-commits] branch FREESIDE_3_BRANCH updated. ab9786fe9ea49e7a00459da99f1b8dc1e2b023d3
Mark Wells
mark at 420.am
Tue Nov 3 01:37:48 PST 2015
The branch, FREESIDE_3_BRANCH has been updated
via ab9786fe9ea49e7a00459da99f1b8dc1e2b023d3 (commit)
from e2b9b80255731ec51fae4941e564f63166336a63 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit ab9786fe9ea49e7a00459da99f1b8dc1e2b023d3
Author: Mark Wells <mark at freeside.biz>
Date: Tue Nov 3 01:25:57 2015 -0800
on invoice summary, include "future" payments to past invoices in balance adjustments, #38165
diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm
index 5abcc14..b9a934d 100644
--- a/FS/FS/Template_Mixin.pm
+++ b/FS/FS/Template_Mixin.pm
@@ -713,6 +713,8 @@ sub print_generic {
# "balance_date_range" unfortunately is unsuitable for this, since it
# cares about application dates. We want to know the sum of all
# _top-level transactions_ dated before the last invoice.
+ #
+ # still do this for the "Previous Balance" line of the summary block
my @sql =
map "$_ WHERE _date <= ? AND custnum = ?", (
"SELECT COALESCE( SUM(charged), 0 ) FROM cust_bill",
@@ -745,19 +747,31 @@ sub print_generic {
# longer stored in the database)
$invoice_data{'true_previous_balance'} = $last_bill_balance;
- # the change in balance from immediately after that invoice
- # to immediately before this one
- my $before_this_bill_balance = 0;
+ # Now, get all applications of credits/payments dated on or after the
+ # previous bill, to invoices before the current bill. (The
+ # credit/payment date restriction prevents these from intersecting
+ # the "Previous Balance" set.)
+ # These are "adjustments". The past due balance will be shown as
+ # Previous Balance - Adjustments.
+ my $adjustments = 0;
+ @sql = map {
+ "SELECT COALESCE(SUM(y.amount),0) FROM $_ JOIN cust_bill USING (invnum)
+ WHERE cust_bill._date < ?
+ AND x._date >= ?
+ AND cust_bill.custnum = ?"
+ } "cust_credit AS x JOIN cust_credit_bill y USING (crednum)",
+ "cust_pay AS x JOIN cust_bill_pay y USING (paynum)"
+ ;
foreach (@sql) {
my $delta = FS::Record->scalar_sql(
$_,
- $self->_date - 1,
+ $self->_date,
+ $last_bill->_date,
$self->custnum,
);
- $before_this_bill_balance += $delta;
+ $adjustments += $delta;
}
- $invoice_data{'balance_adjustments'} =
- sprintf("%.2f", $last_bill_balance - $before_this_bill_balance);
+ $invoice_data{'balance_adjustments'} = sprintf("%.2f", $adjustments);
warn sprintf("BALANCE ADJUSTMENTS: %.2f\n\n",
$invoice_data{'balance_adjustments'}
-----------------------------------------------------------------------
Summary of changes:
FS/FS/Template_Mixin.pm | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
More information about the freeside-commits
mailing list