4 % if ( $payby{'BILL'} && $curuser->access_right('Post payment') ) {
5 <% $s++ ? ' | ' : '' %>
6 <% include('/elements/popup_link-cust_main.html',
7 'label' => 'Enter check payment',
8 'action' => "${p}edit/cust_pay.cgi?popup=1;payby=BILL",
9 'cust_main' => $cust_main,
10 'actionlabel' => 'Enter check payment',
12 #default# 'height' => 336,
17 % if ( $payby{'CASH'} && $curuser->access_right('Post payment') ) {
18 <% $s++ ? ' | ' : '' %>
19 <% include('/elements/popup_link-cust_main.html',
20 'label' => 'Enter cash payment',
21 'action' => "${p}edit/cust_pay.cgi?popup=1;payby=CASH",
22 'cust_main' => $cust_main,
23 'actionlabel' => 'Enter cash payment',
25 #default# 'height' => 336,
30 % if ( $payby{'WEST'} && $curuser->access_right('Post payment') ) {
31 <% $s++ ? ' | ' : '' %>
32 <A HREF="<% $p %>edit/cust_pay.cgi?payby=WEST;custnum=<% $custnum %>">Enter Western Union payment</A>
35 % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
36 % && $curuser->access_right('Process payment')
37 % && ! $cust_main->is_encrypted($cust_main->payinfo)
39 <% $s++ ? ' | ' : '' %>
40 <A HREF="<% $p %>misc/payment.cgi?payby=CARD;custnum=<% $custnum %>">Process credit card payment</A>
43 % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
44 % && $curuser->access_right('Process payment')
45 % && ! $cust_main->is_encrypted($cust_main->payinfo)
47 <% $s++ ? ' | ' : '' %>
48 <A HREF="<% $p %>misc/payment.cgi?payby=CHEK;custnum=<% $custnum %>">Process electronic check (ACH) payment</A>
51 % if ( $payby{'MCRD'} && $curuser->access_right('Post payment') ) {
52 <% $s++ ? ' | ' : '' %>
53 <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCRD;custnum=<% $custnum %>">Post manual (offline/POS) credit card payment</A>
60 % if ( $curuser->access_right('Post credit') ) {
61 <% include('/elements/popup_link-cust_main.html',
62 'label' => 'Enter credit',
63 'action' => "${p}edit/cust_credit.cgi",
64 'cust_main' => $cust_main,
65 'actionlabel' => 'Enter credit',
66 'width' => 616, #make room for reasons #540 default
67 #default# 'height' => 336,
76 % if ( $payby{'BILL'} && $curuser->access_right('Post refund') ) {
77 <% $s++ ? ' | ' : '' %>
78 <% include('/elements/popup_link-cust_main.html',
79 'label' => 'Enter check refund',
80 'action' => "${p}edit/cust_refund.cgi?popup=1;payby=BILL",
81 'cust_main' => $cust_main,
82 'actionlabel' => 'Enter check refund',
84 #default# 'height' => 336,
89 % if ( $payby{'CASH'} && $curuser->access_right('Post refund') ) {
90 <% $s++ ? ' | ' : '' %>
91 <% include('/elements/popup_link-cust_main.html',
92 'label' => 'Enter cash refund',
93 'action' => "${p}edit/cust_refund.cgi?popup=1;payby=CASH",
94 'cust_main' => $cust_main,
95 'actionlabel' => 'Enter cash refund',
97 #default# 'height' => 336,
102 %# someday, perhaps. very few gateways let you do unlinked refunds at all.
103 %# Authorize.net makes you sign a special form
105 %# % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
106 %# % && $curuser->access_right('Process refund')
107 %# % && ! $cust_main->is_encrypted($cust_main->payinfo)
109 %# <% $s++ ? ' | ' : '' %>
110 %# <A HREF="<% $p %>misc/refund.cgi?payby=CARD;custnum=<% $custnum %>">Process credit card refund</A>
113 %# % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
114 %# % && $curuser->access_right('Process refund')
115 %# % && ! $cust_main->is_encrypted($cust_main->payinfo)
117 %# <% $s++ ? ' | ' : '' %>
118 %# <A HREF="<% $p %>misc/refund.cgi?payby=CHEK;custnum=<% $custnum %>">Process electronic check (ACH) refund</A>
121 % if ( $payby{'MCRD'} && $curuser->access_right('Post refund') ) {
122 <% $s++ ? ' | ' : '' %>
123 <A HREF="<% $p %>edit/cust_refund.cgi?payby=MCRD;custnum=<% $custnum %>">Post manual (offline/POS) credit card refund</A>
128 %# tax exemption link
130 % my $view_exemptions = $curuser->access_right('View customer tax exemptions');
131 % my $add_adjustment = ( $conf->exists('enable_tax_adjustments')
132 % && $curuser->access_right('Add customer tax adjustment')
134 % if ( $view_exemptions || $add_adjustment ) {
136 % if ( $view_exemptions ) {
137 <A HREF="<% $p %>search/cust_tax_exempt_pkg.cgi?custnum=<% $custnum %>">View tax exemptions</A>
138 <% $add_adjustment ? '|' : '' %>
141 % if ( $add_adjustment ) {
142 <% include('/elements/popup_link.html', {
143 'action' => $p.'edit/cust_tax_adjustment.html?custnum='. $cust_main->custnum,
144 'label' => 'Add tax adjustment',
145 'actionlabel' => 'Add tax adjustment',
146 #'color' => '#333399',
152 <A HREF="<% $p %>search/cust_tax_adjustment.html?custnum=<% $custnum %>">View tax adjustments</A>
158 %# batched payment links
160 % if ( ( $conf->exists('batch-enable') || $conf->config('batch-enable_payby') )
161 % && $curuser->access_right('View customer batched payments')
164 View batched payments:
165 % foreach my $status (qw( Queued In-transit Complete All )) {
166 <A HREF="<% $p %>search/cust_pay_batch.cgi?status=<% $status{$status} %>;custnum=<% $custnum %>"><% $status %></A>
167 <% $status ne 'All' ? '|' : '' %>
172 %# pending payment links
174 % if ( $curuser->access_right('View customer pending payments')
175 % && scalar($cust_main->cust_pay_pending)
178 <A HREF="<% $p %>search/cust_pay_pending.html?magic=_date;statusNOT=done;custnum=<% $custnum %>">View pending payments</A><BR>
183 <% include("/elements/table-grid.html") %>
184 % my $bgcolor1 = '#eeeeee';
185 % my $bgcolor2 = '#ffffff';
189 <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
190 <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
191 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Invoice</FONT></TH>
192 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Payment</FONT></TH>
193 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
194 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Refund</FONT></TH>
195 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Balance</FONT></TH>
198 %#display payment history
200 %my $money_char = $conf->config('money_char') || '$';
202 %sub balance_forward_row {
203 % my( $b, $date, $money_char ) = @_;
204 % ( my $balance_forward = $money_char. $b ) =~ s/^\$\-/- \$/;
206 <TR ID="balance_forward_row">
207 <TD CLASS="grid" BGCOLOR="#dddddd">
208 <% time2str("%D",$date) %>
211 <TD CLASS="grid" BGCOLOR="#dddddd">
212 <I>Starting balance on <% time2str("%D",$date) %></I>
213 (<A HREF="javascript:void(0);" onClick="show_history();">show prior history</A>)
216 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
217 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
218 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
219 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
220 <TD CLASS="grid" BGCOLOR="#dddddd" ALIGN="right"><I><% $balance_forward %></I></TD>
228 %my $years = $conf->config('payment_history-years') || 2;
229 %my $older_than = time - $years * 31556926; #60*60*24*365.2422
232 %my $old_history = 0;
235 %foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
237 % $lastdate = $item->{'date'};
240 % if ( $item->{'date'} < $older_than ) {
241 % $display = ' STYLE="display:none" ';
247 % if ( $hidden && ! $seen++ ) {
248 % balance_forward_row($balance, $item->{'date'}, $money_char);
253 % if ( $bgcolor eq $bgcolor1 ) {
254 % $bgcolor = $bgcolor2;
256 % $bgcolor = $bgcolor1;
259 % my $charge = exists($item->{'charge'})
260 % ? sprintf("$money_char\%.2f", $item->{'charge'})
263 % my $payment = exists($item->{'payment'})
264 % ? sprintf("- $money_char\%.2f", $item->{'payment'})
267 % $payment ||= sprintf( "<DEL>- $money_char\%.2f</DEL>",
268 % $item->{'void_payment'}
270 % if exists($item->{'void_payment'});
272 % my $credit = exists($item->{'credit'})
273 % ? sprintf("- $money_char\%.2f", $item->{'credit'})
276 % my $refund = exists($item->{'refund'})
277 % ? sprintf("$money_char\%.2f", $item->{'refund'})
280 % my $target = exists($item->{'target'}) ? $item->{'target'} : '';
282 % $balance += $item->{'charge'} if exists $item->{'charge'};
283 % $balance -= $item->{'payment'} if exists $item->{'payment'};
284 % $balance -= $item->{'credit'} if exists $item->{'credit'};
285 % $balance += $item->{'refund'} if exists $item->{'refund'};
286 % $balance = sprintf("%.2f", $balance);
287 % $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
288 % ( my $showbalance = $money_char. $balance ) =~ s/^\$\-/- \$/;
293 <TR <% $display ? $display.' ID="old_history'.$old_history++.'"' : ''%>>
294 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
295 % unless ( !$target || $target{$target}++ ) {
297 <A NAME="<% $target %>">
300 <% time2str("%D",$item->{'date'}) %>
301 % if ( $target && $target{$target} == 1 ) {
308 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
309 <% $item->{'desc'} %>
311 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
314 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
317 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
320 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
323 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
329 %if ( scalar(@history) && $hidden && ! $seen++ ) {
330 % balance_forward_row($balance, $lastdate, $money_char);
335 <SCRIPT TYPE="text/javascript">
337 function show_history () {
338 //alert('showing history!');
340 var balance_forward_row = document.getElementById('balance_forward_row');
342 balance_forward_row.style.display = 'none';
343 for ( var i = 0; i < <% $old_history %>; i++ ) {
344 var oldRow = document.getElementById('old_history'+i);
345 oldRow.style.display = '';
354 my( $cust_main ) = @_;
355 my $custnum = $cust_main->custnum;
357 my $conf = new FS::Conf;
359 my $curuser = $FS::CurrentUser::CurrentUser;
361 my @payby = grep /\w/, $conf->config('payby');
362 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
363 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
365 my %payby = map { $_=>1 } @payby;
368 'Queued' => 'O', #Open
370 'Complete' => 'R', #Resolved
378 ( map { $_ => scalar($conf->config($_)) }
379 qw( card_refund-days )
381 ( map { $_ => $conf->exists($_) }
382 qw( deleteinvoices deletepayments deleterefunds pkg-balances )
387 foreach my $cust_bill ($cust_main->cust_bill) {
389 'date' => $cust_bill->_date,
390 'desc' => include('payment_history/invoice.html', $cust_bill, %opt ),
391 'charge' => $cust_bill->charged,
396 foreach my $cust_statement ($cust_main->cust_statement) {
398 'date' => $cust_statement->_date,
399 'desc' => include('payment_history/statement.html', $cust_statement, %opt ),
400 #'charge' => $cust_bill->charged,
404 #payments (some false laziness w/credits)
405 foreach my $cust_pay ($cust_main->cust_pay) {
407 'date' => $cust_pay->_date,
408 'desc' => include('payment_history/payment.html', $cust_pay, %opt ),
409 'payment' => $cust_pay->paid,
410 #'target' => $target, #XXX
415 foreach my $cust_pay_void ($cust_main->cust_pay_void) {
417 'date' => $cust_pay_void->_date,
418 'desc' => include('payment_history/voided_payment.html', $cust_pay_void, %opt ),
419 'void_payment' => $cust_pay_void->paid,
424 #credits (some false laziness w/payments)
425 foreach my $cust_credit ($cust_main->cust_credit) {
427 'date' => $cust_credit->_date,
428 'desc' => include('payment_history/credit.html', $cust_credit, %opt ),
429 'credit' => $cust_credit->amount,
435 foreach my $cust_refund ($cust_main->cust_refund) {
437 'date' => $cust_refund->_date,
438 'desc' => include('payment_history/refund.html', $cust_refund),
439 'refund' => $cust_refund->refund,