summaryrefslogtreecommitdiff
path: root/FS/FS/cust_main_Mixin.pm
diff options
context:
space:
mode:
authorJonathan Prykop <jonathan@freeside.biz>2016-03-14 23:39:18 -0500
committerJonathan Prykop <jonathan@freeside.biz>2016-03-17 00:31:29 -0500
commitfdff077d075af80c623bf03ce65cca4af0ebdde5 (patch)
tree8550b45ecb206bfadac1cc31da8bec5f07c6c0d5 /FS/FS/cust_main_Mixin.pm
parent216272ed8a5ccfc8dc72268b9b02cc8fcd4479cf (diff)
RT#28648: Unsuspend when past due balance is paid
Diffstat (limited to 'FS/FS/cust_main_Mixin.pm')
-rw-r--r--FS/FS/cust_main_Mixin.pm39
1 files changed, 39 insertions, 0 deletions
diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm
index de13847..9b4ae3a 100644
--- a/FS/FS/cust_main_Mixin.pm
+++ b/FS/FS/cust_main_Mixin.pm
@@ -654,6 +654,45 @@ sub time2str_local {
$string;
}
+=item unsuspend_balance
+
+If conf I<unsuspend_balance> is set and customer's current balance is
+beneath the set threshold, unsuspends customer packages.
+
+=cut
+
+sub unsuspend_balance {
+ my $self = shift;
+ my $cust_main = $self->cust_main;
+ my $conf = $self->conf;
+ my $setting = $conf->config('unsuspend_balance');
+ my $maxbalance;
+ if ($setting eq 'Zero') {
+ $maxbalance = 0;
+ } 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;
+ } elsif (length($setting)) {
+ warn "Unrecognized unsuspend_balance setting $setting";
+ return;
+ } else {
+ return;
+ }
+ my $balance = $cust_main->balance || 0;
+ if ($balance <= $maxbalance) {
+ # or should this be
+ # my @errors = grep { ($_->get('setup')) && $_->unsuspend } $cust_main->unflagged_suspended_pkgs;
+ my @errors = $cust_main->unsuspend;
+ # side-fx with nested transactions? upstack rolls back?
+ warn "WARNING:Errors unsuspending customer ". $cust_main->custnum. ": ".
+ join(' / ', @errors)
+ if @errors;
+ }
+ return;
+}
+
=back
=head1 BUGS