57eb6763b7f2dab800ad72bb2849a41e8d546efc
[freeside.git] / httemplate / search / phone_inventory_provisioned.html
1 <% include( 'elements/search.html',
2               'title'         => 'LATA Search Results',
3               'name_singular' => 'LATA',
4               'query'         => {
5                                    'table'   => 'phone_avail',
6                                    'hashref' => {},
7                                    'select'  => 'distinct latanum',
8                                  },
9               'count_query'   => 'SELECT COUNT(distinct latanum) FROM phone_avail',
10               'header'        => [ 'LATA',
11                                    'Available',
12                                    'Provisioned',
13                                    'Have Usage',
14                                  ],
15               'fields'        => [
16         sub { # LATA
17             my $phone_avail = shift;
18             my $lata = $phone_avail->lata;
19             $lata = $lata ? $lata->description : '';
20             $phone_avail->latanum . " - " . $lata;
21         },
22                 sub { # Available
23                     my $latanum = shift->latanum;
24                     my $cnt = qsearchs({ 'table'    => 'phone_avail',
25                                  'hashref'  => 
26                                     { 'svcnum' => '',
27                                       'latanum' => $latanum,
28                                     },
29                                  'select'   => 'count(1) as cnt',
30                           });
31                     ($cnt) ? $cnt->cnt : '';
32                 },
33                 sub { # Provisioned
34                     my $latanum = shift->latanum;
35             my $cnt = qsearchs({   'table'     => 'phone_avail',
36                         'hashref'   => { 'latanum' => $latanum,
37                                          'svcnum' => { op => '>',
38                                                         value => '0'
39                                                      },
40                                         },
41                         'select'    => 'count(1) as cnt'
42                     });
43                     ($cnt) ? $cnt->cnt : '';
44                 },
45                 sub { # Have Usage
46             my $phone_avail = shift;
47             return '' unless $phone_avail->latanum;
48             my $latanum = $phone_avail->latanum;
49                     my $count = 0;
50             my $sql = "select count(1) from cdr where src in 
51                 (select phonenum from svc_phone where svcnum in (
52                     select svcnum from phone_avail where latanum = $latanum
53                         and svcnum is not null) )
54                 or charged_party in (select phonenum from svc_phone where
55                     svcnum in (select svcnum from phone_avail where
56                         latanum = $latanum and svcnum is not null) )";
57             my $c = $phone_avail->scalar_sql($sql);
58             $count++ if $c > 0;
59                     $count;
60                 },
61               ],
62               'align'         => 'lccc',
63               'links'         => [
64                 '',
65                 '',
66                 '',
67                 '',
68               ],
69               'color' => [ 
70                            '',
71                            '',
72                            '',
73                            '',
74                          ],
75               'style' => [ 
76                            '',
77                            '',
78                            '',
79                            '',
80                          ],
81       )
82 %>
83 <%init>
84
85 die "access denied"
86   unless ( $FS::CurrentUser::CurrentUser->access_right('List inventory')
87          && $FS::CurrentUser::CurrentUser->access_right('List services')
88          );
89
90 # XXX: agent virtualize
91
92 </%init>