fix edge case with prorate_defer_bill, #15432
[freeside.git] / FS / FS / part_pkg / prorate_Mixin.pm
index 7d68be0..78a0893 100644 (file)
@@ -98,8 +98,12 @@ sub calc_prorate {
     my $months = ( ( $self->freq - 1 ) + ($mend-$mnow) / ($mend-$mstart) );
 
     # add a full period if currently billing for a partial period
-    if ( ( $self->option('add_full_period',1) 
-        or $self->option('prorate_defer_bill',1) ) # necessary
+    # or periods up to freq_override if billing for an override interval
+    if ( ($param->{'freq_override'} || 0) > 1 ) {
+      $months += $param->{'freq_override'} - 1;
+    }
+    elsif ( ( $self->option('add_full_period',1) 
+        or $self->option('prorate_defer_bill',1) )
         and $months < $self->freq ) {
       $months += $self->freq;
       $$sdate = $self->add_freq($mstart);
@@ -127,10 +131,12 @@ sub prorate_setup {
       and $cutoff_day
   ) {
     my ($mnow, $mend, $mstart) = $self->_endpoints($sdate, $cutoff_day);
-    # if today is the cutoff day, set the next bill to right now instead 
-    # of waiting a month.
+    # If today is the cutoff day, set the next bill and setup both to 
+    # midnight today, so that the customer will be billed normally for a 
+    # month starting today.
     if ( $mnow - $mstart < 86400 ) {
-      $cust_pkg->bill($mnow);
+      $cust_pkg->setup($mstart);
+      $cust_pkg->bill($mstart);
     }
     else {
       $cust_pkg->bill($mend);