This commit was generated by cvs2svn to compensate for changes in r10640,
[freeside.git] / httemplate / search / phone_inventory_provisioned.html
1 <% include( 'elements/search.html',
2               'title'         => 'Phone Number (DID) Search Results',
3               'name_singular' => 'phone number',
4               'query'         => {
5                                    'table'   => 'phone_avail',
6                                    'hashref' => {},
7                                    'select'  => 'distinct npa||nxx as npanxx'
8                                  },
9               'count_query'   => 'SELECT COUNT(distinct npa||nxx) FROM phone_avail',
10               'header'        => [ 'NPANXX',
11                                    'Available',
12                                    'Provisioned',
13                                    'Have Usage',
14                                  ],
15               'fields'        => [
16                 'npanxx',
17                 sub {
18                     my $npanxx = shift->npanxx;
19                     my @dids = qsearch('phone_avail',
20                                         { 'svcnum' => '',
21                                           'npa' => substr($npanxx,0,3),
22                                           'nxx' => substr($npanxx,3,3),
23                                         }
24                                       );
25                     return scalar(@dids);
26                 },
27                 sub {
28                     my $npanxx = shift->npanxx;
29                     my @dids = provisioned_dids($npanxx);
30                     return scalar(@dids);
31                 },
32                 sub {
33                     my $npanxx = shift->npanxx;
34                     my @dids = provisioned_dids($npanxx);
35                     my $count = 0;
36                     foreach my $did ( @dids ) {
37                         next unless $did->cust_svc;
38                         my $svc_phone = $did->cust_svc->svc_x;
39                         next unless $svc_phone;
40                         my @cdrs = $svc_phone->get_cdrs;
41                         $count++ if scalar(@cdrs);
42                     }
43                     $count;
44                 },
45               ],
46               'align'         => 'lccc',
47               'links'         => [
48                 '',
49                 '',
50                 '',
51                 '',
52               ],
53               'color' => [ 
54                            '',
55                            '',
56                            '',
57                            '',
58                          ],
59               'style' => [ 
60                            '',
61                            '',
62                            '',
63                            '',
64                          ],
65       )
66 %>
67 <%init>
68
69 die "access denied"
70   unless ( $FS::CurrentUser::CurrentUser->access_right('List inventory')
71          && $FS::CurrentUser::CurrentUser->access_right('List services')
72          );
73
74 # XXX: agent virtualize
75
76 sub provisioned_dids {
77     my $npanxx = shift;
78     qsearch({ 'table' => 'phone_avail',
79               'hashref' => { 
80                 'npa' => substr($npanxx,0,3),
81                 'nxx' => substr($npanxx,3,3),
82               },
83               'extra_sql' => ' and svcnum is not null ',
84           });
85 }
86
87 </%init>