summaryrefslogtreecommitdiff
path: root/httemplate/search/cust_main-zip.html
diff options
context:
space:
mode:
authorivan <ivan>2007-02-03 11:36:30 +0000
committerivan <ivan>2007-02-03 11:36:30 +0000
commit590603ecaea3184f64530755a76626be8205da49 (patch)
tree0fdb8164cd74bd4cbbd3c2266b8f8bf4cbb7fc00 /httemplate/search/cust_main-zip.html
parent14e3560b43ca8a747f4210bd784a0315daeb5e9e (diff)
add customer status column to customer & most other reports. also put the C in ACL in the search/ and graph/ directories.
Diffstat (limited to 'httemplate/search/cust_main-zip.html')
-rw-r--r--httemplate/search/cust_main-zip.html175
1 files changed, 89 insertions, 86 deletions
diff --git a/httemplate/search/cust_main-zip.html b/httemplate/search/cust_main-zip.html
index 9790c0fef..56df924bc 100644
--- a/httemplate/search/cust_main-zip.html
+++ b/httemplate/search/cust_main-zip.html
@@ -1,89 +1,3 @@
-%
-%
-%# XXX link to customers
-%
-%my @where = ();
-%
-%# select status
-%
-%if ( $cgi->param('status') =~ /^(prospect|uncancel|active|susp|cancel)$/ ) {
-% my $method = $1.'_sql';
-% push @where, FS::cust_main->$method();
-%}
-%
-%# select agent
-%# XXX this needs to be virtualized by agent too (like lots of stuff)
-%
-%my $agentnum = '';
-%if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
-% $agentnum = $1;
-% push @where, "cust_main.agentnum = $agentnum";
-%}
-%my $where = scalar(@where) ? 'WHERE '. join(' AND ', @where) : '';
-%
-%# bill zip vs ship zip
-%
-%sub fieldorempty {
-% my $field = shift;
-% "CASE WHEN $field IS NULL THEN '' ELSE $field END";
-%}
-%
-%sub strip_plus4 {
-% my $field = shift;
-% "CASE WHEN $field is NULL
-% THEN ''
-% ELSE CASE WHEN $field LIKE '_____-____'
-% THEN SUBSTRING($field FROM 1 FOR 5)
-% ELSE $field
-% END
-% END";
-%}
-%
-%my( $zip, $czip);
-%if ( $cgi->param('column') eq 'ship_zip' ) {
-%
-% my $casewhen_noship =
-% "CASE WHEN ( ship_last IS NULL OR ship_last = '' ) THEN ";
-%
-% $czip = "$casewhen_noship zip ELSE ship_zip END";
-%
-% if ( $cgi->param('ignore_plus4') ) {
-% $zip = $casewhen_noship. strip_plus4('zip').
-% " ELSE ". strip_plus4('ship_zip'). ' END';
-%
-% } else {
-% $zip = $casewhen_noship. fieldorempty('zip').
-% " ELSE ". fieldorempty('ship_zip'). ' END';
-% }
-%
-%} else {
-%
-% $czip = 'zip';
-%
-% if ( $cgi->param('ignore_plus4') ) {
-% $zip = strip_plus4('zip');
-% } else {
-% $zip = fieldorempty('zip');
-% }
-%
-%}
-%
-%# construct the queries and send 'em off
-%
-%my $sql_query =
-% "SELECT $zip AS zipcode,
-% COUNT(*) AS num_cust
-% FROM cust_main
-% $where
-% GROUP BY zipcode
-% ORDER BY num_cust DESC
-% ";
-%
-%my $count_sql = "select count(distinct $czip) from cust_main $where";
-%
-%# XXX should link...
-%
-%
<% include( 'elements/search.html',
'title' => 'Zip code Search Results',
'name' => 'zip codes',
@@ -94,3 +8,92 @@
'links' => [ '', sub { 'somewhere'; } ],
)
%>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('List zip codes');
+
+# XXX link to customers
+
+my @where = ();
+
+# select status
+
+if ( $cgi->param('status') =~ /^(prospect|uncancel|active|susp|cancel)$/ ) {
+ my $method = $1.'_sql';
+ push @where, FS::cust_main->$method();
+}
+
+# select agent
+# XXX this needs to be virtualized by agent too (like lots of stuff)
+
+my $agentnum = '';
+if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
+ $agentnum = $1;
+ push @where, "cust_main.agentnum = $agentnum";
+}
+my $where = scalar(@where) ? 'WHERE '. join(' AND ', @where) : '';
+
+# bill zip vs ship zip
+
+sub fieldorempty {
+ my $field = shift;
+ "CASE WHEN $field IS NULL THEN '' ELSE $field END";
+}
+
+sub strip_plus4 {
+ my $field = shift;
+ "CASE WHEN $field is NULL
+ THEN ''
+ ELSE CASE WHEN $field LIKE '_____-____'
+ THEN SUBSTRING($field FROM 1 FOR 5)
+ ELSE $field
+ END
+ END";
+}
+
+my( $zip, $czip);
+if ( $cgi->param('column') eq 'ship_zip' ) {
+
+ my $casewhen_noship =
+ "CASE WHEN ( ship_last IS NULL OR ship_last = '' ) THEN ";
+
+ $czip = "$casewhen_noship zip ELSE ship_zip END";
+
+ if ( $cgi->param('ignore_plus4') ) {
+ $zip = $casewhen_noship. strip_plus4('zip').
+ " ELSE ". strip_plus4('ship_zip'). ' END';
+
+ } else {
+ $zip = $casewhen_noship. fieldorempty('zip').
+ " ELSE ". fieldorempty('ship_zip'). ' END';
+ }
+
+} else {
+
+ $czip = 'zip';
+
+ if ( $cgi->param('ignore_plus4') ) {
+ $zip = strip_plus4('zip');
+ } else {
+ $zip = fieldorempty('zip');
+ }
+
+}
+
+# construct the queries and send 'em off
+
+my $sql_query =
+ "SELECT $zip AS zipcode,
+ COUNT(*) AS num_cust
+ FROM cust_main
+ $where
+ GROUP BY zipcode
+ ORDER BY num_cust DESC
+ ";
+
+my $count_sql = "select count(distinct $czip) from cust_main $where";
+
+# XXX should link...
+
+</%init>