diff options
author | Mark Wells <mark@freeside.biz> | 2015-05-15 10:22:50 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2015-05-15 10:22:50 -0700 |
commit | 230e099f92541bc3bc0e2a08e81932ee17909fa0 (patch) | |
tree | 1dec136d50a0c458bad6cc68b451f114dd56c828 /FS/FS | |
parent | bd4ed118a478f56e32fe8fcbaf8aac1955236123 (diff) |
view svc_pbx usage in selfservice, #34836
Diffstat (limited to 'FS/FS')
-rw-r--r-- | FS/FS/ClientAPI.pm | 2 | ||||
-rw-r--r-- | FS/FS/ClientAPI/MyAccount.pm | 42 | ||||
-rw-r--r-- | FS/FS/svc_pbx.pm | 25 |
3 files changed, 47 insertions, 22 deletions
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 |