summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorChristopher Burger <burgerc@freeside.biz>2017-07-11 11:35:14 -0400
committerChristopher Burger <burgerc@freeside.biz>2017-07-12 16:19:03 -0400
commit109a0744cf4da3acec4c8638adc9f5771a56ed45 (patch)
tree5ba1f3788092c729bfa979a1e4fc9d330b561cb1 /FS
parentce0dabc99cf469db3abc85800b23be8dfcdd5790 (diff)
RT# 76307 - Added billing event action to add a tag
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/part_event/Action/addtag.pm53
1 files changed, 53 insertions, 0 deletions
diff --git a/FS/FS/part_event/Action/addtag.pm b/FS/FS/part_event/Action/addtag.pm
new file mode 100644
index 000000000..947f0c37d
--- /dev/null
+++ b/FS/FS/part_event/Action/addtag.pm
@@ -0,0 +1,53 @@
+package FS::part_event::Action::addtag;
+
+use strict;
+use base qw( FS::part_event::Action );
+use FS::Record qw( qsearch );
+
+sub description { 'Add 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 { 20; }
+
+sub do_action {
+ my( $self, $object, $tagnum ) = @_;
+
+ my %exists = map { $_->tagnum => $_->tagnum }
+ qsearch({
+ table => 'cust_tag',
+ hashref => { custnum => $object->custnum, },
+ });
+
+ my @tags = split(/\,/, $self->option('tagnum'));
+ foreach my $tagnum ( split(/\,/, $self->option('tagnum') ) ) {
+ if ( !$exists{$tagnum} ) {
+ my $cust_tag = new FS::cust_tag { 'tagnum' => $tagnum,
+ 'custnum' => $object->custnum, };
+ my $error = $cust_tag->insert;
+ if ( $error ) {
+ return $error;
+ }
+ }
+ }
+ '';
+}
+
+1;