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,
20 'fields' => [ 'paybatchnum',
23 sub { $_[0]->cust_main->name_short },
27 return('') if $_[0]->payby ne 'CARD';
28 $_[0]->get('exp') =~ /^\d\d(\d\d)-(\d\d)/;
29 sprintf('%02d/%02d',$1,$2);
32 sprintf('%.02f', $_[0]->amount)
34 sub { $_[0]->display_status },
38 'align' => 'rrrlllcrllll',
40 ["${p}view/cust_bill.cgi?", 'invnum'],
41 (["${p}view/cust_main.cgi?", 'custnum']) x 2,
43 'link_onclicks' => [ ('') x 8,
49 my $conf = new FS::Conf;
51 my $curuser = $FS::CurrentUser::CurrentUser;
54 unless $curuser->access_right('Financial reports')
55 || $curuser->access_right('Process batches')
56 || $curuser->access_right('Process global batches')
57 || ( $cgi->param('custnum')
58 && ( $conf->exists('batch-enable')
59 || $conf->config('batch-enable_payby')
63 my( $count_query, $sql_query );
66 my $orderby = 'paybatchnum';
68 my( $pay_batch, $batchnum ) = ( '', '');
69 if ( $cgi->param('batchnum') && $cgi->param('batchnum') =~ /^(\d+)$/ ) {
70 push @search, "batchnum = $1";
71 $pay_batch = qsearchs('pay_batch', { 'batchnum' => $1 } );
72 die "Batch $1 not found!" unless $pay_batch;
73 $batchnum = $pay_batch->batchnum;
76 if ( $cgi->param('custnum') && $cgi->param('custnum') =~ /^(\d+)$/ ) {
77 push @search, "cust_pay_batch.custnum = $1";
80 if ( $cgi->param('status') && $cgi->param('status') =~ /^(\w)$/ ) {
81 push @search, "pay_batch.status = '$1'";
84 if ( $cgi->param('payby') ) {
85 $cgi->param('payby') =~ /^(CARD|CHEK)$/
86 or die "illegal payby " . $cgi->param('payby');
88 push @search, "cust_pay_batch.payby = '$1'";
91 if ( not $cgi->param('dcln') ) {
92 push @search, "cust_pay_batch.status IS DISTINCT FROM 'Approved'";
95 my ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
97 push @search, "pay_batch.upload >= $beginning" if ($beginning);
98 push @search, "pay_batch.upload <= $ending" if ($ending < 4294967295);#2^32-1
99 $orderby = "pay_batch.download,paybatchnum";
102 push @search, $curuser->agentnums_sql({ table => 'cust_main' });
104 push @search, $curuser->agentnums_sql({ table => 'pay_batch',
105 null_right => 'Process global batches',
108 my $search = ' WHERE ' . join(' AND ', @search);
110 $count_query = 'SELECT COUNT(*) FROM cust_pay_batch ' .
111 'LEFT JOIN cust_main USING ( custnum ) ' .
112 'LEFT JOIN pay_batch USING ( batchnum )' .
116 'table' => 'cust_pay_batch',
117 'select' => 'cust_pay_batch.*, cust_pay.paynum',
119 'addl_from' => 'LEFT JOIN pay_batch USING ( batchnum ) '.
120 'LEFT JOIN cust_main USING ( custnum ) '.
121 'LEFT JOIN cust_pay USING ( batchnum, custnum ) ',
122 'extra_sql' => $search,
123 'order_by' => "ORDER BY $orderby",
126 my $sub_receipt = sub {
127 my $paynum = shift->paynum or return '';
128 include('/elements/popup_link_onclick.html',
129 'action' => $p.'view/cust_pay.html?link=popup;paynum='.$paynum,
130 'actionlabel' => emt('Payment Receipt'),
134 my $sub_unbatch = '';
135 if ( ($pay_batch && ($pay_batch->status eq 'O'))
136 && ( $curuser->access_right('Process batches')
137 || $curuser->access_right('Process global batches') )
141 return '' if $self->status; # sanity check, shouldn't happen
142 my $batchnum = $self->batchnum;
143 my $paybatchnum = $self->paybatchnum;
145 <FORM name="delete_cust_pay_batch_$paybatchnum">
146 <INPUT TYPE="hidden" name="paybatchnum" value="$paybatchnum">
149 $out .= include('/elements/progress-init.html',
150 "delete_cust_pay_batch_$paybatchnum",
152 $p.'misc/process/delete-cust_pay_batch.cgi',
153 $p.'search/cust_pay_batch.cgi?' . $cgi->query_string,
154 "paybatchnum$paybatchnum",
156 my $onclick = 'if ( confirm(\'';
157 $onclick .= emt('Are you sure you want to delete batch payment ') . $self->paybatchnum;
158 $onclick .= emt(' from payment batch ') . $self->batchnum;
159 $onclick .= '\') ) { paybatchnum' . $paybatchnum . 'process() }';
160 return $out . '<A HREF="javascript:void(0)" ONCLICK="' . $onclick . '">delete</A>';
166 $html_init = include('elements/cust_pay_batch_top.html',
167 'pay_batch' => $pay_batch);