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;
if ( $discount->percent > 0 ) {
$amount = $discount->percent * $param->{'setup_charge'} / 100;
- } elsif ( $discount->amount > 0 && ($discount->months || 0) == 1) {
+ } elsif ( $discount->amount > 0 ) {
# apply the discount amount, up to a maximum of the setup charge
$amount = min($discount->amount, $param->{'setup_charge'});
$discount_left = sprintf('%.2f', $discount->amount - $amount);
# transfer remainder of discount, if any, to recur
$param->{'discount_left_recur'}{$discount->discountnum} = $discount_left;
- } else {
- # I guess we don't allow multiple-month flat amount discounts to
- # apply to setup?
- next;
- }
+ }
} 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.
- 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);
'pkgdiscountnum' => $cust_pkg_discount->pkgdiscountnum,
'amount' => $amount,
'months' => $months,
- # XXX should have a 'setuprecur'
+ # XXX should have a 'setuprecur' (and on 4.x, it does)
};
push @{ $param->{'discounts'} }, $cust_bill_pkg_discount;
$tot_discount += $amount;