cb13b1f09915f6f40e1b202d9881e01f69525a68
[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 sub eventtable_hashref {
14   { 'cust_bill' => 1 };
15 }
16
17 sub option_fields {
18   (
19     'agentnum'           => { label    => 'Only for agent(s)',
20                               type     => 'select-agent',
21                               multiple => 1
22                             },
23     'modenum' => {  label => 'Invoice mode',
24                     type  => 'select-invoice_mode',
25                  },
26     'agent_templatename' => { label    => 'Template',
27                               type     => 'select-invoice_template',
28                             },
29     'agent_invoice_from' => 'Invoice email From: address',
30   );
31 }
32
33 sub default_weight { 50; }
34
35 sub do_action {
36   my( $self, $cust_bill ) = @_;
37
38   #my $cust_main = $self->cust_main($cust_bill);
39   my $cust_main = $cust_bill->cust_main;
40
41   my %agentnums = map { $_=>1 } split(/\s*,\s*/, $self->option('agentnum'));
42   if (keys(%agentnums) and !exists($agentnums{$cust_main->agentnum})) {
43     return;
44   }
45
46   $cust_bill->set('mode' => $self->option('modenum'));
47   $cust_bill->send(
48     'template' => $self->option('agent_templatename'),
49     'from'     => $self->option('agent_invoice_from'),
50   );
51 }
52
53 1;