X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2Fbin%2Ffreeside-expiration-alerter;h=0bb61db4a9e920e0271a98865652f22c07b5440a;hb=c6ba0fa6271880599ce3d60dcd23de248526f0b8;hp=691fd3aa5cf2bbc8433b654d0520b685e2f1f869;hpb=c0567c688084e89fcd11bf82348b6c418f1254ac;p=freeside.git diff --git a/FS/bin/freeside-expiration-alerter b/FS/bin/freeside-expiration-alerter index 691fd3aa5..0bb61db4a 100755 --- a/FS/bin/freeside-expiration-alerter +++ b/FS/bin/freeside-expiration-alerter @@ -13,7 +13,7 @@ use FS::UID qw(adminsuidsetup); use FS::Record qw(qsearch); use FS::cust_main; -use vars qw($smtpmachine @body); +use vars qw($smtpmachine %agent_failure_body); #hush, perl! $FS::alerter::_template::first = ""; @@ -47,11 +47,6 @@ adminsuidsetup $user; # Get the needed configuration files my $conf = new FS::Conf; $smtpmachine = $conf->config('smtpmachine'); -$mail_sender = $conf->config('invoice_from') - if $conf->exists('invoice_from'); -$failure_recipient = $conf->config('invoice_from') - if $conf->exists('invoice_from'); - my(@customers)=qsearch('cust_main',{}); if (scalar(@customers) == 0) @@ -59,24 +54,6 @@ if (scalar(@customers) == 0) exit 1; } -# Prepare for sending email - -$ENV{MAILADDRESS} = $mail_sender; -my $header = new Mail::Header ( [ - "From: Account Processor", - "To: $failure_recipient", - "Sender: $mail_sender", - "Reply-To: $mail_sender", - "Subject: Unnotified Billing Arrangement Expirations", -] ); - -my @alerter_template = $conf->config('alerter_template') - 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 new Text::Template object: Text::Template::ERROR"; -$alerter->compile() or die "can't compile template: Text::Template::ERROR"; - # Now I can start looping foreach my $customer (@customers) { @@ -110,7 +87,26 @@ foreach my $customer (@customers) ($expire_time < $_date + $panic_time && $expire_time > $_date + $panic_time - $window_time)) { + # Prepare for sending email, now inside the customer loop so i can be agent + # virtualized + + my $agentnum = $customer->agentnum; + + $mail_sender = $conf->config('invoice_from', $agentnum ) + if $conf->exists('invoice_from', $agentnum); + $failure_recipient = $conf->config('invoice_from', $agentnum) + if $conf->exists('invoice_from', $agentnum); + + $ENV{MAILADDRESS} = $mail_sender; + + 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 new Text::Template object: $Text::Template::ERROR"; + + $alerter->compile() or die "can't compile template: $Text::Template::ERROR"; my @packages = $customer->ncancelled_pkgs; if (scalar(@packages) != 0) { @@ -138,6 +134,11 @@ foreach my $customer (@customers) } $FS::alerter::_template::expdate = $expire_time; + $FS::alerter::_template::company_name = + $conf->config('company_name', $agentnum); + $FS::alerter::_template::company_address = + join("\n", $conf->config('company_address', $agentnum) ). "\n"; + my $message = new Mail::Internet ( 'Header' => $header, 'Body' => [ $alerter->fill_in( PACKAGE => 'FS::alerter::_template' ) ], @@ -148,23 +149,41 @@ foreach my $customer (@customers) or die "Can't send expiration email: $!"; } elsif ( ! @invoicing_list || grep { $_ eq 'POST' } @invoicing_list ) { - push @body, sprintf(qq{%5d %-32.32s %4s %10s %12s %12s}, - $custnum, - $first . " " . $last . " " . $company, - $payby, - $paydate, - $daytime, - $night); + push @{$agent_failure_body{$customer->agentnum}}, + sprintf(qq{%5d %-32.32s %4s %10s %12s %12s}, + $custnum, + $first . " " . $last . " " . $company, + $payby, + $paydate, + $daytime, + $night + ); } } } } -# Now I need to send EMAIL -if (scalar(@body)) { +# Now I need to send failure EMAIL + +foreach my $agentnum ( keys %agent_failure_body ) { + + $mail_sender = $conf->config('invoice_from', $agentnum ) + if $conf->exists('invoice_from', $agentnum); + $failure_recipient = $conf->config('invoice_from', $agentnum) + if $conf->exists('invoice_from', $agentnum); + + $ENV{MAILADDRESS} = $mail_sender; + my $header = new Mail::Header ( [ + "From: Account Processor", + "To: $failure_recipient", + "Sender: $mail_sender", + "Reply-To: $mail_sender", + "Subject: Unnotified Billing Arrangement Expirations", + ] ); + my $message = new Mail::Internet ( 'Header' => $header, - 'Body' => [ (@body) ], + 'Body' => [ @{$agent_failure_body{$agentnum}} ], ); $!=0; $message->smtpsend( Host => $smtpmachine ) @@ -200,10 +219,6 @@ is about to expire. Usually run as a cron job. user: From the mapsecrets file - see config.html from the base documentation -=head1 VERSION - -$Id: freeside-expiration-alerter,v 1.5 2003-04-21 20:53:57 ivan Exp $ - =head1 BUGS Yes..... Use at your own risk. No guarantees or warrantees of any