summaryrefslogtreecommitdiff
path: root/FS/FS/part_event/Condition
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2013-07-23 12:20:00 -0700
committerIvan Kohler <ivan@freeside.biz>2013-07-23 12:20:00 -0700
commit04e3881b4d2d515464eec0573782d4eac7e08e7c (patch)
tree1b943a608e355fd630d4bd4ba1f43c4e014f2e6e /FS/FS/part_event/Condition
parent095f0bf409cc1e30e6ce583b2f48e639ad79b8b2 (diff)
add "Package Age Younger" condition, RT#23171
Diffstat (limited to 'FS/FS/part_event/Condition')
-rw-r--r--FS/FS/part_event/Condition/pkg_age.pm64
1 files changed, 7 insertions, 57 deletions
diff --git a/FS/FS/part_event/Condition/pkg_age.pm b/FS/FS/part_event/Condition/pkg_age.pm
index de58970..6629e9d 100644
--- a/FS/FS/part_event/Condition/pkg_age.pm
+++ b/FS/FS/part_event/Condition/pkg_age.pm
@@ -1,67 +1,17 @@
package FS::part_event::Condition::pkg_age;
+use base qw( FS::part_event::Condition::pkg_age_Common );
use strict;
-use base qw( FS::part_event::Condition );
-use FS::Record qw( qsearch );
-sub description {
- 'Package Age';
-}
-
-sub eventtable_hashref {
- { 'cust_main' => 0,
- 'cust_bill' => 0,
- 'cust_pkg' => 1,
- };
-}
-
-#something like this
-sub option_fields {
- (
- 'age' => { 'label' => 'Package date age',
- 'type' => 'freq',
- },
- 'field' => { 'label' => 'Compare date',
- 'type' => 'select',
- 'options' => [qw(
- setup last_bill bill adjourn susp expire cancel contract_end
- )],
- 'labels' => {
- 'setup' => 'Setup date',
- 'last_bill' => 'Last bill date',
- 'bill' => 'Next bill date',
- 'adjourn' => 'Adjournment date',
- 'susp' => 'Suspension date',
- 'expire' => 'Expiration date',
- 'cancel' => 'Cancellation date',
- 'contract_end' => 'Contract end date',
- },
- },
- );
-}
+sub description { 'Package Age'; }
-sub condition {
- my( $self, $cust_pkg, %opt ) = @_;
+sub pkg_age_operator { '<='; }
- my $age = $self->option_age_from('age', $opt{'time'} );
-
- my $pkg_date = $cust_pkg->get( $self->option('field') );
-
- $pkg_date && $pkg_date <= $age;
-
-}
+sub pkg_age_label { 'Package date age older than'; }
-sub condition_sql {
- my( $class, $table, %opt ) = @_;
- my $age = $class->condition_sql_option_age_from('age', $opt{'time'});
- my $field = $class->condition_sql_option('field');
-#amazingly, this is actually faster
- my $sql = '( CASE';
- foreach( qw(setup last_bill bill adjourn susp expire cancel contract_end) ) {
- $sql .= " WHEN $field = '$_' THEN (cust_pkg.$_ IS NOT NULL AND cust_pkg.$_ <= $age)";
- }
- $sql .= ' END )';
- return $sql;
+sub pkg_age_compare {
+ my( $self, $pkg_date, $age ) = @_;
+ $pkg_date <= $age;
}
1;