summaryrefslogtreecommitdiff
path: root/FS/FS/part_event/Condition/pkg_dundate_age.pm
blob: 75fce1fd24374a95d9ae92e1b1e9fca16f866d43 (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
package FS::part_event::Condition::pkg_dundate_age;
use base qw( FS::part_event::Condition );

use strict;

sub description {
  "Skip until specified # of days before package suspension delay date";
}


sub option_fields {
  (
    'age'     => { 'label'      => 'Time before suspension delay date',
                   'type'       => 'freq',
                 },
  );
}

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

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

  my $age = $self->option_age_from('age', $opt{'time'} );

  $cust_pkg->dundate <= $age;
}

sub condition_sql {
  my( $class, $table, %opt ) = @_;
  return 'true' unless $table eq 'cust_pkg';
  
  my $age = $class->condition_sql_option_age_from('age', $opt{'time'});
  
  "COALESCE($table.dundate,0) <= ". $age;
}

1;