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', $_) } @discount_term },
29 onchange => $amount_id ? 'change_discount_term(this)' : '',
39 my $custnum = $opt{'custnum'};
41 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
42 or die "unknown custnum $custnum\n";
44 my @discount_term = ();
45 my %discounted_total = ();
46 my $last_bill = ($cust_main->cust_bill)[-1];
47 if ( $last_bill ) { # if not, there are no discounts possible
48 my %plans = $last_bill->discount_plans;
49 @discount_term = sort { $a <=> $b } keys %plans;
50 %discounted_total = map { $_, $plans{$_}->discounted_total } @discount_term;
53 # the DOM id of an input to be disabled/populated with the amount due
54 my $amount_id = $opt{'amount_id'};