bill recurring packages up to current date, #12569
authormark <mark>
Mon, 9 May 2011 20:31:10 +0000 (20:31 +0000)
committermark <mark>
Mon, 9 May 2011 20:31:10 +0000 (20:31 +0000)
FS/FS/cust_main/Billing.pm
FS/FS/part_pkg/prorate_Mixin.pm

index 4c8d40f..f6a6080 100644 (file)
@@ -416,18 +416,27 @@ sub bill {
 
       my $pass = ($cust_pkg->no_auto || $part_pkg->no_auto) ? 'no_auto' : '';
 
-      my $error =
-        $self->_make_lines( 'part_pkg'            => $part_pkg,
-                            'cust_pkg'            => $cust_pkg,
-                            'precommit_hooks'     => \@precommit_hooks,
-                            'line_items'          => $cust_bill_pkg{$pass},
-                            'setup'               => $total_setup{$pass},
-                            'recur'               => $total_recur{$pass},
-                            'tax_matrix'          => $taxlisthash{$pass},
-                            'time'                => $time,
-                            'real_pkgpart'        => $real_pkgpart,
-                            'options'             => \%options,
-                          );
+      my $next_bill = $cust_pkg->getfield('bill') || 0;
+      my $error;
+      while ( $next_bill <= $time ) {
+        $error =
+          $self->_make_lines( 'part_pkg'            => $part_pkg,
+                              'cust_pkg'            => $cust_pkg,
+                              'precommit_hooks'     => \@precommit_hooks,
+                              'line_items'          => $cust_bill_pkg{$pass},
+                              'setup'               => $total_setup{$pass},
+                              'recur'               => $total_recur{$pass},
+                              'tax_matrix'          => $taxlisthash{$pass},
+                              'time'                => $time,
+                              'real_pkgpart'        => $real_pkgpart,
+                              'options'             => \%options,
+                            );
+        # Stop if anything goes wrong, or if we're not incrementing 
+        # the bill date.
+        last if $error;
+        last if ($cust_pkg->getfield('bill') || 0) == $next_bill;
+        $next_bill = $cust_pkg->getfield('bill') || 0;
+      }
       if ($error) {
         $dbh->rollback if $oldAutoCommit && !$options{no_commit};
         return $error;
index 29409fa..6d0c2da 100644 (file)
@@ -50,6 +50,7 @@ day arrives.
 sub calc_prorate {
   my ($self, $cust_pkg, $sdate, $details, $param, $cutoff_day) = @_;
   die "no cutoff_day" unless $cutoff_day;
+  die "can't prorate non-monthly package\n" if $self->freq =~ /\D/;
 
   my $charge = $self->base_recur($cust_pkg, $sdate) || 0;