RT# 37817 - added a declaration to cust bill event actions that send out invoices
[freeside.git] / FS / FS / part_event / Action / cust_bill_send_if_newest.pm
1 package FS::part_event::Action::cust_bill_send_if_newest;
2
3 use strict;
4 use base qw( FS::part_event::Action );
5
6 sub description {
7   'Send invoice (email/print/fax) with alternate template, if it is still the newest invoice (useful for late notices - set to 31 days or later)';
8 }
9
10 # XXX is this handled better by something against customers??
11 #sub deprecated {
12 #  1;
13 #}
14
15 ## declaring that this action will send out an invoice
16 sub will_send_invoice { 1; }
17
18 sub eventtable_hashref {
19   { 'cust_bill' => 1 };
20 }
21
22 sub option_fields {
23   (
24     'modenum' => {  label => 'Invoice mode',
25                     type  => 'select-invoice_mode',
26                  },
27     'if_newest_templatename' => { label    => 'Template',
28                                   type     => 'select-invoice_template',
29                                 },
30   );
31 }
32
33 sub default_weight { 50; }
34
35 sub do_action {
36   my( $self, $cust_bill ) = @_;
37
38   my $invnum = $cust_bill->invnum;
39   my $custnum = $cust_bill->custnum;
40   return '' if scalar(
41     grep { $_->owed > 0 }
42       qsearch('cust_bill', {
43           'custnum' => $custnum,
44           'invnum'  => { op=>'>', value=>$invnum },
45         })
46     );
47   $cust_bill->set('mode' => $self->option('modenum'));
48   $cust_bill->send( 'template' => $self->option('templatename') );
49 }
50
51 1;