- my $discountable;
- if ( $discount->setup ) {
- $discountable += $setup;
- }
- else {
- $hash->{discounted} += $setup;
- }
-
- if ( $discount->percent ) {
- $discountable += $months * $permonth;
- $discountable -= ($discountable * $discount->percent / 100);
- $discountable -= ($permonth - $recur); # correct for prorate
- $hash->{discounted} += $discountable;
- }
- else {
- $discountable += $recur;
- $discountable -= $discount->amount * $recur/$permonth;
-
- $discountable += ($months - 1) * max($permonth - $discount->amount,0);
- }
-
- $hash->{discounted} += $discountable;
- push @{ $hash->{pkgnums} }, $cust_pkg->pkgnum;
- }
- else { #no discount
- $hash->{discounted} += $setup + $recur + ($months - 1) * $permonth;
- $hash->{list_pkgnums} = 1;
- }
- } #if $freq eq '1'
- else { # all non-monthly packages: include current charges only
- $hash->{discounted} += $setup + $recur;
- $hash->{base} += $setup + $recur;
- $hash->{list_pkgnums} = 1;
- }
- } #foreach $cust_bill_pkg
-
- # don't show this line if no packages have discounts at this term
- # or if there are no new charges to apply the discount to
- delete $terms{$months} if $hash->{base} == $hash->{discounted}
- or $hash->{base} == 0;