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',
38 my $type = $self->type eq 'CREDIT' ? 'CREDIT' : '';
39 $type ." " . FS::payby->shortname($self->payby);
43 my $_date = $self->download;
45 time2str("%a %b %e %T %Y", $_date);
46 } elsif ( $self->status eq 'O' ) {
54 my $_date = $self->upload;
56 time2str("%a %b %e %T %Y", $_date);
57 } elsif ( $self->status eq 'I' ) {
64 my $c = FS::cust_pay_batch->count('batchnum = '.$_[0]->batchnum);
68 my $st = "SELECT SUM(amount) from cust_pay_batch 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 my $c = FS::cust_pay->count('batchnum = '.$_[0]->batchnum);
81 my $st = "SELECT SUM(paid) from cust_pay WHERE batchnum=" . shift->batchnum;
82 my $sth = dbh->prepare($st)
83 or die dbh->errstr. "doing $st";
85 or die "Error executing \"$st\": ". $sth->errstr;
86 my $total = $sth->fetchrow_arrayref->[0];
87 $total ? $money_char.sprintf('%.2f',$total) : '';
90 $statusmap{shift->status};
96 sub { shift->status eq 'O' ? $cpb_link : '' },
97 sub { shift->status eq 'I' ? $cpb_link : '' },
106 sub { shift->status eq 'O' ? "+1" : '' },
107 sub { shift->status eq 'I' ? "+1" : '' },
112 sub { shift->status eq 'O' ? "b" : '' },
113 sub { shift->status eq 'I' ? "b" : '' },
115 'html_init' => $html_init,
116 'html_foot' => include('.upload_incoming'),
118 <%def .upload_incoming>
119 % if ( FS::payment_gateway->count("gateway_namespace = 'Business::BatchPayment' AND disabled IS NULL") > 0 ) {
120 <& /elements/form-file_upload.html,
121 name => 'FileUpload',
122 action => $p.'misc/upload-batch.cgi',
124 fields => [ 'gatewaynum' ],
125 message => 'Incoming batch uploaded.',
129 Upload incoming batch from gateway
130 <& /elements/select-table.html,
131 table => 'payment_gateway',
132 field => 'gatewaynum',
134 value_col => 'gatewaynum',
135 order_by => 'ORDER BY gatewaynum',
138 { 'gateway_namespace' => 'Business::BatchPayment',
142 <& '/elements/file-upload.html',
147 <INPUT TYPE="submit" VALUE="Upload">
154 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports')
155 || $FS::CurrentUser::CurrentUser->access_right('Process batches');
157 my %statusmap = ('I'=>'In Transit', 'O'=>'Open', 'R'=>'Resolved');
159 my $count_query = 'SELECT COUNT(*) FROM pay_batch';
161 my($begin, $end) = ( '', '' );
165 my($beginning,$ending) = FS::UI::Web::parse_beginning_ending($cgi);
166 push @where, "( (download >= $beginning AND download <= $ending) ".
167 ' OR download IS NULL )';
170 if ( $cgi->param('open') ) {
174 if ( $cgi->param('intransit') ) {
178 if ( $cgi->param('resolved') ) {
183 scalar(@status) ? q!(status='! . join(q!' OR status='!, @status) . q!')!
184 : q!status='X'!; # kludgy, X is unused at present
186 my $extra_sql = scalar(@where) ? 'WHERE ' . join(' AND ', @where) : '';
188 my $cpb_link = [ "${p}search/cust_pay_batch.cgi?dcln=1;batchnum=", 'batchnum' ];
189 my $pay_link = [ "${p}search/cust_pay.html?magic=batchnum;batchnum=", 'batchnum' ];
191 my $resolved = $cgi->param('resolved') || 0;
192 $cgi->param('resolved' => !$resolved);
193 my $html_init = '<A HREF="' . $cgi->self_url . '"><I>'.
194 ($resolved ? 'Hide' : 'Show') . ' resolved batches</I></A><BR>';
196 my $money_char = FS::Conf->new->config('money_char') || '$';