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",
10 'header' => [ 'Batch',
19 'fields' => [ 'batchnum',
21 FS::payby->shortname(shift->payby);
25 my $_date = $self->download;
27 time2str("%a %b %e %T %Y", $_date);
28 } elsif ( $self->status eq 'O' ) {
36 my $_date = $self->upload;
38 time2str("%a %b %e %T %Y", $_date);
39 } elsif ( $self->status eq 'I' ) {
46 my $st = "SELECT COUNT(*) from cust_pay_batch WHERE batchnum=" . shift->batchnum;
47 my $sth = dbh->prepare($st)
48 or die dbh->errstr. "doing $st";
50 or die "Error executing \"$st\": ". $sth->errstr;
51 $sth->fetchrow_arrayref->[0];
54 my $st = "SELECT SUM(amount) from cust_pay_batch WHERE batchnum=" . shift->batchnum;
55 my $sth = dbh->prepare($st)
56 or die dbh->errstr. "doing $st";
58 or die "Error executing \"$st\": ". $sth->errstr;
59 $sth->fetchrow_arrayref->[0];
62 $statusmap{shift->status};
68 sub { shift->status eq 'O' ? $link : '' },
69 sub { shift->status eq 'I' ? $link : '' },
74 sub { shift->status eq 'O' ? "+1" : '' },
75 sub { shift->status eq 'I' ? "+1" : '' },
80 sub { shift->status eq 'O' ? "b" : '' },
81 sub { shift->status eq 'I' ? "b" : '' },
89 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports')
90 || $FS::CurrentUser::CurrentUser->access_right('Process batches');
92 my %statusmap = ('I'=>'In Transit', 'O'=>'Open', 'R'=>'Resolved');
94 my $count_query = 'SELECT COUNT(*) FROM pay_batch';
96 my($begin, $end) = ( '', '' );
99 if ( $cgi->param('beginning')
100 && $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/ ) {
101 $begin = parse_datetime($1);
102 push @where, "download >= $begin";
104 if ( $cgi->param('ending')
105 && $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/ ) {
106 $end = parse_datetime($1) + 86399;
107 push @where, "download < $end";
111 if ( $cgi->param('open') ) {
115 if ( $cgi->param('intransit') ) {
119 if ( $cgi->param('resolved') ) {
124 scalar(@status) ? q!(status='! . join(q!' OR status='!, @status) . q!')!
125 : q!status='X'!; # kludgy, X is unused at present
127 my $extra_sql = scalar(@where) ? 'WHERE ' . join(' AND ', @where) : '';
129 my $link = [ "${p}search/cust_pay_batch.cgi?dcln=1;batchnum=", 'batchnum' ];