1 % if ( scalar(@discount_term) ) {
3 <TD ALIGN="right"><% emt('Prepayment for') %></TD>
5 <SCRIPT type="text/javascript">
6 var discounted_total = <% encode_json \%discounted_total %>;
7 function change_discount_term(what) {
8 var new_term = what.value;
9 var amount_field = document.getElementById('<% $amount_id %>');
11 amount_field.readOnly = false;
12 amount_field.value = '';
15 amount_field.value = discounted_total[new_term];
16 amount_field.readOnly = true;
23 field => 'discount_term',
24 id => 'discount_term',
25 options => [ '', @discount_term ],
26 labels => { '' => mt('1 month'),
27 map { $_ => mt('[_1] months', sprintf('%.0f', $_)) }
31 onchange => $amount_id ? 'change_discount_term(this)' : '',
41 my $custnum = $opt{'custnum'};
43 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
44 or die "unknown custnum $custnum\n";
46 my @discount_term = ();
47 my %discounted_total = ();
49 #this is inefficient for many years worth of invoices
50 my $last_bill = ($cust_main->cust_bill)[-1];
52 if ( $last_bill ) { # if not, there are no discounts possible
53 my %plans = $last_bill->discount_plans;
54 @discount_term = sort { $a <=> $b } keys %plans;
55 %discounted_total = map { $_, $plans{$_}->discounted_total } @discount_term;
58 # the DOM id of an input to be disabled/populated with the amount due
59 my $amount_id = $opt{'amount_id'};