summaryrefslogtreecommitdiff
path: root/httemplate/view/legacy_cust_bill-pdf.cgi
blob: c6ecfb17f403922cd9fb7625280e3ed603dc3e0c (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
27
28
29
30
31
32
33
34
35
<% $content %>\
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('View invoices');

my $legacyinvnum;
my($query) = $cgi->keywords;
if ( $query =~ /^(\d+)(.pdf)?$/ ) { #.pdf probably not necessary anymore?
  $legacyinvnum = $1;
} else {
  $legacyinvnum = $cgi->param('legacyinvnum');
  $legacyinvnum =~ s/\.pdf//i; #probably not necessary anymore
}

my $legacy_cust_bill = qsearchs({
  'select'    => 'legacy_cust_bill.*',
  'table'     => 'legacy_cust_bill',
  'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
  'hashref'   => { 'legacyinvnum' => $legacyinvnum },
  'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
});
die "Legacy invoice #$legacyinvnum not found!" unless $legacy_cust_bill;

my $content = $legacy_cust_bill->content_pdf;

#maybe should name the file after legacyid if present, but have to clean it
#my $filename = $legacy_cust_bill->legacyid

http_header('Content-Type' => 'application/pdf' );
http_header('Content-Disposition' => "filename=$legacyinvnum.pdf" );
http_header('Content-Length' => length($content) );
#http_header('Cache-control' => 'max-age=60' );

</%init>