stray closing /TABLE in the no-ticket case
[freeside.git] / httemplate / search / phone_inventory_provisioned.html
index c3de38f..b3efdbd 100644 (file)
@@ -1,87 +1,86 @@
-<% include( 'elements/search.html',
-              'title'         => 'Phone Number (DID) Search Results',
-              'name_singular' => 'phone number',
+<& elements/search.html,
+              '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',
-                                  'Available',
-                                  'Provisioned',
-                                  'Have Usage',
+              'count_query'   => 'SELECT COUNT(distinct latanum) FROM phone_avail',
+              'header'        => [ 
+                                   '#',
+                                   'LATA',
+                                   'Available',
+                                   'Provisioned',
+                                   'Have Usage',
                                  ],
               'fields'        => [
-                'npanxx',
-               sub {
-                   my $npanxx = shift->npanxx;
-                   my @dids = qsearch('phone_avail',
-                                       { 'svcnum' => '',
-                                         'npa' => substr($npanxx,0,3),
-                                         'nxx' => substr($npanxx,3,3),
-                                       }
-                                     );
-                   return scalar(@dids);
-               },
-               sub {
-                   my $npanxx = shift->npanxx;
-                   my @dids = provisioned_dids($npanxx);
-                   return scalar(@dids);
-               },
-               sub {
-                   my $npanxx = shift->npanxx;
-                   my @dids = provisioned_dids($npanxx);
-                   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);
-                   }
-                   $count;
-               },
+                'latanum',
+                sub { # LATA Description
+                    my $phone_avail = shift;
+                    return '' unless $phone_avail->lata;
+                    $phone_avail->lata->description;
+                },
+                sub { # Available
+                    my $latanum = shift->latanum;
+                    my $cnt = qsearchs({ 'table'    => 'phone_avail',
+                                 'hashref'  => 
+                                    { 'svcnum' => '',
+                                      'latanum' => $latanum,
+                                    },
+                                 'select'   => 'count(1) as cnt',
+                          });
+                    ($cnt) ? $cnt->cnt : '';
+                },
+                sub { # Provisioned
+                    my $latanum = shift->latanum;
+                    my $cnt = qsearchs({   'table'     => 'phone_avail',
+                        'hashref'   => { 'latanum' => $latanum,
+                                         'svcnum' => { op => '>',
+                                                        value => '0'
+                                                     },
+                                        },
+                        'select'    => 'count(1) as cnt'
+                    });
+                    ($cnt) ? $cnt->cnt : '';
+                },
+                sub { # Have Usage
+                    my $phone_avail = shift;
+                    return '' unless $phone_avail->lata;
+                    $phone_avail->lata->have_usage;
+                },
               ],
-              'align'         => 'lccc',
+              'align'         => 'rlrrr',
               'links'         => [
                 '',
-               '',
-               '',
-               '',
+                '',
+                '',
+                '',
+                '',
               ],
               'color' => [ 
                            '',
-                          '',
-                          '',
-                          '',
+                           '',
+                           '',
+                           '',
+                           '',
                          ],
               'style' => [ 
                            '',
-                          '',
-                          '',
-                          '',
+                           '',
+                           '',
+                           '',
+                           '',
                          ],
-      )
-%>
+      
+&>
 <%init>
 
 die "access denied"
   unless ( $FS::CurrentUser::CurrentUser->access_right('List inventory')
-        && $FS::CurrentUser::CurrentUser->access_right('List services')
-        );
+         && $FS::CurrentUser::CurrentUser->access_right('List services')
+         );
 
 # 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 ',
-         });
-}
-
 </%init>