fix prorates & recurring fees with recur_Common-using packages, RT#11993
authorivan <ivan>
Mon, 14 Mar 2011 23:39:14 +0000 (23:39 +0000)
committerivan <ivan>
Mon, 14 Mar 2011 23:39:14 +0000 (23:39 +0000)
FS/FS/part_pkg/flat.pm
FS/FS/part_pkg/prorate.pm
FS/FS/part_pkg/prorate_Mixin.pm
FS/FS/part_pkg/recur_Common.pm

index fdf08c9..d4b95b5 100644 (file)
@@ -126,7 +126,7 @@ sub calc_recur {
     if $self->option('recur_temporality', 1) eq 'preceding' && $last_bill == 0;
 
   my $charge = $self->base_recur($cust_pkg, $sdate);
-  if ( my $cutoff_day = $self->cutoff_day($cust_pkg) ) {
+  if ( my $cutoff_day = $self->flat_cutoff_day($cust_pkg) ) {
     $charge = $self->calc_prorate(@_);
   }
   elsif ( $param->{freq_override} ) {
@@ -140,7 +140,7 @@ sub calc_recur {
   return sprintf('%.2f', $charge - $discount);
 }
 
-sub cutoff_day {
+sub flat_cutoff_day {
   my $self = shift;
   my $cust_pkg = shift;
   if ( $self->option('sync_bill_date',1) ) {
index f6f2abd..31fee85 100644 (file)
@@ -38,11 +38,6 @@ use FS::part_pkg::flat;
   'weight' => 20,
 );
 
-sub cutoff_day {
-  my $self = shift;
-  $self->option('cutoff_day', 1) || 1;
-}
-
 sub calc_recur {
   my $self = shift;
   return $self->calc_prorate(@_) - $self->calc_discount(@_);
index 1aa2f2c..7bdb666 100644 (file)
@@ -50,7 +50,7 @@ day arrives.
 sub calc_prorate {
   my $self  = shift;
   my ($cust_pkg, $sdate, $details, $param) = @_;
-  my $cutoff_day = $self->cutoff_day($cust_pkg) or return; #die?
+  my $cutoff_day = $self->cutoff_day or die "no cutoff_day"; #($cust_pkg)
 
   my $charge = $self->base_recur($cust_pkg, $sdate) || 0;
   if ( $cutoff_day ) {
@@ -90,6 +90,17 @@ sub calc_prorate {
   return $charge;
 }
 
+=item cutoff_day
+
+Returns the value of the "cutoff_day" option, or 1.
+
+=cut
+
+sub cutoff_day {
+  my $self = shift;
+  $self->option('cutoff_day', 1) || 1;
+}
+
 =item prorate_setup CUST_PKG SDATE
 
 Set up the package.  This only has an effect if prorate_defer_bill is 
index 05e1efb..b6bfd6f 100644 (file)
@@ -1,12 +1,10 @@
 package FS::part_pkg::recur_Common;
 
 use strict;
-use vars qw( @ISA %info %recur_method );
+use base qw( FS::part_pkg::flat );
+use vars qw( %info %recur_method );
 use Tie::IxHash;
 use Time::Local;
-use FS::part_pkg::flat;
-
-@ISA = qw(FS::part_pkg::flat);
 
 %info = ( 'disabled' => 1 ); #recur_Common not a usable price plan directly
 
@@ -35,20 +33,22 @@ sub calc_recur_Common {
     $charges += $param->{'override_charges'} if $param->{'override_charges'};
 
     if ( $recur_method eq 'prorate' ) {
+
       my $cutoff_day = $self->option('cutoff_day') || 1;
       $charges = $self->calc_prorate(@_, $cutoff_day);
       $charges += $param->{'override_charges'} if $param->{'override_charges'};
-    }
-    elsif ( $recur_method eq 'anniversary' and 
+
+    elsif ( $recur_method eq 'anniversary' and 
             $self->option('sync_bill_date',1) ) {
+
       my $next_bill = $cust_pkg->cust_main->next_bill_date;
       if ( defined($next_bill) ) {
         my $cutoff_day = (localtime($next_bill))[3];
         $charges = $self->calc_prorate(@_, $cutoff_day);
         $charges += $param->{'override_charges'} if $param->{'override_charges'};
       }
-    } 
-    elsif ( $recur_method eq 'subscription' ) {
+
+    elsif ( $recur_method eq 'subscription' ) {
 
       my $cutoff_day = $self->option('cutoff_day', 1) || 1;
       my ($day, $mon, $year) = ( localtime($$sdate) )[ 3..5 ];
@@ -60,7 +60,7 @@ sub calc_recur_Common {
 
       $$sdate = timelocal(0, 0, 0, $cutoff_day, $mon, $year);
 
-    }#$recur_method eq 'subscription'
+    }#$recur_method
 
     $charges -= $self->calc_discount( $cust_pkg, $sdate, $details, $param );