X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FCron%2Falert_expiration.pm;h=eb53ea88007efec94d2d64d8fc0ee2776905ab4d;hb=b5c4237a34aef94976bc343c8d9e138664fc3984;hp=a9b9da9e92ce5a7697869cdf5f4aa29cf3e6a834;hpb=d8e19d73efa750780648146fd45fe701c70c3465;p=freeside.git diff --git a/FS/FS/Cron/alert_expiration.pm b/FS/FS/Cron/alert_expiration.pm index a9b9da9e9..eb53ea880 100644 --- a/FS/FS/Cron/alert_expiration.pm +++ b/FS/FS/Cron/alert_expiration.pm @@ -2,7 +2,7 @@ package FS::Cron::alert_expiration; use vars qw( @ISA @EXPORT_OK); use Exporter; -use FS::Record qw(qsearch); +use FS::Record qw(qsearch qsearchs); use FS::Conf; use FS::cust_main; use FS::Misc; @@ -58,6 +58,7 @@ sub alert_expiration { } return if(!@customers); foreach my $customer (@customers) { + next if !($customer->ncancelled_pkgs); # skip inactive customers my $paydate = $customer->paydate; next if $paydate =~ /^\s*$/; # skip empty expiration dates @@ -91,25 +92,33 @@ sub alert_expiration { if (grep { $expire_time < $_date + $_ && $expire_time > $_date + $_ - $window_time } ($warning_time, $urgent_time, $panic_time) ) { + # Send an expiration notice. my $agentnum = $customer->agentnum; - $mail_sender = $conf->config('invoice_from', $agentnum); - $failure_recipient = $conf->config('invoice_from', $agentnum) - || 'postmaster'; - - my @alerter_template = $conf->config('alerter_template', $agentnum) - or die 'cannot load config file alerter_template'; - - my $alerter = new Text::Template(TYPE => 'ARRAY', - SOURCE => [ - map "$_\n", @alerter_template - ]) - or die "can't create Text::Template object: $Text::Template::ERROR"; - - $alerter->compile() - or die "can't compile template: $Text::Template::ERROR"; - - my @packages = $customer->ncancelled_pkgs; - if(@packages) { + my $error = ''; + + my $msgnum = $conf->config('alerter_msgnum', $agentnum); + if ( $msgnum ) { # new hotness + my $msg_template = qsearchs('msg_template', { msgnum => $msgnum } ); + $customer->setfield('expdate', $expire_time); + $error = $msg_template->send('cust_main' => $customer); + } + else { #!$msgnum, the hard way + $mail_sender = $conf->config('invoice_from', $agentnum); + $failure_recipient = $conf->config('invoice_from', $agentnum) + || 'postmaster'; + + my @alerter_template = $conf->config('alerter_template', $agentnum) + or die 'cannot load config file alerter_template'; + + my $alerter = new Text::Template(TYPE => 'ARRAY', + SOURCE => [ + map "$_\n", @alerter_template + ]) + or die "can't create Text::Template object: $Text::Template::ERROR"; + + $alerter->compile() + or die "can't compile template: $Text::Template::ERROR"; + my @invoicing_list = $customer->invoicing_list; my @to_addrs = grep { $_ ne 'POST' } @invoicing_list; if(@to_addrs) { @@ -133,26 +142,29 @@ sub alert_expiration { $fill_in{'payby'} = 'current method'; } # Send it already! - my $error = FS::Misc::send_email ( + $error = FS::Misc::send_email ( from => $mail_sender, to => [ @to_addrs ], subject => 'Billing Arrangement Expiration', body => [ $alerter->fill_in( HASH => \%fill_in ) ], ); - die "can't send expiration alert: $error" - if $error; - } - else { # if(@to_addrs) - push @{$agent_failure_body{$customer->agentnum}}, - sprintf(qq{%5d %-32.32s %4s %10s %12s %12s}, - $custnum, - $first . " " . $last . " " . $company, - $payby, - $paydate, - $daytime, - $night ); - } - } # if(@packages) + } + else { # if(@to_addrs) + push @{$agent_failure_body{$customer->agentnum}}, + sprintf(qq{%5d %-32.32s %4s %10s %12s %12s}, + $custnum, + $first . " " . $last . " " . $company, + $payby, + $paydate, + $daytime, + $night ); + } + } # if($msgnum) + +# should we die here rather than report failure as below? + die "can't send expiration alert: $error" + if $error; + } # if(expired) } # foreach(@customers)