RT #31482 making sure the tax class is not editable after the customer has been billed.
[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 #something like this
20 sub option_fields {
21   (
22     'tagnum'  => { 'label'    => 'Customer tag',
23                    'type'     => 'select-cust_tag',
24                    'multiple' => 1,
25                  },
26   );
27 }
28
29 sub condition {
30   my( $self, $object ) = @_;
31
32   my $cust_main = $self->cust_main($object);
33
34   my $hashref = $self->option('tagnum') || {};
35   grep $hashref->{ $_->tagnum }, $cust_main->cust_tag;
36 }
37
38 sub condition_sql {
39   my( $self, $table ) = @_;
40
41   my $matching_tags = 
42     "SELECT tagnum FROM cust_tag WHERE cust_tag.custnum = $table.custnum".
43     " AND cust_tag.tagnum IN ".
44     $self->condition_sql_option_option_integer('tagnum');
45
46   "EXISTS($matching_tags)";
47 }
48
49 1;