freeside/httemplate/search cust_bill.html,1.2,1.3 sql.html,1.2,1.3
ivan
ivan at pouncequick.420.am
Thu Apr 22 19:32:40 PDT 2004
Update of /home/cvs/cvsroot/freeside/httemplate/search
In directory pouncequick:/tmp/cvs-serv13975/search
Modified Files:
cust_bill.html sql.html
Log Message:
working templated invoice search!
Index: cust_bill.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/search/cust_bill.html,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- cust_bill.html 26 Dec 2001 04:52:38 -0000 1.2
+++ cust_bill.html 23 Apr 2004 02:32:37 -0000 1.3
@@ -1,19 +1,81 @@
-<HTML>
- <HEAD>
- <TITLE>Invoice Search</TITLE>
- </HEAD>
- <BODY BGCOLOR="#e8e8e8">
- <FONT SIZE=7>
- Invoice Search
- </FONT>
- <BR><BR>
- <FORM ACTION="cust_bill.cgi" METHOD="post">
- Search for <B>invoice #</B>:
- <INPUT TYPE="text" NAME="invnum">
+<%
+ my( $count_query, $sql_query );
+ if ( $cgi->keywords ) {
+ my($query) = $cgi->keywords;
+ my $owed =
+ "charged - ( SELECT COALESCE(SUM(amount),0) FROM cust_bill_pay
+ WHERE cust_bill_pay.invnum = cust_bill.invnum )
+ - ( SELECT COALESCE(SUM(amount),0) FROM cust_credit_bill
+ WHERE cust_credit_bill.invnum = cust_bill.invnum )";
+ my @where;
+ my $orderby = '';
+ if ( $query =~ /^(OPEN(\d*)_)?(invnum|date|custnum)$/ ) {
+ my($open, $days, $field) = ($1, $2, $3);
+ $field = "_date" if $field eq 'date';
+ $orderby = "ORDER BY cust_bill.$field";
+ push @where, "0 != $owed" if $open;
+ push @where, "cust_bill._date < ". (time-86400*$days) if $days;
+ } else {
+ die "unknown query string $query";
+ }
+
+ my $extra_sql = scalar(@where) ? 'WHERE '. join(' AND ', @where) : '';
+
+ $count_query = "SELECT COUNT(*), sum(charged), sum($owed)
+ FROM cust_bill $extra_sql";
+
+ $sql_query = {
+ 'table' => 'cust_bill',
+ 'hashref' => {},
+ 'select' => "cust_bill.*, $owed as owed",
+ 'extra_sql' => "$extra_sql $orderby"
+ };
+
+ } else {
+ $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/;
+ $count_query = 'SELECT 1';
+ $sql_query = {
+ 'table' => 'cust_bill',
+ 'hashref' => { 'invnum' => $2 },
+ #'select' => '*',
+ };
+ }
- <P><INPUT TYPE="submit" VALUE="Search">
+ my $link = [ "${p}view/cust_bill.cgi?", 'invnum', ];
+ my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];
- </FORM>
- </BODY>
-</HTML>
+%>
+<%= include( 'elements/search.html',
+ 'title' => 'Invoice Search Results',
+ 'name' => 'invoices',
+ 'query' => $sql_query,
+ 'count_query' => $count_query,
+ 'count_addl' => [ '$%.2f total amount',
+ '$%.2f total outstanding balance',
+ ],
+ 'redirect' => $link,
+ 'header' =>
+ [ '', qw(Balance Amount Date ), 'Contact name', 'Company' ],
+ 'fields' => [
+ 'invnum',
+ sub { sprintf('$%.2f', shift->get('owed') ) },
+ sub { sprintf('$%.2f', shift->charged ) },
+ sub { time2str('%b %d %Y', shift->_date ) },
+ sub { my $cust_main = shift->cust_main;
+ $cust_main->get('last'). ', '. $cust_main->first;
+ },
+ sub { my $cust_main = shift->cust_main;
+ $cust_main->company;
+ },
+ ],
+ 'links' => [
+ $link,
+ $link,
+ $link,
+ $link,
+ $clink,
+ $clink,
+ ],
+ )
+%>
Index: sql.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/search/sql.html,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- sql.html 8 Aug 2003 05:42:13 -0000 1.2
+++ sql.html 23 Apr 2004 02:32:37 -0000 1.3
@@ -1,12 +1,7 @@
-<%= include( '/elements/header.html', 'Query Results',
- include( '/elements/menubar.html', 'Main Menu' => $p )
- )
-%>
-
<%= include( 'elements/search.html',
+ 'title' => 'Query Results',
'name' => 'rows',
'query' => 'SELECT '. ( $cgi->param('sql')
|| eidiot('Empty query') ),
)
%>
-
More information about the freeside-commits
mailing list