ae766e81b7026a6e08def166f8414e5eb19687ab
[freeside.git] / FS / FS / part_event / Action / notice_to_emailtovoice.pm
1 package FS::part_event::Action::notice_to_emailtovoice;
2
3 use strict;
4 use base qw( FS::part_event::Action );
5 use FS::Record qw( qsearchs );
6 use FS::msg_template;
7 use FS::Conf;
8
9 sub description { 'Email a email to voice notice'; }
10
11 sub eventtable_hashref {
12     {
13       'cust_main'      => 1,
14       'cust_bill'      => 1,
15       'cust_pkg'       => 1,
16       'cust_pay'       => 1,
17       'cust_pay_batch' => 1,
18       'cust_statement' => 1,
19       'svc_acct'       => 1,
20     };
21 }
22
23 sub option_fields {
24
25   #my $conf = new FS::Conf;
26   #my $to_domain = $conf->config('send-to-domain');
27
28 (
29     'to_name'   => { 'label'            => 'Address To',
30                      'type'             => 'select',
31                      'options'          => [ 'mobile', 'fax', 'daytime' ],
32                      'option_labels'    => { 'mobile'  => 'Mobile Phone #',
33                                              'fax'     => 'Fax #',
34                                              'daytime' => 'Day Time #',
35                                            },
36                      'post_field_label' => "@" , #. $to_domain ,
37                    },
38
39     'msgnum'    => { 'label'    => 'Template',
40                      'type'     => 'select-table',
41                      'table'    => 'msg_template',
42                      'name_col' => 'msgname',
43                      'hashref'  => { disabled => '' },
44                      'disable_empty' => 1,
45                 },
46   );
47
48 }
49
50 sub default_weight { 56; } #?
51
52 sub do_action {
53   my( $self, $object ) = @_;
54
55   my $conf = new FS::Conf;
56   my $to_domain = $conf->config('send-to-domain')
57     or die "Can't send notice with out send-to-domain, being set in global config \n";
58
59   my $cust_main = $self->cust_main($object);
60
61   my $msgnum = $self->option('msgnum');
62   my $name = $self->option('to_name');
63
64   my $msg_template = qsearchs('msg_template', { 'msgnum' => $msgnum } )
65       or die "Template $msgnum not found";
66
67   my $to_name = $cust_main->$name
68     or die "Can't send notice with out " . $cust_main->$name . " number set";
69
70   ## remove - from phone number
71   $to_name =~ s/-//g;
72
73   #my $to = $to_name . '@' . $self->option('to_domain');
74   my $to = $to_name . '@' . $to_domain;
75   
76   $msg_template->send(
77     'to'        => $to,
78     'cust_main' => $cust_main,
79     'object'    => $object,
80   );
81
82 }
83
84 1;