X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_event%2FCondition%2Fbalance_age.pm;h=701dafdfe9ab640e8792cc5c1661b5af5f666f74;hb=529413f23d545179ff07ac393713a225a78014c2;hp=f1a9707960d6550d7a55be16eaa5ae78d5664a7a;hpb=40a7b3dc653e099f7bd0bd762b649b04c4432db2;p=freeside.git diff --git a/FS/FS/part_event/Condition/balance_age.pm b/FS/FS/part_event/Condition/balance_age.pm index f1a970796..701dafdfe 100644 --- a/FS/FS/part_event/Condition/balance_age.pm +++ b/FS/FS/part_event/Condition/balance_age.pm @@ -5,6 +5,46 @@ use base qw( FS::part_event::Condition ); sub description { 'Customer balance age'; } +=item check_options OPTIONS + +Validate options + +=cut + +my $duration_rx = qr/^(\d+)$/; +my $unit_rx = qr/^[wmdh]$/; +my $both_rx = qr/^(\d+)([wmdh])/; + +sub check_options { + my ($self, $options) = @_; + + my $age = $options->{age}; + my $age_units = $options->{age_units}; + + return "Invalid (age) must be defined: $age" + unless( defined $age ); + + # over-ride possibly inaccurate unit indicator + if( $age =~ /$both_rx/ ){ + $age = $1; + $age_units = $2; + } + + return "Invalid (age_units) must be defined: $age_units" + unless defined $age_units; + + return "Invalid (age) must be integer: $age" + unless( $age =~ /$duration_rx/ ); + + return "Invalid (age) must be non-zero: $age" + if ( $age == 0 ); + + return( "Invalid (age_units) must be m/w/d/h: $age_units" ) + unless( $age_units =~ /$unit_rx/i ); + + return ''; +} + sub option_fields { ( 'balance' => { 'label' => 'Balance over', @@ -38,15 +78,13 @@ sub condition_sql { my $balance_sql = FS::cust_main->balance_date_sql( $age ); - "$balance_sql > CAST( $over AS numeric )"; + "$balance_sql > CAST( $over AS DECIMAL(10,2) )"; } sub order_sql { shift->condition_sql_option_age('age'); } -use FS::UID qw( driver_name ); - sub order_sql_weight { 10; }