8 % if ( $payby{'BILL'} && $curuser->access_right(['Post payment', 'Post check payment' ]) ) {
9 <% $s++ ? ' | ' : '' %>
10 <% include('/elements/popup_link-cust_main.html',
11 'label' => 'Enter check payment',
12 'action' => "${p}edit/cust_pay.cgi?popup=1;payby=BILL",
13 'cust_main' => $cust_main,
14 'actionlabel' => 'Enter check payment',
16 #default# 'height' => 336,
21 % if ( $payby{'CASH'} && $curuser->access_right(['Post payment', 'Post cash payment']) ) {
22 <% $s++ ? ' | ' : '' %>
23 <% include('/elements/popup_link-cust_main.html',
24 'label' => 'Enter cash payment',
25 'action' => "${p}edit/cust_pay.cgi?popup=1;payby=CASH",
26 'cust_main' => $cust_main,
27 'actionlabel' => 'Enter cash payment',
29 #default# 'height' => 336,
34 % if ( $payby{'WEST'} && $curuser->access_right('Post payment') ) {
35 <% $s++ ? ' | ' : '' %>
36 <A HREF="<% $p %>edit/cust_pay.cgi?payby=WEST;custnum=<% $custnum %>">Enter Western Union payment</A>
42 % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
43 % && $curuser->access_right(['Process payment', 'Process credit card payment'])
44 % && ! $cust_main->is_encrypted($cust_main->payinfo)
46 <% $s++ ? ' | ' : '' %>
47 <A HREF="<% $p %>misc/payment.cgi?payby=CARD;custnum=<% $custnum %>">Process credit card payment</A>
50 % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
51 % && $curuser->access_right(['Process payment', 'Process Echeck payment'])
52 % && ! $cust_main->is_encrypted($cust_main->payinfo)
54 <% $s++ ? ' | ' : '' %>
55 <A HREF="<% $p %>misc/payment.cgi?payby=CHEK;custnum=<% $custnum %>">Process electronic check (ACH) payment</A>
58 % if ( $payby{'MCRD'} && $curuser->access_right('Post payment') ) {
59 <% $s++ ? ' | ' : '' %>
60 <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCRD;custnum=<% $custnum %>">Post manual (offline/POS) credit card payment</A>
67 % if ( $curuser->access_right('Post credit') ) {
68 <% include('/elements/popup_link-cust_main.html',
69 'label' => 'Enter credit',
70 'action' => "${p}edit/cust_credit.cgi",
71 'cust_main' => $cust_main,
72 'actionlabel' => 'Enter credit',
73 'width' => 616, #make room for reasons #540 default
74 #default# 'height' => 336,
83 % if ( $payby{'BILL'} && $curuser->access_right(['Post refund', 'Post check refund']) ) {
84 <% $s++ ? ' | ' : '' %>
85 <% include('/elements/popup_link-cust_main.html',
86 'label' => 'Enter check refund',
87 'action' => "${p}edit/cust_refund.cgi?popup=1;payby=BILL",
88 'cust_main' => $cust_main,
89 'actionlabel' => 'Enter check refund',
91 #default# 'height' => 336,
96 % if ( $payby{'CASH'} && $curuser->access_right(['Post refund', 'Post cash refund']) ) {
97 <% $s++ ? ' | ' : '' %>
98 <% include('/elements/popup_link-cust_main.html',
99 'label' => 'Enter cash refund',
100 'action' => "${p}edit/cust_refund.cgi?popup=1;payby=CASH",
101 'cust_main' => $cust_main,
102 'actionlabel' => 'Enter cash refund',
104 #default# 'height' => 336,
109 %# someday, perhaps. very few gateways let you do unlinked refunds at all.
110 %# Authorize.net makes you sign a special form
112 %# % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
113 %# % && $curuser->access_right('Process refund')
114 %# % && ! $cust_main->is_encrypted($cust_main->payinfo)
116 %# <% $s++ ? ' | ' : '' %>
117 %# <A HREF="<% $p %>misc/refund.cgi?payby=CARD;custnum=<% $custnum %>">Process credit card refund</A>
120 %# % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
121 %# % && $curuser->access_right('Process refund')
122 %# % && ! $cust_main->is_encrypted($cust_main->payinfo)
124 %# <% $s++ ? ' | ' : '' %>
125 %# <A HREF="<% $p %>misc/refund.cgi?payby=CHEK;custnum=<% $custnum %>">Process electronic check (ACH) refund</A>
128 % if ( $payby{'MCRD'} && $curuser->access_right('Post refund') ) {
129 <% $s++ ? ' | ' : '' %>
130 <A HREF="<% $p %>edit/cust_refund.cgi?payby=MCRD;custnum=<% $custnum %>">Post manual (offline/POS) credit card refund</A>
134 <TD ALIGN="right" VALIGN="top">
137 % if ( $curuser->access_right('List invoices') ) {
138 <A HREF="<% $p %>search/report_cust_bill.html?custnum=<% $custnum %>">Invoice reports</A>
142 %# XXX payments, credits, refund reports
144 %# tax exemption link
146 % my $view_exemptions = $curuser->access_right('View customer tax exemptions');
147 % my $add_adjustment = ( $conf->exists('enable_tax_adjustments')
148 % && $curuser->access_right('Add customer tax adjustment')
150 % if ( $view_exemptions || $add_adjustment ) {
152 % if ( $view_exemptions ) {
153 <A HREF="<% $p %>search/cust_tax_exempt_pkg.cgi?custnum=<% $custnum %>">View tax exemptions</A>
154 <% $add_adjustment ? '|' : '' %>
157 % if ( $add_adjustment ) {
158 <% include('/elements/popup_link.html', {
159 'action' => $p.'edit/cust_tax_adjustment.html?custnum='. $cust_main->custnum,
160 'label' => 'Add tax adjustment',
161 'actionlabel' => 'Add tax adjustment',
162 #'color' => '#333399',
168 <A HREF="<% $p %>search/cust_tax_adjustment.html?custnum=<% $custnum %>">View tax adjustments</A>
174 %# batched payment links
176 % if ( ( $conf->exists('batch-enable') || $conf->config('batch-enable_payby') )
177 % && $curuser->access_right('View customer batched payments')
180 View batched payments:
181 % foreach my $status (qw( Queued In-transit Complete All )) {
182 <A HREF="<% $p %>search/cust_pay_batch.cgi?status=<% $status{$status} %>;custnum=<% $custnum %>"><% $status %></A>
183 <% $status ne 'All' ? '|' : '' %>
188 %# pending payment links
190 % if ( $curuser->access_right('View customer pending payments')
191 % && scalar($cust_main->cust_pay_pending)
194 <A HREF="<% $p %>search/cust_pay_pending.html?magic=_date;statusNOT=done;custnum=<% $custnum %>">View pending payments</A><BR>
204 <% include("/elements/table-grid.html") %>
205 % my $bgcolor1 = '#eeeeee';
206 % my $bgcolor2 = '#ffffff';
210 <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
211 <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
212 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Invoice</FONT></TH>
213 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Payment</FONT></TH>
214 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
215 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Refund</FONT></TH>
216 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Balance</FONT></TH>
219 %#display payment history
221 %my $money_char = $conf->config('money_char') || '$';
223 %sub balance_forward_row {
224 % my( $b, $date, $money_char ) = @_;
225 % ( my $balance_forward = $money_char. $b ) =~ s/^\$\-/- \$/;
227 <TR ID="balance_forward_row">
228 <TD CLASS="grid" BGCOLOR="#dddddd">
229 <% time2str($date_format, $date) %>
232 <TD CLASS="grid" BGCOLOR="#dddddd">
233 <I>Starting balance on <% time2str($date_format, $date) %></I>
234 (<A HREF="javascript:void(0);" onClick="show_history();">show prior history</A>)
237 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
238 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
239 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
240 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
241 <TD CLASS="grid" BGCOLOR="#dddddd" ALIGN="right"><I><% $balance_forward %></I></TD>
249 %my $years = $conf->config('payment_history-years') || 2;
250 %my $older_than = time - $years * 31556926; #60*60*24*365.2422
253 %my $old_history = 0;
256 %foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
258 % $lastdate = $item->{'date'};
261 % if ( $item->{'date'} < $older_than ) {
262 % $display = ' STYLE="display:none" ';
268 % if ( $hidden && ! $seen++ ) {
269 % balance_forward_row($balance, $item->{'date'}, $money_char);
274 % if ( $bgcolor eq $bgcolor1 ) {
275 % $bgcolor = $bgcolor2;
277 % $bgcolor = $bgcolor1;
280 % my $charge = exists($item->{'charge'})
281 % ? sprintf("$money_char\%.2f", $item->{'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 )
412 foreach my $cust_bill ($cust_main->cust_bill) {
414 'date' => $cust_bill->_date,
415 'desc' => include('payment_history/invoice.html', $cust_bill, %opt ),
416 'charge' => $cust_bill->charged,
421 foreach my $cust_statement ($cust_main->cust_statement) {
423 'date' => $cust_statement->_date,
424 'desc' => include('payment_history/statement.html', $cust_statement, %opt ),
425 #'charge' => $cust_bill->charged,
429 #payments (some false laziness w/credits)
430 foreach my $cust_pay ($cust_main->cust_pay) {
432 'date' => $cust_pay->_date,
433 'desc' => include('payment_history/payment.html', $cust_pay, %opt ),
434 'payment' => $cust_pay->paid,
435 #'target' => $target, #XXX
440 foreach my $cust_pay_pending ($cust_main->cust_pay_pending) {
442 'date' => $cust_pay_pending->_date,
443 'desc' => include('payment_history/pending_payment.html', $cust_pay_pending, %opt ),
444 'void_payment' => $cust_pay_pending->paid,
450 foreach my $cust_pay_void ($cust_main->cust_pay_void) {
452 'date' => $cust_pay_void->_date,
453 'desc' => include('payment_history/voided_payment.html', $cust_pay_void, %opt ),
454 'void_payment' => $cust_pay_void->paid,
460 foreach my $cust_pay_pending ($cust_main->cust_pay_pending_attempt) {
462 'date' => $cust_pay_pending->_date,
463 'desc' => include('payment_history/attempted_payment.html', $cust_pay_pending, %opt ),
464 'void_payment' => $cust_pay_pending->paid, #??
465 #'target' => $target, #XXX
469 #credits (some false laziness w/payments)
470 foreach my $cust_credit ($cust_main->cust_credit) {
472 'date' => $cust_credit->_date,
473 'desc' => include('payment_history/credit.html', $cust_credit, %opt ),
474 'credit' => $cust_credit->amount,
480 foreach my $cust_refund ($cust_main->cust_refund) {
482 'date' => $cust_refund->_date,
483 'desc' => include('payment_history/refund.html', $cust_refund, %opt),
484 'refund' => $cust_refund->refund,