From: Jonathan Prykop Date: Tue, 12 Apr 2016 10:36:58 +0000 (-0500) Subject: RT#28648: Unsuspend when past due balance is paid [new option, Charges not past due] X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=31807e3e9acddff34011e919728c113e69ad9a26 RT#28648: Unsuspend when past due balance is paid [new option, Charges not past due] --- diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index d0b1180cb..87fd2524a 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -1972,7 +1972,7 @@ and customer address. Include units.', 'description' => 'Enables the automatic unsuspension of suspended packages when a customer\'s balance due is at or below the specified amount after a payment or credit', 'type' => 'select', 'select_enum' => [ - '', 'Zero', 'Latest invoice charges' + '', 'Zero', 'Latest invoice charges', 'Charges not past due' ], }, diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm index 9a2a9d7b1..bbba8c5f7 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;