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>
37 <% $s ? '<BR>' : '' %>
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>
61 <% $s ? '<BR>' : '' %>
66 % if ( $curuser->access_right('Post credit') ) {
67 <% $s++ ? ' | ' : '' %>
68 <& /elements/popup_link-cust_main.html,
69 'label' => emt('Enter credit'),
70 'action' => "${p}edit/cust_credit.cgi",
71 'cust_main' => $cust_main,
72 'actionlabel' => emt('Enter credit'),
73 'width' => 616, #make room for reasons #540 default
76 % if ( $curuser->access_right('Credit line items') ) {
77 <% $s++ ? ' | ' : '' %>
78 <& /elements/popup_link-cust_main.html,
79 'label' => emt('Credit line items'),
80 #'action' => "${p}search/cust_bill_pkg.cgi?nottax=1;type=select",
81 'action' => "${p}edit/credit-cust_bill_pkg.html",
82 'cust_main' => $cust_main,
83 'actionlabel' => emt('Credit line items'),
88 <% $s ? '<BR>' : '' %>
93 % if ( $payby{'BILL'} && $curuser->access_right(['Post refund', 'Post check refund']) ) {
94 <% $s++ ? ' | ' : '' %>
95 <& /elements/popup_link-cust_main.html,
96 'label' => emt('Enter check refund'),
97 'action' => "${p}edit/cust_refund.cgi?popup=1;payby=BILL",
98 'cust_main' => $cust_main,
99 'actionlabel' => emt('Enter check refund'),
104 % if ( $payby{'CASH'} && $curuser->access_right(['Post refund', 'Post cash refund']) ) {
105 <% $s++ ? ' | ' : '' %>
106 <& /elements/popup_link-cust_main.html,
107 'label' => emt('Enter cash refund'),
108 'action' => "${p}edit/cust_refund.cgi?popup=1;payby=CASH",
109 'cust_main' => $cust_main,
110 'actionlabel' => emt('Enter cash refund'),
115 %# someday, perhaps. very few gateways let you do unlinked refunds at all.
116 %# Authorize.net makes you sign a special form
118 %# % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
119 %# % && $curuser->access_right('Process refund')
120 %# % && ! $cust_main->is_encrypted($cust_main->payinfo)
122 %# <% $s++ ? ' | ' : '' %>
123 %# <A HREF="<% $p %>misc/refund.cgi?payby=CARD;custnum=<% $custnum %>">Process credit card refund</A>
126 %# % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
127 %# % && $curuser->access_right('Process refund')
128 %# % && ! $cust_main->is_encrypted($cust_main->payinfo)
130 %# <% $s++ ? ' | ' : '' %>
131 %# <A HREF="<% $p %>misc/refund.cgi?payby=CHEK;custnum=<% $custnum %>">Process electronic check (ACH) refund</A>
134 % if ( $payby{'MCRD'} && $curuser->access_right('Post refund') ) {
135 <% $s++ ? ' | ' : '' %>
136 <A HREF="<% $p %>edit/cust_refund.cgi?payby=MCRD;custnum=<% $custnum %>"><% mt('Post manual (offline/POS) credit card refund') |h %></A>
140 <TD ALIGN="right" VALIGN="top">
142 %# invoice reports, combined statement
143 % if ( $curuser->access_right('List invoices') ) {
144 % if ( $conf->exists('cust_main-print_statement_link')
145 % and $num_cust_bill > 0 ) {
146 <A HREF="<% $p %>view/cust_main_statement-pdf.cgi?<% $custnum %>"><%
147 mt('Print a current statement') |h %></A>
150 <A HREF="<% $p %>search/report_cust_bill.html?custnum=<% $custnum %>"><% mt('Invoice reports') |h %></A>
154 %# XXX payments, credits, refund reports
156 %# tax exemption link
158 % my $view_exemptions = $curuser->access_right('View customer tax exemptions');
159 % my $add_adjustment = ( $conf->exists('enable_tax_adjustments')
160 % && $curuser->access_right('Add customer tax adjustment')
162 % if ( $view_exemptions || $add_adjustment ) {
164 % if ( $view_exemptions ) {
165 <A HREF="<% $p %>search/cust_tax_exempt_pkg.cgi?custnum=<% $custnum %>"><% mt('View tax exemptions') |h %></A>
166 <% $add_adjustment ? '|' : '' %>
169 % if ( $add_adjustment ) {
170 <& /elements/popup_link.html, {
171 'action' => $p.'edit/cust_tax_adjustment.html?custnum='. $cust_main->custnum,
172 'label' => emt('Add tax adjustment'),
173 'actionlabel' => emt('Add tax adjustment'),
178 <A HREF="<% $p %>search/cust_tax_adjustment.html?custnum=<% $custnum %>"><% mt('View tax adjustments') |h %></A>
184 %# batched payment links
186 % if ( ( $conf->exists('batch-enable') || $conf->config('batch-enable_payby') )
187 % && $curuser->access_right('View customer batched payments')
190 <% mt('View batched payments:') |h %>
191 % foreach my $status (qw( Queued In-transit Complete All )) {
192 <A HREF="<% $p %>search/cust_pay_batch.cgi?status=<% $status{$status} %>;custnum=<% $custnum %>"><% mt($status) |h %></A>
193 <% $status ne 'All' ? '|' : '' %>
198 %# pending payment links
200 % if ( $curuser->access_right('View customer pending payments')
201 % && scalar($cust_main->cust_pay_pending)
204 <A HREF="<% $p %>search/cust_pay_pending.html?magic=_date;statusNOT=done;custnum=<% $custnum %>"><% mt('View pending payments') |h %></A><BR>
214 <& /elements/table-grid.html &>
215 % my $bgcolor1 = '#eeeeee';
216 % my $bgcolor2 = '#ffffff';
220 <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Date') |h %></TH>
221 <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Description') |h %></TH>
222 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Invoice') |h %></FONT></TH>
223 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Payment') |h %></FONT></TH>
224 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('In-house Credit') |h %></FONT></TH>
225 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Refund') |h %></FONT></TH>
226 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Balance') |h %></FONT></TH>
229 %#display payment history
231 %my $money_char = $conf->config('money_char') || '$';
233 %sub balance_forward_row {
234 % my( $b, $date, $money_char ) = @_;
235 % ( my $balance_forward = $money_char. $b ) =~ s/^\$\-/- \$/;
237 <TR ID="balance_forward_row">
238 <TD CLASS="grid" BGCOLOR="#dddddd">
239 <% time2str($date_format, $date) %>
242 <TD CLASS="grid" BGCOLOR="#dddddd">
243 <I><% mt("Starting balance on [_1]", time2str($date_format, $date) ) |h %></I>
244 (<A HREF="javascript:void(0);" onClick="show_history();"><% mt('show prior history') |h %></A>)
247 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
248 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
249 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
250 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
251 <TD CLASS="grid" BGCOLOR="#dddddd" ALIGN="right"><I><% $balance_forward %></I></TD>
259 %my $years = $conf->config('payment_history-years') || 2;
260 %my $older_than = time - $years * 31556926; #60*60*24*365.2422
263 %my $old_history = 0;
266 %foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
268 % $lastdate = $item->{'date'};
271 % if ( $item->{'date'} < $older_than ) {
272 % $display = ' STYLE="display:none" ';
278 % if ( $hidden && ! $seen++ ) {
279 % balance_forward_row($balance, $item->{'date'}, $money_char);
284 % if ( $bgcolor eq $bgcolor1 ) {
285 % $bgcolor = $bgcolor2;
287 % $bgcolor = $bgcolor1;
290 % my $charge = exists($item->{'charge'})
291 % ? sprintf("$money_char\%.2f", $item->{'charge'})
292 % : exists($item->{'charge_nobal'})
293 % ? sprintf("$money_char\%.2f", $item->{'charge_nobal'})
294 % : exists($item->{'void_charge'})
295 % ? sprintf("<DEL>$money_char\%.2f</DEL>", $item->{'void_charge'})
298 % my $payment = exists($item->{'payment'})
299 % ? sprintf("- $money_char\%.2f", $item->{'payment'})
302 % $payment ||= sprintf( "<DEL>- $money_char\%.2f</DEL>",
303 % $item->{'void_payment'}
305 % if exists($item->{'void_payment'});
307 % my $credit = exists($item->{'credit'})
308 % ? sprintf("- $money_char\%.2f", $item->{'credit'})
311 % my $refund = exists($item->{'refund'})
312 % ? sprintf("$money_char\%.2f", $item->{'refund'})
315 % my $target = exists($item->{'target'}) ? $item->{'target'} : '';
317 % $balance += $item->{'charge'} if exists $item->{'charge'};
318 % $balance -= $item->{'payment'} if exists $item->{'payment'};
319 % $balance -= $item->{'credit'} if exists $item->{'credit'};
320 % $balance += $item->{'refund'} if exists $item->{'refund'};
321 % $balance = sprintf("%.2f", $balance);
322 % $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
323 % ( my $showbalance = $money_char. $balance ) =~ s/^\$\-/- \$/;
328 <TR <% $display ? $display.' ID="old_history'.$old_history++.'"' : ''%>>
329 <TD VALIGN="top" CLASS="grid" BGCOLOR="<% $bgcolor %>">
330 % unless ( !$target || $target{$target}++ ) {
332 <A NAME="<% $target %>">
335 <% time2str($date_format, $item->{'date'}) %>
336 % if ( $target && $target{$target} == 1 ) {
343 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
344 <% $item->{'desc'} %>
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 %>">
355 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
358 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
364 %if ( scalar(@history) && $hidden && ! $seen++ ) {
365 % balance_forward_row($balance, $lastdate, $money_char);
373 <SCRIPT TYPE="text/javascript">
375 function show_history () {
376 //alert('showing history!');
378 var balance_forward_row = document.getElementById('balance_forward_row');
380 balance_forward_row.style.display = 'none';
381 for ( var i = 0; i < <% $old_history %>; i++ ) {
382 var oldRow = document.getElementById('old_history'+i);
383 oldRow.style.display = '';
392 my( $cust_main ) = @_;
393 my $custnum = $cust_main->custnum;
395 my $conf = new FS::Conf;
396 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
398 my $curuser = $FS::CurrentUser::CurrentUser;
400 my @payby = grep /\w/, $conf->config('payby');
401 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
402 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
404 my %payby = map { $_=>1 } @payby;
407 'Queued' => 'O', #Open
409 'Complete' => 'R', #Resolved
417 ( map { $_ => scalar($conf->config($_)) }
418 qw( card_refund-days date_format )
420 ( map { $_ => $conf->exists($_) }
421 qw( deleteinvoices deletepayments deleterefunds pkg-balances )
425 $opt{'date_format'} ||= '%m/%d/%Y';
428 foreach my $legacy_cust_bill ($cust_main->legacy_cust_bill) {
430 'date' => $legacy_cust_bill->_date,
431 'desc' => include('payment_history/legacy_invoice.html', $legacy_cust_bill, %opt ),
432 'charge_nobal' => $legacy_cust_bill->charged,
437 my $num_cust_bill = 0;
438 foreach my $cust_bill ($cust_main->cust_bill) {
440 'date' => $cust_bill->_date,
441 'desc' => include('payment_history/invoice.html', $cust_bill, %opt ),
442 'charge' => $cust_bill->charged,
448 foreach my $cust_bill_void ($cust_main->cust_bill_void) {
450 'date' => $cust_bill_void->_date,
451 'desc' => include('payment_history/voided_invoice.html', $cust_bill_void, %opt ),
452 'void_charge' => $cust_bill_void->charged,
457 foreach my $cust_statement ($cust_main->cust_statement) {
459 'date' => $cust_statement->_date,
460 'desc' => include('payment_history/statement.html', $cust_statement, %opt ),
461 #'charge' => $cust_bill->charged,
465 #payments (some false laziness w/credits)
466 foreach my $cust_pay ($cust_main->cust_pay) {
468 'date' => $cust_pay->_date,
469 'desc' => include('payment_history/payment.html', $cust_pay, %opt ),
470 'payment' => $cust_pay->paid,
471 #'target' => $target, #XXX
476 foreach my $cust_pay_pending ($cust_main->cust_pay_pending) {
478 'date' => $cust_pay_pending->_date,
479 'desc' => include('payment_history/pending_payment.html', $cust_pay_pending, %opt ),
480 'void_payment' => $cust_pay_pending->paid,
486 foreach my $cust_pay_void ($cust_main->cust_pay_void) {
488 'date' => $cust_pay_void->_date,
489 'desc' => include('payment_history/voided_payment.html', $cust_pay_void, %opt ),
490 'void_payment' => $cust_pay_void->paid,
496 foreach my $cust_pay_pending ($cust_main->cust_pay_pending_attempt) {
498 'date' => $cust_pay_pending->_date,
499 'desc' => include('payment_history/attempted_payment.html', $cust_pay_pending, %opt ),
500 'void_payment' => $cust_pay_pending->paid, #??
501 #'target' => $target, #XXX
504 #declined batch payments
505 foreach my $cust_pay_batch (
506 $cust_main->cust_pay_batch(hashref => {status => 'Declined'})
508 my $pay_batch = $cust_pay_batch->pay_batch;
510 'date' => $pay_batch->upload,
511 'desc' => include('payment_history/attempted_batch_payment.html', $cust_pay_batch, %opt),
512 'void_payment' => $cust_pay_batch->amount,
516 #credits (some false laziness w/payments)
517 foreach my $cust_credit ($cust_main->cust_credit) {
519 'date' => $cust_credit->_date,
520 'desc' => include('payment_history/credit.html', $cust_credit, %opt ),
521 'credit' => $cust_credit->amount,
527 foreach my $cust_refund ($cust_main->cust_refund) {
529 'date' => $cust_refund->_date,
530 'desc' => include('payment_history/refund.html', $cust_refund, %opt),
531 'refund' => $cust_refund->refund,
536 sub translate_payby {
537 my ($payby,$payinfo) = (shift,shift);
539 FS::payby->payby2shortname,
540 BILL => $payinfo ? emt('Check #') : '',
541 CHEK => emt('Electronic check '),
542 PREP => emt('Prepaid card '),
543 CARD => emt('Credit card #'),
544 COMP => emt('Complimentary by '),
545 #CASH => emt('Cash'),
546 #WEST => emt('Western Union'),
547 #MCRD => emt('Manual credit card'),
549 $payby = (exists $payby{$payby}) ? $payby{$payby} : $payby;
553 sub translate_payby_refund {
554 my ($payby,$payinfo) = (shift,shift);
556 FS::payby->payby2shortname,
557 BILL => $payinfo ? emt('Check #') : emt('Check'),
558 CHEK => emt('Electronic check '),
559 CARD => emt('Credit card #'),
560 COMP => emt('Complimentary by '),
562 $payby = (exists $payby{$payby}) ? $payby{$payby} : $payby;
566 sub translate_payinfo {
568 my $payby = $object->payby;
569 my $payinfo = $object->payinfo;
571 my $conf = new FS::Conf;
573 if ( $payby eq 'CARD' ) {
574 $payinfo = $object->paymask;
575 } elsif ( $payby eq 'CHEK' ) {
576 my( $account, $aba ) = split('@', $object->paymask );
577 $payinfo = emt("ABA [_1], Acct #[_2]",$aba,$account);
583 sub areyousure_link {
584 my ($url,$msg,$title,$label) = (shift,shift,shift,shift);
585 ' (<A HREF="javascript:areyousure(\''.$url.'\',\''.$msg.'\')" TITLE="'.$title.'">'.$label.'</A>)';