X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Frecur_Common.pm;h=719fb234e846cbec8828335319db05e2c177fa9f;hb=ca3c2d180e6005dc10c1492b60e847ad32c99c57;hp=9a6774579bff7577e715289f6407327aab451bce;hpb=4117c20f85ce085d7dd42b8970ce9c65b95d7e27;p=freeside.git diff --git a/FS/FS/part_pkg/recur_Common.pm b/FS/FS/part_pkg/recur_Common.pm index 9a6774579..719fb234e 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::prorate_Mixin; - -@ISA = qw(FS::part_pkg::prorate_Mixin); %info = ( 'disabled' => 1 ); #recur_Common not a usable price plan directly @@ -16,6 +14,23 @@ tie %recur_method, 'Tie::IxHash', 'subscription' => 'Charge the full fee for the first partial period (selectable billing date)', ; +sub base_recur { + my $self = shift; + $self->option('recur_fee', 1) || 0; +} + +sub cutoff_day { + # prorate/subscription only; we don't support sync_bill_date here + my $self = shift; + my $cust_pkg = shift; + my $recur_method = $self->option('recur_method',1) || 'anniversary'; + if ( $recur_method eq 'prorate' or $recur_method eq 'subscription' ) { + return $self->option('cutoff_day',1) || 1; + } else { + return 0; + } +} + sub calc_recur_Common { my $self = shift; my($cust_pkg, $sdate, $details, $param ) = @_; #only need $sdate & $param @@ -25,32 +40,31 @@ sub calc_recur_Common { if ( $param->{'increment_next_bill'} ) { my $recur_method = $self->option('recur_method', 1) || 'anniversary'; - - if ( $recur_method eq 'prorate' - or ($recur_method eq 'anniversary' and $self->option('sync_bill_date')) - ) { - $charges = $self->calc_prorate(@_); - } - else { + my $cutoff_day = $self->cutoff_day($cust_pkg); + + $charges = $self->base_recur; + $charges += $param->{'override_charges'} if $param->{'override_charges'}; + + if ( $recur_method eq 'prorate' ) { + + $charges = $self->calc_prorate(@_, $cutoff_day); + $charges += $param->{'override_charges'} if $param->{'override_charges'}; - $charges = $self->option('recur_fee'); + } elsif ( $recur_method eq 'subscription' ) { - if ( $recur_method eq 'subscription' ) { + my ($day, $mon, $year) = ( localtime($$sdate) )[ 3..5 ]; - my $cutoff_day = $self->option('cutoff_day', 1) || 1; - my ($day, $mon, $year) = ( localtime($$sdate) )[ 3..5 ]; + if ( $day < $cutoff_day ) { + if ( $mon == 0 ) { $mon=11; $year--; } + else { $mon--; } + } - if ( $day < $cutoff_day ) { - if ( $mon == 0 ) { $mon=11; $year--; } - else { $mon--; } - } + $$sdate = timelocal(0, 0, 0, $cutoff_day, $mon, $year); - $$sdate = timelocal(0, 0, 0, $cutoff_day, $mon, $year); + }#$recur_method - }#$recur_method eq 'subscription' $charges -= $self->calc_discount( $cust_pkg, $sdate, $details, $param ); - }#$recur_method eq 'prorate' or ... }#increment_next_bill return $charges;