[freeside-commits] freeside/httemplate/elements tr-select-discount_term.html, 1.1, 1.2

Mark Wells mark at wavetail.420.am
Tue Dec 6 21:50:35 PST 2011


Update of /home/cvs/cvsroot/freeside/httemplate/elements
In directory wavetail.420.am:/tmp/cvs-serv25294/httemplate/elements

Modified Files:
	tr-select-discount_term.html 
Log Message:
minor refactor and better safeguards on term discounts, #15068

Index: tr-select-discount_term.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/elements/tr-select-discount_term.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- tr-select-discount_term.html	22 Sep 2010 19:16:18 -0000	1.1
+++ tr-select-discount_term.html	7 Dec 2011 05:50:33 -0000	1.2
@@ -1,12 +1,33 @@
 % if ( scalar(@discount_term) ) {
   <TR>
-    <TD ALIGN="right">Prepayment for</TD>
+    <TD ALIGN="right"><% emt('Prepayment for') %></TD>
+%  if ( $amount_id ) {
+    <SCRIPT type="text/javascript">
+var discounted_total = <% encode_json \%discounted_total %>;
+function change_discount_term(what) {
+  var new_term = what.value;
+  var amount_field = document.getElementById('<% $amount_id %>');
+  if(new_term == "") {
+    amount_field.readOnly = false;
+    amount_field.value = '';
+  }
+  else {
+    amount_field.value = discounted_total[new_term];
+    amount_field.readOnly = true;
+  }
+}
+</SCRIPT>
+% }
     <TD COLSPAN=2>
-      <% include('select-discount_term.html',
-                   'discount_term' => \@discount_term,
-                   'cgi'           => $opt{'cgi'},
-                )
-      %>
+      <& select.html,
+        field   => 'discount_term',
+        id      => 'discount_term',
+        options => [ '', @discount_term ],
+        labels  => { '' => mt('1 month'), 
+                     map { $_ => mt('[_1] months', $_) } @discount_term },
+        curr_value => '',
+        onchange => $amount_id ? 'change_discount_term(this)' : '',
+      &>
     </TD>
   </TR>
 
@@ -20,6 +41,16 @@
 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
   or die "unknown custnum $custnum\n";
 
-my @discount_term = $cust_main->discount_terms;
+my @discount_term = ();
+my %discounted_total = ();
+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'};
 
 </%init>



More information about the freeside-commits mailing list