[freeside-commits] freeside/FS/FS/Cron alert_expiration.pm, 1.1, 1.2 notify.pm, 1.8, 1.9

Mark Wells mark at wavetail.420.am
Wed Jul 28 16:16:32 PDT 2010


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

Modified Files:
	alert_expiration.pm notify.pm 
Log Message:
msg_template improvements, RT#8324

Index: alert_expiration.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Cron/alert_expiration.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- alert_expiration.pm	24 Jun 2009 09:07:21 -0000	1.1
+++ alert_expiration.pm	28 Jul 2010 23:16:30 -0000	1.2
@@ -2,7 +2,7 @@
 
 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 @@
   }
   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,7 +92,16 @@
     if (grep { $expire_time < $_date + $_ &&
                $expire_time > $_date + $_ - $window_time } 
                ($warning_time, $urgent_time, $panic_time) ) {
+      # Send an expiration notice.
       my $agentnum = $customer->agentnum;
+      my $error = '';
+
+      my $msgnum = $conf->config('alerter_msgnum', $agentnum);
+      if ( $msgnum ) { # new hotness
+        my $msg_template = qsearchs('msg_template', { msgnum => $msgnum } );
+        $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';
@@ -108,8 +118,6 @@
       $alerter->compile()
         or die "can't compile template: $Text::Template::ERROR";
       
-      my @packages = $customer->ncancelled_pkgs;
-      if(@packages) {
         my @invoicing_list = $customer->invoicing_list;
         my @to_addrs = grep { $_ ne 'POST' } @invoicing_list;
         if(@to_addrs) {
@@ -133,14 +141,12 @@
             $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}},
@@ -152,7 +158,12 @@
               $daytime,
               $night );
         }
-      } # if(@packages)
+    } # 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)
 

Index: notify.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Cron/notify.pm,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -w -d -r1.8 -r1.9
--- notify.pm	31 Mar 2009 19:51:54 -0000	1.8
+++ notify.pm	28 Jul 2010 23:16:30 -0000	1.9
@@ -21,6 +21,8 @@
   
   #we're at now now (and later).
   my($time) = $^T;
+  my $conf = new FS::Conf;
+  my $error = '';
 
   my $integer = driver_name =~ /^mysql/ ? 'SIGNED' : 'INTEGER';
 
@@ -101,14 +103,20 @@
       push @cust_pkgs, $cust_pkg[0];
       shift @cust_pkg;
     }
-    my $error = 
-      $cust_main->notify( 'impending_recur_template',
+    my $msgnum = $conf->config('impending_recur_msgnum',$cust_main->agentnum);
+    if ( $msgnum ) {
+      my $msg_template = qsearchs('msg_template', { msgnum => $msgnum });
+      $error = $msg_template->send($cust_main);
+    }
+    else {
+      $error = $cust_main->notify( 'impending_recur_template',
                           'extra_fields' => { 'packages'   => \@packages,
                                               'recurdates' => \@recurdates,
                                               'package'    => $packages[0],
                                               'recurdate'  => $recurdates[0],
                                             },
                         );
+    } #if $msgnum
     warn "Error notifying, custnum ". $cust_main->custnum. ": $error" if $error;
 
     unless ($error) { 



More information about the freeside-commits mailing list