summaryrefslogtreecommitdiff
path: root/FS/FS/cust_pkg.pm
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2016-10-17 16:03:13 -0700
committerMark Wells <mark@freeside.biz>2016-10-17 16:08:39 -0700
commit3bfc810bd02e6b822964cbabda2480a21b61ff38 (patch)
tree3c7ee30618200247ef22106e2d8983f8944b625e /FS/FS/cust_pkg.pm
parente1bd031f800327e3efcc35ae2715794b85352a94 (diff)
limit unused-time credit if the invoice already has credits applied, #72873, from #42729
Diffstat (limited to 'FS/FS/cust_pkg.pm')
-rw-r--r--FS/FS/cust_pkg.pm21
1 files changed, 16 insertions, 5 deletions
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 634895a..4de2faa 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -1817,6 +1817,8 @@ sub credit_remaining {
# 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;
+ my $max_credit = $amount
+ - $cust_bill_pkg->credited('', '', setuprecur => 'recur') || 0;
# but if the cancellation happens during the interval, prorate it:
# (XXX obey prorate_round_day here?)
@@ -1825,14 +1827,23 @@ sub credit_remaining {
($edate - $time) / ($edate - $cust_bill_pkg->sdate);
}
+ # if there are existing credits, don't let the sum of credits exceed
+ # the recurring charge
+ $amount = $max_credit if $amount > $max_credit;
+
$amount = sprintf('%.2f', $amount);
- push @billpkgnums, $cust_bill_pkg->billpkgnum;
- push @amounts, $amount;
- push @setuprecurs, 'recur';
+ # if no time has been used and/or there are existing line item
+ # credits, we may end up not needing to credit anything.
+ if ( $amount > 0 ) {
- warn "Crediting for $amount on package ".$remain_pkg->pkgnum."\n"
- if $DEBUG;
+ push @billpkgnums, $cust_bill_pkg->billpkgnum;
+ push @amounts, $amount;
+ push @setuprecurs, 'recur';
+
+ warn "Crediting for $amount on package ".$remain_pkg->pkgnum."\n"
+ if $DEBUG;
+ }
}