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'),
20 % if ( $payby{'CASH'} && $curuser->access_right(['Post payment', 'Post cash payment']) ) {
21 <% $s++ ? ' | ' : '' %>
22 <& /elements/popup_link-cust_main.html,
23 'label' => emt('Enter cash payment'),
24 'action' => "${p}edit/cust_pay.cgi?popup=1;payby=CASH",
25 'cust_main' => $cust_main,
26 'actionlabel' => emt('Enter cash payment'),
32 % if ( $payby{'WEST'} && $curuser->access_right('Post payment') ) {
33 <% $s++ ? ' | ' : '' %>
34 <A HREF="<% $p %>edit/cust_pay.cgi?payby=WEST;custnum=<% $custnum %>"><% mt('Enter Western Union payment') |h %></A>
40 % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
41 % && $curuser->access_right(['Process payment', 'Process credit card payment'])
42 % && ! $cust_main->is_encrypted($cust_main->payinfo)
44 <% $s++ ? ' | ' : '' %>
45 <A HREF="<% $p %>misc/payment.cgi?payby=CARD;custnum=<% $custnum %>"><% mt('Process credit card payment') |h %></A>
48 % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
49 % && $curuser->access_right(['Process payment', 'Process Echeck payment'])
50 % && ! $cust_main->is_encrypted($cust_main->payinfo)
52 <% $s++ ? ' | ' : '' %>
53 <A HREF="<% $p %>misc/payment.cgi?payby=CHEK;custnum=<% $custnum %>"><% mt('Process electronic check (ACH) payment') |h %></A>
56 % if ( $payby{'MCRD'} && $curuser->access_right('Post payment') ) {
57 <% $s++ ? ' | ' : '' %>
58 <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCRD;custnum=<% $custnum %>"><% mt('Post manual (offline/POS) credit card payment') |h %></A>
65 % if ( $curuser->access_right('Post credit') ) {
66 <& /elements/popup_link-cust_main.html,
67 'label' => emt('Enter credit'),
68 'action' => "${p}edit/cust_credit.cgi",
69 'cust_main' => $cust_main,
70 'actionlabel' => emt('Enter credit'),
71 'width' => 616, #make room for reasons #540 default
79 % if ( $payby{'BILL'} && $curuser->access_right(['Post refund', 'Post check refund']) ) {
80 <% $s++ ? ' | ' : '' %>
81 <& /elements/popup_link-cust_main.html,
82 'label' => emt('Enter check refund'),
83 'action' => "${p}edit/cust_refund.cgi?popup=1;payby=BILL",
84 'cust_main' => $cust_main,
85 'actionlabel' => emt('Enter check refund'),
90 % if ( $payby{'CASH'} && $curuser->access_right(['Post refund', 'Post cash refund']) ) {
91 <% $s++ ? ' | ' : '' %>
92 <& /elements/popup_link-cust_main.html,
93 'label' => emt('Enter cash refund'),
94 'action' => "${p}edit/cust_refund.cgi?popup=1;payby=CASH",
95 'cust_main' => $cust_main,
96 'actionlabel' => emt('Enter cash refund'),
101 %# someday, perhaps. very few gateways let you do unlinked refunds at all.
102 %# Authorize.net makes you sign a special form
104 %# % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
105 %# % && $curuser->access_right('Process refund')
106 %# % && ! $cust_main->is_encrypted($cust_main->payinfo)
108 %# <% $s++ ? ' | ' : '' %>
109 %# <A HREF="<% $p %>misc/refund.cgi?payby=CARD;custnum=<% $custnum %>">Process credit card refund</A>
112 %# % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
113 %# % && $curuser->access_right('Process refund')
114 %# % && ! $cust_main->is_encrypted($cust_main->payinfo)
116 %# <% $s++ ? ' | ' : '' %>
117 %# <A HREF="<% $p %>misc/refund.cgi?payby=CHEK;custnum=<% $custnum %>">Process electronic check (ACH) refund</A>
120 % if ( $payby{'MCRD'} && $curuser->access_right('Post refund') ) {
121 <% $s++ ? ' | ' : '' %>
122 <A HREF="<% $p %>edit/cust_refund.cgi?payby=MCRD;custnum=<% $custnum %>"><% mt('Post manual (offline/POS) credit card refund') |h %></A>
126 <TD ALIGN="right" VALIGN="top">
128 %# invoice reports, combined statement
129 % if ( $curuser->access_right('List invoices') ) {
130 % if ( $conf->exists('cust_main-print_statement_link')
131 % and $num_cust_bill > 0 ) {
132 <A HREF="<% $p %>view/cust_main_statement-pdf.cgi?<% $custnum %>"><%
133 mt('Print a current statement') |h %></A>
136 <A HREF="<% $p %>search/report_cust_bill.html?custnum=<% $custnum %>"><% mt('Invoice reports') |h %></A>
140 %# XXX payments, credits, refund reports
142 %# tax exemption link
144 % my $view_exemptions = $curuser->access_right('View customer tax exemptions');
145 % my $add_adjustment = ( $conf->exists('enable_tax_adjustments')
146 % && $curuser->access_right('Add customer tax adjustment')
148 % if ( $view_exemptions || $add_adjustment ) {
150 % if ( $view_exemptions ) {
151 <A HREF="<% $p %>search/cust_tax_exempt_pkg.cgi?custnum=<% $custnum %>"><% mt('View tax exemptions') |h %></A>
152 <% $add_adjustment ? '|' : '' %>
155 % if ( $add_adjustment ) {
156 <& /elements/popup_link.html, {
157 'action' => $p.'edit/cust_tax_adjustment.html?custnum='. $cust_main->custnum,
158 'label' => emt('Add tax adjustment'),
159 'actionlabel' => emt('Add tax adjustment'),
164 <A HREF="<% $p %>search/cust_tax_adjustment.html?custnum=<% $custnum %>"><% mt('View tax adjustments') |h %></A>
170 %# batched payment links
172 % if ( ( $conf->exists('batch-enable') || $conf->config('batch-enable_payby') )
173 % && $curuser->access_right('View customer batched payments')
176 <% mt('View batched payments:') |h %>
177 % foreach my $status (qw( Queued In-transit Complete All )) {
178 <A HREF="<% $p %>search/cust_pay_batch.cgi?status=<% $status{$status} %>;custnum=<% $custnum %>"><% mt($status) |h %></A>
179 <% $status ne 'All' ? '|' : '' %>
184 %# pending payment links
186 % if ( $curuser->access_right('View customer pending payments')
187 % && scalar($cust_main->cust_pay_pending)
190 <A HREF="<% $p %>search/cust_pay_pending.html?magic=_date;statusNOT=done;custnum=<% $custnum %>"><% mt('View pending payments') |h %></A><BR>
200 <& /elements/table-grid.html &>
201 % my $bgcolor1 = '#eeeeee';
202 % my $bgcolor2 = '#ffffff';
206 <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Date') |h %></TH>
207 <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Description') |h %></TH>
208 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Invoice') |h %></FONT></TH>
209 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Payment') |h %></FONT></TH>
210 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('In-house Credit') |h %></FONT></TH>
211 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Refund') |h %></FONT></TH>
212 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Balance') |h %></FONT></TH>
215 %#display payment history
217 %my $money_char = $conf->config('money_char') || '$';
219 %sub balance_forward_row {
220 % my( $b, $date, $money_char ) = @_;
221 % ( my $balance_forward = $money_char. $b ) =~ s/^\$\-/- \$/;
223 <TR ID="balance_forward_row">
224 <TD CLASS="grid" BGCOLOR="#dddddd">
225 <% time2str($date_format, $date) %>
228 <TD CLASS="grid" BGCOLOR="#dddddd">
229 <I><% mt("Starting balance on [_1]", time2str($date_format, $date) ) |h %></I>
230 (<A HREF="javascript:void(0);" onClick="show_history();"><% mt('show prior history') |h %></A>)
233 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
234 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
235 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
236 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
237 <TD CLASS="grid" BGCOLOR="#dddddd" ALIGN="right"><I><% $balance_forward %></I></TD>
245 %my $years = $conf->config('payment_history-years') || 2;
246 %my $older_than = time - $years * 31556926; #60*60*24*365.2422
249 %my $old_history = 0;
252 %foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
254 % $lastdate = $item->{'date'};
257 % if ( $item->{'date'} < $older_than ) {
258 % $display = ' STYLE="display:none" ';
264 % if ( $hidden && ! $seen++ ) {
265 % balance_forward_row($balance, $item->{'date'}, $money_char);
270 % if ( $bgcolor eq $bgcolor1 ) {
271 % $bgcolor = $bgcolor2;
273 % $bgcolor = $bgcolor1;
276 % my $charge = exists($item->{'charge'})
277 % ? sprintf("$money_char\%.2f", $item->{'charge'})
278 % : exists($item->{'charge_nobal'})
279 % ? sprintf("$money_char\%.2f", $item->{'charge_nobal'})
280 % : exists($item->{'void_charge'})
281 % ? sprintf("<DEL>$money_char\%.2f</DEL>", $item->{'void_charge'})
284 % my $payment = exists($item->{'payment'})
285 % ? sprintf("- $money_char\%.2f", $item->{'payment'})
288 % $payment ||= sprintf( "<DEL>- $money_char\%.2f</DEL>",
289 % $item->{'void_payment'}
291 % if exists($item->{'void_payment'});
293 % my $credit = exists($item->{'credit'})
294 % ? sprintf("- $money_char\%.2f", $item->{'credit'})
297 % my $refund = exists($item->{'refund'})
298 % ? sprintf("$money_char\%.2f", $item->{'refund'})
301 % my $target = exists($item->{'target'}) ? $item->{'target'} : '';
303 % $balance += $item->{'charge'} if exists $item->{'charge'};
304 % $balance -= $item->{'payment'} if exists $item->{'payment'};
305 % $balance -= $item->{'credit'} if exists $item->{'credit'};
306 % $balance += $item->{'refund'} if exists $item->{'refund'};
307 % $balance = sprintf("%.2f", $balance);
308 % $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
309 % ( my $showbalance = $money_char. $balance ) =~ s/^\$\-/- \$/;
314 <TR <% $display ? $display.' ID="old_history'.$old_history++.'"' : ''%>>
315 <TD VALIGN="top" CLASS="grid" BGCOLOR="<% $bgcolor %>">
316 % unless ( !$target || $target{$target}++ ) {
318 <A NAME="<% $target %>">
321 <% time2str($date_format, $item->{'date'}) %>
322 % if ( $target && $target{$target} == 1 ) {
329 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
330 <% $item->{'desc'} %>
332 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
335 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
338 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
341 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
344 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
350 %if ( scalar(@history) && $hidden && ! $seen++ ) {
351 % balance_forward_row($balance, $lastdate, $money_char);
359 <SCRIPT TYPE="text/javascript">
361 function show_history () {
362 //alert('showing history!');
364 var balance_forward_row = document.getElementById('balance_forward_row');
366 balance_forward_row.style.display = 'none';
367 for ( var i = 0; i < <% $old_history %>; i++ ) {
368 var oldRow = document.getElementById('old_history'+i);
369 oldRow.style.display = '';
378 my( $cust_main ) = @_;
379 my $custnum = $cust_main->custnum;
381 my $conf = new FS::Conf;
382 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
384 my $curuser = $FS::CurrentUser::CurrentUser;
386 my @payby = grep /\w/, $conf->config('payby');
387 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
388 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
390 my %payby = map { $_=>1 } @payby;
393 'Queued' => 'O', #Open
395 'Complete' => 'R', #Resolved
403 ( map { $_ => scalar($conf->config($_)) }
404 qw( card_refund-days date_format )
406 ( map { $_ => $conf->exists($_) }
407 qw( deleteinvoices deletepayments deleterefunds pkg-balances )
411 $opt{'date_format'} ||= '%m/%d/%Y';
414 foreach my $legacy_cust_bill ($cust_main->legacy_cust_bill) {
416 'date' => $legacy_cust_bill->_date,
417 'desc' => include('payment_history/legacy_invoice.html', $legacy_cust_bill, %opt ),
418 'charge_nobal' => $legacy_cust_bill->charged,
423 my $num_cust_bill = 0;
424 foreach my $cust_bill ($cust_main->cust_bill) {
426 'date' => $cust_bill->_date,
427 'desc' => include('payment_history/invoice.html', $cust_bill, %opt ),
428 'charge' => $cust_bill->charged,
434 foreach my $cust_bill_void ($cust_main->cust_bill_void) {
436 'date' => $cust_bill_void->_date,
437 'desc' => include('payment_history/voided_invoice.html', $cust_bill_void, %opt ),
438 'void_charge' => $cust_bill_void->charged,
443 foreach my $cust_statement ($cust_main->cust_statement) {
445 'date' => $cust_statement->_date,
446 'desc' => include('payment_history/statement.html', $cust_statement, %opt ),
447 #'charge' => $cust_bill->charged,
451 #payments (some false laziness w/credits)
452 foreach my $cust_pay ($cust_main->cust_pay) {
454 'date' => $cust_pay->_date,
455 'desc' => include('payment_history/payment.html', $cust_pay, %opt ),
456 'payment' => $cust_pay->paid,
457 #'target' => $target, #XXX
462 foreach my $cust_pay_pending ($cust_main->cust_pay_pending) {
464 'date' => $cust_pay_pending->_date,
465 'desc' => include('payment_history/pending_payment.html', $cust_pay_pending, %opt ),
466 'void_payment' => $cust_pay_pending->paid,
472 foreach my $cust_pay_void ($cust_main->cust_pay_void) {
474 'date' => $cust_pay_void->_date,
475 'desc' => include('payment_history/voided_payment.html', $cust_pay_void, %opt ),
476 'void_payment' => $cust_pay_void->paid,
482 foreach my $cust_pay_pending ($cust_main->cust_pay_pending_attempt) {
484 'date' => $cust_pay_pending->_date,
485 'desc' => include('payment_history/attempted_payment.html', $cust_pay_pending, %opt ),
486 'void_payment' => $cust_pay_pending->paid, #??
487 #'target' => $target, #XXX
491 #credits (some false laziness w/payments)
492 foreach my $cust_credit ($cust_main->cust_credit) {
494 'date' => $cust_credit->_date,
495 'desc' => include('payment_history/credit.html', $cust_credit, %opt ),
496 'credit' => $cust_credit->amount,
502 foreach my $cust_refund ($cust_main->cust_refund) {
504 'date' => $cust_refund->_date,
505 'desc' => include('payment_history/refund.html', $cust_refund, %opt),
506 'refund' => $cust_refund->refund,
511 sub translate_payby {
512 my ($payby,$payinfo) = (shift,shift);
514 FS::payby->payby2shortname,
515 BILL => $payinfo ? emt('Check #') : '',
516 CHEK => emt('Electronic check '),
517 PREP => emt('Prepaid card '),
518 CARD => emt('Credit card #'),
519 COMP => emt('Complimentary by '),
520 #CASH => emt('Cash'),
521 #WEST => emt('Western Union'),
522 #MCRD => emt('Manual credit card'),
524 $payby = (exists $payby{$payby}) ? $payby{$payby} : $payby;
528 sub translate_payby_refund {
529 my ($payby,$payinfo) = (shift,shift);
531 FS::payby->payby2shortname,
532 BILL => $payinfo ? emt('Check #') : emt('Check'),
533 CHEK => emt('Electronic check '),
534 CARD => emt('Credit card #'),
535 COMP => emt('Complimentary by '),
537 $payby = (exists $payby{$payby}) ? $payby{$payby} : $payby;
541 sub translate_payinfo {
543 my $payby = $object->payby;
544 my $payinfo = $object->payinfo;
546 my $conf = new FS::Conf;
548 if ( $payby eq 'CARD' ) {
549 $payinfo = $object->paymask;
550 } elsif ( $payby eq 'CHEK' ) {
551 my( $account, $aba ) = split('@', $object->paymask );
552 $payinfo = emt("ABA [_1], Acct #[_2]",$aba,$account);
558 sub areyousure_link {
559 my ($url,$msg,$title,$label) = (shift,shift,shift,shift);
560 ' (<A HREF="javascript:areyousure(\''.$url.'\',\''.$msg.'\')" TITLE="'.$title.'">'.$label.'</A>)';