+=item _items_discounts_avail
+
+Returns an array of line item hashrefs representing available term discounts
+for this invoice. This makes the same assumptions that apply to term
+discounts in general: that the package is billed monthly, at a flat rate,
+with no usage charges. A prorated first month will be handled, as will
+a setup fee if the discount is allowed to apply to setup fees.
+
+=cut
+
+sub _items_discounts_avail {
+ my $self = shift;
+ my $list_pkgnums = 0; # if any packages are not eligible for all discounts
+
+ my %plans = $self->discount_plans;
+
+ $list_pkgnums = grep { $_->list_pkgnums } values %plans;
+
+ map {
+ my $months = $_;
+ my $plan = $plans{$months};
+
+ my $term_total = sprintf('%.2f', $plan->discounted_total);
+ my $percent = sprintf('%.0f',
+ 100 * (1 - $term_total / $plan->base_total) );
+ my $permonth = sprintf('%.2f', $term_total / $months);
+ my $detail = $self->mt('discount on item'). ' '.
+ join(', ', map { "#$_" } $plan->pkgnums)
+ if $list_pkgnums;
+
+ +{
+ description => $self->mt('Save [_1]% by paying for [_2] months',
+ $percent, $months),
+ amount => $self->mt('[_1] ([_2] per month)',
+ $term_total, $money_char.$permonth),
+ ext_description => ($detail || ''),
+ }
+ } #map
+ sort { $b <=> $a } keys %plans;
+
+}
+