[freeside-commits] branch FREESIDE_3_BRANCH updated. f6a37fa1d6a30484ce8a268de170ecc8d5c31a23

Mark Wells mark at 420.am
Mon Aug 22 14:21:36 PDT 2016


The branch, FREESIDE_3_BRANCH has been updated
       via  f6a37fa1d6a30484ce8a268de170ecc8d5c31a23 (commit)
      from  f5935488fe25773db20f376150e24e35a123870a (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 f6a37fa1d6a30484ce8a268de170ecc8d5c31a23
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Aug 22 13:41:13 2016 -0700

    show data usage report link only for customers that might have data usage, #42310

diff --git a/FS/FS/cust_main/Packages.pm b/FS/FS/cust_main/Packages.pm
index 343112d..8f96f81 100644
--- a/FS/FS/cust_main/Packages.pm
+++ b/FS/FS/cust_main/Packages.pm
@@ -684,6 +684,28 @@ sub num_pkgs {
   $sth->fetchrow_arrayref->[0];
 }
 
+=item num_usage_pkgs
+
+Returns the number of packages for this customer that have services that
+can have RADIUS usage statistics.
+
+=cut
+
+sub num_usage_pkgs {
+  my $self = shift;
+  # have to enumerate exportnums but it's not bad
+  my @exportnums = map { $_->exportnum }
+                   grep { $_->can('usage_sessions') }
+                   qsearch('part_export');
+  return 0 if !@exportnums;
+  my $in_exportnums = join(',', @exportnums);
+  my $sql = "SELECT COUNT(DISTINCT pkgnum) FROM cust_pkg
+    JOIN cust_svc USING (pkgnum)
+    JOIN export_svc USING (svcpart)
+    WHERE exportnum IN( $in_exportnums ) AND custnum = ?";
+  FS::Record->scalar_sql($sql, $self->custnum);
+}
+
 =back
 
 =head1 BUGS
diff --git a/httemplate/view/cust_main/packages.html b/httemplate/view/cust_main/packages.html
index f3cfc06..958a061 100755
--- a/httemplate/view/cust_main/packages.html
+++ b/httemplate/view/cust_main/packages.html
@@ -167,7 +167,8 @@ if ( el ) el.scrollIntoView(true);
         <A HREF="<%$p%>search/report_svc_acct.html?custnum=<% $cust_main->custnum %>"><% mt('accounts') |h %></A><BR>
       <% mt('Usage reports:') |h %> 
         <A HREF="<%$p%>search/report_cdr.html?custnum=<% $cust_main->custnum %>"><% mt('CDRs') |h %></A>
-%      if ( $curuser->access_right('Usage: RADIUS sessions') ) {
+%      if ( $curuser->access_right('Usage: RADIUS sessions')
+%           and $cust_main->num_usage_pkgs > 0 ) {
        |
      <& /elements/popup_link-cust_main.html,
                  'label'       => emt('Data usage'),

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

Summary of changes:
 FS/FS/cust_main/Packages.pm             |   22 ++++++++++++++++++++++
 httemplate/view/cust_main/packages.html |    3 ++-
 2 files changed, 24 insertions(+), 1 deletion(-)




More information about the freeside-commits mailing list