1 % my $batchnum = $cgi->param('download');
2 % if ( $batchnum =~ /^\d+$/ ) {
3 % my $download = $p."misc/download-bill_batch.html?$batchnum";
5 <HEAD><TITLE>Starting download...</TITLE>
6 <SCRIPT TYPE="text/javascript">
8 window.location.replace('<% $download %>');
12 <SCRIPT TYPE="text/javascript">function start() {}</SCRIPT>
15 <BODY onload="start()" STYLE="background-color:#ccccff">
16 <TABLE STYLE="height:125px; width:100%; text-align:center"><TR><TD STYLE="vertical-align:middle;text-align:center">
17 <A HREF="<% $download %>">Click here if your download does not start</A>
19 <& /elements/footer.html &>
22 %# delete existing download cookie
23 % my $cookie = CGI::Cookie->new(
24 % -name => 'bill_batch_download',
28 % $r->headers_out->add( 'Set-Cookie' => $cookie->as_string );
29 <% include( 'elements/search.html',
30 'title' => 'Invoice Batches',
31 'name_singular' => 'batch',
32 'query' => { 'table' => 'bill_batch',
33 'hashref' => $hashref,
34 #'extra_sql' => $extra_sql.
35 'order_by' => 'ORDER BY batchnum DESC',
37 'count_query' => $count_query,
38 'header' => [ 'Batch',
44 'fields' => [ 'batchnum',
46 my $st = "SELECT COUNT(*) from cust_bill_batch WHERE batchnum=" . shift->batchnum;
47 my $sth = dbh->prepare($st)
48 or die dbh->errstr. "doing $st";
50 or die "Error executing \"$st\": ". $sth->errstr;
51 $sth->fetchrow_arrayref->[0];
54 $statusmap{shift->status};
64 'really_disable_download' => 1,
66 'agent_null_right' => [ 'Process global invoice batches', 'Configuration' ],
68 'html_foot' => include('.foot'),
75 <SCRIPT type="text/javascript">
77 function checkDownloadStatus(batchnum) {
78 var re = new RegExp('bill_batch_download=' + batchnum);
79 if ( re.test(document.cookie) ) {
80 window.clearInterval(timer);
81 window.location.reload();
84 function startBatch(batchnum) {
85 timer = window.setInterval(function() {
86 checkDownloadStatus(batchnum);
88 eval('batch'+batchnum+'process()');
94 my $curuser = $FS::CurrentUser::CurrentUser;
97 unless $curuser->access_right('Process invoice batches')
98 || $curuser->access_right('Process global invoice batches')
99 || $curuser->access_right('Configuration'); #remove in 2.5
101 my %statusmap = ('O'=>'Open', 'R'=>'Closed');
103 my $count_query = "SELECT COUNT(*) FROM bill_batch WHERE". # $extra_sql AND "
104 $curuser->agentnums_sql(
105 'null_right' => ['Process global invoice batches', 'Configuration' ],
108 #my $extra_sql = ''; # may add something here later
109 my $link = [ "${p}view/bill_batch.cgi?batchnum=", 'batchnum' ];
113 my $batchnum = $batch->batchnum;
114 my $close = ($batch->status eq 'O' ? ';close=1' : '');
115 my $html = qq!<FORM NAME="Download$batchnum" STYLE="display:inline">
116 <INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum">
117 <INPUT TYPE="hidden" NAME="close" VALUE="1">
119 $html .= include('/elements/progress-init.html',
121 [ 'batchnum', 'close' ],
122 $p.'misc/process/bill_batch-print.html',
123 { popup_url => $p."search/bill_batch.cgi?download=$batchnum" },
124 "batch$batchnum" #key
126 $html .= '<A href="#" onclick="startBatch('.$batchnum.');">' .
127 ($batch->status eq 'O' ? '<B>Download and close</B>' : 'Download');
128 $html .= '</A></FORM>';