8 % if ( $payby{'BILL'} && $curuser->access_right(['Post payment', 'Post check payment' ]) ) {
9 <% $s++ ? ' | ' : '' %>
10 <& /elements/popup_link-cust_main.html,
11 'label' => emt('Enter check payment'),
12 'action' => "${p}edit/cust_pay.cgi?popup=1;payby=BILL",
13 'cust_main' => $cust_main,
14 'actionlabel' => emt('Enter check payment'),
19 % if ( $payby{'CASH'} && $curuser->access_right(['Post payment', 'Post cash payment']) ) {
20 <% $s++ ? ' | ' : '' %>
21 <& /elements/popup_link-cust_main.html,
22 'label' => emt('Enter cash payment'),
23 'action' => "${p}edit/cust_pay.cgi?popup=1;payby=CASH",
24 'cust_main' => $cust_main,
25 'actionlabel' => emt('Enter cash payment'),
30 % if ( $payby{'WEST'} && $curuser->access_right('Post payment') ) {
31 <% $s++ ? ' | ' : '' %>
32 <A HREF="<% $p %>edit/cust_pay.cgi?payby=WEST;custnum=<% $custnum %>"><% mt('Enter Western Union payment') |h %></A>
38 % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
39 % && $curuser->access_right(['Process payment', 'Process credit card payment'])
40 % && ! $cust_main->is_encrypted($cust_main->payinfo)
42 <% $s++ ? ' | ' : '' %>
43 <A HREF="<% $p %>misc/payment.cgi?payby=CARD;custnum=<% $custnum %>"><% mt('Process credit card payment') |h %></A>
46 % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
47 % && $curuser->access_right(['Process payment', 'Process Echeck payment'])
48 % && ! $cust_main->is_encrypted($cust_main->payinfo)
50 <% $s++ ? ' | ' : '' %>
51 <A HREF="<% $p %>misc/payment.cgi?payby=CHEK;custnum=<% $custnum %>"><% mt('Process electronic check (ACH) payment') |h %></A>
54 % if ( $payby{'MCRD'} && $curuser->access_right('Post payment') ) {
55 <% $s++ ? ' | ' : '' %>
56 <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCRD;custnum=<% $custnum %>"><% mt('Post manual (offline/POS) credit card payment') |h %></A>
63 % if ( $curuser->access_right('Post credit') ) {
64 <& /elements/popup_link-cust_main.html,
65 'label' => emt('Enter credit'),
66 'action' => "${p}edit/cust_credit.cgi",
67 'cust_main' => $cust_main,
68 'actionlabel' => emt('Enter credit'),
69 'width' => 616, #make room for reasons #540 default
77 % if ( $payby{'BILL'} && $curuser->access_right(['Post refund', 'Post check refund']) ) {
78 <% $s++ ? ' | ' : '' %>
79 <& /elements/popup_link-cust_main.html,
80 'label' => emt('Enter check refund'),
81 'action' => "${p}edit/cust_refund.cgi?popup=1;payby=BILL",
82 'cust_main' => $cust_main,
83 'actionlabel' => emt('Enter check refund'),
88 % if ( $payby{'CASH'} && $curuser->access_right(['Post refund', 'Post cash refund']) ) {
89 <% $s++ ? ' | ' : '' %>
90 <& /elements/popup_link-cust_main.html,
91 'label' => emt('Enter cash refund'),
92 'action' => "${p}edit/cust_refund.cgi?popup=1;payby=CASH",
93 'cust_main' => $cust_main,
94 'actionlabel' => emt('Enter cash refund'),
99 %# someday, perhaps. very few gateways let you do unlinked refunds at all.
100 %# Authorize.net makes you sign a special form
102 %# % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
103 %# % && $curuser->access_right('Process refund')
104 %# % && ! $cust_main->is_encrypted($cust_main->payinfo)
106 %# <% $s++ ? ' | ' : '' %>
107 %# <A HREF="<% $p %>misc/refund.cgi?payby=CARD;custnum=<% $custnum %>">Process credit card refund</A>
110 %# % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
111 %# % && $curuser->access_right('Process refund')
112 %# % && ! $cust_main->is_encrypted($cust_main->payinfo)
114 %# <% $s++ ? ' | ' : '' %>
115 %# <A HREF="<% $p %>misc/refund.cgi?payby=CHEK;custnum=<% $custnum %>">Process electronic check (ACH) refund</A>
118 % if ( $payby{'MCRD'} && $curuser->access_right('Post refund') ) {
119 <% $s++ ? ' | ' : '' %>
120 <A HREF="<% $p %>edit/cust_refund.cgi?payby=MCRD;custnum=<% $custnum %>"><% mt('Post manual (offline/POS) credit card refund') |h %></A>
124 <TD ALIGN="right" VALIGN="top">
127 % if ( $curuser->access_right('List invoices') ) {
128 <A HREF="<% $p %>search/report_cust_bill.html?custnum=<% $custnum %>"><% mt('Invoice reports') |h %></A>
132 %# XXX payments, credits, refund reports
134 %# tax exemption link
136 % my $view_exemptions = $curuser->access_right('View customer tax exemptions');
137 % my $add_adjustment = ( $conf->exists('enable_tax_adjustments')
138 % && $curuser->access_right('Add customer tax adjustment')
140 % if ( $view_exemptions || $add_adjustment ) {
142 % if ( $view_exemptions ) {
143 <A HREF="<% $p %>search/cust_tax_exempt_pkg.cgi?custnum=<% $custnum %>"><% mt('View tax exemptions') |h %></A>
144 <% $add_adjustment ? '|' : '' %>
147 % if ( $add_adjustment ) {
148 <& /elements/popup_link.html, {
149 'action' => $p.'edit/cust_tax_adjustment.html?custnum='. $cust_main->custnum,
150 'label' => emt('Add tax adjustment'),
151 'actionlabel' => emt('Add tax adjustment'),
156 <A HREF="<% $p %>search/cust_tax_adjustment.html?custnum=<% $custnum %>"><% mt('View tax adjustments') |h %></A>
162 %# batched payment links
164 % if ( ( $conf->exists('batch-enable') || $conf->config('batch-enable_payby') )
165 % && $curuser->access_right('View customer batched payments')
168 <% mt('View batched payments:') |h %>
169 % foreach my $status (qw( Queued In-transit Complete All )) {
170 <A HREF="<% $p %>search/cust_pay_batch.cgi?status=<% $status{$status} %>;custnum=<% $custnum %>"><% mt($status) |h %></A>
171 <% $status ne 'All' ? '|' : '' %>
176 %# pending payment links
178 % if ( $curuser->access_right('View customer pending payments')
179 % && scalar($cust_main->cust_pay_pending)
182 <A HREF="<% $p %>search/cust_pay_pending.html?magic=_date;statusNOT=done;custnum=<% $custnum %>"><% mt('View pending payments') |h %></A><BR>
192 <& /elements/table-grid.html &>
193 % my $bgcolor1 = '#eeeeee';
194 % my $bgcolor2 = '#ffffff';
198 <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Date') |h %></TH>
199 <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Description') |h %></TH>
200 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Invoice') |h %></FONT></TH>
201 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Payment') |h %></FONT></TH>
202 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('In-house Credit') |h %></FONT></TH>
203 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Refund') |h %></FONT></TH>
204 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Balance') |h %></FONT></TH>
207 %#display payment history
209 %my $money_char = $conf->config('money_char') || '$';
211 %sub balance_forward_row {
212 % my( $b, $date, $money_char ) = @_;
213 % ( my $balance_forward = $money_char. $b ) =~ s/^\$\-/- \$/;
215 <TR ID="balance_forward_row">
216 <TD CLASS="grid" BGCOLOR="#dddddd">
217 <% time2str($date_format, $date) %>
220 <TD CLASS="grid" BGCOLOR="#dddddd">
221 <I><% mt("Starting balance on [_1]", time2str($date_format, $date) ) |h %></I>
222 (<A HREF="javascript:void(0);" onClick="show_history();"><% mt('show prior history') |h %></A>)
225 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
226 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
227 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
228 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
229 <TD CLASS="grid" BGCOLOR="#dddddd" ALIGN="right"><I><% $balance_forward %></I></TD>
237 %my $years = $conf->config('payment_history-years') || 2;
238 %my $older_than = time - $years * 31556926; #60*60*24*365.2422
241 %my $old_history = 0;
244 %foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
246 % $lastdate = $item->{'date'};
249 % if ( $item->{'date'} < $older_than ) {
250 % $display = ' STYLE="display:none" ';
256 % if ( $hidden && ! $seen++ ) {
257 % balance_forward_row($balance, $item->{'date'}, $money_char);
262 % if ( $bgcolor eq $bgcolor1 ) {
263 % $bgcolor = $bgcolor2;
265 % $bgcolor = $bgcolor1;
268 % my $charge = exists($item->{'charge'})
269 % ? sprintf("$money_char\%.2f", $item->{'charge'})
270 % : exists($item->{'charge_nobal'})
271 % ? sprintf("$money_char\%.2f", $item->{'charge_nobal'})
274 % my $payment = exists($item->{'payment'})
275 % ? sprintf("- $money_char\%.2f", $item->{'payment'})
278 % $payment ||= sprintf( "<DEL>- $money_char\%.2f</DEL>",
279 % $item->{'void_payment'}
281 % if exists($item->{'void_payment'});
283 % my $credit = exists($item->{'credit'})
284 % ? sprintf("- $money_char\%.2f", $item->{'credit'})
287 % my $refund = exists($item->{'refund'})
288 % ? sprintf("$money_char\%.2f", $item->{'refund'})
291 % my $target = exists($item->{'target'}) ? $item->{'target'} : '';
293 % $balance += $item->{'charge'} if exists $item->{'charge'};
294 % $balance -= $item->{'payment'} if exists $item->{'payment'};
295 % $balance -= $item->{'credit'} if exists $item->{'credit'};
296 % $balance += $item->{'refund'} if exists $item->{'refund'};
297 % $balance = sprintf("%.2f", $balance);
298 % $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
299 % ( my $showbalance = $money_char. $balance ) =~ s/^\$\-/- \$/;
304 <TR <% $display ? $display.' ID="old_history'.$old_history++.'"' : ''%>>
305 <TD VALIGN="top" CLASS="grid" BGCOLOR="<% $bgcolor %>">
306 % unless ( !$target || $target{$target}++ ) {
308 <A NAME="<% $target %>">
311 <% time2str($date_format, $item->{'date'}) %>
312 % if ( $target && $target{$target} == 1 ) {
319 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
320 <% $item->{'desc'} %>
322 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
325 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
328 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
331 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
334 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
340 %if ( scalar(@history) && $hidden && ! $seen++ ) {
341 % balance_forward_row($balance, $lastdate, $money_char);
349 <SCRIPT TYPE="text/javascript">
351 function show_history () {
352 //alert('showing history!');
354 var balance_forward_row = document.getElementById('balance_forward_row');
356 balance_forward_row.style.display = 'none';
357 for ( var i = 0; i < <% $old_history %>; i++ ) {
358 var oldRow = document.getElementById('old_history'+i);
359 oldRow.style.display = '';
368 my( $cust_main ) = @_;
369 my $custnum = $cust_main->custnum;
371 my $conf = new FS::Conf;
372 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
374 my $curuser = $FS::CurrentUser::CurrentUser;
376 my @payby = grep /\w/, $conf->config('payby');
377 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
378 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
380 my %payby = map { $_=>1 } @payby;
383 'Queued' => 'O', #Open
385 'Complete' => 'R', #Resolved
393 ( map { $_ => scalar($conf->config($_)) }
394 qw( card_refund-days date_format )
396 ( map { $_ => $conf->exists($_) }
397 qw( deleteinvoices deletepayments deleterefunds pkg-balances )
401 $opt{'date_format'} ||= '%m/%d/%Y';
404 foreach my $legacy_cust_bill ($cust_main->legacy_cust_bill) {
406 'date' => $legacy_cust_bill->_date,
407 'desc' => include('payment_history/legacy_invoice.html', $legacy_cust_bill, %opt ),
408 'charge_nobal' => $legacy_cust_bill->charged,
413 foreach my $cust_bill ($cust_main->cust_bill) {
415 'date' => $cust_bill->_date,
416 'desc' => include('payment_history/invoice.html', $cust_bill, %opt ),
417 'charge' => $cust_bill->charged,
422 foreach my $cust_statement ($cust_main->cust_statement) {
424 'date' => $cust_statement->_date,
425 'desc' => include('payment_history/statement.html', $cust_statement, %opt ),
426 #'charge' => $cust_bill->charged,
430 #payments (some false laziness w/credits)
431 foreach my $cust_pay ($cust_main->cust_pay) {
433 'date' => $cust_pay->_date,
434 'desc' => include('payment_history/payment.html', $cust_pay, %opt ),
435 'payment' => $cust_pay->paid,
436 #'target' => $target, #XXX
441 foreach my $cust_pay_pending ($cust_main->cust_pay_pending) {
443 'date' => $cust_pay_pending->_date,
444 'desc' => include('payment_history/pending_payment.html', $cust_pay_pending, %opt ),
445 'void_payment' => $cust_pay_pending->paid,
451 foreach my $cust_pay_void ($cust_main->cust_pay_void) {
453 'date' => $cust_pay_void->_date,
454 'desc' => include('payment_history/voided_payment.html', $cust_pay_void, %opt ),
455 'void_payment' => $cust_pay_void->paid,
461 foreach my $cust_pay_pending ($cust_main->cust_pay_pending_attempt) {
463 'date' => $cust_pay_pending->_date,
464 'desc' => include('payment_history/attempted_payment.html', $cust_pay_pending, %opt ),
465 'void_payment' => $cust_pay_pending->paid, #??
466 #'target' => $target, #XXX
470 #credits (some false laziness w/payments)
471 foreach my $cust_credit ($cust_main->cust_credit) {
473 'date' => $cust_credit->_date,
474 'desc' => include('payment_history/credit.html', $cust_credit, %opt ),
475 'credit' => $cust_credit->amount,
481 foreach my $cust_refund ($cust_main->cust_refund) {
483 'date' => $cust_refund->_date,
484 'desc' => include('payment_history/refund.html', $cust_refund),
485 'refund' => $cust_refund->refund,
490 sub translate_payby {
491 my ($payby,$payinfo) = (shift,shift);
493 BILL => $payinfo ? emt('Check #') : '',
494 CHEK => emt('Electronic check '),
495 PREP => emt('Prepaid card '),
496 CARD => emt('Credit card #'),
497 COMP => emt('Complimentary by '),
499 WEST => emt('Western Union'),
500 MCRD => emt('Manual credit card'),
502 $payby = (exists $payby{$payby}) ? $payby{$payby} : $payby;
506 sub translate_payby_refund {
507 my ($payby,$payinfo) = (shift,shift);
509 BILL => $payinfo ? emt('Check #') : emt('Check'),
510 CHEK => emt('Electronic check '),
511 CARD => emt('Credit card #'),
512 COMP => emt('Complimentary by '),
514 $payby = (exists $payby{$payby}) ? $payby{$payby} : $payby;
518 sub translate_payinfo {
520 my $payby = $object->payby;
521 my $payinfo = $object->payinfo;
523 my $conf = new FS::Conf;
525 if ( $payby eq 'CARD' ) {
526 $payinfo = $object->paymask;
527 } elsif ( $payby eq 'CHEK' ) {
528 my( $account, $aba ) = split('@', $object->paymask );
529 $payinfo = emt("ABA [_1], Acct #[_2]",$aba,$account);
535 sub areyousure_link {
536 my ($url,$msg,$title,$label) = (shift,shift,shift,shift);
537 ' (<A HREF="javascript:areyousure(\''.$url.'\',\''.$msg.'\')" TITLE="'.$title.'">'.$label.'</A>)';