summaryrefslogtreecommitdiff
path: root/FS/FS/cust_main_Mixin.pm
diff options
context:
space:
mode:
authorJonathan Prykop <jonathan@freeside.biz>2016-04-12 05:36:58 -0500
committerJonathan Prykop <jonathan@freeside.biz>2016-04-12 05:40:59 -0500
commit3061ba49c4e98dd806cbaa9b037711e220244a54 (patch)
tree3a9c6e10c0743b1c5df96bca4306b92d6fb869b1 /FS/FS/cust_main_Mixin.pm
parent7b14607a667af826d4b8dd90ca4267f5b51c33ba (diff)
RT#28648: Unsuspend when past due balance is paid [new option, Charges not past due]
Diffstat (limited to 'FS/FS/cust_main_Mixin.pm')
-rw-r--r--FS/FS/cust_main_Mixin.pm18
1 files changed, 16 insertions, 2 deletions
diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm
index 9a2a9d7..bbba8c5 100644
--- a/FS/FS/cust_main_Mixin.pm
+++ b/FS/FS/cust_main_Mixin.pm
@@ -669,11 +669,25 @@ sub unsuspend_balance {
my $maxbalance;
if ($setting eq 'Zero') {
$maxbalance = 0;
+
+ # kind of a pain to load/check all cust_bill instead of just open ones,
+ # but if for some reason payment gets applied to later bills before
+ # earlier ones, we still want to consider the later ones as allowable balance
} elsif ($setting eq 'Latest invoice charges') {
my @cust_bill = $cust_main->cust_bill();
my $cust_bill = $cust_bill[-1]; #always want the most recent one
- return unless $cust_bill;
- $maxbalance = $cust_bill->charged || 0;
+ if ($cust_bill) {
+ $maxbalance = $cust_bill->charged || 0;
+ } else {
+ $maxbalance = 0;
+ }
+ } elsif ($setting eq 'Charges not past due') {
+ my $now = time;
+ $maxbalance = 0;
+ foreach my $cust_bill ($cust_main->cust_bill()) {
+ next unless $now <= ($cust_bill->due_date || $cust_bill->_date);
+ $maxbalance += $cust_bill->charged || 0;
+ }
} elsif (length($setting)) {
warn "Unrecognized unsuspend_balance setting $setting";
return;