X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_event%2FCondition%2Fbalance_age.pm;h=f1a9707960d6550d7a55be16eaa5ae78d5664a7a;hb=ea3c94b9862524f0d17931e77bf3955bac5ad83f;hp=ec3624a6d838a4a84be3ca9461a59a067e8fc730;hpb=5e05724a635a22776f1b973f5d7e77989da4e048;p=freeside.git diff --git a/FS/FS/part_event/Condition/balance_age.pm b/FS/FS/part_event/Condition/balance_age.pm index ec3624a6d..f1a970796 100644 --- a/FS/FS/part_event/Condition/balance_age.pm +++ b/FS/FS/part_event/Condition/balance_age.pm @@ -1,9 +1,6 @@ package FS::part_event::Condition::balance_age; -require 5.006; use strict; -use Time::Local qw(timelocal_nocheck); - use base qw( FS::part_event::Condition ); sub description { 'Customer balance age'; } @@ -28,29 +25,9 @@ sub condition { my $over = $self->option('balance'); $over = 0 unless length($over); - #false laziness w/cust_bill_age - my $time = $opt{'time'}; - my $age = $self->option('age'); - $age = '0m' unless length($age); - - 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_main->balance_date($age_date) > $over; + my $age = $self->option_age_from('age', $opt{'time'} ); + + $cust_main->balance_date($age) > $over; } sub condition_sql { @@ -61,7 +38,7 @@ sub condition_sql { my $balance_sql = FS::cust_main->balance_date_sql( $age ); - "$balance_sql > $over"; + "$balance_sql > CAST( $over AS numeric )"; } sub order_sql {