summaryrefslogtreecommitdiff
path: root/httemplate/search/phone_avail.html
blob: e1c264fb662db61636d36d122553b4fef3f2d809 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<% include( 'elements/search.html',
              'title'         => 'Phone Number (DID) Search Results',
              'name_singular' => 'phone number',
              'query'         => {
                                   'table'   => 'phone_avail',
                                   'hashref' => {},
                                   'select'  => join(', ',
                                       'phone_avail.*',
                                       'cust_main.custnum',
                                       FS::UI::Web::cust_sql_fields(),
                                   ),
                                   'extra_sql' => $search,
                                   'addl_from' => $addl_from,
                                 },
              'count_query'   => $count_query,
              'header'        => [ '#',
                                   'State',
                                   'Phone Number',
				   'Rate Center',
				   'Batch',
                                   'Export',
                                   'Service',
                                    FS::UI::Web::cust_header(),
                                 ],
              'fields'        => [
                'availnum',
                'state',
                sub { my $pn = shift;
                      '+'. $pn->countrycode. ' '.
                        $pn->npa. ' '.  $pn->nxx. '-'. $pn->station;
                    },
		'name',
		'availbatch',
                'exportnum', #XXX
                #sub { },
                'svcnum', #XXX
                \&FS::UI::Web::cust_fields,
              ],
              'align'         => 'rllllll'.FS::UI::Web::cust_aligns(),
              'links'         => [
                '',
                '',
		'',
		'',
                '',
                '', #XXX #$export_link
                '', #XXX #$svc_link
                ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
                      FS::UI::Web::cust_header()
                ),
              ],
              'color' => [ 
                           '',
                           '',
			   '',
			   '',
                           '',
                           '',
                           '',
                           FS::UI::Web::cust_colors(),
                         ],
              'style' => [ 
                           '',
                           '',
			   '',
			   '',
                           '',
                           '',
                           '',
                           FS::UI::Web::cust_styles(),
                         ],
      )
%>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Import');

my @search = ();

push @search, "availbatch = '$1'" 
    if ( $cgi->param('availbatch') =~ /^([\w\d \/\:\-\.]+)$/ ); 
  
push @search, "countrycode = '$1'" 
    if ( $cgi->param('countrycode') =~ /^(\d{1,3})$/ );

push @search, "phone_avail.state = '$1'" 
    if ( $cgi->param('state') =~ /^(\w{2})$/ );

# i know that the regexps match more than NPA/NXX, but this is good enough now
push @search, "npa = '$1'" 
    if ( $cgi->param('npa') =~ /^(\d{3})$/ ); 
push @search, "nxx = '$1'" 
    if ( $cgi->param('npa') =~ /^\d{3}$/ && $cgi->param('nxx') =~ /^(\d{3})$/ ); 

push @search, "name = '$1'" 
    if ( $cgi->param('ratecenter') =~ /^([\w \-\.]+)$/ );

push @search, "svcnum is null" 
    if ( $cgi->param('avail_status') eq 'AVAIL' );
push @search, "svcnum is not null" 
    if ( $cgi->param('avail_status') eq 'UNAVAIL' );

#  #here is the agent virtualization
#  push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;

my $search = scalar(@search) 
               ? ' WHERE '. join(' AND ', @search)
               : '';


my $addl_from = ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
                #' LEFT JOIN part_svc  USING ( svcpart ) '.
                ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
                ' LEFT JOIN cust_main USING ( custnum ) ';

my $count_query = "SELECT COUNT(*) FROM phone_avail $search"; #$addl_from?

my $link_cust = sub {
  my $phone_avail = shift;
  if ( $phone_avail->svcnum ) {
    my $cust_svc = $phone_avail->cust_svc;
    if ( $cust_svc->pkgnum ) {
      #my $cust_main = $cust_svc->cust_pkg->cust_main;
      return [ "${p}view/cust_main.cgi?", 'custnum' ];
    }
  }
  '';
};

</%init>