suspend event option to skip packages with a start_date, RT#83847
[freeside.git] / FS / FS / part_event / Action / removetag.pm
1 package FS::part_event::Action::removetag;
2
3 use strict;
4 use base qw( FS::part_event::Action );
5 use FS::Record qw( qsearch );
6
7 sub description { 'Remove customer tag'; }
8
9 sub eventtable_hashref {
10     { 'cust_main'      => 1,
11       'cust_bill'      => 1,
12       'cust_pkg'       => 1,
13       'cust_pay'       => 1,
14       'cust_pay_batch' => 1,
15       'cust_statement' => 1,
16     };
17 }
18
19 sub option_fields {
20   (
21     'tagnum'  => { 'label'    => 'Customer tag',
22                    'type'     => 'select-cust_tag',
23                    'multiple' => 1,
24                  },
25   );
26 }
27
28 sub default_weight { 21; }
29
30 sub do_action {
31   my( $self, $object, $tagnum ) = @_;
32
33   # Get hashref of tags applied to selected customer record
34   my %cust_tag = map { $_->tagnum => $_ } qsearch({
35     table     => 'cust_tag',
36     hashref   => { custnum  => $object->custnum, },
37   });
38
39   # Remove tags chosen for this billing event from the customer record
40   foreach my $tagnum ( split(/\,/, $self->option('tagnum') ) ) {
41     if ( exists $cust_tag{$tagnum} ) {
42       my $error = $cust_tag{$tagnum}->delete;
43       die $error if $error;
44     }
45   }
46   '';
47 }
48
49 1;