[freeside-commits] branch FREESIDE_3_BRANCH updated. a2d3ebe7029269a5ed2df08536ab5a757905b53f

Mark Wells mark at 420.am
Wed Mar 23 13:20:50 PDT 2016


The branch, FREESIDE_3_BRANCH has been updated
       via  a2d3ebe7029269a5ed2df08536ab5a757905b53f (commit)
      from  70145b4a1ade2ed39ae793ccb1364e2b41d6f1e4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit a2d3ebe7029269a5ed2df08536ab5a757905b53f
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Mar 23 11:46:41 2016 -0700

    add event action to send an invoice attached to a notice, #40152

diff --git a/FS/FS/msg_template.pm b/FS/FS/msg_template.pm
index 5c6392c..70e5569 100644
--- a/FS/FS/msg_template.pm
+++ b/FS/FS/msg_template.pm
@@ -422,7 +422,7 @@ sub prepare {
     'bcc'  => $self->bcc_addr || undef,
     'subject'   => $subject,
     'html_body' => $body,
-    'text_body' => $text_body
+    'text_body' => $text_body,
   );
 
 }
@@ -430,7 +430,8 @@ sub prepare {
 =item send OPTION => VALUE
 
 Fills in the template and sends it to the customer.  Options are as for 
-'prepare'.
+'prepare', plus 'attach', a L<MIME::Entity> (or arrayref of them) to attach
+to the message.
 
 =cut
 
@@ -438,7 +439,20 @@ Fills in the template and sends it to the customer.  Options are as for
 # preview it, etc.
 sub send {
   my $self = shift;
-  send_email(generate_email($self->prepare(@_)));
+  my %opt = @_;
+
+  my %email = generate_email($self->prepare(%opt));
+  if ( $opt{'attach'} ) {
+    my @attach;
+    if (ref($opt{'attach'}) eq 'ARRAY') {
+      @attach = @{ $opt{'attach'} };
+    } else {
+      @attach = $opt{'attach'};
+    }
+    push @{ $email{mimeparts} }, @attach;
+  }
+
+  send_email(%email);
 }
 
 =item render OPTION => VALUE ...
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 0000000..10e86e3
--- /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 835dec2..123b990 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 ) = @_;

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/msg_template.pm                              |   20 ++++++--
 .../Action/cust_bill_send_with_notice.pm           |   48 ++++++++++++++++++++
 FS/FS/part_event/Action/letter.pm                  |    2 +-
 3 files changed, 66 insertions(+), 4 deletions(-)
 create mode 100644 FS/FS/part_event/Action/cust_bill_send_with_notice.pm




More information about the freeside-commits mailing list