4 % if ( $payby{'BILL'} && $curuser->access_right(['Post payment', 'Post check payment' ]) ) {
5 <% $s++ ? ' | ' : '' %>
6 <& /elements/popup_link-cust_main.html,
7 'label' => mt('Enter check payment'),
8 'action' => "${p}edit/cust_pay.cgi?popup=1;payby=BILL",
9 'cust_main' => $cust_main,
10 'actionlabel' => mt('Enter check payment'),
15 % if ( $payby{'CASH'} && $curuser->access_right(['Post payment', 'Post cash payment']) ) {
16 <% $s++ ? ' | ' : '' %>
17 <& /elements/popup_link-cust_main.html,
18 'label' => mt('Enter cash payment'),
19 'action' => "${p}edit/cust_pay.cgi?popup=1;payby=CASH",
20 'cust_main' => $cust_main,
21 'actionlabel' => mt('Enter cash payment'),
26 % if ( $payby{'WEST'} && $curuser->access_right('Post payment') ) {
27 <% $s++ ? ' | ' : '' %>
28 <A HREF="<% $p %>edit/cust_pay.cgi?payby=WEST;custnum=<% $custnum %>"><% mt('Enter Western Union payment') |h %></A>
31 % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
32 % && $curuser->access_right(['Process payment', 'Process credit card payment'])
33 % && ! $cust_main->is_encrypted($cust_main->payinfo)
35 <% $s++ ? ' | ' : '' %>
36 <A HREF="<% $p %>misc/payment.cgi?payby=CARD;custnum=<% $custnum %>"><% mt('Process credit card payment') |h %></A>
39 % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
40 % && $curuser->access_right(['Process payment', 'Process Echeck payment'])
41 % && ! $cust_main->is_encrypted($cust_main->payinfo)
43 <% $s++ ? ' | ' : '' %>
44 <A HREF="<% $p %>misc/payment.cgi?payby=CHEK;custnum=<% $custnum %>"><% mt('Process electronic check (ACH) payment') |h %></A>
47 % if ( $payby{'MCRD'} && $curuser->access_right('Post payment') ) {
48 <% $s++ ? ' | ' : '' %>
49 <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCRD;custnum=<% $custnum %>"><% mt('Post manual (offline/POS) credit card payment') |h %></A>
56 % if ( $curuser->access_right('Post credit') ) {
57 <& /elements/popup_link-cust_main.html,
58 'label' => mt('Enter credit'),
59 'action' => "${p}edit/cust_credit.cgi",
60 'cust_main' => $cust_main,
61 'actionlabel' => mt('Enter credit'),
62 'width' => 616, #make room for reasons #540 default
70 % if ( $payby{'BILL'} && $curuser->access_right(['Post refund', 'Post check refund']) ) {
71 <% $s++ ? ' | ' : '' %>
72 <& /elements/popup_link-cust_main.html,
73 'label' => mt('Enter check refund'),
74 'action' => "${p}edit/cust_refund.cgi?popup=1;payby=BILL",
75 'cust_main' => $cust_main,
76 'actionlabel' => mt('Enter check refund'),
81 % if ( $payby{'CASH'} && $curuser->access_right(['Post refund', 'Post cash refund']) ) {
82 <% $s++ ? ' | ' : '' %>
83 <& /elements/popup_link-cust_main.html,
84 'label' => mt('Enter cash refund'),
85 'action' => "${p}edit/cust_refund.cgi?popup=1;payby=CASH",
86 'cust_main' => $cust_main,
87 'actionlabel' => mt('Enter cash refund'),
92 %# someday, perhaps. very few gateways let you do unlinked refunds at all.
93 %# Authorize.net makes you sign a special form
95 %# % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
96 %# % && $curuser->access_right('Process refund')
97 %# % && ! $cust_main->is_encrypted($cust_main->payinfo)
99 %# <% $s++ ? ' | ' : '' %>
100 %# <A HREF="<% $p %>misc/refund.cgi?payby=CARD;custnum=<% $custnum %>">Process credit card refund</A>
103 %# % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
104 %# % && $curuser->access_right('Process refund')
105 %# % && ! $cust_main->is_encrypted($cust_main->payinfo)
107 %# <% $s++ ? ' | ' : '' %>
108 %# <A HREF="<% $p %>misc/refund.cgi?payby=CHEK;custnum=<% $custnum %>">Process electronic check (ACH) refund</A>
111 % if ( $payby{'MCRD'} && $curuser->access_right('Post refund') ) {
112 <% $s++ ? ' | ' : '' %>
113 <A HREF="<% $p %>edit/cust_refund.cgi?payby=MCRD;custnum=<% $custnum %>"><% mt('Post manual (offline/POS) credit card refund') |h %></A>
118 %# tax exemption link
120 % my $view_exemptions = $curuser->access_right('View customer tax exemptions');
121 % my $add_adjustment = ( $conf->exists('enable_tax_adjustments')
122 % && $curuser->access_right('Add customer tax adjustment')
124 % if ( $view_exemptions || $add_adjustment ) {
126 % if ( $view_exemptions ) {
127 <A HREF="<% $p %>search/cust_tax_exempt_pkg.cgi?custnum=<% $custnum %>"><% mt('View tax exemptions') |h %></A>
128 <% $add_adjustment ? '|' : '' %>
131 % if ( $add_adjustment ) {
132 <& /elements/popup_link.html, {
133 'action' => $p.'edit/cust_tax_adjustment.html?custnum='. $cust_main->custnum,
134 'label' => mt('Add tax adjustment'),
135 'actionlabel' => mt('Add tax adjustment'),
140 <A HREF="<% $p %>search/cust_tax_adjustment.html?custnum=<% $custnum %>"><% mt('View tax adjustments') |h %></A>
146 %# batched payment links
148 % if ( ( $conf->exists('batch-enable') || $conf->config('batch-enable_payby') )
149 % && $curuser->access_right('View customer batched payments')
152 <% mt('View batched payments:') |h %>
153 % foreach my $status (qw( Queued In-transit Complete All )) {
154 <A HREF="<% $p %>search/cust_pay_batch.cgi?status=<% $status{$status} %>;custnum=<% $custnum %>"><% mt($status) |h %></A>
155 <% $status ne 'All' ? '|' : '' %>
160 %# pending payment links
162 % if ( $curuser->access_right('View customer pending payments')
163 % && scalar($cust_main->cust_pay_pending)
166 <A HREF="<% $p %>search/cust_pay_pending.html?magic=_date;statusNOT=done;custnum=<% $custnum %>"><% mt('View pending payments') |h %></A><BR>
171 <& /elements/table-grid.html &>
172 % my $bgcolor1 = '#eeeeee';
173 % my $bgcolor2 = '#ffffff';
177 <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Date') |h %></TH>
178 <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Description') |h %></TH>
179 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Invoice') |h %></FONT></TH>
180 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Payment') |h %></FONT></TH>
181 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>In-house Credit</FONT></TH>
182 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Refund') |h %></FONT></TH>
183 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1><% mt('Balance') |h %></FONT></TH>
186 %#display payment history
188 %my $money_char = $conf->config('money_char') || '$';
190 %sub balance_forward_row {
191 % my( $b, $date, $money_char ) = @_;
192 % ( my $balance_forward = $money_char. $b ) =~ s/^\$\-/- \$/;
194 <TR ID="balance_forward_row">
195 <TD CLASS="grid" BGCOLOR="#dddddd">
196 <% time2str($date_format, $date) %>
199 <TD CLASS="grid" BGCOLOR="#dddddd">
200 <I><% mt("Starting balance on [_1]", time2str($date_format, $date) ) |h %></I>
201 (<A HREF="javascript:void(0);" onClick="show_history();"><% mt('show prior history') |h %></A>)
204 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
205 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
206 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
207 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
208 <TD CLASS="grid" BGCOLOR="#dddddd" ALIGN="right"><I><% $balance_forward %></I></TD>
216 %my $years = $conf->config('payment_history-years') || 2;
217 %my $older_than = time - $years * 31556926; #60*60*24*365.2422
220 %my $old_history = 0;
223 %foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
225 % $lastdate = $item->{'date'};
228 % if ( $item->{'date'} < $older_than ) {
229 % $display = ' STYLE="display:none" ';
235 % if ( $hidden && ! $seen++ ) {
236 % balance_forward_row($balance, $item->{'date'}, $money_char);
241 % if ( $bgcolor eq $bgcolor1 ) {
242 % $bgcolor = $bgcolor2;
244 % $bgcolor = $bgcolor1;
247 % my $charge = exists($item->{'charge'})
248 % ? sprintf("$money_char\%.2f", $item->{'charge'})
251 % my $payment = exists($item->{'payment'})
252 % ? sprintf("- $money_char\%.2f", $item->{'payment'})
255 % $payment ||= sprintf( "<DEL>- $money_char\%.2f</DEL>",
256 % $item->{'void_payment'}
258 % if exists($item->{'void_payment'});
260 % my $credit = exists($item->{'credit'})
261 % ? sprintf("- $money_char\%.2f", $item->{'credit'})
264 % my $refund = exists($item->{'refund'})
265 % ? sprintf("$money_char\%.2f", $item->{'refund'})
268 % my $target = exists($item->{'target'}) ? $item->{'target'} : '';
270 % $balance += $item->{'charge'} if exists $item->{'charge'};
271 % $balance -= $item->{'payment'} if exists $item->{'payment'};
272 % $balance -= $item->{'credit'} if exists $item->{'credit'};
273 % $balance += $item->{'refund'} if exists $item->{'refund'};
274 % $balance = sprintf("%.2f", $balance);
275 % $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
276 % ( my $showbalance = $money_char. $balance ) =~ s/^\$\-/- \$/;
281 <TR <% $display ? $display.' ID="old_history'.$old_history++.'"' : ''%>>
282 <TD VALIGN="top" CLASS="grid" BGCOLOR="<% $bgcolor %>">
283 % unless ( !$target || $target{$target}++ ) {
285 <A NAME="<% $target %>">
288 <% time2str($date_format, $item->{'date'}) %>
289 % if ( $target && $target{$target} == 1 ) {
296 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
297 <% $item->{'desc'} %>
299 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
302 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
305 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
308 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
311 <TD VALIGN="top" ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
317 %if ( scalar(@history) && $hidden && ! $seen++ ) {
318 % balance_forward_row($balance, $lastdate, $money_char);
323 <SCRIPT TYPE="text/javascript">
325 function show_history () {
326 //alert('showing history!');
328 var balance_forward_row = document.getElementById('balance_forward_row');
330 balance_forward_row.style.display = 'none';
331 for ( var i = 0; i < <% $old_history %>; i++ ) {
332 var oldRow = document.getElementById('old_history'+i);
333 oldRow.style.display = '';
342 my( $cust_main ) = @_;
343 my $custnum = $cust_main->custnum;
345 my $conf = new FS::Conf;
346 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
348 my $curuser = $FS::CurrentUser::CurrentUser;
350 my @payby = grep /\w/, $conf->config('payby');
351 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
352 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
354 my %payby = map { $_=>1 } @payby;
357 'Queued' => 'O', #Open
359 'Complete' => 'R', #Resolved
367 ( map { $_ => scalar($conf->config($_)) }
368 qw( card_refund-days date_format )
370 ( map { $_ => $conf->exists($_) }
371 qw( deleteinvoices deletepayments deleterefunds pkg-balances )
376 foreach my $cust_bill ($cust_main->cust_bill) {
378 'date' => $cust_bill->_date,
379 'desc' => include('payment_history/invoice.html', $cust_bill, %opt ),
380 'charge' => $cust_bill->charged,
385 foreach my $cust_statement ($cust_main->cust_statement) {
387 'date' => $cust_statement->_date,
388 'desc' => include('payment_history/statement.html', $cust_statement, %opt ),
389 #'charge' => $cust_bill->charged,
393 #payments (some false laziness w/credits)
394 foreach my $cust_pay ($cust_main->cust_pay) {
396 'date' => $cust_pay->_date,
397 'desc' => include('payment_history/payment.html', $cust_pay, %opt ),
398 'payment' => $cust_pay->paid,
399 #'target' => $target, #XXX
404 foreach my $cust_pay_pending ($cust_main->cust_pay_pending) {
406 'date' => $cust_pay_pending->_date,
407 'desc' => include('payment_history/pending_payment.html', $cust_pay_pending, %opt ),
408 'void_payment' => $cust_pay_pending->paid,
414 foreach my $cust_pay_void ($cust_main->cust_pay_void) {
416 'date' => $cust_pay_void->_date,
417 'desc' => include('payment_history/voided_payment.html', $cust_pay_void, %opt ),
418 'void_payment' => $cust_pay_void->paid,
424 foreach my $cust_pay_pending ($cust_main->cust_pay_pending_attempt) {
426 'date' => $cust_pay_pending->_date,
427 'desc' => include('payment_history/attempted_payment.html', $cust_pay_pending, %opt ),
428 'void_payment' => $cust_pay_pending->paid, #??
429 #'target' => $target, #XXX
433 #credits (some false laziness w/payments)
434 foreach my $cust_credit ($cust_main->cust_credit) {
436 'date' => $cust_credit->_date,
437 'desc' => include('payment_history/credit.html', $cust_credit, %opt ),
438 'credit' => $cust_credit->amount,
444 foreach my $cust_refund ($cust_main->cust_refund) {
446 'date' => $cust_refund->_date,
447 'desc' => include('payment_history/refund.html', $cust_refund),
448 'refund' => $cust_refund->refund,
453 sub translate_payby {
454 my ($payby,$payinfo) = (shift,shift);
456 BILL => $payinfo ? mt('Check #') : '',
457 CHEK => mt('Electronic check '),
458 PREP => mt('Prepaid card '),
459 CARD => mt('Credit card #'),
460 COMP => mt('Complimentary by '),
462 WEST => mt('Western Union'),
463 MCRD => mt('Manual credit card'),
465 $payby = (exists $payby{$payby}) ? $payby{$payby} : $payby;
469 sub translate_payby_refund {
470 my ($payby,$payinfo) = (shift,shift);
472 BILL => $payinfo ? mt('Check #') : mt('Check'),
473 CHEK => mt('Electronic check '),
477 $payby = (exists $payby{$payby}) ? $payby{$payby} : $payby;