[freeside-commits] branch FREESIDE_3_BRANCH updated. 67ca665cce866aff8c4f1fecd700c44c5e63c2a0
Mark Wells
mark at 420.am
Mon Feb 1 16:06:16 PST 2016
The branch, FREESIDE_3_BRANCH has been updated
via 67ca665cce866aff8c4f1fecd700c44c5e63c2a0 (commit)
from e0d137dcd3e28fcf8f307120ef86733b5814ffec (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 67ca665cce866aff8c4f1fecd700c44c5e63c2a0
Author: Mark Wells <mark at freeside.biz>
Date: Mon Feb 1 15:52:39 2016 -0800
fix calculation of unused time credit + advance billing, #36726
diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm
index da1f0ad..6ff91b5 100644
--- a/FS/FS/part_pkg/flat.pm
+++ b/FS/FS/part_pkg/flat.pm
@@ -239,24 +239,33 @@ sub calc_remain {
# Use sdate < $time and edate >= $time because when billing on
# cancellation, edate = $time.
my $credit = 0;
- foreach my $item (
+ foreach my $cust_bill_pkg (
qsearch('cust_bill_pkg', {
pkgnum => $cust_pkg->pkgnum,
- sdate => {op => '<' , value => $time},
edate => {op => '>=', value => $time},
recur => {op => '>' , value => 0},
})
) {
# hack to deal with the weird behavior of edate on package cancellation
- my $edate = $item->edate;
+ my $edate = $cust_bill_pkg->edate;
if ( $self->recur_temporality eq 'preceding' ) {
- $edate = $self->add_freq($item->sdate);
+ $edate = $self->add_freq($cust_bill_pkg->sdate);
}
- $credit += ($item->recur - $item->usage) *
- ($edate - $time) / ($edate - $item->sdate);
+
+ # this will also get any package charges that are _entirely_ after the
+ # cancellation date (can happen with advance billing). in that case,
+ # use the entire recurring charge:
+ my $amount = $cust_bill_pkg->recur - $cust_bill_pkg->usage;
+
+ # but if the cancellation happens during the interval, prorate it:
+ # (XXX obey prorate_round_day here?)
+ if ( $cust_bill_pkg->sdate < $time ) {
+ $amount = $amount * ($edate - $time) / ($edate - $cust_bill_pkg->sdate);
+ }
+
+ $credit += $amount;
}
sprintf('%.2f', $credit);
- #sprintf("%.2f", $self->base_recur($cust_pkg, \$time) * ( $next_bill - $time ) / $freq_sec );
}
-----------------------------------------------------------------------
Summary of changes:
FS/FS/part_pkg/flat.pm | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
More information about the freeside-commits
mailing list