add menu items for credit card batching, debug last-minute changes to payby.pm, add...
[freeside.git] / httemplate / search / pay_batch.cgi
1 %
2 %
3 %my %statusmap = ('I'=>'In Transit', 'O'=>'Open', 'R'=>'Resolved');
4 %my $hashref = {};
5 %my $count_query = 'SELECT COUNT(*) FROM pay_batch';
6 %
7 %my($begin, $end) = ( '', '' );
8 %
9 %my @where;
10 %if ( $cgi->param('beginning')
11 %     && $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/ ) {
12 %  $begin = str2time($1);
13 %  push @where, "download >= $begin";
14 %}
15 %if ( $cgi->param('ending')
16 %      && $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/ ) {
17 %  $end = str2time($1) + 86399;
18 %  push @where, "download < $end";
19 %}
20 %
21 %my @status;
22 %if ( $cgi->param('open') ) {
23 %  push @status, "O";
24 %}
25 %
26 %if ( $cgi->param('intransit') ) {
27 %  push @status, "I";
28 %}
29 %
30 %if ( $cgi->param('resolved') ) {
31 %  push @status, "R";
32 %}
33 %
34 %push @where,
35 %     scalar(@status) ? q!(status='! . join(q!' OR status='!, @status) . q!')!
36 %                     : q!status='X'!;  # kludgy, X is unused at present
37 %
38 %my $extra_sql = scalar(@where) ? 'WHERE ' . join(' AND ', @where) : ''; 
39 %
40 %my $link = [ "${p}search/cust_pay_batch.cgi?batchnum=", 'batchnum' ];
41 %
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",
48                                     },
49                  'count_query'   => "$count_query $extra_sql",
50                  'header'        => [ 'Batch',
51                                       'Type',
52                                       'First Download',
53                                       'Last Upload',
54                                       'Item Count',
55                                       'Amount',
56                                       'Status',
57                                     ],
58                  'align'         => 'rcllrrc',
59                  'fields'        => [ 'batchnum',
60                                       sub { 
61                                         FS::payby->shortname(shift->payby);
62                                       },
63                                       sub {
64                                         my $self = shift;
65                                         my $_date = $self->download;
66                                         if ( $_date ) {
67                                           time2str("%a %b %e %T %Y", $_date);
68                                         } elsif ( $self->status eq 'O' ) {
69                                           'Download batch';
70                                         } else {
71                                           '';
72                                         }
73                                       },
74                                       sub {
75                                         my $self = shift;
76                                         my $_date = $self->upload;
77                                         if ( $_date ) {
78                                           time2str("%a %b %e %T %Y", $_date);
79                                         } elsif ( $self->status eq 'I' ) {
80                                           'Upload results';
81                                         } else {
82                                           '';
83                                         }
84                                       },
85                                       sub {
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";
89                                         $sth->execute
90                                           or die "Error executing \"$st\": ". $sth->errstr;
91                                         $sth->fetchrow_arrayref->[0];
92                                       },
93                                       sub {
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";
97                                         $sth->execute
98                                           or die "Error executing \"$st\": ". $sth->errstr;
99                                         $sth->fetchrow_arrayref->[0];
100                                       },
101                                       sub {
102                                         $statusmap{shift->status};
103                                       },
104                                     ],
105                  'links'         => [
106                                       $link,
107                                       '',
108                                       sub { shift->status eq 'O' ? $link : '' },
109                                       sub { shift->status eq 'I' ? $link : '' },
110                                     ],
111                  'size'         => [
112                                       '',
113                                       '',
114                                       sub { shift->status eq 'O' ? "+1" : '' },
115                                       sub { shift->status eq 'I' ? "+1" : '' },
116                                     ],
117                  'style'         => [
118                                       '',
119                                       '',
120                                       sub { shift->status eq 'O' ? "b" : '' },
121                                       sub { shift->status eq 'I' ? "b" : '' },
122                                     ],
123       )
124
125 %>
126
127