combine ticket notification scrips, #15353
[freeside.git] / httemplate / view / cust_bill-ps.cgi
1 <% $ps %>
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   $template = $cgi->param('template');
16   $notice_name = ( $cgi->param('notice_name') || 'Invoice' );
17 }
18
19 my $conf = new FS::Conf;
20
21 my %opt = (
22   'unsquelch_cdr' => $conf->exists('voip-cdr_email'),
23   'template'      => $template,
24   'notice_name'   => $notice_name,
25 );
26
27 my $cust_bill = qsearchs({
28   'select'    => 'cust_bill.*',
29   'table'     => 'cust_bill',
30   'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
31   'hashref'   => { 'invnum' => $invnum },
32   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
33 });
34 die "Invoice #$invnum not found!" unless $cust_bill;
35
36 my $ps = $cust_bill->print_ps(\%opt);
37
38 http_header('Content-Type' => 'application/postscript' );
39 http_header('Content-Disposition' => "filename=$invnum.ps" );
40 http_header('Content-Length' => length($ps) );
41 http_header('Cache-control' => 'max-age=60' );
42
43 </%init>