fix v3 perf regression from #79636, RT#80177
[freeside.git] / FS / FS / Template_Mixin.pm
index 99019e9..e5a449a 100644 (file)
@@ -299,7 +299,7 @@ before that line item (quotations only)
 
 =item template
 
-Dprecated.  Used as a suffix for a configuration template.  Please 
+Deprecated.  Used as a suffix for a configuration template.  Please
 don't use this, it deprecated in favor of more flexible alternatives.
 
 =back
@@ -831,7 +831,7 @@ sub print_generic {
       $invoice_data{'previous_credits'} = [];
     }
  
-    if ( $conf->exists('invoice_usesummary', $agentnum) ) {
+    if ( $conf->config_bool('invoice_usesummary', $agentnum) ) {
       $invoice_data{'summarypage'} = $summarypage = 1;
     }
 
@@ -939,7 +939,7 @@ sub print_generic {
   my $multisection = $self->has_sections;
   $invoice_data{'multisection'} = $multisection;
   my $section_with_taxes = 1
-    if $conf->exists('invoice_sections_with_taxes');
+    if $conf->config_bool('invoice_sections_with_taxes', $cust_main->agentnum);
   my $late_sections;
   my $extra_sections = [];
   my $extra_lines = ();
@@ -1190,6 +1190,8 @@ sub print_generic {
 
     my %options = ();
     $options{'section'} = $section if $multisection;
+    $options{'section_with_taxes'} = 1
+      if $conf->config_bool('invoice_sections_with_taxes', $cust_main->agentnum);
     $options{'format'} = $format;
     $options{'escape_function'} = $escape_function;
     $options{'no_usage'} = 1 unless $unsquelched;
@@ -1377,7 +1379,7 @@ sub print_generic {
         $tax_section->{'description'} = $self->mt($tax_description);
         $tax_section->{'summarized'} = '';
 
-        if ( $conf->exists('invoice_sections_with_taxes')) {
+        if ( $conf->config_bool('invoice_sections_with_taxes', $cust_main->agentnum) ) {
 
           # remove tax section if taxes are itemized within other sections
           @sections = grep{ $_ ne $tax_section } @sections;
@@ -2028,8 +2030,8 @@ sub balance_due_msg {
   my $msg = $self->mt('Balance Due');
   return $msg unless $self->terms; # huh?
   if ( !$self->conf->exists('invoice_show_prior_due_date')
-       or $self->conf->exists('invoice_sections') ) {
-    # if enabled, the due date is shown with Total New Charges (see 
+       || $self->has_sections ) {
+    # if enabled, the due date is shown with Total New Charges (see
     # _items_total) and not here
     # (yes, or if invoice_sections is enabled; this is just for compatibility)
     if ( $self->due_date ) {
@@ -3131,7 +3133,7 @@ sub _items_fee {
     # but not escape the base description line
 
     my @pkg_tax = $cust_bill_pkg->_pkg_tax_list
-      if $self->conf->exists('invoice_sections_with_taxes');
+      if $options{section_with_taxes};
 
     push @items,
       { feepart     => $cust_bill_pkg->feepart,
@@ -3377,7 +3379,7 @@ sub _items_cust_bill_pkg {
                         );
 
       my @pkg_tax = $cust_bill_pkg->_pkg_tax_list
-        if $self->conf->exists('invoice_sections_with_taxes');
+        if $opt{section_with_taxes};
 
       if ( ref($cust_bill_pkg) eq 'FS::quotation_pkg' ) {
         # XXX this should be pulled out into quotation_pkg
@@ -3885,8 +3887,8 @@ sub has_sections {
 
   return 0 unless $self->invnum > 0;
 
-  $agentnum ||= $self->cust_main->agentnum;
-  return 1 if $self->conf->exists('invoice_sections', $agentnum);
+  $agentnum ||= $self->agentnum;
+  return 1 if $self->conf->config_bool('invoice_sections', $agentnum);
   return 1 if $self->conf->exists('sections_by_location', $agentnum);
 
   my $location_min = $self->conf->config(