1 package FS::part_event::Condition::balance_age;
4 use base qw( FS::part_event::Condition );
6 sub description { 'Customer balance age'; }
8 =item check_options OPTIONS
14 my $duration_rx = qr/^(\d+)$/;
15 my $unit_rx = qr/^[wmdh]$/;
16 my $both_rx = qr/^(\d+)([wmdh])/;
19 my ($self, $options) = @_;
21 my $age = $options->{age};
22 my $age_units = $options->{age_units};
24 return "Invalid (age) must be defined: $age"
25 unless( defined $age );
27 # over-ride possibly inaccurate unit indicator
28 if( $age =~ /$both_rx/ ){
33 return "Invalid (age_units) must be defined: $age_units"
34 unless defined $age_units;
36 return "Invalid (age) must be integer: $age"
37 unless( $age =~ /$duration_rx/ );
39 return "Invalid (age) must be non-zero: $age"
42 return( "Invalid (age_units) must be m/w/d/h: $age_units" )
43 unless( $age_units =~ /$unit_rx/i );
50 'balance' => { 'label' => 'Balance over',
52 'value' => '0.00', #default
54 'age' => { 'label' => 'Age',
61 my($self, $object, %opt) = @_;
63 my $cust_main = $self->cust_main($object);
65 my $over = $self->option('balance');
66 $over = 0 unless length($over);
68 my $age = $self->option_age_from('age', $opt{'time'} );
70 $cust_main->balance_date($age) > $over;
74 my( $class, $table, %opt ) = @_;
76 my $over = $class->condition_sql_option('balance');
77 my $age = $class->condition_sql_option_age_from('age', $opt{'time'});
79 my $balance_sql = FS::cust_main->balance_date_sql( $age );
81 "$balance_sql > CAST( $over AS DECIMAL(10,2) )";
85 shift->condition_sql_option_age('age');
88 sub order_sql_weight {