RT# 76303 - added tag options to payments, batch payments, and statement billing...
[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       'cust_pay'       => 1,
17       'cust_pay_batch' => 1,
18       'cust_statement' => 1,
19     };
20 }
21
22 #something like this
23 sub option_fields {
24   (
25     'tagnum'  => { 'label'    => 'Customer tag',
26                    'type'     => 'select-cust_tag',
27                    'multiple' => 1,
28                  },
29   );
30 }
31
32 sub condition {
33   my( $self, $object ) = @_;
34
35   my $cust_main = $self->cust_main($object);
36
37   my $hashref = $self->option('tagnum') || {};
38   grep $hashref->{ $_->tagnum }, $cust_main->cust_tag;
39 }
40
41 sub condition_sql {
42   my( $self, $table ) = @_;
43
44   my $matching_tags = 
45     "SELECT tagnum FROM cust_tag WHERE cust_tag.custnum = $table.custnum".
46     " AND cust_tag.tagnum IN ".
47     $self->condition_sql_option_option_integer('tagnum');
48
49   "EXISTS($matching_tags)";
50 }
51
52 1;