diff options
author | mark <mark> | 2011-07-01 05:33:55 +0000 |
---|---|---|
committer | mark <mark> | 2011-07-01 05:33:55 +0000 |
commit | 4b80fe118da16b21603fcdbd090bc03d8fbf0578 (patch) | |
tree | fe5960c7c4ad7514dc46bd37e8e09cb86f266845 /FS | |
parent | 2c69cd41531a493c45ea72da3aa379fcc9f70aa9 (diff) |
send email from customer view, #13444
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Misc.pm | 58 | ||||
-rw-r--r-- | FS/FS/cust_main/Search.pm | 27 | ||||
-rw-r--r-- | FS/FS/cust_main_Mixin.pm | 10 | ||||
-rw-r--r-- | FS/FS/msg_template.pm | 26 |
4 files changed, 67 insertions, 54 deletions
diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm index d5f02de1d..3b0de3dc3 100644 --- a/FS/FS/Misc.pm +++ b/FS/FS/Misc.pm @@ -89,10 +89,14 @@ encoding which, if specified, overrides the default "7bit". (optional) type parameter for multipart/related messages -=item cust_msg +=item custnum -(optional) L<FS::cust_msg> object. If provided, it will be updated -with the message envelope information, contents, and server response. +(optional) L<FS::cust_main> key; if passed, the message will be logged +(if logging is enabled) with this custnum. + +=item msgnum + +(optional) L<FS::msg_template> key, for logging. =back @@ -255,18 +259,20 @@ sub send_email { } # Logging - my $cust_msg = $options{'cust_msg'}; - if ( $cust_msg ) { - $cust_msg->env_from($options{from}); - $cust_msg->env_to(join(",", @to)); - $cust_msg->header($message->header_as_string); - $cust_msg->body($message->body_as_string); - $cust_msg->_date($time); - $cust_msg->error($error); - $cust_msg->status( $error ? 'failed' : 'sent' ); - $cust_msg->replace; - }; - return $error; + if ( $conf->exists('log_sent_mail') and $options{'custnum'} ) { + my $cust_msg = FS::cust_msg->new({ + 'env_from' => $options{'from'}, + 'env_to' => join(', ', @to), + 'header' => $message->header_as_string, + 'body' => $message->body_as_string, + '_date' => $time, + 'error' => $error, + 'custnum' => $options{'custnum'}, + 'msgnum' => $options{'msgnum'}, + 'status' => ($error ? 'failed' : 'sent'), + }); + $cust_msg->insert; # ignore errors + } } @@ -302,9 +308,9 @@ Will be placed inside an HTML <BODY> tag. Email body (Text alternative). Arrayref of lines, or scalar. -=item cust_msg (optional) +=item custnum, msgnum (optional) -An L<FS::cust_msg> object. Will be passed through to send_email. +Customer and template numbers, passed through to send_email for logging. =back @@ -322,21 +328,9 @@ sub generate_email { my $me = '[FS::Misc::generate_email]'; - my %return = ( - 'from' => $args{'from'}, - 'to' => $args{'to'}, - 'bcc' => $args{'bcc'}, - 'subject' => $args{'subject'}, - 'cust_msg'=> $args{'cust_msg'}, - ); - - #if (ref($args{'to'}) eq 'ARRAY') { - # $return{'to'} = $args{'to'}; - #} else { - # $return{'to'} = [ grep { $_ !~ /^(POST|FAX)$/ } - # $self->cust_main->invoicing_list - # ]; - #} + my @fields = qw(from to bcc subject custnum msgnum); + my %return; + @return{@fields} = @args{@fields}; warn "$me creating HTML/text multipart message" if $DEBUG; diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm index 06a4522f4..5636fc6e4 100644 --- a/FS/FS/cust_main/Search.pm +++ b/FS/FS/cust_main/Search.pm @@ -471,6 +471,33 @@ sub search { my @where = (); my $orderby; + # initialize these to prevent warnings + $params = { + 'custnum' => '', + 'agentnum' => '', + 'usernum' => '', + 'status' => '', + 'address' => '', + 'paydate_year' => '', + 'invoice_terms' => '', + 'custbatch' => '', + %$params + }; + + ## + # explicit custnum(s) + ## + + if ( $params->{'custnum'} ) { + my @custnums = ref($params->{'custnum'}) ? + @{ $params->{'custnum'} } : + $params->{'custnum'}; + push @where, + 'cust_main.custnum IN (' . + join(',', map { $_ =~ /^(\d+)$/ ? $1 : () } @custnums ) . + ')' if scalar(@custnums) > 0; + } + ## # parse agent ## diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm index 8c8553c09..e8e243f2d 100644 --- a/FS/FS/cust_main_Mixin.pm +++ b/FS/FS/cust_main_Mixin.pm @@ -408,9 +408,6 @@ sub email_search_result { or die "msgnum $msgnum not found\n"; } - $param->{'payby'} = [ split(/\0/, $param->{'payby'}) ] - unless ref($param->{'payby'}); - my $sql_query = $class->search($param->{'search'}); my $count_query = delete($sql_query->{'count_query'}); @@ -463,15 +460,16 @@ sub email_search_result { @message = $msg_template->prepare( 'cust_main' => $cust_main ); } else { - my $to = $cust_main->invoicing_list_emailonly_scalar; - next if !$to; + my @to = $cust_main->invoicing_list_emailonly; + next if !@to; @message = ( 'from' => $from, - 'to' => $to, + 'to' => \@to, 'subject' => $subject, 'html_body' => $html_body, 'text_body' => $text_body, + 'custnum' => $cust_main->custnum, ); } #if $msg_template diff --git a/FS/FS/msg_template.pm b/FS/FS/msg_template.pm index 4a1e34584..e90cffd73 100644 --- a/FS/FS/msg_template.pm +++ b/FS/FS/msg_template.pm @@ -193,11 +193,6 @@ The I<from_addr> field in the template takes precedence over this. Destination address. The default is to use the customer's 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 =cut @@ -318,16 +313,16 @@ sub prepare { $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); - } +# 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); +# } ( 'custnum' => $cust_main->custnum, @@ -339,7 +334,6 @@ sub prepare { 'html_body' => $body, 'text_body' => HTML::FormatText->new(leftmargin => 0, rightmargin => 70 )->format( HTML::TreeBuilder->new_from_content($body) ), - @cust_msg, ); } |