From db5e7f34b1e17ae6ce8909062537cc2fb98ca30d Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Mon, 25 Feb 2013 17:10:46 -0800 Subject: display inbound CDRs in selfservice, #18316; Taqua caller ID, #18574 --- FS/FS/svc_phone.pm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'FS/FS/svc_phone.pm') diff --git a/FS/FS/svc_phone.pm b/FS/FS/svc_phone.pm index bf610c6..f28002c 100644 --- a/FS/FS/svc_phone.pm +++ b/FS/FS/svc_phone.pm @@ -688,6 +688,8 @@ with the chosen prefix. =item disable_src => 1: Only match on "charged_party", not "src". +=item nonzero: Only return CDRs where duration > 0. + =item by_svcnum: not supported for svc_phone =item billsec_sum: Instead of returning all of the CDRs, return a single @@ -755,6 +757,9 @@ sub psearch_cdrs { if ( $options{'end'} ) { push @where, 'startdate < '. $options{'end'}; } + if ( $options{'nonzero'} ) { + push @where, 'duration > 0'; + } my $extra_sql = ( keys(%hash) ? ' AND ' : ' WHERE ' ). join(' AND ', @where ); @@ -781,6 +786,30 @@ 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 -- cgit v1.1