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',
17 { label => 'Requested', colspan => 2 },
19 { label => 'Paid', colspan => 2 },
34 'align' => 'rcllrrrrc',
35 'fields' => [ 'batchnum',
37 FS::payby->shortname(shift->payby);
41 my $_date = $self->download;
43 time2str("%a %b %e %T %Y", $_date);
44 } elsif ( $self->status eq 'O' ) {
52 my $_date = $self->upload;
54 time2str("%a %b %e %T %Y", $_date);
55 } elsif ( $self->status eq 'I' ) {
62 my $c = FS::cust_pay_batch->count('batchnum = '.$_[0]->batchnum);
66 my $st = "SELECT SUM(amount) from cust_pay_batch WHERE batchnum=" . shift->batchnum;
67 my $sth = dbh->prepare($st)
68 or die dbh->errstr. "doing $st";
70 or die "Error executing \"$st\": ". $sth->errstr;
71 my $total = $sth->fetchrow_arrayref->[0];
72 $total ? $money_char.sprintf('%.2f',$total) : '';
75 my $c = FS::cust_pay->count('batchnum = '.$_[0]->batchnum);
79 my $st = "SELECT SUM(paid) from cust_pay WHERE batchnum=" . shift->batchnum;
80 my $sth = dbh->prepare($st)
81 or die dbh->errstr. "doing $st";
83 or die "Error executing \"$st\": ". $sth->errstr;
84 my $total = $sth->fetchrow_arrayref->[0];
85 $total ? $money_char.sprintf('%.2f',$total) : '';
88 $statusmap{shift->status};
94 sub { shift->status eq 'O' ? $cpb_link : '' },
95 sub { shift->status eq 'I' ? $cpb_link : '' },
104 sub { shift->status eq 'O' ? "+1" : '' },
105 sub { shift->status eq 'I' ? "+1" : '' },
110 sub { shift->status eq 'O' ? "b" : '' },
111 sub { shift->status eq 'I' ? "b" : '' },
113 'html_init' => $html_init,
114 'html_foot' => include('.upload_incoming'),
116 <%def .upload_incoming>
117 % if ( FS::payment_gateway->count("gateway_namespace = 'Business::BatchPayment' AND disabled IS NULL") > 0 ) {
118 <& /elements/form-file_upload.html,
119 name => 'FileUpload',
120 action => $p.'misc/upload-batch.cgi',
122 fields => [ 'gatewaynum' ],
123 message => 'Incoming batch uploaded.',
127 Upload incoming batch from gateway
128 <& /elements/select-table.html,
129 table => 'payment_gateway',
130 field => 'gatewaynum',
132 value_col => 'gatewaynum',
133 order_by => 'ORDER BY gatewaynum',
136 { 'gateway_namespace' => 'Business::BatchPayment',
140 <& '/elements/file-upload.html',
145 <INPUT TYPE="submit" VALUE="Upload">
152 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports')
153 || $FS::CurrentUser::CurrentUser->access_right('Process batches');
155 my %statusmap = ('I'=>'In Transit', 'O'=>'Open', 'R'=>'Resolved');
157 my $count_query = 'SELECT COUNT(*) FROM pay_batch';
159 my($begin, $end) = ( '', '' );
163 my($beginning,$ending) = FS::UI::Web::parse_beginning_ending($cgi);
164 push @where, "( (download >= $beginning AND download <= $ending) ".
165 ' OR download IS NULL )';
168 if ( $cgi->param('open') ) {
172 if ( $cgi->param('intransit') ) {
176 if ( $cgi->param('resolved') ) {
181 scalar(@status) ? q!(status='! . join(q!' OR status='!, @status) . q!')!
182 : q!status='X'!; # kludgy, X is unused at present
184 my $extra_sql = scalar(@where) ? 'WHERE ' . join(' AND ', @where) : '';
186 my $cpb_link = [ "${p}search/cust_pay_batch.cgi?dcln=1;batchnum=", 'batchnum' ];
187 my $pay_link = [ "${p}search/cust_pay.html?magic=batchnum;batchnum=", 'batchnum' ];
189 my $resolved = $cgi->param('resolved') || 0;
190 $cgi->param('resolved' => !$resolved);
191 my $html_init = '<A HREF="' . $cgi->self_url . '"><I>'.
192 ($resolved ? 'Hide' : 'Show') . ' resolved batches</I></A><BR>';
194 my $money_char = FS::Conf->new->config('money_char') || '$';