RT# 76309 - Updated 3 email notices to use more billing event types
[freeside.git] / FS / FS / part_event / Action / notice_to.pm
1 package FS::part_event::Action::notice_to;
2
3 use strict;
4 use base qw( FS::part_event::Action );
5 use FS::Record qw( qsearchs );
6 use FS::msg_template;
7
8 sub description { 'Email a notice to a specific address'; }
9
10 sub eventtable_hashref {
11     {
12       'cust_main'      => 1,
13       'cust_bill'      => 1,
14       'cust_pkg'       => 1,
15       'cust_pay'       => 1,
16       'cust_pay_batch' => 1,
17       'cust_statement' => 1,
18       'svc_acct'       => 1,
19     };
20 }
21
22 sub option_fields {
23   (
24     'to'     => { 'label'    => 'Destination',
25                   'type'     => 'text',
26                   'size'     => 30,
27                 },
28     'msgnum' => { 'label'    => 'Template',
29                   'type'     => 'select-table',
30                   'table'    => 'msg_template',
31                   'name_col' => 'msgname',
32                   'hashref'  => { disabled => '' },
33                   'disable_empty' => 1,
34                 },
35   );
36 }
37
38 sub default_weight { 56; } #?
39
40 sub do_action {
41   my( $self, $object ) = @_;
42
43   my $cust_main = $self->cust_main($object);
44
45   my $msgnum = $self->option('msgnum');
46
47   my $msg_template = qsearchs('msg_template', { 'msgnum' => $msgnum } )
48       or die "Template $msgnum not found";
49
50   my $to = $self->option('to') 
51       or die "Can't send notice without a destination address";
52   
53   $msg_template->send(
54     'to'        => $to,
55     'cust_main' => $cust_main,
56     'object'    => $object,
57   );
58
59 }
60
61 1;