d300e338532d3d21d9c07a5444c10ce243805e9c
[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 #    { 'cust_main' => 1,
12 #      'cust_bill' => 1,
13 #      'cust_pkg'  => 1,
14 #    };
15 #}
16
17 sub option_fields {
18   (
19     'to'     => { 'label'    => 'Destination',
20                   'type'     => 'text',
21                   'size'     => 30,
22                 },
23     'msgnum' => { 'label'    => 'Template',
24                   'type'     => 'select-table',
25                   'table'    => 'msg_template',
26                   'name_col' => 'msgname',
27                   'hashref'  => { disabled => '' },
28                   'disable_empty' => 1,
29                 },
30   );
31 }
32
33 sub default_weight { 56; } #?
34
35 sub do_action {
36   my( $self, $object ) = @_;
37
38   my $cust_main = $self->cust_main($object);
39
40   my $msgnum = $self->option('msgnum');
41
42   my $msg_template = qsearchs('msg_template', { 'msgnum' => $msgnum } )
43       or die "Template $msgnum not found";
44
45   my $to = $self->option('to') 
46       or die "Can't send notice without a destination address";
47   
48   $msg_template->send(
49     'to'        => $to,
50     'cust_main' => $cust_main,
51     'object'    => $object,
52   );
53
54 }
55
56 1;