RT#42043: Check for cancelled packages with a cancellation date age option [hasnt...
[freeside.git] / FS / FS / part_event / Condition / hasnt_pkg_class_cancelled.pm
1 package FS::part_event::Condition::hasnt_pkg_class_cancelled;
2 use base qw( FS::part_event::Condition );
3
4 use strict;
5
6 sub description {
7   'Customer does not have canceled package with class';
8 }
9
10 sub eventtable_hashref {
11     { 'cust_main' => 1,
12       'cust_bill' => 1,
13       'cust_pkg'  => 1,
14     };
15 }
16
17 #something like this
18 sub option_fields {
19   (
20     'pkgclass'  => { 'label'    => 'Package Class',
21                      'type'     => 'select-pkg_class',
22                      'multiple' => 1,
23                    },
24     'age'       => { 'label'      => 'Cancellation in last',
25                      'type'       => 'freq',
26                    },
27   );
28 }
29
30 sub condition {
31   my( $self, $object, %opt ) = @_;
32
33   my $cust_main = $self->cust_main($object);
34
35   my $age = $self->option_age_from('age', $opt{'time'} );
36
37   #XXX test
38   my $hashref = $self->option('pkgclass') || {};
39   ! grep { $hashref->{ $_->part_pkg->classnum } && $_->get('cancel') > $age }
40     $cust_main->cancelled_pkgs;
41 }
42
43 1;
44