1 <BR><BR><A NAME="history"><FONT SIZE="+2">Payment History</FONT></A><BR>
6 % if ( $payby{'BILL'} && $curuser->access_right('Post payment') ) {
7 <% $s++ ? ' | ' : '' %>
8 <% include('/elements/popup_link-cust_main.html',
9 'label' => 'Enter check payment',
10 'action' => "${p}edit/cust_pay.cgi?popup=1;payby=BILL",
11 'cust_main' => $cust_main,
12 'actionlabel' => 'Enter check payment',
14 #default# 'height' => 336,
19 % if ( $payby{'CASH'} && $curuser->access_right('Post payment') ) {
20 <% $s++ ? ' | ' : '' %>
21 <% include('/elements/popup_link-cust_main.html',
22 'label' => 'Enter cash payment',
23 'action' => "${p}edit/cust_pay.cgi?popup=1;payby=CASH",
24 'cust_main' => $cust_main,
25 'actionlabel' => 'Enter cash payment',
27 #default# 'height' => 336,
32 % if ( $payby{'WEST'} && $curuser->access_right('Post payment') ) {
33 <% $s++ ? ' | ' : '' %>
34 <A HREF="<% $p %>edit/cust_pay.cgi?payby=WEST;custnum=<% $custnum %>">Enter Western Union payment</A>
37 % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
38 % && $curuser->access_right('Process payment')
39 % && ! $cust_main->is_encrypted($cust_main->payinfo)
41 <% $s++ ? ' | ' : '' %>
42 <A HREF="<% $p %>misc/payment.cgi?payby=CARD;custnum=<% $custnum %>">Process credit card payment</A>
45 % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
46 % && $curuser->access_right('Process payment')
47 % && ! $cust_main->is_encrypted($cust_main->payinfo)
49 <% $s++ ? ' | ' : '' %>
50 <A HREF="<% $p %>misc/payment.cgi?payby=CHEK;custnum=<% $custnum %>">Process electronic check (ACH) payment</A>
53 % if ( $payby{'MCRD'} && $curuser->access_right('Post payment') ) {
54 <% $s++ ? ' | ' : '' %>
55 <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCRD;custnum=<% $custnum %>">Post manual (offline/POS) credit card payment</A>
62 % if ( $curuser->access_right('Post credit') ) {
63 <% include('/elements/popup_link-cust_main.html',
64 'label' => 'Enter credit',
65 'action' => "${p}edit/cust_credit.cgi",
66 'cust_main' => $cust_main,
67 'actionlabel' => 'Enter credit',
69 #default# 'height' => 336,
78 % if ( $payby{'BILL'} && $curuser->access_right('Post refund') ) {
79 <% $s++ ? ' | ' : '' %>
80 <% include('/elements/popup_link-cust_main.html',
81 'label' => 'Enter check refund',
82 'action' => "${p}edit/cust_refund.cgi?popup=1;payby=BILL",
83 'cust_main' => $cust_main,
84 'actionlabel' => 'Enter check refund',
86 #default# 'height' => 336,
91 % if ( $payby{'CASH'} && $curuser->access_right('Post refund') ) {
92 <% $s++ ? ' | ' : '' %>
93 <% include('/elements/popup_link-cust_main.html',
94 'label' => 'Enter cash refund',
95 'action' => "${p}edit/cust_refund.cgi?popup=1;payby=CASH",
96 'cust_main' => $cust_main,
97 'actionlabel' => 'Enter cash refund',
99 #default# 'height' => 336,
104 %# someday, perhaps. very few gateways let you do unlinked refunds at all.
105 %# Authorize.net makes you sign a special form
107 %# % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
108 %# % && $curuser->access_right('Process refund')
109 %# % && ! $cust_main->is_encrypted($cust_main->payinfo)
111 %# <% $s++ ? ' | ' : '' %>
112 %# <A HREF="<% $p %>misc/refund.cgi?payby=CARD;custnum=<% $custnum %>">Process credit card refund</A>
115 %# % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
116 %# % && $curuser->access_right('Process refund')
117 %# % && ! $cust_main->is_encrypted($cust_main->payinfo)
119 %# <% $s++ ? ' | ' : '' %>
120 %# <A HREF="<% $p %>misc/refund.cgi?payby=CHEK;custnum=<% $custnum %>">Process electronic check (ACH) refund</A>
123 % if ( $payby{'MCRD'} && $curuser->access_right('Post refund') ) {
124 <% $s++ ? ' | ' : '' %>
125 <A HREF="<% $p %>edit/cust_refund.cgi?payby=MCRD;custnum=<% $custnum %>">Post manual (offline/POS) credit card refund</A>
130 %# tax exemption link
132 % if ( $curuser->access_right('View customer tax exemptions') ) {
133 <A HREF="<% $p %>search/cust_tax_exempt_pkg.cgi?custnum=<% $custnum %>">View tax exemptions</A>
137 %# batched payment links
139 % if ( ( $conf->exists('batch-enable') || $conf->config('batch-enable_payby') )
140 % && $curuser->access_right('View customer batched payments')
142 View batched payments:
143 % foreach my $status (qw( Queued In-transit Complete All )) {
144 <A HREF="<% $p %>search/cust_pay_batch.cgi?status=<% $status{$status} %>;custnum=<% $custnum %>"><% $status %></A>
145 <% $status ne 'All' ? '|' : '' %>
152 <% include("/elements/table-grid.html") %>
153 % my $bgcolor1 = '#eeeeee';
154 % my $bgcolor2 = '#ffffff';
158 <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
159 <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
160 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Invoice</FONT></TH>
161 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Payment</FONT></TH>
162 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
163 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Refund</FONT></TH>
164 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Balance</FONT></TH>
167 %#display payment history
169 %sub balance_forward_row {
170 % my( $b, $date ) = @_;
171 % my $conf = new FS::Conf;
172 % my $money_char = $conf->config('money_char') || '$';
173 % ( my $balance_forward = $money_char. $b ) =~ s/^\$\-/- \$/;
175 <TR ID="balance_forward_row">
176 <TD CLASS="grid" BGCOLOR="#dddddd">
177 <% time2str("%D",$date) %>
180 <TD CLASS="grid" BGCOLOR="#dddddd">
181 <I>Starting balance on <% time2str("%D",$date) %></I>
182 (<A HREF="javascript:void(0);" onClick="show_history();">show prior history</A>)
185 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
186 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
187 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
188 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
189 <TD CLASS="grid" BGCOLOR="#dddddd"><I><% $balance_forward %></I></TD>
196 %my $money_char = $conf->config('money_char') || '$';
198 %my $years = $conf->config('payment_history-years') || 2;
199 %my $older_than = time - $years * 31556736; #60*60*24*365.24
202 %my $old_history = 0;
205 %foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
207 % $lastdate = $item->{'date'};
210 % if ( $item->{'date'} < $older_than ) {
211 % $display = ' STYLE="display:none" ';
217 % if ( $hidden && ! $seen++ ) {
218 % balance_forward_row($balance, $item->{'date'});
223 % if ( $bgcolor eq $bgcolor1 ) {
224 % $bgcolor = $bgcolor2;
226 % $bgcolor = $bgcolor1;
229 % my $charge = exists($item->{'charge'})
230 % ? sprintf("$money_char\%.2f", $item->{'charge'})
233 % my $payment = exists($item->{'payment'})
234 % ? sprintf("- $money_char\%.2f", $item->{'payment'})
237 % $payment ||= sprintf( "<DEL>- $money_char\%.2f</DEL>",
238 % $item->{'void_payment'}
240 % if exists($item->{'void_payment'});
242 % my $credit = exists($item->{'credit'})
243 % ? sprintf("- $money_char\%.2f", $item->{'credit'})
246 % my $refund = exists($item->{'refund'})
247 % ? sprintf("$money_char\%.2f", $item->{'refund'})
250 % my $target = exists($item->{'target'}) ? $item->{'target'} : '';
252 % $balance += $item->{'charge'} if exists $item->{'charge'};
253 % $balance -= $item->{'payment'} if exists $item->{'payment'};
254 % $balance -= $item->{'credit'} if exists $item->{'credit'};
255 % $balance += $item->{'refund'} if exists $item->{'refund'};
256 % $balance = sprintf("%.2f", $balance);
257 % $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
258 % ( my $showbalance = $money_char. $balance ) =~ s/^\$\-/- \$/;
263 <TR <% $display ? $display.' ID="old_history'.$old_history++.'"' : ''%>>
264 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
265 % unless ( !$target || $target{$target}++ ) {
267 <A NAME="<% $target %>">
270 <% time2str("%D",$item->{'date'}) %>
271 % if ( $target && $target{$target} == 1 ) {
278 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
279 <% $item->{'desc'} %>
281 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
284 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
287 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
290 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
293 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
299 %if ( scalar(@history) && $hidden && ! $seen++ ) {
300 % balance_forward_row($balance, $lastdate);
305 <SCRIPT TYPE="text/javascript">
307 function show_history () {
308 //alert('showing history!');
310 var balance_forward_row = document.getElementById('balance_forward_row');
312 balance_forward_row.style.display = 'none';
313 for ( var i = 0; i < <% $old_history %>; i++ ) {
314 var oldRow = document.getElementById('old_history'+i);
315 oldRow.style.display = '';
324 my( $cust_main ) = @_;
325 my $custnum = $cust_main->custnum;
327 my $conf = new FS::Conf;
329 my $curuser = $FS::CurrentUser::CurrentUser;
331 my @payby = grep /\w/, $conf->config('payby');
332 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
333 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
335 my %payby = map { $_=>1 } @payby;
338 'Queued' => 'O', #Open
340 'Complete' => 'R', #Resolved
348 ( map { $_ => scalar($conf->config($_)) }
349 qw( card_refund-days )
351 ( map { $_ => $conf->exists($_) }
352 qw( deletepayments deleterefunds )
356 foreach my $cust_bill ($cust_main->cust_bill) {
358 'date' => $cust_bill->_date,
359 'desc' => include('payment_history/invoice.html', $cust_bill, %opt ),
360 'charge' => $cust_bill->charged,
364 #payments (some false laziness w/credits)
365 foreach my $cust_pay ($cust_main->cust_pay) {
367 'date' => $cust_pay->_date,
368 'desc' => include('payment_history/payment.html', $cust_pay, %opt ),
369 'payment' => $cust_pay->paid,
370 #'target' => $target, #XXX
375 foreach my $cust_pay_void ($cust_main->cust_pay_void) {
377 'date' => $cust_pay_void->_date,
378 'desc' => include('payment_history/voided_payment.html', $cust_pay_void),
379 'void_payment' => $cust_pay_void->paid,
384 #credits (some false laziness w/payments)
385 foreach my $cust_credit ($cust_main->cust_credit) {
387 'date' => $cust_credit->_date,
388 'desc' => include('payment_history/credit.html', $cust_credit),
389 'credit' => $cust_credit->amount,
395 foreach my $cust_refund ($cust_main->cust_refund) {
397 'date' => $cust_refund->_date,
398 'desc' => include('payment_history/refund.html', $cust_refund),
399 'refund' => $cust_refund->refund,