summaryrefslogtreecommitdiff
path: root/httemplate/misc/download-bill_batch.html
blob: 9b5f1efa8bf3ce557cee366ef7b797efa761f32d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<%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"');
my $cookie = CGI::Cookie->new(
  -name => "bill_batch_download",
  -value => $batchnum,
  -expires => '+1d',
);
$r->headers_out->add( 'Set-Cookie' => $cookie->as_string );
$m->print($content);

$batch->pdf('');
my $error = $batch->replace;
warn "error deleting cached PDF: '$error'\n" if $error;
</%init>