[freeside-commits] branch master updated. 230e099f92541bc3bc0e2a08e81932ee17909fa0

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


The branch, master has been updated
       via  230e099f92541bc3bc0e2a08e81932ee17909fa0 (commit)
       via  bd4ed118a478f56e32fe8fcbaf8aac1955236123 (commit)
      from  ba92d105395292725e293f79a561d22902c13a91 (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 230e099f92541bc3bc0e2a08e81932ee17909fa0
Author: Mark Wells <mark at freeside.biz>
Date:   Fri May 15 10:22:50 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 e2f8595..c89b7bb 100644
--- a/FS/FS/ClientAPI/MyAccount.pm
+++ b/FS/FS/ClientAPI/MyAccount.pm
@@ -1857,18 +1857,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
@@ -2163,11 +2165,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
     );
@@ -2175,9 +2177,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 {
@@ -2194,17 +2194,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 e19dc88..b28f057 100644
--- a/FS/FS/svc_pbx.pm
+++ b/FS/FS/svc_pbx.pm
@@ -386,6 +386,31 @@ 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} );
+}
+
 =back
 
 =head1 BUGS
diff --git a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi
index 2337fb5..8fec011 100755
--- a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi
+++ b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi
@@ -957,7 +957,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>';
 }
 '';

commit bd4ed118a478f56e32fe8fcbaf8aac1955236123
Author: Mark Wells <mark at freeside.biz>
Date:   Fri May 15 10:21:27 2015 -0700

    fix svc_phone.circuit_svcnum column config

diff --git a/FS/FS/svc_phone.pm b/FS/FS/svc_phone.pm
index 326c0be..fc90365 100644
--- a/FS/FS/svc_phone.pm
+++ b/FS/FS/svc_phone.pm
@@ -201,9 +201,10 @@ sub table_info {
                        },
         'circuit_svcnum'   => { label             => 'Circuit',
                                 type              => 'select',
-                                select_table      => 'svc_domain',
+                                select_table      => 'svc_circuit',
                                 select_key        => 'svcnum',
-                                select_label      => 'circuit_label',
+                                select_label      => 'label',
+                                select_allow_empty=> 1,
                                 disable_inventory => 1,
                               },
 

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

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




More information about the freeside-commits mailing list