(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
}
# 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
+ }
}
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
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;
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
##
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'});
@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
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
$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,
'html_body' => $body,
'text_body' => HTML::FormatText->new(leftmargin => 0, rightmargin => 70
)->format( HTML::TreeBuilder->new_from_content($body) ),
- @cust_msg,
);
}
<SCRIPT>
function areyousure(href) {
- return confirm("Send this notice to <% $num_cust %> customers?");
+ return confirm("Send this notice to <% ($num_cust > 1) ? "$num_cust customers" : '1 customer' %> ?");
}
</SCRIPT>
<% include('/elements/tr-input-text.html',
'field' => 'from',
'label' => 'From:',
+ 'size' => 50,
)
%>
<% include('/elements/tr-input-text.html',
'field' => 'subject',
'label' => 'Subject:',
+ 'size' => 50,
)
%>
<TR>
- <TD ALIGN="right" VALIGN="top">Message: </TD>
- <TD><% include('/elements/htmlarea.html', 'field'=>'html_body') %></TD>
+ <TD ALIGN="right" VALIGN="top" STYLE="padding-top:3px">Message: </TD>
+ <TD><& '/elements/htmlarea.html',
+ 'field' => 'html_body',
+ 'width' => 600 &></TD>
</TR>
</TABLE>
@search{keys %search} = map { /\0/ ? [ split /\0/, $_ ] : $_ } values %search;
}
-my $title = 'Send bulk customer notices';
+my $title = 'Send customer notices';
my $num_cust;
my $from = $cgi->param('from') || '';
or die "template not found: ".$cgi->param('msgnum');
$sql_query->{'extra_sql'} .= ' LIMIT 1';
$sql_query->{'order_by'} = '';
- my $cust = qsearchs($sql_query)->cust_main;
- my %message = $msg_template->prepare( 'cust_main' => $cust, 'preview' => 1 );
+ my $object = qsearchs($sql_query);
+ my $cust = $object->cust_main;
+ my %message = $msg_template->prepare( 'cust_main' => $cust );
($from, $subject, $html_body) = @message{'from', 'subject', 'html_body'};
}
}
$date ? time2str('%Y-%m-%d %T',$_[0]->_date) : ''
},
'msgname',
- 'env_to',
+ sub {
+ join('<BR>', split(/,\s*/, $_[0]->env_to) )
+ },
'status',
sub { encode_entities($_[0]->error) },
],
};
my %color = (
- 'prepared' => '0000FF',
'failed' => 'FF0000',
'sent' => '',
);
include('/elements/select.html',
'field' => 'status',
'curr_value' => $cgi->param('status') || '',
- 'options' => [ '', 'failed', 'sent', 'prepared' ],
+ 'options' => [ '', 'failed', 'sent', ],
'labels' => { '' => '(any)',
'failed' => 'failed',
- 'sent' => 'sent',
- 'prepared'=> 'prepared' },
+ 'sent' => 'sent', },
) .
'</TD>
<TD><INPUT type="submit" value="Search"></TD></TR>
% $br=1;
<A HREF="<% $p %>search/cust_event.html?custnum=<% $custnum %>"><% mt('View billing events for this customer') |h %></A>
% }
+%
+% my $email_link = ($cust_main->invoicing_list_emailonly) &&
+% include('/elements/email-link.html',
+% 'table' => 'cust_main',
+% 'search_hash' => { 'custnum' => $custnum },
+% 'label' => 'Email a notice to this customer',
+% );
+% if ( $email_link and $br ) {
+ |
+% }
+<% $email_link || '' %>
% if ( $conf->config('cust_main-external_links') ) {
<% $br++ ? ' | ' : '' %>