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>
56 %foreach my $cust_bill ($cust_main->cust_bill) {
57 % my $pre = ( $cust_bill->owed > 0 )
58 % ? '<B><FONT SIZE="+1" COLOR="#FF0000">Open '
60 % my $post = ( $cust_bill->owed > 0 ) ? '</FONT></B>' : '';
61 % my $invnum = $cust_bill->invnum;
62 % my $link = $curuser->access_right('View invoices')
63 % ? qq!<A HREF="${p}view/cust_bill.cgi?$invnum">!
66 % 'date' => $cust_bill->_date,
67 % 'desc' => $link. $pre.
68 % "Invoice #$invnum (Balance \$". $cust_bill->owed. ')'.
69 % $post. ( $link ? '</A>' : '' ),
70 % 'charge' => $cust_bill->charged,
74 %#payments (some false laziness w/credits)
75 %foreach my $cust_pay ($cust_main->cust_pay) {
77 % my $payby = $cust_pay->payby;
80 % if ( $payby eq 'CARD' ) {
81 % $payinfo = $cust_pay->paymask;
82 % } elsif ( $payby eq 'CHEK' && $cust_pay->payinfo =~ /^(\d+)\@(\d+)$/ ) {
83 % $payinfo = "ABA $2, Acct# $1";
85 % $payinfo = $cust_pay->payinfo;
87 % my @cust_bill_pay = $cust_pay->cust_bill_pay;
88 % my @cust_pay_refund = $cust_pay->cust_pay_refund;
90 % my $target = "$payby$payinfo";
91 % $payby =~ s/^BILL$/Check #/ if $payinfo;
92 % $payby =~ s/^CHEK$/Electronic check /;
93 % $payby =~ s/^PREP$/Prepaid card /;
94 % $payby =~ s/^CARD$/Credit card #/;
95 % $payby =~ s/^COMP$/Complimentary by /;
96 % $payby =~ s/^CASH$/Cash/;
97 % $payby =~ s/^WEST$/Western Union/;
98 % $payby =~ s/^MCRD$/Manual credit card/;
99 % $payby =~ s/^BILL$//;
100 % my $info = $payby ? " ($payby$payinfo)" : '';
102 % my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
103 % if ( scalar(@cust_bill_pay) == 0
104 % && scalar(@cust_pay_refund) == 0 ) {
105 % #completely unapplied
106 % $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
107 % $post = '</FONT></B>';
108 % $apply = qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_bill_pay.cgi?!.
110 % qq!', 392, 336, 'cust_bill_pay_popup' ), CAPTION, 'Apply payment', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!;
112 % } elsif ( scalar(@cust_bill_pay) == 1
113 % && scalar(@cust_pay_refund) == 0
114 % && $cust_pay->unapplied == 0 ) {
115 % #applied to one invoice, the usual situation
116 % $desc = ' applied to Invoice #'. $cust_bill_pay[0]->invnum;
117 % } elsif ( scalar(@cust_bill_pay) == 0
118 % && scalar(@cust_pay_refund) == 1
119 % && $cust_pay->unapplied == 0 ) {
120 % #applied to one refund
121 % $desc = ' refunded on '. time2str("%D", $cust_pay_refund[0]->_date);
125 % foreach my $app ( sort { $a->_date <=> $b->_date }
126 % ( @cust_bill_pay, @cust_pay_refund ) ) {
127 % if ( $app->isa('FS::cust_bill_pay') ) {
128 % $desc .= ' '.
130 % ' applied to Invoice #'. $app->invnum.
132 % #' on '. time2str("%D", $cust_bill_pay->_date).
133 % } elsif ( $app->isa('FS::cust_pay_refund') ) {
134 % $desc .= ' '.
136 % ' refunded on '. time2str("%D", $app->_date).
139 % die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
142 % if ( $cust_pay->unapplied > 0 ) {
143 % $desc .= ' '.
144 % '<B><FONT COLOR="#FF0000">$'.
145 % $cust_pay->unapplied. ' unapplied</FONT></B>'.
146 % qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_bill_pay.cgi?!.
148 % qq!', 392, 336, 'cust_bill_pay_popup' ), CAPTION, 'Apply payment', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!.
154 % my $refund_days = $conf->config('card_refund-days') || 120;
155 % if ( $cust_pay->closed !~ /^Y/i
156 % && $cust_pay->payby =~ /^(CARD|CHEK)$/
157 % && time-$cust_pay->_date < $refund_days*86400
158 % && $cust_pay->unrefunded > 0
159 % && $curuser->access_right('Refund payment')
161 % $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
162 % qq!paynum=!. $cust_pay->paynum. '"'.
163 % qq! TITLE="Send a refund for this payment to the payment gateway"!.
168 % if ( $cust_pay->closed !~ /^Y/i
169 % && ( ( $cust_pay->payby eq 'CARD'
170 % && $curuser->access_right('Credit card void')
172 % || ( $cust_pay->payby eq 'CHEK'
173 % && $curuser->access_right('Echeck void')
175 % || ( $cust_pay->payby !~ /^(CARD|CHEK)$/
176 % && $curuser->access_right('Regular void')
181 % $void = qq! (<A HREF="javascript:areyousure('!.
182 % qq!${p}misc/void-cust_pay.cgi?!. $cust_pay->paynum.
183 % qq!', 'Are you sure you want to void this payment?')"!.
184 % qq! TITLE="Void this payment from the database!.
185 % ( $cust_pay->payby =~ /^(CARD|CHEK)$/
186 % ? ' (do not send anything to the payment gateway)'
193 % if ( $cust_pay->closed !~ /^Y/i
194 % && $conf->exists('deletepayments')
195 % && $curuser->access_right('Delete payment')
198 % $delete = qq! (<A HREF="javascript:areyousure('!.
199 % qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
200 % qq!', 'Are you sure you want to delete this payment?')"!.
201 % qq! TITLE="Delete this payment from the database completely - not recommended"!.
206 % if ( $cust_pay->closed !~ /^Y/i
207 % && scalar(@cust_bill_pay)
208 % && $curuser->access_right('Unapply payment')
211 % $unapply = qq! (<A HREF="javascript:areyousure('!.
212 % qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
213 % qq!', 'Are you sure you want to unapply this payment?')"!.
214 % qq! TITLE="Keep this payment, but dissociate it from the invoices it is currently applied against"!.
219 % 'date' => $cust_pay->_date,
220 % 'desc' => $pre. "Payment$post$info$desc".
221 % "$apply$refund$void$delete$unapply",
222 % 'payment' => $cust_pay->paid,
223 % 'target' => $target,
228 %foreach my $cust_pay_void ($cust_main->cust_pay_void) {
230 % my $payby = $cust_pay_void->payby;
231 % my $payinfo = $payby eq 'CARD'
232 % ? $cust_pay_void->paymask
233 % : $cust_pay_void->payinfo;
235 % $payby =~ s/^BILL$/Check #/ if $payinfo;
236 % $payby =~ s/^CHEK$/Electronic check /;
237 % $payby =~ s/^BILL$//;
238 % $payby =~ s/^(CARD|COMP)$/$1 /;
239 % my $info = $payby ? " ($payby$payinfo)" : '';
242 % if ( $cust_pay_void->closed !~ /^Y/i
243 % && $curuser->access_right('Unvoid')
246 % $unvoid = qq! (<A HREF="javascript:areyousure('!.
247 % qq!${p}misc/unvoid-cust_pay_void.cgi?!. $cust_pay_void->paynum.
248 % qq!', 'Are you sure you want to unvoid this payment?')"!.
249 % qq! TITLE="Unvoid this payment from the database!.
250 % ( $cust_pay_void->payby =~ /^(CARD|CHEK)$/
251 % ? ' (do not send anything to the payment gateway)'
258 % 'date' => $cust_pay_void->_date,
259 % 'desc' => "<DEL>Payment $info</DEL> <I>voided ".
260 % time2str("%D", $cust_pay_void->void_date).
261 % " by ". $cust_pay_void->otaker. '</i>'. $unvoid,
262 % 'void_payment' => $cust_pay_void->paid,
267 %#credits (some false laziness w/payments)
268 %foreach my $cust_credit ($cust_main->cust_credit) {
270 % my @cust_credit_bill = $cust_credit->cust_credit_bill;
271 % my @cust_credit_refund = $cust_credit->cust_credit_refund;
273 % my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
274 % if ( scalar(@cust_credit_bill) == 0
275 % && scalar(@cust_credit_refund) == 0 ) {
276 % #completely unapplied
277 % $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
278 % $post = '</FONT></B>';
279 % $apply = qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_credit_bill.cgi?!.
280 % $cust_credit->crednum.
281 % qq!', 392, 336, 'cust_credit_bill_popup' ), CAPTION, 'Apply credit', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!;
282 % } elsif ( scalar(@cust_credit_bill) == 1
283 % && scalar(@cust_credit_refund) == 0
284 % && $cust_credit->credited == 0 ) {
285 % #applied to one invoice, the usual situation
286 % $desc = ' applied to Invoice #'. $cust_credit_bill[0]->invnum;
287 % } elsif ( scalar(@cust_credit_bill) == 0
288 % && scalar(@cust_credit_refund) == 1
289 % && $cust_credit->credited == 0 ) {
290 % #applied to one refund
291 % $desc = ' refunded on '. time2str("%D", $cust_credit_refund[0]->_date);
295 % foreach my $app ( sort { $a->_date <=> $b->_date }
296 % ( @cust_credit_bill, @cust_credit_refund ) ) {
297 % if ( $app->isa('FS::cust_credit_bill') ) {
298 % $desc .= ' '.
300 % ' applied to Invoice #'. $app->invnum.
302 % #' on '. time2str("%D", $app->_date).
303 % } elsif ( $app->isa('FS::cust_credit_refund') ) {
304 % $desc .= ' '.
306 % ' refunded on '. time2str("%D", $app->_date).
309 % die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
312 % if ( $cust_credit->credited > 0 ) {
313 % $desc .= ' <B><FONT COLOR="#FF0000">$'.
314 % $cust_credit->credited. ' unapplied</FONT></B>'.
315 % qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_credit_bill.cgi?!.
316 % $cust_credit->crednum.
317 % qq!', 392, 336, 'cust_credit_bill_popup' ), CAPTION, 'Apply credit', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!.
323 % if ( $cust_credit->closed !~ /^Y/i
325 % #s'pose deleting a credit isn't bad like deleting a payment
326 % # and this needs to be generally available until we have credit voiding..
327 % #&& $conf->exists('deletecredits')
329 % && $curuser->access_right('Delete credit')
332 % $delete = qq! (<A HREF="javascript:areyousure('!.
333 % qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
334 % qq!', 'Are you sure you want to delete this credit?')">!.
339 % if ( $cust_credit->closed !~ /^Y/i
340 % && scalar(@cust_credit_bill)
341 % && $curuser->access_right('Unapply credit')
344 % $unapply = qq! (<A HREF="javascript:areyousure('!.
345 % qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
346 % qq!', 'Are you sure you want to unapply this credit?')">!.
351 % 'date' => $cust_credit->_date,
352 % 'desc' => $pre. "Credit$post by ". $cust_credit->otaker.
353 % ( $cust_credit->reason
354 % ? ' ('. $cust_credit->reason. ')'
357 % "$desc$apply$delete$unapply",
358 % 'credit' => $cust_credit->amount,
364 %foreach my $cust_refund ($cust_main->cust_refund) {
366 % my $payby = $cust_refund->payby;
367 % my $payinfo = $payby eq 'CARD'
368 % ? $cust_refund->paymask
369 % : $cust_refund->payinfo;
371 % $payby =~ s/^BILL$/Check #/ if $payinfo;
372 % $payby =~ s/^CHEK$/Electronic check /;
373 % $payby =~ s/^(CARD|COMP)$/$1 /;
376 % if ( $cust_refund->closed !~ /^Y/i
377 % && $conf->exists('deleterefunds')
378 % && $curuser->access_right('Delete refund')
381 % $delete = qq! (<A HREF="javascript:areyousure('!.
382 % qq!${p}misc/delete-cust_refund.cgi?!. $cust_refund->refundnum.
383 % qq!', 'Are you sure you want to delete this refund?')"!.
384 % qq! TITLE="Delete this refund from the database completely - not recommended"!.
389 % 'date' => $cust_refund->_date,
390 % 'desc' => "Refund ($payby$payinfo) by ". $cust_refund->otaker. "<BR>".
392 % 'refund' => $cust_refund->refund,
400 <% include("/elements/table-grid.html") %>
401 % my $bgcolor1 = '#eeeeee';
402 % my $bgcolor2 = '#ffffff';
408 <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
409 <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
410 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Charge</FONT></TH>
411 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Payment</FONT></TH>
412 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
413 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Refund</FONT></TH>
414 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Balance</FONT></TH>
417 %#display payment history
419 %sub balance_forward_row {
420 % my( $b, $date ) = @_;
421 % my $conf = new FS::Conf;
422 % my $money_char = $conf->config('money_char') || '$';
423 % ( my $balance_forward = $money_char. $b ) =~ s/^\$\-/- \$/;
425 <TR ID="balance_forward_row">
426 <TD CLASS="grid" BGCOLOR="#dddddd">
427 <% time2str("%D",$date) %>
430 <TD CLASS="grid" BGCOLOR="#dddddd">
431 <I>Starting balance on <% time2str("%D",$date) %></I>
432 (<A HREF="javascript:void(0);" onClick="show_history();">show prior history</A>)
435 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
436 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
437 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
438 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
439 <TD CLASS="grid" BGCOLOR="#dddddd"><I><% $balance_forward %></I></TD>
446 %my $money_char = $conf->config('money_char') || '$';
448 %my $years = $conf->config('payment_history-years') || 2;
449 %my $older_than = time - $years * 31556736; #60*60*24*365.24
452 %my $old_history = 0;
455 %foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
457 % $lastdate = $item->{'date'};
460 % if ( $item->{'date'} < $older_than ) {
461 % $display = ' STYLE="display:none" ';
467 % if ( $hidden && ! $seen++ ) {
468 % balance_forward_row($balance, $item->{'date'});
473 % if ( $bgcolor eq $bgcolor1 ) {
474 % $bgcolor = $bgcolor2;
476 % $bgcolor = $bgcolor1;
479 % my $charge = exists($item->{'charge'})
480 % ? sprintf("$money_char\%.2f", $item->{'charge'})
483 % my $payment = exists($item->{'payment'})
484 % ? sprintf("- $money_char\%.2f", $item->{'payment'})
487 % $payment ||= sprintf( "<DEL>- $money_char\%.2f</DEL>",
488 % $item->{'void_payment'}
490 % if exists($item->{'void_payment'});
492 % my $credit = exists($item->{'credit'})
493 % ? sprintf("- $money_char\%.2f", $item->{'credit'})
496 % my $refund = exists($item->{'refund'})
497 % ? sprintf("$money_char\%.2f", $item->{'refund'})
500 % my $target = exists($item->{'target'}) ? $item->{'target'} : '';
502 % $balance += $item->{'charge'} if exists $item->{'charge'};
503 % $balance -= $item->{'payment'} if exists $item->{'payment'};
504 % $balance -= $item->{'credit'} if exists $item->{'credit'};
505 % $balance += $item->{'refund'} if exists $item->{'refund'};
506 % $balance = sprintf("%.2f", $balance);
507 % $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
508 % ( my $showbalance = $money_char. $balance ) =~ s/^\$\-/- \$/;
513 <TR <% $display ? $display.' ID="old_history'.$old_history++.'"' : ''%>>
514 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
515 % unless ( !$target || $target{$target}++ ) {
517 <A NAME="<% $target %>">
520 <% time2str("%D",$item->{'date'}) %>
521 % if ( $target && $target{$target} == 1 ) {
528 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
529 <% $item->{'desc'} %>
531 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
534 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
537 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
540 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
543 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
549 %if ( scalar(@history) && $hidden && ! $seen++ ) {
550 % balance_forward_row($balance, $lastdate);
555 <SCRIPT TYPE="text/javascript">
557 function show_history () {
558 //alert('showing history!');
560 var balance_forward_row = document.getElementById('balance_forward_row');
562 balance_forward_row.style.display = 'none';
563 for ( var i = 0; i < <% $old_history %>; i++ ) {
564 var oldRow = document.getElementById('old_history'+i);
565 oldRow.style.display = '';
574 my( $cust_main ) = @_;
575 my $custnum = $cust_main->custnum;
577 my $conf = new FS::Conf;
579 my $curuser = $FS::CurrentUser::CurrentUser;
581 my @payby = grep /\w/, $conf->config('payby');
582 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
583 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
585 my %payby = map { $_=>1 } @payby;