RT# 73211 - Add billing event: remove customer tag
authorMitch Jackson <mitch@freeside.biz>
Sun, 19 Nov 2017 00:43:07 +0000 (00:43 +0000)
committerMitch Jackson <mitch@freeside.biz>
Sun, 19 Nov 2017 00:43:07 +0000 (00:43 +0000)
 - 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
FS/FS/part_event/Action/removetag.pm [new file with mode: 0644]

index c4e9820..c929b41 100644 (file)
@@ -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 (file)
index 0000000..41cf917
--- /dev/null
@@ -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;