add mobile phone to message templates, RT#12427
[freeside.git] / FS / FS / msg_template.pm
index c183477..62bcebc 100644 (file)
@@ -262,6 +262,10 @@ The I<from_addr> field in the template takes precedence over this.
 Destination address.  The default is to use the customer's 
 invoicing_list addresses.  Multiple addresses may be comma-separated.
 
+=item substitutions
+
+A hash reference of additional substitutions
+
 =back
 
 =cut
@@ -324,8 +328,12 @@ sub prepare {
       } 
     } 
   } 
-  $_ = encode_entities($_ || '') foreach values(%hash);
 
+  if ( $opt{substitutions} ) {
+    $hash{$_} = $opt{substitutions}->{$_} foreach keys %{$opt{substitutions}};
+  }
+
+  $_ = encode_entities($_ || '') foreach values(%hash);
 
   ###
   # clean up template
@@ -430,6 +438,20 @@ sub send {
 # helper sub for package dates
 my $ymd = sub { $_[0] ? time2str('%Y-%m-%d', $_[0]) : '' };
 
+# helper sub for usage-related messages
+my $usage_warning = sub {
+  my $svc = shift;
+  foreach my $col (qw(seconds upbytes downbytes totalbytes)) {
+    my $amount = $svc->$col; next if $amount eq '';
+    my $method = $col.'_threshold';
+    my $threshold = $svc->$method; next if $threshold eq '';
+    return [$col, $amount, $threshold] if $amount <= $threshold;
+    # this only returns the first one that's below threshold, if there are 
+    # several.
+  }
+  return ['', '', ''];
+};
+
 #my $conf = new FS::Conf;
 
 #return contexts and fill-in values
@@ -443,14 +465,14 @@ sub substitutions {
       name name_short contact contact_firstlast
       address1 address2 city county state zip
       country
-      daytime night fax
+      daytime night mobile fax
 
       has_ship_address
       ship_last ship_first ship_company
       ship_name ship_name_short ship_contact ship_contact_firstlast
       ship_address1 ship_address2 ship_city ship_county ship_state ship_zip
       ship_country
-      ship_daytime ship_night ship_fax
+      ship_daytime ship_night ship_mobile ship_fax
 
       paymask payname paytype payip
       num_cancelled_pkgs num_ncancelled_pkgs num_pkgs
@@ -514,6 +536,9 @@ sub substitutions {
       domain
       ),
       [ password          => sub { shift->getfield('_password') } ],
+      [ column            => sub { &$usage_warning(shift)->[0] } ],
+      [ amount            => sub { &$usage_warning(shift)->[1] } ],
+      [ threshold         => sub { &$usage_warning(shift)->[2] } ],
     ],
     'svc_domain' => [qw(
       svcnum
@@ -627,8 +652,7 @@ sub _upgrade_data {
         my $new = new FS::msg_template({
           'msgname'   => $oldname,
           'agentnum'  => $agentnum,
-          'from_addr' => ($from && $conf->config($from, $agentnum)) || 
-                         $conf->config('invoice_from', $agentnum),
+          'from_addr' => ($from && $conf->config($from, $agentnum)) || '',
           'bcc_addr'  => ($bcc && $conf->config($from, $agentnum)) || '',
           'subject'   => ($subject && $conf->config($subject, $agentnum)) || '',
           'mime_type' => 'text/html',