2 my( $count_query, $sql_query );
3 if ( $cgi->param('magic') && $cgi->param('magic') eq '_date' ) {
8 if ( $cgi->param('payby') ) {
9 $cgi->param('payby') =~ /^(CARD|CHEK|BILL)(-(VisaMC|Amex|Discover))?$/
10 or die "illegal payby ". $cgi->param('payby');
11 $search{'payby'} = $1;
13 if ( $3 eq 'VisaMC' ) {
14 #avoid posix regexes for portability
15 push @search, " ( substring(payinfo from 1 for 1) = '4' ".
16 " OR substring(payinfo from 1 for 2) = '51' ".
17 " OR substring(payinfo from 1 for 2) = '52' ".
18 " OR substring(payinfo from 1 for 2) = '53' ".
19 " OR substring(payinfo from 1 for 2) = '54' ".
20 " OR substring(payinfo from 1 for 2) = '54' ".
21 " OR substring(payinfo from 1 for 2) = '55' ".
23 } elsif ( $3 eq 'Amex' ) {
24 push @search, " ( substring(payinfo from 1 for 2 ) = '34' ".
25 " OR substring(payinfo from 1 for 2 ) = '37' ".
27 } elsif ( $3 eq 'Discover' ) {
28 push @search, " substring(payinfo from 1 for 4 ) = '6011' ";
30 die "unknown card type $3";
35 #false laziness with cust_pkg.cgi
36 if ( $cgi->param('beginning')
37 && $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/ ) {
38 my $beginning = str2time($1);
39 push @search, "_date >= $beginning ";
41 if ( $cgi->param('ending')
42 && $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/ ) {
43 my $ending = str2time($1) + 86399;
44 push @search, " _date <= $ending ";
46 if ( $cgi->param('begin')
47 && $cgi->param('begin') =~ /^(\d+)$/ ) {
48 push @search, "_date >= $1 ";
50 if ( $cgi->param('end')
51 && $cgi->param('end') =~ /^(\d+)$/ ) {
52 push @search, " _date < $1 ";
57 $search = ( scalar(keys %search) ? ' AND ' : ' WHERE ' ).
58 join(' AND ', @search);
61 my $hsearch = join(' AND ', map { "$_ = '$search{$_}'" } keys %search );
62 $count_query = "SELECT COUNT(*), SUM(paid) FROM cust_pay ".
63 ( $hsearch ? " WHERE $hsearch " : '' ).
67 'table' => 'cust_pay',
68 'hashref' => \%search,
69 'extra_sql' => "$search ORDER BY _date",
74 $cgi->param('payinfo') =~ /^\s*(\d+)\s*$/ or die "illegal payinfo";
77 $cgi->param('payby') =~ /^(\w+)$/ or die "illegal payby";
80 $count_query = "SELECT COUNT(*), SUM(paid) FROM cust_pay ".
81 "WHERE payinfo = '$payinfo' AND payby = '$payby'";
84 'table' => 'cust_pay',
85 'hashref' => { 'payinfo' => $payinfo,
87 'extra_sql' => "ORDER BY _date",
92 my $link = [ "${p}view/cust_main.cgi?", 'custnum' ];
95 <%= include( 'elements/search.html',
96 'title' => 'Payment Search Results',
98 'query' => $sql_query,
99 'count_query' => $count_query,
100 'count_addl' => [ '$%.2f total paid', ],
102 [ qw(Payment Amount Date), 'Contact name', 'Company', ],
105 my $cust_pay = shift;
106 if ( $cust_pay->payby eq 'CARD' ) {
107 'Card #'. $cust_pay->payinfo_masked;
108 } elsif ( $cust_pay->payby eq 'CHEK' ) {
109 'E-check acct#'. $cust_pay->payinfo;
110 } elsif ( $cust_pay->payby eq 'BILL' ) {
111 'Check #'. $cust_pay->payinfo;
113 $cust_pay->payby. ' '. $cust_pay->payinfo;
116 sub { sprintf('$%.2f', shift->paid ) },
117 sub { time2str('%b %d %Y', shift->_date ) },
118 sub { my $cust_main = shift->cust_main;
119 $cust_main->get('last'). ', '. $cust_main->first;
121 sub { my $cust_main = shift->cust_main;