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'})
292 % my $payment = exists($item->{'payment'})
293 % ? sprintf("- $money_char\%.2f", $item->{'payment'})
296 % $payment ||= sprintf( "<DEL>- $money_char\%.2f</DEL>",
297 % $item->{'void_payment'}
299 % if exists($item->{'void_payment'});
301 % my $credit = exists($item->{'credit'})
302 % ? sprintf("- $money_char\%.2f", $item->{'credit'})
305 % my $refund = exists($item->{'refund'})
306 % ? sprintf("$money_char\%.2f", $item->{'refund'})
309 % my $target = exists($item->{'target'}) ? $item->{'target'} : '';
311 % $balance += $item->{'charge'} if exists $item->{'charge'};
312 % $balance -= $item->{'payment'} if exists $item->{'payment'};
313 % $balance -= $item->{'credit'} if exists $item->{'credit'};
314 % $balance += $item->{'refund'} if exists $item->{'refund'};
315 % $balance = sprintf("%.2f", $balance);
316 % $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
317 % ( my $showbalance = $money_char. $balance ) =~ s/^\$\-/- \$/;
322 <TR <% $display ? $display.' ID="old_history'.$old_history++.'"' : ''%>>
323 <TD VALIGN="top" CLASS="grid" BGCOLOR="<% $bgcolor %>">
324 % unless ( !$target || $target{$target}++ ) {
326 <A NAME="<% $target %>">
329 <% time2str($date_format, $item->{'date'}) %>
330 % if ( $target && $target{$target} == 1 ) {
337 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
338 <% $item->{'desc'} %>
340 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
343 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
346 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
349 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
352 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
358 %if ( scalar(@history) && $hidden && ! $seen++ ) {
359 % balance_forward_row($balance, $lastdate, $money_char);
367 <SCRIPT TYPE="text/javascript">
369 function show_history () {
370 //alert('showing history!');
372 var balance_forward_row = document.getElementById('balance_forward_row');
374 balance_forward_row.style.display = 'none';
375 for ( var i = 0; i < <% $old_history %>; i++ ) {
376 var oldRow = document.getElementById('old_history'+i);
377 oldRow.style.display = '';
386 my( $cust_main ) = @_;
387 my $custnum = $cust_main->custnum;
389 my $conf = new FS::Conf;
390 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
392 my $curuser = $FS::CurrentUser::CurrentUser;
394 my @payby = grep /\w/, $conf->config('payby');
395 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
396 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
398 my %payby = map { $_=>1 } @payby;
401 'Queued' => 'O', #Open
403 'Complete' => 'R', #Resolved
411 ( map { $_ => scalar($conf->config($_)) }
412 qw( card_refund-days date_format )
414 ( map { $_ => $conf->exists($_) }
415 qw( deleteinvoices deletepayments deleterefunds pkg-balances )
419 $opt{'date_format'} ||= '%m/%d/%Y';
422 foreach my $legacy_cust_bill ($cust_main->legacy_cust_bill) {
424 'date' => $legacy_cust_bill->_date,
425 'desc' => include('payment_history/legacy_invoice.html', $legacy_cust_bill, %opt ),
426 'charge_nobal' => $legacy_cust_bill->charged,
431 my $num_cust_bill = 0;
432 foreach my $cust_bill ($cust_main->cust_bill) {
434 'date' => $cust_bill->_date,
435 'desc' => include('payment_history/invoice.html', $cust_bill, %opt ),
436 'charge' => $cust_bill->charged,
442 foreach my $cust_statement ($cust_main->cust_statement) {
444 'date' => $cust_statement->_date,
445 'desc' => include('payment_history/statement.html', $cust_statement, %opt ),
446 #'charge' => $cust_bill->charged,
450 #payments (some false laziness w/credits)
451 foreach my $cust_pay ($cust_main->cust_pay) {
453 'date' => $cust_pay->_date,
454 'desc' => include('payment_history/payment.html', $cust_pay, %opt ),
455 'payment' => $cust_pay->paid,
456 #'target' => $target, #XXX
461 foreach my $cust_pay_pending ($cust_main->cust_pay_pending) {
463 'date' => $cust_pay_pending->_date,
464 'desc' => include('payment_history/pending_payment.html', $cust_pay_pending, %opt ),
465 'void_payment' => $cust_pay_pending->paid,
471 foreach my $cust_pay_void ($cust_main->cust_pay_void) {
473 'date' => $cust_pay_void->_date,
474 'desc' => include('payment_history/voided_payment.html', $cust_pay_void, %opt ),
475 'void_payment' => $cust_pay_void->paid,
481 foreach my $cust_pay_pending ($cust_main->cust_pay_pending_attempt) {
483 'date' => $cust_pay_pending->_date,
484 'desc' => include('payment_history/attempted_payment.html', $cust_pay_pending, %opt ),
485 'void_payment' => $cust_pay_pending->paid, #??
486 #'target' => $target, #XXX
490 #credits (some false laziness w/payments)
491 foreach my $cust_credit ($cust_main->cust_credit) {
493 'date' => $cust_credit->_date,
494 'desc' => include('payment_history/credit.html', $cust_credit, %opt ),
495 'credit' => $cust_credit->amount,
501 foreach my $cust_refund ($cust_main->cust_refund) {
503 'date' => $cust_refund->_date,
504 'desc' => include('payment_history/refund.html', $cust_refund, %opt),
505 'refund' => $cust_refund->refund,
510 sub translate_payby {
511 my ($payby,$payinfo) = (shift,shift);
513 BILL => $payinfo ? emt('Check #') : '',
514 CHEK => emt('Electronic check '),
515 PREP => emt('Prepaid card '),
516 CARD => emt('Credit card #'),
517 COMP => emt('Complimentary by '),
519 WEST => emt('Western Union'),
520 MCRD => emt('Manual credit card'),
522 $payby = (exists $payby{$payby}) ? $payby{$payby} : $payby;
526 sub translate_payby_refund {
527 my ($payby,$payinfo) = (shift,shift);
529 BILL => $payinfo ? emt('Check #') : emt('Check'),
530 CHEK => emt('Electronic check '),
531 CARD => emt('Credit card #'),
532 COMP => emt('Complimentary by '),
534 $payby = (exists $payby{$payby}) ? $payby{$payby} : $payby;
538 sub translate_payinfo {
540 my $payby = $object->payby;
541 my $payinfo = $object->payinfo;
543 my $conf = new FS::Conf;
545 if ( $payby eq 'CARD' ) {
546 $payinfo = $object->paymask;
547 } elsif ( $payby eq 'CHEK' ) {
548 my( $account, $aba ) = split('@', $object->paymask );
549 $payinfo = emt("ABA [_1], Acct #[_2]",$aba,$account);
555 sub areyousure_link {
556 my ($url,$msg,$title,$label) = (shift,shift,shift,shift);
557 ' (<A HREF="javascript:areyousure(\''.$url.'\',\''.$msg.'\')" TITLE="'.$title.'">'.$label.'</A>)';