From 197e19d52c02f541850ca06f2628d86c2c3b9464 Mon Sep 17 00:00:00 2001 From: mark Date: Sat, 30 Jul 2011 23:14:23 +0000 Subject: [PATCH] rearrange flow of batch download, #947 --- FS/FS/bill_batch.pm | 6 +++ httemplate/elements/progress-popup.html | 3 +- httemplate/misc/download-bill_batch.html | 21 +++++++++ httemplate/search/bill_batch.cgi | 58 +++++++++++++++++------- httemplate/view/bill_batch.cgi | 76 ++++++-------------------------- 5 files changed, 85 insertions(+), 79 deletions(-) create mode 100644 httemplate/misc/download-bill_batch.html diff --git a/FS/FS/bill_batch.pm b/FS/FS/bill_batch.pm index ec5c19456..1a46db0b2 100644 --- a/FS/FS/bill_batch.pm +++ b/FS/FS/bill_batch.pm @@ -84,6 +84,7 @@ sub print_pdf { die $error if $error; } } + $job->update_statustext(100, 'Combining invoices') if $job; return $pdf_out->toPDF; } @@ -144,6 +145,11 @@ sub process_print_pdf { my $batch = FS::bill_batch->by_key($param->{batchnum}); die "batch '$param->{batchnum}' not found!\n" if !$batch; + if ( $param->{'close'} ) { + my $error = $batch->close; + die $error if $error; + } + my $pdf = $batch->print_pdf($job); $batch->pdf($pdf); my $error = $batch->replace; diff --git a/httemplate/elements/progress-popup.html b/httemplate/elements/progress-popup.html index 73440bbc3..2d273880c 100644 --- a/httemplate/elements/progress-popup.html +++ b/httemplate/elements/progress-popup.html @@ -63,12 +63,13 @@ function updateStatus( status_statustext ) { % } % } elsif ( $url ) { - + parent.nd(1); window.top.location.href = '<% $url %>'; % } elsif ( $popup_url ) { document.location.replace('<% $popup_url %>'); % } else { + alert('job done but no url or message specified'); % } } else if ( status.indexOf('done') > -1 ) { diff --git a/httemplate/misc/download-bill_batch.html b/httemplate/misc/download-bill_batch.html new file mode 100644 index 000000000..70e3003ce --- /dev/null +++ b/httemplate/misc/download-bill_batch.html @@ -0,0 +1,21 @@ +<%init> +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('View invoices'); +my ($batchnum) = $cgi->keywords; +$batchnum =~ /^\d+$/ or die "invalid batchnum '$batchnum'"; +my $batch = FS::bill_batch->by_key($batchnum) + or die "Batch $batchnum not found"; + +# send the batch +my $content = $batch->pdf; +$m->clear_buffer; +$r->content_type('application/pdf'); +$r->headers_out->add( 'Content-Disposition' => + 'attachment;filename="invoice_batch_'.$batchnum.'.pdf"'); +$m->print($content); + +#$batch->pdf(''); +#my $error = $batch->replace; +# warn "error deleting cached PDF: '$error'\n" if $error; +#} + diff --git a/httemplate/search/bill_batch.cgi b/httemplate/search/bill_batch.cgi index 6d7e18fee..cbd7f270a 100755 --- a/httemplate/search/bill_batch.cgi +++ b/httemplate/search/bill_batch.cgi @@ -1,3 +1,18 @@ +% my $batchnum = $cgi->param('download'); +% if ( $batchnum =~ /^\d+$/ ) { +% $cgi->delete('download'); + +Starting download... + + +<& /elements/footer.html &> +% } +% else { <% include( 'elements/search.html', 'title' => 'Invoice Batches', 'name_singular' => 'batch', @@ -25,22 +40,14 @@ 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' ], @@ -49,6 +56,7 @@ ) %> +%} <%init> my $curuser = $FS::CurrentUser::CurrentUser; @@ -67,10 +75,28 @@ my $count_query = "SELECT COUNT(*) FROM bill_batch WHERE". # $extra_sql AND " #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'] -}; + +my $download_id = int(rand(1000000)); + +sub download_link { + my $batch = shift; + my $batchnum = $batch->batchnum; + my $close = ($batch->status eq 'O' ? ';close=1' : ''); + my $html = qq!
+ + + !; + $html .= include('/elements/progress-init.html', + "Download$batchnum", + [ 'batchnum', 'close' ], + $p.'misc/process/bill_batch-print.html', + { url => $p."search/bill_batch.cgi?download=$batchnum" }, + "batch$batchnum" #key + ); + $html .= '' . + ($batch->status eq 'O' ? 'Download and close' : 'Download'); + $html .= '
'; + return $html; +} + diff --git a/httemplate/view/bill_batch.cgi b/httemplate/view/bill_batch.cgi index c848664ac..7d640395e 100644 --- a/httemplate/view/bill_batch.cgi +++ b/httemplate/view/bill_batch.cgi @@ -1,39 +1,8 @@ -% if($magic eq 'download') { -% my $content = $batch->pdf; -% $batch->pdf(''); -% my $error = $batch->replace; -% warn "error deleting cached PDF: '$error'\n" if $error; -% -% $m->clear_buffer; -% $r->content_type('application/pdf'); -% $r->headers_out->add('Content-Disposition' => 'attachment;filename="invoice_batch_'.$batchnum.'.pdf"'); -<% $content %> -% } -% -% elsif ($magic eq 'download_popup') { -% -<& /elements/header-popup.html, - { 'etc' => 'BGCOLOR="#ccccff"' } &> - -
- -Download batch #<% $batchnum %> - -
-<& /elements/footer.html &> -% -% } -% -% else { <% include('/search/elements/search.html', 'title' => $close ? "Batch $batchnum closed." : "Invoice Batch $batchnum", + 'menubar' => ['All batches' => $p.'search/bill_batch.cgi'], 'name' => 'invoices', 'query' => { 'table' => 'cust_bill_batch', 'select' => join(', ', @@ -49,7 +18,6 @@ parent.nd(1); }, 'count_query' => "SELECT COUNT(*) FROM cust_bill_batch WHERE batchnum = $batchnum", 'html_init' => $html_init, - 'html_foot' => $html_foot, 'header' => [ 'Invoice #', 'Amount', 'Date', @@ -67,7 +35,6 @@ parent.nd(1); ], 'really_disable_download' => 1, ) %> -% } <%init> die "access denied" @@ -80,38 +47,23 @@ my $batchnum = $cgi->param('batchnum'); $batch = FS::bill_batch->by_key($batchnum); die "Batch '$batchnum' not found!\n" if !$batch; -my $magic = $cgi->param('magic'); -$cgi->delete('magic'); - my $close = $cgi->param('close'); $batch->close if $close; -my $html_init = ''; -my $html_foot = ''; -if ( !$magic ) { - $html_init .= qq!
- !; - $html_init .= include('/elements/progress-init.html', - 'OneTrueForm', - [ 'batchnum' ], - $p.'misc/process/bill_batch-print.html', - { - 'popup_url' => $cgi->self_url . ';magic=download_popup', - }, - '', - ); - $html_init .= '
-Download this batch
'; - if ( $batch->status eq 'O' ) { - $cgi->param('close' => 1); - $html_init .= 'Close this batch
'; - } - $html_init .= '
'; - if ( $cgi->param('start_download') ) { - $cgi->delete('start_download'); - $html_foot = ''; - } +my $html_init = qq!
+ ! . + include('/elements/progress-init.html', + 'OneTrueForm', + [ 'batchnum' ], + $p.'misc/process/bill_batch-print.html', + { url => $p.'misc/download-bill_batch.html?'.$batchnum } + ) . + 'Download this batch

'; +if ( $batch->status eq 'O' ) { + $cgi->param('close' => 1); + $html_init .= 'Close this batch
'; } +$html_init .= '
'; my $link = [ "$p/view/cust_bill.cgi?", 'invnum' ]; my $clink = [ "$p/view/cust_main.cgi?", 'custnum' ]; -- 2.11.0