Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / view / elements / cust_bill-typeset
1 <% $content %>\
2 <%init>
3
4 die "access denied"
5   unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
6
7 my $type = shift;
8
9 my( $invnum, $template, $notice_name );
10 my($query) = $cgi->keywords;
11 if ( $query =~ /^((.+)-)?(\d+)(.pdf)?$/ ) { #probably not necessary anymore?
12   $template = $2;
13   $invnum = $3;
14   $notice_name = 'Invoice';
15 } else {
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' );
20 }
21
22 my $conf = new FS::Conf;
23
24 my %opt = (
25   'unsquelch_cdr' => $conf->exists('voip-cdr_email'),
26   'template'      => $template,
27   'notice_name'   => $notice_name,
28 );
29
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,
36 });
37 die "Invoice #$invnum not found!" unless $cust_bill;
38
39 my $method = "print_$type";
40
41 my $content = $cust_bill->$method(\%opt);
42
43 my %mime = ( 'pdf' => 'application/pdf',
44              'ps'  => 'application/postscript',
45            );
46
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' );
51
52 </%init>