[freeside-commits] freeside/FS/bin freeside-expiration-alerter, 1.7, 1.8

Ivan,,, ivan at wavetail.420.am
Mon Feb 9 06:05:33 PST 2009


Update of /home/cvs/cvsroot/freeside/FS/bin
In directory wavetail.420.am:/tmp/cvs-serv17630/FS/bin

Modified Files:
	freeside-expiration-alerter 
Log Message:
rest of per-agent config for company_name, company_address, logo, etc.. RT#3989

Index: freeside-expiration-alerter
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/bin/freeside-expiration-alerter,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- freeside-expiration-alerter	8 Nov 2007 00:59:35 -0000	1.7
+++ freeside-expiration-alerter	9 Feb 2009 14:05:30 -0000	1.8
@@ -13,7 +13,7 @@
 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 @@
 # 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 @@
   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 @@
       ($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,9 +134,10 @@
         }
         $FS::alerter::_template::expdate = $expire_time;
 
-        $FS::alerter::_template::company_name = $conf->config('company_name');
+        $FS::alerter::_template::company_name =
+          $conf->config('company_name', $agentnum);
         $FS::alerter::_template::company_address =
-          join("\n", $conf->config('company_address') ). "\n";
+          join("\n", $conf->config('company_address', $agentnum) ). "\n";
 
         my $message = new Mail::Internet (
           'Header' => $header,
@@ -152,23 +149,41 @@
             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 )



More information about the freeside-commits mailing list