credit card expiration event, #13202
[freeside.git] / FS / FS / msg_template.pm
index 73284d1..65acd9a 100644 (file)
@@ -7,11 +7,16 @@ use FS::Misc qw( generate_email send_email );
 use FS::Conf;
 use FS::Record qw( qsearch qsearchs );
 
+use FS::cust_main;
+use FS::cust_msg;
+
 use Date::Format qw( time2str );
 use HTML::Entities qw( decode_entities encode_entities ) ;
 use HTML::FormatText;
 use HTML::TreeBuilder;
-use vars '$DEBUG';
+use vars qw( $DEBUG $conf );
+
+FS::UID->install_callback( sub { $conf = new FS::Conf; } );
 
 $DEBUG=0;
 
@@ -244,7 +249,7 @@ sub prepare {
       } 
     } 
   } 
-  $_ = encode_entities($_) foreach values(%hash);
+  $_ = encode_entities($_ || '') foreach values(%hash);
 
 
   ###
@@ -298,7 +303,6 @@ sub prepare {
   }
   # no warning when preparing with no destination
 
-  my $conf = new FS::Conf;
   my $from_addr = $self->from_addr;
 
   if ( !$from_addr ) {
@@ -309,8 +313,20 @@ sub prepare {
     $from_addr ||= scalar( $conf->config('invoice_from',
                                          $cust_main->agentnum) );
   }
+#  my @cust_msg = ();
+#  if ( $conf->exists('log_sent_mail') and !$opt{'preview'} ) {
+#    my $cust_msg = FS::cust_msg->new({
+#        'custnum' => $cust_main->custnum,
+#        'msgnum'  => $self->msgnum,
+#        'status'  => 'prepared',
+#      });
+#    $cust_msg->insert;
+#    @cust_msg = ('cust_msg' => $cust_msg);
+#  }
 
   (
+    'custnum' => $cust_main->custnum,
+    'msgnum'  => $self->msgnum,
     'from' => $from_addr,
     'to'   => \@to,
     'bcc'  => $self->bcc_addr || undef,
@@ -339,8 +355,7 @@ sub send {
 # helper sub for package dates
 my $ymd = sub { $_[0] ? time2str('%Y-%m-%d', $_[0]) : '' };
 
-# needed for some things
-my $conf = new FS::Conf;
+#my $conf = new FS::Conf;
 
 #return contexts and fill-in values
 # If you add anything, be sure to add a description in 
@@ -371,12 +386,11 @@ sub substitutions {
       cust_status ucfirst_cust_status cust_statuscolor
 
       signupdate dundate
-      expdate
       packages recurdates
       ),
-      # expdate is a special case
-      [ signupdate_ymd    => sub { time2str('%Y-%m-%d', shift->signupdate) } ],
-      [ dundate_ymd       => sub { time2str('%Y-%m-%d', shift->dundate) } ],
+      [ expdate           => sub { shift->paydate_epoch } ], #compatibility
+      [ signupdate_ymd    => sub { $ymd->(shift->signupdate) } ],
+      [ dundate_ymd       => sub { $ymd->(shift->dundate) } ],
       [ paydate_my        => sub { sprintf('%02d/%04d', shift->paydate_monthyear) } ],
       [ otaker_first      => sub { shift->access_user->first } ],
       [ otaker_last       => sub { shift->access_user->last } ],
@@ -504,7 +518,6 @@ sub _upgrade_data {
     [ 'warning_msgnum',  'warning_email',      'warning_email-subject', 'warning_email-from', '' ],
   );
  
-  my $conf = new FS::Conf;
   my @agentnums = ('', map {$_->agentnum} qsearch('agent', {}));
   foreach my $agentnum (@agentnums) {
     foreach (@fixes) {