summaryrefslogtreecommitdiff
path: root/FS/FS/part_event/Action/cust_bill_send_with_notice.pm
blob: efaa03537faeedf3bb2cc8d84811c1a45b3d78fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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_main'      => 1,
      'cust_bill'      => 1,
      'cust_pkg'       => 1,
      'cust_pay'       => 1,
      'cust_pay_batch' => 1,
      'cust_statement' => 1,
      'svc_acct'       => 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, $cust_event ) = @_;

  $cust_bill->set('mode' => $self->option('modenum'));
  my %args = ( 'time' => $cust_event->_date );
  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;