fix 1.9 queued billing from doing weird things with expirations and adjournments...
authorivan <ivan>
Mon, 28 Apr 2008 19:17:00 +0000 (19:17 +0000)
committerivan <ivan>
Mon, 28 Apr 2008 19:17:00 +0000 (19:17 +0000)
FS/FS/Cron/bill.pm
FS/FS/cust_main.pm

index 7de2ff2..ad6498c 100644 (file)
@@ -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 );
 
     }
 
index 76cea83..c28991f 100644 (file)
@@ -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"