+ $months = 1; # XXX really? not $chg_months?
+ }
+ #elsif ( $discount->setup
+ # && ($discount->months || 0) == 1
+ # && $discount->amount > 0
+ # ) {
+ # next;
+ #
+ # RT #11512: bugfix to prevent applying flat discount to both setup
+ # and recur. The original implementation ignored discount_left_recur
+ # if it was zero, so if the setup fee used up the entire flat
+ # discount, the recurring charge would get to use the entire flat
+ # discount also. This bugfix was a kludge. Instead, we now allow
+ # discount_left_recur to be zero in that case, and then the available
+ # recur discount is zero.
+ #}
+
+ # Transfer remainder of discount, if any, to setup
+ # This is used when the recur phase wants to add a setup fee
+ # (prorate_defer_bill): the "discount_left_setup" amount will
+ # be subtracted in _make_lines.
+ if ( $discount->amount > 0 && ($discount->months || 0) != 1 )
+ {
+ # make sure there is a setup discount with this discountnum
+ # on the same package.
+ if ( qsearchs('cust_pkg_discount', {
+ pkgnum => $cust_pkg->pkgnum,
+ discountnum => $discount->discountnum,
+ setuprecur => 'setup'
+ }) )
+ {
+ # $amount is no longer permonth at this point! correct. very good.
+ $discount_left = $amount - $recur_charge; # backward, as above
+ if ( $discount_left > 0 ) {
+ $amount = $recur_charge;
+ $param->{'discount_left_setup'}{$discount->discountnum} =
+ 0 - $discount_left;
+ }
+ }
+ }
+
+ # cap the discount amount at the recur charge
+ $amount = min($amount, $recur_charge);