X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_event%2FCondition%2Fbillday.pm;h=078166ddba24d013ce2ffa0ef77e140afdb95648;hb=4d2467d2b8c2134f8cab6907c675a9c4f56472ed;hp=b150a6cb834e43336b37bc9b9498b3caaed7ad06;hpb=867d4f2ed3127ec20548911b79017668b771331c;p=freeside.git diff --git a/FS/FS/part_event/Condition/billday.pm b/FS/FS/part_event/Condition/billday.pm index b150a6cb8..078166ddb 100644 --- a/FS/FS/part_event/Condition/billday.pm +++ b/FS/FS/part_event/Condition/billday.pm @@ -6,25 +6,48 @@ use Tie::IxHash; use base qw( FS::part_event::Condition ); sub description { - "Customer's monthly billing day matches current day or customer has no billing day"; + "Customer's monthly billing day is before or on current day or customer has no billing day"; +} + +sub option_fields { + ( + 'delay' => { label => 'Delay additional days', + type => 'text', + value => '0', + }, + ); } sub condition { - my( $self, $object ) = @_; + my( $self, $object, %opt ) = @_; my $cust_main = $self->cust_main($object); - my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + my $delay = $self->option('delay') || 0; + my $as_of = $opt{'time'} - $delay * 86400; # $opt{'time'}, not time() - ($mday == $cust_main->billday) || (!$cust_main->billday); + my ($mday) = (localtime($as_of))[3]; # what day it was $delay days before now + + (!$cust_main->billday) || ($mday >= $cust_main->billday); } sub condition_sql { - my( $self, $table ) = @_; - - my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); - - "cust_main.billday is null or cust_main.billday = $mday"; + my( $class, $table, %opt ) = @_; + my $delay = $class->condition_sql_option_integer('delay', + $opt{'driver_name'}); # returns 0 for null + my $as_of = $opt{'time'} . " - ($delay * 86400)"; # in seconds + my $mday; + if ( $opt{'driver_name'} eq 'Pg' ) { + $mday = "EXTRACT( DAY FROM TO_TIMESTAMP($as_of) )"; + } + elsif ( $opt{'driver_name'} eq 'mysql' ) { + $mday = "DAY( FROM_UNIXTIME($as_of) )"; + } + else { + return 'true' + } + + "cust_main.billday is null or $mday >= cust_main.billday"; } 1;