re-email/fax/print links should respect template, also add direct re-send links like...
[freeside.git] / httemplate / view / cust_bill.cgi
1 <%
2
3 #untaint invnum
4 my($query) = $cgi->keywords;
5 $query =~ /^((.+)-)?(\d+)$/;
6 my $templatename = $2;
7 my $invnum = $3;
8
9 my $conf = new FS::Conf;
10
11 my $cust_bill = qsearchs('cust_bill',{'invnum'=>$invnum});
12 die "Invoice #$invnum not found!" unless $cust_bill;
13 my $custnum = $cust_bill->getfield('custnum');
14
15 #my $printed = $cust_bill->printed;
16
17 my $link = $templatename ? "$templatename-$invnum" : $invnum;
18
19 %>
20 <%= header('Invoice View', menubar(
21   "Main Menu" => $p,
22   "View this customer (#$custnum)" => "${p}view/cust_main.cgi?$custnum",
23 )) %>
24
25 <% if ( $cust_bill->owed > 0 ) { %>
26   <A HREF="<%= $p %>edit/cust_pay.cgi?<%= $invnum %>">Enter payments (check/cash) against this invoice</A> |
27 <% } %>
28
29 <A HREF="<%= $p %>misc/print-invoice.cgi?<%= $link %>">Reprint this invoice</A>
30
31 <% if ( grep { $_ ne 'POST' } $cust_bill->cust_main->invoicing_list ) { %>
32   | <A HREF="<%= $p %>misc/email-invoice.cgi?<%= $link %>">Re-email
33       this invoice</A>
34 <% } %>
35
36 <% if ( $conf->exists('hylafax') && length($cust_bill->cust_main->fax) ) { %>
37   | <A HREF="<%= $p %>misc/fax-invoice.cgi?<%= $link %>">Re-fax
38       this invoice</A>
39 <% } %>
40
41 <BR><BR>
42
43 <% if ( $conf->exists('invoice_latex') ) { %>
44   <A HREF="<%= $p %>view/cust_bill-pdf.cgi?$link.pdf">View typeset invoice</A>
45   <BR><BR>
46 <% } %>
47
48 <% #false laziness with search/cust_bill_event.cgi
49    unless ( $templatename ) { %>
50
51   <%= table() %>
52   <TR>
53     <TH>Event</TH>
54     <TH>Date</TH>
55     <TH>Status</TH>
56   </TR>
57
58   <% foreach my $cust_bill_event (
59        sort { $a->_date <=> $b->_date } $cust_bill->cust_bill_event
60      ) {
61
62     my $status = $cust_bill_event->status;
63     $status .= ': '. encode_entities($cust_bill_event->statustext)
64       if $cust_bill_event->statustext;
65     my $part_bill_event = $cust_bill_event->part_bill_event;
66   %>
67     <TR>
68       <TD><%= $part_bill_event->event %>
69   
70         <% if (
71           $part_bill_event->plan eq 'send_alternate'
72           && $part_bill_event->plandata =~ /^(agent_)?templatename (.*)$/m
73         ) {
74           my $alt_templatename = $2;
75           my $alt_link = "$templatename-$invnum";
76         %>
77           ( <A HREF="<%= $p %>view/cust_bill.cgi?<%= $alt_link %>">view</A>
78           | <A HREF="<%= $p %>view/cust_bill-pdf.cgi?<%= $alt_link %>.pdf">view
79               typeset</A>
80           | <A HREF="<%= $p %>misc/print-invoice.cgi?<%= $alt_link %>">re-print</A>
81           <% if ( grep { $_ ne 'POST' }
82                        $cust_bill->cust_main->invoicing_list ) { %>
83             | <A HREF="<%= $p %>misc/email-invoice.cgi?<%= $alt_link %>">re-email</A>
84           <% } %>
85                        
86           <% if ( $conf->exists('hylafax')
87                   && length($cust_bill->cust_main->fax) ) { %>
88             | <A HREF="<%= $p %>misc/fax-invoice.cgi?<%= $alt_link %>">re-fax</A>
89           <% } %>
90
91           )
92         <% } %>
93   
94       </TD>
95       <TD><%= time2str("%a %b %e %T %Y", $cust_bill_event->_date) %></TD>
96       <TD><%= $status %></TD>
97     </TR>
98   <% } %>
99
100   </TABLE>
101   <BR>
102
103 <% } %>
104
105 <% if ( $conf->exists('invoice_html') ) { %>
106   <%= $cust_bill->print_html('', $templatename) %>
107 <% } else { %>
108   <PRE><%= $cust_bill->print_text('', $templatename) %></PRE>
109 <% } %>
110
111 </BODY></HTML>