[freeside-commits] freeside/FS/FS/part_event/Condition billday.pm, 1.3, 1.4
Mark Wells
mark at wavetail.420.am
Wed Nov 30 21:27:56 PST 2011
Update of /home/cvs/cvsroot/freeside/FS/FS/part_event/Condition
In directory wavetail.420.am:/tmp/cvs-serv5409/FS/FS/part_event/Condition
Modified Files:
billday.pm
Log Message:
improve "billing day" event condition, #10813
Index: billday.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_event/Condition/billday.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -d -r1.3 -r1.4
--- billday.pm 3 Jun 2011 18:10:22 -0000 1.3
+++ billday.pm 1 Dec 2011 05:27:54 -0000 1.4
@@ -13,33 +13,42 @@
(
'delay' => { label => 'Delay additional days',
type => 'text',
- value => '1',
+ 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()
- my $delay = $self->option('delay');
- $delay = 0 unless length($delay);
+ my ($mday) = (localtime($as_of))[3]; # what day it was $delay days before now
- (!$cust_main->billday) || ($mday >= $cust_main->billday + $delay);
+ (!$cust_main->billday) || ($mday >= $cust_main->billday);
}
sub condition_sql {
my( $class, $table, %opt ) = @_;
+ # ick
+ 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'
+ }
- my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
-
- my $delay = $class->condition_sql_option_integer('delay', $opt{'driver_name'});
-
- "cust_main.billday is null or $mday >= (cust_main.billday + $delay)";
+ "cust_main.billday is null or $mday >= cust_main.billday";
}
1;
More information about the freeside-commits
mailing list