X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main_Mixin.pm;h=9a2a9d7b1c6bf154cac0837da0a7577f5b827cde;hb=cc4caa54e9974ea3d6ac7cf55cf45863d2a8905e;hp=867d43e60996d4b7e2091a8ec2d4881b1567c87f;hpb=2b2dd969f3c18751afc583ad1e836ab8e6f73b5d;p=freeside.git diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm index 867d43e60..9a2a9d7b1 100644 --- a/FS/FS/cust_main_Mixin.pm +++ b/FS/FS/cust_main_Mixin.pm @@ -313,8 +313,6 @@ in HASHREF. Valid parameters are: =item status -=item payby - =back =cut @@ -339,15 +337,6 @@ sub cust_search_sql { push @search, $class->$method(); } - #payby - my @payby = ref($param->{'payby'}) - ? @{ $param->{'payby'} } - : split(',', $param->{'payby'}); - @payby = grep /^([A-Z]{4})$/, @payby; - if ( @payby ) { - push @search, 'cust_main.payby IN ('. join(',', map "'$_'", @payby). ')'; - } - #here is the agent virtualization push @search, $FS::CurrentUser::CurrentUser->agentnums_sql( 'table' => 'cust_main' ); @@ -557,9 +546,6 @@ sub process_email_search_result { $param->{'search'} = thaw(decode_base64($param->{'search'})) or die "process_email_search_result requires search params.\n"; -# $param->{'payby'} = [ split(/\0/, $param->{'payby'}) ] -# unless ref($param->{'payby'}); - my $table = $param->{'table'} or die "process_email_search_result requires table.\n"; @@ -668,6 +654,43 @@ 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) { + 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