Option to ignore old CDRs, RT#81480
[freeside.git] / httemplate / view / cust_bill-tex.cgi
1 <% $tex %>
2 <%init>
3
4 use File::Slurp 'slurp';
5
6 die "access denied"
7   unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
8
9 my( $invnum, $mode, $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   $mode = $cgi->param('mode');
21 }
22
23 my $conf = new FS::Conf;
24
25 my %opt = (
26   'unsquelch_cdr' => $conf->exists('voip-cdr_email'),
27   'template'      => $template,
28   'notice_name'   => $notice_name,
29   'no_coupon'     => ($cgi->param('no_coupon') || 0)
30 );
31
32 my $cust_bill = qsearchs({
33   'select'    => 'cust_bill.*',
34   'table'     => 'cust_bill',
35   'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
36   'hashref'   => { 'invnum' => $invnum },
37   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
38 });
39 die "Invoice #$invnum not found!" unless $cust_bill;
40
41 $cust_bill->set(mode => $mode);
42
43 my ($file) = $cust_bill->print_latex(\%opt);
44 my $tex = slurp("$file.tex");
45
46 http_header('Content-Type' => 'text/plain' );
47 http_header('Content-Disposition' => "filename=$invnum.tex" );
48 http_header('Content-Length' => length($tex) );
49 http_header('Cache-control' => 'max-age=60' );
50
51 </%init>