X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fmsg_template.pm;h=4a1e34584c9dc18ad5145a3e1860617ea7fbcb02;hb=30f9308a0b5b482e1d1f11444078309834a66dd6;hp=f0cda41bf119c21c542fdb9305fdb6b01f2b6f5b;hpb=6d14d1fd9ddd1be4b13c05d44bb91bb8fcae519b;p=freeside.git diff --git a/FS/FS/msg_template.pm b/FS/FS/msg_template.pm index f0cda41bf..4a1e34584 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; @@ -175,10 +180,23 @@ 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. + +=item preview + +Set to true when preparing a message for previewing, rather than to actually +send it. This turns off logging. =back @@ -281,23 +299,47 @@ 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; - # warning is not appropriate now that we use these for tickets + 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 $conf = new FS::Conf; + my $from_addr = $self->from_addr; + + 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, 'html_body' => $body, 'text_body' => HTML::FormatText->new(leftmargin => 0, rightmargin => 70 )->format( HTML::TreeBuilder->new_from_content($body) ), + @cust_msg, ); } @@ -319,8 +361,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 @@ -367,6 +408,9 @@ 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( @@ -481,7 +525,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) {