[freeside-commits] branch master updated. 5dea8988e7a25387bb3a3fedff67b62851280016

Mitch Jackson mitch at freeside.biz
Tue Mar 27 22:45:52 PDT 2018


The branch, master has been updated
       via  5dea8988e7a25387bb3a3fedff67b62851280016 (commit)
      from  e75717bd49c68a49940ebd668368a6542097a234 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5dea8988e7a25387bb3a3fedff67b62851280016
Author: Mitch Jackson <mitch at freeside.biz>
Date:   Wed Mar 28 00:42:24 2018 -0500

    RT# 79636 Add conf flag invoice_sections_multilocation

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 721b7bdf9..9dd10a4c7 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -1583,6 +1583,15 @@ and customer address. Include units.',
     'per_agent'   => 1,
   },
 
+  {
+    'key'         => 'invoice_sections_multilocation',
+    'section'     => 'invoicing',
+    'description' => 'Enable invoice_sections for for any bill with at least this many locations on the bill.',
+    'type'        => 'text',
+    'per_agent'   => 1,
+    'validate'    => sub { shift =~ /^\d+$/ ? undef : 'Please enter a number' },
+  },
+
   { 
     'key'         => 'invoice_include_aging',
     'section'     => 'invoice_balances',
diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm
index a1ed4b0c0..3d206db2c 100644
--- a/FS/FS/Template_Mixin.pm
+++ b/FS/FS/Template_Mixin.pm
@@ -19,7 +19,7 @@ use HTML::Entities;
 use Cwd;
 use FS::UID;
 use FS::Misc qw( send_email );
-use FS::Record qw( qsearch qsearchs );
+use FS::Record qw( qsearch qsearchs dbh );
 use FS::Conf;
 use FS::Misc qw( generate_ps generate_pdf );
 use FS::pkg_category;
@@ -933,8 +933,6 @@ sub print_generic {
 
   my $unsquelched = $params{unsquelch_cdr} || $cust_main->squelch_cdr ne 'Y';
   my $multisection = $self->has_sections;
-  $conf->exists($tc.'sections', $cust_main->agentnum) ||
-                     $conf->exists($tc.'sections_by_location', $cust_main->agentnum);
   $invoice_data{'multisection'} = $multisection;
   my $late_sections;
   my $extra_sections = [];
@@ -3828,5 +3826,68 @@ sub _items_discounts_avail {
 
 }
 
+=item has_sections AGENTNUM
+
+Return true if invoice_sections should be enabled for this bill.
+ (Inherited by both cust_bill and cust_bill_void)
+
+Determination:
+* False if not an invoice
+* True always if conf invoice_sections is enabled
+* True always if sections_by_location is enabled
+* True if conf invoice_sections_multilocation > 1,
+  and location_count >= invoice_sections_multilocation
+* Else, False
+
+=cut
+
+sub has_sections {
+  my ($self, $agentnum) = @_;
+
+  return 0 unless $self->invnum > 0;
+
+  $agentnum ||= $self->cust_main->agentnum;
+  return 1 if $self->conf->exists('invoice_sections', $agentnum);
+  return 1 if $self->conf->exists('sections_by_location', $agentnum);
+
+  my $location_min = $self->conf->config(
+    'invoice_sections_multilocation', $agentnum,
+  );
+
+  return 1
+    if $location_min
+    && $self->location_count >= $location_min;
+
+  0;
+}
+
+
+=item location_count
+
+Return the number of locations billed on this invoice
+
+=cut
+
+sub location_count {
+  my ($self) = @_;
+  return 0 unless $self->invnum;
+
+  # SELECT COUNT( DISTINCT cust_pkg.locationnum )
+  # FROM cust_bill_pkg
+  # LEFT JOIN cust_pkg USING (pkgnum)
+  # WHERE invnum = 278
+  #   AND cust_bill_pkg.pkgnum > 0
+
+  my $result = qsearchs({
+    select    => 'COUNT(DISTINCT cust_pkg.locationnum) as location_count',
+    table     => 'cust_bill_pkg',
+    addl_from => 'LEFT JOIN cust_pkg USING (pkgnum)',
+    extra_sql => 'WHERE invnum = '.dbh->quote( $self->invnum )
+               . '  AND cust_bill_pkg.pkgnum > 0'
+  });
+  ref $result ? $result->location_count : 0;
+}
+
+
 
 1;
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index bd1b8bbec..942715b20 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -148,15 +148,6 @@ Invoices are normally created by calling the bill method of a customer object
 sub table { 'cust_bill'; }
 sub template_conf { 'invoice_'; }
 
-sub has_sections {
-  my $self = shift;
-  my $agentnum = $self->cust_main->agentnum;
-  my $tc = $self->template_conf;
-
-  $self->conf->exists($tc.'sections', $agentnum) ||
-  $self->conf->exists($tc.'sections_by_location', $agentnum);
-}
-
 # should be the ONLY occurrence of "Invoice" in invoice rendering code.
 # (except email_subject and invnum_date_pretty)
 sub notice_name {
diff --git a/FS/FS/cust_bill_void.pm b/FS/FS/cust_bill_void.pm
index 50f69c9fa..43b295014 100644
--- a/FS/FS/cust_bill_void.pm
+++ b/FS/FS/cust_bill_void.pm
@@ -119,15 +119,6 @@ sub table { 'cust_bill_void'; }
 sub notice_name { 'VOIDED Invoice'; }
 sub template_conf { 'invoice_'; }
 
-sub has_sections {
-  my $self = shift;
-  my $agentnum = $self->cust_main->agentnum;
-  my $tc = $self->template_conf;
-
-  $self->conf->exists($tc.'sections', $agentnum) ||
-  $self->conf->exists($tc.'sections_by_location', $agentnum);
-}
-
 
 =item insert
 
@@ -375,4 +366,3 @@ L<FS::Record>, schema.html from the base documentation.
 =cut
 
 1;
-

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Conf.pm           |  9 +++++++
 FS/FS/Template_Mixin.pm | 67 ++++++++++++++++++++++++++++++++++++++++++++++---
 FS/FS/cust_bill.pm      |  9 -------
 FS/FS/cust_bill_void.pm | 10 --------
 4 files changed, 73 insertions(+), 22 deletions(-)




More information about the freeside-commits mailing list