RT#42043: Check for cancelled packages with a cancellation date age option [hasnt...
[freeside.git] / FS / FS / part_event / Condition / hasnt_pkgpart_cancelled.pm
1 package FS::part_event::Condition::hasnt_pkgpart_cancelled;
2 use base qw( FS::part_event::Condition );
3
4 use strict;
5
6 sub description { 'Customer does not have canceled 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'    => 'Packages: ',
18                       'type'     => 'select-part_pkg',
19                       'multiple' => 1,
20                     },
21     'age'        => { 'label'      => 'Cancellation in last',
22                       'type'       => 'freq',
23                     },
24   );
25 }
26
27 sub condition {
28   my( $self, $object, %opt ) = @_;
29
30   my $cust_main = $self->cust_main($object);
31
32   my $age = $self->option_age_from('age', $opt{'time'} );
33
34   my $if_pkgpart = $self->option('if_pkgpart') || {};
35   ! grep { $if_pkgpart->{ $_->pkgpart } && $_->get('cancel') > $age }
36     $cust_main->cancelled_pkgs;
37
38 }
39
40 #XXX 
41 #sub condition_sql {
42 #
43 #}
44
45 1;
46