1 <% include( 'elements/search.html',
2 'title' => 'Payment Batches',
3 'name_singular' => 'batch',
4 'query' => { 'table' => 'pay_batch',
6 'extra_sql' => "$extra_sql ORDER BY batchnum DESC",
8 'count_query' => "$count_query $extra_sql",
18 'fields' => [ 'batchnum',
20 FS::payby->shortname(shift->payby);
24 my $_date = $self->download;
26 time2str("%a %b %e %T %Y", $_date);
27 } elsif ( $self->status eq 'O' ) {
35 my $_date = $self->upload;
37 time2str("%a %b %e %T %Y", $_date);
38 } elsif ( $self->status eq 'I' ) {
45 my $st = "SELECT COUNT(*) from cust_pay_batch WHERE batchnum=" . shift->batchnum;
46 my $sth = dbh->prepare($st)
47 or die dbh->errstr. "doing $st";
49 or die "Error executing \"$st\": ". $sth->errstr;
50 $sth->fetchrow_arrayref->[0];
53 my $st = "SELECT SUM(amount) from cust_pay_batch WHERE batchnum=" . shift->batchnum;
54 my $sth = dbh->prepare($st)
55 or die dbh->errstr. "doing $st";
57 or die "Error executing \"$st\": ". $sth->errstr;
58 $sth->fetchrow_arrayref->[0];
61 $statusmap{shift->status};
67 sub { shift->status eq 'O' ? $link : '' },
68 sub { shift->status eq 'I' ? $link : '' },
73 sub { shift->status eq 'O' ? "+1" : '' },
74 sub { shift->status eq 'I' ? "+1" : '' },
79 sub { shift->status eq 'O' ? "b" : '' },
80 sub { shift->status eq 'I' ? "b" : '' },
88 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports')
89 || $FS::CurrentUser::CurrentUser->access_right('Process batches');
91 my %statusmap = ('I'=>'In Transit', 'O'=>'Open', 'R'=>'Resolved');
93 my $count_query = 'SELECT COUNT(*) FROM pay_batch';
95 my($begin, $end) = ( '', '' );
98 if ( $cgi->param('beginning')
99 && $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/ ) {
100 $begin = parse_datetime($1);
101 push @where, "download >= $begin";
103 if ( $cgi->param('ending')
104 && $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/ ) {
105 $end = parse_datetime($1) + 86399;
106 push @where, "download < $end";
110 if ( $cgi->param('open') ) {
114 if ( $cgi->param('intransit') ) {
118 if ( $cgi->param('resolved') ) {
123 scalar(@status) ? q!(status='! . join(q!' OR status='!, @status) . q!')!
124 : q!status='X'!; # kludgy, X is unused at present
126 my $extra_sql = scalar(@where) ? 'WHERE ' . join(' AND ', @where) : '';
128 my $link = [ "${p}search/cust_pay_batch.cgi?dcln=1;batchnum=", 'batchnum' ];