fix long package locations showing up as line item on typeset invoices, RT#10093
[freeside.git] / FS / FS / msg_template.pm
index 50298d2..270eb1f 100644 (file)
@@ -166,7 +166,18 @@ Customer object (required).
 =item object
 
 Additional context object (currently, can be a cust_main, cust_pkg, 
-cust_bill, svc_acct, cust_pay, or cust_pay_pending object).
+cust_bill, svc_acct, cust_pay, or cust_pay_pending).  If the object 
+is a svc_acct, its cust_pkg will be fetched and used for substitution.
+
+As a special case, this may be an arrayref of two objects.  Both 
+objects will be available for substitution, with their field names 
+prefixed with 'new_' and 'old_' respectively.  This is used in the 
+rt_ticket export when exporting "replace" events.
+
+=item to
+
+Destination address.  The default is to use the customer's 
+invoicing_list addresses.
 
 =back
 
@@ -186,15 +197,37 @@ sub prepare {
   # create substitution table
   ###  
   my %hash;
-  foreach my $obj ($cust_main, $object || ()) {
+  my @objects = ($cust_main);
+  my @prefixes = ('');
+  my $svc;
+  if( ref $object ) {
+    if( ref($object) eq 'ARRAY' ) {
+      # [new, old], for provisioning tickets
+      push @objects, $object->[0], $object->[1];
+      push @prefixes, 'new_', 'old_';
+      $svc = $object->[0] if $object->[0]->isa('FS::svc_Common');
+    }
+    else {
+      push @objects, $object;
+      push @prefixes, '';
+      $svc = $object if $object->isa('FS::svc_Common');
+    }
+  }
+  if( $svc ) {
+    push @objects, $svc->cust_svc->cust_pkg;
+    push @prefixes, '';
+  }
+
+  foreach my $obj (@objects) {
+    my $prefix = shift @prefixes;
     foreach my $name (@{ $subs->{$obj->table} }) {
       if(!ref($name)) {
         # simple case
-        $hash{$name} = $obj->$name();
+        $hash{$prefix.$name} = $obj->$name();
       }
       elsif( ref($name) eq 'ARRAY' ) {
         # [ foo => sub { ... } ]
-        $hash{$name->[0]} = $name->[1]->($obj);
+        $hash{$prefix.($name->[0])} = $name->[1]->($obj);
       }
       else {
         warn "bad msg_template substitution: '$name'\n";
@@ -247,7 +280,7 @@ sub prepare {
   # and email
   ###
 
-  my @to = $cust_main->invoicing_list_emailonly;
+  my @to = ($opt{'to'}) || $cust_main->invoicing_list_emailonly;
   warn "prepared msg_template with no email destination (custnum ".
     $cust_main->custnum.")\n"
     if !@to;
@@ -311,6 +344,7 @@ sub substitutions {
       num_cancelled_pkgs num_ncancelled_pkgs num_pkgs
       classname categoryname
       balance
+      credit_limit
       invoicing_list_emailonly
       cust_status ucfirst_cust_status cust_statuscolor
 
@@ -334,7 +368,7 @@ sub substitutions {
     ],
     # next_bill_date
     'cust_pkg'  => [qw( 
-      pkgnum pkg_label pkg_label_long
+      pkgnum pkg pkg_label pkg_label_long
       location_label
       status statuscolor
     
@@ -360,7 +394,9 @@ sub substitutions {
     
     # for welcome and limit warning messages
     'svc_acct' => [qw(
+      svcnum
       username
+      domain
       ),
       [ password          => sub { shift->getfield('_password') } ],
     ],