1 % my $batchnum = $cgi->param('download');
2 % if ( $batchnum =~ /^\d+$/ ) {
3 % $cgi->delete('download');
5 <HEAD><TITLE>Starting download...</TITLE>
6 <SCRIPT TYPE="text/javascript">
7 function refreshParent() {
8 window.top.setTimeout("window.top.location.href = '<% $cgi->self_url %>'", 2000);
9 window.top.location.replace('<%$p%>misc/download-bill_batch.html?<%$batchnum%>');
12 </HEAD><BODY onload="refreshParent();">
13 <& /elements/footer.html &>
16 <% include( 'elements/search.html',
17 'title' => 'Invoice Batches',
18 'name_singular' => 'batch',
19 'query' => { 'table' => 'bill_batch',
20 'hashref' => $hashref,
21 #'extra_sql' => $extra_sql.
22 'order_by' => 'ORDER BY batchnum DESC',
24 'count_query' => $count_query,
25 'header' => [ 'Batch',
31 'fields' => [ 'batchnum',
33 my $st = "SELECT COUNT(*) from cust_bill_batch WHERE batchnum=" . shift->batchnum;
34 my $sth = dbh->prepare($st)
35 or die dbh->errstr. "doing $st";
37 or die "Error executing \"$st\": ". $sth->errstr;
38 $sth->fetchrow_arrayref->[0];
41 $statusmap{shift->status};
51 'really_disable_download' => 1,
53 'agent_null_right' => [ 'Process global invoice batches', 'Configuration' ],
62 my $curuser = $FS::CurrentUser::CurrentUser;
65 unless $curuser->access_right('Process invoice batches')
66 || $curuser->access_right('Process global invoice batches')
67 || $curuser->access_right('Configuration'); #remove in 2.5
69 my %statusmap = ('O'=>'Open', 'R'=>'Closed');
71 my $count_query = "SELECT COUNT(*) FROM bill_batch WHERE". # $extra_sql AND "
72 $curuser->agentnums_sql(
73 'null_right' => ['Process global invoice batches', 'Configuration' ],
76 #my $extra_sql = ''; # may add something here later
77 my $link = [ "${p}view/bill_batch.cgi?batchnum=", 'batchnum' ];
79 my $download_id = int(rand(1000000));
83 my $batchnum = $batch->batchnum;
84 my $close = ($batch->status eq 'O' ? ';close=1' : '');
85 my $html = qq!<FORM NAME="Download$batchnum" STYLE="display:inline">
86 <INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum">
87 <INPUT TYPE="hidden" NAME="close" VALUE="1">
89 $html .= include('/elements/progress-init.html',
91 [ 'batchnum', 'close' ],
92 $p.'misc/process/bill_batch-print.html',
93 { url => $p."search/bill_batch.cgi?download=$batchnum" },
96 $html .= '<A href="#" onclick="batch'.$batchnum.'process();">' .
97 ($batch->status eq 'O' ? '<B>Download and close</B>' : 'Download');
98 $html .= '</A></FORM>';