1 package FS::part_event::Condition::pkg_age_Common;
2 use base qw( FS::part_event::Condition );
7 tie our %dates, 'Tie::IxHash',
8 'setup' => 'Setup date',
9 'last_bill' => 'Last bill date',
10 'bill' => 'Next bill date',
11 'adjourn' => 'Adjournment date',
12 'susp' => 'Suspension date',
13 'expire' => 'Expiration date',
14 'cancel' => 'Cancellation date',
15 'contract_end' => 'Contract end date',
18 sub eventtable_hashref {
29 'age' => { 'label' => $class->pkg_age_label,
32 'field' => { 'label' => 'Compare date',
34 'options' => [ keys %dates ],
41 my( $self, $cust_pkg, %opt ) = @_;
43 my $age = $self->option_age_from('age', $opt{'time'} );
45 my $pkg_date = $cust_pkg->get( $self->option('field') );
47 $pkg_date && $self->pkg_age_compare( $pkg_date, $age );
52 my( $class, $table, %opt ) = @_;
53 my $age = $class->condition_sql_option_age_from('age', $opt{'time'});
54 my $field = $class->condition_sql_option('field');
55 my $op = $class->pkg_age_operator;
57 #amazingly, this is actually faster
59 foreach ( keys %dates ) {
60 $sql .= " WHEN $field = '$_' THEN ".
61 " (cust_pkg.$_ IS NOT NULL AND cust_pkg.$_ $op $age)";