invoice batch download fix, #11871
[freeside.git] / httemplate / search / bill_batch.cgi
1 <% include( 'elements/search.html',
2                  'title'         => 'Invoice Batches',
3                  'name_singular' => 'batch',
4                  'query'         => { 'table'     => 'bill_batch',
5                                       'hashref'   => $hashref,
6                                       'extra_sql' => $extra_sql.
7                                         'ORDER BY batchnum DESC',
8                                     },
9                  'count_query'   => "$count_query $extra_sql",
10                  'header'        => [ 'Batch',
11                                       'Item Count',
12                                       'Status',
13                                       '',
14                                     ],
15                  'align'         => 'rrcc',
16                  'fields'        => [ 'batchnum',
17                                       sub {
18                                         my $st = "SELECT COUNT(*) from cust_bill_batch WHERE batchnum=" . shift->batchnum;
19                                         my $sth = dbh->prepare($st)
20                                           or die dbh->errstr. "doing $st";
21                                         $sth->execute
22                                           or die "Error executing \"$st\": ". $sth->errstr;
23                                         $sth->fetchrow_arrayref->[0];
24                                       },
25                                       sub {
26                                         $statusmap{shift->status};
27                                       },
28                                       sub { shift->status eq 'O' ? 
29                                             'Download and close' : 'Download' 
30                                       },
31                                     ],
32                  'links'         => [
33                                       $link,
34                                       $link,
35                                       $link,
36                                       $dlink,
37                                     ],
38                  'style'         => [
39                                       '',
40                                       '',
41                                       '',
42                                       sub { shift->status eq 'O' ? "b" : '' },
43                                     ],
44                  'really_disable_download' => 1,
45       )
46
47 %>
48 <%init>
49
50 die "access denied"
51   unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
52
53 my %statusmap = ('O'=>'Open', 'R'=>'Closed');
54 my $hashref = {};
55 my $count_query = 'SELECT COUNT(*) FROM bill_batch';
56
57 my $extra_sql = ''; # may add something here later
58 my $link = [ "${p}view/bill_batch.cgi?batchnum=", 'batchnum' ];
59 my $dlink = sub {
60   [ "${p}view/bill_batch.cgi?start_download=1;".
61       (shift->status eq 'O' ? 'close=1;' : '').
62       'batchnum=',
63     'batchnum'] 
64 };
65 </%init>