X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Frecur_Common.pm;h=05e1efb028c10a854218143fdb18ddde9bab05f5;hb=a067102c0d7c19e1206c7ad44ac067e55b1b3024;hp=21a78c00a5aef19e7369cbfa08cb5278c698514b;hpb=ced6be92d868addbed9ff93b39bbd6a1f634bcb7;p=freeside.git diff --git a/FS/FS/part_pkg/recur_Common.pm b/FS/FS/part_pkg/recur_Common.pm index 21a78c00a..05e1efb02 100644 --- a/FS/FS/part_pkg/recur_Common.pm +++ b/FS/FS/part_pkg/recur_Common.pm @@ -4,9 +4,9 @@ use strict; use vars qw( @ISA %info %recur_method ); use Tie::IxHash; use Time::Local; -use FS::part_pkg::prorate_Mixin; +use FS::part_pkg::flat; -@ISA = qw(FS::part_pkg::prorate_Mixin); +@ISA = qw(FS::part_pkg::flat); %info = ( 'disabled' => 1 ); #recur_Common not a usable price plan directly @@ -16,6 +16,11 @@ 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 calc_recur_Common { my $self = shift; my($cust_pkg, $sdate, $details, $param ) = @_; #only need $sdate & $param @@ -25,32 +30,40 @@ 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',1)) - ) { - $charges = $self->calc_prorate(@_); + + $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'}; + } } - else { - - $charges = $self->option('recur_fee'); + elsif ( $recur_method eq 'subscription' ) { - if ( $recur_method eq 'subscription' ) { + my $cutoff_day = $self->option('cutoff_day', 1) || 1; + 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 eq 'subscription' - }#$recur_method eq 'subscription' $charges -= $self->calc_discount( $cust_pkg, $sdate, $details, $param ); - }#$recur_method eq 'prorate' or ... }#increment_next_bill return $charges;