move POP to browse template; whew, its paged
[freeside.git] / httemplate / browse / svc_acct_pop.cgi
1 <% include( 'elements/browse.html',
2                 'title'         => 'Access Numbers',
3                 'html_init'     => $html_init,
4                 'name_singular' => 'access number',
5                 'query'         => $query,
6                 'count_query'   => $count_query,
7                 'header'        => [
8                                      '#',
9                                      'City',
10                                      'State',
11                                      'Area code',
12                                      'Exchange',
13                                      'Local',
14                                      'Accounts',
15                                    ],
16                   'fields'      => [
17                                      'popnum',
18                                      'city',
19                                      'state',
20                                      'ac',
21                                      'exch',
22                                      'loc',
23                                      $num_accounts_sub,
24                                    ],
25                   'align'       => 'rllrrrr',
26           )
27 %>
28 <%init>
29
30 die "access denied"
31   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
32
33 my $html_init = qq!
34   <A HREF="${p}edit/svc_acct_pop.cgi"><I>Add new Access Number</I></A>
35   <BR><BR>
36 !;
37
38 my $query = { 'select'    => '*,
39                               ( SELECT COUNT(*) FROM svc_acct
40                                   WHERE svc_acct.popnum = svc_acct_pop.popnum
41                               ) AS num_accounts
42                              ',
43               'table'     => 'svc_acct_pop',
44               #'hashref'   => { 'disabled' => '' },
45               'extra_sql' => 'ORDER BY state, city, ac, exch, loc',
46             };
47
48 my $count_query = "SELECT COUNT(*) FROM svc_acct_pop"; # WHERE DISABLED IS NULL OR DISABLED = ''";
49
50 my $svc_acct_pop_link = [ $p.'edit/svc_acct_pop.cgi?', 'popnum' ];
51
52 my $svc_acct_link = $p. 'search/svc_acct.cgi?popnum=';
53
54 my $num_accounts_sub = sub {
55   my $svc_acct_pop = shift;
56   [
57     [
58       { 'data'  => '<B><FONT COLOR="#00CC00">'.
59                    $svc_acct_pop->get('num_accounts').
60                    '</FONT></B>',
61         'align' => 'right',
62       },
63       { 'data'  => 'active',
64         'align' => 'left',
65         'link'  => ( $svc_acct_pop->get('num_accounts')
66                        ? $svc_acct_link. $svc_acct_pop->popnum
67                        : ''
68                    ),
69       },
70     ],
71   ];
72 };
73
74 </%init>