From cb43a46ebb3d5c5ce8b60707093a53e8bb2e8f9b Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 14 Mar 2011 23:39:14 +0000 Subject: [PATCH] fix prorates & recurring fees with recur_Common-using packages, RT#11993 --- FS/FS/part_pkg/flat.pm | 4 ++-- FS/FS/part_pkg/prorate.pm | 5 ----- FS/FS/part_pkg/prorate_Mixin.pm | 13 ++++++++++++- FS/FS/part_pkg/recur_Common.pm | 18 +++++++++--------- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm index fdf08c99b..d4b95b510 100644 --- a/FS/FS/part_pkg/flat.pm +++ b/FS/FS/part_pkg/flat.pm @@ -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) ) { diff --git a/FS/FS/part_pkg/prorate.pm b/FS/FS/part_pkg/prorate.pm index f6f2abd6f..31fee85ce 100644 --- a/FS/FS/part_pkg/prorate.pm +++ b/FS/FS/part_pkg/prorate.pm @@ -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(@_); diff --git a/FS/FS/part_pkg/prorate_Mixin.pm b/FS/FS/part_pkg/prorate_Mixin.pm index 1aa2f2c0c..7bdb66680 100644 --- a/FS/FS/part_pkg/prorate_Mixin.pm +++ b/FS/FS/part_pkg/prorate_Mixin.pm @@ -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 diff --git a/FS/FS/part_pkg/recur_Common.pm b/FS/FS/part_pkg/recur_Common.pm index 05e1efb02..b6bfd6ff8 100644 --- a/FS/FS/part_pkg/recur_Common.pm +++ b/FS/FS/part_pkg/recur_Common.pm @@ -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 ); -- 2.11.0