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,
19 'fields' => [ 'paybatchnum',
22 sub { $_[0]->cust_main->name_short },
26 return('') if $_[0]->payby ne 'CARD';
27 $_[0]->get('exp') =~ /^\d\d(\d\d)-(\d\d)/;
28 sprintf('%02d/%02d',$1,$2);
31 sprintf('%.02f', $_[0]->amount)
36 'align' => 'rrrlllcrll',
38 ["${p}view/cust_bill.cgi?", 'invnum'],
39 (["${p}view/cust_main.cgi?", 'custnum']) x 2,
41 'link_onclicks' => [ ('') x 8,
48 my $conf = new FS::Conf;
50 my $curuser = $FS::CurrentUser::CurrentUser;
53 unless $curuser->access_right('Financial reports')
54 || $curuser->access_right('Process batches')
55 || $curuser->access_right('Process global batches')
56 || ( $cgi->param('custnum')
57 && ( $conf->exists('batch-enable')
58 || $conf->config('batch-enable_payby')
62 my( $count_query, $sql_query );
65 my $orderby = 'paybatchnum';
67 my( $pay_batch, $batchnum ) = ( '', '');
68 if ( $cgi->param('batchnum') && $cgi->param('batchnum') =~ /^(\d+)$/ ) {
69 push @search, "batchnum = $1";
70 $pay_batch = qsearchs('pay_batch', { 'batchnum' => $1 } );
71 die "Batch $1 not found!" unless $pay_batch;
72 $batchnum = $pay_batch->batchnum;
75 if ( $cgi->param('custnum') && $cgi->param('custnum') =~ /^(\d+)$/ ) {
76 push @search, "custnum = $1";
79 if ( $cgi->param('status') && $cgi->param('status') =~ /^(\w)$/ ) {
80 push @search, "pay_batch.status = '$1'";
83 if ( $cgi->param('payby') ) {
84 $cgi->param('payby') =~ /^(CARD|CHEK)$/
85 or die "illegal payby " . $cgi->param('payby');
87 push @search, "cust_pay_batch.payby = '$1'";
90 if ( not $cgi->param('dcln') ) {
91 push @search, "cpb.status IS DISTINCT FROM 'Approved'";
94 my ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
96 push @search, "pay_batch.upload >= $beginning" if ($beginning);
97 push @search, "pay_batch.upload <= $ending" if ($ending < 4294967295);#2^32-1
98 $orderby = "pay_batch.download,paybatchnum";
101 push @search, $curuser->agentnums_sql({ table=>'cust_main' });
103 my $search = ' WHERE ' . join(' AND ', @search);
105 $count_query = 'SELECT COUNT(*) FROM cust_pay_batch AS cpb ' .
106 'LEFT JOIN cust_main USING ( custnum ) ' .
107 'LEFT JOIN pay_batch USING ( batchnum )' .
111 'table' => 'cust_pay_batch',
112 'select' => 'cust_pay_batch.*, cust_main.*, cust_pay.paynum',
114 'addl_from' => 'LEFT JOIN pay_batch USING ( batchnum ) '.
115 'LEFT JOIN cust_main USING ( custnum ) '.
117 'LEFT JOIN cust_pay USING ( batchnum, custnum ) ',
118 'extra_sql' => $search,
119 'order_by' => "ORDER BY $orderby",
122 my $sub_receipt = sub {
123 my $paynum = shift->paynum or return '';
124 include('/elements/popup_link_onclick.html',
125 'action' => $p.'view/cust_pay.html?link=popup;paynum='.$paynum,
126 'actionlabel' => emt('Payment Receipt'),
132 $html_init = include('elements/cust_pay_batch_top.html',
133 'pay_batch' => $pay_batch);