add svc_elec_features merged from reference code RT#7643
[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)?$/ ) {
10   $template = $2;
11   $invnum = $3;
12   $notice_name = 'Invoice';
13 } else {
14   $invnum = $cgi->param('invnum');
15   $invnum =~ s/\.pdf//i;
16   $template = $cgi->param('template');
17   $notice_name = ( $cgi->param('notice_name') || 'Invoice' );
18 }
19
20 my %opt = (
21   'template'    => $template,
22   'notice_name' => $notice_name,
23 );
24
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,
31 });
32 die "Invoice #$invnum not found!" unless $cust_bill;
33
34 if ( $notice_name eq 'Record' ) {
35   $opt{base}='rec';
36 } elsif ( $notice_name eq 'Record Ignoring DUE DATE' ) {
37   $opt{base}='rec';
38   $opt{ignore_due_date}=1;
39 }
40 my $pdf = $cust_bill->print_pdf(\%opt);
41
42 http_header('Content-Type' => 'application/pdf' );
43 http_header('Content-Length' => length($pdf) );
44 http_header('Cache-control' => 'max-age=60' );
45
46 </%init>