summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS/bill_batch.pm6
-rw-r--r--httemplate/elements/progress-popup.html3
-rw-r--r--httemplate/misc/download-bill_batch.html20
-rwxr-xr-xhttemplate/search/bill_batch.cgi58
-rw-r--r--httemplate/view/bill_batch.cgi76
5 files changed, 84 insertions, 79 deletions
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..00d9236f3
--- /dev/null
+++ b/httemplate/misc/download-bill_batch.html
@@ -0,0 +1,20 @@
+<%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;
+</%init>
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');
+<HTML>
+<HEAD><TITLE>Starting download...</TITLE>
+<SCRIPT TYPE="text/javascript">
+function refreshParent() {
+ window.top.setTimeout("window.top.location.href = '<% $cgi->self_url %>'", 2000);
+ window.top.location.replace('<%$p%>misc/download-bill_batch.html?<%$batchnum%>');
+}
+</SCRIPT>
+</HEAD><BODY onload="refreshParent();">
+<& /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!<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',
+ { url => $p."search/bill_batch.cgi?download=$batchnum" },
+ "batch$batchnum" #key
+ );
+ $html .= '<A href="#" onclick="batch'.$batchnum.'process();">' .
+ ($batch->status eq 'O' ? '<B>Download and close</B>' : 'Download');
+ $html .= '</A></FORM>';
+ return $html;
+}
+
</%init>
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"' } &>
-<SCRIPT type="text/javascript">
-function start() {
-window.open('<% $cgi->self_url . ';magic=download' %>');
-parent.nd(1);
-}
-</SCRIPT>
-<TABLE WIDTH="100%"><TR><TD STYLE="text-align:center;vertical-align:middle">
-<FONT SIZE="+1">
-<A HREF="javascript:start()">Download batch #<% $batchnum %></A>
-</FONT>
-</TD></TR></TABLE>
-<& /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!<FORM NAME="OneTrueForm">
- <INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum">!;
- $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 .= '</FORM>
-<A HREF="javascript:process()">Download this batch</A></BR>';
- if ( $batch->status eq 'O' ) {
- $cgi->param('close' => 1);
- $html_init .= '<A HREF="'.$cgi->self_url.'">Close this batch</A><BR>';
- }
- $html_init .= '<BR>';
- if ( $cgi->param('start_download') ) {
- $cgi->delete('start_download');
- $html_foot = '<SCRIPT TYPE="text/javascript">process();</SCRIPT>';
- }
+my $html_init = qq!<FORM NAME="OneTrueForm">
+ <INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum">! .
+ include('/elements/progress-init.html',
+ 'OneTrueForm',
+ [ 'batchnum' ],
+ $p.'misc/process/bill_batch-print.html',
+ { url => $p.'misc/download-bill_batch.html?'.$batchnum }
+ ) .
+ '<A HREF="#" onclick="process();">Download this batch</A></FORM><BR>';
+if ( $batch->status eq 'O' ) {
+ $cgi->param('close' => 1);
+ $html_init .= '<A HREF="'.$cgi->self_url.'">Close this batch</A><BR>';
}
+$html_init .= '<BR>';
my $link = [ "$p/view/cust_bill.cgi?", 'invnum' ];
my $clink = [ "$p/view/cust_main.cgi?", 'custnum' ];