2 #my( $count_query, $sql_query );
6 if ( $cgi->param('otaker') && $cgi->param('otaker') =~ /^([\w\.\-]+)$/ ) {
7 push @search, "otaker = '$1'";
10 #false laziness with cust_pkg.cgi and cust_pay.cgi
11 if ( $cgi->param('beginning')
12 && $cgi->param('beginning') =~ /^([ 0-9\-\/]{1,10})$/ ) {
13 my $beginning = str2time($1);
14 push @search, "_date >= $beginning ";
16 if ( $cgi->param('ending')
17 && $cgi->param('ending') =~ /^([ 0-9\-\/]{1,10})$/ ) {
18 my $ending = str2time($1) + 86399;
19 push @search, " _date <= $ending ";
22 if ( $cgi->param('begin')
23 && $cgi->param('begin') =~ /^(\d+)$/ ) {
24 push @search, "_date >= $1 ";
26 if ( $cgi->param('end')
27 && $cgi->param('end') =~ /^(\d+)$/ ) {
28 push @search, " _date < $1 ";
31 my $where = scalar(@search)
32 ? 'WHERE '. join(' AND ', @search)
35 my $count_query = "SELECT COUNT(*), SUM(amount) FROM cust_credit $where";
37 'table' => 'cust_credit',
39 'extra_sql' => $where,
42 my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];
45 <%= include( 'elements/search.html',
46 'title' => 'Credit Search Results',
48 'query' => $sql_query,
49 'count_query' => $count_query,
50 'count_addl' => [ '$%.2f total credited', ],
53 [ qw(Amount Date), 'Cust #', 'Contact name',
54 qw(Company By Reason) ],
57 sub { sprintf('$%.2f', shift->amount ) },
58 sub { time2str('%b %d %Y', shift->_date ) },
60 sub { my $cust_main = shift->cust_main;
61 $cust_main->get('last'). ', '. $cust_main->first;
63 sub { my $cust_main = shift->cust_main;