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",
11 'agent_null_right' => 'Process batches', #'Process global batches',
13 'header' => [ 'Batch',
22 'fields' => [ 'batchnum',
24 FS::payby->shortname(shift->payby);
28 my $_date = $self->download;
30 time2str("%a %b %e %T %Y", $_date);
31 } elsif ( $self->status eq 'O' ) {
39 my $_date = $self->upload;
41 time2str("%a %b %e %T %Y", $_date);
42 } elsif ( $self->status eq 'I' ) {
49 my $st = "SELECT COUNT(*) from cust_pay_batch WHERE batchnum=" . shift->batchnum;
50 my $sth = dbh->prepare($st)
51 or die dbh->errstr. "doing $st";
53 or die "Error executing \"$st\": ". $sth->errstr;
54 $sth->fetchrow_arrayref->[0];
57 my $st = "SELECT SUM(amount) from cust_pay_batch WHERE batchnum=" . shift->batchnum;
58 my $sth = dbh->prepare($st)
59 or die dbh->errstr. "doing $st";
61 or die "Error executing \"$st\": ". $sth->errstr;
62 $sth->fetchrow_arrayref->[0];
65 $statusmap{shift->status};
71 sub { shift->status eq 'O' ? $link : '' },
72 sub { shift->status eq 'I' ? $link : '' },
77 sub { shift->status eq 'O' ? "+1" : '' },
78 sub { shift->status eq 'I' ? "+1" : '' },
83 sub { shift->status eq 'O' ? "b" : '' },
84 sub { shift->status eq 'I' ? "b" : '' },
86 'html_init' => $html_init,
93 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports')
94 || $FS::CurrentUser::CurrentUser->access_right('Process batches');
96 my %statusmap = ('I'=>'In Transit', 'O'=>'Open', 'R'=>'Resolved');
98 my $count_query = 'SELECT COUNT(*) FROM pay_batch';
100 my($begin, $end) = ( '', '' );
103 if ( $cgi->param('beginning')
104 && $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/ ) {
105 $begin = parse_datetime($1);
106 push @where, "download >= $begin";
108 if ( $cgi->param('ending')
109 && $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/ ) {
110 $end = parse_datetime($1) + 86399;
111 push @where, "download < $end";
115 if ( $cgi->param('open') ) {
119 if ( $cgi->param('intransit') ) {
123 if ( $cgi->param('resolved') ) {
128 scalar(@status) ? q!(status='! . join(q!' OR status='!, @status) . q!')!
129 : q!status='X'!; # kludgy, X is unused at present
131 my $extra_sql = scalar(@where) ? 'WHERE ' . join(' AND ', @where) : '';
133 my $link = [ "${p}search/cust_pay_batch.cgi?dcln=1;batchnum=", 'batchnum' ];
135 my $resolved = $cgi->param('resolved') || 0;
136 $cgi->param('resolved' => !$resolved);
137 my $html_init = '<A HREF="' . $cgi->self_url . '"><I>'.
138 ($resolved ? 'Hide' : 'Show') . ' resolved batches</I></A><BR>';