Will things ever be the same again?
[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 =  grep /\w/, $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 @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
27 <% include("/elements/header.html",'Invoice View', menubar(
28   "Main Menu" => $p,
29   "View this customer (#$custnum)" => "${p}view/cust_main.cgi?$custnum",
30 )) %>
31 % if ( $cust_bill->owed > 0
32 %        && ( $payby{'BILL'} || $payby{'CASH'} || $payby{'WEST'} || $payby{'MCRD'} )
33 %      )
34 %   {
35 %     my $s = 0;
36 %
37
38
39   Post 
40 % if ( $payby{'BILL'} ) { 
41
42   
43     <% $s++ ? ' | ' : '' %>
44     <A HREF="<% $p %>edit/cust_pay.cgi?payby=BILL;invnum=<% $invnum %>">check</A>
45 % } 
46 % if ( $payby{'CASH'} ) { 
47
48   
49     <% $s++ ? ' | ' : '' %>
50     <A HREF="<% $p %>edit/cust_pay.cgi?payby=CASH;invnum=<% $invnum %>">cash</A>
51 % } 
52 % if ( $payby{'WEST'} ) { 
53
54   
55     <% $s++ ? ' | ' : '' %>
56     <A HREF="<% $p %>edit/cust_pay.cgi?payby=WEST;invnum=<% $invnum %>">Western Union</A>
57 % } 
58 % if ( $payby{'MCRD'} ) { 
59
60   
61     <% $s++ ? ' | ' : '' %>
62     <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCRD;invnum=<% $invnum %>">manual credit card</A>
63 % } 
64
65
66   payment against this invoice<BR>
67 % } 
68
69
70 <A HREF="<% $p %>misc/print-invoice.cgi?<% $link %>">Re-print this invoice</A>
71 % if ( grep { $_ ne 'POST' } $cust_bill->cust_main->invoicing_list ) { 
72
73   | <A HREF="<% $p %>misc/email-invoice.cgi?<% $link %>">Re-email
74       this invoice</A>
75 % } 
76 % if ( $conf->exists('hylafax') && length($cust_bill->cust_main->fax) ) { 
77
78   | <A HREF="<% $p %>misc/fax-invoice.cgi?<% $link %>">Re-fax
79       this invoice</A>
80 % } 
81
82
83 <BR><BR>
84 % if ( $conf->exists('invoice_latex') ) { 
85
86   <A HREF="<% $p %>view/cust_bill-pdf.cgi?<% $link %>.pdf">View typeset invoice</A>
87   <BR><BR>
88 % } 
89 % #false laziness with search/cust_bill_event.cgi
90 %   unless ( $templatename ) { 
91
92
93   <% table() %>
94   <TR>
95     <TH>Event</TH>
96     <TH>Date</TH>
97     <TH>Status</TH>
98   </TR>
99 % foreach my $cust_bill_event (
100 %       sort { $a->_date <=> $b->_date } $cust_bill->cust_bill_event
101 %     ) {
102 %
103 %    my $status = $cust_bill_event->status;
104 %    $status .= ': '. encode_entities($cust_bill_event->statustext)
105 %      if $cust_bill_event->statustext;
106 %    my $part_bill_event = $cust_bill_event->part_bill_event;
107 %  
108
109     <TR>
110       <TD><% $part_bill_event->event %>
111 % if ( $part_bill_event->templatename ) {
112 %          my $alt_templatename = $part_bill_event->templatename;
113 %          my $alt_link = "$alt_templatename-$invnum";
114 %        
115
116           ( <A HREF="<% $p %>view/cust_bill.cgi?<% $alt_link %>">view</A>
117           | <A HREF="<% $p %>view/cust_bill-pdf.cgi?<% $alt_link %>.pdf">view
118               typeset</A>
119           | <A HREF="<% $p %>misc/print-invoice.cgi?<% $alt_link %>">re-print</A>
120 % if ( grep { $_ ne 'POST' }
121 %                       $cust_bill->cust_main->invoicing_list ) { 
122
123             | <A HREF="<% $p %>misc/email-invoice.cgi?<% $alt_link %>">re-email</A>
124 % } 
125 % if ( $conf->exists('hylafax')
126 %                  && length($cust_bill->cust_main->fax) ) { 
127
128             | <A HREF="<% $p %>misc/fax-invoice.cgi?<% $alt_link %>">re-fax</A>
129 % } 
130
131
132           )
133 % } 
134
135   
136       </TD>
137       <TD><% time2str("%a %b %e %T %Y", $cust_bill_event->_date) %></TD>
138       <TD><% $status %></TD>
139     </TR>
140 % } 
141
142
143   </TABLE>
144   <BR>
145 % } 
146 % if ( $conf->exists('invoice_html') ) { 
147
148   <% join('', $cust_bill->print_html('', $templatename) ) %>
149 % } else { 
150
151   <PRE><% join('', $cust_bill->print_text('', $templatename) ) %></PRE>
152 % } 
153
154
155 </BODY></HTML>