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->pkg_age_age( $cust_pkg, %opt );
45 my $pkg_date = $cust_pkg->get( $self->option('field') );
47 $pkg_date && $self->pkg_age_compare( $pkg_date, $age );
52 my( $self, $cust_pkg, %opt ) = @_;
53 $self->option_age_from('age', $opt{'time'} );
56 #doesn't work if you override pkg_age_age,
57 # so if you do, override this with at least a stub that returns 'true'
59 my( $class, $table, %opt ) = @_;
60 my $age = $class->condition_sql_option_age_from('age', $opt{'time'});
61 my $field = $class->condition_sql_option('field');
62 my $op = $class->pkg_age_operator;
64 #amazingly, this is actually faster
66 foreach ( keys %dates ) {
67 $sql .= " WHEN $field = '$_' THEN ".
68 " (cust_pkg.$_ IS NOT NULL AND cust_pkg.$_ $op $age)";