3 <BR><BR><A NAME="history"><FONT SIZE="+2">Payment History</FONT></A><BR>
6 % if ( $payby{'BILL'} && $curuser->access_right('Post payment') ) {
8 <% $s++ ? ' | ' : '' %>
9 <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>
11 % if ( $payby{'CASH'} && $curuser->access_right('Post payment') ) {
14 <% $s++ ? ' | ' : '' %>
15 <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>
17 % if ( $payby{'WEST'} && $curuser->access_right('Post payment') ) {
20 <% $s++ ? ' | ' : '' %>
21 <A HREF="<% $p %>edit/cust_pay.cgi?payby=WEST;custnum=<% $custnum %>">Enter Western Union payment</A>
23 % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
24 % && $curuser->access_right('Process payment')
29 <% $s++ ? ' | ' : '' %>
30 <A HREF="<% $p %>misc/payment.cgi?payby=CARD;custnum=<% $custnum %>">Process credit card payment</A>
32 % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
33 % && $curuser->access_right('Process payment')
38 <% $s++ ? ' | ' : '' %>
39 <A HREF="<% $p %>misc/payment.cgi?payby=CHEK;custnum=<% $custnum %>">Process electronic check (ACH) payment</A>
41 % if ( $payby{'MCRD'} && $curuser->access_right('Post payment') ) {
44 <% $s++ ? ' | ' : '' %>
45 <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCRD;custnum=<% $custnum %>">Post manual (offline) credit card payment</A>
50 % if ( $curuser->access_right('Post credit') ) {
51 <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>
55 % if ( $curuser->access_right('View customer tax exemptions') ) {
56 <A HREF="<% $p %>search/cust_tax_exempt_pkg.cgi?custnum=<% $custnum %>">View tax exemptions</A>
66 %foreach my $cust_bill ($cust_main->cust_bill) {
67 % my $pre = ( $cust_bill->owed > 0 )
68 % ? '<B><FONT SIZE="+1" COLOR="#FF0000">Open '
70 % my $post = ( $cust_bill->owed > 0 ) ? '</FONT></B>' : '';
71 % my $invnum = $cust_bill->invnum;
72 % my $link = $curuser->access_right('View invoices')
73 % ? qq!<A HREF="${p}view/cust_bill.cgi?$invnum">!
76 % 'date' => $cust_bill->_date,
77 % 'desc' => $link. $pre.
78 % "Invoice #$invnum (Balance \$". $cust_bill->owed. ')'.
79 % $post. ( $link ? '</A>' : '' ),
80 % 'charge' => $cust_bill->charged,
84 %#payments (some false laziness w/credits)
85 %foreach my $cust_pay ($cust_main->cust_pay) {
87 % my $payby = $cust_pay->payby;
90 % if ( $payby eq 'CARD' ) {
91 % $payinfo = $cust_pay->payinfo_masked;
92 % } elsif ( $payby eq 'CHEK' && $cust_pay->payinfo =~ /^(\d+)\@(\d+)$/ ) {
93 % $payinfo = "ABA $2, Acct# $1";
95 % $payinfo = $cust_pay->payinfo;
97 % my @cust_bill_pay = $cust_pay->cust_bill_pay;
98 % my @cust_pay_refund = $cust_pay->cust_pay_refund;
100 % my $target = "$payby$payinfo";
101 % $payby =~ s/^BILL$/Check #/ if $payinfo;
102 % $payby =~ s/^CHEK$/Electronic check /;
103 % $payby =~ s/^PREP$/Prepaid card /;
104 % $payby =~ s/^CARD$/Credit card #/;
105 % $payby =~ s/^COMP$/Complimentary by /;
106 % $payby =~ s/^CASH$/Cash/;
107 % $payby =~ s/^WEST$/Western Union/;
108 % $payby =~ s/^MCRD$/Manual credit card/;
109 % $payby =~ s/^BILL$//;
110 % my $info = $payby ? " ($payby$payinfo)" : '';
112 % my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
113 % if ( scalar(@cust_bill_pay) == 0
114 % && scalar(@cust_pay_refund) == 0 ) {
115 % #completely unapplied
116 % $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
117 % $post = '</FONT></B>';
118 % $apply = qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_bill_pay.cgi?!.
120 % qq!', 392, 336, 'cust_bill_pay_popup' ), CAPTION, 'Apply payment', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!;
122 % } elsif ( scalar(@cust_bill_pay) == 1
123 % && scalar(@cust_pay_refund) == 0
124 % && $cust_pay->unapplied == 0 ) {
125 % #applied to one invoice, the usual situation
126 % $desc = ' applied to Invoice #'. $cust_bill_pay[0]->invnum;
127 % } elsif ( scalar(@cust_bill_pay) == 0
128 % && scalar(@cust_pay_refund) == 1
129 % && $cust_pay->unapplied == 0 ) {
130 % #applied to one refund
131 % $desc = ' refunded on '. time2str("%D", $cust_pay_refund[0]->_date);
135 % foreach my $app ( sort { $a->_date <=> $b->_date }
136 % ( @cust_bill_pay, @cust_pay_refund ) ) {
137 % if ( $app->isa('FS::cust_bill_pay') ) {
138 % $desc .= ' '.
140 % ' applied to Invoice #'. $app->invnum.
142 % #' on '. time2str("%D", $cust_bill_pay->_date).
143 % } elsif ( $app->isa('FS::cust_pay_refund') ) {
144 % $desc .= ' '.
146 % ' refunded on '. time2str("%D", $app->_date).
149 % die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
152 % if ( $cust_pay->unapplied > 0 ) {
153 % $desc .= ' '.
154 % '<B><FONT COLOR="#FF0000">$'.
155 % $cust_pay->unapplied. ' unapplied</FONT></B>'.
156 % qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_bill_pay.cgi?!.
158 % qq!', 392, 336, 'cust_bill_pay_popup' ), CAPTION, 'Apply payment', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!.
164 % my $refund_days = $conf->config('card_refund-days') || 120;
165 % if ( $cust_pay->closed !~ /^Y/i
166 % && $cust_pay->payby =~ /^(CARD|CHEK)$/
167 % && time-$cust_pay->_date < $refund_days*86400
168 % && $cust_pay->unrefunded > 0
169 % && $curuser->access_right('Refund payment')
171 % $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
172 % qq!paynum=!. $cust_pay->paynum. '"'.
173 % qq! TITLE="Send a refund for this payment to the payment gateway"!.
178 % if ( $cust_pay->closed !~ /^Y/i
179 % && ( ( $cust_pay->payby eq 'CARD'
180 % && $curuser->access_right('Credit card void')
182 % || ( $cust_pay->payby eq 'CHEK'
183 % && $curuser->access_right('Echeck void')
185 % || ( $cust_pay->payby !~ /^(CARD|CHEK)$/
186 % && $curuser->access_right('Regular void')
191 % $void = qq! (<A HREF="javascript:areyousure('!.
192 % qq!${p}misc/void-cust_pay.cgi?!. $cust_pay->paynum.
193 % qq!', 'Are you sure you want to void this payment?')"!.
194 % qq! TITLE="Void this payment from the database!.
195 % ( $cust_pay->payby =~ /^(CARD|CHEK)$/
196 % ? ' (do not send anything to the payment gateway)'
203 % if ( $cust_pay->closed !~ /^Y/i
204 % && $conf->exists('deletepayments')
205 % && $curuser->access_right('Delete payment')
208 % $delete = qq! (<A HREF="javascript:areyousure('!.
209 % qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
210 % qq!', 'Are you sure you want to delete this payment?')"!.
211 % qq! TITLE="Delete this payment from the database completely - not recommended"!.
216 % if ( $cust_pay->closed !~ /^Y/i
217 % && scalar(@cust_bill_pay)
218 % && $curuser->access_right('Unapply payment')
221 % $unapply = qq! (<A HREF="javascript:areyousure('!.
222 % qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
223 % qq!', 'Are you sure you want to unapply this payment?')"!.
224 % qq! TITLE="Keep this payment, but dissociate it from the invoices it is currently applied against"!.
229 % 'date' => $cust_pay->_date,
230 % 'desc' => $pre. "Payment$post$info$desc".
231 % "$apply$refund$void$delete$unapply",
232 % 'payment' => $cust_pay->paid,
233 % 'target' => $target,
238 %foreach my $cust_pay_void ($cust_main->cust_pay_void) {
240 % my $payby = $cust_pay_void->payby;
241 % my $payinfo = $payby eq 'CARD'
242 % ? $cust_pay_void->payinfo_masked
243 % : $cust_pay_void->payinfo;
245 % $payby =~ s/^BILL$/Check #/ if $payinfo;
246 % $payby =~ s/^CHEK$/Electronic check /;
247 % $payby =~ s/^BILL$//;
248 % $payby =~ s/^(CARD|COMP)$/$1 /;
249 % my $info = $payby ? " ($payby$payinfo)" : '';
252 % if ( $cust_pay_void->closed !~ /^Y/i
253 % && $curuser->access_right('Unvoid')
256 % $unvoid = qq! (<A HREF="javascript:areyousure('!.
257 % qq!${p}misc/unvoid-cust_pay_void.cgi?!. $cust_pay_void->paynum.
258 % qq!', 'Are you sure you want to unvoid this payment?')"!.
259 % qq! TITLE="Unvoid this payment from the database!.
260 % ( $cust_pay_void->payby =~ /^(CARD|CHEK)$/
261 % ? ' (do not send anything to the payment gateway)'
268 % 'date' => $cust_pay_void->_date,
269 % 'desc' => "<DEL>Payment $info</DEL> <I>voided ".
270 % time2str("%D", $cust_pay_void->void_date).
271 % " by ". $cust_pay_void->otaker. '</i>'. $unvoid,
272 % 'void_payment' => $cust_pay_void->paid,
277 %#credits (some false laziness w/payments)
278 %foreach my $cust_credit ($cust_main->cust_credit) {
280 % my @cust_credit_bill = $cust_credit->cust_credit_bill;
281 % my @cust_credit_refund = $cust_credit->cust_credit_refund;
283 % my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
284 % if ( scalar(@cust_credit_bill) == 0
285 % && scalar(@cust_credit_refund) == 0 ) {
286 % #completely unapplied
287 % $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
288 % $post = '</FONT></B>';
289 % $apply = qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_credit_bill.cgi?!.
290 % $cust_credit->crednum.
291 % qq!', 392, 336, 'cust_credit_bill_popup' ), CAPTION, 'Apply credit', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!;
292 % } elsif ( scalar(@cust_credit_bill) == 1
293 % && scalar(@cust_credit_refund) == 0
294 % && $cust_credit->credited == 0 ) {
295 % #applied to one invoice, the usual situation
296 % $desc = ' applied to Invoice #'. $cust_credit_bill[0]->invnum;
297 % } elsif ( scalar(@cust_credit_bill) == 0
298 % && scalar(@cust_credit_refund) == 1
299 % && $cust_credit->credited == 0 ) {
300 % #applied to one refund
301 % $desc = ' refunded on '. time2str("%D", $cust_credit_refund[0]->_date);
305 % foreach my $app ( sort { $a->_date <=> $b->_date }
306 % ( @cust_credit_bill, @cust_credit_refund ) ) {
307 % if ( $app->isa('FS::cust_credit_bill') ) {
308 % $desc .= ' '.
310 % ' applied to Invoice #'. $app->invnum.
312 % #' on '. time2str("%D", $app->_date).
313 % } elsif ( $app->isa('FS::cust_credit_refund') ) {
314 % $desc .= ' '.
316 % ' refunded on '. time2str("%D", $app->_date).
319 % die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
322 % if ( $cust_credit->credited > 0 ) {
323 % $desc .= ' <B><FONT COLOR="#FF0000">$'.
324 % $cust_credit->credited. ' unapplied</FONT></B>'.
325 % qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_credit_bill.cgi?!.
326 % $cust_credit->crednum.
327 % qq!', 392, 336, 'cust_credit_bill_popup' ), CAPTION, 'Apply credit', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!.
333 % if ( $cust_credit->closed !~ /^Y/i
335 % #s'pose deleting a credit isn't bad like deleting a payment
336 % # and this needs to be generally available until we have credit voiding..
337 % #&& $conf->exists('deletecredits')
339 % && $curuser->access_right('Delete credit')
342 % $delete = qq! (<A HREF="javascript:areyousure('!.
343 % qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
344 % qq!', 'Are you sure you want to delete this credit?')">!.
349 % if ( $cust_credit->closed !~ /^Y/i
350 % && scalar(@cust_credit_bill)
351 % && $curuser->access_right('Unapply credit')
354 % $unapply = qq! (<A HREF="javascript:areyousure('!.
355 % qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
356 % qq!', 'Are you sure you want to unapply this credit?')">!.
361 % 'date' => $cust_credit->_date,
362 % 'desc' => $pre. "Credit$post by ". $cust_credit->otaker.
363 % ( $cust_credit->reason
364 % ? ' ('. $cust_credit->reason. ')'
367 % "$desc$apply$delete$unapply",
368 % 'credit' => $cust_credit->amount,
374 %foreach my $cust_refund ($cust_main->cust_refund) {
376 % my $payby = $cust_refund->payby;
377 % my $payinfo = $payby eq 'CARD'
378 % ? $cust_refund->payinfo_masked
379 % : $cust_refund->payinfo;
381 % $payby =~ s/^BILL$/Check #/ if $payinfo;
382 % $payby =~ s/^CHEK$/Electronic check /;
383 % $payby =~ s/^(CARD|COMP)$/$1 /;
386 % 'date' => $cust_refund->_date,
387 % 'desc' => "Refund ($payby$payinfo) by ". $cust_refund->otaker,
388 % 'refund' => $cust_refund->refund,
396 <% include("/elements/table-grid.html") %>
397 % my $bgcolor1 = '#eeeeee';
398 % my $bgcolor2 = '#ffffff';
404 <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
405 <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
406 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Charge</FONT></TH>
407 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Payment</FONT></TH>
408 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
409 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Refund</FONT></TH>
410 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Balance</FONT></TH>
413 %#display payment history
417 %my $money_char = $conf->config('money_char') || '$';
419 %my $years = $conf->config('payment_history-years') || 2;
420 %my $older_than = time - $years * 31556736; #60*60*24*365.24
423 %my $old_history = 0;
425 %foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
428 % if ( $item->{'date'} < $older_than ) {
429 % $display = ' STYLE="display:none" ';
435 % if ( $hidden && ! $seen++ ) {
436 % ( my $balance_forward = $money_char. $balance ) =~ s/^\$\-/- \$/;
440 <TR ID="balance_forward_row">
441 <TD CLASS="grid" BGCOLOR="#dddddd">
442 <% time2str("%D",$item->{'date'}) %>
445 <TD CLASS="grid" BGCOLOR="#dddddd">
446 <I>Starting balance on <% time2str("%D",$item->{'date'}) %></I>
447 (<A HREF="javascript:void(0);" onClick="show_history();">show prior history</A>)
450 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
451 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
452 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
453 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
454 <TD CLASS="grid" BGCOLOR="#dddddd"><I><% $balance_forward %></I></TD>
462 % if ( $bgcolor eq $bgcolor1 ) {
463 % $bgcolor = $bgcolor2;
465 % $bgcolor = $bgcolor1;
468 % my $charge = exists($item->{'charge'})
469 % ? sprintf("$money_char\%.2f", $item->{'charge'})
472 % my $payment = exists($item->{'payment'})
473 % ? sprintf("- $money_char\%.2f", $item->{'payment'})
476 % $payment ||= sprintf( "<DEL>- $money_char\%.2f</DEL>",
477 % $item->{'void_payment'}
479 % if exists($item->{'void_payment'});
481 % my $credit = exists($item->{'credit'})
482 % ? sprintf("- $money_char\%.2f", $item->{'credit'})
485 % my $refund = exists($item->{'refund'})
486 % ? sprintf("$money_char\%.2f", $item->{'refund'})
489 % my $target = exists($item->{'target'}) ? $item->{'target'} : '';
491 % $balance += $item->{'charge'} if exists $item->{'charge'};
492 % $balance -= $item->{'payment'} if exists $item->{'payment'};
493 % $balance -= $item->{'credit'} if exists $item->{'credit'};
494 % $balance += $item->{'refund'} if exists $item->{'refund'};
495 % $balance = sprintf("%.2f", $balance);
496 % $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
497 % ( my $showbalance = $money_char. $balance ) =~ s/^\$\-/- \$/;
502 <TR <% $display ? $display.' ID="old_history'.$old_history++.'"' : ''%>>
503 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
504 % unless ( !$target || $target{$target}++ ) {
506 <A NAME="<% $target %>">
509 <% time2str("%D",$item->{'date'}) %>
510 % if ( $target && $target{$target} == 1 ) {
517 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
518 <% $item->{'desc'} %>
520 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
523 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
526 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
529 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
532 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
541 <SCRIPT TYPE="text/javascript">
543 function show_history () {
544 //alert('showing history!');
546 var balance_forward_row = document.getElementById('balance_forward_row');
548 balance_forward_row.style.display = 'none';
549 for ( var i = 0; i < <% $old_history %>; i++ ) {
550 var oldRow = document.getElementById('old_history'+i);
551 oldRow.style.display = '';
560 my( $cust_main ) = @_;
561 my $custnum = $cust_main->custnum;
563 my $conf = new FS::Conf;
565 my $curuser = $FS::CurrentUser::CurrentUser;
567 my @payby = grep /\w/, $conf->config('payby');
568 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
569 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
571 my %payby = map { $_=>1 } @payby;