1 <% include( 'elements/search.html',
2 'title' => 'Zip code Search Results',
5 'count_query' => $count_sql,
6 'header' => [ 'Zip code', 'Customers', ],
7 #'fields' => [ 'zip', 'num_cust', ],
8 'links' => [ '', sub { 'somewhere'; } ],
14 unless $FS::CurrentUser::CurrentUser->access_right('List zip codes');
16 # XXX link to customers
22 if ( $cgi->param('status') =~ /^(prospect|uncancel|active|susp|cancel)$/ ) {
23 my $method = $1.'_sql';
24 push @where, FS::cust_main->$method();
28 # XXX this needs to be virtualized by agent too (like lots of stuff)
31 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
33 push @where, "cust_main.agentnum = $agentnum";
35 my $where = scalar(@where) ? 'WHERE '. join(' AND ', @where) : '';
37 # bill zip vs ship zip
41 "CASE WHEN $field IS NULL THEN '' ELSE $field END";
46 "CASE WHEN $field is NULL
48 ELSE CASE WHEN $field LIKE '_____-____'
49 THEN SUBSTRING($field FROM 1 FOR 5)
56 if ( $cgi->param('column') eq 'ship_zip' ) {
59 "CASE WHEN ( ship_last IS NULL OR ship_last = '' ) THEN ";
61 $czip = "$casewhen_noship zip ELSE ship_zip END";
63 if ( $cgi->param('ignore_plus4') ) {
64 $zip = $casewhen_noship. strip_plus4('zip').
65 " ELSE ". strip_plus4('ship_zip'). ' END';
68 $zip = $casewhen_noship. fieldorempty('zip').
69 " ELSE ". fieldorempty('ship_zip'). ' END';
76 if ( $cgi->param('ignore_plus4') ) {
77 $zip = strip_plus4('zip');
79 $zip = fieldorempty('zip');
84 # construct the queries and send 'em off
87 "SELECT $zip AS zipcode,
92 ORDER BY num_cust DESC
95 my $count_sql = "select count(distinct $czip) from cust_main $where";