X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Fdiscount_Mixin.pm;h=ec37624f2ad8cb1345a5ad9040d4b3012a736de5;hb=57bb423fe457ba4e13726877f53bcdf944f828f8;hp=1e39f6aefb82135bf5ea7fdff123b0cd8bedbd56;hpb=f641486e28214ad1eca18c47d2252701b83614f1;p=freeside.git diff --git a/FS/FS/part_pkg/discount_Mixin.pm b/FS/FS/part_pkg/discount_Mixin.pm index 1e39f6aef..ec37624f2 100644 --- a/FS/FS/part_pkg/discount_Mixin.pm +++ b/FS/FS/part_pkg/discount_Mixin.pm @@ -4,6 +4,7 @@ use strict; use vars qw( %info ); use Time::Local qw( timelocal ); use List::Util qw( min ); +use FS::Record qw( qsearchs ); use FS::cust_pkg; use FS::cust_bill_pkg_discount; @@ -45,7 +46,11 @@ sub calc_discount { my $conf = new FS::Conf; my $br = $self->base_recur($cust_pkg, $sdate); - $br += $param->{'override_charges'} * ($cust_pkg->part_pkg->freq || 0) if $param->{'override_charges'}; + + ## can not multiply non monthly recurring frequency so skip. + unless ($cust_pkg->part_pkg->freq !~ /^\d+$/) { + $br += $param->{'override_charges'} * ($cust_pkg->part_pkg->freq || 0) if $param->{'override_charges'}; + } my $tot_discount = 0; #UI enforces just 1 for now, will need ordering when they can be stacked @@ -97,7 +102,10 @@ sub calc_discount { # $chg_months: the number of months we are charging recur for # $months: $chg_months or the months left on the discount, whchever is less - my $chg_months = $cust_pkg->part_pkg->freq || 1; + my $chg_months = 1; + unless ($cust_pkg->part_pkg->freq !~ /^\d+$/) { + $chg_months = $cust_pkg->part_pkg->freq || 1; + } if ( defined($param->{'months'}) ) { # then override $chg_months = $param->{'months'}; } @@ -141,11 +149,15 @@ sub calc_discount { } else { # we are calculating a recurring fee discount. estimate the recurring - # fee: - # XXX it would be more accurate for calc_recur to just _tell us_ what - # it's going to charge + # fee. Note we use $months here rather than $chg_months so that if the + # remaining discount amount is for less time than the package period, + # the "estimated recurring fee" is only for as long as the discount + # lasts. + + # can not multiply non monthly recurring frequency so skip. + next if $self->freq !~ /^\d+$/; - my $recur_charge = $br * ($cust_pkg->quantity || 1) * $chg_months / $self->freq; + my $recur_charge = $br * $months / $self->freq; # round this, because the real recur charge is rounded $recur_charge = sprintf('%.2f', $recur_charge); @@ -232,7 +244,6 @@ sub calc_discount { 'pkgdiscountnum' => $cust_pkg_discount->pkgdiscountnum, 'amount' => $amount, 'months' => $months, - # 'setuprecur' is implied by the cust_pkg_discount link }; push @{ $param->{'discounts'} }, $cust_bill_pkg_discount; $tot_discount += $amount;