1 package FS::part_event::Condition::balance_age_on_day;
4 use base qw( FS::part_event::Condition );
5 use Time::Local qw(timelocal);
7 sub description { 'Customer balance age on a day last month'; }
11 'balance' => { 'label' => 'Balance over',
13 'value' => '0.00', #default
15 'day' => { 'label' => 'Day of month',
17 'options' => [ 1..28 ]
19 'age' => { 'label' => 'Balance age on that day',
26 my($self, $object, %opt) = @_;
28 my $cust_main = $self->cust_main($object);
30 my $over = $self->option('balance');
31 $over = 0 unless length($over);
33 my $day = $self->option('day');
34 my $as_of = $opt{'time'};
37 my ($month, $year) = (localtime($opt{'time'}))[4,5];
43 $as_of = timelocal(0,0,0,$day,$month,$year);
46 my $age = $self->option_age_from('age', $as_of );
48 my $sql = $cust_main->balance_date_sql(
49 $age, # latest invoice date to consider
50 undef, # earliest invoice date
51 'cutoff' => $as_of, # ignore applications after this date
52 'unapplied_date' => 1 # ignore unapplied payments after $age
54 $sql = "SELECT ($sql) FROM cust_main WHERE custnum = ".$cust_main->custnum;
55 FS::Record->scalar_sql($sql) > $over;
58 # XXX do this if needed
59 #sub condition_sql { }