835dec2b94f64e5508aeb01f5caf0d2e1e501ce6
[freeside.git] / FS / FS / part_event / Action / letter.pm
1 package FS::part_event::Action::letter;
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 { 'Print a form letter to the customer' }
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     'msgnum' => { 'label'    => 'Template',
20                   'type'     => 'select-table',
21                   'table'    => 'msg_template',
22                   'name_col' => 'msgname',
23                   'hashref'  => { disabled => '' },
24                   'disable_empty' => 1,
25                 },
26   );
27 }
28
29 sub default_weight { 56; } #?
30
31 sub do_action {
32   my( $self, $object ) = @_;
33
34   my $cust_main = $self->cust_main($object);
35
36   my $msgnum = $self->option('msgnum');
37
38   my $msg_template = qsearchs('msg_template', { 'msgnum' => $msgnum } )
39       or die "Template $msgnum not found";
40
41   $msg_template->print(
42     'cust_main' => $cust_main,
43     'object'    => $object,
44   );
45
46 }
47
48 1;