contacts can be shared among customers / "duplicate contact emails", RT#27943
[freeside.git] / FS / FS / part_event / Condition / has_cust_tag.pm
1 package FS::part_event::Condition::has_cust_tag;
2
3 use strict;
4
5 use base qw( FS::part_event::Condition );
6 use FS::Record qw( qsearch );
7
8 sub description {
9   'Customer has tag',
10 }
11
12 sub eventtable_hashref {
13     { 'cust_main' => 1,
14       'cust_bill' => 1,
15       'cust_pkg'  => 1,
16     };
17 }
18
19 sub option_fields {
20   (
21     'tagnum'  => { 'label'    => 'Customer tag',
22                    'type'     => 'select-cust_tag',
23                    'multiple' => 1,
24                  },
25   );
26 }
27
28 sub condition {
29   my( $self, $object ) = @_;
30
31   my $cust_main = $self->cust_main($object);
32
33   my $hashref = $self->option('tagnum') || {};
34   grep $hashref->{ $_->tagnum }, $cust_main->cust_tag;
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   "EXISTS($matching_tags)";
46 }
47
48 1;