prorate option to round to full day, RT#7353
[freeside.git] / FS / FS / part_pkg / prorate_Mixin.pm
index a60858b..b77d898 100644 (file)
@@ -48,7 +48,7 @@ sub calc_prorate {
  
   my $charge = $self->option('recur_fee') || 0;
   my $cutoff_day;
-  if( $self->option('sync_bill_date') ) {
+  if( $self->option('sync_bill_date',1) ) {
     my $next_bill = $cust_pkg->cust_main->next_bill_date;
     if( defined($next_bill) and $next_bill != $$sdate ) {
       $cutoff_day = (localtime($next_bill))[3];
@@ -66,6 +66,10 @@ sub calc_prorate {
     # only works for freq >= 1 month; probably can't be fixed
     my $mnow = $$sdate;
     my ($sec, $min, $hour, $mday, $mon, $year) = (localtime($mnow))[0..5];
+    if ( $self->option('prorate_round_day',1) ) {
+      $mday++ if $hour >= 12;
+      $mnow = timelocal(0,0,0,$mday,$mon,$year);
+    }
     my $mend;
     my $mstart;
     if ( $mday >= $cutoff_day ) {
@@ -80,12 +84,19 @@ sub calc_prorate {
       $mstart = 
         timelocal(0,0,0,$cutoff_day,$mon == 0 ? 11 : $mon - 1,$year-($mon==11));
     }
-    
+   
+    # next bill date will be figured as $$sdate + one period
     $$sdate = $mstart;
 
     my $permonth = $self->option('recur_fee', 1) / $self->freq;
     my $months = ( ( $self->freq - 1 ) + ($mend-$mnow) / ($mend-$mstart) );
-    
+
+    if ( $self->option('add_full_period',1) ) {
+      # charge a full period in addition to the partial month
+      $months += $self->freq;
+      $$sdate = $self->add_freq($mstart);
+    }
+
     $param->{'months'} = $months;
     $charge = sprintf('%.2f', $permonth * $months);
   }