X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fmsg_template.pm;h=270eb1f720de2b6c61ee72a623a28821c004a2a3;hb=4ad8b72c0dde10d4907298277181ddfaa99dafb6;hp=7321351d3f14e18e291b07e22e9a09e69664378b;hpb=523edd344793bba1c53a622dcc618e74a962bcb6;p=freeside.git diff --git a/FS/FS/msg_template.pm b/FS/FS/msg_template.pm index 7321351d3..270eb1f72 100644 --- a/FS/FS/msg_template.pm +++ b/FS/FS/msg_template.pm @@ -166,7 +166,13 @@ 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 @@ -191,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"; @@ -340,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 @@ -366,7 +394,9 @@ sub substitutions { # for welcome and limit warning messages 'svc_acct' => [qw( + svcnum username + domain ), [ password => sub { shift->getfield('_password') } ], ],