correct ordering and other bugs in tax updates
[freeside.git] / httemplate / search / phone_avail.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'  => join(', ',
8                                        'phone_avail.*',
9                                        'cust_main.custnum',
10                                        FS::UI::Web::cust_sql_fields(),
11                                    ),
12                                    'extra_sql' => $search,
13                                    'addl_from' => $addl_from,
14                                  },
15               'count_query'   => $count_query,
16               'header'        => [ '#',
17                                    'State',
18                                    'Phone Number',
19                                    'Export',
20                                    'Service',
21                                     FS::UI::Web::cust_header(),
22                                  ],
23               'fields'        => [
24                 'availnum',
25                 'state',
26                 sub { my $pn = shift;
27                       '+'. $pn->countrycode. ' '.
28                         $pn->npa. ' '.  $pn->nxx. '-'. $pn->station;
29                     },
30                 'exportnum', #XXX
31                 #sub { },
32                 'svcnum', #XXX
33                 \&FS::UI::Web::cust_fields,
34               ],
35               'align'         => 'rllll'.FS::UI::Web::cust_aligns(),
36               'links'         => [
37                 '',
38                 '',
39                 '',
40                 '', #XXX #$export_link
41                 '', #XXX #$svc_link
42                 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
43                       FS::UI::Web::cust_header()
44                 ),
45               ],
46               'color' => [ 
47                            '',
48                            '',
49                            '',
50                            '',
51                            '',
52                            FS::UI::Web::cust_colors(),
53                          ],
54               'style' => [ 
55                            '',
56                            '',
57                            '',
58                            '',
59                            '',
60                            FS::UI::Web::cust_styles(),
61                          ],
62       )
63 %>
64 <%init>
65
66 die "access denied"
67   unless $FS::CurrentUser::CurrentUser->access_right('Import');
68
69 my @search = ();
70
71 if ( $cgi->param('availbatch') =~ /^([\w\/\:\-\.]+)$/ ) {
72   push @search, "availbatch = '$1'";
73 }
74
75 #  #here is the agent virtualization
76 #  push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;
77
78 my $search = scalar(@search) 
79                ? ' WHERE '. join(' AND ', @search)
80                : '';
81
82
83 my $addl_from = ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
84                 #' LEFT JOIN part_svc  USING ( svcpart ) '.
85                 ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
86                 ' LEFT JOIN cust_main USING ( custnum ) ';
87
88 my $count_query = "SELECT COUNT(*) FROM phone_avail $search"; #$addl_from?
89
90 my $link_cust = sub {
91   my $phone_avail = shift;
92   if ( $phone_avail->svcnum ) {
93     my $cust_svc = $phone_avail->svc_phone->cust_svc;
94     if ( $cust_svc->pkgnum ) {
95       #my $cust_main = $cust_svc->cust_pkg->cust_main;
96       return [ "${p}view/cust_main.cgi?", 'custnum' ];
97     }
98   }
99   '';
100 };
101
102 </%init>