X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_pbx.pm;h=1989622604100adf75407e325e030d581e2c7fc5;hb=aba308a52b4cf39e9bd84301514b45734f540260;hp=ad3e477ef33b92b7b58b6a5983d1b1c6bd0274e2;hpb=9ad0574bb99869836af00800423af7249721c1d1;p=freeside.git diff --git a/FS/FS/svc_pbx.pm b/FS/FS/svc_pbx.pm index ad3e477ef..198962260 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 });