From: ivan Date: Mon, 28 Apr 2008 19:17:00 +0000 (+0000) Subject: fix 1.9 queued billing from doing weird things with expirations and adjournments... X-Git-Tag: root_of_webpay_support~678 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=d8d9ab1e82463af03526f85c6c20b58881ddcfa4 fix 1.9 queued billing from doing weird things with expirations and adjournments because freeside-queued $^T != freeside-daily $^T --- diff --git a/FS/FS/Cron/bill.pm b/FS/FS/Cron/bill.pm index 7de2ff2f6..ad6498c74 100644 --- a/FS/FS/Cron/bill.pm +++ b/FS/FS/Cron/bill.pm @@ -115,33 +115,29 @@ END ### foreach my $custnum ( @custnums ) { + + my %args = ( + 'time' => $time, + 'invoice_time' => $invoice_time, + 'actual_time' => $^T, #when freeside-bill was started + #(not, when using -m, freeside-queued) + 'check_freq' => $check_freq, + 'resetup' => ( $opt{'s'} ? $opt{'s'} : 0 ), + ); if ( $opt{'m'} ) { #add job to queue that calls bill_and_collect with options - my $queue = new FS::queue { - 'job' => 'FS::cust_main::queued_bill', - 'secure' => 'Y', - }; - my $error = $queue->insert( - 'custnum' => $custnum, - 'time' => $time, - 'invoice_time' => $invoice_time, - 'check_freq' => $check_freq, - 'resetup' => $opt{'s'} ? $opt{'s'} : 0, - ); + my $queue = new FS::queue { + 'job' => 'FS::cust_main::queued_bill', + 'secure' => 'Y', + }; + my $error = $queue->insert( 'custnum'=>$custnum, %args ); } else { my $cust_main = qsearchs( 'cust_main', { 'custnum' => $custnum } ); - - $cust_main->bill_and_collect( - 'time' => $time, - 'invoice_time' => $invoice_time, - 'check_freq' => $check_freq, - 'resetup' => $opt{'s'}, - 'debug' => $debug, - ); + $cust_main->bill_and_collect( %args, 'debug' => $debug ); } diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 76cea831d..c28991fff 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1950,10 +1950,12 @@ sub bill_and_collect { # cancel packages ### - #$^T not $options{time} because freeside-daily -d is for pre-printing invoices - foreach my $cust_pkg ( - grep { $_->expire && $_->expire <= $^T } $self->ncancelled_pkgs - ) { + #$options{actual_time} not $options{time} because freeside-daily -d is for + #pre-printing invoices + my @cancel_pkgs = grep { $_->expire && $_->expire <= $options{actual_time} } + $self->ncancelled_pkgs; + + foreach my $cust_pkg ( @cancel_pkgs ) { my $error = $cust_pkg->cancel; warn "Error cancelling expired pkg ". $cust_pkg->pkgnum. " for custnum ". $self->custnum. ": $error" @@ -1964,15 +1966,22 @@ sub bill_and_collect { # suspend packages ### - #$^T not $options{time} because freeside-daily -d is for pre-printing invoices - foreach my $cust_pkg ( - grep { ( $_->part_pkg->is_prepaid && $_->bill && $_->bill < $^T - || $_->adjourn && $_->adjourn <= $^T - ) - && ! $_->susp + #$options{actual_time} not $options{time} because freeside-daily -d is for + #pre-printing invoices + my @susp_pkgs = + grep { ! $_->susp + && ( ( $_->part_pkg->is_prepaid + && $_->bill + && $_->bill < $options{actual_time} + ) + || ( $_->adjourn + && $_->adjourn <= $options{actual_time} + ) + ) } - $self->ncancelled_pkgs - ) { + $self->ncancelled_pkgs; + + foreach my $cust_pkg ( @susp_pkgs ) { my $error = $cust_pkg->suspend; warn "Error suspending package ". $cust_pkg->pkgnum. " for custnum ". $self->custnum. ": $error"