[freeside-commits] freeside/httemplate/search
report_cust_main-zip.html, NONE, 1.1 cust_main-zip.html, NONE,
1.1 cust_main.cgi, 1.60, 1.61
Ivan,,,
ivan at wavetail.420.am
Wed Apr 12 05:36:41 PDT 2006
Update of /home/cvs/cvsroot/freeside/httemplate/search
In directory wavetail:/tmp/cvs-serv2564/httemplate/search
Modified Files:
cust_main.cgi
Added Files:
report_cust_main-zip.html cust_main-zip.html
Log Message:
zip code report
--- NEW FILE: report_cust_main-zip.html ---
<%= include('/elements/header.html', 'Zip code report') %>
<FORM ACTION="cust_main-zip.html" METHOD="GET">
<TABLE>
<TR>
<TD ALIGN="right">Billing or service zip</TD>
<TD>
<SELECT NAME="column">
<OPTION VALUE="zip">Billing zip
<OPTION VALUE="ship_zip">Service zip
</SELECT>
</TD>
</TR>
<TR>
<TD ALIGN="right">Ignore +4 for US zip codes</TD>
<TD><INPUT TYPE="checkbox" NAME="ignore_plus4" VALUE="yes" CHECKED> </TD>
</TR>
<TR>
<TD ALIGN="right">Show customers with status:</TD>
<TD>
<SELECT NAME="status">
<OPTION VALUE="">all
<OPTION VALUE="prospect">prospect (no packages ever)
<OPTION SELECTED VALUE="uncancel">all except cancelled
<OPTION VALUE="active">active recurring packages
<OPTION VALUE="susp">suspended
<OPTION VALUE="cancel">cancelled
</SELECT>
</TD>
</TR>
<%= include( '/elements/tr-select-agent.html',
$cgi->param('agentnum'),
'label' => 'for agent: ',
)
%>
</TABLE>
<BR><INPUT TYPE="submit" VALUE="Get Report">
</FORM>
</BODY>
</HTML>
Index: cust_main.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/search/cust_main.cgi,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- cust_main.cgi 21 May 2005 17:26:01 -0000 1.60
+++ cust_main.cgi 12 Apr 2006 12:36:39 -0000 1.61
@@ -102,18 +102,8 @@
&& ! $cgi->param('showcancelledcustomers') )
) {
#grep { $_->ncancelled_pkgs || ! $_->all_pkgs }
- push @qual, "
- ( 0 < ( SELECT COUNT(*) FROM cust_pkg
- WHERE cust_pkg.custnum = cust_main.custnum
- AND ( cust_pkg.cancel IS NULL
- OR cust_pkg.cancel = 0
- )
- )
- OR 0 = ( SELECT COUNT(*) FROM cust_pkg
- WHERE cust_pkg.custnum = cust_main.custnum
- )
- )
- ";
+ push @qual, FS::cust_main->uncancel_sql;
+
}
push @qual, FS::cust_main->cancel_sql if $cgi->param('cancelled');
--- NEW FILE: cust_main-zip.html ---
<%
# 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',
'query' => $sql_query,
'count_query' => $count_sql,
'header' => [ 'Zip code', 'Customers', ],
#'fields' => [ 'zip', 'num_cust', ],
'links' => [ '', sub { 'somewhere'; } ],
)
%>
More information about the freeside-commits
mailing list