From 871700058406b65d66bfcf645e4546fafb132246 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Wed, 23 Mar 2016 11:46:41 -0700 Subject: [PATCH] add event action to send an invoice attached to a notice, #40152 --- FS/FS/msg_template/email.pm | 21 +++++++++- .../Action/cust_bill_send_with_notice.pm | 48 ++++++++++++++++++++++ FS/FS/part_event/Action/letter.pm | 2 +- 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 FS/FS/part_event/Action/cust_bill_send_with_notice.pm diff --git a/FS/FS/msg_template/email.pm b/FS/FS/msg_template/email.pm index 83ff18f19..07a1fa093 100644 --- a/FS/FS/msg_template/email.pm +++ b/FS/FS/msg_template/email.pm @@ -206,6 +206,12 @@ A string to use as the HTML body; if specified, replaces the entire body of the message. This should be used ONLY by L and may go away in the future. +=item attach + +A L (or arrayref of them) to attach to the message. + +=cut + =back =cut @@ -348,13 +354,24 @@ sub prepare { 'Type' => 'multipart/related', ); + if ( $opt{'attach'} ) { + my @attach; + if (ref $opt{'attach'} eq 'ARRAY') { + @attach = @{ $opt{'attach'} }; + } else { + @attach = $opt{'attach'}; + } + foreach (@attach) { + $message->add_part($_); + } + } + #$message->head->replace('Content-type', # 'multipart/related; '. # 'boundary="' . $message->head->multipart_boundary . '"; ' . # 'type=multipart/alternative' #); - - # XXX a facility to attach additional parts is necessary at some point + foreach my $part (@{ $email{mimeparts} }) { warn "$me appending part ".$part->mime_type."\n" if $DEBUG; $message->add_part( $part ); diff --git a/FS/FS/part_event/Action/cust_bill_send_with_notice.pm b/FS/FS/part_event/Action/cust_bill_send_with_notice.pm new file mode 100644 index 000000000..10e86e37f --- /dev/null +++ b/FS/FS/part_event/Action/cust_bill_send_with_notice.pm @@ -0,0 +1,48 @@ +package FS::part_event::Action::cust_bill_send_with_notice; + +use strict; +use base qw( FS::part_event::Action ); +use FS::msg_template; +use MIME::Entity; + +sub description { 'Email a notice to the customer with invoice attached'; } + +sub eventtable_hashref { + { 'cust_bill' => 1 }; +} + +sub option_fields { + ( + 'msgnum' => { label => 'Message template', + type => 'select-table', + table => 'msg_template', + hashref => { disabled => '' }, + name_col => 'msgname', + disable_empty => 1, + }, + 'modenum' => { label => 'Invoice mode', + type => 'select-invoice_mode', + }, + + ); +} + +sub default_weight { 56; } + +sub do_action { + my( $self, $cust_bill, %opt ) = @_; + + $cust_bill->set('mode' => $self->option('modenum')); + my %args = ( 'time' => $opt{'time'} ); + my $mimepart = MIME::Entity->build( $cust_bill->mimebuild_pdf(\%args) ); + my $msgnum = $self->option('msgnum'); + my $msg_template = FS::msg_template->by_key($msgnum) + or die "can't find message template #$msgnum to send with invoice"; + $msg_template->send( + 'cust_main' => $cust_bill->cust_main, + 'object' => $cust_bill, + 'attach' => $mimepart + ); +} + +1; diff --git a/FS/FS/part_event/Action/letter.pm b/FS/FS/part_event/Action/letter.pm index 835dec2b9..123b99004 100644 --- a/FS/FS/part_event/Action/letter.pm +++ b/FS/FS/part_event/Action/letter.pm @@ -26,7 +26,7 @@ sub option_fields { ); } -sub default_weight { 56; } #? +sub default_weight { 58; } sub do_action { my( $self, $object ) = @_; -- 2.11.0