add CASH and WEST payment types (payments only, not cust_main.payby)
[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 @payby = $conf->config('payby');
12 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
13 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
14   unless grep /\w/, @payby;
15 my %payby = map { $_=>1 } @payby;
16
17 my $cust_bill = qsearchs('cust_bill',{'invnum'=>$invnum});
18 die "Invoice #$invnum not found!" unless $cust_bill;
19 my $custnum = $cust_bill->getfield('custnum');
20
21 #my $printed = $cust_bill->printed;
22
23 my $link = $templatename ? "$templatename-$invnum" : $invnum;
24
25 %>
26 <%= header('Invoice View', menubar(
27   "Main Menu" => $p,
28   "View this customer (#$custnum)" => "${p}view/cust_main.cgi?$custnum",
29 )) %>
30
31 <% if ( $cust_bill->owed > 0
32         && ( $payby{'BILL'} || $payby{'CASH'} || $payby{'WEST'} )
33       )
34    {
35      my $s = 0;
36 %>
37
38   Post 
39
40   <% if ( $payby{'BILL'} ) { %>
41   
42     <%= $s++ ? ' | ' : '' %>
43     <A HREF="<%= $p %>edit/cust_pay.cgi?payby=BILL;invnum=<%= $invnum %>">check</A>
44   
45   <% } %>
46   
47   <% if ( $payby{'CASH'} ) { %>
48   
49     <%= $s++ ? ' | ' : '' %>
50     <A HREF="<%= $p %>edit/cust_pay.cgi?payby=CASH;invnum=<%= $invnum %>">cash</A>
51   
52   <% } %>
53   
54   <% if ( $payby{'WEST'} ) { %>
55   
56     <%= $s++ ? ' | ' : '' %>
57     <A HREF="<%= $p %>edit/cust_pay.cgi?payby=WEST;invnum=<%= $invnum %>">Western Union</A>
58   
59   <% } %>
60
61   payment against this invoice<BR>
62
63 <% } %>
64
65 <A HREF="<%= $p %>misc/print-invoice.cgi?<%= $link %>">Re-print this invoice</A>
66
67 <% if ( grep { $_ ne 'POST' } $cust_bill->cust_main->invoicing_list ) { %>
68   | <A HREF="<%= $p %>misc/email-invoice.cgi?<%= $link %>">Re-email
69       this invoice</A>
70 <% } %>
71
72 <% if ( $conf->exists('hylafax') && length($cust_bill->cust_main->fax) ) { %>
73   | <A HREF="<%= $p %>misc/fax-invoice.cgi?<%= $link %>">Re-fax
74       this invoice</A>
75 <% } %>
76
77 <BR><BR>
78
79 <% if ( $conf->exists('invoice_latex') ) { %>
80   <A HREF="<%= $p %>view/cust_bill-pdf.cgi?<%= $link %>.pdf">View typeset invoice</A>
81   <BR><BR>
82 <% } %>
83
84 <% #false laziness with search/cust_bill_event.cgi
85    unless ( $templatename ) { %>
86
87   <%= table() %>
88   <TR>
89     <TH>Event</TH>
90     <TH>Date</TH>
91     <TH>Status</TH>
92   </TR>
93
94   <% foreach my $cust_bill_event (
95        sort { $a->_date <=> $b->_date } $cust_bill->cust_bill_event
96      ) {
97
98     my $status = $cust_bill_event->status;
99     $status .= ': '. encode_entities($cust_bill_event->statustext)
100       if $cust_bill_event->statustext;
101     my $part_bill_event = $cust_bill_event->part_bill_event;
102   %>
103     <TR>
104       <TD><%= $part_bill_event->event %>
105   
106         <% if ( $part_bill_event->templatename ) {
107           my $alt_templatename = $part_bill_event->templatename;
108           my $alt_link = "$alt_templatename-$invnum";
109         %>
110           ( <A HREF="<%= $p %>view/cust_bill.cgi?<%= $alt_link %>">view</A>
111           | <A HREF="<%= $p %>view/cust_bill-pdf.cgi?<%= $alt_link %>.pdf">view
112               typeset</A>
113           | <A HREF="<%= $p %>misc/print-invoice.cgi?<%= $alt_link %>">re-print</A>
114           <% if ( grep { $_ ne 'POST' }
115                        $cust_bill->cust_main->invoicing_list ) { %>
116             | <A HREF="<%= $p %>misc/email-invoice.cgi?<%= $alt_link %>">re-email</A>
117           <% } %>
118                        
119           <% if ( $conf->exists('hylafax')
120                   && length($cust_bill->cust_main->fax) ) { %>
121             | <A HREF="<%= $p %>misc/fax-invoice.cgi?<%= $alt_link %>">re-fax</A>
122           <% } %>
123
124           )
125         <% } %>
126   
127       </TD>
128       <TD><%= time2str("%a %b %e %T %Y", $cust_bill_event->_date) %></TD>
129       <TD><%= $status %></TD>
130     </TR>
131   <% } %>
132
133   </TABLE>
134   <BR>
135
136 <% } %>
137
138 <% if ( $conf->exists('invoice_html') ) { %>
139   <%= join('', $cust_bill->print_html('', $templatename) ) %>
140 <% } else { %>
141   <PRE><%= join('', $cust_bill->print_text('', $templatename) ) %></PRE>
142 <% } %>
143
144 </BODY></HTML>