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' && $self->type eq 'CREDIT') {
47 'Download credit batch';
48 } elsif ( $self->status eq 'O' && $self->type eq 'DEBIT') {
56 my $_date = $self->upload;
58 time2str("%a %b %e %T %Y", $_date);
59 } elsif ( $self->status eq 'I' ) {
66 my $c = FS::cust_pay_batch->count('batchnum = '.$_[0]->batchnum);
70 my $st = "SELECT SUM(amount) from cust_pay_batch WHERE batchnum=" . shift->batchnum;
71 my $sth = dbh->prepare($st)
72 or die dbh->errstr. "doing $st";
74 or die "Error executing \"$st\": ". $sth->errstr;
75 my $total = $sth->fetchrow_arrayref->[0];
76 $total ? $money_char.sprintf('%.2f',$total) : '';
79 my $c = FS::cust_pay->count('batchnum = '.$_[0]->batchnum);
83 my $st = "SELECT SUM(paid) from cust_pay WHERE batchnum=" . shift->batchnum;
84 my $sth = dbh->prepare($st)
85 or die dbh->errstr. "doing $st";
87 or die "Error executing \"$st\": ". $sth->errstr;
88 my $total = $sth->fetchrow_arrayref->[0];
89 $total ? $money_char.sprintf('%.2f',$total) : '';
92 $statusmap{shift->status};
98 sub { shift->status eq 'O' ? $cpb_link : '' },
99 sub { shift->status eq 'I' ? $cpb_link : '' },
108 sub { shift->status eq 'O' ? "+1" : '' },
109 sub { shift->status eq 'I' ? "+1" : '' },
114 sub { shift->status eq 'O' ? "b" : '' },
115 sub { shift->status eq 'I' ? "b" : '' },
117 'html_init' => $html_init,
118 'html_foot' => include('.upload_incoming'),
120 <%def .upload_incoming>
121 % if ( FS::payment_gateway->count("gateway_namespace = 'Business::BatchPayment' AND disabled IS NULL") > 0 ) {
122 <& /elements/form-file_upload.html,
123 name => 'FileUpload',
124 action => $p.'misc/upload-batch.cgi',
126 fields => [ 'gatewaynum' ],
127 message => 'Incoming batch uploaded.',
131 Upload incoming batch from gateway
132 <& /elements/select-table.html,
133 table => 'payment_gateway',
134 field => 'gatewaynum',
136 value_col => 'gatewaynum',
137 order_by => 'ORDER BY gatewaynum',
140 { 'gateway_namespace' => 'Business::BatchPayment',
144 <& '/elements/file-upload.html',
149 <INPUT TYPE="submit" VALUE="Upload">
156 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports')
157 || $FS::CurrentUser::CurrentUser->access_right('Process batches');
159 my %statusmap = ('I'=>'In Transit', 'O'=>'Open', 'R'=>'Resolved');
161 my $count_query = 'SELECT COUNT(*) FROM pay_batch';
163 my($begin, $end) = ( '', '' );
167 my($beginning,$ending) = FS::UI::Web::parse_beginning_ending($cgi);
168 push @where, "( (download >= $beginning AND download <= $ending) ".
169 ' OR download IS NULL )';
172 if ( $cgi->param('open') ) {
176 if ( $cgi->param('intransit') ) {
180 if ( $cgi->param('resolved') ) {
185 scalar(@status) ? q!(status='! . join(q!' OR status='!, @status) . q!')!
186 : q!status='X'!; # kludgy, X is unused at present
188 my $extra_sql = scalar(@where) ? 'WHERE ' . join(' AND ', @where) : '';
190 my $cpb_link = [ "${p}search/cust_pay_batch.cgi?dcln=1;batchnum=", 'batchnum' ];
191 my $pay_link = [ "${p}search/cust_pay.html?magic=batchnum;batchnum=", 'batchnum' ];
193 my $resolved = $cgi->param('resolved') || 0;
194 $cgi->param('resolved' => !$resolved);
195 my $html_init = '<A HREF="' . $cgi->self_url . '"><I>'.
196 ($resolved ? 'Hide' : 'Show') . ' resolved batches</I></A><BR>';
198 my $money_char = FS::Conf->new->config('money_char') || '$';