2 my $title = 'Payment Search Results';
3 my( $count_query, $sql_query );
4 if ( $cgi->param('magic') ) {
8 if ( $cgi->param('magic') eq '_date' ) {
11 if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
12 push @search, "agentnum = $1"; # $search{'agentnum'} = $1;
13 my $agent = qsearchs('agent', { 'agentnum' => $1 } );
14 die "unknown agentnum $1" unless $agent;
15 $title = $agent->agent. " $title";
18 if ( $cgi->param('payby') ) {
19 $cgi->param('payby') =~ /^(CARD|CHEK|BILL)(-(VisaMC|Amex|Discover))?$/
20 or die "illegal payby ". $cgi->param('payby');
21 push @search, "cust_pay.payby = '$1'";
23 if ( $3 eq 'VisaMC' ) {
24 #avoid posix regexes for portability
26 " ( substring(cust_pay.payinfo from 1 for 1) = '4' ".
27 " OR substring(cust_pay.payinfo from 1 for 2) = '51' ".
28 " OR substring(cust_pay.payinfo from 1 for 2) = '52' ".
29 " OR substring(cust_pay.payinfo from 1 for 2) = '53' ".
30 " OR substring(cust_pay.payinfo from 1 for 2) = '54' ".
31 " OR substring(cust_pay.payinfo from 1 for 2) = '54' ".
32 " OR substring(cust_pay.payinfo from 1 for 2) = '55' ".
34 } elsif ( $3 eq 'Amex' ) {
36 " ( substring(cust_pay.payinfo from 1 for 2 ) = '34' ".
37 " OR substring(cust_pay.payinfo from 1 for 2 ) = '37' ".
39 } elsif ( $3 eq 'Discover' ) {
41 " substring(cust_pay.payinfo from 1 for 4 ) = '6011' ";
43 die "unknown card type $3";
48 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
49 push @search, "_date >= $beginning ",
54 } elsif ( $cgi->param('magic') eq 'paybatch' ) {
56 $cgi->param('paybatch') =~ /^([\w\/\:\-\.]+)$/
57 or die "illegal paybatch: ". $cgi->param('paybatch');
59 push @search, "paybatch = '$1'";
61 $orderby = "LOWER(company || ' ' || last || ' ' || first )";
64 die "unknown search magic: ". $cgi->param('magic');
69 $search = ' WHERE '. join(' AND ', @search);
72 $count_query = "SELECT COUNT(*), SUM(paid) ".
73 "FROM cust_pay LEFT JOIN cust_main USING ( custnum )".
77 'table' => 'cust_pay',
78 'select' => join(', ',
80 'cust_main.custnum as cust_main_custnum',
81 FS::UI::Web::cust_sql_fields(),
84 'extra_sql' => "$search ORDER BY $orderby",
85 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
90 $cgi->param('payinfo') =~ /^\s*(\d+)\s*$/ or die "illegal payinfo";
93 $cgi->param('payby') =~ /^(\w+)$/ or die "illegal payby";
96 $count_query = "SELECT COUNT(*), SUM(paid) FROM cust_pay ".
97 "WHERE payinfo = '$payinfo' AND payby = '$payby'";
100 'table' => 'cust_pay',
101 'hashref' => { 'payinfo' => $payinfo,
103 'extra_sql' => "ORDER BY _date",
109 my $cust_pay = shift;
110 $cust_pay->cust_main_custnum
111 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
115 %><%= include( 'elements/search.html',
117 'name' => 'payments',
118 'query' => $sql_query,
119 'count_query' => $count_query,
120 'count_addl' => [ '$%.2f total paid', ],
121 'header' => [ 'Payment',
124 FS::UI::Web::cust_header(),
128 my $cust_pay = shift;
129 if ( $cust_pay->payby eq 'CARD' ) {
130 'Card #'. $cust_pay->payinfo_masked;
131 } elsif ( $cust_pay->payby eq 'CHEK' ) {
132 'E-check acct#'. $cust_pay->payinfo;
133 } elsif ( $cust_pay->payby eq 'BILL' ) {
134 'Check #'. $cust_pay->payinfo;
135 } elsif ( $cust_pay->payby eq 'PREP' ) {
136 'Prepaid card #'. $cust_pay->payinfo;
138 $cust_pay->payby. ' '. $cust_pay->payinfo;
141 sub { sprintf('$%.2f', shift->paid ) },
142 sub { time2str('%b %d %Y', shift->_date ) },
143 \&FS::UI::Web::cust_fields,
145 #'align' => 'lrrrll',
151 ( map { $link } FS::UI::Web::cust_header() ),