eWay self-signup fixes
[freeside.git] / FS / FS / msg_template.pm
index 5582d0f..f0cda41 100644 (file)
@@ -166,7 +166,14 @@ 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, cust_pay, cust_pay_pending, or svc_(acct, phone, broadband, 
+domain) ).  If the object is a svc_*, 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
 
@@ -193,17 +200,24 @@ sub prepare {
   my %hash;
   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;
@@ -268,9 +282,10 @@ sub prepare {
   ###
 
   my @to = ($opt{'to'}) || $cust_main->invoicing_list_emailonly;
-  warn "prepared msg_template with no email destination (custnum ".
-    $cust_main->custnum.")\n"
-    if !@to;
+  #warn "prepared msg_template with no email destination (custnum ".
+  #  $cust_main->custnum.")\n"
+  #  if !@to;
+  #  warning is not appropriate now that we use these for tickets
 
   my $conf = new FS::Conf;
 
@@ -363,6 +378,7 @@ sub substitutions {
       adjourn susp expire 
       labels_short
       ),
+      [ pkg               => sub { shift->part_pkg->pkg } ],
       [ cancel            => sub { shift->getfield('cancel') } ], # grrr...
       [ start_ymd         => sub { $ymd->(shift->getfield('start_date')) } ],
       [ setup_ymd         => sub { $ymd->(shift->getfield('setup')) } ],
@@ -387,6 +403,37 @@ sub substitutions {
       ),
       [ password          => sub { shift->getfield('_password') } ],
     ],
+    'svc_domain' => [qw(
+      svcnum
+      domain
+      ),
+      [ registrar         => sub {
+          my $registrar = qsearchs('registrar', 
+            { registrarnum => shift->registrarnum} );
+          $registrar ? $registrar->registrarname : ''
+        }
+      ],
+      [ catchall          => sub { 
+          my $svc_acct = qsearchs('svc_acct', { svcnum => shift->catchall });
+          $svc_acct ? $svc_acct->email : ''
+        }
+      ],
+    ],
+    'svc_phone' => [qw(
+      svcnum
+      phonenum
+      countrycode
+      domain
+      )
+    ],
+    'svc_broadband' => [qw(
+      svcnum
+      speed_up
+      speed_down
+      ip_addr
+      mac_addr
+      )
+    ],
     # for payment receipts
     'cust_pay' => [qw(
       paynum