stray closing /TABLE in the no-ticket case
[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, $mode, $template, $notice_name, $no_coupon );
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');
20   $mode = $cgi->param('mode');
21   $no_coupon = $cgi->param('no_coupon');
22 }
23
24 my $conf = new FS::Conf;
25
26 my %opt = (
27   'unsquelch_cdr' => $conf->exists('voip-cdr_email'),
28   'template'      => $template,
29   'notice_name'   => $notice_name,
30   'no_coupon'     => $no_coupon,
31 );
32
33 my $cust_bill = qsearchs({
34   'select'    => 'cust_bill.*',
35   'table'     => 'cust_bill',
36   'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
37   'hashref'   => { 'invnum' => $invnum },
38   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
39 });
40 die "Invoice #$invnum not found!" unless $cust_bill;
41
42 $cust_bill->set(mode => $mode);
43
44 my $method = "print_$type";
45
46 my $content = $cust_bill->$method(\%opt);
47
48 my %mime = ( 'pdf' => 'application/pdf',
49              'ps'  => 'application/postscript',
50            );
51
52 http_header('Content-Type' => $mime{$type} );
53 http_header('Content-Disposition' => "filename=$invnum.$type" );
54 http_header('Content-Length' => length($content) );
55 http_header('Cache-control' => 'max-age=60' );
56
57 </%init>