summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2012-03-28 17:35:38 -0700
committerMark Wells <mark@freeside.biz>2012-03-28 17:35:38 -0700
commit09bdd45e0a95601b7c51c5dbbef03793f320a61d (patch)
tree52c53c0f133347f6f7e5d0e82054aef6e6421bde
parent0c7f9a2952acf2caf16a2d1156f99d9c81b486b1 (diff)
customer tag event condition, #15116
-rw-r--r--FS/FS/part_event/Condition.pm2
-rw-r--r--FS/FS/part_event/Condition/has_cust_tag.pm49
-rw-r--r--httemplate/elements/tr-select-cust_tag.html2
3 files changed, 51 insertions, 2 deletions
diff --git a/FS/FS/part_event/Condition.pm b/FS/FS/part_event/Condition.pm
index 32751974c..b3948153e 100644
--- a/FS/FS/part_event/Condition.pm
+++ b/FS/FS/part_event/Condition.pm
@@ -360,7 +360,7 @@ sub condition_sql_option_option {
}
-#used for part_event/Condition/cust_bill_has_service.pm
+#used for part_event/Condition/cust_bill_has_service.pm and has_cust_tag.pm
#a little false laziness w/above and condition_sql_option_integer
sub condition_sql_option_option_integer {
my( $class, $option, $driver_name ) = @_;
diff --git a/FS/FS/part_event/Condition/has_cust_tag.pm b/FS/FS/part_event/Condition/has_cust_tag.pm
new file mode 100644
index 000000000..cde933881
--- /dev/null
+++ b/FS/FS/part_event/Condition/has_cust_tag.pm
@@ -0,0 +1,49 @@
+package FS::part_event::Condition::has_cust_tag;
+
+use strict;
+
+use base qw( FS::part_event::Condition );
+use FS::Record qw( qsearch );
+
+sub description {
+ 'Customer has tag',
+}
+
+sub eventtable_hashref {
+ { 'cust_main' => 1,
+ 'cust_bill' => 1,
+ 'cust_pkg' => 1,
+ };
+}
+
+#something like this
+sub option_fields {
+ (
+ 'tagnum' => { 'label' => 'Customer tag',
+ 'type' => 'select-cust_tag',
+ 'multiple' => 1,
+ },
+ );
+}
+
+sub condition {
+ my( $self, $object ) = @_;
+
+ my $cust_main = $self->cust_main($object);
+
+ my $hashref = $self->option('tagnum') || {};
+ grep $hashref->{ $_->tagnum }, $cust_main->cust_tag;
+}
+
+sub condition_sql {
+ my( $self, $table ) = @_;
+
+ my $matching_tags =
+ "SELECT tagnum FROM cust_tag WHERE cust_tag.custnum = $table.custnum".
+ " AND cust_tag.tagnum IN ".
+ $self->condition_sql_option_option_integer('tagnum');
+
+ "EXISTS($matching_tags)";
+}
+
+1;
diff --git a/httemplate/elements/tr-select-cust_tag.html b/httemplate/elements/tr-select-cust_tag.html
index b2b6d967e..5312644ef 100644
--- a/httemplate/elements/tr-select-cust_tag.html
+++ b/httemplate/elements/tr-select-cust_tag.html
@@ -28,7 +28,7 @@ my $cgi = $opt{'cgi'};
my $is_report = $opt{'is_report'};
my @curr_tagnum = ();
-if ( $cgi->param('error') ) {
+if ( $cgi && $cgi->param('error') ) {
@curr_tagnum = $cgi->param('tagnum');
} elsif ( $opt{'custnum'} ) {
@curr_tagnum = map $_->tagnum,