RT#42043: Check for cancelled packages with a cancellation date age option [age_newes...
[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_newest' => { 'label'      => 'Cancelled more than',
22                       'type'       => 'freq',
23                       'post_text'  => ' ago (blank for no limit)',
24                       'allow_blank' => 1,
25                     },
26     'age'        => { 'label'      => 'Cancelled less than',
27                       'type'       => 'freq',
28                       'post_text'  => ' ago (blank for no limit)',
29                       'allow_blank' => 1,
30                     },
31   );
32 }
33
34 sub condition {
35   my( $self, $object, %opt ) = @_;
36
37   my $cust_main = $self->cust_main($object);
38
39   my $oldest = length($self->option('age')) ? $self->option_age_from('age', $opt{'time'} ) : 0;
40   my $newest = $self->option_age_from('age_newest', $opt{'time'} );
41
42   my $if_pkgpart = $self->option('if_pkgpart') || {};
43
44   ! grep { $if_pkgpart->{ $_->pkgpart } && ($_->get('cancel') > $oldest) && ($_->get('cancel') <= $newest) }
45     $cust_main->cancelled_pkgs;
46
47 }
48
49 #XXX 
50 #sub condition_sql {
51 #
52 #}
53
54 1;
55