X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_event%2FCondition%2Fpkg_age.pm;h=4a85387803e4dbe4ea9ccc27edd07191daf91218;hb=06e353b743e7be88afa8fce50ea10f27ebb7adef;hp=8b3b4c971f82b2709ef75682319032b081f3a103;hpb=624b2d44625f69d71175c3348cae635d580c890b;p=freeside.git diff --git a/FS/FS/part_event/Condition/pkg_age.pm b/FS/FS/part_event/Condition/pkg_age.pm index 8b3b4c971..4a8538780 100644 --- a/FS/FS/part_event/Condition/pkg_age.pm +++ b/FS/FS/part_event/Condition/pkg_age.pm @@ -49,10 +49,18 @@ sub condition { } -#XXX write me for efficiency -#sub condition_sql { -# -#} +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) ) { + $sql .= " WHEN $field = '$_' THEN (cust_pkg.$_ IS NOT NULL AND cust_pkg.$_ <= $age)"; + } + $sql .= ' END )'; + return $sql; +} 1;