1 <& 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,
47 my $conf = new FS::Conf;
49 my $curuser = $FS::CurrentUser::CurrentUser;
52 unless $curuser->access_right('Financial reports')
53 || $curuser->access_right('Process batches')
54 || $curuser->access_right('Process global batches')
55 || ( $cgi->param('custnum')
56 && ( $conf->exists('batch-enable')
57 || $conf->config('batch-enable_payby')
61 my( $count_query, $sql_query );
64 my $orderby = 'paybatchnum';
66 my( $pay_batch, $batchnum ) = ( '', '');
67 if ( $cgi->param('batchnum') && $cgi->param('batchnum') =~ /^(\d+)$/ ) {
68 push @search, "batchnum = $1";
69 $pay_batch = qsearchs('pay_batch', { 'batchnum' => $1 } );
70 die "Batch $1 not found!" unless $pay_batch;
71 $batchnum = $pay_batch->batchnum;
74 if ( $cgi->param('custnum') && $cgi->param('custnum') =~ /^(\d+)$/ ) {
75 push @search, "cust_pay_batch.custnum = $1";
78 if ( $cgi->param('status') && $cgi->param('status') =~ /^(\w)$/ ) {
79 push @search, "pay_batch.status = '$1'";
82 if ( $cgi->param('payby') ) {
83 $cgi->param('payby') =~ /^(CARD|CHEK)$/
84 or die "illegal payby " . $cgi->param('payby');
86 push @search, "cust_pay_batch.payby = '$1'";
89 if ( not $cgi->param('dcln') ) {
90 push @search, "cust_pay_batch.status IS DISTINCT FROM 'Approved'";
93 my ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
95 push @search, "pay_batch.upload >= $beginning" if ($beginning);
96 push @search, "pay_batch.upload <= $ending" if ($ending < 4294967295);#2^32-1
97 $orderby = "pay_batch.download,paybatchnum";
100 push @search, $curuser->agentnums_sql({ table => 'cust_main' });
102 push @search, $curuser->agentnums_sql({ table => 'pay_batch',
103 null_right => 'Process global batches',
106 my $search = ' WHERE ' . join(' AND ', @search);
108 $count_query = 'SELECT COUNT(*) FROM cust_pay_batch ' .
109 'LEFT JOIN cust_main USING ( custnum ) ' .
110 'LEFT JOIN pay_batch USING ( batchnum )' .
114 'table' => 'cust_pay_batch',
115 'select' => 'cust_pay_batch.*, cust_main.*, cust_pay.paynum',
117 'addl_from' => 'LEFT JOIN pay_batch USING ( batchnum ) '.
118 'LEFT JOIN cust_main USING ( custnum ) '.
119 'LEFT JOIN cust_pay USING ( batchnum, custnum ) ',
120 'extra_sql' => $search,
121 'order_by' => "ORDER BY $orderby",
124 my $sub_receipt = sub {
125 my $paynum = shift->paynum or return '';
126 include('/elements/popup_link_onclick.html',
127 'action' => $p.'view/cust_pay.html?link=popup;paynum='.$paynum,
128 'actionlabel' => emt('Payment Receipt'),
134 $html_init = include('elements/cust_pay_batch_top.html',
135 'pay_batch' => $pay_batch);