2 my $title = 'Payment Search Results';
3 my( $count_query, $sql_query );
4 if ( $cgi->param('magic') && $cgi->param('magic') eq '_date' ) {
8 if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
9 push @search, "agentnum = $1"; # $search{'agentnum'} = $1;
10 my $agent = qsearchs('agent', { 'agentnum' => $1 } );
11 die "unknown agentnum $1" unless $agent;
12 $title = $agent->agent. " $title";
15 if ( $cgi->param('payby') ) {
16 $cgi->param('payby') =~ /^(CARD|CHEK|BILL)(-(VisaMC|Amex|Discover))?$/
17 or die "illegal payby ". $cgi->param('payby');
18 push @search, "cust_pay.payby = '$1'";
20 if ( $3 eq 'VisaMC' ) {
21 #avoid posix regexes for portability
23 " ( substring(cust_pay.payinfo from 1 for 1) = '4' ".
24 " OR substring(cust_pay.payinfo from 1 for 2) = '51' ".
25 " OR substring(cust_pay.payinfo from 1 for 2) = '52' ".
26 " OR substring(cust_pay.payinfo from 1 for 2) = '53' ".
27 " OR substring(cust_pay.payinfo from 1 for 2) = '54' ".
28 " OR substring(cust_pay.payinfo from 1 for 2) = '54' ".
29 " OR substring(cust_pay.payinfo from 1 for 2) = '55' ".
31 } elsif ( $3 eq 'Amex' ) {
33 " ( substring(cust_pay.payinfo from 1 for 2 ) = '34' ".
34 " OR substring(cust_pay.payinfo from 1 for 2 ) = '37' ".
36 } elsif ( $3 eq 'Discover' ) {
38 " substring(cust_pay.payinfo from 1 for 4 ) = '6011' ";
40 die "unknown card type $3";
45 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
46 push @search, "_date >= $beginning ",
51 $search = ' WHERE '. join(' AND ', @search);
54 $count_query = "SELECT COUNT(*), SUM(paid) ".
55 "FROM cust_pay LEFT JOIN cust_main USING ( custnum )".
59 'table' => 'cust_pay',
60 'select' => join(', ',
62 'cust_main.custnum as cust_main_custnum',
63 FS::UI::Web::cust_sql_fields(),
66 'extra_sql' => "$search ORDER BY _date",
67 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
72 $cgi->param('payinfo') =~ /^\s*(\d+)\s*$/ or die "illegal payinfo";
75 $cgi->param('payby') =~ /^(\w+)$/ or die "illegal payby";
78 $count_query = "SELECT COUNT(*), SUM(paid) FROM cust_pay ".
79 "WHERE payinfo = '$payinfo' AND payby = '$payby'";
82 'table' => 'cust_pay',
83 'hashref' => { 'payinfo' => $payinfo,
85 'extra_sql' => "ORDER BY _date",
92 $cust_pay->cust_main_custnum
93 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
97 %><%= include( 'elements/search.html',
100 'query' => $sql_query,
101 'count_query' => $count_query,
102 'count_addl' => [ '$%.2f total paid', ],
103 'header' => [ 'Payment',
106 FS::UI::Web::cust_header(),
110 my $cust_pay = shift;
111 if ( $cust_pay->payby eq 'CARD' ) {
112 'Card #'. $cust_pay->payinfo_masked;
113 } elsif ( $cust_pay->payby eq 'CHEK' ) {
114 'E-check acct#'. $cust_pay->payinfo;
115 } elsif ( $cust_pay->payby eq 'BILL' ) {
116 'Check #'. $cust_pay->payinfo;
117 } elsif ( $cust_pay->payby eq 'PREP' ) {
118 'Prepaid card #'. $cust_pay->payinfo;
120 $cust_pay->payby. ' '. $cust_pay->payinfo;
123 sub { sprintf('$%.2f', shift->paid ) },
124 sub { time2str('%b %d %Y', shift->_date ) },
125 \&FS::UI::Web::cust_fields,
127 #'align' => 'lrrrll',
133 ( map { $link } FS::UI::Web::cust_header() ),