From 028c83edfa000f6bdbcd32ee3ffd5ee5561110d2 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Tue, 6 May 2014 18:53:46 -0700 Subject: [PATCH] config to turn on term discounts feature, fixing perf problems entering payments / manually processing cards, RT#27038 --- FS/FS/Conf.pm | 7 +++++++ httemplate/edit/cust_pay.cgi | 10 ++++++---- httemplate/elements/tr-select-discount_term.html | 5 ++++- httemplate/misc/payment.cgi | 10 ++++++---- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 4b55f65a1..f1893b7a4 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -5701,6 +5701,13 @@ and customer address. Include units.', }, }, + { + 'key' => 'part_pkg-term_discounts', + 'section' => 'billing', + 'description' => 'Enable the term discounts feature. Recommended to keep turned off unless actually using - not well optimized for large installations.', + 'type' => 'checkbox', + }, + { key => "apacheroot", section => "deprecated", description => "DEPRECATED", type => "text" }, { key => "apachemachine", section => "deprecated", description => "DEPRECATED", type => "text" }, { key => "apachemachines", section => "deprecated", description => "DEPRECATED", type => "text" }, diff --git a/httemplate/edit/cust_pay.cgi b/httemplate/edit/cust_pay.cgi index d4414e44e..ec7391b20 100755 --- a/httemplate/edit/cust_pay.cgi +++ b/httemplate/edit/cust_pay.cgi @@ -56,10 +56,12 @@ <% mt('by') |h %> <% mt(FS::payby->payname($payby)) |h %> - <& /elements/tr-select-discount_term.html, - 'custnum' => $custnum, - 'amount_id' => 'paid', - &> +% if ( $conf->exists('part_pkg-term_discounts') ) { + <& /elements/tr-select-discount_term.html, + 'custnum' => $custnum, + '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 d4218f848..171c1037a 100644 --- a/httemplate/elements/tr-select-discount_term.html +++ b/httemplate/elements/tr-select-discount_term.html @@ -34,8 +34,8 @@ function change_discount_term(what) { % } - <%init> + my %opt = @_; my $custnum = $opt{'custnum'}; @@ -45,7 +45,10 @@ my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ) 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; diff --git a/httemplate/misc/payment.cgi b/httemplate/misc/payment.cgi index 5b9f63dc0..90b03c7e8 100644 --- a/httemplate/misc/payment.cgi +++ b/httemplate/misc/payment.cgi @@ -20,10 +20,12 @@ 'surcharge_percentage' => scalar($conf->config('credit-card-surcharge-percentage')), &> - <& /elements/tr-select-discount_term.html, - 'custnum' => $custnum, - 'amount_id' => 'amount', - &> +% if ( $conf->exists('part_pkg-term_discounts') ) { + <& /elements/tr-select-discount_term.html, + 'custnum' => $custnum, + 'amount_id' => 'amount', + &> +% } % if ( $payby eq 'CARD' ) { % -- 2.11.0