7c2c20799feb4943d36ea543bad1935286deb57c
[freeside.git] / httemplate / view / cust_main_statement-pdf.cgi
1 <%doc>
2 Like view/cust_statement-pdf.cgi, but for viewing/printing the implicit 
3 statement containing all of a customer's invoices.  Slightly redundant.
4 I don't see the need to create an equivalent to view/cust_statement.html 
5 for this case, but one can be added if necessary.
6 </%doc>
7 <% $pdf %>
8 <%init>
9
10 die "access denied"
11   unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
12
13 #untaint statement
14 my($query) = $cgi->keywords;
15 $query =~ /^((.+)-)?(\d+)$/;
16 my $templatename = $2 || 'statement'; #XXX configure... via event??  eh..
17 my $custnum = $3;
18
19 my $cust_main = qsearchs({
20   'select'    => 'cust_main.*',
21   'table'     => 'cust_main',
22   'hashref'   => { 'custnum' => $custnum },
23   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
24 });
25 die "Customer #$custnum not found!" unless $cust_main;
26 my $cust_bill = ($cust_main->cust_bill)[-1]
27   or die "Customer #$custnum has no invoices!";
28
29 my $cust_statement = FS::cust_statement->new({
30   'custnum'       => $custnum,
31 #  'statementnum'  => 'ALL', #magic
32   'invnum'        => $cust_bill->invnum,
33   '_date'         => time,
34 });
35
36
37 my $pdf = $cust_statement->print_pdf( '', $templatename );
38
39 http_header('Content-Type' => 'application/pdf' );
40 http_header('Content-Length' => length($pdf) );
41 http_header('Cache-control' => 'max-age=60' );
42
43 </%init>