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',
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,
92 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports')
93 || $FS::CurrentUser::CurrentUser->access_right('Process batches');
95 my %statusmap = ('I'=>'In Transit', 'O'=>'Open', 'R'=>'Resolved');
97 my $count_query = 'SELECT COUNT(*) FROM pay_batch';
99 my($begin, $end) = ( '', '' );
103 my($beginning,$ending) = FS::UI::Web::parse_beginning_ending($cgi);
104 push @where, "( (download >= $beginning AND download <= $ending)".
105 ' OR download IS NULL )';
108 if ( $cgi->param('open') ) {
112 if ( $cgi->param('intransit') ) {
116 if ( $cgi->param('resolved') ) {
121 scalar(@status) ? q!(status='! . join(q!' OR status='!, @status) . q!')!
122 : q!status='X'!; # kludgy, X is unused at present
124 my $extra_sql = scalar(@where) ? 'WHERE ' . join(' AND ', @where) : '';
126 my $link = [ "${p}search/cust_pay_batch.cgi?dcln=1;batchnum=", 'batchnum' ];
128 my $resolved = $cgi->param('resolved') || 0;
129 $cgi->param('resolved' => !$resolved);
130 my $html_init = '<A HREF="' . $cgi->self_url . '"><I>'.
131 ($resolved ? 'Hide' : 'Show') . ' resolved batches</I></A><BR>';