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