1 <% include('elements/search.html',
2 'title' => 'Batch payment details',
3 'name' => 'batch details',
5 'count_query' => $count_query,
6 'html_init' => $pay_batch ? $html_init : '',
7 'disable_download' => 1,
29 $cpb->[3] . ', ' . $cpb->[4];
35 my $cardnum = shift->[6];
36 'x'x(length($cardnum)-4). substr($cardnum,(length($cardnum)-4));
39 shift->[7] =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
40 my( $mon, $year ) = ( $2, $1 );
41 $mon = "0$mon" if length($mon) == 1;
51 'align' => 'lllllllrl',
52 'links' => [ ['', sub{'#';}],
53 ["${p}view/cust_bill.cgi?", sub{shift->[1];},],
54 ["${p}view/cust_main.cgi?", sub{shift->[2];},],
55 ["${p}view/cust_main.cgi?", sub{shift->[2];},],
61 my $conf = new FS::Conf;
64 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports')
65 || $FS::CurrentUser::CurrentUser->access_right('Process batches')
66 || ( $cgi->param('custnum')
67 && ( $conf->exists('batch-enable')
68 || $conf->config('batch-enable_payby')
72 my( $count_query, $sql_query );
75 my $orderby = 'paybatchnum';
77 my( $pay_batch, $batchnum ) = ( '', '');
78 if ( $cgi->param('batchnum') && $cgi->param('batchnum') =~ /^(\d+)$/ ) {
79 push @search, "batchnum = $1";
80 $pay_batch = qsearchs('pay_batch', { 'batchnum' => $1 } );
81 die "Batch $1 not found!" unless $pay_batch;
82 $batchnum = $pay_batch->batchnum;
85 if ( $cgi->param('custnum') && $cgi->param('custnum') =~ /^(\d+)$/ ) {
86 push @search, "custnum = $1";
89 if ( $cgi->param('status') && $cgi->param('status') =~ /^(\w)$/ ) {
90 push @search, "pay_batch.status = '$1'";
93 if ( $cgi->param('payby') ) {
94 $cgi->param('payby') =~ /^(CARD|CHEK)$/
95 or die "illegal payby " . $cgi->param('payby');
97 push @search, "cust_pay_batch.payby = '$1'";
100 if ( not $cgi->param('dcln') ) {
101 push @search, "cpb.status IS DISTINCT FROM 'Approved'";
104 my ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
106 push @search, "pay_batch.upload >= $beginning" if ($beginning);
107 push @search, "pay_batch.upload <= $ending" if ($ending < 4294967295);#2^32-1
108 $orderby = "pay_batch.download,paybatchnum";
111 push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;
112 my $search = ' WHERE ' . join(' AND ', @search);
114 $count_query = 'SELECT COUNT(*) FROM cust_pay_batch AS cpb ' .
115 'LEFT JOIN cust_main USING ( custnum ) ' .
116 'LEFT JOIN pay_batch USING ( batchnum )' .
120 $sql_query = "SELECT paybatchnum,invnum,custnum,cpb.last,cpb.first," .
121 "cpb.payname,cpb.payinfo,cpb.exp,amount,cpb.status " .
122 "FROM cust_pay_batch AS cpb " .
123 'LEFT JOIN cust_main USING ( custnum ) ' .
124 'LEFT JOIN pay_batch USING ( batchnum ) ' .
125 "$search ORDER BY $orderby";
129 $html_init = include('elements/cust_pay_batch_top.html',
130 'pay_batch' => $pay_batch);