- $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;
-
- }
-
- $list_pkgnums = grep { $_->{list_pkgnums} > 0 } values %terms;
-
- foreach my $months (keys %terms) {
- my $hash = $terms{$months};
- my $term_total = sprintf('%.2f', $hash->{discounted});
- # possibly shouldn't include previous balance in these?
- my $percent = sprintf('%.0f', 100 * (1 - $term_total / $hash->{base}) );
+ my $term_total = sprintf('%.2f', $plan->discounted_total);
+ my $percent = sprintf('%.0f',
+ 100 * (1 - $term_total / $plan->base_total) );