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