[freeside-commits] branch FREESIDE_3_BRANCH updated. aea97dbd5c5ac96c4610b112e55f64da66028ef6

Ivan ivan at 420.am
Thu Jan 28 16:23:43 PST 2016


The branch, FREESIDE_3_BRANCH has been updated
       via  aea97dbd5c5ac96c4610b112e55f64da66028ef6 (commit)
      from  bbdb9bc8f7fe69bb9b4fe4445f65479ef77f144e (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 aea97dbd5c5ac96c4610b112e55f64da66028ef6
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Thu Jan 28 16:23:42 2016 -0800

    optimize Reports->Customers->List Customers, RT#20173

diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index 671d16c..18624e6 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -204,6 +204,7 @@ sub new {
 
   $self->{'modified'} = 0;
 
+  $self->_simplecache($self->{'Hash'})  if $self->can('_simplecache');
   $self->_cache($self->{'Hash'}, shift) if $self->can('_cache') && @_;
 
   $self;
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index abbbc8d..6a5580a 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -56,18 +56,25 @@ $disable_agentcheck = 0;
 
 $upgrade = 0; #go away after setup+start dates cleaned up for old customers
 
-sub _cache {
-  my $self = shift;
-  my ( $hashref, $cache ) = @_;
-  #if ( $hashref->{'pkgpart'} ) {
+sub _simplecache {
+  my( $self, $hashref ) = @_;
   if ( $hashref->{'pkg'} ) {
-    # #@{ $self->{'_pkgnum'} } = ();
-    # my $subcache = $cache->subcache('pkgpart', 'part_pkg');
-    # $self->{'_pkgpart'} = $subcache;
-    # #push @{ $self->{'_pkgnum'} },
-    #   FS::part_pkg->new_or_cached($hashref, $subcache);
     $self->{'_pkgpart'} = FS::part_pkg->new($hashref);
   }
+}
+
+sub _cache {
+  my $self = shift;
+  my ( $hashref, $cache ) = @_;
+#  #if ( $hashref->{'pkgpart'} ) {
+#  if ( $hashref->{'pkg'} ) {
+#    # #@{ $self->{'_pkgnum'} } = ();
+#    # my $subcache = $cache->subcache('pkgpart', 'part_pkg');
+#    # $self->{'_pkgpart'} = $subcache;
+#    # #push @{ $self->{'_pkgnum'} },
+#    #   FS::part_pkg->new_or_cached($hashref, $subcache);
+#    $self->{'_pkgpart'} = FS::part_pkg->new($hashref);
+#  }
   if ( exists $hashref->{'svcnum'} ) {
     #@{ $self->{'_pkgnum'} } = ();
     my $subcache = $cache->subcache('svcnum', 'cust_svc', $hashref->{pkgnum});
diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm
index 3192f2f..da1f0ad 100644
--- a/FS/FS/part_pkg/flat.pm
+++ b/FS/FS/part_pkg/flat.pm
@@ -134,8 +134,11 @@ sub calc_setup {
 
 sub unit_setup {
   my($self, $cust_pkg, $sdate, $details ) = @_;
-
-  $self->option('setup_fee') || 0;
+  ( exists( $self->{'Hash'}{'_opt_setup_fee'} )
+      ? $self->{'Hash'}{'_opt_setup_fee'}
+      : $self->option('setup_fee', 1) 
+  )
+    || 0;
 }
 
 sub calc_recur {
@@ -185,7 +188,11 @@ sub cutoff_day {
 
 sub base_recur {
   my($self, $cust_pkg, $sdate) = @_;
-  $self->option('recur_fee', 1) || 0;
+  ( exists( $self->{'Hash'}{'_opt_recur_fee'} )
+      ? $self->{'Hash'}{'_opt_recur_fee'}
+      : $self->option('recur_fee', 1) 
+  )
+    || 0;
 }
 
 sub base_recur_permonth {
diff --git a/FS/FS/part_svc.pm b/FS/FS/part_svc.pm
index 8a5fc35..aba3ead 100644
--- a/FS/FS/part_svc.pm
+++ b/FS/FS/part_svc.pm
@@ -561,6 +561,9 @@ is specified as B<0>, returns the number of unlinked customer services.
 sub num_cust_svc {
   my $self = shift;
 
+  return $self->{Hash}{num_cust_svc}
+    if !@_ && exists($self->{Hash}{num_cust_svc});
+
   my @param = ( $self->svcpart );
 
   my( $join, $and ) = ( '', '' );
diff --git a/httemplate/search/cust_main.cgi b/httemplate/search/cust_main.cgi
index fb59882..ba80f02 100755
--- a/httemplate/search/cust_main.cgi
+++ b/httemplate/search/cust_main.cgi
@@ -119,9 +119,11 @@
 %    foreach my $cust_pkg ( @{$all_pkgs{$custnum}} ) {
 %      my %cust_svc_by_svcpart;
 %      my $rows = 0;
-%      foreach my $part_svc ( $cust_pkg->part_svc ) {
+%      foreach my $part_svc (
+%        $cust_pkg->part_svc( summarize_size=>$large_pkg_size )
+%      ) {
 %        my $svcpart = $part_svc->svcpart;
-%        my $num_cust_svc = $cust_pkg->num_cust_svc($svcpart);
+%        my $num_cust_svc = $part_svc->num_cust_svc;
 %        if ( $large_pkg_size > 0 and $num_cust_svc >= $large_pkg_size ) {
 %          # don't retrieve the cust_svc records, just stash the 
 %          # part_svc and num_cust_svc for later
@@ -130,7 +132,7 @@
 %          $rows += 2;
 %        }
 %        elsif ( $num_cust_svc ) {
-%          $cust_svc_by_svcpart{$svcpart} = [ $cust_pkg->cust_svc($svcpart) ];
+%          $cust_svc_by_svcpart{$svcpart} = $part_svc->cust_pkg_svc;
 %          $rows += $num_cust_svc;
 %        } #if summarize
 %      } #foreach $part_svc
@@ -482,7 +484,7 @@ if ( $cgi->param('browse')
     );
   }
 
-  @cust_main = grep { $_->ncancelled_pkgs || ! $_->all_pkgs } @cust_main
+  @cust_main = grep { $_->num_ncancelled_pkgs || ! $_->num_pkgs } @cust_main
     if ! $cgi->param('cancelled')
        && (
          $cgi->param('showcancelledcustomers') eq '0' #see if it was set by me
@@ -494,12 +496,30 @@ if ( $cgi->param('browse')
   @cust_main = grep { !$saw{$_->custnum}++ } @cust_main;
 }
 
-my %all_pkgs;
-if ( $conf->exists('hidecancelledpackages' ) ) {
-  %all_pkgs = map { $_->custnum => [ $_->ncancelled_pkgs ] } @cust_main;
-} else {
-  %all_pkgs = map { $_->custnum => [ $_->all_pkgs ] } @cust_main;
-}
+my $pkgs_method = $conf->exists('hidecancelledpackages')
+                    ? 'ncancelled_pkgs'
+                    : 'all_pkgs';
+
+#false laziness w/httemplate/view/cust_main/packages.html
+my $select = '*, setup_option.optionvalue AS _opt_setup_fee, '.
+                'recur_option.optionvalue AS _opt_recur_fee',
+my $addl_from = qq{
+    LEFT JOIN part_pkg USING ( pkgpart )
+    LEFT JOIN part_pkg_option AS setup_option
+      ON (     cust_pkg.pkgpart = setup_option.pkgpart
+           AND setup_option.optionname = 'setup_fee' )
+    LEFT JOIN part_pkg_option AS recur_option
+      ON (     cust_pkg.pkgpart = recur_option.pkgpart
+           AND recur_option.optionname = 'recur_fee' )
+};
+
+my %all_pkgs = map { $_->custnum =>
+                       [ $_->$pkgs_method({ select    => $select,
+                                            addl_from => $addl_from,
+                                         })
+                       ];
+                   }
+                 @cust_main;
 
 sub last_sort {
   lc($a->getfield('last')) cmp lc($b->getfield('last'))

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

Summary of changes:
 FS/FS/Record.pm                 |    1 +
 FS/FS/cust_pkg.pm               |   25 +++++++++++++++---------
 FS/FS/part_pkg/flat.pm          |   13 ++++++++++---
 FS/FS/part_svc.pm               |    3 +++
 httemplate/search/cust_main.cgi |   40 +++++++++++++++++++++++++++++----------
 5 files changed, 60 insertions(+), 22 deletions(-)




More information about the freeside-commits mailing list