+my @discount_term = ();
+my %discounted_total = ();
+
+#this is inefficient for many years worth of invoices
+my $last_bill = ($cust_main->cust_bill)[-1];
+
+if ( $last_bill ) { # if not, there are no discounts possible
+ my %plans = $last_bill->discount_plans;
+ @discount_term = sort { $a <=> $b } keys %plans;
+ %discounted_total = map { $_, $plans{$_}->discounted_total } @discount_term;
+}
+
+# the DOM id of an input to be disabled/populated with the amount due
+my $amount_id = $opt{'amount_id'};