X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Felements%2Ftr-select-discount_term.html;h=171c1037a3a7aa32a9dd2bb41aaeafad4aa42710;hb=9270a9fe7ea00f5a24a9ce3b927f932db6650b23;hp=58582675d35681de0839ebe57c6ac48bc1bcd763;hpb=5250c44bd7f282c7d782bf0e8349af12376929df;p=freeside.git
diff --git a/httemplate/elements/tr-select-discount_term.html b/httemplate/elements/tr-select-discount_term.html
index 58582675d..171c1037a 100644
--- a/httemplate/elements/tr-select-discount_term.html
+++ b/httemplate/elements/tr-select-discount_term.html
@@ -1,18 +1,41 @@
% if ( scalar(@discount_term) ) {
- Prepayment for |
+ <% emt('Prepayment for') %> |
+% if ( $amount_id ) {
+
+% }
- <% 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', sprintf('%.0f', $_)) }
+ @discount_term
+ },
+ curr_value => '',
+ onchange => $amount_id ? 'change_discount_term(this)' : '',
+ &>
|
% }
-
<%init>
+
my %opt = @_;
my $custnum = $opt{'custnum'};
@@ -20,6 +43,19 @@ 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 = ();
+
+#this is inefficient for many years worth of invoices
+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>