per-agent invoice PDF batches, RT#13727
[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'  => 'ORDER BY batchnum DESC',
8                                     },
9                  'count_query'   => $count_query,
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                  'agent_virt' => 1,
46                  'agent_null_right' => [ 'Process global invoice batches', 'Configuration' ],
47                  'agent_pos' => 1,
48
49       )
50
51 %>
52 <%init>
53
54 my $curuser = $FS::CurrentUser::CurrentUser;
55
56 die "access denied"
57   unless $curuser->access_right('Process invoice batches')
58       || $curuser->access_right('Process global invoice batches')
59       || $curuser->access_right('Configuration'); #remove in 2.5
60
61 my %statusmap = ('O'=>'Open', 'R'=>'Closed');
62 my $hashref = {};
63 my $count_query = "SELECT COUNT(*) FROM bill_batch WHERE". # $extra_sql AND "
64                     $curuser->agentnums_sql(
65                       'null_right' => ['Process global invoice batches', 'Configuration' ],
66                     );
67
68 #my $extra_sql = ''; # may add something here later
69 my $link = [ "${p}view/bill_batch.cgi?batchnum=", 'batchnum' ];
70 my $dlink = sub {
71   [ "${p}view/bill_batch.cgi?start_download=1;".
72       (shift->status eq 'O' ? 'close=1;' : '').
73       'batchnum=',
74     'batchnum'] 
75 };
76 </%init>