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