From: mark Date: Fri, 20 Jan 2012 04:55:18 +0000 (+0000) Subject: delayed late fee conditions, #15957 X-Git-Tag: freeside_2_3_1~6 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=cc8222b36f680b9f39370852be49807f033babc6 delayed late fee conditions, #15957 --- diff --git a/FS/FS/part_event/Condition/balance_age_on_day.pm b/FS/FS/part_event/Condition/balance_age_on_day.pm new file mode 100644 index 000000000..9c7efdd76 --- /dev/null +++ b/FS/FS/part_event/Condition/balance_age_on_day.pm @@ -0,0 +1,61 @@ +package FS::part_event::Condition::balance_age_on_day; + +use strict; +use base qw( FS::part_event::Condition ); +use Time::Local qw(timelocal); + +sub description { 'Customer balance age on a day last month'; } + +sub option_fields { + ( + 'balance' => { 'label' => 'Balance over', + 'type' => 'money', + 'value' => '0.00', #default + }, + 'day' => { 'label' => 'Day of month', + 'type' => 'select', + 'options' => [ 1..28 ] + }, + 'age' => { 'label' => 'Balance age on that day', + 'type' => 'freq', + }, + ); +} + +sub condition { + my($self, $object, %opt) = @_; + + my $cust_main = $self->cust_main($object); + + my $over = $self->option('balance'); + $over = 0 unless length($over); + + my $day = $self->option('day'); + my $as_of = $opt{'time'}; + + if ( $day ) { + my ($month, $year) = (localtime($opt{'time'}))[4,5]; + $month--; + if ( $month < 0 ) { + $month = 11; + $year--; + } + $as_of = timelocal(0,0,0,$day,$month,$year); + } + + my $age = $self->option_age_from('age', $as_of ); + + my $sql = $cust_main->balance_date_sql( + $age, # latest invoice date to consider + undef, # earliest invoice date + 'cutoff' => $as_of, # ignore applications after this date + 'unapplied_date' => 1 # ignore unapplied payments after $age + ); + $sql = "SELECT ($sql) FROM cust_main WHERE custnum = ".$cust_main->custnum; + FS::Record->scalar_sql($sql) > $over; +} + +# XXX do this if needed +#sub condition_sql { } + +1; diff --git a/FS/FS/part_event/Condition/cust_bill_owed_on_day.pm b/FS/FS/part_event/Condition/cust_bill_owed_on_day.pm new file mode 100644 index 000000000..41c4519a8 --- /dev/null +++ b/FS/FS/part_event/Condition/cust_bill_owed_on_day.pm @@ -0,0 +1,64 @@ +package FS::part_event::Condition::cust_bill_owed_on_day; + +use strict; +use base qw( FS::part_event::Condition ); +use Time::Local qw(timelocal); + +sub description { 'Amount owed on the invoice on a day last month' }; + +sub eventtable_hashref { + { 'cust_bill' => 1 }; +} + +sub option_fields { + ( + 'balance' => { 'label' => 'Balance over', + 'type' => 'money', + 'value' => '0.00', #default + }, + 'day' => { 'label' => 'Day of month', + 'type' => 'select', + 'options' => [ 1..28 ] + }, + 'age' => { 'label' => 'Minimum invoice age on that day', + 'type' => 'freq', + }, + ); +} + +sub condition { + my($self, $object, %opt) = @_; + + my $cust_bill = $object; + + my $over = $self->option('balance'); + $over = 0 unless length($over); + + my $day = $self->option('day'); + my $as_of = $opt{'time'}; + + if ( $day ) { + my ($month, $year) = (localtime($opt{'time'}))[4,5]; + $month--; + if ( $month < 0 ) { + $month = 11; + $year--; + } + $as_of = timelocal(0,0,0,$day,$month,$year); + } + + # check invoice date + my $age = $self->option_age_from('age', $as_of ); + return 0 if $cust_bill->_date > $age; + + # check balance on the specified day + my $sql = $cust_bill->owed_sql( $as_of ); + + $sql = "SELECT ($sql) FROM cust_bill WHERE invnum = ".$cust_bill->invnum; + FS::Record->scalar_sql($sql) > $over; +} + +# XXX do this if needed +#sub condition_sql { } + +1;