combine ticket notification scrips, #15353
[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', $_) } @discount_term },
28         curr_value => '',
29         onchange => $amount_id ? 'change_discount_term(this)' : '',
30       &>
31     </TD>
32   </TR>
33
34 % }
35
36 <%init>
37 my %opt = @_;
38
39 my $custnum = $opt{'custnum'};
40
41 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
42   or die "unknown custnum $custnum\n";
43
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;
51 }
52
53 # the DOM id of an input to be disabled/populated with the amount due
54 my $amount_id = $opt{'amount_id'};
55
56 </%init>