efaa03537faeedf3bb2cc8d84811c1a45b3d78fe
[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     {
12       'cust_main'      => 1,
13       'cust_bill'      => 1,
14       'cust_pkg'       => 1,
15       'cust_pay'       => 1,
16       'cust_pay_batch' => 1,
17       'cust_statement' => 1,
18       'svc_acct'       => 1,
19     };
20 }
21
22 sub option_fields {
23   (
24     'msgnum'      => { label  => 'Message template',
25                        type     => 'select-table',
26                        table    => 'msg_template',
27                        hashref  => { disabled => '' },
28                        name_col => 'msgname',
29                        disable_empty => 1,
30                      },
31     'modenum'     => { label  => 'Invoice mode',
32                        type   => 'select-invoice_mode',
33                      },
34
35   );
36 }
37
38 sub default_weight { 56; }
39
40 sub do_action {
41   my( $self, $cust_bill, $cust_event ) = @_;
42
43   $cust_bill->set('mode' => $self->option('modenum'));
44   my %args = ( 'time' => $cust_event->_date );
45   my $mimepart = MIME::Entity->build( $cust_bill->mimebuild_pdf(\%args) );
46   my $msgnum = $self->option('msgnum');
47   my $msg_template = FS::msg_template->by_key($msgnum)
48     or die "can't find message template #$msgnum to send with invoice";
49   $msg_template->send(
50     'cust_main' => $cust_bill->cust_main,
51     'object'    => $cust_bill,
52     'attach'    => $mimepart
53   );
54 }
55
56 1;