1 <& 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'),
105 <%def .upload_incoming>
106 % if ( FS::payment_gateway->count("gateway_namespace = 'Business::BatchPayment' AND disabled IS NULL") > 0 ) {
107 <& /elements/form-file_upload.html,
108 name => 'FileUpload',
109 action => $p.'misc/upload-batch.cgi',
111 fields => [ 'gatewaynum' ],
112 message => 'Incoming batch uploaded.',
116 Upload incoming batch from gateway
117 <& /elements/select-table.html,
118 table => 'payment_gateway',
119 field => 'gatewaynum',
121 value_col => 'gatewaynum',
122 order_by => 'ORDER BY gatewaynum',
125 { 'gateway_namespace' => 'Business::BatchPayment',
129 <& '/elements/file-upload.html',
134 <INPUT TYPE="submit" VALUE="Upload">
141 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports')
142 || $FS::CurrentUser::CurrentUser->access_right('Process batches');
144 my %statusmap = ('I'=>'In Transit', 'O'=>'Open', 'R'=>'Resolved');
146 my $count_query = 'SELECT COUNT(*) FROM pay_batch';
148 my($begin, $end) = ( '', '' );
152 my($beginning,$ending) = FS::UI::Web::parse_beginning_ending($cgi);
153 push @where, "download >= $beginning",
154 "download <= $ending";
157 if ( $cgi->param('open') ) {
161 if ( $cgi->param('intransit') ) {
165 if ( $cgi->param('resolved') ) {
170 scalar(@status) ? q!(status='! . join(q!' OR status='!, @status) . q!')!
171 : q!status='X'!; # kludgy, X is unused at present
173 my $extra_sql = scalar(@where) ? 'WHERE ' . join(' AND ', @where) : '';
175 my $cpb_link = [ "${p}search/cust_pay_batch.cgi?dcln=1;batchnum=", 'batchnum' ];
176 my $pay_link = [ "${p}search/cust_pay.html?magic=batchnum;batchnum=", 'batchnum' ];
178 my $resolved = $cgi->param('resolved') || 0;
179 $cgi->param('resolved' => !$resolved);
180 my $html_init = '<A HREF="' . $cgi->self_url . '"><I>'.
181 ($resolved ? 'Hide' : 'Show') . ' resolved batches</I></A><BR>';
183 my $money_char = FS::Conf->new->config('money_char') || '$';