[freeside-commits] branch master updated. c34a48fd2107adbc7ea08cf3aae007d70ec60b61

Jonathan Prykop jonathan at 420.am
Wed Sep 23 21:57:20 PDT 2015


The branch, master has been updated
       via  c34a48fd2107adbc7ea08cf3aae007d70ec60b61 (commit)
      from  1c83c4c02ba6d35ffbabe71bfd4cf6e70afbb894 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit c34a48fd2107adbc7ea08cf3aae007d70ec60b61
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Wed Sep 23 23:56:32 2015 -0500

    RT#37908: Convert existing email-sending code to use common interface [removed template confs]

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 5c4774a..db7dbd0 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -2355,13 +2355,6 @@ and customer address. Include units.',
   },
 
   {
-    'key'         => 'declinetemplate',
-    'section'     => 'deprecated',
-    'description' => 'Template file for credit card and electronic check decline emails.',
-    'type'        => 'textarea',
-  },
-
-  {
     'key'         => 'emaildecline',
     'section'     => 'notification',
     'description' => 'Enable emailing of credit card and electronic check decline notices.',
@@ -2385,20 +2378,6 @@ and customer address. Include units.',
   },
 
   {
-    'key'         => 'cancelmessage',
-    'section'     => 'deprecated',
-    'description' => 'Template file for cancellation emails.',
-    'type'        => 'textarea',
-  },
-
-  {
-    'key'         => 'cancelsubject',
-    'section'     => 'deprecated',
-    'description' => 'Subject line for cancellation emails.',
-    'type'        => 'text',
-  },
-
-  {
     'key'         => 'emailcancel',
     'section'     => 'notification',
     'description' => 'Enable emailing of cancellation notices.  Make sure to select the template in the cancel_msgnum option.',
@@ -2522,86 +2501,17 @@ and customer address. Include units.',
   },
 
   {
-    'key'         => 'welcome_email',
-    'section'     => 'deprecated',
-    'description' => 'Template file for welcome email.  Welcome emails are sent to the customer email invoice destination(s) each time a svc_acct record is created.',
-    'type'        => 'textarea',
-    'per_agent'   => 1,
-  },
-
-  {
-    'key'         => 'welcome_email-from',
-    'section'     => 'deprecated',
-    'description' => 'From: address header for welcome email',
-    'type'        => 'text',
-    'per_agent'   => 1,
-  },
-
-  {
-    'key'         => 'welcome_email-subject',
-    'section'     => 'deprecated',
-    'description' => 'Subject: header for welcome email',
-    'type'        => 'text',
-    'per_agent'   => 1,
-  },
-  
-  {
-    'key'         => 'welcome_email-mimetype',
-    'section'     => 'deprecated',
-    'description' => 'MIME type for welcome email',
-    'type'        => 'select',
-    'select_enum' => [ 'text/plain', 'text/html' ],
-    'per_agent'   => 1,
-  },
-
-  {
     'key'         => 'welcome_letter',
     'section'     => '',
     'description' => 'Optional LaTex template file for a printed welcome letter.  A welcome letter is printed the first time a cust_pkg record is created.  See the <a href="http://search.cpan.org/dist/Text-Template/lib/Text/Template.pm">Text::Template</a> documentation and the billing documentation for details on the template substitution language.  A variable exists for each fieldname in the customer record (<code>$first, $last, etc</code>).  The following additional variables are available<ul><li><code>$payby</code> - a friendler represenation of the field<li><code>$payinfo</code> - the masked payment information<li><code>$expdate</code> - the time at which the payment method expires (a UNIX timestamp)<li><code>$returnaddress</code> - the invoice return address for this customer\'s agent</ul>',
     'type'        => 'textarea',
   },
 
-#  {
-#    'key'         => 'warning_msgnum',
-#    'section'     => 'notification',
-#    'description' => 'Template to use for warning messages, sent to the customer email invoice destination(s) when a svc_acct record has its usage drop below a threshold.',
-#    %msg_template_options,
-#  },
-
-  {
-    'key'         => 'warning_email',
-    'section'     => 'notification',
-    'description' => 'Template file for warning email.  Warning emails are sent to the customer email invoice destination(s) each time a svc_acct record has its usage drop below a threshold or 0.  See the <a href="http://search.cpan.org/dist/Text-Template/lib/Text/Template.pm">Text::Template</a> documentation for details on the template substitution language.  The following variables are available<ul><li><code>$username</code> <li><code>$password</code> <li><code>$first</code> <li><code>$last</code> <li><code>$pkg</code> <li><code>$column</code> <li><code>$amount</code> <li><code>$threshold</code></ul>',
-    'type'        => 'textarea',
-  },
-
-  {
-    'key'         => 'warning_email-from',
-    'section'     => 'notification',
-    'description' => 'From: address header for warning email',
-    'type'        => 'text',
-  },
-
   {
-    'key'         => 'warning_email-cc',
+    'key'         => 'threshold_warning_msgnum',
     'section'     => 'notification',
-    'description' => 'Additional recipient(s) (comma separated) for warning email when remaining usage reaches zero.',
-    'type'        => 'text',
-  },
-
-  {
-    'key'         => 'warning_email-subject',
-    'section'     => 'notification',
-    'description' => 'Subject: header for warning email',
-    'type'        => 'text',
-  },
-  
-  {
-    'key'         => 'warning_email-mimetype',
-    'section'     => 'notification',
-    'description' => 'MIME type for warning email',
-    'type'        => 'select',
-    'select_enum' => [ 'text/plain', 'text/html' ],
+    'description' => 'Template to use for warning messages sent to the customer email invoice destination(s) when a svc_acct record has its usage drop below a threshold.  Extra substitutions available: $column, $amount, $threshold',
+    %msg_template_options,
   },
 
   {
@@ -4065,14 +3975,6 @@ and customer address. Include units.',
   },
 
   {
-    'key'         => 'impending_recur_template',
-    'section'     => 'deprecated',
-    'description' => 'Template file for alerts about looming first time recurrant billing.  See the <a href="http://search.cpan.org/dist/Text-Template/lib/Text/Template.pm">Text::Template</a> documentation for details on the template substitition language.  Also see packages with a <a href="../browse/part_pkg.cgi">flat price plan</a>  The following variables are available<ul><li><code>$packages</code> allowing <code>$packages->[0]</code> thru <code>$packages->[n]</code> <li><code>$package</code> the first package, same as <code>$packages->[0]</code> <li><code>$recurdates</code> allowing <code>$recurdates->[0]</code> thru <code>$recurdates->[n]</code> <li><code>$recurdate</code> the first recurdate, same as <code>$recurdate->[0]</code> <li><code>$first</code> <li><code>$last</code></ul>',
-# <li><code>$payby</code> <li><code>$expdate</code> most likely only confuse
-    'type'        => 'textarea',
-  },
-
-  {
     'key'         => 'logo.png',
     'section'     => 'UI',  #'invoicing' ?
     'description' => 'Company logo for HTML invoices and the backoffice interface, in PNG format.  Suggested size somewhere near 92x62.',
diff --git a/FS/FS/Cron/notify.pm b/FS/FS/Cron/notify.pm
index 6d70654..34977c8 100644
--- a/FS/FS/Cron/notify.pm
+++ b/FS/FS/Cron/notify.pm
@@ -111,15 +111,6 @@ END
       $error = $msg_template->send('cust_main' => $cust_main,
                                    'object'    => $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) { 
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index c636408..6afbd1c 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -32,7 +32,7 @@ use Locale::Country;
 use FS::UID qw( dbh driver_name );
 use FS::Record qw( qsearchs qsearch dbdef regexp_sql );
 use FS::Cursor;
-use FS::Misc qw( generate_email send_email generate_ps do_print money_pretty );
+use FS::Misc qw( generate_ps do_print money_pretty );
 use FS::Msgcat qw(gettext);
 use FS::CurrentUser;
 use FS::TicketSystem;
@@ -4574,102 +4574,102 @@ sub search {
 
 =over 4
 
-=item notify CUSTOMER_OBJECT TEMPLATE_NAME OPTIONS
+#=item notify CUSTOMER_OBJECT TEMPLATE_NAME OPTIONS
 
-Deprecated.  Use event notification and message templates 
-(L<FS::msg_template>) instead.
+#Deprecated.  Use event notification and message templates 
+#(L<FS::msg_template>) instead.
 
-Sends a templated email notification to the customer (see L<Text::Template>).
+#Sends a templated email notification to the customer (see L<Text::Template>).
 
-OPTIONS is a hash and may include
-
-I<from> - the email sender (default is invoice_from)
+#OPTIONS is a hash and may include
 
-I<to> - comma-separated scalar or arrayref of recipients 
-   (default is invoicing_list)
+#I<from> - the email sender (default is invoice_from)
 
-I<subject> - The subject line of the sent email notification
-   (default is "Notice from company_name")
+#I<to> - comma-separated scalar or arrayref of recipients 
+#   (default is invoicing_list)
 
-I<extra_fields> - a hashref of name/value pairs which will be substituted
-   into the template
+#I<subject> - The subject line of the sent email notification
+#   (default is "Notice from company_name")
 
-The following variables are vavailable in the template.
+#I<extra_fields> - a hashref of name/value pairs which will be substituted
+#   into the template
 
-I<$first> - the customer first name
-I<$last> - the customer last name
-I<$company> - the customer company
-I<$payby> - a description of the method of payment for the customer
-            # would be nice to use FS::payby::shortname
-I<$payinfo> - the account information used to collect for this customer
-I<$expdate> - the expiration of the customer payment in seconds from epoch
-
-=cut
-
-sub notify {
-  my ($self, $template, %options) = @_;
+#The following variables are vavailable in the template.
 
-  return unless $conf->exists($template);
+#I<$first> - the customer first name
+#I<$last> - the customer last name
+#I<$company> - the customer company
+#I<$payby> - a description of the method of payment for the customer
+#            # would be nice to use FS::payby::shortname
+#I<$payinfo> - the account information used to collect for this customer
+#I<$expdate> - the expiration of the customer payment in seconds from epoch
 
-  my $from = $conf->invoice_from_full($self->agentnum)
-    if $conf->exists('invoice_from', $self->agentnum);
-  $from = $options{from} if exists($options{from});
-
-  my $to = join(',', $self->invoicing_list_emailonly);
-  $to = $options{to} if exists($options{to});
-  
-  my $subject = "Notice from " . $conf->config('company_name', $self->agentnum)
-    if $conf->exists('company_name', $self->agentnum);
-  $subject = $options{subject} if exists($options{subject});
-
-  my $notify_template = new Text::Template (TYPE => 'ARRAY',
-                                            SOURCE => [ map "$_\n",
-                                              $conf->config($template)]
-                                           )
-    or die "can't create new Text::Template object: Text::Template::ERROR";
-  $notify_template->compile()
-    or die "can't compile template: Text::Template::ERROR";
-
-  $FS::notify_template::_template::company_name =
-    $conf->config('company_name', $self->agentnum);
-  $FS::notify_template::_template::company_address =
-    join("\n", $conf->config('company_address', $self->agentnum) ). "\n";
-
-  my $paydate = $self->paydate || '2037-12-31';
-  $FS::notify_template::_template::first = $self->first;
-  $FS::notify_template::_template::last = $self->last;
-  $FS::notify_template::_template::company = $self->company;
-  $FS::notify_template::_template::payinfo = $self->mask_payinfo;
-  my $payby = $self->payby;
-  my ($payyear,$paymonth,$payday) = split (/-/,$paydate);
-  my $expire_time = timelocal(0,0,0,$payday,--$paymonth,$payyear);
-
-  #credit cards expire at the end of the month/year of their exp date
-  if ($payby eq 'CARD' || $payby eq 'DCRD') {
-    $FS::notify_template::_template::payby = 'credit card';
-    ($paymonth < 11) ? $paymonth++ : ($paymonth=0, $payyear++);
-    $expire_time = timelocal(0,0,0,$payday,$paymonth,$payyear);
-    $expire_time--;
-  }elsif ($payby eq 'COMP') {
-    $FS::notify_template::_template::payby = 'complimentary account';
-  }else{
-    $FS::notify_template::_template::payby = 'current method';
-  }
-  $FS::notify_template::_template::expdate = $expire_time;
-
-  for (keys %{$options{extra_fields}}){
-    no strict "refs";
-    ${"FS::notify_template::_template::$_"} = $options{extra_fields}->{$_};
-  }
+#=cut
 
-  send_email(from => $from,
-             to => $to,
-             subject => $subject,
-             body => $notify_template->fill_in( PACKAGE =>
-                                                'FS::notify_template::_template'                                              ),
-            );
+#sub notify {
+#  my ($self, $template, %options) = @_;
+
+#  return unless $conf->exists($template);
+
+#  my $from = $conf->invoice_from_full($self->agentnum)
+#    if $conf->exists('invoice_from', $self->agentnum);
+#  $from = $options{from} if exists($options{from});
+
+#  my $to = join(',', $self->invoicing_list_emailonly);
+#  $to = $options{to} if exists($options{to});
+#  
+#  my $subject = "Notice from " . $conf->config('company_name', $self->agentnum)
+#    if $conf->exists('company_name', $self->agentnum);
+#  $subject = $options{subject} if exists($options{subject});
+
+#  my $notify_template = new Text::Template (TYPE => 'ARRAY',
+#                                            SOURCE => [ map "$_\n",
+#                                              $conf->config($template)]
+#                                           )
+#    or die "can't create new Text::Template object: Text::Template::ERROR";
+#  $notify_template->compile()
+#    or die "can't compile template: Text::Template::ERROR";
+
+#  $FS::notify_template::_template::company_name =
+#    $conf->config('company_name', $self->agentnum);
+#  $FS::notify_template::_template::company_address =
+#    join("\n", $conf->config('company_address', $self->agentnum) ). "\n";
+
+#  my $paydate = $self->paydate || '2037-12-31';
+#  $FS::notify_template::_template::first = $self->first;
+#  $FS::notify_template::_template::last = $self->last;
+#  $FS::notify_template::_template::company = $self->company;
+#  $FS::notify_template::_template::payinfo = $self->mask_payinfo;
+#  my $payby = $self->payby;
+#  my ($payyear,$paymonth,$payday) = split (/-/,$paydate);
+#  my $expire_time = timelocal(0,0,0,$payday,--$paymonth,$payyear);
+
+#  #credit cards expire at the end of the month/year of their exp date
+#  if ($payby eq 'CARD' || $payby eq 'DCRD') {
+#    $FS::notify_template::_template::payby = 'credit card';
+#    ($paymonth < 11) ? $paymonth++ : ($paymonth=0, $payyear++);
+#    $expire_time = timelocal(0,0,0,$payday,$paymonth,$payyear);
+#    $expire_time--;
+#  }elsif ($payby eq 'COMP') {
+#    $FS::notify_template::_template::payby = 'complimentary account';
+#  }else{
+#    $FS::notify_template::_template::payby = 'current method';
+#  }
+#  $FS::notify_template::_template::expdate = $expire_time;
+
+#  for (keys %{$options{extra_fields}}){
+#    no strict "refs";
+#    ${"FS::notify_template::_template::$_"} = $options{extra_fields}->{$_};
+#  }
+
+#  send_email(from => $from,
+#             to => $to,
+#             subject => $subject,
+#             body => $notify_template->fill_in( PACKAGE =>
+#                                                'FS::notify_template::_template'                                              ),
+#            );
 
-}
+#}
 
 =item generate_letter CUSTOMER_OBJECT TEMPLATE_NAME OPTIONS
 
diff --git a/FS/FS/cust_main/Billing_Realtime.pm b/FS/FS/cust_main/Billing_Realtime.pm
index fda3ae0..c6b3b31 100644
--- a/FS/FS/cust_main/Billing_Realtime.pm
+++ b/FS/FS/cust_main/Billing_Realtime.pm
@@ -8,7 +8,6 @@ use Data::Dumper;
 use Business::CreditCard 0.28;
 use FS::UID qw( dbh );
 use FS::Record qw( qsearch qsearchs );
-use FS::Misc qw( send_email );
 use FS::payby;
 use FS::cust_pay;
 use FS::cust_pay_pending;
@@ -1121,31 +1120,7 @@ sub _realtime_bop_result {
         $error = $msg_template->send( 'cust_main' => $self,
                                       'object'    => $cust_pay_pending );
       }
-      else { #!$msgnum
-
-        my @templ = $conf->config('declinetemplate');
-        my $template = new Text::Template (
-          TYPE   => 'ARRAY',
-          SOURCE => [ map "$_\n", @templ ],
-        ) or return "($perror) can't create template: $Text::Template::ERROR";
-        $template->compile()
-          or return "($perror) can't compile template: $Text::Template::ERROR";
-
-        my $templ_hash = {
-          'company_name'    =>
-            scalar( $conf->config('company_name', $self->agentnum ) ),
-          'company_address' =>
-            join("\n", $conf->config('company_address', $self->agentnum ) ),
-          'error'           => $transaction->error_message,
-        };
-
-        my $error = send_email(
-          'from'    => $conf->invoice_from_full( $self->agentnum ),
-          'to'      => [ grep { $_ ne 'POST' } $self->invoicing_list ],
-          'subject' => 'Your payment could not be processed',
-          'body'    => [ $template->fill_in(HASH => $templ_hash) ],
-        );
-      }
+
 
       $perror .= " (also received error sending decline notification: $error)"
         if $error;
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 0ef7aa0..279205b 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -13,7 +13,6 @@ use Tie::IxHash;
 use Time::Local qw( timelocal timelocal_nocheck );
 use MIME::Entity;
 use FS::UID qw( dbh driver_name );
-use FS::Misc qw( send_email );
 use FS::Record qw( qsearch qsearchs fields );
 use FS::CurrentUser;
 use FS::cust_svc;
@@ -1057,16 +1056,6 @@ sub cancel {
       $error = $msg_template->send( 'cust_main' => $self->cust_main,
                                     'object'    => $self );
     }
-    else {
-      $error = send_email(
-        'from'    => $conf->invoice_from_full( $self->cust_main->agentnum ),
-        'to'      => \@invoicing_list,
-        'subject' => ( $conf->config('cancelsubject') || 'Cancellation Notice' ),
-        'body'    => [ map "$_\n", $conf->config('cancelmessage') ],
-        'custnum' => $self->custnum,
-        'msgtype' => '', #admin?
-      );
-    }
     #should this do something on errors?
   }
 
diff --git a/FS/FS/msg_template.pm b/FS/FS/msg_template.pm
index 4c2ac4b..4940388 100644
--- a/FS/FS/msg_template.pm
+++ b/FS/FS/msg_template.pm
@@ -94,6 +94,7 @@ sub _rebless {
   my $class = 'FS::msg_template::' . $self->msgclass;
   eval "use $class;";
   bless($self, $class) unless $@;
+  warn "Error loading msg_template msgclass: " . $@ if $@; #or die?
 
   # merge in the extension fields (but let fields in $self override them)
   # except don't ever override the extension's primary key, it's immutable
@@ -657,20 +658,22 @@ sub _upgrade_data {
     [ 'decline_msgnum',  'declinetemplate',    '',               '', '' ],
     [ 'impending_recur_msgnum', 'impending_recur_template', '',  '', 'impending_recur_bcc' ],
     [ 'payment_receipt_msgnum', 'payment_receipt_email', '',     '', '' ],
-    [ 'welcome_msgnum',  'welcome_email',      'welcome_email-subject', 'welcome_email-from', '' ],
-    [ 'warning_msgnum',  'warning_email',      'warning_email-subject', 'warning_email-from', '' ],
+    [ 'welcome_msgnum',  'welcome_email',      'welcome_email-subject', 'welcome_email-from', '', 'welcome_email-mimetype' ],
+    [ 'threshold_warning_msgnum',  'warning_email',      'warning_email-subject', 'warning_email-from', 'warning_email-cc', 'warning_email-mimetype' ],
   );
  
   my @agentnums = ('', map {$_->agentnum} qsearch('agent', {}));
   foreach my $agentnum (@agentnums) {
     foreach (@fixes) {
-      my ($newname, $oldname, $subject, $from, $bcc) = @$_;
+      my ($newname, $oldname, $subject, $from, $bcc, $mimetype) = @$_;
+      
       if ($conf->exists($oldname, $agentnum)) {
         my $new = new FS::msg_template({
+          'msgclass'  => 'email',
           'msgname'   => $oldname,
           'agentnum'  => $agentnum,
           'from_addr' => ($from && $conf->config($from, $agentnum)) || '',
-          'bcc_addr'  => ($bcc && $conf->config($from, $agentnum)) || '',
+          'bcc_addr'  => ($bcc && $conf->config($bcc, $agentnum)) || '',
           'subject'   => ($subject && $conf->config($subject, $agentnum)) || '',
           'mime_type' => 'text/html',
           'body'      => join('<BR>',$conf->config($oldname, $agentnum)),
@@ -681,6 +684,8 @@ sub _upgrade_data {
         $conf->delete($oldname, $agentnum);
         $conf->delete($from, $agentnum) if $from;
         $conf->delete($subject, $agentnum) if $subject;
+        $conf->delete($bcc, $agentnum) if $bcc;
+        $conf->delete($mimetype, $agentnum) if $mimetype;
       }
     }
 
diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm
index 0181b1e..f307033 100644
--- a/FS/FS/svc_acct.pm
+++ b/FS/FS/svc_acct.pm
@@ -17,8 +17,7 @@ use vars qw( $DEBUG $me $conf $skip_fuzzyfiles
              $username_slash $username_equals $username_pound
              $username_exclamation
              $password_noampersand $password_noexclamation
-             $warning_template $warning_from $warning_subject $warning_mimetype
-             $warning_cc
+             $warning_msgnum
              $smtpmachine
              $radius_password $radius_ip
              $dirhash
@@ -90,22 +89,7 @@ FS::UID->install_callback( sub {
   $password_noampersand = $conf->exists('password-noexclamation');
   $password_noexclamation = $conf->exists('password-noexclamation');
   $dirhash = $conf->config('dirhash') || 0;
-  if ( $conf->exists('warning_email') ) {
-    $warning_template = new Text::Template (
-      TYPE   => 'ARRAY',
-      SOURCE => [ map "$_\n", $conf->config('warning_email') ]
-    ) or warn "can't create warning email template: $Text::Template::ERROR";
-    $warning_from = $conf->config('warning_email-from'); # || 'your-isp-is-dum'
-    $warning_subject = $conf->config('warning_email-subject') || 'Warning';
-    $warning_mimetype = $conf->config('warning_email-mimetype') || 'text/plain';
-    $warning_cc = $conf->config('warning_email-cc');
-  } else {
-    $warning_template = '';
-    $warning_from = '';
-    $warning_subject = '';
-    $warning_mimetype = '';
-    $warning_cc = '';
-  }
+  $warning_msgnum = $conf->config('threshold_warning_msgnum');
   $smtpmachine = $conf->config('smtpmachine');
   $radius_password = $conf->config('radius-password') || 'Password';
   $radius_ip = $conf->config('radius-ip') || 'Framed-IP-Address';
@@ -737,83 +721,8 @@ sub insert {
           my $msg_template = qsearchs('msg_template', { msgnum => $msgnum });
           $error = $msg_template->send('cust_main' => $cust_main,
                                        'object'    => $self);
+          #should this do something on error?
         }
-        else { #!$msgnum
-          my ($to,$welcome_template,$welcome_from,$welcome_subject,$welcome_subject_template,$welcome_mimetype)
-            = ('','','','','','');
-
-          if ( $conf->exists('welcome_email', $agentnum) ) {
-            $welcome_template = new Text::Template (
-              TYPE   => 'ARRAY',
-              SOURCE => [ map "$_\n", $conf->config('welcome_email', $agentnum) ]
-            ) or warn "can't create welcome email template: $Text::Template::ERROR";
-            $welcome_from = $conf->config('welcome_email-from', $agentnum);
-              # || 'your-isp-is-dum'
-            $welcome_subject = $conf->config('welcome_email-subject', $agentnum)
-              || 'Welcome';
-            $welcome_subject_template = new Text::Template (
-              TYPE   => 'STRING',
-              SOURCE => $welcome_subject,
-            ) or warn "can't create welcome email subject template: $Text::Template::ERROR";
-            $welcome_mimetype = $conf->config('welcome_email-mimetype', $agentnum)
-              || 'text/plain';
-          }
-          if ( $welcome_template ) {
-            my $to = join(', ', grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list );
-            if ( $to ) {
-
-              my %hash = (
-                           'custnum'  => $self->custnum,
-                           'username' => $self->username,
-                           'password' => $self->_password,
-                           'first'    => $cust_main->first,
-                           'last'     => $cust_main->getfield('last'),
-                           'pkg'      => $cust_pkg->part_pkg->pkg,
-                         );
-              my $wqueue = new FS::queue {
-                'svcnum' => $self->svcnum,
-                'job'    => 'FS::svc_acct::send_email'
-              };
-              my $error = $wqueue->insert(
-                'to'       => $to,
-                'from'     => $welcome_from,
-                'subject'  => $welcome_subject_template->fill_in( HASH => \%hash, ),
-                'mimetype' => $welcome_mimetype,
-                'body'     => $welcome_template->fill_in( HASH => \%hash, ),
-              );
-              if ( $error ) {
-                $dbh->rollback if $oldAutoCommit;
-                return "error queuing welcome email: $error";
-              }
-
-              if ( $options{'depend_jobnum'} ) {
-                warn "$me depend_jobnum found; adding to welcome email dependancies"
-                  if $DEBUG;
-                if ( ref($options{'depend_jobnum'}) ) {
-                  warn "$me adding jobs ". join(', ', @{$options{'depend_jobnum'}} ).
-                       "to welcome email dependancies"
-                    if $DEBUG;
-                  push @jobnums, @{ $options{'depend_jobnum'} };
-                } else {
-                  warn "$me adding job $options{'depend_jobnum'} ".
-                       "to welcome email dependancies"
-                    if $DEBUG;
-                  push @jobnums, $options{'depend_jobnum'};
-                }
-              }
-
-              foreach my $jobnum ( @jobnums ) {
-                my $error = $wqueue->depend_insert($jobnum);
-                if ( $error ) {
-                  $dbh->rollback if $oldAutoCommit;
-                  return "error queuing welcome email job dependancy: $error";
-                }
-              }
-
-            }
-
-          } # if $welcome_template
-        } # if !$msgnum
     }
   } # if $cust_pkg
 
@@ -2119,23 +2028,17 @@ sub _op_usage {
     }
   }
 
-  if ($warning_template && &{$op2warncondition{$op}}($self, $column, $amount)) {
+  if ($warning_msgnum && &{$op2warncondition{$op}}($self, $column, $amount)) {
     my $wqueue = new FS::queue {
       'svcnum' => $self->svcnum,
       'job'    => 'FS::svc_acct::reached_threshold',
     };
 
-    my $to = '';
-    if ($op eq '-'){
-      $to = $warning_cc if &{$op2condition{$op}}($self, $column, $amount);
-    }
-
     # x_threshold race
     my $error = $wqueue->insert(
       'svcnum' => $self->svcnum,
       'op'     => $op,
-      'column' => $column,
-      'to'     => $to,
+      'column' => $column
     );
     if ( $error ) {
       $dbh->rollback if $oldAutoCommit;
@@ -2834,32 +2737,6 @@ sub _search_svc {
 
 =over 4
 
-=item send_email
-
-This is the FS::svc_acct job-queue-able version.  It still uses
-FS::Misc::send_email under-the-hood.
-
-=cut
-
-sub send_email {
-  my %opt = @_;
-
-  eval "use FS::Misc qw(send_email)";
-  die $@ if $@;
-
-  $opt{mimetype} ||= 'text/plain';
-  $opt{mimetype} .= '; charset="iso-8859-1"' unless $opt{mimetype} =~ /charset/;
-
-  my $error = send_email(
-    'from'         => $opt{from},
-    'to'           => $opt{to},
-    'subject'      => $opt{subject},
-    'content-type' => $opt{mimetype},
-    'body'         => [ map "$_\n", split("\n", $opt{body}) ],
-  );
-  die $error if $error;
-}
-
 =item check_and_rebuild_fuzzyfiles
 
 =cut
@@ -2973,46 +2850,33 @@ sub reached_threshold {
     my $error = $svc_acct->replace;
     die $error if $error; # email next time, i guess
 
-    if ( $warning_template ) {
-      eval "use FS::Misc qw(send_email)";
-      die $@ if $@;
+    if ( $warning_msgnum ) {
 
-      my $cust_pkg  = $svc_acct->cust_svc->cust_pkg;
-      my $cust_main = $cust_pkg->cust_main;
+      my $msg_template = qsearchs('msg_template',{ msgnum => $warning_msgnum });
+      die "Could not load template for threshold_warning_msgnum ($warning_msgnum)" unless $msg_template;
 
-      my $to = join(', ', grep { $_ !~ /^(POST|FAX)$/ } 
-                               $cust_main->invoicing_list,
-                               ($opt{'to'} ? $opt{'to'} : ())
-                   );
-
-      my $mimetype = $warning_mimetype;
-      $mimetype .= '; charset="iso-8859-1"' unless $opt{mimetype} =~ /charset/;
-
-      my $body       =  $warning_template->fill_in( HASH => {
-                        'custnum'   => $cust_main->custnum,
-                        'username'  => $svc_acct->username,
-                        'password'  => $svc_acct->_password,
-                        'first'     => $cust_main->first,
-                        'last'      => $cust_main->getfield('last'),
-                        'pkg'       => $cust_pkg->part_pkg->pkg,
-                        'column'    => $opt{'column'},
-                        'amount'    => $opt{'column'} =~/bytes/
-                                       ? FS::UI::bytecount::display_bytecount($svc_acct->getfield($opt{'column'}))
-                                       : $svc_acct->getfield($opt{'column'}),
-                        'threshold' => $opt{'column'} =~/bytes/
-                                       ? FS::UI::bytecount::display_bytecount($threshold)
-                                       : $threshold,
-                      } );
-
-
-      my $error = send_email(
-        'from'         => $warning_from,
-        'to'           => $to,
-        'subject'      => $warning_subject,
-        'content-type' => $mimetype,
-        'body'         => [ map "$_\n", split("\n", $body) ],
+      my $cust_main = $svc_acct->cust_svc->cust_pkg->cust_main;
+
+      my $to = join(', ', $cust_main->invoicing_list_emailonly );
+
+      my $error = $msg_template->send(
+        cust_main     => $cust_main,
+        object        => $svc_acct,
+        to            => $to,
+        substitutions => {
+          # have to override these, because we changed threshold above
+          'column'    => $opt{'column'},
+          'amount'    => $opt{'column'} =~/bytes/
+                         ? FS::UI::bytecount::display_bytecount($svc_acct->getfield($opt{'column'}))
+                         : $svc_acct->getfield($opt{'column'}),
+          'threshold' => $opt{'column'} =~/bytes/
+                         ? FS::UI::bytecount::display_bytecount($threshold)
+                         : $threshold,
+        },
       );
-      die $error if $error;
+
+      die "Error sending threshold warning email: $error" if $error;
+
     }
   }else{
     die "unknown op: " . $opt{'op'};

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Conf.pm                       |  104 +------------------
 FS/FS/Cron/notify.pm                |    9 --
 FS/FS/cust_main.pm                  |  170 +++++++++++++++---------------
 FS/FS/cust_main/Billing_Realtime.pm |   27 +----
 FS/FS/cust_pkg.pm                   |   11 --
 FS/FS/msg_template.pm               |   13 ++-
 FS/FS/svc_acct.pm                   |  194 ++++++-----------------------------
 7 files changed, 127 insertions(+), 401 deletions(-)




More information about the freeside-commits mailing list