5 unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
7 my( $invnum, $template, $notice_name );
8 my($query) = $cgi->keywords;
9 if ( $query =~ /^((.+)-)?(\d+)(.pdf)?$/ ) {
12 $notice_name = 'Invoice';
14 $invnum = $cgi->param('invnum');
15 $invnum =~ s/\.pdf//i;
16 $template = $cgi->param('template');
17 $notice_name = ( $cgi->param('notice_name') || 'Invoice' );
21 'template' => $template,
22 'notice_name' => $notice_name,
25 my $cust_bill = qsearchs({
26 'select' => 'cust_bill.*',
27 'table' => 'cust_bill',
28 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
29 'hashref' => { 'invnum' => $invnum },
30 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
32 die "Invoice #$invnum not found!" unless $cust_bill;
34 my $pdf = $cust_bill->print_pdf(\%opt);
36 http_header('Content-Type' => 'application/pdf' );
37 http_header('Content-Length' => length($pdf) );
38 http_header('Cache-control' => 'max-age=60' );