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 <A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('<% $p %>edit/cust_pay.cgi?popup=1;payby=BILL;custnum=<% $custnum %>', 392, 336, 'cust_pay_popup' ), CAPTION, 'Enter check payment', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">Enter check payment</A>
9 % if ( $payby{'CASH'} && $curuser->access_right('Post payment') ) {
10 <% $s++ ? ' | ' : '' %>
11 <A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('<% $p %>edit/cust_pay.cgi?popup=1;payby=CASH;custnum=<% $custnum %>', 392, 336, 'cust_pay_popup' ), CAPTION, 'Enter cash payment', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">Enter cash payment</A>
14 % if ( $payby{'WEST'} && $curuser->access_right('Post payment') ) {
15 <% $s++ ? ' | ' : '' %>
16 <A HREF="<% $p %>edit/cust_pay.cgi?payby=WEST;custnum=<% $custnum %>">Enter Western Union payment</A>
19 % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
20 % && $curuser->access_right('Process payment')
21 % && ! $cust_main->is_encrypted($cust_main->payinfo)
23 <% $s++ ? ' | ' : '' %>
24 <A HREF="<% $p %>misc/payment.cgi?payby=CARD;custnum=<% $custnum %>">Process credit card payment</A>
27 % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
28 % && $curuser->access_right('Process payment')
29 % && ! $cust_main->is_encrypted($cust_main->payinfo)
31 <% $s++ ? ' | ' : '' %>
32 <A HREF="<% $p %>misc/payment.cgi?payby=CHEK;custnum=<% $custnum %>">Process electronic check (ACH) payment</A>
35 % if ( $payby{'MCRD'} && $curuser->access_right('Post payment') ) {
36 <% $s++ ? ' | ' : '' %>
37 <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCRD;custnum=<% $custnum %>">Post manual (offline) credit card payment</A>
42 % if ( $curuser->access_right('Post credit') ) {
43 <A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('<% $p %>edit/cust_credit.cgi?<% $custnum %>', 392, 336, 'cust_credit_popup' ), CAPTION, 'Enter credit', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">Enter credit</A>
47 % if ( $curuser->access_right('View customer tax exemptions') ) {
48 <A HREF="<% $p %>search/cust_tax_exempt_pkg.cgi?custnum=<% $custnum %>">View tax exemptions</A>
52 % if ( $conf->exists('batch-enable')
53 % #&& $curuser->access_right('View customer tax exemptions')
55 View batched payments:
56 % foreach my $status (qw( Queued In-transit Complete All )) {
57 <A HREF="<% $p %>search/cust_pay_batch.cgi?status=<% $status{$status} %>;custnum=<% $custnum %>"><% $status %></A>
58 <% $status ne 'All' ? '|' : '' %>
67 %foreach my $cust_bill ($cust_main->cust_bill) {
68 % my $pre = ( $cust_bill->owed > 0 )
69 % ? '<B><FONT SIZE="+1" COLOR="#FF0000">Open '
71 % my $post = ( $cust_bill->owed > 0 ) ? '</FONT></B>' : '';
72 % my $invnum = $cust_bill->invnum;
73 % my $link = $curuser->access_right('View invoices')
74 % ? qq!<A HREF="${p}view/cust_bill.cgi?$invnum">!
77 % 'date' => $cust_bill->_date,
78 % 'desc' => $link. $pre.
79 % "Invoice #$invnum (Balance \$". $cust_bill->owed. ')'.
80 % $post. ( $link ? '</A>' : '' ),
81 % 'charge' => $cust_bill->charged,
85 %#payments (some false laziness w/credits)
86 %foreach my $cust_pay ($cust_main->cust_pay) {
88 % my $payby = $cust_pay->payby;
91 % if ( $payby eq 'CARD' ) {
92 % $payinfo = $cust_pay->paymask;
93 % } elsif ( $payby eq 'CHEK' && $cust_pay->payinfo =~ /^(\d+)\@(\d+)$/ ) {
94 % $payinfo = "ABA $2, Acct# $1";
96 % $payinfo = $cust_pay->payinfo;
98 % my @cust_bill_pay = $cust_pay->cust_bill_pay;
99 % my @cust_pay_refund = $cust_pay->cust_pay_refund;
101 % my $target = "$payby$payinfo";
102 % $payby =~ s/^BILL$/Check #/ if $payinfo;
103 % $payby =~ s/^CHEK$/Electronic check /;
104 % $payby =~ s/^PREP$/Prepaid card /;
105 % $payby =~ s/^CARD$/Credit card #/;
106 % $payby =~ s/^COMP$/Complimentary by /;
107 % $payby =~ s/^CASH$/Cash/;
108 % $payby =~ s/^WEST$/Western Union/;
109 % $payby =~ s/^MCRD$/Manual credit card/;
110 % $payby =~ s/^BILL$//;
111 % my $info = $payby ? " ($payby$payinfo)" : '';
113 % my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
114 % if ( scalar(@cust_bill_pay) == 0
115 % && scalar(@cust_pay_refund) == 0 ) {
116 % #completely unapplied
117 % $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
118 % $post = '</FONT></B>';
119 % $apply = qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_bill_pay.cgi?!.
121 % qq!', 392, 336, 'cust_bill_pay_popup' ), CAPTION, 'Apply payment', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!;
123 % } elsif ( scalar(@cust_bill_pay) == 1
124 % && scalar(@cust_pay_refund) == 0
125 % && $cust_pay->unapplied == 0 ) {
126 % #applied to one invoice, the usual situation
127 % $desc = ' applied to Invoice #'. $cust_bill_pay[0]->invnum;
128 % } elsif ( scalar(@cust_bill_pay) == 0
129 % && scalar(@cust_pay_refund) == 1
130 % && $cust_pay->unapplied == 0 ) {
131 % #applied to one refund
132 % $desc = ' refunded on '. time2str("%D", $cust_pay_refund[0]->_date);
136 % foreach my $app ( sort { $a->_date <=> $b->_date }
137 % ( @cust_bill_pay, @cust_pay_refund ) ) {
138 % if ( $app->isa('FS::cust_bill_pay') ) {
139 % $desc .= ' '.
141 % ' applied to Invoice #'. $app->invnum.
143 % #' on '. time2str("%D", $cust_bill_pay->_date).
144 % } elsif ( $app->isa('FS::cust_pay_refund') ) {
145 % $desc .= ' '.
147 % ' refunded on '. time2str("%D", $app->_date).
150 % die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
153 % if ( $cust_pay->unapplied > 0 ) {
154 % $desc .= ' '.
155 % '<B><FONT COLOR="#FF0000">$'.
156 % $cust_pay->unapplied. ' unapplied</FONT></B>'.
157 % qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_bill_pay.cgi?!.
159 % qq!', 392, 336, 'cust_bill_pay_popup' ), CAPTION, 'Apply payment', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!.
165 % my $refund_days = $conf->config('card_refund-days') || 120;
166 % if ( $cust_pay->closed !~ /^Y/i
167 % && $cust_pay->payby =~ /^(CARD|CHEK)$/
168 % && time-$cust_pay->_date < $refund_days*86400
169 % && $cust_pay->unrefunded > 0
170 % && $curuser->access_right('Refund payment')
172 % $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
173 % qq!paynum=!. $cust_pay->paynum. '"'.
174 % qq! TITLE="Send a refund for this payment to the payment gateway"!.
179 % if ( $cust_pay->closed !~ /^Y/i
180 % && ( ( $cust_pay->payby eq 'CARD'
181 % && $curuser->access_right('Credit card void')
183 % || ( $cust_pay->payby eq 'CHEK'
184 % && $curuser->access_right('Echeck void')
186 % || ( $cust_pay->payby !~ /^(CARD|CHEK)$/
187 % && $curuser->access_right('Regular void')
192 % $void = qq! (<A HREF="javascript:areyousure('!.
193 % qq!${p}misc/void-cust_pay.cgi?!. $cust_pay->paynum.
194 % qq!', 'Are you sure you want to void this payment?')"!.
195 % qq! TITLE="Void this payment from the database!.
196 % ( $cust_pay->payby =~ /^(CARD|CHEK)$/
197 % ? ' (do not send anything to the payment gateway)'
204 % if ( $cust_pay->closed !~ /^Y/i
205 % && $conf->exists('deletepayments')
206 % && $curuser->access_right('Delete payment')
209 % $delete = qq! (<A HREF="javascript:areyousure('!.
210 % qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
211 % qq!', 'Are you sure you want to delete this payment?')"!.
212 % qq! TITLE="Delete this payment from the database completely - not recommended"!.
217 % if ( $cust_pay->closed !~ /^Y/i
218 % && scalar(@cust_bill_pay)
219 % && $curuser->access_right('Unapply payment')
222 % $unapply = qq! (<A HREF="javascript:areyousure('!.
223 % qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
224 % qq!', 'Are you sure you want to unapply this payment?')"!.
225 % qq! TITLE="Keep this payment, but dissociate it from the invoices it is currently applied against"!.
230 % 'date' => $cust_pay->_date,
231 % 'desc' => $pre. "Payment$post$info$desc".
232 % "$apply$refund$void$delete$unapply",
233 % 'payment' => $cust_pay->paid,
234 % 'target' => $target,
239 %foreach my $cust_pay_void ($cust_main->cust_pay_void) {
241 % my $payby = $cust_pay_void->payby;
242 % my $payinfo = $payby eq 'CARD'
243 % ? $cust_pay_void->paymask
244 % : $cust_pay_void->payinfo;
246 % $payby =~ s/^BILL$/Check #/ if $payinfo;
247 % $payby =~ s/^CHEK$/Electronic check /;
248 % $payby =~ s/^BILL$//;
249 % $payby =~ s/^(CARD|COMP)$/$1 /;
250 % my $info = $payby ? " ($payby$payinfo)" : '';
253 % if ( $cust_pay_void->closed !~ /^Y/i
254 % && $curuser->access_right('Unvoid')
257 % $unvoid = qq! (<A HREF="javascript:areyousure('!.
258 % qq!${p}misc/unvoid-cust_pay_void.cgi?!. $cust_pay_void->paynum.
259 % qq!', 'Are you sure you want to unvoid this payment?')"!.
260 % qq! TITLE="Unvoid this payment from the database!.
261 % ( $cust_pay_void->payby =~ /^(CARD|CHEK)$/
262 % ? ' (do not send anything to the payment gateway)'
269 % 'date' => $cust_pay_void->_date,
270 % 'desc' => "<DEL>Payment $info</DEL> <I>voided ".
271 % time2str("%D", $cust_pay_void->void_date).
272 % " by ". $cust_pay_void->otaker. '</i>'. $unvoid,
273 % 'void_payment' => $cust_pay_void->paid,
278 %#credits (some false laziness w/payments)
279 %foreach my $cust_credit ($cust_main->cust_credit) {
281 % my @cust_credit_bill = $cust_credit->cust_credit_bill;
282 % my @cust_credit_refund = $cust_credit->cust_credit_refund;
284 % my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
285 % if ( scalar(@cust_credit_bill) == 0
286 % && scalar(@cust_credit_refund) == 0 ) {
287 % #completely unapplied
288 % $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
289 % $post = '</FONT></B>';
290 % $apply = qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_credit_bill.cgi?!.
291 % $cust_credit->crednum.
292 % qq!', 392, 336, 'cust_credit_bill_popup' ), CAPTION, 'Apply credit', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!;
293 % } elsif ( scalar(@cust_credit_bill) == 1
294 % && scalar(@cust_credit_refund) == 0
295 % && $cust_credit->credited == 0 ) {
296 % #applied to one invoice, the usual situation
297 % $desc = ' applied to Invoice #'. $cust_credit_bill[0]->invnum;
298 % } elsif ( scalar(@cust_credit_bill) == 0
299 % && scalar(@cust_credit_refund) == 1
300 % && $cust_credit->credited == 0 ) {
301 % #applied to one refund
302 % $desc = ' refunded on '. time2str("%D", $cust_credit_refund[0]->_date);
306 % foreach my $app ( sort { $a->_date <=> $b->_date }
307 % ( @cust_credit_bill, @cust_credit_refund ) ) {
308 % if ( $app->isa('FS::cust_credit_bill') ) {
309 % $desc .= ' '.
311 % ' applied to Invoice #'. $app->invnum.
313 % #' on '. time2str("%D", $app->_date).
314 % } elsif ( $app->isa('FS::cust_credit_refund') ) {
315 % $desc .= ' '.
317 % ' refunded on '. time2str("%D", $app->_date).
320 % die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
323 % if ( $cust_credit->credited > 0 ) {
324 % $desc .= ' <B><FONT COLOR="#FF0000">$'.
325 % $cust_credit->credited. ' unapplied</FONT></B>'.
326 % qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_credit_bill.cgi?!.
327 % $cust_credit->crednum.
328 % qq!', 392, 336, 'cust_credit_bill_popup' ), CAPTION, 'Apply credit', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!.
334 % if ( $cust_credit->closed !~ /^Y/i
336 % #s'pose deleting a credit isn't bad like deleting a payment
337 % # and this needs to be generally available until we have credit voiding..
338 % #&& $conf->exists('deletecredits')
340 % && $curuser->access_right('Delete credit')
343 % $delete = qq! (<A HREF="javascript:areyousure('!.
344 % qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
345 % qq!', 'Are you sure you want to delete this credit?')">!.
350 % if ( $cust_credit->closed !~ /^Y/i
351 % && scalar(@cust_credit_bill)
352 % && $curuser->access_right('Unapply credit')
355 % $unapply = qq! (<A HREF="javascript:areyousure('!.
356 % qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
357 % qq!', 'Are you sure you want to unapply this credit?')">!.
362 % 'date' => $cust_credit->_date,
363 % 'desc' => $pre. "Credit$post by ". $cust_credit->otaker.
364 % ( $cust_credit->reason
365 % ? ' ('. $cust_credit->reason. ')'
368 % "$desc$apply$delete$unapply",
369 % 'credit' => $cust_credit->amount,
375 %foreach my $cust_refund ($cust_main->cust_refund) {
377 % my $payby = $cust_refund->payby;
378 % my $payinfo = $payby eq 'CARD'
379 % ? $cust_refund->paymask
380 % : $cust_refund->payinfo;
382 % $payby =~ s/^BILL$/Check #/ if $payinfo;
383 % $payby =~ s/^CHEK$/Electronic check /;
384 % $payby =~ s/^(CARD|COMP)$/$1 /;
387 % if ( $cust_refund->closed !~ /^Y/i
388 % && $conf->exists('deleterefunds')
389 % && $curuser->access_right('Delete refund')
392 % $delete = qq! (<A HREF="javascript:areyousure('!.
393 % qq!${p}misc/delete-cust_refund.cgi?!. $cust_refund->refundnum.
394 % qq!', 'Are you sure you want to delete this refund?')"!.
395 % qq! TITLE="Delete this refund from the database completely - not recommended"!.
400 % 'date' => $cust_refund->_date,
401 % 'desc' => "Refund ($payby$payinfo) by ". $cust_refund->otaker. "<BR>".
403 % 'refund' => $cust_refund->refund,
411 <% include("/elements/table-grid.html") %>
412 % my $bgcolor1 = '#eeeeee';
413 % my $bgcolor2 = '#ffffff';
419 <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
420 <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
421 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Charge</FONT></TH>
422 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Payment</FONT></TH>
423 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
424 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Refund</FONT></TH>
425 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Balance</FONT></TH>
428 %#display payment history
430 %sub balance_forward_row {
431 % my( $b, $date ) = @_;
432 % my $conf = new FS::Conf;
433 % my $money_char = $conf->config('money_char') || '$';
434 % ( my $balance_forward = $money_char. $b ) =~ s/^\$\-/- \$/;
436 <TR ID="balance_forward_row">
437 <TD CLASS="grid" BGCOLOR="#dddddd">
438 <% time2str("%D",$date) %>
441 <TD CLASS="grid" BGCOLOR="#dddddd">
442 <I>Starting balance on <% time2str("%D",$date) %></I>
443 (<A HREF="javascript:void(0);" onClick="show_history();">show prior history</A>)
446 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
447 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
448 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
449 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
450 <TD CLASS="grid" BGCOLOR="#dddddd"><I><% $balance_forward %></I></TD>
457 %my $money_char = $conf->config('money_char') || '$';
459 %my $years = $conf->config('payment_history-years') || 2;
460 %my $older_than = time - $years * 31556736; #60*60*24*365.24
463 %my $old_history = 0;
466 %foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
468 % $lastdate = $item->{'date'};
471 % if ( $item->{'date'} < $older_than ) {
472 % $display = ' STYLE="display:none" ';
478 % if ( $hidden && ! $seen++ ) {
479 % balance_forward_row($balance, $item->{'date'});
484 % if ( $bgcolor eq $bgcolor1 ) {
485 % $bgcolor = $bgcolor2;
487 % $bgcolor = $bgcolor1;
490 % my $charge = exists($item->{'charge'})
491 % ? sprintf("$money_char\%.2f", $item->{'charge'})
494 % my $payment = exists($item->{'payment'})
495 % ? sprintf("- $money_char\%.2f", $item->{'payment'})
498 % $payment ||= sprintf( "<DEL>- $money_char\%.2f</DEL>",
499 % $item->{'void_payment'}
501 % if exists($item->{'void_payment'});
503 % my $credit = exists($item->{'credit'})
504 % ? sprintf("- $money_char\%.2f", $item->{'credit'})
507 % my $refund = exists($item->{'refund'})
508 % ? sprintf("$money_char\%.2f", $item->{'refund'})
511 % my $target = exists($item->{'target'}) ? $item->{'target'} : '';
513 % $balance += $item->{'charge'} if exists $item->{'charge'};
514 % $balance -= $item->{'payment'} if exists $item->{'payment'};
515 % $balance -= $item->{'credit'} if exists $item->{'credit'};
516 % $balance += $item->{'refund'} if exists $item->{'refund'};
517 % $balance = sprintf("%.2f", $balance);
518 % $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
519 % ( my $showbalance = $money_char. $balance ) =~ s/^\$\-/- \$/;
524 <TR <% $display ? $display.' ID="old_history'.$old_history++.'"' : ''%>>
525 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
526 % unless ( !$target || $target{$target}++ ) {
528 <A NAME="<% $target %>">
531 <% time2str("%D",$item->{'date'}) %>
532 % if ( $target && $target{$target} == 1 ) {
539 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
540 <% $item->{'desc'} %>
542 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
545 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
548 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
551 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
554 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
560 %if ( scalar(@history) && $hidden && ! $seen++ ) {
561 % balance_forward_row($balance, $lastdate);
566 <SCRIPT TYPE="text/javascript">
568 function show_history () {
569 //alert('showing history!');
571 var balance_forward_row = document.getElementById('balance_forward_row');
573 balance_forward_row.style.display = 'none';
574 for ( var i = 0; i < <% $old_history %>; i++ ) {
575 var oldRow = document.getElementById('old_history'+i);
576 oldRow.style.display = '';
585 my( $cust_main ) = @_;
586 my $custnum = $cust_main->custnum;
588 my $conf = new FS::Conf;
590 my $curuser = $FS::CurrentUser::CurrentUser;
592 my @payby = grep /\w/, $conf->config('payby');
593 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
594 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
596 my %payby = map { $_=>1 } @payby;
599 'Queued' => 'O', #Open
601 'Complete' => 'R', #Resolved