1 <% include( 'elements/search.html',
2 'title' => 'Payment Batches',
3 'name_singular' => 'batch',
4 'query' => { 'table' => 'pay_batch',
6 'extra_sql' => $extra_sql,
7 'order_by' => 'ORDER BY batchnum DESC',
9 'count_query' => "$count_query $extra_sql",
11 'agent_null_right' => 'Process batches', #'Process global batches',
13 'header' => [ 'Batch',
23 'align' => 'rcllrrrrc',
24 'fields' => [ 'batchnum',
26 FS::payby->shortname(shift->payby);
30 my $_date = $self->download;
32 time2str("%a %b %e %T %Y", $_date);
33 } elsif ( $self->status eq 'O' ) {
41 my $_date = $self->upload;
43 time2str("%a %b %e %T %Y", $_date);
44 } elsif ( $self->status eq 'I' ) {
51 my $c = FS::cust_pay_batch->count('batchnum = '.$_[0]->batchnum);
52 $c ? "$c requested" : ''
55 my $st = "SELECT SUM(amount) from cust_pay_batch WHERE batchnum=" . shift->batchnum;
56 my $sth = dbh->prepare($st)
57 or die dbh->errstr. "doing $st";
59 or die "Error executing \"$st\": ". $sth->errstr;
60 my $total = $sth->fetchrow_arrayref->[0];
61 $total ? $money_char.sprintf('%.2f',$total) : '';
64 my $c = FS::cust_pay->count('batchnum = '.$_[0]->batchnum);
68 my $st = "SELECT SUM(paid) from cust_pay WHERE batchnum=" . shift->batchnum;
69 my $sth = dbh->prepare($st)
70 or die dbh->errstr. "doing $st";
72 or die "Error executing \"$st\": ". $sth->errstr;
73 my $total = $sth->fetchrow_arrayref->[0];
74 $total ? $money_char.sprintf('%.2f',$total) : '';
77 $statusmap{shift->status};
83 sub { shift->status eq 'O' ? $cpb_link : '' },
84 sub { shift->status eq 'I' ? $cpb_link : '' },
93 sub { shift->status eq 'O' ? "+1" : '' },
94 sub { shift->status eq 'I' ? "+1" : '' },
99 sub { shift->status eq 'O' ? "b" : '' },
100 sub { shift->status eq 'I' ? "b" : '' },
102 'html_init' => $html_init,
103 'html_foot' => include('.upload_incoming'),
106 <%def .upload_incoming>
107 % if ( FS::payment_gateway->count("gateway_namespace = 'Business::BatchPayment' AND disabled IS NULL") > 0 ) {
108 <& /elements/form-file_upload.html,
109 name => 'FileUpload',
110 action => $p.'misc/upload-batch.cgi',
112 fields => [ 'gatewaynum' ],
113 message => 'Incoming batch uploaded.',
117 Upload incoming batch from gateway
118 <& /elements/select-table.html,
119 table => 'payment_gateway',
120 field => 'gatewaynum',
122 value_col => 'gatewaynum',
123 order_by => 'ORDER BY gatewaynum',
126 { 'gateway_namespace' => 'Business::BatchPayment',
130 <& '/elements/file-upload.html',
135 <INPUT TYPE="submit" VALUE="Upload">
142 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports')
143 || $FS::CurrentUser::CurrentUser->access_right('Process batches');
145 my %statusmap = ('I'=>'In Transit', 'O'=>'Open', 'R'=>'Resolved');
147 my $count_query = 'SELECT COUNT(*) FROM pay_batch';
149 my($begin, $end) = ( '', '' );
152 if ( $cgi->param('beginning')
153 && $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/ ) {
154 $begin = parse_datetime($1);
155 push @where, "download >= $begin";
157 if ( $cgi->param('ending')
158 && $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/ ) {
159 $end = parse_datetime($1) + 86399;
160 push @where, "download < $end";
164 if ( $cgi->param('open') ) {
168 if ( $cgi->param('intransit') ) {
172 if ( $cgi->param('resolved') ) {
177 scalar(@status) ? q!(status='! . join(q!' OR status='!, @status) . q!')!
178 : q!status='X'!; # kludgy, X is unused at present
180 my $extra_sql = scalar(@where) ? 'WHERE ' . join(' AND ', @where) : '';
182 my $cpb_link = [ "${p}search/cust_pay_batch.cgi?dcln=1;batchnum=", 'batchnum' ];
183 my $pay_link = [ "${p}search/cust_pay.html?magic=batchnum;batchnum=", 'batchnum' ];
185 my $resolved = $cgi->param('resolved') || 0;
186 $cgi->param('resolved' => !$resolved);
187 my $html_init = '<A HREF="' . $cgi->self_url . '"><I>'.
188 ($resolved ? 'Hide' : 'Show') . ' resolved batches</I></A><BR>';
190 my $money_char = FS::Conf->new->config('money_char') || '$';