optimize CDR rating after timed rate perf regression, RT#15739
[freeside.git] / httemplate / view / cust_bill-pdf.cgi
1 <% $pdf %>
2 <%init>
3
4 die "access denied"
5   unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
6
7 my( $invnum, $template, $notice_name );
8 my($query) = $cgi->keywords;
9 if ( $query =~ /^((.+)-)?(\d+)(.pdf)?$/ ) { #probably not necessary anymore?
10   $template = $2;
11   $invnum = $3;
12   $notice_name = 'Invoice';
13 } else {
14   $invnum = $cgi->param('invnum');
15   $invnum =~ s/\.pdf//i; #probably not necessary anymore
16   $template = $cgi->param('template');
17   $notice_name = ( $cgi->param('notice_name') || 'Invoice' );
18 }
19
20 my $conf = new FS::Conf;
21
22 my %opt = (
23   'unsquelch_cdr' => $conf->exists('voip-cdr_email'),
24   'template'      => $template,
25   'notice_name'   => $notice_name,
26 );
27
28 my $cust_bill = qsearchs({
29   'select'    => 'cust_bill.*',
30   'table'     => 'cust_bill',
31   'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
32   'hashref'   => { 'invnum' => $invnum },
33   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
34 });
35 die "Invoice #$invnum not found!" unless $cust_bill;
36
37 my $pdf = $cust_bill->print_pdf(\%opt);
38
39 http_header('Content-Type' => 'application/pdf' );
40 http_header('Content-Disposition' => "filename=$invnum.pdf" );
41 http_header('Content-Length' => length($pdf) );
42 http_header('Cache-control' => 'max-age=60' );
43
44 </%init>