X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Frecur_Common.pm;h=7197eaeee95b0a8de071730532ed82b27eb03a9e;hb=729a3c80385332bd26f62024e5d955d58d1eb9e3;hp=05e1efb028c10a854218143fdb18ddde9bab05f5;hpb=1833cbb8c9a99ac9e650dda0a51bba492ad25c04;p=freeside.git diff --git a/FS/FS/part_pkg/recur_Common.pm b/FS/FS/part_pkg/recur_Common.pm index 05e1efb02..7197eaeee 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 base qw( FS::part_pkg::flat ); use strict; -use vars qw( @ISA %info %recur_method ); +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 @@ -21,6 +19,36 @@ sub base_recur { $self->option('recur_fee', 1) || 0; } +sub calc_setup { + # moved from all descendant packages which just had $self->option('setup_fee') + my($self, $cust_pkg, $sdate, $details, $param) = @_; + + return 0 if $self->prorate_setup($cust_pkg, $sdate); + + my $charge = $self->option('setup_fee'); + + my $discount = 0; + if ( $charge > 0 ) { + $param->{'setup_charge'} = $charge; + $discount = $self->calc_discount($cust_pkg, $sdate, $details, $param); + delete $param->{'setup_charge'}; + } + + sprintf('%.2f', $charge - $discount); +} + +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 @@ -30,27 +58,18 @@ sub calc_recur_Common { if ( $param->{'increment_next_bill'} ) { my $recur_method = $self->option('recur_method', 1) || 'anniversary'; - + 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' ) { - 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 - $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' ) { - my $cutoff_day = $self->option('cutoff_day', 1) || 1; + } elsif ( $recur_method eq 'subscription' ) { + my ($day, $mon, $year) = ( localtime($$sdate) )[ 3..5 ]; if ( $day < $cutoff_day ) { @@ -60,7 +79,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 );