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',
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 % if ( $curuser->access_right('View customer tax exemptions') ) {
131 <A HREF="<% $p %>search/cust_tax_exempt_pkg.cgi?custnum=<% $custnum %>">View tax exemptions</A>
135 %# batched payment links
137 % if ( ( $conf->exists('batch-enable') || $conf->config('batch-enable_payby') )
138 % && $curuser->access_right('View customer batched payments')
141 View batched payments:
142 % foreach my $status (qw( Queued In-transit Complete All )) {
143 <A HREF="<% $p %>search/cust_pay_batch.cgi?status=<% $status{$status} %>;custnum=<% $custnum %>"><% $status %></A>
144 <% $status ne 'All' ? '|' : '' %>
149 %# pending payment links
151 % if ( $curuser->access_right('View customer pending payments')
152 % && scalar($cust_main->cust_pay_pending)
155 <A HREF="<% $p %>search/cust_pay_pending.html?magic=_date;statusNOT=done;custnum=<% $custnum %>">View pending payments</A><BR>
160 <% include("/elements/table-grid.html") %>
161 % my $bgcolor1 = '#eeeeee';
162 % my $bgcolor2 = '#ffffff';
166 <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
167 <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
168 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Invoice</FONT></TH>
169 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Payment</FONT></TH>
170 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
171 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Refund</FONT></TH>
172 <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Balance</FONT></TH>
175 %#display payment history
177 %my $money_char = $conf->config('money_char') || '$';
179 %sub balance_forward_row {
180 % my( $b, $date, $money_char ) = @_;
181 % ( my $balance_forward = $money_char. $b ) =~ s/^\$\-/- \$/;
183 <TR ID="balance_forward_row">
184 <TD CLASS="grid" BGCOLOR="#dddddd">
185 <% time2str("%D",$date) %>
188 <TD CLASS="grid" BGCOLOR="#dddddd">
189 <I>Starting balance on <% time2str("%D",$date) %></I>
190 (<A HREF="javascript:void(0);" onClick="show_history();">show prior history</A>)
193 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
194 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
195 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
196 <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
197 <TD CLASS="grid" BGCOLOR="#dddddd" ALIGN="right"><I><% $balance_forward %></I></TD>
205 %my $years = $conf->config('payment_history-years') || 2;
206 %my $older_than = time - $years * 31556736; #60*60*24*365.24
209 %my $old_history = 0;
212 %foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
214 % $lastdate = $item->{'date'};
217 % if ( $item->{'date'} < $older_than ) {
218 % $display = ' STYLE="display:none" ';
224 % if ( $hidden && ! $seen++ ) {
225 % balance_forward_row($balance, $item->{'date'}, $money_char);
230 % if ( $bgcolor eq $bgcolor1 ) {
231 % $bgcolor = $bgcolor2;
233 % $bgcolor = $bgcolor1;
236 % my $charge = exists($item->{'charge'})
237 % ? sprintf("$money_char\%.2f", $item->{'charge'})
240 % my $payment = exists($item->{'payment'})
241 % ? sprintf("- $money_char\%.2f", $item->{'payment'})
244 % $payment ||= sprintf( "<DEL>- $money_char\%.2f</DEL>",
245 % $item->{'void_payment'}
247 % if exists($item->{'void_payment'});
249 % my $credit = exists($item->{'credit'})
250 % ? sprintf("- $money_char\%.2f", $item->{'credit'})
253 % my $refund = exists($item->{'refund'})
254 % ? sprintf("$money_char\%.2f", $item->{'refund'})
257 % my $target = exists($item->{'target'}) ? $item->{'target'} : '';
259 % $balance += $item->{'charge'} if exists $item->{'charge'};
260 % $balance -= $item->{'payment'} if exists $item->{'payment'};
261 % $balance -= $item->{'credit'} if exists $item->{'credit'};
262 % $balance += $item->{'refund'} if exists $item->{'refund'};
263 % $balance = sprintf("%.2f", $balance);
264 % $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
265 % ( my $showbalance = $money_char. $balance ) =~ s/^\$\-/- \$/;
270 <TR <% $display ? $display.' ID="old_history'.$old_history++.'"' : ''%>>
271 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
272 % unless ( !$target || $target{$target}++ ) {
274 <A NAME="<% $target %>">
277 <% time2str("%D",$item->{'date'}) %>
278 % if ( $target && $target{$target} == 1 ) {
285 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
286 <% $item->{'desc'} %>
288 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
291 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
294 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
297 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
300 <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
306 %if ( scalar(@history) && $hidden && ! $seen++ ) {
307 % balance_forward_row($balance, $lastdate, $money_char);
312 <SCRIPT TYPE="text/javascript">
314 function show_history () {
315 //alert('showing history!');
317 var balance_forward_row = document.getElementById('balance_forward_row');
319 balance_forward_row.style.display = 'none';
320 for ( var i = 0; i < <% $old_history %>; i++ ) {
321 var oldRow = document.getElementById('old_history'+i);
322 oldRow.style.display = '';
331 my( $cust_main ) = @_;
332 my $custnum = $cust_main->custnum;
334 my $conf = new FS::Conf;
336 my $curuser = $FS::CurrentUser::CurrentUser;
338 my @payby = grep /\w/, $conf->config('payby');
339 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
340 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
342 my %payby = map { $_=>1 } @payby;
345 'Queued' => 'O', #Open
347 'Complete' => 'R', #Resolved
355 ( map { $_ => scalar($conf->config($_)) }
356 qw( card_refund-days )
358 ( map { $_ => $conf->exists($_) }
359 qw( deletepayments deleterefunds )
363 foreach my $cust_bill ($cust_main->cust_bill) {
365 'date' => $cust_bill->_date,
366 'desc' => include('payment_history/invoice.html', $cust_bill, %opt ),
367 'charge' => $cust_bill->charged,
371 #payments (some false laziness w/credits)
372 foreach my $cust_pay ($cust_main->cust_pay) {
374 'date' => $cust_pay->_date,
375 'desc' => include('payment_history/payment.html', $cust_pay, %opt ),
376 'payment' => $cust_pay->paid,
377 #'target' => $target, #XXX
382 foreach my $cust_pay_void ($cust_main->cust_pay_void) {
384 'date' => $cust_pay_void->_date,
385 'desc' => include('payment_history/voided_payment.html', $cust_pay_void),
386 'void_payment' => $cust_pay_void->paid,
391 #credits (some false laziness w/payments)
392 foreach my $cust_credit ($cust_main->cust_credit) {
394 'date' => $cust_credit->_date,
395 'desc' => include('payment_history/credit.html', $cust_credit),
396 'credit' => $cust_credit->amount,
402 foreach my $cust_refund ($cust_main->cust_refund) {
404 'date' => $cust_refund->_date,
405 'desc' => include('payment_history/refund.html', $cust_refund),
406 'refund' => $cust_refund->refund,