X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Frecur_Common.pm;h=fc87628ea99ad179eaf9b00a4143ca6960a09f0f;hp=9d7341b76a6209414e74a52acb80039510c18dbd;hb=74f4610304eb373363ac07fc6e655d16c5f0ed33;hpb=f3c4966ed1f6ec3db7accd6dcdd3a5a3821d72a7 diff --git a/FS/FS/part_pkg/recur_Common.pm b/FS/FS/part_pkg/recur_Common.pm index 9d7341b76..fc87628ea 100644 --- a/FS/FS/part_pkg/recur_Common.pm +++ b/FS/FS/part_pkg/recur_Common.pm @@ -21,32 +21,39 @@ sub base_recur { sub calc_setup { # moved from all descendant packages which just had $self->option('setup_fee') - my($self, $cust_pkg, $sdate, $details, $param) = @_; + my($self, $cust_pkg, $time, $details, $param) = @_; - return 0 if $self->prorate_setup($cust_pkg, $sdate); + return 0 if $self->prorate_setup($cust_pkg, $time); 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); + $discount = $self->calc_discount($cust_pkg, \$time, $details, $param); delete $param->{'setup_charge'}; } - sprintf('%.2f', $charge - $discount); + sprintf('%.2f', ($cust_pkg->quantity || 1) * ($charge - $discount) ); } sub cutoff_day { # prorate/subscription only; we don't support sync_bill_date here - my $self = shift; - my $cust_pkg = shift; + my( $self, $cust_pkg ) = @_; 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 (); - } + my $cust_main = $cust_pkg->cust_main; + + return ( $cust_main->prorate_day ) + if $cust_main->prorate_day and ( $cust_main->force_prorate_day + || $recur_method eq 'prorate' + || $recur_method eq 'subscription' + ); + + return split(/\s*,\s*/, $self->option('cutoff_day', 1) || '1') + if $recur_method eq 'prorate' + || $recur_method eq 'subscription'; + + return (); } sub calc_recur_Common { @@ -60,7 +67,7 @@ sub calc_recur_Common { my $recur_method = $self->option('recur_method', 1) || 'anniversary'; my @cutoff_day = $self->cutoff_day($cust_pkg); - $charges = $self->base_recur($cust_pkg); + $charges = $self->base_recur($cust_pkg, $sdate, $details, $param); $charges += $param->{'override_charges'} if $param->{'override_charges'}; if ( $recur_method eq 'prorate' ) {