1 package FS::part_event::Condition::cust_bill_owed_on_day;
4 use base qw( FS::part_event::Condition );
5 use Time::Local qw(timelocal);
7 sub description { 'Amount owed on the invoice on a day last month' };
9 sub eventtable_hashref {
15 'balance' => { 'label' => 'Balance over',
17 'value' => '0.00', #default
19 'day' => { 'label' => 'Day of month',
21 'options' => [ 1..28 ]
23 'age' => { 'label' => 'Minimum invoice age on that day',
30 my($self, $object, %opt) = @_;
32 my $cust_bill = $object;
34 my $over = $self->option('balance');
35 $over = 0 unless length($over);
37 my $day = $self->option('day');
38 my $as_of = $opt{'time'};
41 my ($month, $year) = (localtime($opt{'time'}))[4,5];
47 $as_of = timelocal(0,0,0,$day,$month,$year);
51 my $age = $self->option_age_from('age', $as_of );
52 return 0 if $cust_bill->_date > $age;
54 # check balance on the specified day
55 my $sql = $cust_bill->owed_sql( $as_of );
57 $sql = "SELECT ($sql) FROM cust_bill WHERE invnum = ".$cust_bill->invnum;
58 FS::Record->scalar_sql($sql) > $over;
61 # XXX do this if needed
62 #sub condition_sql { }