merging RT 4.0.6
[freeside.git] / FS / FS / part_event / Condition / pkg_dundate_age.pm
1 package FS::part_event::Condition::pkg_dundate_age;
2 use base qw( FS::part_event::Condition );
3
4 use strict;
5
6 sub description {
7   "Skip until specified # of days before package suspension delay date";
8 }
9
10
11 sub option_fields {
12   (
13     'age'     => { 'label'      => 'Time before suspension delay date',
14                    'type'       => 'freq',
15                  },
16   );
17 }
18
19 sub eventtable_hashref {
20   { 'cust_main' => 0,
21     'cust_bill' => 0,
22     'cust_pkg'  => 1,
23   };
24 }
25
26 sub condition {
27   my($self, $cust_pkg, %opt) = @_;
28
29   my $age = $self->option_age_from('age', $opt{'time'} );
30
31   $cust_pkg->dundate <= $age;
32 }
33
34 sub condition_sql {
35   my( $class, $table, %opt ) = @_;
36   return 'true' unless $table eq 'cust_pkg';
37   
38   my $age = $class->condition_sql_option_age_from('age', $opt{'time'});
39   
40   "COALESCE($table.dundate,0) <= ". $age;
41 }
42
43 1;