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')
22 <% $s++ ? ' | ' : '' %>
23 <A HREF="<% $p %>misc/payment.cgi?payby=CARD;custnum=<% $custnum %>">Process credit card payment</A>
26 % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
27 % && $curuser->access_right('Process payment')
29 <% $s++ ? ' | ' : '' %>
30 <A HREF="<% $p %>misc/payment.cgi?payby=CHEK;custnum=<% $custnum %>">Process electronic check (ACH) payment</A>
33 % if ( $payby{'MCRD'} && $curuser->access_right('Post payment') ) {
34 <% $s++ ? ' | ' : '' %>
35 <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCRD;custnum=<% $custnum %>">Post manual (offline) credit card payment</A>
40 % if ( $curuser->access_right('Post credit') ) {
41 <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>
45 % if ( $curuser->access_right('View customer tax exemptions') ) {
46 <A HREF="<% $p %>search/cust_tax_exempt_pkg.cgi?custnum=<% $custnum %>">View tax exemptions</A>
54 %foreach my $cust_bill ($cust_main->cust_bill) {
55 % my $pre = ( $cust_bill->owed > 0 )
56 % ? '<B><FONT SIZE="+1" COLOR="#FF0000">Open '
58 % my $post = ( $cust_bill->owed > 0 ) ? '</FONT></B>' : '';
59 % my $invnum = $cust_bill->invnum;
60 % my $link = $curuser->access_right('View invoices')
61 % ? qq!<A HREF="${p}view/cust_bill.cgi?$invnum">!
64 % 'date' => $cust_bill->_date,
65 % 'desc' => $link. $pre.
66 % "Invoice #$invnum (Balance \$". $cust_bill->owed. ')'.
67 % $post. ( $link ? '</A>' : '' ),
68 % 'charge' => $cust_bill->charged,
72 %#payments (some false laziness w/credits)
73 %foreach my $cust_pay ($cust_main->cust_pay) {
75 % my $payby = $cust_pay->payby;
78 % if ( $payby eq 'CARD' ) {
79 % $payinfo = $cust_pay->payinfo_masked;
80 % } elsif ( $payby eq 'CHEK' && $cust_pay->payinfo =~ /^(\d+)\@(\d+)$/ ) {
81 % $payinfo = "ABA $2, Acct# $1";
83 % $payinfo = $cust_pay->payinfo;
85 % my @cust_bill_pay = $cust_pay->cust_bill_pay;
86 % my @cust_pay_refund = $cust_pay->cust_pay_refund;
88 % my $target = "$payby$payinfo";
89 % $payby =~ s/^BILL$/Check #/ if $payinfo;
90 % $payby =~ s/^CHEK$/Electronic check /;
91 % $payby =~ s/^PREP$/Prepaid card /;
92 % $payby =~ s/^CARD$/Credit card #/;
93 % $payby =~ s/^COMP$/Complimentary by /;
94 % $payby =~ s/^CASH$/Cash/;
95 % $payby =~ s/^WEST$/Western Union/;
96 % $payby =~ s/^MCRD$/Manual credit card/;
97 % $payby =~ s/^BILL$//;
98 % my $info = $payby ? " ($payby$payinfo)" : '';
100 % my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
101 % if ( scalar(@cust_bill_pay) == 0
102 % && scalar(@cust_pay_refund) == 0 ) {
103 % #completely unapplied
104 % $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
105 % $post = '</FONT></B>';
106 % $apply = qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_bill_pay.cgi?!.
108 % qq!', 392, 336, 'cust_bill_pay_popup' ), CAPTION, 'Apply payment', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!;
110 % } elsif ( scalar(@cust_bill_pay) == 1
111 % && scalar(@cust_pay_refund) == 0
112 % && $cust_pay->unapplied == 0 ) {
113 % #applied to one invoice, the usual situation
114 % $desc = ' applied to Invoice #'. $cust_bill_pay[0]->invnum;
115 % } elsif ( scalar(@cust_bill_pay) == 0
116 % && scalar(@cust_pay_refund) == 1
117 % && $cust_pay->unapplied == 0 ) {
118 % #applied to one refund
119 % $desc = ' refunded on '. time2str("%D", $cust_pay_refund[0]->_date);
123 % foreach my $app ( sort { $a->_date <=> $b->_date }
124 % ( @cust_bill_pay, @cust_pay_refund ) ) {
125 % if ( $app->isa('FS::cust_bill_pay') ) {
126 % $desc .= ' '.
128 % ' applied to Invoice #'. $app->invnum.
130 % #' on '. time2str("%D", $cust_bill_pay->_date).
131 % } elsif ( $app->isa('FS::cust_pay_refund') ) {
132 % $desc .= ' '.
134 % ' refunded on '. time2str("%D", $app->_date).
137 % die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
140 % if ( $cust_pay->unapplied > 0 ) {
141 % $desc .= ' '.
142 % '<B><FONT COLOR="#FF0000">$'.
143 % $cust_pay->unapplied. ' unapplied</FONT></B>'.
144 % qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_bill_pay.cgi?!.
146 % qq!', 392, 336, 'cust_bill_pay_popup' ), CAPTION, 'Apply payment', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!.
152 % my $refund_days = $conf->config('card_refund-days') || 120;
153 % if ( $cust_pay->closed !~ /^Y/i
154 % && $cust_pay->payby =~ /^(CARD|CHEK)$/
155 % && time-$cust_pay->_date < $refund_days*86400
156 % && $cust_pay->unrefunded > 0
157 % && $curuser->access_right('Refund payment')
159 % $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
160 % qq!paynum=!. $cust_pay->paynum. '"'.
161 % qq! TITLE="Send a refund for this payment to the payment gateway"!.
166 % if ( $cust_pay->closed !~ /^Y/i
167 % && ( ( $cust_pay->payby eq 'CARD'
168 % && $curuser->access_right('Credit card void')
170 % || ( $cust_pay->payby eq 'CHEK'
171 % && $curuser->access_right('Echeck void')
173 % || ( $cust_pay->payby !~ /^(CARD|CHEK)$/
174 % && $curuser->access_right('Regular void')
179 % $void = qq! (<A HREF="javascript:areyousure('!.
180 % qq!${p}misc/void-cust_pay.cgi?!. $cust_pay->paynum.
181 % qq!', 'Are you sure you want to void this payment?')"!.
182 % qq! TITLE="Void this payment from the database!.
183 % ( $cust_pay->payby =~ /^(CARD|CHEK)$/
184 % ? ' (do not send anything to the payment gateway)'
191 % if ( $cust_pay->closed !~ /^Y/i
192 % && $conf->exists('deletepayments')
193 % && $curuser->access_right('Delete payment')
196 % $delete = qq! (<A HREF="javascript:areyousure('!.
197 % qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
198 % qq!', 'Are you sure you want to delete this payment?')"!.
199 % qq! TITLE="Delete this payment from the database completely - not recommended"!.
204 % if ( $cust_pay->closed !~ /^Y/i
205 % && scalar(@cust_bill_pay)
206 % && $curuser->access_right('Unapply payment')
209 % $unapply = qq! (<A HREF="javascript:areyousure('!.
210 % qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
211 % qq!', 'Are you sure you want to unapply this payment?')"!.
212 % qq! TITLE="Keep this payment, but dissociate it from the invoices it is currently applied against"!.
217 % 'date' => $cust_pay->_date,
218 % 'desc' => $pre. "Payment$post$info$desc".
219 % "$apply$refund$void$delete$unapply",
220 % 'payment' => $cust_pay->paid,
221 % 'target' => $target,
226 %foreach my $cust_pay_void ($cust_main->cust_pay_void) {
228 % my $payby = $cust_pay_void->payby;
229 % my $payinfo = $payby eq 'CARD'
230 % ? $cust_pay_void->payinfo_masked
231 % : $cust_pay_void->payinfo;
233 % $payby =~ s/^BILL$/Check #/ if $payinfo;
234 % $payby =~ s/^CHEK$/Electronic check /;
235 % $payby =~ s/^BILL$//;
236 % $payby =~ s/^(CARD|COMP)$/$1 /;
237 % my $info = $payby ? " ($payby$payinfo)" : '';
240 % if ( $cust_pay_void->closed !~ /^Y/i
241 % && $curuser->access_right('Unvoid')
244 % $unvoid = qq! (<A HREF="javascript:areyousure('!.
245 % qq!${p}misc/unvoid-cust_pay_void.cgi?!. $cust_pay_void->paynum.
246 % qq!', 'Are you sure you want to unvoid this payment?')"!.
247 % qq! TITLE="Unvoid this payment from the database!.
248 % ( $cust_pay_void->payby =~ /^(CARD|CHEK)$/
249 % ? ' (do not send anything to the payment gateway)'
256 % 'date' => $cust_pay_void->_date,
257 % 'desc' => "<DEL>Payment $info</DEL> <I>voided ".
258 % time2str("%D", $cust_pay_void->void_date).
259 % " by ". $cust_pay_void->otaker. '</i>'. $unvoid,
260 % 'void_payment' => $cust_pay_void->paid,
265 %#credits (some false laziness w/payments)
266 %foreach my $cust_credit ($cust_main->cust_credit) {
268 % my @cust_credit_bill = $cust_credit->cust_credit_bill;
269 % my @cust_credit_refund = $cust_credit->cust_credit_refund;
271 % my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
272 % if ( scalar(@cust_credit_bill) == 0
273 % && scalar(@cust_credit_refund) == 0 ) {
274 % #completely unapplied
275 % $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
276 % $post = '</FONT></B>';
277 % $apply = qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_credit_bill.cgi?!.
278 % $cust_credit->crednum.
279 % qq!', 392, 336, 'cust_credit_bill_popup' ), CAPTION, 'Apply credit', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!;
280 % } elsif ( scalar(@cust_credit_bill) == 1
281 % && scalar(@cust_credit_refund) == 0
282 % && $cust_credit->credited == 0 ) {
283 % #applied to one invoice, the usual situation
284 % $desc = ' applied to Invoice #'. $cust_credit_bill[0]->invnum;
285 % } elsif ( scalar(@cust_credit_bill) == 0
286 % && scalar(@cust_credit_refund) == 1
287 % && $cust_credit->credited == 0 ) {
288 % #applied to one refund
289 % $desc = ' refunded on '. time2str("%D", $cust_credit_refund[0]->_date);
293 % foreach my $app ( sort { $a->_date <=> $b->_date }
294 % ( @cust_credit_bill, @cust_credit_refund ) ) {
295 % if ( $app->isa('FS::cust_credit_bill') ) {
296 % $desc .= ' '.
298 % ' applied to Invoice #'. $app->invnum.
300 % #' on '. time2str("%D", $app->_date).
301 % } elsif ( $app->isa('FS::cust_credit_refund') ) {
302 % $desc .= ' '.
304 % ' refunded on '. time2str("%D", $app->_date).
307 % die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
310 % if ( $cust_credit->credited > 0 ) {
311 % $desc .= ' <B><FONT COLOR="#FF0000">$'.
312 % $cust_credit->credited. ' unapplied</FONT></B>'.
313 % qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_credit_bill.cgi?!.
314 % $cust_credit->crednum.
315 % qq!', 392, 336, 'cust_credit_bill_popup' ), CAPTION, 'Apply credit', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!.
321 % if ( $cust_credit->closed !~ /^Y/i
323 % #s'pose deleting a credit isn't bad like deleting a payment
324 % # and this needs to be generally available until we have credit voiding..
325 % #&& $conf->exists('deletecredits')
327 % && $curuser->access_right('Delete credit')
330 % $delete = qq! (<A HREF="javascript:areyousure('!.
331 % qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
332 % qq!', 'Are you sure you want to delete this credit?')">!.
337 % if ( $cust_credit->closed !~ /^Y/i
338 % && scalar(@cust_credit_bill)
339 % && $curuser->access_right('Unapply credit')
342 % $unapply = qq! (<A HREF="javascript:areyousure('!.
343 % qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
344 % qq!', 'Are you sure you want to unapply this credit?')">!.
349 % 'date' => $cust_credit->_date,
350 % 'desc' => $pre. "Credit$post by ". $cust_credit->otaker.
351 % ( $cust_credit->reason
352 % ? ' ('. $cust_credit->reason. ')'
355 % "$desc$apply$delete$unapply",
356 % 'credit' => $cust_credit->amount,
362 %foreach my $cust_refund ($cust_main->cust_refund) {
364 % my $payby = $cust_refund->payby;
365 % my $payinfo = $payby eq 'CARD'
366 % ? $cust_refund->payinfo_masked
367 % : $cust_refund->payinfo;
369 % $payby =~ s/^BILL$/Check #/ if $payinfo;
370 % $payby =~ s/^CHEK$/Electronic check /;
371 % $payby =~ s/^(CARD|COMP)$/$1 /;
374 % 'date' => $cust_refund->_date,
375 % 'desc' => "Refund ($payby$payinfo) by ". $cust_refund->otaker,
376 % 'refund' => $cust_refund->refund,
384 <% include("/elements/table-grid.html") %>
385 % my $bgcolor1 = '#eeeeee';
386 % my $bgcolor2 = '#ffffff';
392 <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
393 <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
394 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Charge</FONT></TH>
395 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Payment</FONT></TH>
396 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
397 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Refund</FONT></TH>
398 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Balance</FONT></TH>
401 %#display payment history
403 %sub balance_forward_row {
404 % my( $b, $date ) = @_;
405 % my $conf = new FS::Conf;
406 % my $money_char = $conf->config('money_char') || '$';
407 % ( my $balance_forward = $money_char. $b ) =~ s/^\$\-/- \$/;
409 <TR ID="balance_forward_row">
410 <TD CLASS="grid" BGCOLOR="#dddddd">
411 <% time2str("%D",$date) %>
414 <TD CLASS="grid" BGCOLOR="#dddddd">
415 <I>Starting balance on <% time2str("%D",$date) %></I>
416 (<A HREF="javascript:void(0);" onClick="show_history();">show prior history</A>)
419 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
420 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
421 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
422 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
423 <TD CLASS="grid" BGCOLOR="#dddddd"><I><% $balance_forward %></I></TD>
430 %my $money_char = $conf->config('money_char') || '$';
432 %my $years = $conf->config('payment_history-years') || 2;
433 %my $older_than = time - $years * 31556736; #60*60*24*365.24
436 %my $old_history = 0;
439 %foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
441 % $lastdate = $item->{'date'};
444 % if ( $item->{'date'} < $older_than ) {
445 % $display = ' STYLE="display:none" ';
451 % if ( $hidden && ! $seen++ ) {
452 % balance_forward_row($balance, $item->{'date'});
457 % if ( $bgcolor eq $bgcolor1 ) {
458 % $bgcolor = $bgcolor2;
460 % $bgcolor = $bgcolor1;
463 % my $charge = exists($item->{'charge'})
464 % ? sprintf("$money_char\%.2f", $item->{'charge'})
467 % my $payment = exists($item->{'payment'})
468 % ? sprintf("- $money_char\%.2f", $item->{'payment'})
471 % $payment ||= sprintf( "<DEL>- $money_char\%.2f</DEL>",
472 % $item->{'void_payment'}
474 % if exists($item->{'void_payment'});
476 % my $credit = exists($item->{'credit'})
477 % ? sprintf("- $money_char\%.2f", $item->{'credit'})
480 % my $refund = exists($item->{'refund'})
481 % ? sprintf("$money_char\%.2f", $item->{'refund'})
484 % my $target = exists($item->{'target'}) ? $item->{'target'} : '';
486 % $balance += $item->{'charge'} if exists $item->{'charge'};
487 % $balance -= $item->{'payment'} if exists $item->{'payment'};
488 % $balance -= $item->{'credit'} if exists $item->{'credit'};
489 % $balance += $item->{'refund'} if exists $item->{'refund'};
490 % $balance = sprintf("%.2f", $balance);
491 % $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
492 % ( my $showbalance = $money_char. $balance ) =~ s/^\$\-/- \$/;
497 <TR <% $display ? $display.' ID="old_history'.$old_history++.'"' : ''%>>
498 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
499 % unless ( !$target || $target{$target}++ ) {
501 <A NAME="<% $target %>">
504 <% time2str("%D",$item->{'date'}) %>
505 % if ( $target && $target{$target} == 1 ) {
512 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
513 <% $item->{'desc'} %>
515 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
518 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
521 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
524 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
527 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
533 %if ( scalar(@history) && $hidden && ! $seen++ ) {
534 % balance_forward_row($balance, $lastdate);
539 <SCRIPT TYPE="text/javascript">
541 function show_history () {
542 //alert('showing history!');
544 var balance_forward_row = document.getElementById('balance_forward_row');
546 balance_forward_row.style.display = 'none';
547 for ( var i = 0; i < <% $old_history %>; i++ ) {
548 var oldRow = document.getElementById('old_history'+i);
549 oldRow.style.display = '';
558 my( $cust_main ) = @_;
559 my $custnum = $cust_main->custnum;
561 my $conf = new FS::Conf;
563 my $curuser = $FS::CurrentUser::CurrentUser;
565 my @payby = grep /\w/, $conf->config('payby');
566 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
567 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
569 my %payby = map { $_=>1 } @payby;