add link to customer tax exemptions to customer view page
[freeside.git] / httemplate / view / cust_main / payment_history.html
1
2
3 <BR><BR><A NAME="history"><FONT SIZE="+2">Payment History</FONT></A><BR>
4
5 % my $s = 0;
6 % if ( $payby{'BILL'} && $curuser->access_right('Post payment') ) { 
7
8   <% $s++ ? ' | ' : '' %>
9   <A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('<% $p %>edit/cust_pay.cgi?popup=1;payby=BILL;custnum=<% $custnum %>', 392, 336, 'cust_pay_popup' ), CAPTION, 'Enter check payment', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">Enter check payment</A>
10 % } 
11 % if ( $payby{'CASH'} && $curuser->access_right('Post payment') ) { 
12
13
14   <% $s++ ? ' | ' : '' %>
15   <A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('<% $p %>edit/cust_pay.cgi?popup=1;payby=CASH;custnum=<% $custnum %>', 392, 336, 'cust_pay_popup' ), CAPTION, 'Enter cash payment', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">Enter cash payment</A>
16 % } 
17 % if ( $payby{'WEST'} && $curuser->access_right('Post payment') ) { 
18
19
20   <% $s++ ? ' | ' : '' %>
21   <A HREF="<% $p %>edit/cust_pay.cgi?payby=WEST;custnum=<% $custnum %>">Enter Western Union payment</A>
22 % } 
23 % if ( ( $payby{'CARD'} || $payby{'DCRD'} )
24 %        && $curuser->access_right('Process payment')
25 %      ) {
26 %
27
28
29   <% $s++ ? ' | ' : '' %>
30   <A HREF="<% $p %>misc/payment.cgi?payby=CARD;custnum=<% $custnum %>">Process credit card payment</A>
31 % } 
32 % if ( ( $payby{'CHEK'} || $payby{'DCHK'} )
33 %        && $curuser->access_right('Process payment')
34 %      ) {
35 %
36
37
38   <% $s++ ? ' | ' : '' %>
39   <A HREF="<% $p %>misc/payment.cgi?payby=CHEK;custnum=<% $custnum %>">Process electronic check (ACH) payment</A>
40 % } 
41 % if ( $payby{'MCRD'} && $curuser->access_right('Post payment') ) { 
42
43
44   <% $s++ ? ' | ' : '' %>
45   <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCRD;custnum=<% $custnum %>">Post manual (offline) credit card payment</A>
46 % } 
47
48 <BR>
49
50 % if ( $curuser->access_right('Post credit') ) { 
51   <A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('<% $p %>edit/cust_credit.cgi?<% $custnum %>', 392, 336, 'cust_credit_popup' ), CAPTION, 'Enter credit', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">Enter credit</A>
52   <BR>
53 % } 
54
55 % if ( $curuser->access_right('View customer tax exemptions') ) { 
56   <A HREF="<% $p %>search/cust_tax_exempt_pkg.cgi?custnum=<% $custnum %>">View tax exemptions</A>
57   <BR>
58 % } 
59
60
61
62 %#get payment history
63 %my @history = ();
64 %
65 %#invoices
66 %foreach my $cust_bill ($cust_main->cust_bill) {
67 %  my $pre = ( $cust_bill->owed > 0 )
68 %              ? '<B><FONT SIZE="+1" COLOR="#FF0000">Open '
69 %              : '';
70 %  my $post = ( $cust_bill->owed > 0 ) ? '</FONT></B>' : '';
71 %  my $invnum = $cust_bill->invnum;
72 %  my $link = $curuser->access_right('View invoices')
73 %               ? qq!<A HREF="${p}view/cust_bill.cgi?$invnum">!
74 %               : '';
75 %  push @history, {
76 %    'date'   => $cust_bill->_date,
77 %    'desc'   => $link. $pre.
78 %                "Invoice #$invnum (Balance \$". $cust_bill->owed. ')'.
79 %                $post. ( $link ? '</A>' : '' ),
80 %    'charge' => $cust_bill->charged,
81 %  };
82 %}
83 %
84 %#payments (some false laziness w/credits)
85 %foreach my $cust_pay ($cust_main->cust_pay) {
86 %
87 %  my $payby = $cust_pay->payby;
88 %
89 %  my $payinfo;
90 %  if ( $payby eq 'CARD' ) {
91 %    $payinfo = $cust_pay->payinfo_masked;
92 %  } elsif ( $payby eq 'CHEK' && $cust_pay->payinfo =~ /^(\d+)\@(\d+)$/ ) {
93 %    $payinfo = "ABA $2, Acct# $1";
94 %  } else {
95 %    $payinfo = $cust_pay->payinfo;
96 %  }
97 %  my @cust_bill_pay = $cust_pay->cust_bill_pay;
98 %  my @cust_pay_refund = $cust_pay->cust_pay_refund;
99 %
100 %  my $target = "$payby$payinfo";
101 %  $payby =~ s/^BILL$/Check #/ if $payinfo;
102 %  $payby =~ s/^CHEK$/Electronic check /;
103 %  $payby =~ s/^PREP$/Prepaid card /;
104 %  $payby =~ s/^CARD$/Credit card #/; 
105 %  $payby =~ s/^COMP$/Complimentary by /; 
106 %  $payby =~ s/^CASH$/Cash/;
107 %  $payby =~ s/^WEST$/Western Union/;
108 %  $payby =~ s/^MCRD$/Manual credit card/;
109 %  $payby =~ s/^BILL$//;
110 %  my $info = $payby ? " ($payby$payinfo)" : '';
111 %
112 %  my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
113 %  if (    scalar(@cust_bill_pay)   == 0
114 %       && scalar(@cust_pay_refund) == 0 ) {
115 %    #completely unapplied
116 %    $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
117 %    $post = '</FONT></B>';
118 %    $apply = qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_bill_pay.cgi?!.
119 %             $cust_pay->paynum.
120 %             qq!', 392, 336, 'cust_bill_pay_popup' ), CAPTION, 'Apply payment', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!;
121 %
122 %  } elsif (    scalar(@cust_bill_pay)   == 1
123 %            && scalar(@cust_pay_refund) == 0
124 %            && $cust_pay->unapplied == 0     ) {
125 %    #applied to one invoice, the usual situation
126 %    $desc = ' applied to Invoice #'. $cust_bill_pay[0]->invnum;
127 %  } elsif (    scalar(@cust_bill_pay)   == 0
128 %            && scalar(@cust_pay_refund) == 1
129 %            && $cust_pay->unapplied == 0     ) {
130 %    #applied to one refund
131 %    $desc = ' refunded on '. time2str("%D", $cust_pay_refund[0]->_date);
132 %  } else {
133 %    #complicated
134 %    $desc = '<BR>';
135 %    foreach my $app ( sort { $a->_date <=> $b->_date }
136 %                           ( @cust_bill_pay, @cust_pay_refund ) ) {
137 %      if ( $app->isa('FS::cust_bill_pay') ) {
138 %        $desc .= '&nbsp;&nbsp;'.
139 %                 '$'. $app->amount.
140 %                 ' applied to Invoice #'. $app->invnum.
141 %                 '<BR>';
142 %                 #' on '. time2str("%D", $cust_bill_pay->_date).
143 %      } elsif ( $app->isa('FS::cust_pay_refund') ) {
144 %        $desc .= '&nbsp;&nbsp;'.
145 %                 '$'. $app->amount.
146 %                 ' refunded on '. time2str("%D", $app->_date).
147 %                 '<BR>';
148 %      } else {
149 %        die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
150 %      }
151 %    }
152 %    if ( $cust_pay->unapplied > 0 ) {
153 %      $desc .= '&nbsp;&nbsp;'.
154 %               '<B><FONT COLOR="#FF0000">$'.
155 %               $cust_pay->unapplied. ' unapplied</FONT></B>'.
156 %               qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_bill_pay.cgi?!.
157 %               $cust_pay->paynum. 
158 %               qq!', 392, 336, 'cust_bill_pay_popup' ), CAPTION, 'Apply payment', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!.
159 %               '<BR>';
160 %    }
161 %  }
162 %
163 %  my $refund = '';
164 %  my $refund_days = $conf->config('card_refund-days') || 120;
165 %  if (    $cust_pay->closed !~ /^Y/i
166 %       && $cust_pay->payby =~ /^(CARD|CHEK)$/
167 %       && time-$cust_pay->_date < $refund_days*86400
168 %       && $cust_pay->unrefunded > 0
169 %       && $curuser->access_right('Refund payment')
170 %  ) {
171 %    $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
172 %              qq!paynum=!. $cust_pay->paynum. '"'.
173 %              qq! TITLE="Send a refund for this payment to the payment gateway"!.
174 %              qq!>refund</A>)!;
175 %  }
176 %
177 %  my $void = '';
178 %  if (    $cust_pay->closed !~ /^Y/i
179 %       && (    ( $cust_pay->payby eq 'CARD'
180 %                 && $curuser->access_right('Credit card void')
181 %               )
182 %            || ( $cust_pay->payby eq 'CHEK'
183 %                 && $curuser->access_right('Echeck void')
184 %               )
185 %            || ( $cust_pay->payby !~ /^(CARD|CHEK)$/
186 %                 && $curuser->access_right('Regular void')
187 %               )
188 %          )
189 %     )
190 %  {
191 %    $void = qq! (<A HREF="javascript:areyousure('!.
192 %            qq!${p}misc/void-cust_pay.cgi?!. $cust_pay->paynum.
193 %            qq!', 'Are you sure you want to void this payment?')"!.
194 %            qq! TITLE="Void this payment from the database!.
195 %              ( $cust_pay->payby =~ /^(CARD|CHEK)$/
196 %                ? ' (do not send anything to the payment gateway)'
197 %                : '' 
198 %              ). '"'.
199 %            qq!>void</A>)!;
200 %  }
201 %
202 %  my $delete = '';
203 %  if ( $cust_pay->closed !~ /^Y/i
204 %       && $conf->exists('deletepayments')
205 %       && $curuser->access_right('Delete payment')
206 %     )
207 %  {
208 %    $delete = qq! (<A HREF="javascript:areyousure('!.
209 %              qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
210 %              qq!', 'Are you sure you want to delete this payment?')"!.
211 %              qq! TITLE="Delete this payment from the database completely - not recommended"!.
212 %              qq!>delete</A>)!;
213 %  }
214 %
215 %  my $unapply = '';
216 %  if (    $cust_pay->closed !~ /^Y/i
217 %       && scalar(@cust_bill_pay)           
218 %       && $curuser->access_right('Unapply payment')
219 %     )
220 %  {
221 %    $unapply = qq! (<A HREF="javascript:areyousure('!.
222 %               qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
223 %               qq!', 'Are you sure you want to unapply this payment?')"!.
224 %               qq! TITLE="Keep this payment, but dissociate it from the invoices it is currently applied against"!.
225 %               qq!>unapply</A>)!;
226 %  }
227 %
228 %  push @history, {
229 %    'date'    => $cust_pay->_date,
230 %    'desc'    => $pre. "Payment$post$info$desc".
231 %                 "$apply$refund$void$delete$unapply",
232 %    'payment' => $cust_pay->paid,
233 %    'target'  => $target,
234 %  };
235 %}
236 %
237 %#voided payments
238 %foreach my $cust_pay_void ($cust_main->cust_pay_void) {
239 %
240 %  my $payby = $cust_pay_void->payby;
241 %  my $payinfo = $payby eq 'CARD'
242 %                  ? $cust_pay_void->payinfo_masked
243 %                  : $cust_pay_void->payinfo;
244 %
245 %  $payby =~ s/^BILL$/Check #/ if $payinfo;
246 %  $payby =~ s/^CHEK$/Electronic check /;
247 %  $payby =~ s/^BILL$//;
248 %  $payby =~ s/^(CARD|COMP)$/$1 /;
249 %  my $info = $payby ? " ($payby$payinfo)" : '';
250 %
251 %  my $unvoid = '';
252 %  if ( $cust_pay_void->closed !~ /^Y/i
253 %       && $curuser->access_right('Unvoid')
254 %     )
255 %  {
256 %    $unvoid = qq! (<A HREF="javascript:areyousure('!.
257 %              qq!${p}misc/unvoid-cust_pay_void.cgi?!. $cust_pay_void->paynum.
258 %              qq!', 'Are you sure you want to unvoid this payment?')"!.
259 %              qq! TITLE="Unvoid this payment from the database!.
260 %                ( $cust_pay_void->payby =~ /^(CARD|CHEK)$/
261 %                  ? ' (do not send anything to the payment gateway)'
262 %                  : '' 
263 %                ). '"'.
264 %              qq!>unvoid</A>)!;
265 %  }
266 %
267 %  push @history, {
268 %    'date'   => $cust_pay_void->_date,
269 %    'desc'   => "<DEL>Payment $info</DEL> <I>voided ".
270 %                time2str("%D", $cust_pay_void->void_date).
271 %                " by ". $cust_pay_void->otaker. '</i>'. $unvoid,
272 %    'void_payment' => $cust_pay_void->paid,
273 %  };
274 %
275 %}
276 %
277 %#credits (some false laziness w/payments)
278 %foreach my $cust_credit ($cust_main->cust_credit) {
279 %
280 %  my @cust_credit_bill = $cust_credit->cust_credit_bill;
281 %  my @cust_credit_refund = $cust_credit->cust_credit_refund;
282 %
283 %  my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
284 %  if (    scalar(@cust_credit_bill)   == 0
285 %       && scalar(@cust_credit_refund) == 0 ) {
286 %    #completely unapplied
287 %    $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
288 %    $post = '</FONT></B>';
289 %    $apply = qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_credit_bill.cgi?!.
290 %             $cust_credit->crednum.
291 %             qq!', 392, 336, 'cust_credit_bill_popup' ), CAPTION, 'Apply credit', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!;
292 %  } elsif (    scalar(@cust_credit_bill)   == 1
293 %            && scalar(@cust_credit_refund) == 0
294 %            && $cust_credit->credited == 0      ) {
295 %    #applied to one invoice, the usual situation
296 %    $desc = ' applied to Invoice #'. $cust_credit_bill[0]->invnum;
297 %  } elsif (    scalar(@cust_credit_bill)   == 0
298 %            && scalar(@cust_credit_refund) == 1
299 %            && $cust_credit->credited == 0      ) {
300 %    #applied to one refund
301 %    $desc = ' refunded on '.  time2str("%D", $cust_credit_refund[0]->_date);
302 %  } else {
303 %    #complicated
304 %    $desc = '<BR>';
305 %    foreach my $app ( sort { $a->_date <=> $b->_date }
306 %                           ( @cust_credit_bill, @cust_credit_refund ) ) {
307 %      if ( $app->isa('FS::cust_credit_bill') ) {
308 %        $desc .= '&nbsp;&nbsp;'.
309 %                 '$'. $app->amount.
310 %                 ' applied to Invoice #'. $app->invnum.
311 %                 '<BR>';
312 %                 #' on '. time2str("%D", $app->_date).
313 %      } elsif ( $app->isa('FS::cust_credit_refund') ) {
314 %        $desc .= '&nbsp;&nbsp;'.
315 %                 '$'. $app->amount.
316 %                 ' refunded on '. time2str("%D", $app->_date).
317 %                 '<BR>';
318 %      } else {
319 %        die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
320 %      }
321 %    }
322 %    if ( $cust_credit->credited > 0 ) {
323 %      $desc .= '&nbsp;&nbsp;<B><FONT COLOR="#FF0000">$'.
324 %               $cust_credit->credited. ' unapplied</FONT></B>'.
325 %               qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_credit_bill.cgi?!.
326 %               $cust_credit->crednum.
327 %               qq!', 392, 336, 'cust_credit_bill_popup' ), CAPTION, 'Apply credit', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">apply</A>)!.
328 %               '<BR>';
329 %    }
330 %  }
331 %#
332 %  my $delete = '';
333 %  if ( $cust_credit->closed !~ /^Y/i
334 %
335 %       #s'pose deleting a credit isn't bad like deleting a payment
336 %       # and this needs to be generally available until we have credit voiding..
337 %       #&& $conf->exists('deletecredits')
338 %
339 %       && $curuser->access_right('Delete credit')
340 %     )
341 %  {
342 %    $delete = qq! (<A HREF="javascript:areyousure('!.
343 %              qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
344 %              qq!', 'Are you sure you want to delete this credit?')">!.
345 %              qq!delete</A>)!;
346 %  }
347 %  
348 %  my $unapply = '';
349 %  if (    $cust_credit->closed !~ /^Y/i
350 %       && scalar(@cust_credit_bill)
351 %       && $curuser->access_right('Unapply credit')
352 %     )
353 %  {
354 %    $unapply = qq! (<A HREF="javascript:areyousure('!.
355 %               qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
356 %               qq!', 'Are you sure you want to unapply this credit?')">!.
357 %               qq!unapply</A>)!;
358 %  }
359 %  
360 %  push @history, {
361 %    'date'   => $cust_credit->_date,
362 %    'desc'   => $pre. "Credit$post by ". $cust_credit->otaker.
363 %                ( $cust_credit->reason
364 %                   ? ' ('. $cust_credit->reason. ')'
365 %                   : ''
366 %               ).
367 %                "$desc$apply$delete$unapply",
368 %    'credit' => $cust_credit->amount,
369 %  };
370 %
371 %}
372 %
373 %#refunds
374 %foreach my $cust_refund ($cust_main->cust_refund) {
375 %
376 %  my $payby = $cust_refund->payby;
377 %  my $payinfo = $payby eq 'CARD'
378 %                  ? $cust_refund->payinfo_masked
379 %                  : $cust_refund->payinfo;
380 %
381 %  $payby =~ s/^BILL$/Check #/ if $payinfo;
382 %  $payby =~ s/^CHEK$/Electronic check /;
383 %  $payby =~ s/^(CARD|COMP)$/$1 /;
384 %
385 %  push @history, {
386 %    'date'   => $cust_refund->_date,
387 %    'desc'   => "Refund ($payby$payinfo) by ". $cust_refund->otaker,
388 %    'refund' => $cust_refund->refund,
389 %  };
390 %
391 %}
392 %
393 %
394
395
396 <% include("/elements/table-grid.html") %>
397 % my $bgcolor1 = '#eeeeee';
398 %   my $bgcolor2 = '#ffffff';
399 %   my $bgcolor = '';
400 %
401
402
403 <TR>
404   <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
405   <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
406   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Charge</FONT></TH>
407   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Payment</FONT></TH>
408   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
409   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Refund</FONT></TH>
410   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Balance</FONT></TH>
411 </TR>
412 %
413 %#display payment history
414 %
415 %my $balance = 0;
416 %my %target = ();
417 %my $money_char = $conf->config('money_char') || '$';
418 %
419 %my $years =  $conf->config('payment_history-years') || 2;
420 %my $older_than = time - $years * 31556736; #60*60*24*365.24
421 %my $hidden = 0;
422 %my $seen = 0;
423 %my $old_history = 0;
424 %
425 %foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
426 %
427 %  my $display;
428 %  if ( $item->{'date'} < $older_than ) {
429 %    $display = ' STYLE="display:none" ';
430 %    $hidden = 1;
431 %  } else {
432 %
433 %    $display = '';
434 %
435 %    if ( $hidden && ! $seen++ ) {
436 %      ( my $balance_forward = $money_char. $balance ) =~ s/^\$\-/-&nbsp;\$/;
437 %    
438
439
440       <TR ID="balance_forward_row">
441         <TD CLASS="grid" BGCOLOR="#dddddd">
442           <% time2str("%D",$item->{'date'}) %>
443         </TD>
444
445         <TD CLASS="grid" BGCOLOR="#dddddd">
446           <I>Starting balance on <% time2str("%D",$item->{'date'}) %></I>
447           (<A HREF="javascript:void(0);" onClick="show_history();">show prior history</A>)
448         </TD>
449
450         <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
451         <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
452         <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
453         <TD CLASS="grid" BGCOLOR="#dddddd"></TD>
454         <TD CLASS="grid" BGCOLOR="#dddddd"><I><% $balance_forward %></I></TD>
455
456       </TR>
457 %
458 %    }
459 %
460 %  }
461 %
462 %  if ( $bgcolor eq $bgcolor1 ) {
463 %    $bgcolor = $bgcolor2;
464 %  } else {
465 %    $bgcolor = $bgcolor1;
466 %  }
467 %
468 %  my $charge  = exists($item->{'charge'})
469 %                  ? sprintf("$money_char\%.2f", $item->{'charge'})
470 %                  : '';
471 %
472 %  my $payment = exists($item->{'payment'})
473 %                  ? sprintf("-&nbsp;$money_char\%.2f", $item->{'payment'})
474 %                  : '';
475 %
476 %  $payment ||= sprintf( "<DEL>-&nbsp;$money_char\%.2f</DEL>",
477 %                        $item->{'void_payment'}
478 %                      )
479 %    if exists($item->{'void_payment'});
480 %
481 %  my $credit  = exists($item->{'credit'})
482 %                  ? sprintf("-&nbsp;$money_char\%.2f", $item->{'credit'})
483 %                  : '';
484 %
485 %  my $refund  = exists($item->{'refund'})
486 %                  ? sprintf("$money_char\%.2f", $item->{'refund'})
487 %                  : '';
488 %
489 %  my $target = exists($item->{'target'}) ? $item->{'target'} : '';
490 %
491 %  $balance += $item->{'charge'}  if exists $item->{'charge'};
492 %  $balance -= $item->{'payment'} if exists $item->{'payment'};
493 %  $balance -= $item->{'credit'}  if exists $item->{'credit'};
494 %  $balance += $item->{'refund'}  if exists $item->{'refund'};
495 %  $balance = sprintf("%.2f", $balance);
496 %  $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
497 %  ( my $showbalance = $money_char. $balance ) =~ s/^\$\-/-&nbsp;\$/;
498 %
499 %
500
501
502   <TR <% $display ? $display.' ID="old_history'.$old_history++.'"'  : ''%>>
503     <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
504 % unless ( !$target || $target{$target}++ ) { 
505
506         <A NAME="<% $target %>">
507 % } 
508
509       <% time2str("%D",$item->{'date'}) %>
510 % if ( $target && $target{$target} == 1 ) { 
511
512         </A>
513 % } 
514
515       </FONT>
516     </TD>
517     <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
518       <% $item->{'desc'} %>
519     </TD>
520     <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
521       <% $charge  %>
522     </TD>
523     <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
524       <% $payment %>
525     </TD>
526     <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
527       <% $credit  %>
528     </TD>
529     <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
530       <% $refund  %>
531     </TD>
532     <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
533       <% $showbalance %>
534     </TD>
535   </TR>
536 % } 
537
538
539 </TABLE>
540
541 <SCRIPT TYPE="text/javascript">
542
543 function show_history () {
544   //alert('showing history!');
545
546   var balance_forward_row = document.getElementById('balance_forward_row');
547
548   balance_forward_row.style.display = 'none';
549   for ( var i = 0; i < <% $old_history %>; i++ ) {
550     var oldRow = document.getElementById('old_history'+i);
551     oldRow.style.display = '';
552   }
553
554 }
555
556 </SCRIPT>
557
558 <%init>
559
560 my( $cust_main ) = @_;
561 my $custnum = $cust_main->custnum;
562
563 my $conf = new FS::Conf;
564
565 my $curuser = $FS::CurrentUser::CurrentUser;
566
567 my @payby = grep /\w/, $conf->config('payby');
568 #@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
569 @payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))
570   unless @payby;
571 my %payby = map { $_=>1 } @payby;
572
573 </%init>
574