4 my $conf = new FS::Conf;
6 #false laziness with view/cust_pkg.cgi, but i'm trying to make that go away so
9 foreach my $part_svc ( qsearch('part_svc',{}) ) {
10 $uiview{$part_svc->svcpart} = popurl(2). "view/". $part_svc->svcdb . ".cgi";
11 $uiadd{$part_svc->svcpart}= popurl(2). "edit/". $part_svc->svcdb . ".cgi";
14 print header("Customer View", menubar(
15 'Main Menu' => popurl(2)
18 die "No customer specified (bad URL)!" unless $cgi->keywords;
19 my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
22 my $cust_main = qsearchs('cust_main',{'custnum'=>$custnum});
23 die "Customer not found!" unless $cust_main;
25 print qq!<A HREF="!, popurl(2),
26 qq!edit/cust_main.cgi?$custnum">Edit this customer</A>!;
27 print qq! | <A HREF="!, popurl(2),
28 qq!misc/delete-customer.cgi?$custnum"> Delete this customer</A>!
29 if $conf->exists('deletecustomers');
31 unless ( $conf->exists('disable_customer_referrals') ) {
32 print qq! | <A HREF="!, popurl(2),
33 qq!edit/cust_main.cgi?referral_custnum=$custnum">!,
34 qq!Refer a new customer</A>!;
36 print qq! | <A HREF="!, popurl(2),
37 qq!search/cust_main.cgi?referral_custnum=$custnum">!,
38 qq!View this customer's referrals</A>!;
43 my $signupurl = $conf->config('signupurl');
45 print "This customer's signup URL: ".
46 "<a href=\"$signupurl?ref=$custnum\">$signupurl?ref=$custnum</a><BR><BR>";
49 print '<A NAME="cust_main"></A>';
51 print &itable(), '<TR>';
53 print '<TD VALIGN="top">';
55 print "Billing address", &ntable("#cccccc"), "<TR><TD>",
57 '<TR><TD ALIGN="right">Contact name</TD>',
58 '<TD COLSPAN=3 BGCOLOR="#ffffff">',
59 $cust_main->last, ', ', $cust_main->first,
61 print '<TD ALIGN="right">SS#</TD><TD BGCOLOR="#ffffff">',
62 $cust_main->ss || ' ', '</TD>'
63 if $conf->exists('show_ss');
66 '<TR><TD ALIGN="right">Company</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
69 '<TR><TD ALIGN="right">Address</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
73 print '<TR><TD ALIGN="right"> </TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
74 $cust_main->address2, '</TD></TR>'
75 if $cust_main->address2;
76 print '<TR><TD ALIGN="right">City</TD><TD BGCOLOR="#ffffff">',
78 '</TD><TD ALIGN="right">State</TD><TD BGCOLOR="#ffffff">',
80 '</TD><TD ALIGN="right">Zip</TD><TD BGCOLOR="#ffffff">',
81 $cust_main->zip, '</TD></TR>',
82 '<TR><TD ALIGN="right">Country</TD><TD BGCOLOR="#ffffff">',
86 my $daytime_label = FS::Msgcat::_gettext('daytime') || 'Day Phone';
87 my $night_label = FS::Msgcat::_gettext('night') || 'Night Phone';
88 print '<TR><TD ALIGN="right">'. $daytime_label.
89 '</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
90 $cust_main->daytime || ' ', '</TD></TR>',
91 '<TR><TD ALIGN="right">'. $night_label.
92 '</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
93 $cust_main->night || ' ', '</TD></TR>',
94 '<TR><TD ALIGN="right">Fax</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
95 $cust_main->fax || ' ', '</TD></TR>',
96 '</TABLE>', "</TD></TR></TABLE>"
99 if ( defined $cust_main->dbdef_table->column('ship_last') ) {
101 my $pre = $cust_main->ship_last ? 'ship_' : '';
103 print "<BR>Service address", &ntable("#cccccc"), "<TR><TD>",
104 &ntable("#cccccc",2),
105 '<TR><TD ALIGN="right">Contact name</TD>',
106 '<TD COLSPAN=5 BGCOLOR="#ffffff">',
107 $cust_main->get("${pre}last"), ', ', $cust_main->get("${pre}first"),
109 '<TR><TD ALIGN="right">Company</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
110 $cust_main->get("${pre}company"),
112 '<TR><TD ALIGN="right">Address</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
113 $cust_main->get("${pre}address1"),
116 print '<TR><TD ALIGN="right"> </TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
117 $cust_main->get("${pre}address2"), '</TD></TR>'
118 if $cust_main->get("${pre}address2");
119 print '<TR><TD ALIGN="right">City</TD><TD BGCOLOR="#ffffff">',
120 $cust_main->get("${pre}city"),
121 '</TD><TD ALIGN="right">State</TD><TD BGCOLOR="#ffffff">',
122 $cust_main->get("${pre}state"),
123 '</TD><TD ALIGN="right">Zip</TD><TD BGCOLOR="#ffffff">',
124 $cust_main->get("${pre}zip"), '</TD></TR>',
125 '<TR><TD ALIGN="right">Country</TD><TD BGCOLOR="#ffffff">',
126 $cust_main->get("${pre}country"),
129 print '<TR><TD ALIGN="right">'. $daytime_label. '</TD>',
130 '<TD COLSPAN=5 BGCOLOR="#ffffff">',
131 $cust_main->get("${pre}daytime") || ' ', '</TD></TR>',
132 '<TR><TD ALIGN="right">'. $night_label. '</TD>'.
133 '<TD COLSPAN=5 BGCOLOR="#ffffff">',
134 $cust_main->get("${pre}night") || ' ', '</TD></TR>',
135 '<TR><TD ALIGN="right">Fax</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
136 $cust_main->get("${pre}fax") || ' ', '</TD></TR>',
137 '</TABLE>', "</TD></TR></TABLE>"
144 print '<TD VALIGN="top">';
146 print &ntable("#cccccc"), "<TR><TD>", &ntable("#cccccc",2),
147 '<TR><TD ALIGN="right">Customer number</TD><TD BGCOLOR="#ffffff">',
148 $custnum, '</TD></TR>',
151 my @agents = qsearch( 'agent', {} );
153 unless ( scalar(@agents) == 1 ) {
154 $agent = qsearchs('agent',{ 'agentnum' => $cust_main->agentnum } );
155 print '<TR><TD ALIGN="right">Agent</TD><TD BGCOLOR="#ffffff">',
156 $agent->agentnum, ": ", $agent->agent, '</TD></TR>';
160 my @referrals = qsearch( 'part_referral', {} );
161 unless ( scalar(@referrals) == 1 ) {
162 my $referral = qsearchs('part_referral', {
163 'refnum' => $cust_main->refnum
165 print '<TR><TD ALIGN="right">Advertising source</TD><TD BGCOLOR="#ffffff">',
166 $referral->refnum, ": ", $referral->referral, '</TD></TR>';
168 print '<TR><TD ALIGN="right">Order taker</TD><TD BGCOLOR="#ffffff">',
169 $cust_main->otaker, '</TD></TR>';
171 print '<TR><TD ALIGN="right">Referring Customer</TD><TD BGCOLOR="#ffffff">';
172 my $referring_cust_main = '';
173 if ( $cust_main->referral_custnum
174 && ( $referring_cust_main =
175 qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
178 print '<A HREF="'. popurl(1). 'cust_main.cgi?'.
179 $cust_main->referral_custnum. '">'.
180 $cust_main->referral_custnum. ': '.
181 ( $referring_cust_main->company
182 ? $referring_cust_main->company. ' ('.
183 $referring_cust_main->last. ', '. $referring_cust_main->first.
185 : $referring_cust_main->last. ', '. $referring_cust_main->first
191 print '</TABLE></TD></TR></TABLE>';
195 if ( $conf->config('payby-default') ne 'HIDE' ) {
197 my @invoicing_list = $cust_main->invoicing_list;
198 print "Billing information (",
199 qq!<A HREF="!, popurl(2), qq!misc/bill.cgi?$custnum">!, "Bill now</A>)",
200 &ntable("#cccccc"), "<TR><TD>", &ntable("#cccccc",2),
201 '<TR><TD ALIGN="right">Tax exempt</TD><TD BGCOLOR="#ffffff">',
202 $cust_main->tax ? 'yes' : 'no',
204 '<TR><TD ALIGN="right">Postal invoices</TD><TD BGCOLOR="#ffffff">',
205 ( grep { $_ eq 'POST' } @invoicing_list ) ? 'yes' : 'no',
207 '<TR><TD ALIGN="right">Email invoices</TD><TD BGCOLOR="#ffffff">',
208 join(', ', grep { $_ ne 'POST' } @invoicing_list ) || 'no',
210 '<TR><TD ALIGN="right">Billing type</TD><TD BGCOLOR="#ffffff">',
213 if ( $cust_main->payby eq 'CARD' ) {
214 my $payinfo = $cust_main->payinfo;
215 $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4));
216 print 'Credit card</TD></TR>',
217 '<TR><TD ALIGN="right">Card number</TD><TD BGCOLOR="#ffffff">',
218 $payinfo, '</TD></TR>',
219 '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
220 $cust_main->paydate, '</TD></TR>',
221 '<TR><TD ALIGN="right">Name on card</TD><TD BGCOLOR="#ffffff">',
222 $cust_main->payname, '</TD></TR>'
224 } elsif ( $cust_main->payby eq 'CHEK' ) {
225 my( $account, $aba ) = split('@', $cust_main->payinfo );
226 print 'Electronic check</TD></TR>',
227 '<TR><TD ALIGN="right">Account number</TD><TD BGCOLOR="#ffffff">',
228 $account, '</TD></TR>',
229 '<TR><TD ALIGN="right">ABA/Routing code</TD><TD BGCOLOR="#ffffff">',
231 '<TR><TD ALIGN="right">Bank name</TD><TD BGCOLOR="#ffffff">',
232 $cust_main->payname, '</TD></TR>'
234 } elsif ( $cust_main->payby eq 'LECB' ) {
235 $cust_main->payinfo =~ /^(\d{3})(\d{3})(\d{4})$/;
236 my $payinfo = "$1-$2-$3";
237 print 'Phone bill billing</TD></TR>',
238 '<TR><TD ALIGN="right">Phone number</TD><TD BGCOLOR="#ffffff">',
239 $payinfo, '</TD></TR>',
241 } elsif ( $cust_main->payby eq 'BILL' ) {
242 print 'Billing</TD></TR>';
243 print '<TR><TD ALIGN="right">P.O. </TD><TD BGCOLOR="#ffffff">',
244 $cust_main->payinfo, '</TD></TR>',
245 if $cust_main->payinfo;
246 print '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
247 $cust_main->paydate, '</TD></TR>',
248 '<TR><TD ALIGN="right">Attention</TD><TD BGCOLOR="#ffffff">',
249 $cust_main->payname, '</TD></TR>',
251 } elsif ( $cust_main->payby eq 'COMP' ) {
252 print 'Complimentary</TD></TR>',
253 '<TR><TD ALIGN="right">Authorized by</TD><TD BGCOLOR="#ffffff">',
254 $cust_main->payinfo, '</TD></TR>',
255 '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
256 $cust_main->paydate, '</TD></TR>',
260 print "</TABLE></TD></TR></TABLE>";
264 print '</TD></TR></TABLE>';
266 if ( defined $cust_main->dbdef_table->column('comments')
267 && $cust_main->comments )
269 print "<BR>Comments". &ntable("#cccccc"). "<TR><TD>".
270 &ntable("#cccccc",2).
271 '<TR><TD BGCOLOR="#ffffff"><PRE>'.
272 encode_entities($cust_main->comments).
273 '</PRE></TD></TR></TABLE></TABLE>';
276 print '</TD></TR></TABLE>';
279 '<FORM ACTION="'.popurl(2).'edit/process/quick-cust_pkg.cgi" METHOD="POST">'.
280 qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!.
281 '<SELECT NAME="pkgpart"><OPTION> ';
283 foreach my $part_pkg (
284 qsearch( 'part_pkg', { 'disabled' => '' }, '',
285 ' AND 0 < ( SELECT COUNT(*) FROM type_pkgs '.
286 ' WHERE typenum = '. $agent->typenum.
287 ' AND type_pkgs.pkgpart = part_pkg.pkgpart )'
290 print '<OPTION VALUE="'. $part_pkg->pkgpart. '">'. $part_pkg->pkg. ' - '.
294 print '</SELECT><INPUT TYPE="submit" VALUE="Order Package"></FORM><BR>';
296 if ( $conf->config('payby-default') ne 'HIDE' ) {
299 qq!<FORM ACTION="${p}edit/process/quick-charge.cgi" METHOD="POST">!.
300 qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!.
301 qq!Description:<INPUT TYPE="text" NAME="pkg">!.
302 qq! Amount:<INPUT TYPE="text" NAME="amount" SIZE=6>!.
305 #false laziness w/ edit/part_pkg.cgi
306 if ( $conf->exists('enable_taxclasses') ) {
307 print '<SELECT NAME="taxclass">';
308 my $sth = dbh->prepare('SELECT DISTINCT taxclass FROM cust_main_county')
310 $sth->execute or die $sth->errstr;
311 foreach my $taxclass ( map $_->[0], @{$sth->fetchall_arrayref} ) {
312 print qq!<OPTION VALUE="$taxclass"!;
313 #print ' SELECTED' if $taxclass eq $hashref->{taxclass};
314 print qq!>$taxclass</OPTION>!;
318 print '<INPUT TYPE="hidden" NAME="taxclass" VALUE="">';
321 print qq!<INPUT TYPE="submit" VALUE="One-time charge"></FORM><BR>!;
327 function cust_pkg_areyousure(href) {
328 if (confirm("Permanently delete included services and cancel this package?") == true)
329 window.location.href = href;
331 function svc_areyousure(href) {
332 if (confirm("Permanently unprovision and delete this service?") == true)
333 window.location.href = href;
338 print qq!<BR><A NAME="cust_pkg">Packages</A> !,
339 # qq!<BR>Click on package number to view/edit package.!,
340 qq!( <A HREF="!, popurl(2), qq!edit/cust_pkg.cgi?$custnum">Order and cancel packages</A> (preserves services) )!,
347 if ( $conf->exists('hidecancelledpackages') ) {
348 @packages = sort { $a->pkgnum <=> $b->pkgnum } ($cust_main->ncancelled_pkgs);
350 @packages = sort { $a->pkgnum <=> $b->pkgnum } ($cust_main->all_pkgs);
355 print &table(), "\n",
356 qq!<TR><TH COLSPAN=2 ROWSPAN=2>Package</TH><TH COLSPAN=5>!,
357 qq!Dates</TH><TH COLSPAN=2 ROWSPAN=2>Services</TH></TR>\n<TR>!,
358 qq!<TH><FONT SIZE=-1>Setup</FONT></TH>!;
360 print qq!<TH><FONT SIZE=-1>Last bill</FONT></TH>!
361 if $packages[0]->dbdef_table->column('last_bill');
363 print qq!<TH><FONT SIZE=-1>Next bill</FONT></TH>!,
364 qq!<TH><FONT SIZE=-1>Susp.</FONT></TH>!,
365 qq!<TH><FONT SIZE=-1>Expire!</FONT></TH>!,
366 qq!<TH><FONT SIZE=-1>Cancel</FONT></TH>!,
371 foreach my $package (@packages) {
372 my $pkgnum = $package->pkgnum;
373 my $pkg = $package->part_pkg->pkg;
374 my $comment = $package->part_pkg->comment;
375 my $pkgview = popurl(2). "view/cust_pkg.cgi?$pkgnum";
377 #my @cust_svc = qsearch( 'cust_svc', { 'pkgnum' => $pkgnum } );
378 #my $rowspan = scalar(@cust_svc) || 1;
382 unless ( $package->getfield('cancel') ) {
383 foreach my $pkg_svc (
384 grep { $_->quantity }
385 qsearch('pkg_svc',{'pkgpart'=> $package->pkgpart })
387 $rowspan += ( $pkg_svc{$pkg_svc->svcpart} = $pkg_svc->quantity );
390 #@cust_svc = qsearch( 'cust_svc', { 'pkgnum' => $pkgnum } );
392 $rowspan = scalar(@cust_svc) || 1;
396 my $button_cgi = new CGI;
397 $button_cgi->param('clone', $package->part_pkg->pkgpart);
398 $button_cgi->param('pkgnum', $package->pkgnum);
399 my $button_url = popurl(2). "edit/part_pkg.cgi?". $button_cgi->query_string;
401 #print $n1, qq!<TD ROWSPAN=$rowspan><A HREF="$pkgview">$pkgnum</A></TD>!,
402 print $n1, qq!<TD ROWSPAN=$rowspan>$pkgnum</TD>!,
403 qq!<TD ROWSPAN=$rowspan><FONT SIZE=-1>!,
404 #qq!<A HREF="$pkgview">$pkg - $comment</A>!,
405 qq!$pkg - $comment ( <a href="$pkgview">Details</a> )!;
408 #false laziness with view/cust_pkg.cgi, but i'm trying to make that go away so
409 unless ( $package->getfield('cancel') ) {
411 print qq! ( <A HREF="${p}misc/change_pkg.cgi?$pkgnum">!.
412 'Change package</A> )';
415 if ( $package->getfield('susp') ) {
416 print qq!<A HREF="${p}misc/unsusp_pkg.cgi?$pkgnum">Unsuspend</A>!;
418 print qq!<A HREF="${p}misc/susp_pkg.cgi?$pkgnum">Suspend</A>!;
420 print ' | <A HREF="javascript:cust_pkg_areyousure(\''. popurl(2).
421 'misc/cancel_pkg.cgi?'. $pkgnum. '\')">Cancel</A>';
425 print ' ( <A HREF="'. popurl(2). 'edit/REAL_cust_pkg.cgi?'. $pkgnum.
426 '">Edit dates</A> | ';
428 print qq!<A HREF="$button_url">Customize</A> )!;
431 print '</FONT></TD>';
433 my @fields = qw( setup );
434 push @fields, qw( last_bill ) if $package->dbdef_table->column('last_bill');
435 push @fields, qw( bill susp expire cancel);
438 print "<TD ROWSPAN=$rowspan><FONT SIZE=-1>", ( $package->getfield($_)
439 ? time2str("%D</FONT><BR><FONT SIZE=-3>%l:%M:%S%P %z</FONT>",
440 $package->getfield($_) )
447 #false laziness with view/cust_pkg.cgi, but i'm trying to make that go away so
448 #foreach my $cust_svc ( @cust_svc ) {
449 foreach my $svcpart ( sort { $a<=>$b } keys %pkg_svc ) {
450 my $svc = qsearchs('part_svc',{'svcpart'=>$svcpart})->getfield('svc');
451 $svc =~ s/ / /g;
452 my(@cust_svc)=qsearch('cust_svc',{'pkgnum'=>$pkgnum,
455 for my $enum ( 1 .. $pkg_svc{$svcpart} ) {
457 if ( $cust_svc = shift @cust_svc ) {
458 my($label, $value, $svcdb) = $cust_svc->label;
459 my($svcnum) = $cust_svc->svcnum;
460 my($sview) = popurl(2). "view";
461 print $n2,qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$label</FONT></A></TD>!,
462 qq!<TD><FONT SIZE=-1><A HREF="$sview/$svcdb.cgi?$svcnum">$value</A><BR>( <A HREF="javascript:svc_areyousure('${p}misc/unprovision.cgi?$svcnum')">Unprovision</A> )</FONT></TD>!;
464 print $n2, qq!<TD COLSPAN=2><A HREF="$uiadd{$svcpart}?pkgnum$pkgnum-svcpart$svcpart"><b><font size="+1" color="#ff0000">!.
465 qq!Provision $svc</A></b></font>!;
467 print qq!<BR><A HREF="../misc/link.cgi?pkgnum$pkgnum-svcpart$svcpart">!.
468 qq!<b><font size="+1" color="#ff0000">Link to legacy $svc</A></b></font>!
469 if $conf->exists('legacy_link');
487 function cust_pay_areyousure(href) {
488 if (confirm("Are you sure you want to delete this payment?")
490 window.location.href = href;
492 function cust_pay_unapply_areyousure(href) {
493 if (confirm("Are you sure you want to unapply this payment?")
495 window.location.href = href;
500 if ( $conf->config('payby-default') ne 'HIDE' ) {
503 print qq!<BR><BR><A NAME="history">Payment History!.
505 qq!<A HREF="!. popurl(2). qq!edit/cust_pay.cgi?custnum=$custnum">!.
506 qq!Post payment</A> | !.
507 qq!<A HREF="!. popurl(2). qq!edit/cust_credit.cgi?$custnum">!.
508 qq!Post credit</A> )!;
512 # major problem: this whole thing is way too sloppy.
513 # minor problem: the description lines need better formatting.
515 my @history = (); #needed for mod_perl :)
519 my @bills = qsearch('cust_bill',{'custnum'=>$custnum});
520 foreach my $bill (@bills) {
521 my($bref)=$bill->hashref;
522 my $bpre = ( $bill->owed > 0 )
523 ? '<b><font size="+1" color="#ff0000"> Open '
525 my $bpost = ( $bill->owed > 0 ) ? '</font></b>' : '';
527 $bref->{_date} . qq!\t<A HREF="!. popurl(2). qq!view/cust_bill.cgi?! .
528 $bref->{invnum} . qq!">${bpre}Invoice #! . $bref->{invnum} .
529 qq! (Balance \$! . $bill->owed . qq!)$bpost</A>\t! .
530 $bref->{charged} . qq!\t\t\t!;
532 my(@cust_bill_pay)=qsearch('cust_bill_pay',{'invnum'=> $bref->{invnum} } );
533 # my(@payments)=qsearch('cust_pay',{'invnum'=> $bref->{invnum} } );
535 foreach my $cust_bill_pay (@cust_bill_pay) {
536 my $payment = $cust_bill_pay->cust_pay;
537 my($date,$invnum,$payby,$payinfo,$paid)=($payment->_date,
538 $cust_bill_pay->invnum,
541 $cust_bill_pay->amount,
543 $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4))
545 my $target = "$payby$payinfo";
546 $payby =~ s/^BILL$/Check #/ if $payinfo;
547 $payby =~ s/^(CARD|COMP)$/$1 /;
548 my $delete = $payment->closed !~ /^Y/i && $conf->exists('deletepayments')
549 ? qq! (<A HREF="javascript:cust_pay_areyousure('${p}misc/delete-cust_pay.cgi?!. $payment->paynum. qq!')">delete</A>)!
552 $payment->closed !~ /^Y/i && $conf->exists('unapplypayments')
553 ? qq! (<A HREF="javascript:cust_pay_unapply_areyousure('${p}misc/unapply-cust_pay.cgi?!. $payment->paynum. qq!')">unapply</A>)!
556 "$date\tPayment, Invoice #$invnum ($payby$payinfo)$delete$unapply\t\t$paid\t\t\t$target";
559 my(@cust_credit_bill)=
560 qsearch('cust_credit_bill', { 'invnum'=> $bref->{invnum} } );
561 foreach my $cust_credit_bill (@cust_credit_bill) {
562 my $cust_credit = $cust_credit_bill->cust_credit;
563 my($date, $invnum, $crednum, $amount, $reason, $app_date ) = (
565 $cust_credit_bill->invnum,
566 $cust_credit_bill->crednum,
567 $cust_credit_bill->amount,
568 $cust_credit->reason,
569 time2str("%D", $cust_credit_bill->_date),
572 "$date\tCredit #$crednum: $reason<BR>".
573 "(applied to invoice #$invnum on $app_date)\t\t\t$amount\t";
577 my @credits = grep { scalar(my @array = $_->cust_credit_refund) }
578 qsearch('cust_credit',{'custnum'=>$custnum});
579 foreach my $credit (@credits) {
580 my($cref)=$credit->hashref;
581 my(@cust_credit_refund)=
582 qsearch('cust_credit_refund', { 'crednum'=> $cref->{crednum} } );
583 foreach my $cust_credit_refund (@cust_credit_refund) {
584 my $cust_refund = $cust_credit_refund->cust_credit;
585 my($date, $crednum, $amount, $reason, $app_date ) = (
588 $cust_credit_refund->amount,
590 time2str("%D", $cust_credit_refund->_date),
593 "$date\tCredit #$crednum: $reason<BR>".
594 "(applied to refund on $app_date)\t\t\t$amount\t";
598 @credits = grep { $_->credited > 0 }
599 qsearch('cust_credit',{'custnum'=>$custnum});
600 foreach my $credit (@credits) {
601 my($cref)=$credit->hashref;
603 $cref->{_date} . "\t" .
604 qq!<A HREF="! . popurl(2). qq!edit/cust_credit_bill.cgi?!. $cref->{crednum} . qq!">!.
605 '<b><font size="+1" color="#ff0000">Unapplied credit #' .
606 $cref->{crednum} . "</font></b></A>: ".
607 $cref->{reason} . "\t\t\t" . $credit->credited . "\t";
610 my(@refunds)=qsearch('cust_refund',{'custnum'=> $custnum } );
611 foreach my $refund (@refunds) {
612 my($rref)=$refund->hashref;
618 $rref->{_date} . "\tRefund #$refundnum, (" .
619 $rref->{payby} . " " . $rref->{payinfo} . ") by " .
620 $rref->{otaker} . " - ". $rref->{reason} . "\t\t\t\t" .
624 my @unapplied_payments =
625 grep { $_->unapplied > 0 } qsearch('cust_pay', { 'custnum' => $custnum } );
626 foreach my $payment (@unapplied_payments) {
627 my $payby = $payment->payby;
628 my $payinfo = $payment->payinfo;
629 #false laziness w/above
630 $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4))
632 my $target = "$payby$payinfo";
633 $payby =~ s/^BILL$/Check #/ if $payinfo;
634 $payby =~ s/^(CARD|COMP)$/$1 /;
635 my $delete = $payment->closed !~ /^Y/i && $conf->exists('deletepayments')
636 ? qq! (<A HREF="javascript:cust_pay_areyousure('${p}misc/delete-cust_pay.cgi?!. $payment->paynum. qq!')">delete</A>)!
639 $payment->_date. "\t".
640 '<b><font size="+1" color="#ff0000">Unapplied payment #' .
641 $payment->paynum . " ($payby$payinfo)</font></b> ".
642 '(<A HREF="'. popurl(2). 'edit/cust_bill_pay.cgi?'. $payment->paynum. '">'.
644 "\t\t" . $payment->unapplied . "\t\t\t$target";
648 print &table(), <<END;
652 <TH><FONT SIZE=-1>Charge</FONT></TH>
653 <TH><FONT SIZE=-1>Payment</FONT></TH>
654 <TH><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
655 <TH><FONT SIZE=-1>Refund</FONT></TH>
656 <TH><FONT SIZE=-1>Balance</FONT></TH>
660 #display payment history
663 foreach my $item (sort keyfield_numerically @history) {
664 my($date,$desc,$charge,$payment,$credit,$refund,$target)=split(/\t/,$item);
669 $balance += $charge - $payment;
670 $balance -= $credit - $refund;
671 $balance = sprintf("%.2f", $balance);
672 $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
673 $target = '' unless defined $target;
675 print "<TR><TD><FONT SIZE=-1>";
676 print qq!<A NAME="$target">! unless $target && $target{$target}++;
677 print time2str("%D",$date);
678 print '</A>' if $target && $target{$target} == 1;
679 print "</FONT></TD>",
680 "<TD><FONT SIZE=-1>$desc</FONT></TD>",
681 "<TD><FONT SIZE=-1>",
682 ( $charge ? "\$".sprintf("%.2f",$charge) : '' ),
684 "<TD><FONT SIZE=-1>",
685 ( $payment ? "- \$".sprintf("%.2f",$payment) : '' ),
687 "<TD><FONT SIZE=-1>",
688 ( $credit ? "- \$".sprintf("%.2f",$credit) : '' ),
690 "<TD><FONT SIZE=-1>",
691 ( $refund ? "\$".sprintf("%.2f",$refund) : '' ),
693 "<TD><FONT SIZE=-1>\$" . $balance,
702 print '</BODY></HTML>';
705 sub keyfield_numerically { (split(/\t/,$a))[0] <=> (split(/\t/,$b))[0]; }