Optimize "Customer has a referring customer" condition, RT#74452
[freeside.git] / httemplate / view / cust_statement.html
1 <% include("/elements/header.html",'Statement View', menubar(
2   "View this customer (#$display_custnum)" => "${p}view/cust_main.cgi?$custnum",
3 )) %>
4
5 % if ( $FS::CurrentUser::CurrentUser->access_right('Resend invoices') ) {
6
7 %#    <A HREF="<% $p %>misc/send-statement.cgi?method=print;<% $link %>">Re-print this statement</A>
8
9 %   if ( grep { $_ ne 'POST' } $cust_statement->cust_main->invoicing_list ) { 
10 %#        |
11         <A HREF="<% $p %>misc/send-statement.cgi?method=email;<% $link %>">Re-email this statement</A>
12 %   } 
13
14 %   if ( 0 ) {
15 %   #if ( $conf->exists('hylafax') && length($cust_statement->cust_main->fax) ) { 
16         | <A HREF="<% $p %>misc/send-statement.cgi?method=fax;<% $link %>">Re-fax this statement</A>
17 %   } 
18
19     <BR><BR>
20
21 % } 
22
23
24 % #if ( $conf->exists('invoice_latex') ) { 
25 % if ( 0 ) { #broken???
26
27   <A HREF="<% $p %>view/cust_statement-pdf.cgi?<% $link %>">View typeset statement</A>
28   <BR><BR>
29 % } 
30
31 % #if ( $cust_statement->num_cust_event ) {
32 % if ( 0 ) {
33 <A HREF="<%$p%>search/cust_event.html?statementnum=<% $cust_statement->statementnum %>">(&nbsp;View statement events&nbsp;)</A><BR><BR>
34 % } 
35
36 % if ( $conf->exists('invoice_html') ) { 
37
38   <% join('', $cust_statement->print_html('template' => $templatename) ) %>
39 % } else { 
40
41   <PRE><% join('', $cust_statement->print_text('template' => $templatename) ) %></PRE>
42 % } 
43
44 <% include('/elements/footer.html') %>
45 <%init>
46
47 die "access denied"
48   unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
49
50 #untaint statement
51 my($query) = $cgi->keywords;
52 $query =~ /^((.+)-)?(\d+)$/;
53 my $templatename = $2 || 'statement'; #XXX configure... via event??  eh..
54 my $statementnum = $3;
55
56 my $conf = new FS::Conf;
57
58 my $cust_statement = qsearchs({
59   'select'    => 'cust_statement.*',
60   'table'     => 'cust_statement',
61   'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
62   'hashref'   => { 'statementnum' => $statementnum },
63   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
64 });
65 die "Statement #$statementnum not found!" unless $cust_statement;
66
67 my $custnum = $cust_statement->custnum;
68 my $display_custnum = $cust_statement->cust_main->display_custnum;
69
70 my $link = "statementnum=$statementnum";
71 $link .= ';template='. uri_escape($templatename) if $templatename;
72
73 </%init>