show more detail about payments on invoice, #21949
[freeside.git] / httemplate / elements / tr-select-discount_term.html
1 % if ( scalar(@discount_term) ) {
2   <TR>
3     <TD ALIGN="right"><% emt('Prepayment for') %></TD>
4 %  if ( $amount_id ) {
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 %>');
10   if(new_term == "") {
11     amount_field.readOnly = false;
12     amount_field.value = '';
13   }
14   else {
15     amount_field.value = discounted_total[new_term];
16     amount_field.readOnly = true;
17   }
18 }
19 </SCRIPT>
20 % }
21     <TD COLSPAN=2>
22       <& select.html,
23         field   => 'discount_term',
24         id      => 'discount_term',
25         options => [ '', @discount_term ],
26         labels  => { '' => mt('1 month'), 
27                      map { $_ => mt('[_1] months', sprintf('%.0f', $_)) }
28                       @discount_term
29                    },
30         curr_value => '',
31         onchange => $amount_id ? 'change_discount_term(this)' : '',
32       &>
33     </TD>
34   </TR>
35
36 % }
37
38 <%init>
39 my %opt = @_;
40
41 my $custnum = $opt{'custnum'};
42
43 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
44   or die "unknown custnum $custnum\n";
45
46 my @discount_term = ();
47 my %discounted_total = ();
48 my $last_bill = ($cust_main->cust_bill)[-1];
49 if ( $last_bill ) { # if not, there are no discounts possible
50   my %plans = $last_bill->discount_plans;
51   @discount_term = sort { $a <=> $b } keys %plans;
52   %discounted_total = map { $_, $plans{$_}->discounted_total } @discount_term;
53 }
54
55 # the DOM id of an input to be disabled/populated with the amount due
56 my $amount_id = $opt{'amount_id'};
57
58 </%init>