+ elsif ( $discount->amount && $discount->months == 1) {
+ $discount_left = $param->{'setup_charge'} - $discount->amount;
+ $amount = $param->{'setup_charge'} if $discount_left < 0;
+ $amount = $discount->amount if $discount_left >= 0;
+ $months = 1;
+
+ # transfer remainder of discount, if any, to recur
+ $param->{'discount_left_recur'}{$discount->discountnum} =
+ 0 - $discount_left if $discount_left < 0;
+ }
+ else {
+ next;
+ }
+ }
+ elsif ( defined $param->{'discount_left_recur'}{$discount->discountnum}
+ && $param->{'discount_left_recur'}{$discount->discountnum} > 0) {
+ # use up transferred remainder of discount from setup
+ $amount = $param->{'discount_left_recur'}{$discount->discountnum};
+ $param->{'discount_left_recur'}{$discount->discountnum} = 0;
+ $months = 1;