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