5 unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
9 my( $invnum, $template, $notice_name );
10 my($query) = $cgi->keywords;
11 if ( $query =~ /^((.+)-)?(\d+)(.pdf)?$/ ) { #probably not necessary anymore?
14 $notice_name = 'Invoice';
16 $invnum = $cgi->param('invnum');
17 $invnum =~ s/\.pdf//i; #probably not necessary anymore
18 $template = $cgi->param('template');
19 $notice_name = ( $cgi->param('notice_name') || 'Invoice' );
22 my $conf = new FS::Conf;
25 'unsquelch_cdr' => $conf->exists('voip-cdr_email'),
26 'template' => $template,
27 'notice_name' => $notice_name,
30 my $cust_bill = qsearchs({
31 'select' => 'cust_bill.*',
32 'table' => 'cust_bill',
33 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
34 'hashref' => { 'invnum' => $invnum },
35 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
37 die "Invoice #$invnum not found!" unless $cust_bill;
39 my $method = "print_$type";
41 my $content = $cust_bill->$method(\%opt);
43 my %mime = ( 'pdf' => 'application/pdf',
44 'ps' => 'application/postscript',
47 http_header('Content-Type' => $mime{$type} );
48 http_header('Content-Disposition' => "filename=$invnum.$type" );
49 http_header('Content-Length' => length($content) );
50 http_header('Cache-control' => 'max-age=60' );