RT# 37817 - added a declaration to cust bill event actions that send out invoices
[freeside.git] / FS / FS / part_event / Action / cust_bill_send_agent.pm
1 package FS::part_event::Action::cust_bill_send_agent;
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, for specific agents';
8 }
9
10 # this event is just cust_bill_send_alternate + an implicit (and inefficient)
11 # 'agent' condition
12
13 ## declaring that this action will send out an invoice
14 sub will_send_invoice { 1; }
15
16 sub eventtable_hashref {
17   { 'cust_bill' => 1 };
18 }
19
20 sub option_fields {
21   (
22     'agentnum'           => { label    => 'Only for agent(s)',
23                               type     => 'select-agent',
24                               multiple => 1
25                             },
26     'modenum' => {  label => 'Invoice mode',
27                     type  => 'select-invoice_mode',
28                  },
29     'agent_templatename' => { label    => 'Template',
30                               type     => 'select-invoice_template',
31                             },
32     'agent_invoice_from' => 'Invoice email From: address',
33   );
34 }
35
36 sub default_weight { 50; }
37
38 sub do_action {
39   my( $self, $cust_bill ) = @_;
40
41   #my $cust_main = $self->cust_main($cust_bill);
42   my $cust_main = $cust_bill->cust_main;
43
44   my %agentnums = map { $_=>1 } split(/\s*,\s*/, $self->option('agentnum'));
45   if (keys(%agentnums) and !exists($agentnums{$cust_main->agentnum})) {
46     return;
47   }
48
49   $cust_bill->set('mode' => $self->option('modenum'));
50   $cust_bill->send(
51     'template' => $self->option('agent_templatename'),
52     'from'     => $self->option('agent_invoice_from'),
53   );
54 }
55
56 1;