}
# Logging
- if ( $conf->exists('log_sent_mail') and $options{'custnum'} ) {
+ if ( $conf->exists('log_sent_mail') ) {
my $cust_msg = FS::cust_msg->new({
'env_from' => $options{'from'},
'env_to' => join(', ', @to),
'custnum' => $options{'custnum'},
'msgnum' => $options{'msgnum'},
'status' => ($error ? 'failed' : 'sent'),
+ 'msgtype' => $options{'msgtype'},
});
$cust_msg->insert; # ignore errors
}
my $me = '[FS::Misc::generate_email]';
- my @fields = qw(from to bcc subject custnum msgnum);
+ my @fields = qw(from to bcc subject custnum msgnum msgtype);
my %return;
@return{@fields} = @args{@fields};
'cust_msg' => {
'columns' => [
'custmsgnum', 'serial', '', '', '', '',
- 'custnum', 'int', '', '', '', '',
+ 'custnum', 'int', 'NULL', '', '', '',
'msgnum', 'int', 'NULL', '', '', '',
'_date', @date_type, '', '',
'env_from', 'varchar', 'NULL', 255, '', '',
'body', 'blob', 'NULL', '', '', '',
'error', 'varchar', 'NULL', 255, '', '',
'status', 'varchar', '',$char_d, '', '',
+ 'msgtype', 'varchar', 'NULL', 16, '', '',
],
'primary_key' => 'custmsgnum',
'unique' => [ ],
my %return = (
'from' => $args{'from'},
'subject' => ($args{'subject'} || $self->email_subject),
+ 'custnum' => $self->custnum,
+ 'msgtype' => 'invoice',
);
$args{'unsquelch_cdr'} = $conf->exists('voip-cdr_email');
=head1 DESCRIPTION
-An FS::cust_msg object represents a template-generated message sent to
-a customer (see L<FS::msg_template>). FS::cust_msg inherits from
-FS::Record. The following fields are currently supported:
+An FS::cust_msg object represents an email message generated by Freeside
+and sent to a customer (see L<FS::msg_template>). FS::cust_msg inherits
+from FS::Record. The following fields are currently supported:
=over 4
=item msgnum - template number
+=item msgtype - the message type
+
=item _date - the time the message was sent
=item env_from - envelope From address
my $error =
$self->ut_numbern('custmsgnum')
- || $self->ut_number('custnum')
- || $self->ut_foreign_key('custnum', 'cust_main', 'custnum')
+ || $self->ut_numbern('custnum')
+ || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum')
|| $self->ut_numbern('msgnum')
|| $self->ut_foreign_keyn('msgnum', 'msg_template', 'msgnum')
|| $self->ut_numbern('_date')
|| $self->ut_anything('body')
|| $self->ut_enum('status', \@statuses)
|| $self->ut_textn('error')
+ || $self->ut_enum('msgtype', [ '',
+ 'invoice',
+ 'receipt',
+ 'admin',
+ ])
;
return $error if $error;
'custnum' => $cust_main->custnum,
};
$error = $queue->insert(
- FS::msg_template->by_key($msgnum)->prepare(
+ FS::msg_template->by_key($msgnum)->prepare(
'cust_main' => $cust_main,
'object' => $self,
'from_config' => 'payment_receipt_from',
- )
+ ),
+ 'msgtype' => 'receipt', # override msg_template's default
);
} elsif ( $conf->exists('payment_receipt_email') ) {
'job' => 'FS::Misc::process_send_generated_email',
'paynum' => $self->paynum,
'custnum' => $cust_main->custnum,
+ 'msgtype' => 'receipt',
};
$error = $queue->insert(
'from' => $conf->config('invoice_from', $cust_main->agentnum),
'to' => \@invoicing_list,
'subject' => ( $conf->config('cancelsubject') || 'Cancellation Notice' ),
'body' => [ map "$_\n", $conf->config('cancelmessage') ],
+ 'custnum' => $self->custnum,
+ 'msgtype' => '', #admin?
);
}
#should this do something on errors?
'Package : #'. $self->pkgnum. " (". $self->part_pkg->pkg_comment. ")\n",
( map { "Service : $_\n" } @labels ),
],
+ 'custnum' => $self->custnum,
+ 'msgtype' => 'admin'
);
if ( $error ) {
: ''
),
],
+ 'custnum' => $self->custnum,
+ 'msgtype' => 'admin',
);
if ( $error ) {
use FS::Record qw(qsearch qsearchs);
use FS::Conf;
use FS::msg_template;
-use FS::Misc qw(send_email);
@ISA = qw(FS::part_export);
'count_query' => $count_query,
'header' => [
'Date',
- 'Template',
+ 'Type',
'Destination',
'Status',
'', #error
my $date = $_[0]->_date;
$date ? time2str('%Y-%m-%d %T',$_[0]->_date) : ''
},
- 'msgname',
+ sub {
+ ucfirst($_[0]->msgtype) || $_[0]->msgname
+ },
sub {
join('<BR>', split(/,\s*/, $_[0]->env_to) )
},
'',
'',
],
- 'color' => [ ('') x 3,
- $statuscolor,
- $statuscolor,
+ 'color' => [ '',
+ $typecolor,
+ '',
+ $statuscolor,
+ $statuscolor,
],
'html_init' => $html_init,
'really_disable_download' => 1,
if ( $cgi->param('status') =~ /^(\w+)$/ ) {
push @where, "status = '$1'";
}
+if ( $cgi->param('msgtype') =~ /^(\w+)$/ ) {
+ push @where, "msgtype = '$1'";
+}
my ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
push @where, "(_date >= $beginning AND _date <= $ending)";
include('/elements/popup_link_onclick.html',
'action' => $p. 'view/cust_msg.html?' . $custmsgnum,
'actionlabel' => 'Message detail',
- 'width' => 600,
- 'height' => 500,
+ 'width' => 680,
+ 'height' => 550,
);
};
my %color = (
'failed' => 'FF0000',
'sent' => '',
+
+ 'invoice' => '00CC00',
+ 'receipt' => '0000CC',
+ 'admin' => 'CC0000',
+ '' => '000000',
);
my $statuscolor = sub { $color{$_[0]->status} };
+my $typecolor = sub { $color{$_[0]->msgtype} };
my $html_init = qq!<FORM ACTION="$p/search/cust_msg.html" METHOD="GET">
<TABLE cellspacing="10">!.
'failed' => 'failed',
'sent' => 'sent', },
) .
+'</TD><TD> Type '.
+include('/elements/select.html',
+ 'field' => 'msgtype',
+ 'curr_value' => $cgi->param('msgtype') || '',
+ 'options' => [ '', 'invoice', 'receipt', 'admin' ],
+ 'labels' => { '' => '(any)',
+ 'invoice' => 'Invoices',
+ 'receipt' => 'Receipts',
+ 'admin' => 'Admin notices',
+ },
+) .
'</TD>
<TD><INPUT type="submit" value="Search"></TD></TR>
</TABLE></FORM><BR>
% $cstyle = qq(STYLE="$cstyle")
% if $cstyle;
- <TD CLASS="<% $class %>" BGCOLOR="<% $bgcolor %>" <% $align %> <% $cstyle %>><% $font %><% $a %><% $s %><% $field %><% $es %><% $a ? '</A>' : '' %><% $font ? '</FONT>' : '' %></TD>
+ <TD CLASS="<% $class %>" BGCOLOR="<% $bgcolor %>" <% $align %> <% $cstyle %>><% $a %><% $font %><% $s %><% $field %><% $es %><% $font ? '</FONT>' : '' %><% $a ? '</A>' : '' %></TD>
% }
%