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'})
282 % my $payment = exists($item->{'payment'})
283 % ? sprintf("- $money_char\%.2f", $item->{'payment'})
286 % $payment ||= sprintf( "<DEL>- $money_char\%.2f</DEL>",
287 % $item->{'void_payment'}
289 % if exists($item->{'void_payment'});
291 % my $credit = exists($item->{'credit'})
292 % ? sprintf("- $money_char\%.2f", $item->{'credit'})
295 % my $refund = exists($item->{'refund'})
296 % ? sprintf("$money_char\%.2f", $item->{'refund'})
299 % my $target = exists($item->{'target'}) ? $item->{'target'} : '';
301 % $balance += $item->{'charge'} if exists $item->{'charge'};
302 % $balance -= $item->{'payment'} if exists $item->{'payment'};
303 % $balance -= $item->{'credit'} if exists $item->{'credit'};
304 % $balance += $item->{'refund'} if exists $item->{'refund'};
305 % $balance = sprintf("%.2f", $balance);
306 % $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
307 % ( my $showbalance = $money_char. $balance ) =~ s/^\$\-/- \$/;
312 <TR <% $display ? $display.' ID="old_history'.$old_history++.'"' : ''%>>
313 <TD VALIGN="top" CLASS="grid" BGCOLOR="<% $bgcolor %>">
314 % unless ( !$target || $target{$target}++ ) {
316 <A NAME="<% $target %>">
319 <% time2str($date_format, $item->{'date'}) %>
320 % if ( $target && $target{$target} == 1 ) {
327 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
328 <% $item->{'desc'} %>
330 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
333 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
336 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
339 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
342 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
348 %if ( scalar(@history) && $hidden && ! $seen++ ) {
349 % balance_forward_row($balance, $lastdate, $money_char);
357 <SCRIPT TYPE="text/javascript">
359 function show_history () {
360 //alert('showing history!');
362 var balance_forward_row = document.getElementById('balance_forward_row');
364 balance_forward_row.style.display = 'none';
365 for ( var i = 0; i < <% $old_history %>; i++ ) {
366 var oldRow = document.getElementById('old_history'+i);
367 oldRow.style.display = '';
376 my( $cust_main ) = @_;
377 my $custnum = $cust_main->custnum;
379 my $conf = new FS::Conf;
380 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
382 my $curuser = $FS::CurrentUser::CurrentUser;
384 my @payby = grep /\w/, $conf->config('payby');
385 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
386 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
388 my %payby = map { $_=>1 } @payby;
391 'Queued' => 'O', #Open
393 'Complete' => 'R', #Resolved
401 ( map { $_ => scalar($conf->config($_)) }
402 qw( card_refund-days date_format )
404 ( map { $_ => $conf->exists($_) }
405 qw( deleteinvoices deletepayments deleterefunds pkg-balances )
409 $opt{'date_format'} ||= '%m/%d/%Y';
412 foreach my $legacy_cust_bill ($cust_main->legacy_cust_bill) {
414 'date' => $legacy_cust_bill->_date,
415 'desc' => include('payment_history/legacy_invoice.html', $legacy_cust_bill, %opt ),
416 'charge_nobal' => $legacy_cust_bill->charged,
421 my $num_cust_bill = 0;
422 foreach my $cust_bill ($cust_main->cust_bill) {
424 'date' => $cust_bill->_date,
425 'desc' => include('payment_history/invoice.html', $cust_bill, %opt ),
426 'charge' => $cust_bill->charged,
432 foreach my $cust_statement ($cust_main->cust_statement) {
434 'date' => $cust_statement->_date,
435 'desc' => include('payment_history/statement.html', $cust_statement, %opt ),
436 #'charge' => $cust_bill->charged,
440 #payments (some false laziness w/credits)
441 foreach my $cust_pay ($cust_main->cust_pay) {
443 'date' => $cust_pay->_date,
444 'desc' => include('payment_history/payment.html', $cust_pay, %opt ),
445 'payment' => $cust_pay->paid,
446 #'target' => $target, #XXX
451 foreach my $cust_pay_pending ($cust_main->cust_pay_pending) {
453 'date' => $cust_pay_pending->_date,
454 'desc' => include('payment_history/pending_payment.html', $cust_pay_pending, %opt ),
455 'void_payment' => $cust_pay_pending->paid,
461 foreach my $cust_pay_void ($cust_main->cust_pay_void) {
463 'date' => $cust_pay_void->_date,
464 'desc' => include('payment_history/voided_payment.html', $cust_pay_void, %opt ),
465 'void_payment' => $cust_pay_void->paid,
471 foreach my $cust_pay_pending ($cust_main->cust_pay_pending_attempt) {
473 'date' => $cust_pay_pending->_date,
474 'desc' => include('payment_history/attempted_payment.html', $cust_pay_pending, %opt ),
475 'void_payment' => $cust_pay_pending->paid, #??
476 #'target' => $target, #XXX
480 #credits (some false laziness w/payments)
481 foreach my $cust_credit ($cust_main->cust_credit) {
483 'date' => $cust_credit->_date,
484 'desc' => include('payment_history/credit.html', $cust_credit, %opt ),
485 'credit' => $cust_credit->amount,
491 foreach my $cust_refund ($cust_main->cust_refund) {
493 'date' => $cust_refund->_date,
494 'desc' => include('payment_history/refund.html', $cust_refund),
495 'refund' => $cust_refund->refund,
500 sub translate_payby {
501 my ($payby,$payinfo) = (shift,shift);
503 FS::payby->payby2shortname,
504 BILL => $payinfo ? emt('Check #') : '',
505 CHEK => emt('Electronic check '),
506 PREP => emt('Prepaid card '),
507 CARD => emt('Credit card #'),
508 COMP => emt('Complimentary by '),
509 #CASH => emt('Cash'),
510 #WEST => emt('Western Union'),
511 #MCRD => emt('Manual credit card'),
513 $payby = (exists $payby{$payby}) ? $payby{$payby} : $payby;
517 sub translate_payby_refund {
518 my ($payby,$payinfo) = (shift,shift);
520 FS::payby->payby2shortname,
521 BILL => $payinfo ? emt('Check #') : emt('Check'),
522 CHEK => emt('Electronic check '),
523 CARD => emt('Credit card #'),
524 COMP => emt('Complimentary by '),
526 $payby = (exists $payby{$payby}) ? $payby{$payby} : $payby;
530 sub translate_payinfo {
532 my $payby = $object->payby;
533 my $payinfo = $object->payinfo;
535 my $conf = new FS::Conf;
537 if ( $payby eq 'CARD' ) {
538 $payinfo = $object->paymask;
539 } elsif ( $payby eq 'CHEK' ) {
540 my( $account, $aba ) = split('@', $object->paymask );
541 $payinfo = emt("ABA [_1], Acct #[_2]",$aba,$account);
547 sub areyousure_link {
548 my ($url,$msg,$title,$label) = (shift,shift,shift,shift);
549 ' (<A HREF="javascript:areyousure(\''.$url.'\',\''.$msg.'\')" TITLE="'.$title.'">'.$label.'</A>)';