1 <% include( 'elements/search.html',
2 'title' => 'Phone Number (DID) Search Results',
3 'name_singular' => 'phone number',
5 'table' => 'phone_avail',
10 FS::UI::Web::cust_sql_fields(),
12 'extra_sql' => $search,
13 'addl_from' => $addl_from,
15 'count_query' => $count_query,
23 FS::UI::Web::cust_header(),
29 '+'. $pn->countrycode. ' '.
30 $pn->npa. ' '. $pn->nxx. '-'. $pn->station;
32 sub { shift->get('name') },
37 \&FS::UI::Web::cust_fields,
39 'align' => 'rllllll'.FS::UI::Web::cust_aligns(),
46 '', #XXX #$export_link
48 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
49 FS::UI::Web::cust_header()
60 FS::UI::Web::cust_colors(),
70 FS::UI::Web::cust_styles(),
77 unless ( $FS::CurrentUser::CurrentUser->access_right('List inventory')
78 || $FS::CurrentUser::CurrentUser->access_right('List services')
83 push @search, "availbatch = '$1'"
84 if ( $cgi->param('availbatch') =~ /^([\w\d \/\:\-\.]+)$/ );
86 push @search, "countrycode = '$1'"
87 if ( $cgi->param('countrycode') =~ /^(\d{1,3})$/ );
89 push @search, "phone_avail.state = '$1'"
90 if ( $cgi->param('state') =~ /^(\w{2})$/ );
92 # i know that the regexps match more than NPA/NXX, but this is good enough now
93 push @search, "npa = '$1'"
94 if ( $cgi->param('npa') =~ /^(\d{3})$/ );
95 push @search, "nxx = '$1'"
96 if ( $cgi->param('npa') =~ /^\d{3}$/ && $cgi->param('nxx') =~ /^(\d{3})$/ );
98 push @search, "name = '$1'"
99 if ( $cgi->param('ratecenter') =~ /^([\w \-\.]+)$/ );
101 push @search, "svcnum is null"
102 if ( $cgi->param('avail_status') eq 'AVAIL' );
103 push @search, "svcnum is not null"
104 if ( $cgi->param('avail_status') eq 'UNAVAIL' );
106 # #here is the agent virtualization
107 # push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;
109 my $search = scalar(@search)
110 ? ' WHERE '. join(' AND ', @search)
114 my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
115 #' LEFT JOIN part_svc USING ( svcpart ) '.
116 ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
117 ' LEFT JOIN cust_main USING ( custnum ) ';
119 my $count_query = "SELECT COUNT(*) FROM phone_avail $search"; #$addl_from?
121 my $link_cust = sub {
122 my $phone_avail = shift;
123 if ( $phone_avail->svcnum ) {
124 my $cust_svc = $phone_avail->cust_svc;
125 if ( $cust_svc->pkgnum ) {
126 #my $cust_main = $cust_svc->cust_pkg->cust_main;
127 return [ "${p}view/cust_main.cgi?", 'custnum' ];