Revert "RT# 39340 - configured the minimal selfservice to get mac address from radius...
[freeside.git] / httemplate / search / pay_batch.cgi
1 <& elements/search.html,
2                  'title'         => 'Payment Batches',
3                  'name_singular' => 'batch',
4                  'query'         => { 'table'     => 'pay_batch',
5                                       'hashref'   => $hashref,
6                                       'extra_sql' => $extra_sql,
7                                       'order_by'  => 'ORDER BY batchnum DESC',
8                                     },
9                  'count_query'   => "$count_query $extra_sql",
10                  'agent_virt'    => 1,
11                  'agent_null_right' => 'Process batches', #'Process global batches',
12                  'agent_pos'     => 1,
13                  'header'        => [ 'Batch',
14                                       'Type',
15                                       'First Download',
16                                       'Last Upload',
17                                       { label => 'Requested', colspan => 2 },
18                                       '',
19                                       { label => 'Paid', colspan => 2 },
20                                       '',
21                                       'Status',
22                                     ],
23                  'header2'       => [ '',
24                                       '',
25                                       '',
26                                       '',
27                                       '',
28                                       'Items',
29                                       'Amount',
30                                       'Items',
31                                       'Amount',
32                                       '',
33                                     ],
34                  'align'         => 'rcllrrrrc',
35                  'fields'        => [ 'batchnum',
36                                       sub { 
37                                         FS::payby->shortname(shift->payby);
38                                       },
39                                       sub {
40                                         my $self = shift;
41                                         my $_date = $self->download;
42                                         if ( $_date ) {
43                                           time2str("%a %b %e %T %Y", $_date);
44                                         } elsif ( $self->status eq 'O' ) {
45                                           'Download batch';
46                                         } else {
47                                           '';
48                                         }
49                                       },
50                                       sub {
51                                         my $self = shift;
52                                         my $_date = $self->upload;
53                                         if ( $_date ) {
54                                           time2str("%a %b %e %T %Y", $_date);
55                                         } elsif ( $self->status eq 'I' ) {
56                                           'Upload results';
57                                         } else {
58                                           '';
59                                         }
60                                       },
61                                       sub {
62                                         my $c = FS::cust_pay_batch->count('batchnum = '.$_[0]->batchnum);
63                                         $c || ''
64                                       },
65                                       sub {
66                                         my $st = "SELECT SUM(amount) from cust_pay_batch WHERE batchnum=" . shift->batchnum;
67                                         my $sth = dbh->prepare($st)
68                                           or die dbh->errstr. "doing $st";
69                                         $sth->execute
70                                           or die "Error executing \"$st\": ". $sth->errstr;
71                                         my $total = $sth->fetchrow_arrayref->[0];
72                                         $total ? $money_char.sprintf('%.2f',$total) : '';
73                                       },
74                                       sub {
75                                         my $c = FS::cust_pay->count('batchnum = '.$_[0]->batchnum);
76                                         $c || '';
77                                       },
78                                       sub {
79                                         my $st = "SELECT SUM(paid) from cust_pay WHERE batchnum=" . shift->batchnum;
80                                         my $sth = dbh->prepare($st)
81                                           or die dbh->errstr. "doing $st";
82                                         $sth->execute
83                                           or die "Error executing \"$st\": ". $sth->errstr;
84                                         my $total = $sth->fetchrow_arrayref->[0];
85                                         $total ? $money_char.sprintf('%.2f',$total) : '';
86                                       },
87                                       sub {
88                                         $statusmap{shift->status};
89                                       },
90                                     ],
91                  'links'         => [
92                                       '',
93                                       '',
94                                       sub { shift->status eq 'O' ? $cpb_link : '' },
95                                       sub { shift->status eq 'I' ? $cpb_link : '' },
96                                       $cpb_link,
97                                       $cpb_link,
98                                       $pay_link,
99                                       $pay_link,
100                                     ],
101                  'size'         => [
102                                       '',
103                                       '',
104                                       sub { shift->status eq 'O' ? "+1" : '' },
105                                       sub { shift->status eq 'I' ? "+1" : '' },
106                                     ],
107                  'style'         => [
108                                       '',
109                                       '',
110                                       sub { shift->status eq 'O' ? "b" : '' },
111                                       sub { shift->status eq 'I' ? "b" : '' },
112                                     ],
113                  'html_init'     => $html_init,
114                  'html_foot'     => include('.upload_incoming'),
115 &>
116 <%def .upload_incoming>
117 % if ( FS::payment_gateway->count("gateway_namespace = 'Business::BatchPayment' AND disabled IS NULL") > 0 ) { 
118 <& /elements/form-file_upload.html,
119     name      => 'FileUpload',
120     action    => $p.'misc/upload-batch.cgi',
121     num_files => 1,
122     fields    => [ 'gatewaynum' ],
123     message   => 'Incoming batch uploaded.',
124 &>
125 <BR>
126 <BR>
127 Upload incoming batch from gateway 
128 <& /elements/select-table.html,
129     table       => 'payment_gateway',
130     field       => 'gatewaynum',
131     name_col    => 'label',
132     value_col   => 'gatewaynum',
133     order_by    => 'ORDER BY gatewaynum',
134     empty_label => ' ',
135     hashref     =>
136       { 'gateway_namespace' => 'Business::BatchPayment',
137         'disabled' => '' },
138 &>
139 <BR>
140 <& '/elements/file-upload.html',
141     field     => 'file',
142     label     => 'Filename',
143     no_table  => 1,
144 &>
145 <INPUT TYPE="submit" VALUE="Upload">
146 </FORM>
147 % }
148 </%def>
149 <%init>
150
151 die "access denied"
152   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports')
153       || $FS::CurrentUser::CurrentUser->access_right('Process batches');
154
155 my %statusmap = ('I'=>'In Transit', 'O'=>'Open', 'R'=>'Resolved');
156 my $hashref = {};
157 my $count_query = 'SELECT COUNT(*) FROM pay_batch';
158
159 my($begin, $end) = ( '', '' );
160
161 my @where;
162
163 my($beginning,$ending) = FS::UI::Web::parse_beginning_ending($cgi);
164 push @where, "( (download >= $beginning AND download <= $ending) ".
165              ' OR download IS NULL )';
166
167 my @status;
168 if ( $cgi->param('open') ) {
169   push @status, "O";
170 }
171
172 if ( $cgi->param('intransit') ) {
173   push @status, "I";
174 }
175
176 if ( $cgi->param('resolved') ) {
177   push @status, "R";
178 }
179
180 push @where,
181      scalar(@status) ? q!(status='! . join(q!' OR status='!, @status) . q!')!
182                      : q!status='X'!;  # kludgy, X is unused at present
183
184 my $extra_sql = scalar(@where) ? 'WHERE ' . join(' AND ', @where) : ''; 
185
186 my $cpb_link = [ "${p}search/cust_pay_batch.cgi?dcln=1;batchnum=", 'batchnum' ];
187 my $pay_link = [ "${p}search/cust_pay.html?magic=batchnum;batchnum=", 'batchnum' ];
188
189 my $resolved = $cgi->param('resolved') || 0;
190 $cgi->param('resolved' => !$resolved);
191 my $html_init = '<A HREF="' . $cgi->self_url . '"><I>'.
192     ($resolved ? 'Hide' : 'Show') . ' resolved batches</I></A><BR>';
193
194 my $money_char = FS::Conf->new->config('money_char') || '$';
195
196 </%init>