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