X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Fphone_inventory_provisioned.html;h=eb5f21ef01438d7d1e1dd5802ccddf76aef81f61;hb=e497a444b638b1bb22e8949cd0703708da35008b;hp=c3de38f3777ff2cfd12b44fea1f594e6703d1d5a;hpb=13a5d5ea7770ef1868e1d9af95a27065008484b7;p=freeside.git diff --git a/httemplate/search/phone_inventory_provisioned.html b/httemplate/search/phone_inventory_provisioned.html index c3de38f37..eb5f21ef0 100644 --- a/httemplate/search/phone_inventory_provisioned.html +++ b/httemplate/search/phone_inventory_provisioned.html @@ -1,44 +1,53 @@ <% include( 'elements/search.html', - 'title' => 'Phone Number (DID) Search Results', - 'name_singular' => 'phone number', + 'title' => 'LATA Search Results', + 'name_singular' => 'LATA', 'query' => { 'table' => 'phone_avail', 'hashref' => {}, - 'select' => 'distinct npa||nxx as npanxx' + 'select' => 'distinct latanum', }, - 'count_query' => 'SELECT COUNT(distinct npa||nxx) FROM phone_avail', - 'header' => [ 'NPANXX', + 'count_query' => 'SELECT COUNT(distinct latanum) FROM phone_avail', + 'header' => [ 'LATA', 'Available', 'Provisioned', 'Have Usage', ], 'fields' => [ - 'npanxx', - sub { - my $npanxx = shift->npanxx; + sub { # LATA + my $did_order = shift; + my $lata = $did_order->lata; + $lata = $lata ? $lata->description : ''; + $did_order->latanum . " - " . $lata; + }, + sub { # Available + my $latanum = shift->latanum; my @dids = qsearch('phone_avail', - { 'svcnum' => '', - 'npa' => substr($npanxx,0,3), - 'nxx' => substr($npanxx,3,3), - } - ); + { 'svcnum' => '', + 'latanum' => $latanum, + } + ); return scalar(@dids); }, - sub { - my $npanxx = shift->npanxx; - my @dids = provisioned_dids($npanxx); + sub { # Provisioned + my $latanum = shift->latanum; + my @dids = provisioned_dids($latanum); return scalar(@dids); }, - sub { - my $npanxx = shift->npanxx; - my @dids = provisioned_dids($npanxx); + sub { # Have Usage + my $did_order = shift; + my @dids = provisioned_dids($did_order->latanum); + my $count = 0; foreach my $did ( @dids ) { - next unless $did->cust_svc; - my $svc_phone = $did->cust_svc->svc_x; - next unless $svc_phone; - my @cdrs = $svc_phone->get_cdrs; - $count++ if scalar(@cdrs); + my $svcnum = $did->svcnum; + next unless $svcnum; + + my $sql = "select count(1) from cdr where src = + (select phonenum from svc_phone where svcnum = $svcnum) + or charged_party = (select phonenum from svc_phone where + svcnum = $svcnum)"; + my $c = $did_order->scalar_sql($sql); + $count++ if $c > 0; } $count; }, @@ -66,6 +75,8 @@ %> <%init> +warn "started @ ".time; + die "access denied" unless ( $FS::CurrentUser::CurrentUser->access_right('List inventory') && $FS::CurrentUser::CurrentUser->access_right('List services') @@ -74,14 +85,11 @@ die "access denied" # XXX: agent virtualize sub provisioned_dids { - my $npanxx = shift; - qsearch({ 'table' => 'phone_avail', - 'hashref' => { - 'npa' => substr($npanxx,0,3), - 'nxx' => substr($npanxx,3,3), - }, - 'extra_sql' => ' and svcnum is not null ', - }); + my $latanum = shift; + qsearch({ 'table' => 'phone_avail', + 'hashref' => { 'latanum' => $latanum, }, + 'extra_sql' => ' and svcnum is not null ', + }); }