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',
23 'fields' => [ 'batchnum',
25 FS::payby->shortname(shift->payby);
29 my $_date = $self->download;
31 time2str("%a %b %e %T %Y", $_date);
32 } elsif ( $self->status eq 'O' ) {
40 my $_date = $self->upload;
42 time2str("%a %b %e %T %Y", $_date);
43 } elsif ( $self->status eq 'I' ) {
50 FS::cust_pay_batch->count(
51 'batchnum = '.$_[0]->batchnum
55 FS::cust_pay_batch->count(
56 'status is null and batchnum = '.
61 my $st = "SELECT SUM(amount) from cust_pay_batch WHERE batchnum=" . shift->batchnum;
62 my $sth = dbh->prepare($st)
63 or die dbh->errstr. "doing $st";
65 or die "Error executing \"$st\": ". $sth->errstr;
66 $sth->fetchrow_arrayref->[0];
69 $statusmap{shift->status};
75 sub { shift->status eq 'O' ? $link : '' },
76 sub { shift->status eq 'I' ? $link : '' },
81 sub { shift->status eq 'O' ? "+1" : '' },
82 sub { shift->status eq 'I' ? "+1" : '' },
87 sub { shift->status eq 'O' ? "b" : '' },
88 sub { shift->status eq 'I' ? "b" : '' },
90 'html_init' => $html_init,
97 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports')
98 || $FS::CurrentUser::CurrentUser->access_right('Process batches');
100 my %statusmap = ('I'=>'In Transit', 'O'=>'Open', 'R'=>'Resolved');
102 my $count_query = 'SELECT COUNT(*) FROM pay_batch';
104 my($begin, $end) = ( '', '' );
107 if ( $cgi->param('beginning')
108 && $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/ ) {
109 $begin = parse_datetime($1);
110 push @where, "download >= $begin";
112 if ( $cgi->param('ending')
113 && $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/ ) {
114 $end = parse_datetime($1) + 86399;
115 push @where, "download < $end";
119 if ( $cgi->param('open') ) {
123 if ( $cgi->param('intransit') ) {
127 if ( $cgi->param('resolved') ) {
132 scalar(@status) ? q!(status='! . join(q!' OR status='!, @status) . q!')!
133 : q!status='X'!; # kludgy, X is unused at present
135 my $extra_sql = scalar(@where) ? 'WHERE ' . join(' AND ', @where) : '';
137 my $link = [ "${p}search/cust_pay_batch.cgi?dcln=1;batchnum=", 'batchnum' ];
139 my $resolved = $cgi->param('resolved') || 0;
140 $cgi->param('resolved' => !$resolved);
141 my $html_init = '<A HREF="' . $cgi->self_url . '"><I>'.
142 ($resolved ? 'Hide' : 'Show') . ' resolved batches</I></A><BR>';