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 <& 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'),
73 <SCRIPT type="text/javascript">
75 function checkDownloadStatus(batchnum) {
76 var re = new RegExp('bill_batch_download=' + batchnum);
77 if ( re.test(document.cookie) ) {
78 window.clearInterval(timer);
79 window.location.reload();
82 function startBatch(batchnum) {
83 timer = window.setInterval(function() {
84 checkDownloadStatus(batchnum);
86 eval('batch'+batchnum+'process()');
92 my $curuser = $FS::CurrentUser::CurrentUser;
95 unless $curuser->access_right('Process invoice batches')
96 || $curuser->access_right('Process global invoice batches')
97 || $curuser->access_right('Configuration'); #remove in 2.5
99 my %statusmap = ('O'=>'Open', 'R'=>'Closed');
101 my $count_query = "SELECT COUNT(*) FROM bill_batch WHERE". # $extra_sql AND "
102 $curuser->agentnums_sql(
103 'null_right' => ['Process global invoice batches', 'Configuration' ],
106 #my $extra_sql = ''; # may add something here later
107 my $link = [ "${p}view/bill_batch.cgi?batchnum=", 'batchnum' ];
111 my $batchnum = $batch->batchnum;
112 my $close = ($batch->status eq 'O' ? ';close=1' : '');
113 my $html = qq!<FORM NAME="Download$batchnum" STYLE="display:inline">
114 <INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum">
115 <INPUT TYPE="hidden" NAME="close" VALUE="1">
117 $html .= include('/elements/progress-init.html',
119 [ 'batchnum', 'close' ],
120 $p.'misc/process/bill_batch-print.html',
121 { popup_url => $p."search/bill_batch.cgi?download=$batchnum" },
122 "batch$batchnum" #key
124 $html .= '<A href="#" onclick="startBatch('.$batchnum.');">' .
125 ($batch->status eq 'O' ? '<B>Download and close</B>' : 'Download');
126 $html .= '</A></FORM>';