3 # XXX link to customers
9 if ( $cgi->param('status') =~ /^(prospect|uncancel|active|susp|cancel)$/ ) {
10 my $method = $1.'_sql';
11 push @where, FS::cust_main->$method();
15 # XXX this needs to be virtualized by agent too (like lots of stuff)
18 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
20 push @where, "cust_main.agentnum = $agentnum";
22 my $where = scalar(@where) ? 'WHERE '. join(' AND ', @where) : '';
24 # bill zip vs ship zip
28 "CASE WHEN $field IS NULL THEN '' ELSE $field END";
33 "CASE WHEN $field is NULL
35 ELSE CASE WHEN $field LIKE '_____-____'
36 THEN SUBSTRING($field FROM 1 FOR 5)
43 if ( $cgi->param('column') eq 'ship_zip' ) {
46 "CASE WHEN ( ship_last IS NULL OR ship_last = '' ) THEN ";
48 $czip = "$casewhen_noship zip ELSE ship_zip END";
50 if ( $cgi->param('ignore_plus4') ) {
51 $zip = $casewhen_noship. strip_plus4('zip').
52 " ELSE ". strip_plus4('ship_zip'). ' END';
55 $zip = $casewhen_noship. fieldorempty('zip').
56 " ELSE ". fieldorempty('ship_zip'). ' END';
63 if ( $cgi->param('ignore_plus4') ) {
64 $zip = strip_plus4('zip');
66 $zip = fieldorempty('zip');
71 # construct the queries and send 'em off
74 "SELECT $zip AS zipcode,
79 ORDER BY num_cust DESC
82 my $count_sql = "select count(distinct $czip) from cust_main $where";
86 %><%= include( 'elements/search.html',
87 'title' => 'Zip code Search Results',
88 'name' => 'zip codes',
89 'query' => $sql_query,
90 'count_query' => $count_sql,
91 'header' => [ 'Zip code', 'Customers', ],
92 #'fields' => [ 'zip', 'num_cust', ],
93 'links' => [ '', sub { 'somewhere'; } ],