1 <BR><BR><A NAME="history"><FONT SIZE="+2">Payment History</FONT></A><BR>
4 % if ( $payby{'BILL'} && $curuser->access_right('Post payment') ) {
5 <% $s++ ? ' | ' : '' %>
6 <% include('/elements/popup_link-cust_main.html',
7 'label' => 'Enter check payment',
8 'action' => "${p}edit/cust_pay.cgi?popup=1;payby=BILL",
9 'cust_main' => $cust_main,
10 'actionlabel' => 'Enter check payment',
12 #default# 'height' => 336,
17 % if ( $payby{'CASH'} && $curuser->access_right('Post payment') ) {
18 <% $s++ ? ' | ' : '' %>
19 <% include('/elements/popup_link-cust_main.html',
20 'label' => 'Enter cash payment',
21 'action' => "${p}edit/cust_pay.cgi?popup=1;payby=CASH",
22 'cust_main' => $cust_main,
23 'actionlabel' => 'Enter cash payment',
25 #default# 'height' => 336,
30 % if ( $payby{'WEST'} && $curuser->access_right('Post payment') ) {
31 <% $s++ ? ' | ' : '' %>
32 <A HREF="<% $p %>edit/cust_pay.cgi?payby=WEST;custnum=<% $custnum %>">Enter Western Union payment</A>
35 % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
36 % && $curuser->access_right('Process payment')
37 % && ! $cust_main->is_encrypted($cust_main->payinfo)
39 <% $s++ ? ' | ' : '' %>
40 <A HREF="<% $p %>misc/payment.cgi?payby=CARD;custnum=<% $custnum %>">Process credit card payment</A>
43 % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
44 % && $curuser->access_right('Process payment')
45 % && ! $cust_main->is_encrypted($cust_main->payinfo)
47 <% $s++ ? ' | ' : '' %>
48 <A HREF="<% $p %>misc/payment.cgi?payby=CHEK;custnum=<% $custnum %>">Process electronic check (ACH) payment</A>
51 % if ( $payby{'MCRD'} && $curuser->access_right('Post payment') ) {
52 <% $s++ ? ' | ' : '' %>
53 <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCRD;custnum=<% $custnum %>">Post manual (offline) credit card payment</A>
58 % if ( $curuser->access_right('Post credit') ) {
59 <% include('/elements/popup_link-cust_main.html',
60 'label' => 'Enter credit',
61 'action' => "${p}edit/cust_credit.cgi",
62 'cust_main' => $cust_main,
63 'actionlabel' => 'Enter credit',
65 #default# 'height' => 336,
71 % if ( $curuser->access_right('View customer tax exemptions') ) {
72 <A HREF="<% $p %>search/cust_tax_exempt_pkg.cgi?custnum=<% $custnum %>">View tax exemptions</A>
76 % if ( $conf->exists('batch-enable')
77 % && $curuser->access_right('View customer batched payments')
79 View batched payments:
80 % foreach my $status (qw( Queued In-transit Complete All )) {
81 <A HREF="<% $p %>search/cust_pay_batch.cgi?status=<% $status{$status} %>;custnum=<% $custnum %>"><% $status %></A>
82 <% $status ne 'All' ? '|' : '' %>
88 <% include("/elements/table-grid.html") %>
89 % my $bgcolor1 = '#eeeeee';
90 % my $bgcolor2 = '#ffffff';
96 <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
97 <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
98 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Charge</FONT></TH>
99 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Payment</FONT></TH>
100 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
101 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Refund</FONT></TH>
102 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Balance</FONT></TH>
105 %#display payment history
107 %sub balance_forward_row {
108 % my( $b, $date ) = @_;
109 % my $conf = new FS::Conf;
110 % my $money_char = $conf->config('money_char') || '$';
111 % ( my $balance_forward = $money_char. $b ) =~ s/^\$\-/- \$/;
113 <TR ID="balance_forward_row">
114 <TD CLASS="grid" BGCOLOR="#dddddd">
115 <% time2str("%D",$date) %>
118 <TD CLASS="grid" BGCOLOR="#dddddd">
119 <I>Starting balance on <% time2str("%D",$date) %></I>
120 (<A HREF="javascript:void(0);" onClick="show_history();">show prior history</A>)
123 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
124 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
125 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
126 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
127 <TD CLASS="grid" BGCOLOR="#dddddd"><I><% $balance_forward %></I></TD>
134 %my $money_char = $conf->config('money_char') || '$';
136 %my $years = $conf->config('payment_history-years') || 2;
137 %my $older_than = time - $years * 31556736; #60*60*24*365.24
140 %my $old_history = 0;
143 %foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
145 % $lastdate = $item->{'date'};
148 % if ( $item->{'date'} < $older_than ) {
149 % $display = ' STYLE="display:none" ';
155 % if ( $hidden && ! $seen++ ) {
156 % balance_forward_row($balance, $item->{'date'});
161 % if ( $bgcolor eq $bgcolor1 ) {
162 % $bgcolor = $bgcolor2;
164 % $bgcolor = $bgcolor1;
167 % my $charge = exists($item->{'charge'})
168 % ? sprintf("$money_char\%.2f", $item->{'charge'})
171 % my $payment = exists($item->{'payment'})
172 % ? sprintf("- $money_char\%.2f", $item->{'payment'})
175 % $payment ||= sprintf( "<DEL>- $money_char\%.2f</DEL>",
176 % $item->{'void_payment'}
178 % if exists($item->{'void_payment'});
180 % my $credit = exists($item->{'credit'})
181 % ? sprintf("- $money_char\%.2f", $item->{'credit'})
184 % my $refund = exists($item->{'refund'})
185 % ? sprintf("$money_char\%.2f", $item->{'refund'})
188 % my $target = exists($item->{'target'}) ? $item->{'target'} : '';
190 % $balance += $item->{'charge'} if exists $item->{'charge'};
191 % $balance -= $item->{'payment'} if exists $item->{'payment'};
192 % $balance -= $item->{'credit'} if exists $item->{'credit'};
193 % $balance += $item->{'refund'} if exists $item->{'refund'};
194 % $balance = sprintf("%.2f", $balance);
195 % $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
196 % ( my $showbalance = $money_char. $balance ) =~ s/^\$\-/- \$/;
201 <TR <% $display ? $display.' ID="old_history'.$old_history++.'"' : ''%>>
202 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
203 % unless ( !$target || $target{$target}++ ) {
205 <A NAME="<% $target %>">
208 <% time2str("%D",$item->{'date'}) %>
209 % if ( $target && $target{$target} == 1 ) {
216 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
217 <% $item->{'desc'} %>
219 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
222 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
225 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
228 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
231 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
237 %if ( scalar(@history) && $hidden && ! $seen++ ) {
238 % balance_forward_row($balance, $lastdate);
243 <SCRIPT TYPE="text/javascript">
245 function show_history () {
246 //alert('showing history!');
248 var balance_forward_row = document.getElementById('balance_forward_row');
250 balance_forward_row.style.display = 'none';
251 for ( var i = 0; i < <% $old_history %>; i++ ) {
252 var oldRow = document.getElementById('old_history'+i);
253 oldRow.style.display = '';
262 my( $cust_main ) = @_;
263 my $custnum = $cust_main->custnum;
265 my $conf = new FS::Conf;
267 my $curuser = $FS::CurrentUser::CurrentUser;
269 my @payby = grep /\w/, $conf->config('payby');
270 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
271 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
273 my %payby = map { $_=>1 } @payby;
276 'Queued' => 'O', #Open
278 'Complete' => 'R', #Resolved
286 foreach my $cust_bill ($cust_main->cust_bill) {
288 'date' => $cust_bill->_date,
289 'desc' => include('payment_history/invoice.html', $cust_bill),
290 'charge' => $cust_bill->charged,
294 #payments (some false laziness w/credits)
295 foreach my $cust_pay ($cust_main->cust_pay) {
297 'date' => $cust_pay->_date,
298 'desc' => include('payment_history/payment.html', $cust_pay),
299 'payment' => $cust_pay->paid,
300 #'target' => $target, #XXX
305 foreach my $cust_pay_void ($cust_main->cust_pay_void) {
307 'date' => $cust_pay_void->_date,
308 'desc' => include('payment_history/voided_payment.html', $cust_pay_void),
309 'void_payment' => $cust_pay_void->paid,
314 #credits (some false laziness w/payments)
315 foreach my $cust_credit ($cust_main->cust_credit) {
317 'date' => $cust_credit->_date,
318 'desc' => include('payment_history/credit.html', $cust_credit),
319 'credit' => $cust_credit->amount,
325 foreach my $cust_refund ($cust_main->cust_refund) {
327 'date' => $cust_refund->_date,
328 'desc' => include('payment_history/refund.html', $cust_refund),
329 'refund' => $cust_refund->refund,