From 71039cd742898a214fe7ae6f3908beb15a0270c6 Mon Sep 17 00:00:00 2001 From: Mitch Jackson Date: Sun, 19 Nov 2017 00:43:07 +0000 Subject: [PATCH] RT# 73211 - Add billing event: remove customer tag - Created billing event removetag, named to match addtag - Weighted addtag and removetag both at 21, to group them in menus --- FS/FS/part_event/Action/addtag.pm | 4 +-- FS/FS/part_event/Action/removetag.pm | 49 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 FS/FS/part_event/Action/removetag.pm diff --git a/FS/FS/part_event/Action/addtag.pm b/FS/FS/part_event/Action/addtag.pm index c4e9820b7..c929b41db 100644 --- a/FS/FS/part_event/Action/addtag.pm +++ b/FS/FS/part_event/Action/addtag.pm @@ -25,12 +25,12 @@ sub option_fields { ); } -sub default_weight { 20; } +sub default_weight { 21; } sub do_action { my( $self, $object, $tagnum ) = @_; - my %exists = map { $_->tagnum => $_->tagnum } + my %exists = map { $_->tagnum => $_->tagnum } qsearch({ table => 'cust_tag', hashref => { custnum => $object->custnum, }, diff --git a/FS/FS/part_event/Action/removetag.pm b/FS/FS/part_event/Action/removetag.pm new file mode 100644 index 000000000..41cf917a7 --- /dev/null +++ b/FS/FS/part_event/Action/removetag.pm @@ -0,0 +1,49 @@ +package FS::part_event::Action::removetag; + +use strict; +use base qw( FS::part_event::Action ); +use FS::Record qw( qsearch ); + +sub description { 'Remove customer tag'; } + +sub eventtable_hashref { + { 'cust_main' => 1, + 'cust_bill' => 1, + 'cust_pkg' => 1, + 'cust_pay' => 1, + 'cust_pay_batch' => 1, + 'cust_statement' => 1, + }; +} + +sub option_fields { + ( + 'tagnum' => { 'label' => 'Customer tag', + 'type' => 'select-cust_tag', + 'multiple' => 1, + }, + ); +} + +sub default_weight { 21; } + +sub do_action { + my( $self, $object, $tagnum ) = @_; + + # Get hashref of tags applied to selected customer record + my %cust_tag = map { $_->tagnum => $_ } qsearch({ + table => 'cust_tag', + hashref => { custnum => $object->custnum, }, + }); + + # Remove tags chosen for this billing event from the customer record + foreach my $tagnum ( split(/\,/, $self->option('tagnum') ) ) { + if ( exists $cust_tag{$tagnum} ) { + my $error = $cust_tag{$tagnum}->delete; + die $error if $error; + } + } + ''; +} + +1; -- 2.11.0