X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_event%2FCondition%2Fcust_bill_age.pm;h=2295e026de37d5bff84ecac0d0f7372ee9426ab9;hb=cc4caa54e9974ea3d6ac7cf55cf45863d2a8905e;hp=9af6bdd4b41302335af0328c156bf0631e636105;hpb=eb4ff7f73c5d4bdf74a3472448b5a195598ff4cd;p=freeside.git diff --git a/FS/FS/part_event/Condition/cust_bill_age.pm b/FS/FS/part_event/Condition/cust_bill_age.pm index 9af6bdd4b..2295e026d 100644 --- a/FS/FS/part_event/Condition/cust_bill_age.pm +++ b/FS/FS/part_event/Condition/cust_bill_age.pm @@ -1,14 +1,9 @@ package FS::part_event::Condition::cust_bill_age; -require 5.006; use strict; -use Time::Local qw(timelocal_nocheck); - use base qw( FS::part_event::Condition ); -sub description { - 'Invoice age'; -} +sub description { 'Invoice age'; } sub eventtable_hashref { { 'cust_main' => 0, @@ -17,10 +12,8 @@ sub eventtable_hashref { }; } -#something like this sub option_fields { ( - #'days' => { label=>'Days', size=>3, }, 'age' => { label=>'Age', type=>'freq', }, ); } @@ -28,52 +21,22 @@ sub option_fields { sub condition { my( $self, $cust_bill, %opt ) = @_; - #false laziness w/balance_age - my $time = $opt{'time'}; - my $age = $self->option('age'); - $age = '0m' unless length($age); + my $age = $self->option_age_from('age', $opt{'time'} ); - my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($time) )[0,1,2,3,4,5]; - if ( $age =~ /^(\d+)m$/i ) { - $mon -= $1; - until ( $mon >= 0 ) { $mon += 12; $year--; } - } elsif ( $age =~ /^(\d+)y$/i ) { - $year -= $1; - } elsif ( $age =~ /^(\d+)w$/i ) { - $mday -= $1 * 7; - } elsif ( $age =~ /^(\d+)d$/i ) { - $mday -= $1; - } elsif ( $age =~ /^(\d+)h$/i ) { - $hour -= $hour; - } else { - die "unparsable age: $age"; - } - my $age_date = timelocal_nocheck($sec,$min,$hour,$mday,$mon,$year); - - $cust_bill->_date <= $age_date; + ( $cust_bill->_date - 60 ) <= $age; } -# and seconds <= $time - cust_bill._date - sub condition_sql { my( $class, $table, %opt ) = @_; - my $time = $opt{'time'}; - - my $age = $class->condition_sql_option('age'); - my $age_sql = - "$time - EXTRACT( EPOCH FROM REPLACE( $age, 'm', 'mon')::interval )"; - - "cust_bill._date <= $age_sql"; + my $age = $class->condition_sql_option_age_from('age', $opt{'time'} ); + "( cust_bill._date - 60 ) <= $age"; } sub order_sql { - my( $class ) = @_; - - my $age = $class->condition_sql_option('age'); - "EXTRACT( EPOCH FROM REPLACE( $age, 'm', 'mon')::interval )"; + shift->condition_sql_option_age('age'); } sub order_sql_weight {