1 package FS::part_event::Condition::pkg_age;
4 use base qw( FS::part_event::Condition );
5 use FS::Record qw( qsearch );
11 sub eventtable_hashref {
21 'age' => { 'label' => 'Package date age',
24 'field' => { 'label' => 'Compare date',
27 setup last_bill bill adjourn susp expire cancel contract_end
30 'setup' => 'Setup date',
31 'last_bill' => 'Last bill date',
32 'bill' => 'Next bill date',
33 'adjourn' => 'Adjournment date',
34 'susp' => 'Suspension date',
35 'expire' => 'Expiration date',
36 'cancel' => 'Cancellation date',
37 'contract_end' => 'Contract end date',
44 my( $self, $cust_pkg, %opt ) = @_;
46 my $age = $self->option_age_from('age', $opt{'time'} );
48 my $pkg_date = $cust_pkg->get( $self->option('field') );
50 $pkg_date && $pkg_date <= $age;
55 my( $class, $table, %opt ) = @_;
56 my $age = $class->condition_sql_option_age_from('age', $opt{'time'});
57 my $field = $class->condition_sql_option('field');
58 #amazingly, this is actually faster
60 foreach( qw(setup last_bill bill adjourn susp expire cancel contract_end) ) {
61 $sql .= " WHEN $field = '$_' THEN (cust_pkg.$_ IS NOT NULL AND cust_pkg.$_ <= $age)";