1 package FS::part_event::Condition::balance_age;
5 use Time::Local qw(timelocal_nocheck);
7 use base qw( FS::part_event::Condition );
9 sub description { 'Customer balance age'; }
13 'balance' => { 'label' => 'Balance over',
15 'value' => '0.00', #default
17 'age' => { 'label' => 'Age',
24 my($self, $object, %opt) = @_;
26 my $cust_main = $self->cust_main($object);
28 my $over = $self->option('balance');
29 $over = 0 unless length($over);
31 #false laziness w/cust_bill_age
32 my $time = $opt{'time'};
33 my $age = $self->option('age');
34 $age = '0m' unless length($age);
36 my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($time) )[0,1,2,3,4,5];
37 if ( $age =~ /^(\d+)m$/i ) {
39 until ( $mon >= 0 ) { $mon += 12; $year--; }
40 } elsif ( $age =~ /^(\d+)y$/i ) {
42 } elsif ( $age =~ /^(\d+)w$/i ) {
44 } elsif ( $age =~ /^(\d+)d$/i ) {
46 } elsif ( $age =~ /^(\d+)h$/i ) {
49 die "unparsable age: $age";
51 my $age_date = timelocal_nocheck($sec,$min,$hour,$mday,$mon,$year);
53 $cust_main->balance_date($age_date) > $over;
57 my( $class, $table, %opt ) = @_;
59 my $over = $class->condition_sql_option('balance');
60 my $age = $class->condition_sql_option_age_from('age', $opt{'time'});
62 my $balance_sql = FS::cust_main->balance_date_sql( $age );
64 "$balance_sql > $over";
68 shift->condition_sql_option_age('age');
71 use FS::UID qw( driver_name );
73 sub order_sql_weight {