summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authormark <mark>2011-12-07 05:50:33 +0000
committermark <mark>2011-12-07 05:50:33 +0000
commitee2ee290c82013f870e2b23e4235e70998e59ee1 (patch)
tree73ab6f5bd5d88a6dcabb13d48b6d951d5a7a8373 /httemplate
parent71d417238c392886be01ac93896399c3dbfa2e16 (diff)
minor refactor and better safeguards on term discounts, #15068
Diffstat (limited to 'httemplate')
-rwxr-xr-xhttemplate/edit/cust_pay.cgi4
-rw-r--r--httemplate/elements/tr-select-discount_term.html45
-rw-r--r--httemplate/misc/payment.cgi3
3 files changed, 42 insertions, 10 deletions
diff --git a/httemplate/edit/cust_pay.cgi b/httemplate/edit/cust_pay.cgi
index 0bb86e3..3fd9c79 100755
--- a/httemplate/edit/cust_pay.cgi
+++ b/httemplate/edit/cust_pay.cgi
@@ -43,12 +43,12 @@
<TR>
<TD ALIGN="right"><% mt('Amount') |h %></TD>
<TD BGCOLOR="#ffffff" ALIGN="right"><% $money_char %></TD>
- <TD><INPUT TYPE="text" NAME="paid" VALUE="<% $paid %>" SIZE=8 MAXLENGTH=9> <% mt('by') |h %> <B><% mt(FS::payby->payname($payby)) |h %></B></TD>
+ <TD><INPUT TYPE="text" NAME="paid" ID="paid" VALUE="<% $paid %>" SIZE=8 MAXLENGTH=9> <% mt('by') |h %> <B><% mt(FS::payby->payname($payby)) |h %></B></TD>
</TR>
<& /elements/tr-select-discount_term.html,
'custnum' => $custnum,
- 'cgi' => $cgi
+ 'amount_id' => 'paid',
&>
% if ( $payby eq 'BILL' ) {
diff --git a/httemplate/elements/tr-select-discount_term.html b/httemplate/elements/tr-select-discount_term.html
index 5858267..e9faeb2 100644
--- a/httemplate/elements/tr-select-discount_term.html
+++ b/httemplate/elements/tr-select-discount_term.html
@@ -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 $custnum = $opt{'custnum'};
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>
diff --git a/httemplate/misc/payment.cgi b/httemplate/misc/payment.cgi
index b2baebd..4a867d2 100644
--- a/httemplate/misc/payment.cgi
+++ b/httemplate/misc/payment.cgi
@@ -14,6 +14,7 @@
<TD COLSPAN=7>
<TABLE><TR><TD BGCOLOR="#ffffff">
<% $money_char %><INPUT NAME = "amount"
+ ID = "amount"
TYPE = "text"
VALUE = "<% $amount %>"
SIZE = 8
@@ -67,7 +68,7 @@
<& /elements/tr-select-discount_term.html,
'custnum' => $custnum,
- 'cgi' => $cgi
+ 'amount_id' => 'amount',
&>
% if ( $payby eq 'CARD' ) {