add event action to send an invoice attached to a notice, #40152
[freeside.git] / FS / FS / part_event / Action / cust_bill_send_with_notice.pm
1 package FS::part_event::Action::cust_bill_send_with_notice;
2
3 use strict;
4 use base qw( FS::part_event::Action );
5 use FS::msg_template;
6 use MIME::Entity;
7
8 sub description { 'Email a notice to the customer with invoice attached'; }
9
10 sub eventtable_hashref {
11   { 'cust_bill' => 1 };
12 }
13
14 sub option_fields {
15   (
16     'msgnum'      => { label  => 'Message template',
17                        type     => 'select-table',
18                        table    => 'msg_template',
19                        hashref  => { disabled => '' },
20                        name_col => 'msgname',
21                        disable_empty => 1,
22                      },
23     'modenum'     => { label  => 'Invoice mode',
24                        type   => 'select-invoice_mode',
25                      },
26
27   );
28 }
29
30 sub default_weight { 56; }
31
32 sub do_action {
33   my( $self, $cust_bill, %opt ) = @_;
34
35   $cust_bill->set('mode' => $self->option('modenum'));
36   my %args = ( 'time' => $opt{'time'} );
37   my $mimepart = MIME::Entity->build( $cust_bill->mimebuild_pdf(\%args) );
38   my $msgnum = $self->option('msgnum');
39   my $msg_template = FS::msg_template->by_key($msgnum)
40     or die "can't find message template #$msgnum to send with invoice";
41   $msg_template->send(
42     'cust_main' => $cust_bill->cust_main,
43     'object'    => $cust_bill,
44     'attach'    => $mimepart
45   );
46 }
47
48 1;