[freeside-commits] branch FREESIDE_3_BRANCH updated. 7ad052da94c4d205cf426c0ef3ef113f5429b948

Mark Wells mark at 420.am
Fri May 15 10:23:07 PDT 2015


The branch, FREESIDE_3_BRANCH has been updated
       via  7ad052da94c4d205cf426c0ef3ef113f5429b948 (commit)
      from  049272bb77e02c5b62885fd2ad302e0c34da4a19 (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 7ad052da94c4d205cf426c0ef3ef113f5429b948
Author: Mark Wells <mark at freeside.biz>
Date:   Fri May 15 10:18:12 2015 -0700

    view svc_pbx usage in selfservice, #34836

diff --git a/FS/FS/ClientAPI.pm b/FS/FS/ClientAPI.pm
index 1fea28c..e4031b2 100644
--- a/FS/FS/ClientAPI.pm
+++ b/FS/FS/ClientAPI.pm
@@ -6,7 +6,7 @@ use vars qw( @EXPORT_OK %handler $domain $DEBUG $me );
 
 @EXPORT_OK = qw( load_clientapi_modules );
 
-$DEBUG = 0;
+$DEBUG = 1;
 $me = '[FS::ClientAPI]';
 
 %handler = ();
diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm
index d05abde..b4b60d4 100644
--- a/FS/FS/ClientAPI/MyAccount.pm
+++ b/FS/FS/ClientAPI/MyAccount.pm
@@ -1823,18 +1823,20 @@ sub list_svcs {
       }
       # no usage to hide here
 
-    } elsif ( $svcdb eq 'svc_phone' ) {
+    } elsif ( $svcdb eq 'svc_phone' or $svcdb eq 'svc_pbx' ) {
       if (!$hide_usage) {
         # could potentially show lots of things...
         $hash{'outbound'} = 1;
         $hash{'inbound'}  = 0;
-        if ( $part_pkg->plan eq 'voip_inbound' ) {
-          $hash{'outbound'} = 0;
-          $hash{'inbound'}  = 1;
-        } elsif ( $part_pkg->option('selfservice_inbound_format')
-              or  $conf->config('selfservice-default_inbound_cdr_format')
-        ) {
-          $hash{'inbound'}  = 1;
+        if ( $svcdb eq 'svc_phone' ) {
+          if ( $part_pkg->plan eq 'voip_inbound' ) {
+            $hash{'outbound'} = 0;
+            $hash{'inbound'}  = 1;
+          } elsif ( $part_pkg->option('selfservice_inbound_format')
+                or  $conf->config('selfservice-default_inbound_cdr_format')
+          ) {
+            $hash{'inbound'}  = 1;
+          }
         }
         foreach (qw(inbound outbound)) {
           # hmm...we can't filter by status here, because there might
@@ -2129,11 +2131,11 @@ sub _list_cdr_usage {
   # XXX CDR type support...
   # XXX any way to do a paged search on this?
   # we have to return the results all at once...
-  my($svc_phone, $begin, $end, %opt) = @_;
+  my($svc_x, $begin, $end, %opt) = @_;
   map [ $_->downstream_csv(%opt, 'keeparray' => 1) ],
-    $svc_phone->get_cdrs(
-      'begin'=>$begin,
-      'end'=>$end,
+    $svc_x->get_cdrs(
+      'begin' => $begin,
+      'end'   => $end,
       'disable_charged_party' => 1,
       %opt
     );
@@ -2141,9 +2143,7 @@ sub _list_cdr_usage {
 
 sub list_cdr_usage {
   my $p = shift;
-  _usage_details( \&_list_cdr_usage, $p,
-                  'svcdb' => 'svc_phone',
-                );
+  _usage_details( \&_list_cdr_usage, $p );
 }
 
 sub _usage_details {
@@ -2160,17 +2160,17 @@ sub _usage_details {
   my $search = { 'svcnum' => $p->{'svcnum'} };
   $search->{'agentnum'} = $session->{'agentnum'} if $context eq 'agent';
 
-  my $svcdb = $opt{'svcdb'} || 'svc_acct';
-
-  my $svc_x = qsearchs( $svcdb, $search );
+  my $cust_svc = qsearchs( 'cust_svc', $search );
   return { 'error' => 'No service selected in list_svc_usage' } 
-    unless $svc_x;
+    unless $cust_svc;
 
-  my $cust_pkg = $svc_x->cust_svc->cust_pkg;
+  my $svc_x = $cust_svc->svc_x;
+  my $svcdb = $svc_x->table;
+  my $cust_pkg = $cust_svc->cust_pkg;
   my $freq     = $cust_pkg->part_pkg->freq;
   my %callback_opt;
   my $header = [];
-  if ( $svcdb eq 'svc_phone' ) {
+  if ( $svcdb eq 'svc_phone' or $svcdb eq 'svc_pbx' ) {
     my $format = '';
     if ( $p->{inbound} ) {
       $format = $cust_pkg->part_pkg->option('selfservice_inbound_format') 
diff --git a/FS/FS/svc_pbx.pm b/FS/FS/svc_pbx.pm
index ad3e477..1989622 100644
--- a/FS/FS/svc_pbx.pm
+++ b/FS/FS/svc_pbx.pm
@@ -387,6 +387,34 @@ sub get_cdrs {
   qsearch ( $psearch->{query} )
 }
 
+=item sum_cdrs
+
+Takes the same options as psearch_cdrs, but returns a single row containing
+"count" (the number of CDRs) and the sums of the following fields: duration,
+billsec, rated_price, rated_seconds, rated_minutes.
+
+Note that if any calls are not rated, their rated_* fields will be null.
+If you want to use those fields, pass the 'status' option to limit to 
+calls that have been rated.  This is intentional; please don't "fix" it.
+
+=cut
+
+sub sum_cdrs {
+  my $self = shift;
+  my $psearch = $self->psearch_cdrs(@_);
+  $psearch->{query}->{'select'} = join(',',
+    'COUNT(*) AS count',
+    map { "SUM($_) AS $_" }
+      qw(duration billsec rated_price rated_seconds rated_minutes)
+  );
+  # hack
+  $psearch->{query}->{'extra_sql'} =~ s/ ORDER BY.*$//;
+  qsearchs ( $psearch->{query} );
+}
+
+
+# 3.x stub
+
 sub pbx_extension {
   my $self = shift;
   qsearch('pbx_extension', { svcnum=>$self->svcnum });
diff --git a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi
index 9443a7d..d039cfd 100755
--- a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi
+++ b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi
@@ -943,7 +943,7 @@ sub delete_svc {
 sub view_usage {
   my $res = list_svcs(
     'session_id'  => $session_id,
-    'svcdb'       => [ 'svc_acct', 'svc_phone', 'svc_port', ],
+    'svcdb'       => [ 'svc_acct', 'svc_phone', 'svc_port', 'svc_pbx' ],
     'ncancelled'  => 1,
   );
   if ($res->{hide_usage}) {
diff --git a/fs_selfservice/FS-SelfService/cgi/view_usage.html b/fs_selfservice/FS-SelfService/cgi/view_usage.html
index 2aa7c1e..4099a57 100644
--- a/fs_selfservice/FS-SelfService/cgi/view_usage.html
+++ b/fs_selfservice/FS-SelfService/cgi/view_usage.html
@@ -3,6 +3,7 @@
     @svc_acct = ();
     @svc_phone = ();
     @svc_port = ();
+    @svc_pbx = ();
 
     foreach (@svcs) {
       $by_pkg_label{ $_->{pkg_label} } ||= [];
@@ -13,6 +14,8 @@
         push @svc_phone, $_;
       } elsif ( $_->{svcdb} eq 'svc_port' ) {
         push @svc_port, $_;
+      } elsif ( $_->{svcdb} eq 'svc_pbx' ) {
+        push @svc_pbx, $_;
       }
     }
     '';
@@ -74,10 +77,10 @@
 
 <%= scalar(@svc_acct) ? '</TABLE><BR><BR>' : '' %>
 
-<%= if ( @svc_phone ) {
+<%= if ( @svc_phone or @svc_pbx ) {
       %any = ();
       for my $dir (qw(outbound inbound)) {
-        $any{$dir} = grep { $_->{$dir} } @svc_phone;
+        $any{$dir} = grep { $_->{$dir} } (@svc_phone, @svc_pbx);
       }
       $OUT.= '<FONT SIZE="4">Call usage</FONT><BR><BR>
               <TABLE BGCOLOR="#cccccc" STYLE="display:inline-block">
@@ -97,21 +100,22 @@
     }
 %>
 
-<%= foreach my $svc_phone ( @svc_phone ) {
-      my $link = "${url}view_cdr_details;".
-        "svcnum=$svc_phone->{'svcnum'};beginning=0;ending=0";
-  $OUT .= '<TR><TD>'. $svc_phone->{'label'}. ': '. $svc_phone->{'value'};
+<%= foreach my $svc_x ( @svc_phone, @svc_pbx ) {
+  my $link = $url . 'view_cdr_details;' .
+          'svcnum='.$svc_x->{'svcnum'}.
+          ';beginning=0;ending=0';
+  $OUT .= '<TR><TD>'. $svc_x->{'label'}. ': '. $svc_x->{'value'};
   $OUT .= '</TD>';
   # usage summary w/ links
   for my $dir (qw(outbound inbound)) {
     if ( $dir eq 'inbound' ) {
       $link .= ';inbound=1';
     }
-    if ( $svc_phone->{$dir} ) {
+    if ( $svc_x->{$dir} ) {
       $OUT .= '<TD ALIGN="right">'.qq!<A HREF="$link">! .
         sprintf('%d calls (%.0f minutes)',
-          $svc_phone->{$dir}->{'count'},
-          $svc_phone->{$dir}->{'duration'} / 60
+          $svc_x->{$dir}->{'count'},
+          $svc_x->{$dir}->{'duration'} / 60
         ) .
         '</A></TD>';
     } elsif ( $any{$dir} )  {
@@ -154,7 +158,7 @@
             '<TD COLSPAN=4>* shared among all your phone plans</TD></TR>';
   }
 }
-if ( scalar(@svc_phone) or scalar(@usage_pools) ) {
+if ( @svc_phone or @svc_pbx or @usage_pools ) {
   $OUT .= '</TABLE><BR><BR>';
 }
 '';

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

Summary of changes:
 FS/FS/ClientAPI.pm                                |    2 +-
 FS/FS/ClientAPI/MyAccount.pm                      |   42 ++++++++++-----------
 FS/FS/svc_pbx.pm                                  |   28 ++++++++++++++
 fs_selfservice/FS-SelfService/cgi/selfservice.cgi |    2 +-
 fs_selfservice/FS-SelfService/cgi/view_usage.html |   24 +++++++-----
 5 files changed, 65 insertions(+), 33 deletions(-)




More information about the freeside-commits mailing list