svc_acct events for usage limits, #13202
[freeside.git] / FS / FS / part_event / Action / svc_acct_notice.pm
1 package FS::part_event::Action::svc_acct_notice;
2
3 use strict;
4 use base qw( FS::part_event::Action );
5 use FS::Record qw( qsearchs );
6 use FS::svc_acct;
7 use FS::msg_template;
8
9 sub description { 'Email a notice to this account'; }
10
11 sub eventtable_hashref {
12   { 'svc_acct' => 1 }
13 };
14
15 sub option_fields {
16   (
17     'msgnum' => { 'label'    => 'Template',
18                   'type'     => 'select-table',
19                   'table'    => 'msg_template',
20                   'name_col' => 'msgname',
21                   'disable_empty' => 1,
22                 },
23   );
24 }
25
26 sub default_weight { 56; } #?
27
28 sub do_action {
29   my( $self, $svc_acct ) = @_;
30
31   my $cust_main = $self->cust_main($svc_acct)
32       or die "No customer found for svcnum ".$svc_acct->svcnum;
33     # this will never be run for unlinked services, for several reasons
34
35   my $msgnum = $self->option('msgnum');
36
37   my $msg_template = qsearchs('msg_template', { 'msgnum' => $msgnum } )
38       or die "Template $msgnum not found";
39
40   my $email = $svc_acct->email
41       or die "No email associated with svcnum ".$svc_acct->svcnum;
42
43   $msg_template->send(
44     'cust_main' => $cust_main,
45     'object'    => $svc_acct,
46     'to'        => $email,
47   );
48
49 }
50
51 1;