enable CardFortress in test database, #71513
[freeside.git] / httemplate / view / cust_main_statement-pdf.cgi
1 <% $pdf %>\
2 <%doc>
3 Like view/cust_statement-pdf.cgi, but for viewing/printing the implicit 
4 statement containing all of a customer's invoices.  Slightly redundant.
5 I don't see the need to create an equivalent to view/cust_statement.html 
6 for this case, but one can be added if necessary.
7 </%doc>
8 <%init>
9
10 die "access denied"
11   unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
12
13 my($query) = $cgi->keywords;
14 $query =~ /^(\d+)$/;
15 my $custnum = $1;
16
17 #mostly for the agent-virt, i guess.  could probably bolt it onto the cust_bill
18 # search
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   or die "Customer #$custnum not found!";
26
27 my $cust_bill = qsearchs({
28   'table'    => 'cust_bill',
29   'hashref'  => { 'custnum' => $custnum },
30   'order_by' => 'ORDER BY _date desc LIMIT 1',
31 })
32   or die "Customer #$custnum has no invoices!";
33
34 my $cust_statement = FS::cust_statement->new({
35   'custnum'       => $custnum,
36 #  'statementnum'  => 'ALL', #magic
37   'invnum'        => $cust_bill->invnum,
38   '_date'         => time,
39 });
40
41 my $pdf = $cust_statement->print_pdf({
42   'notice_name' => 'Statement',
43   'no_date'     => 1,
44   'no_number'   => 1,
45 });
46
47 http_header('Content-Type'   => 'application/pdf' );
48 http_header('Content-Length' => length($pdf) );
49 http_header('Cache-control'  => 'max-age=60' );
50
51 </%init>