- } elsif ( defined $param->{'discount_left_recur'}{$discount->discountnum}
- && $param->{'discount_left_recur'}{$discount->discountnum} > 0
- ) {
- # use up transferred remainder of discount from setup
+
+ } else {
+
+ # we are calculating a recurring fee discount. estimate the recurring
+ # 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 * $months / $self->freq;
+ # round this, because the real recur charge is rounded
+ $recur_charge = sprintf('%.2f', $recur_charge);
+
+ # if it's a percentage discount, calculate it based on that estimate.
+ # otherwise use the flat amount.
+
+ if ( $discount->percent > 0 ) {
+ $amount = $recur_charge * $discount->percent / 100;
+ } elsif ( $discount->amount > 0
+ and $cust_pkg->pkgpart == $param->{'real_pkgpart'} ) {
+ $amount = $discount->amount * $months;
+ }
+
+ if ( exists $param->{'discount_left_recur'}{$discount->discountnum} ) {
+ # there is a discount_left_recur entry for this discountnum, so this
+ # is the second (recur) pass on the discount. use up transferred
+ # remainder of discount from setup.
+ #
+ # note that discount_left_recur can now be zero.