X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fmsg_template.pm;h=65acd9aaca276e66e7bb1ac39574ec2937b1e45f;hb=8f30986e5eb4255a98a52b7a6da3fc5c89694ca2;hp=270eb1f720de2b6c61ee72a623a28821c004a2a3;hpb=794e709ef65adb15d75a02ca9fd53d2a2caa5f8b;p=freeside.git diff --git a/FS/FS/msg_template.pm b/FS/FS/msg_template.pm index 270eb1f72..65acd9aac 100644 --- a/FS/FS/msg_template.pm +++ b/FS/FS/msg_template.pm @@ -7,11 +7,16 @@ use FS::Misc qw( generate_email send_email ); use FS::Conf; use FS::Record qw( qsearch qsearchs ); +use FS::cust_main; +use FS::cust_msg; + use Date::Format qw( time2str ); use HTML::Entities qw( decode_entities encode_entities ) ; use HTML::FormatText; use HTML::TreeBuilder; -use vars '$DEBUG'; +use vars qw( $DEBUG $conf ); + +FS::UID->install_callback( sub { $conf = new FS::Conf; } ); $DEBUG=0; @@ -166,18 +171,27 @@ 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). If the object -is a svc_acct, its cust_pkg will be fetched and used for substitution. +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 from_config + +Configuration option to use as the source address, based on the customer's +agentnum. If unspecified (or the named option is empty), 'invoice_from' +will be used. + +The I field in the template takes precedence over this. + =item to Destination address. The default is to use the customer's -invoicing_list addresses. +invoicing_list addresses. Multiple addresses may be comma-separated. =back @@ -235,7 +249,7 @@ sub prepare { } } } - $_ = encode_entities($_) foreach values(%hash); + $_ = encode_entities($_ || '') foreach values(%hash); ### @@ -280,16 +294,40 @@ sub prepare { # and email ### - my @to = ($opt{'to'}) || $cust_main->invoicing_list_emailonly; - warn "prepared msg_template with no email destination (custnum ". - $cust_main->custnum.")\n" - if !@to; + my @to; + if ( exists($opt{'to'}) ) { + @to = split(/\s*,\s*/, $opt{'to'}); + } + else { + @to = $cust_main->invoicing_list_emailonly; + } + # no warning when preparing with no destination + + my $from_addr = $self->from_addr; - my $conf = new FS::Conf; + if ( !$from_addr ) { + if ( $opt{'from_config'} ) { + $from_addr = scalar( $conf->config($opt{'from_config'}, + $cust_main->agentnum) ); + } + $from_addr ||= scalar( $conf->config('invoice_from', + $cust_main->agentnum) ); + } +# my @cust_msg = (); +# if ( $conf->exists('log_sent_mail') and !$opt{'preview'} ) { +# my $cust_msg = FS::cust_msg->new({ +# 'custnum' => $cust_main->custnum, +# 'msgnum' => $self->msgnum, +# 'status' => 'prepared', +# }); +# $cust_msg->insert; +# @cust_msg = ('cust_msg' => $cust_msg); +# } ( - 'from' => $self->from_addr || - scalar( $conf->config('invoice_from', $cust_main->agentnum) ), + 'custnum' => $cust_main->custnum, + 'msgnum' => $self->msgnum, + 'from' => $from_addr, 'to' => \@to, 'bcc' => $self->bcc_addr || undef, 'subject' => $subject, @@ -317,8 +355,7 @@ sub send { # helper sub for package dates my $ymd = sub { $_[0] ? time2str('%Y-%m-%d', $_[0]) : '' }; -# needed for some things -my $conf = new FS::Conf; +#my $conf = new FS::Conf; #return contexts and fill-in values # If you add anything, be sure to add a description in @@ -349,12 +386,11 @@ sub substitutions { cust_status ucfirst_cust_status cust_statuscolor signupdate dundate - expdate packages recurdates ), - # expdate is a special case - [ signupdate_ymd => sub { time2str('%Y-%m-%d', shift->signupdate) } ], - [ dundate_ymd => sub { time2str('%Y-%m-%d', shift->dundate) } ], + [ expdate => sub { shift->paydate_epoch } ], #compatibility + [ signupdate_ymd => sub { $ymd->(shift->signupdate) } ], + [ dundate_ymd => sub { $ymd->(shift->dundate) } ], [ paydate_my => sub { sprintf('%02d/%04d', shift->paydate_monthyear) } ], [ otaker_first => sub { shift->access_user->first } ], [ otaker_last => sub { shift->access_user->last } ], @@ -365,10 +401,13 @@ sub substitutions { [ company_address => sub { $conf->config('company_address', shift->agentnum) } ], + [ company_phonenum => sub { + $conf->config('company_phonenum', shift->agentnum) + } ], ], # next_bill_date 'cust_pkg' => [qw( - pkgnum pkg pkg_label pkg_label_long + pkgnum pkg_label pkg_label_long location_label status statuscolor @@ -376,6 +415,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')) } ], @@ -400,6 +440,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 @@ -447,7 +518,6 @@ sub _upgrade_data { [ 'warning_msgnum', 'warning_email', 'warning_email-subject', 'warning_email-from', '' ], ); - my $conf = new FS::Conf; my @agentnums = ('', map {$_->agentnum} qsearch('agent', {})); foreach my $agentnum (@agentnums) { foreach (@fixes) {