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
74 <& /elements/popup_link-cust_main.html,
75 'label' => emt('Credit line items'),
76 #'action' => "${p}search/cust_bill_pkg.cgi?nottax=1;type=select",
77 'action' => "${p}edit/credit-cust_bill_pkg.html",
78 'cust_main' => $cust_main,
79 'actionlabel' => emt('Credit line items'),
89 % if ( $payby{'BILL'} && $curuser->access_right(['Post refund', 'Post check refund']) ) {
90 <% $s++ ? ' | ' : '' %>
91 <& /elements/popup_link-cust_main.html,
92 'label' => emt('Enter check refund'),
93 'action' => "${p}edit/cust_refund.cgi?popup=1;payby=BILL",
94 'cust_main' => $cust_main,
95 'actionlabel' => emt('Enter check refund'),
100 % if ( $payby{'CASH'} && $curuser->access_right(['Post refund', 'Post cash refund']) ) {
101 <% $s++ ? ' | ' : '' %>
102 <& /elements/popup_link-cust_main.html,
103 'label' => emt('Enter cash refund'),
104 'action' => "${p}edit/cust_refund.cgi?popup=1;payby=CASH",
105 'cust_main' => $cust_main,
106 'actionlabel' => emt('Enter cash refund'),
111 %# someday, perhaps. very few gateways let you do unlinked refunds at all.
112 %# Authorize.net makes you sign a special form
114 %# % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
115 %# % && $curuser->access_right('Process refund')
116 %# % && ! $cust_main->is_encrypted($cust_main->payinfo)
118 %# <% $s++ ? ' | ' : '' %>
119 %# <A HREF="<% $p %>misc/refund.cgi?payby=CARD;custnum=<% $custnum %>">Process credit card refund</A>
122 %# % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
123 %# % && $curuser->access_right('Process refund')
124 %# % && ! $cust_main->is_encrypted($cust_main->payinfo)
126 %# <% $s++ ? ' | ' : '' %>
127 %# <A HREF="<% $p %>misc/refund.cgi?payby=CHEK;custnum=<% $custnum %>">Process electronic check (ACH) refund</A>
130 % if ( $payby{'MCRD'} && $curuser->access_right('Post refund') ) {
131 <% $s++ ? ' | ' : '' %>
132 <A HREF="<% $p %>edit/cust_refund.cgi?payby=MCRD;custnum=<% $custnum %>"><% mt('Post manual (offline/POS) credit card refund') |h %></A>
136 <TD ALIGN="right" VALIGN="top">
138 %# invoice reports, combined statement
139 % if ( $curuser->access_right('List invoices') ) {
140 % if ( $conf->exists('cust_main-print_statement_link')
141 % and $num_cust_bill > 0 ) {
142 <A HREF="<% $p %>view/cust_main_statement-pdf.cgi?<% $custnum %>"><%
143 mt('Print a current statement') |h %></A>
146 <A HREF="<% $p %>search/report_cust_bill.html?custnum=<% $custnum %>"><% mt('Invoice reports') |h %></A>
150 %# XXX payments, credits, refund reports
152 %# tax exemption link
154 % my $view_exemptions = $curuser->access_right('View customer tax exemptions');
155 % my $add_adjustment = ( $conf->exists('enable_tax_adjustments')
156 % && $curuser->access_right('Add customer tax adjustment')
158 % if ( $view_exemptions || $add_adjustment ) {
160 % if ( $view_exemptions ) {
161 <A HREF="<% $p %>search/cust_tax_exempt_pkg.cgi?custnum=<% $custnum %>"><% mt('View tax exemptions') |h %></A>
162 <% $add_adjustment ? '|' : '' %>
165 % if ( $add_adjustment ) {
166 <& /elements/popup_link.html, {
167 'action' => $p.'edit/cust_tax_adjustment.html?custnum='. $cust_main->custnum,
168 'label' => emt('Add tax adjustment'),
169 'actionlabel' => emt('Add tax adjustment'),
174 <A HREF="<% $p %>search/cust_tax_adjustment.html?custnum=<% $custnum %>"><% mt('View tax adjustments') |h %></A>
180 %# batched payment links
182 % if ( ( $conf->exists('batch-enable') || $conf->config('batch-enable_payby') )
183 % && $curuser->access_right('View customer batched payments')
186 <% mt('View batched payments:') |h %>
187 % foreach my $status (qw( Queued In-transit Complete All )) {
188 <A HREF="<% $p %>search/cust_pay_batch.cgi?status=<% $status{$status} %>;custnum=<% $custnum %>"><% mt($status) |h %></A>
189 <% $status ne 'All' ? '|' : '' %>
194 %# pending payment links
196 % if ( $curuser->access_right('View customer pending payments')
197 % && scalar($cust_main->cust_pay_pending)
200 <A HREF="<% $p %>search/cust_pay_pending.html?magic=_date;statusNOT=done;custnum=<% $custnum %>"><% mt('View pending payments') |h %></A><BR>
210 <& /elements/table-grid.html &>
211 % my $bgcolor1 = '#eeeeee';
212 % my $bgcolor2 = '#ffffff';
216 <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Date') |h %></TH>
217 <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Description') |h %></TH>
218 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Invoice') |h %></FONT></TH>
219 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Payment') |h %></FONT></TH>
220 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('In-house Credit') |h %></FONT></TH>
221 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Refund') |h %></FONT></TH>
222 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Balance') |h %></FONT></TH>
225 %#display payment history
227 %my $money_char = $conf->config('money_char') || '$';
229 %sub balance_forward_row {
230 % my( $b, $date, $money_char ) = @_;
231 % ( my $balance_forward = $money_char. $b ) =~ s/^\$\-/- \$/;
233 <TR ID="balance_forward_row">
234 <TD CLASS="grid" BGCOLOR="#dddddd">
235 <% time2str($date_format, $date) %>
238 <TD CLASS="grid" BGCOLOR="#dddddd">
239 <I><% mt("Starting balance on [_1]", time2str($date_format, $date) ) |h %></I>
240 (<A HREF="javascript:void(0);" onClick="show_history();"><% mt('show prior history') |h %></A>)
243 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
244 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
245 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
246 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
247 <TD CLASS="grid" BGCOLOR="#dddddd" ALIGN="right"><I><% $balance_forward %></I></TD>
255 %my $years = $conf->config('payment_history-years') || 2;
256 %my $older_than = time - $years * 31556926; #60*60*24*365.2422
259 %my $old_history = 0;
262 %foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
264 % $lastdate = $item->{'date'};
267 % if ( $item->{'date'} < $older_than ) {
268 % $display = ' STYLE="display:none" ';
274 % if ( $hidden && ! $seen++ ) {
275 % balance_forward_row($balance, $item->{'date'}, $money_char);
280 % if ( $bgcolor eq $bgcolor1 ) {
281 % $bgcolor = $bgcolor2;
283 % $bgcolor = $bgcolor1;
286 % my $charge = exists($item->{'charge'})
287 % ? sprintf("$money_char\%.2f", $item->{'charge'})
288 % : exists($item->{'charge_nobal'})
289 % ? sprintf("$money_char\%.2f", $item->{'charge_nobal'})
290 % : exists($item->{'void_charge'})
291 % ? sprintf("<DEL>$money_char\%.2f</DEL>", $item->{'void_charge'})
294 % my $payment = exists($item->{'payment'})
295 % ? sprintf("- $money_char\%.2f", $item->{'payment'})
298 % $payment ||= sprintf( "<DEL>- $money_char\%.2f</DEL>",
299 % $item->{'void_payment'}
301 % if exists($item->{'void_payment'});
303 % my $credit = exists($item->{'credit'})
304 % ? sprintf("- $money_char\%.2f", $item->{'credit'})
307 % my $refund = exists($item->{'refund'})
308 % ? sprintf("$money_char\%.2f", $item->{'refund'})
311 % my $target = exists($item->{'target'}) ? $item->{'target'} : '';
313 % $balance += $item->{'charge'} if exists $item->{'charge'};
314 % $balance -= $item->{'payment'} if exists $item->{'payment'};
315 % $balance -= $item->{'credit'} if exists $item->{'credit'};
316 % $balance += $item->{'refund'} if exists $item->{'refund'};
317 % $balance = sprintf("%.2f", $balance);
318 % $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
319 % ( my $showbalance = $money_char. $balance ) =~ s/^\$\-/- \$/;
324 <TR <% $display ? $display.' ID="old_history'.$old_history++.'"' : ''%>>
325 <TD VALIGN="top" CLASS="grid" BGCOLOR="<% $bgcolor %>">
326 % unless ( !$target || $target{$target}++ ) {
328 <A NAME="<% $target %>">
331 <% time2str($date_format, $item->{'date'}) %>
332 % if ( $target && $target{$target} == 1 ) {
339 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
340 <% $item->{'desc'} %>
342 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
345 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
348 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
351 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
354 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
360 %if ( scalar(@history) && $hidden && ! $seen++ ) {
361 % balance_forward_row($balance, $lastdate, $money_char);
369 <SCRIPT TYPE="text/javascript">
371 function show_history () {
372 //alert('showing history!');
374 var balance_forward_row = document.getElementById('balance_forward_row');
376 balance_forward_row.style.display = 'none';
377 for ( var i = 0; i < <% $old_history %>; i++ ) {
378 var oldRow = document.getElementById('old_history'+i);
379 oldRow.style.display = '';
388 my( $cust_main ) = @_;
389 my $custnum = $cust_main->custnum;
391 my $conf = new FS::Conf;
392 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
394 my $curuser = $FS::CurrentUser::CurrentUser;
396 my @payby = grep /\w/, $conf->config('payby');
397 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
398 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
400 my %payby = map { $_=>1 } @payby;
403 'Queued' => 'O', #Open
405 'Complete' => 'R', #Resolved
413 ( map { $_ => scalar($conf->config($_)) }
414 qw( card_refund-days date_format )
416 ( map { $_ => $conf->exists($_) }
417 qw( deleteinvoices deletepayments deleterefunds pkg-balances )
421 $opt{'date_format'} ||= '%m/%d/%Y';
424 foreach my $legacy_cust_bill ($cust_main->legacy_cust_bill) {
426 'date' => $legacy_cust_bill->_date,
427 'desc' => include('payment_history/legacy_invoice.html', $legacy_cust_bill, %opt ),
428 'charge_nobal' => $legacy_cust_bill->charged,
433 my $num_cust_bill = 0;
434 foreach my $cust_bill ($cust_main->cust_bill) {
436 'date' => $cust_bill->_date,
437 'desc' => include('payment_history/invoice.html', $cust_bill, %opt ),
438 'charge' => $cust_bill->charged,
444 foreach my $cust_bill_void ($cust_main->cust_bill_void) {
446 'date' => $cust_bill_void->_date,
447 'desc' => include('payment_history/voided_invoice.html', $cust_bill_void, %opt ),
448 'void_charge' => $cust_bill_void->charged,
453 foreach my $cust_statement ($cust_main->cust_statement) {
455 'date' => $cust_statement->_date,
456 'desc' => include('payment_history/statement.html', $cust_statement, %opt ),
457 #'charge' => $cust_bill->charged,
461 #payments (some false laziness w/credits)
462 foreach my $cust_pay ($cust_main->cust_pay) {
464 'date' => $cust_pay->_date,
465 'desc' => include('payment_history/payment.html', $cust_pay, %opt ),
466 'payment' => $cust_pay->paid,
467 #'target' => $target, #XXX
472 foreach my $cust_pay_pending ($cust_main->cust_pay_pending) {
474 'date' => $cust_pay_pending->_date,
475 'desc' => include('payment_history/pending_payment.html', $cust_pay_pending, %opt ),
476 'void_payment' => $cust_pay_pending->paid,
482 foreach my $cust_pay_void ($cust_main->cust_pay_void) {
484 'date' => $cust_pay_void->_date,
485 'desc' => include('payment_history/voided_payment.html', $cust_pay_void, %opt ),
486 'void_payment' => $cust_pay_void->paid,
492 foreach my $cust_pay_pending ($cust_main->cust_pay_pending_attempt) {
494 'date' => $cust_pay_pending->_date,
495 'desc' => include('payment_history/attempted_payment.html', $cust_pay_pending, %opt ),
496 'void_payment' => $cust_pay_pending->paid, #??
497 #'target' => $target, #XXX
501 #credits (some false laziness w/payments)
502 foreach my $cust_credit ($cust_main->cust_credit) {
504 'date' => $cust_credit->_date,
505 'desc' => include('payment_history/credit.html', $cust_credit, %opt ),
506 'credit' => $cust_credit->amount,
512 foreach my $cust_refund ($cust_main->cust_refund) {
514 'date' => $cust_refund->_date,
515 'desc' => include('payment_history/refund.html', $cust_refund, %opt),
516 'refund' => $cust_refund->refund,
521 sub translate_payby {
522 my ($payby,$payinfo) = (shift,shift);
524 FS::payby->payby2shortname,
525 BILL => $payinfo ? emt('Check #') : '',
526 CHEK => emt('Electronic check '),
527 PREP => emt('Prepaid card '),
528 CARD => emt('Credit card #'),
529 COMP => emt('Complimentary by '),
530 #CASH => emt('Cash'),
531 #WEST => emt('Western Union'),
532 #MCRD => emt('Manual credit card'),
534 $payby = (exists $payby{$payby}) ? $payby{$payby} : $payby;
538 sub translate_payby_refund {
539 my ($payby,$payinfo) = (shift,shift);
541 FS::payby->payby2shortname,
542 BILL => $payinfo ? emt('Check #') : emt('Check'),
543 CHEK => emt('Electronic check '),
544 CARD => emt('Credit card #'),
545 COMP => emt('Complimentary by '),
547 $payby = (exists $payby{$payby}) ? $payby{$payby} : $payby;
551 sub translate_payinfo {
553 my $payby = $object->payby;
554 my $payinfo = $object->payinfo;
556 my $conf = new FS::Conf;
558 if ( $payby eq 'CARD' ) {
559 $payinfo = $object->paymask;
560 } elsif ( $payby eq 'CHEK' ) {
561 my( $account, $aba ) = split('@', $object->paymask );
562 $payinfo = emt("ABA [_1], Acct #[_2]",$aba,$account);
568 sub areyousure_link {
569 my ($url,$msg,$title,$label) = (shift,shift,shift,shift);
570 ' (<A HREF="javascript:areyousure(\''.$url.'\',\''.$msg.'\')" TITLE="'.$title.'">'.$label.'</A>)';