add condition on lack of customer tag, RT#28784
[freeside.git] / FS / FS / part_event / Condition / hasnt_cust_tag.pm
1 package FS::part_event::Condition::hasnt_cust_tag;
2 use base qw( FS::part_event::Condition );
3
4 use strict;
5 #use FS::Record qw( qsearch );
6
7 sub description {
8   'Customer does not have (any selected) tag',
9 }
10
11 sub eventtable_hashref {
12     { 'cust_main' => 1,
13       'cust_bill' => 1,
14       'cust_pkg'  => 1,
15     };
16 }
17
18 sub option_fields {
19   (
20     'tagnum'  => { 'label'    => 'Customer tag',
21                    'type'     => 'select-cust_tag',
22                    'multiple' => 1,
23                  },
24   );
25 }
26
27 sub condition {
28   my( $self, $object ) = @_;
29
30   my $cust_main = $self->cust_main($object);
31
32   my $hashref = $self->option('tagnum') || {};
33   ! grep $hashref->{ $_->tagnum }, $cust_main->cust_tag;
34
35 }
36
37 sub condition_sql {
38   my( $self, $table ) = @_;
39
40   my $matching_tags = 
41     "SELECT tagnum FROM cust_tag WHERE cust_tag.custnum = $table.custnum".
42     " AND cust_tag.tagnum IN ".
43     $self->condition_sql_option_option_integer('tagnum');
44
45   "NOT EXISTS($matching_tags)";
46 }
47
48 1;
49