default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / FS / FS / part_event / Condition / has_pkgpart.pm
1 package FS::part_event::Condition::has_pkgpart;
2 use base qw( FS::part_event::Condition );
3
4 use strict;
5
6 sub description { 'Customer has uncancelled specific package(s)'; }
7
8 sub eventtable_hashref {
9     { 'cust_main' => 1,
10       'cust_bill' => 1,
11       'cust_pkg'  => 1,
12     };
13 }
14
15 sub option_fields {
16   ( 
17     'if_pkgpart' => { 'label'    => 'Only packages: ',
18                       'type'     => 'select-part_pkg',
19                       'multiple' => 1,
20                     },
21   );
22 }
23
24 sub condition {
25   my( $self, $object) = @_;
26
27   my $cust_main = $self->cust_main($object);
28
29   my $if_pkgpart = $self->option('if_pkgpart') || {};
30   grep $if_pkgpart->{ $_->pkgpart },
31          $cust_main->ncancelled_pkgs( 'skip_label_sort'=>1 );
32
33 }
34
35 sub condition_sql {
36   my( $self, $table ) = @_;
37
38   'ARRAY'. $self->condition_sql_option_option_integer('if_pkgpart').
39   ' && '. #overlap (have elements in common)
40   'ARRAY( SELECT pkgpart FROM cust_pkg AS has_pkgpart_cust_pkg
41             WHERE has_pkgpart_cust_pkg.custnum = cust_main.custnum
42               AND (    has_pkgpart_cust_pkg.cancel IS NULL
43                     OR has_pkgpart_cust_pkg.cancel = 0
44                   )
45         )
46   ';
47 }
48
49 1;