[freeside-commits] freeside/FS/FS/cust_main Billing.pm,1.31,1.32
Erik Levinson
levinse at wavetail.420.am
Tue May 3 16:26:10 PDT 2011
Update of /home/cvs/cvsroot/freeside/FS/FS/cust_main
In directory wavetail.420.am:/tmp/cvs-serv21881/FS/FS/cust_main
Modified Files:
Billing.pm
Log Message:
configurable ignore time portion of billing timestamp when billing
Index: Billing.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main/Billing.pm,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -w -d -r1.31 -r1.32
--- Billing.pm 25 Apr 2011 04:37:08 -0000 1.31
+++ Billing.pm 3 May 2011 23:26:08 -0000 1.32
@@ -20,6 +20,7 @@
use FS::part_event;
use FS::part_event_condition;
use FS::pkg_category;
+use POSIX;
# 1 is mostly method/subroutine entry and options
# 2 traces progress of some operations
@@ -112,7 +113,7 @@
my $job = $options{'job'};
$job->update_statustext('0,cleaning expired packages') if $job;
- $error = $self->cancel_expired_pkgs( $options{actual_time} );
+ $error = $self->cancel_expired_pkgs( $self->day_end( $options{actual_time} ) );
if ( $error ) {
$error = "Error expiring custnum ". $self->custnum. ": $error";
if ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; }
@@ -120,7 +121,7 @@
else { warn $error; }
}
- $error = $self->suspend_adjourned_pkgs( $options{actual_time} );
+ $error = $self->suspend_adjourned_pkgs( $self->day_end( $options{actual_time} ) );
if ( $error ) {
$error = "Error adjourning custnum ". $self->custnum. ": $error";
if ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; }
@@ -164,6 +165,19 @@
}
+sub day_end {
+ # XXX: sometimes "incorrect" if crossing DST boundaries?
+
+ my $self = shift;
+ my $time = shift;
+
+ return $time unless $conf->exists('next-bill-ignore-time');
+
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
+ localtime($time);
+ mktime(59,59,23,$mday,$mon,$year,$wday,$yday,$isdst);
+}
+
sub cancel_expired_pkgs {
my ( $self, $time, %options ) = @_;
@@ -833,7 +847,7 @@
and ( $options{'resetup'}
|| ( ! $cust_pkg->setup
&& ( ! $cust_pkg->start_date
- || $cust_pkg->start_date <= $time
+ || $cust_pkg->start_date <= $self->day_end($time)
)
&& ( ! $conf->exists('disable_setup_suspended_pkgs')
|| ( $conf->exists('disable_setup_suspended_pkgs') &&
@@ -878,7 +892,7 @@
if ( ! $cust_pkg->start_date
and ( ! $cust_pkg->susp || $part_pkg->option('suspend_bill', 1) )
and
- ( $part_pkg->freq ne '0' && ( $cust_pkg->bill || 0 ) <= $time )
+ ( $part_pkg->freq ne '0' && ( $cust_pkg->bill || 0 ) <= $self->day_end($time) )
|| ( $part_pkg->plan eq 'voip_cdr'
&& $part_pkg->option('bill_every_call')
)
@@ -902,7 +916,7 @@
#over two params! lets at least switch to a hashref for the rest...
my $increment_next_bill = ( $part_pkg->freq ne '0'
- && ( $cust_pkg->getfield('bill') || 0 ) <= $time
+ && ( $cust_pkg->getfield('bill') || 0 ) <= $self->day_end($time)
&& !$options{cancel}
);
my %param = ( 'precommit_hooks' => $precommit_hooks,
More information about the freeside-commits
mailing list