3 %my %statusmap = ('I'=>'In Transit', 'O'=>'Open', 'R'=>'Resolved');
5 %my $count_query = 'SELECT COUNT(*) FROM pay_batch';
7 %my($begin, $end) = ( '', '' );
10 %if ( $cgi->param('beginning')
11 % && $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/ ) {
12 % $begin = str2time($1);
13 % push @where, "download >= $begin";
15 %if ( $cgi->param('ending')
16 % && $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/ ) {
17 % $end = str2time($1) + 86399;
18 % push @where, "download < $end";
22 %if ( $cgi->param('open') ) {
26 %if ( $cgi->param('intransit') ) {
30 %if ( $cgi->param('resolved') ) {
35 % scalar(@status) ? q!(status='! . join(q!' OR status='!, @status) . q!')!
36 % : q!status='X'!; # kludgy, X is unused at present
38 %my $extra_sql = scalar(@where) ? 'WHERE ' . join(' AND ', @where) : '';
40 %my $link = [ "${p}search/cust_pay_batch.cgi?batchnum=", 'batchnum' ];
42 <% include( 'elements/search.html',
43 'title' => 'Payment Batches',
44 'name_singular' => 'batch',
45 'query' => { 'table' => 'pay_batch',
46 'hashref' => $hashref,
47 'extra_sql' => "$extra_sql ORDER BY batchnum DESC",
49 'count_query' => "$count_query $extra_sql",
50 'header' => [ 'Batch',
59 'fields' => [ 'batchnum',
61 FS::payby->shortname(shift->payby);
65 my $_date = $self->download;
67 time2str("%a %b %e %T %Y", $_date);
68 } elsif ( $self->status eq 'O' ) {
76 my $_date = $self->upload;
78 time2str("%a %b %e %T %Y", $_date);
79 } elsif ( $self->status eq 'I' ) {
86 my $st = "SELECT COUNT(*) from cust_pay_batch WHERE batchnum=" . shift->batchnum;
87 my $sth = dbh->prepare($st)
88 or die dbh->errstr. "doing $st";
90 or die "Error executing \"$st\": ". $sth->errstr;
91 $sth->fetchrow_arrayref->[0];
94 my $st = "SELECT SUM(amount) from cust_pay_batch WHERE batchnum=" . shift->batchnum;
95 my $sth = dbh->prepare($st)
96 or die dbh->errstr. "doing $st";
98 or die "Error executing \"$st\": ". $sth->errstr;
99 $sth->fetchrow_arrayref->[0];
102 $statusmap{shift->status};
108 sub { shift->status eq 'O' ? $link : '' },
109 sub { shift->status eq 'I' ? $link : '' },
114 sub { shift->status eq 'O' ? "+1" : '' },
115 sub { shift->status eq 'I' ? "+1" : '' },
120 sub { shift->status eq 'O' ? "b" : '' },
121 sub { shift->status eq 'I' ? "b" : '' },