-<% include( 'elements/search.html',
+% my $batchnum = $cgi->param('download');
+% if ( $batchnum =~ /^\d+$/ ) {
+% my $download = $p."misc/download-bill_batch.html?$batchnum";
+<HTML>
+<HEAD><TITLE>Starting download...</TITLE>
+<SCRIPT TYPE="text/javascript">
+function start() {
+ window.location.replace('<% $download %>');
+}
+</SCRIPT>
+<!--[if lte IE 7]>
+<SCRIPT TYPE="text/javascript">function start() {}</SCRIPT>
+<![endif]-->
+</HEAD>
+<BODY onload="start()" STYLE="background-color:#ccccff">
+<TABLE STYLE="height:125px; width:100%; text-align:center"><TR><TD STYLE="vertical-align:middle;text-align:center">
+<A HREF="<% $download %>">Click here if your download does not start</A>
+</TD></TR></TABLE>
+<& /elements/footer.html &>
+% }
+% else {
+%# delete existing download cookie
+% my $cookie = CGI::Cookie->new(
+% -name => 'bill_batch_download',
+% -value => 0,
+% -expires => '-1d',
+% );
+% $r->headers_out->add( 'Set-Cookie' => $cookie->as_string );
+<& elements/search.html,
'title' => 'Invoice Batches',
'name_singular' => 'batch',
'query' => { 'table' => 'bill_batch',
sub {
$statusmap{shift->status};
},
- sub { shift->status eq 'O' ?
- 'Download and close' : 'Download'
- },
+ \&download_link,
],
'links' => [
$link,
$link,
$link,
- $dlink,
- ],
- 'style' => [
- '',
- '',
'',
- sub { shift->status eq 'O' ? "b" : '' },
- ],
+ ],
'really_disable_download' => 1,
'agent_virt' => 1,
'agent_null_right' => [ 'Process global invoice batches', 'Configuration' ],
'agent_pos' => 1,
+ 'html_foot' => include('.foot'),
- )
-
-%>
+&>
+%}
+<%def .foot>
+<SCRIPT type="text/javascript">
+var timer;
+function checkDownloadStatus(batchnum) {
+ var re = new RegExp('bill_batch_download=' + batchnum);
+ if ( re.test(document.cookie) ) {
+ window.clearInterval(timer);
+ window.location.reload();
+ }
+}
+function startBatch(batchnum) {
+ timer = window.setInterval(function() {
+ checkDownloadStatus(batchnum);
+ }, 2000);
+ eval('batch'+batchnum+'process()');
+}
+</SCRIPT>
+</%def>
<%init>
my $curuser = $FS::CurrentUser::CurrentUser;
#my $extra_sql = ''; # may add something here later
my $link = [ "${p}view/bill_batch.cgi?batchnum=", 'batchnum' ];
-my $dlink = sub {
- [ "${p}view/bill_batch.cgi?start_download=1;".
- (shift->status eq 'O' ? 'close=1;' : '').
- 'batchnum=',
- 'batchnum']
-};
+
+sub download_link {
+ my $batch = shift;
+ my $batchnum = $batch->batchnum;
+ my $close = ($batch->status eq 'O' ? ';close=1' : '');
+ my $html = qq!<FORM NAME="Download$batchnum" STYLE="display:inline">
+ <INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum">
+ <INPUT TYPE="hidden" NAME="close" VALUE="1">
+ !;
+ $html .= include('/elements/progress-init.html',
+ "Download$batchnum",
+ [ 'batchnum', 'close' ],
+ $p.'misc/process/bill_batch-print.html',
+ { popup_url => $p."search/bill_batch.cgi?download=$batchnum" },
+ "batch$batchnum" #key
+ );
+ $html .= '<A href="#" onclick="startBatch('.$batchnum.');">' .
+ ($batch->status eq 'O' ? '<B>Download and close</B>' : 'Download');
+ $html .= '</A></FORM>';
+ return $html;
+}
+
</%init>