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" : '' },
83 'html_init' => $html_init,
90 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports')
91 || $FS::CurrentUser::CurrentUser->access_right('Process batches');
93 my %statusmap = ('I'=>'In Transit', 'O'=>'Open', 'R'=>'Resolved');
95 my $count_query = 'SELECT COUNT(*) FROM pay_batch';
97 my($begin, $end) = ( '', '' );
100 if ( $cgi->param('beginning')
101 && $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/ ) {
102 $begin = parse_datetime($1);
103 push @where, "download >= $begin";
105 if ( $cgi->param('ending')
106 && $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/ ) {
107 $end = parse_datetime($1) + 86399;
108 push @where, "download < $end";
112 if ( $cgi->param('open') ) {
116 if ( $cgi->param('intransit') ) {
120 if ( $cgi->param('resolved') ) {
125 scalar(@status) ? q!(status='! . join(q!' OR status='!, @status) . q!')!
126 : q!status='X'!; # kludgy, X is unused at present
128 my $extra_sql = scalar(@where) ? 'WHERE ' . join(' AND ', @where) : '';
130 my $link = [ "${p}search/cust_pay_batch.cgi?dcln=1;batchnum=", 'batchnum' ];
132 my $resolved = $cgi->param('resolved') || 0;
133 $cgi->param('resolved' => !$resolved);
134 my $html_init = '<A HREF="' . $cgi->self_url . '"><I>'.
135 ($resolved ? 'Hide' : 'Show') . ' resolved batches</I></A><BR>';