summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2016-02-01 15:52:39 -0800
committerMark Wells <mark@freeside.biz>2016-02-01 15:52:54 -0800
commitf5674f02fc85ffe3cb8b5ff8b2ca1ffd1af70d00 (patch)
tree54530964446a3731bb727979e1cc2ba285b36463
parent6f870771982425279dd9576b7e36710dc79911b2 (diff)
fix calculation of unused time credit + advance billing, #36726
-rw-r--r--FS/FS/part_pkg/flat.pm14
1 files changed, 11 insertions, 3 deletions
diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm
index b82303c1e..8844991cd 100644
--- a/FS/FS/part_pkg/flat.pm
+++ b/FS/FS/part_pkg/flat.pm
@@ -247,7 +247,6 @@ sub calc_remain {
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},
})
@@ -259,8 +258,17 @@ sub calc_remain {
$edate = $self->add_freq($cust_bill_pkg->sdate);
}
- my $amount = ($cust_bill_pkg->recur - $cust_bill_pkg->usage) *
- ($edate - $time) / ($edate - $cust_bill_pkg->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;
push @{ $options{'cust_credit_source_bill_pkg'} },