5 unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
9 my( $invnum, $mode, $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');
20 $mode = $cgi->param('mode');
23 my $conf = new FS::Conf;
26 'unsquelch_cdr' => $conf->exists('voip-cdr_email'),
27 'template' => $template,
28 'notice_name' => $notice_name,
31 my $cust_bill = qsearchs({
32 'select' => 'cust_bill.*',
33 'table' => 'cust_bill',
34 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
35 'hashref' => { 'invnum' => $invnum },
36 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
38 die "Invoice #$invnum not found!" unless $cust_bill;
40 $cust_bill->set(mode => $mode);
42 my $method = "print_$type";
44 my $content = $cust_bill->$method(\%opt);
46 my %mime = ( 'pdf' => 'application/pdf',
47 'ps' => 'application/postscript',
50 http_header('Content-Type' => $mime{$type} );
51 http_header('Content-Disposition' => "filename=$invnum.$type" );
52 http_header('Content-Length' => length($content) );
53 http_header('Cache-control' => 'max-age=60' );