X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_main_Mixin.pm;fp=FS%2FFS%2Fcust_main_Mixin.pm;h=9b4ae3a090c6cdc13ee4a053cde11247e9cee769;hp=de13847a41ab83c1714ef99d97fb2e0e1af3300d;hb=b3cc20aeca25e4351c6ec3b795a951e6124f6376;hpb=2ffdb485e5534df3d89bcc12d4d02d485e9b28f5 diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm index de13847a4..9b4ae3a09 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 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