summaryrefslogtreecommitdiff
path: root/FS/FS/part_event/Condition/hasnt_pkgpart_cancelled.pm
blob: 42845cb8af56a692ec265da11ca12b1c5bb4e335 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package FS::part_event::Condition::hasnt_pkgpart_cancelled;
use base qw( FS::part_event::Condition );

use strict;

sub description { 'Customer does not have canceled specific package(s)'; }

sub eventtable_hashref {
    { 'cust_main' => 1,
      'cust_bill' => 1,
      'cust_pkg'  => 1,
    };
}

sub option_fields {
  ( 
    'if_pkgpart' => { 'label'    => 'Packages: ',
                      'type'     => 'select-part_pkg',
                      'multiple' => 1,
                    },
    'age_newest' => { 'label'      => 'Cancelled more than',
                      'type'       => 'freq',
                      'post_text'  => ' ago (blank for no limit)',
                      'allow_blank' => 1,
                    },
    'age'        => { 'label'      => 'Cancelled less than',
                      'type'       => 'freq',
                      'post_text'  => ' ago (blank for no limit)',
                      'allow_blank' => 1,
                    },
  );
}

sub condition {
  my( $self, $object, %opt ) = @_;

  my $cust_main = $self->cust_main($object);

  my $oldest = length($self->option('age')) ? $self->option_age_from('age', $opt{'time'} ) : 0;
  my $newest = $self->option_age_from('age_newest', $opt{'time'} );

  my $if_pkgpart = $self->option('if_pkgpart') || {};

  ! grep { $if_pkgpart->{ $_->pkgpart } && ($_->get('cancel') > $oldest) && ($_->get('cancel') <= $newest) }
    $cust_main->cancelled_pkgs;

}

#XXX 
#sub condition_sql {
#
#}

1;