[freeside-commits] freeside/FS/FS/part_event/Condition cust_bill_owed_on_day.pm, NONE, 1.1.2.2 balance_age_on_day.pm, NONE, 1.1.2.2
Mark Wells
mark at wavetail.420.am
Thu Jan 19 20:55:21 PST 2012
Update of /home/cvs/cvsroot/freeside/FS/FS/part_event/Condition
In directory wavetail.420.am:/tmp/cvs-serv17823/FS/FS/part_event/Condition
Added Files:
Tag: FREESIDE_2_3_BRANCH
cust_bill_owed_on_day.pm balance_age_on_day.pm
Log Message:
delayed late fee conditions, #15957
--- NEW FILE: balance_age_on_day.pm ---
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;
--- NEW FILE: cust_bill_owed_on_day.pm ---
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;
More information about the freeside-commits
mailing list