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="${p}edit/cust_main.cgi?$custnum">Edit this customer</A>!;
29 function cancel_areyousure(href) {
30 if (confirm("Perminantly delete all services and cancel this customer?") == true)
31 window.location.href = href;
36 print qq! | <A HREF="javascript:cancel_areyousure('${p}misc/cust_main-cancel.cgi?$custnum')">!.
37 'Cancel this customer</A>'
38 if $cust_main->ncancelled_pkgs;
40 print qq! | <A HREF="${p}misc/delete-customer.cgi?$custnum">!.
41 'Delete this customer</A>'
42 if $conf->exists('deletecustomers');
44 unless ( $conf->exists('disable_customer_referrals') ) {
45 print qq! | <A HREF="!, popurl(2),
46 qq!edit/cust_main.cgi?referral_custnum=$custnum">!,
47 qq!Refer a new customer</A>!;
49 print qq! | <A HREF="!, popurl(2),
50 qq!search/cust_main.cgi?referral_custnum=$custnum">!,
51 qq!View this customer's referrals</A>!;
56 my $signupurl = $conf->config('signupurl');
58 print "This customer's signup URL: ".
59 "<a href=\"$signupurl?ref=$custnum\">$signupurl?ref=$custnum</a><BR><BR>";
62 print '<A NAME="cust_main"></A>';
64 print &itable(), '<TR>';
66 print '<TD VALIGN="top">';
68 print "Billing address", &ntable("#cccccc"), "<TR><TD>",
70 '<TR><TD ALIGN="right">Contact name</TD>',
71 '<TD COLSPAN=3 BGCOLOR="#ffffff">',
72 $cust_main->last, ', ', $cust_main->first,
74 print '<TD ALIGN="right">SS#</TD><TD BGCOLOR="#ffffff">',
75 $cust_main->ss || ' ', '</TD>'
76 if $conf->exists('show_ss');
79 '<TR><TD ALIGN="right">Company</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
82 '<TR><TD ALIGN="right">Address</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
86 print '<TR><TD ALIGN="right"> </TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
87 $cust_main->address2, '</TD></TR>'
88 if $cust_main->address2;
89 print '<TR><TD ALIGN="right">City</TD><TD BGCOLOR="#ffffff">',
91 '</TD><TD ALIGN="right">State</TD><TD BGCOLOR="#ffffff">',
93 '</TD><TD ALIGN="right">Zip</TD><TD BGCOLOR="#ffffff">',
94 $cust_main->zip, '</TD></TR>',
95 '<TR><TD ALIGN="right">Country</TD><TD BGCOLOR="#ffffff">',
99 my $daytime_label = FS::Msgcat::_gettext('daytime') || 'Day Phone';
100 my $night_label = FS::Msgcat::_gettext('night') || 'Night Phone';
101 print '<TR><TD ALIGN="right">'. $daytime_label.
102 '</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
103 $cust_main->daytime || ' ', '</TD></TR>',
104 '<TR><TD ALIGN="right">'. $night_label.
105 '</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
106 $cust_main->night || ' ', '</TD></TR>',
107 '<TR><TD ALIGN="right">Fax</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
108 $cust_main->fax || ' ', '</TD></TR>',
109 '</TABLE>', "</TD></TR></TABLE>"
112 if ( defined $cust_main->dbdef_table->column('ship_last') ) {
114 my $pre = $cust_main->ship_last ? 'ship_' : '';
116 print "<BR>Service address", &ntable("#cccccc"), "<TR><TD>",
117 &ntable("#cccccc",2),
118 '<TR><TD ALIGN="right">Contact name</TD>',
119 '<TD COLSPAN=5 BGCOLOR="#ffffff">',
120 $cust_main->get("${pre}last"), ', ', $cust_main->get("${pre}first"),
122 '<TR><TD ALIGN="right">Company</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
123 $cust_main->get("${pre}company"),
125 '<TR><TD ALIGN="right">Address</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
126 $cust_main->get("${pre}address1"),
129 print '<TR><TD ALIGN="right"> </TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
130 $cust_main->get("${pre}address2"), '</TD></TR>'
131 if $cust_main->get("${pre}address2");
132 print '<TR><TD ALIGN="right">City</TD><TD BGCOLOR="#ffffff">',
133 $cust_main->get("${pre}city"),
134 '</TD><TD ALIGN="right">State</TD><TD BGCOLOR="#ffffff">',
135 $cust_main->get("${pre}state"),
136 '</TD><TD ALIGN="right">Zip</TD><TD BGCOLOR="#ffffff">',
137 $cust_main->get("${pre}zip"), '</TD></TR>',
138 '<TR><TD ALIGN="right">Country</TD><TD BGCOLOR="#ffffff">',
139 $cust_main->get("${pre}country"),
142 print '<TR><TD ALIGN="right">'. $daytime_label. '</TD>',
143 '<TD COLSPAN=5 BGCOLOR="#ffffff">',
144 $cust_main->get("${pre}daytime") || ' ', '</TD></TR>',
145 '<TR><TD ALIGN="right">'. $night_label. '</TD>'.
146 '<TD COLSPAN=5 BGCOLOR="#ffffff">',
147 $cust_main->get("${pre}night") || ' ', '</TD></TR>',
148 '<TR><TD ALIGN="right">Fax</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
149 $cust_main->get("${pre}fax") || ' ', '</TD></TR>',
150 '</TABLE>', "</TD></TR></TABLE>"
157 print '<TD VALIGN="top">';
159 print &ntable("#cccccc"), "<TR><TD>", &ntable("#cccccc",2),
160 '<TR><TD ALIGN="right">Customer number</TD><TD BGCOLOR="#ffffff">',
161 $custnum, '</TD></TR>',
164 my @agents = qsearch( 'agent', {} );
166 unless ( scalar(@agents) == 1 ) {
167 $agent = qsearchs('agent',{ 'agentnum' => $cust_main->agentnum } );
168 print '<TR><TD ALIGN="right">Agent</TD><TD BGCOLOR="#ffffff">',
169 $agent->agentnum, ": ", $agent->agent, '</TD></TR>';
173 my @referrals = qsearch( 'part_referral', {} );
174 unless ( scalar(@referrals) == 1 ) {
175 my $referral = qsearchs('part_referral', {
176 'refnum' => $cust_main->refnum
178 print '<TR><TD ALIGN="right">Advertising source</TD><TD BGCOLOR="#ffffff">',
179 $referral->refnum, ": ", $referral->referral, '</TD></TR>';
181 print '<TR><TD ALIGN="right">Order taker</TD><TD BGCOLOR="#ffffff">',
182 $cust_main->otaker, '</TD></TR>';
184 print '<TR><TD ALIGN="right">Referring Customer</TD><TD BGCOLOR="#ffffff">';
185 my $referring_cust_main = '';
186 if ( $cust_main->referral_custnum
187 && ( $referring_cust_main =
188 qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
191 print '<A HREF="'. popurl(1). 'cust_main.cgi?'.
192 $cust_main->referral_custnum. '">'.
193 $cust_main->referral_custnum. ': '.
194 ( $referring_cust_main->company
195 ? $referring_cust_main->company. ' ('.
196 $referring_cust_main->last. ', '. $referring_cust_main->first.
198 : $referring_cust_main->last. ', '. $referring_cust_main->first
204 print '</TABLE></TD></TR></TABLE>';
208 if ( $conf->config('payby-default') ne 'HIDE' ) {
210 my @invoicing_list = $cust_main->invoicing_list;
211 print "Billing information (",
212 qq!<A HREF="!, popurl(2), qq!misc/bill.cgi?$custnum">!, "Bill now</A>)",
213 &ntable("#cccccc"), "<TR><TD>", &ntable("#cccccc",2),
214 '<TR><TD ALIGN="right">Tax exempt</TD><TD BGCOLOR="#ffffff">',
215 $cust_main->tax ? 'yes' : 'no',
217 '<TR><TD ALIGN="right">Postal invoices</TD><TD BGCOLOR="#ffffff">',
218 ( grep { $_ eq 'POST' } @invoicing_list ) ? 'yes' : 'no',
220 '<TR><TD ALIGN="right">Email invoices</TD><TD BGCOLOR="#ffffff">',
221 join(', ', grep { $_ ne 'POST' } @invoicing_list ) || 'no',
223 '<TR><TD ALIGN="right">Billing type</TD><TD BGCOLOR="#ffffff">',
226 if ( $cust_main->payby eq 'CARD' ) {
227 my $payinfo = $cust_main->payinfo;
228 $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4));
229 print 'Credit card</TD></TR>',
230 '<TR><TD ALIGN="right">Card number</TD><TD BGCOLOR="#ffffff">',
231 $payinfo, '</TD></TR>',
232 '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
233 $cust_main->paydate, '</TD></TR>',
234 '<TR><TD ALIGN="right">Name on card</TD><TD BGCOLOR="#ffffff">',
235 $cust_main->payname, '</TD></TR>'
237 } elsif ( $cust_main->payby eq 'CHEK' ) {
238 my( $account, $aba ) = split('@', $cust_main->payinfo );
239 print 'Electronic check</TD></TR>',
240 '<TR><TD ALIGN="right">Account number</TD><TD BGCOLOR="#ffffff">',
241 $account, '</TD></TR>',
242 '<TR><TD ALIGN="right">ABA/Routing code</TD><TD BGCOLOR="#ffffff">',
244 '<TR><TD ALIGN="right">Bank name</TD><TD BGCOLOR="#ffffff">',
245 $cust_main->payname, '</TD></TR>'
247 } elsif ( $cust_main->payby eq 'LECB' ) {
248 $cust_main->payinfo =~ /^(\d{3})(\d{3})(\d{4})$/;
249 my $payinfo = "$1-$2-$3";
250 print 'Phone bill billing</TD></TR>',
251 '<TR><TD ALIGN="right">Phone number</TD><TD BGCOLOR="#ffffff">',
252 $payinfo, '</TD></TR>',
254 } elsif ( $cust_main->payby eq 'BILL' ) {
255 print 'Billing</TD></TR>';
256 print '<TR><TD ALIGN="right">P.O. </TD><TD BGCOLOR="#ffffff">',
257 $cust_main->payinfo, '</TD></TR>',
258 if $cust_main->payinfo;
259 print '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
260 $cust_main->paydate, '</TD></TR>',
261 '<TR><TD ALIGN="right">Attention</TD><TD BGCOLOR="#ffffff">',
262 $cust_main->payname, '</TD></TR>',
264 } elsif ( $cust_main->payby eq 'COMP' ) {
265 print 'Complimentary</TD></TR>',
266 '<TR><TD ALIGN="right">Authorized by</TD><TD BGCOLOR="#ffffff">',
267 $cust_main->payinfo, '</TD></TR>',
268 '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
269 $cust_main->paydate, '</TD></TR>',
273 print "</TABLE></TD></TR></TABLE>";
277 print '</TD></TR></TABLE>';
279 if ( defined $cust_main->dbdef_table->column('comments')
280 && $cust_main->comments )
282 print "<BR>Comments". &ntable("#cccccc"). "<TR><TD>".
283 &ntable("#cccccc",2).
284 '<TR><TD BGCOLOR="#ffffff"><PRE>'.
285 encode_entities($cust_main->comments).
286 '</PRE></TD></TR></TABLE></TABLE>';
289 print '</TD></TR></TABLE>';
292 '<FORM ACTION="'.popurl(2).'edit/process/quick-cust_pkg.cgi" METHOD="POST">'.
293 qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!.
294 '<SELECT NAME="pkgpart"><OPTION> ';
296 foreach my $part_pkg (
297 qsearch( 'part_pkg', { 'disabled' => '' }, '',
298 ' AND 0 < ( SELECT COUNT(*) FROM type_pkgs '.
299 ' WHERE typenum = '. $agent->typenum.
300 ' AND type_pkgs.pkgpart = part_pkg.pkgpart )'
303 print '<OPTION VALUE="'. $part_pkg->pkgpart. '">'. $part_pkg->pkg. ' - '.
307 print '</SELECT><INPUT TYPE="submit" VALUE="Order Package"></FORM><BR>';
309 if ( $conf->config('payby-default') ne 'HIDE' ) {
312 qq!<FORM ACTION="${p}edit/process/quick-charge.cgi" METHOD="POST">!.
313 qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!.
314 qq!Description:<INPUT TYPE="text" NAME="pkg">!.
315 qq! Amount:<INPUT TYPE="text" NAME="amount" SIZE=6>!.
318 #false laziness w/ edit/part_pkg.cgi
319 if ( $conf->exists('enable_taxclasses') ) {
320 print '<SELECT NAME="taxclass">';
321 my $sth = dbh->prepare('SELECT DISTINCT taxclass FROM cust_main_county')
323 $sth->execute or die $sth->errstr;
324 foreach my $taxclass ( map $_->[0], @{$sth->fetchall_arrayref} ) {
325 print qq!<OPTION VALUE="$taxclass"!;
326 #print ' SELECTED' if $taxclass eq $hashref->{taxclass};
327 print qq!>$taxclass</OPTION>!;
331 print '<INPUT TYPE="hidden" NAME="taxclass" VALUE="">';
334 print qq!<INPUT TYPE="submit" VALUE="One-time charge"></FORM><BR>!;
340 function cust_pkg_areyousure(href) {
341 if (confirm("Permanently delete included services and cancel this package?") == true)
342 window.location.href = href;
344 function svc_areyousure(href) {
345 if (confirm("Permanently unprovision and delete this service?") == true)
346 window.location.href = href;
351 print qq!<BR><A NAME="cust_pkg">Packages</A> !,
352 # qq!<BR>Click on package number to view/edit package.!,
353 qq!( <A HREF="!, popurl(2), qq!edit/cust_pkg.cgi?$custnum">Order and cancel packages</A> (preserves services) )!,
360 if ( $conf->exists('hidecancelledpackages') ) {
361 @packages = sort { $a->pkgnum <=> $b->pkgnum } ($cust_main->ncancelled_pkgs);
363 @packages = sort { $a->pkgnum <=> $b->pkgnum } ($cust_main->all_pkgs);
368 print &table(), "\n",
369 qq!<TR><TH COLSPAN=2 ROWSPAN=2>Package</TH><TH COLSPAN=5>!,
370 qq!Dates</TH><TH COLSPAN=2 ROWSPAN=2>Services</TH></TR>\n<TR>!,
371 qq!<TH><FONT SIZE=-1>Setup</FONT></TH>!;
373 print qq!<TH><FONT SIZE=-1>Last bill</FONT></TH>!
374 if $packages[0]->dbdef_table->column('last_bill');
376 print qq!<TH><FONT SIZE=-1>Next bill</FONT></TH>!,
377 qq!<TH><FONT SIZE=-1>Susp.</FONT></TH>!,
378 qq!<TH><FONT SIZE=-1>Expire!</FONT></TH>!,
379 qq!<TH><FONT SIZE=-1>Cancel</FONT></TH>!,
384 foreach my $package (@packages) {
385 my $pkgnum = $package->pkgnum;
386 my $pkg = $package->part_pkg->pkg;
387 my $comment = $package->part_pkg->comment;
388 my $pkgview = popurl(2). "view/cust_pkg.cgi?$pkgnum";
390 #my @cust_svc = qsearch( 'cust_svc', { 'pkgnum' => $pkgnum } );
391 #my $rowspan = scalar(@cust_svc) || 1;
395 unless ( $package->getfield('cancel') ) {
396 foreach my $pkg_svc (
397 grep { $_->quantity }
398 qsearch('pkg_svc',{'pkgpart'=> $package->pkgpart })
400 $rowspan += ( $pkg_svc{$pkg_svc->svcpart} = $pkg_svc->quantity );
403 #@cust_svc = qsearch( 'cust_svc', { 'pkgnum' => $pkgnum } );
405 $rowspan = scalar(@cust_svc) || 1;
409 my $button_cgi = new CGI;
410 $button_cgi->param('clone', $package->part_pkg->pkgpart);
411 $button_cgi->param('pkgnum', $package->pkgnum);
412 my $button_url = popurl(2). "edit/part_pkg.cgi?". $button_cgi->query_string;
414 #print $n1, qq!<TD ROWSPAN=$rowspan><A HREF="$pkgview">$pkgnum</A></TD>!,
415 print $n1, qq!<TD ROWSPAN=$rowspan>$pkgnum</TD>!,
416 qq!<TD ROWSPAN=$rowspan><FONT SIZE=-1>!,
417 #qq!<A HREF="$pkgview">$pkg - $comment</A>!,
418 qq!$pkg - $comment ( <a href="$pkgview">Details</a> )!;
421 #false laziness with view/cust_pkg.cgi, but i'm trying to make that go away so
422 unless ( $package->getfield('cancel') ) {
424 print qq! ( <A HREF="${p}misc/change_pkg.cgi?$pkgnum">!.
425 'Change package</A> )';
428 if ( $package->getfield('susp') ) {
429 print qq!<A HREF="${p}misc/unsusp_pkg.cgi?$pkgnum">Unsuspend</A>!;
431 print qq!<A HREF="${p}misc/susp_pkg.cgi?$pkgnum">Suspend</A>!;
433 print ' | <A HREF="javascript:cust_pkg_areyousure(\''. popurl(2).
434 'misc/cancel_pkg.cgi?'. $pkgnum. '\')">Cancel</A>';
438 print ' ( <A HREF="'. popurl(2). 'edit/REAL_cust_pkg.cgi?'. $pkgnum.
439 '">Edit dates</A> | ';
441 print qq!<A HREF="$button_url">Customize</A> )!;
444 print '</FONT></TD>';
446 my @fields = qw( setup );
447 push @fields, qw( last_bill ) if $package->dbdef_table->column('last_bill');
448 push @fields, qw( bill susp expire cancel);
451 print "<TD ROWSPAN=$rowspan><FONT SIZE=-1>", ( $package->getfield($_)
452 ? time2str("%D</FONT><BR><FONT SIZE=-3>%l:%M:%S%P %z</FONT>",
453 $package->getfield($_) )
460 #false laziness with view/cust_pkg.cgi, but i'm trying to make that go away so
461 #foreach my $cust_svc ( @cust_svc ) {
462 foreach my $svcpart ( sort { $a<=>$b } keys %pkg_svc ) {
463 my $svc = qsearchs('part_svc',{'svcpart'=>$svcpart})->getfield('svc');
464 $svc =~ s/ / /g;
465 my(@cust_svc)=qsearch('cust_svc',{'pkgnum'=>$pkgnum,
468 for my $enum ( 1 .. $pkg_svc{$svcpart} ) {
470 if ( $cust_svc = shift @cust_svc ) {
471 my($label, $value, $svcdb) = $cust_svc->label;
472 my($svcnum) = $cust_svc->svcnum;
473 my($sview) = popurl(2). "view";
474 print $n2,qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$label</FONT></A></TD>!,
475 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>!;
477 print $n2, qq!<TD COLSPAN=2><A HREF="$uiadd{$svcpart}?pkgnum$pkgnum-svcpart$svcpart"><b><font size="+1" color="#ff0000">!.
478 qq!Provision $svc</A></b></font>!;
480 print qq!<BR><A HREF="../misc/link.cgi?pkgnum$pkgnum-svcpart$svcpart">!.
481 qq!<b><font size="+1" color="#ff0000">Link to legacy $svc</A></b></font>!
482 if $conf->exists('legacy_link');
500 function cust_pay_areyousure(href) {
501 if (confirm("Are you sure you want to delete this payment?")
503 window.location.href = href;
505 function cust_pay_unapply_areyousure(href) {
506 if (confirm("Are you sure you want to unapply this payment?")
508 window.location.href = href;
513 if ( $conf->config('payby-default') ne 'HIDE' ) {
516 print qq!<BR><BR><A NAME="history">Payment History!.
518 qq!<A HREF="!. popurl(2). qq!edit/cust_pay.cgi?custnum=$custnum">!.
519 qq!Post payment</A> | !.
520 qq!<A HREF="!. popurl(2). qq!edit/cust_credit.cgi?$custnum">!.
521 qq!Post credit</A> )!;
525 # major problem: this whole thing is way too sloppy.
526 # minor problem: the description lines need better formatting.
528 my @history = (); #needed for mod_perl :)
532 my @bills = qsearch('cust_bill',{'custnum'=>$custnum});
533 foreach my $bill (@bills) {
534 my($bref)=$bill->hashref;
535 my $bpre = ( $bill->owed > 0 )
536 ? '<b><font size="+1" color="#ff0000"> Open '
538 my $bpost = ( $bill->owed > 0 ) ? '</font></b>' : '';
540 $bref->{_date} . qq!\t<A HREF="!. popurl(2). qq!view/cust_bill.cgi?! .
541 $bref->{invnum} . qq!">${bpre}Invoice #! . $bref->{invnum} .
542 qq! (Balance \$! . $bill->owed . qq!)$bpost</A>\t! .
543 $bref->{charged} . qq!\t\t\t!;
545 my(@cust_bill_pay)=qsearch('cust_bill_pay',{'invnum'=> $bref->{invnum} } );
546 # my(@payments)=qsearch('cust_pay',{'invnum'=> $bref->{invnum} } );
548 foreach my $cust_bill_pay (@cust_bill_pay) {
549 my $payment = $cust_bill_pay->cust_pay;
550 my($date,$invnum,$payby,$payinfo,$paid)=($payment->_date,
551 $cust_bill_pay->invnum,
554 $cust_bill_pay->amount,
556 $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4))
558 my $target = "$payby$payinfo";
559 $payby =~ s/^BILL$/Check #/ if $payinfo;
560 $payby =~ s/^(CARD|COMP)$/$1 /;
561 my $delete = $payment->closed !~ /^Y/i && $conf->exists('deletepayments')
562 ? qq! (<A HREF="javascript:cust_pay_areyousure('${p}misc/delete-cust_pay.cgi?!. $payment->paynum. qq!')">delete</A>)!
565 $payment->closed !~ /^Y/i && $conf->exists('unapplypayments')
566 ? qq! (<A HREF="javascript:cust_pay_unapply_areyousure('${p}misc/unapply-cust_pay.cgi?!. $payment->paynum. qq!')">unapply</A>)!
569 "$date\tPayment, Invoice #$invnum ($payby$payinfo)$delete$unapply\t\t$paid\t\t\t$target";
572 my(@cust_credit_bill)=
573 qsearch('cust_credit_bill', { 'invnum'=> $bref->{invnum} } );
574 foreach my $cust_credit_bill (@cust_credit_bill) {
575 my $cust_credit = $cust_credit_bill->cust_credit;
576 my($date, $invnum, $crednum, $amount, $reason, $app_date ) = (
578 $cust_credit_bill->invnum,
579 $cust_credit_bill->crednum,
580 $cust_credit_bill->amount,
581 $cust_credit->reason,
582 time2str("%D", $cust_credit_bill->_date),
585 "$date\tCredit #$crednum: $reason<BR>".
586 "(applied to invoice #$invnum on $app_date)\t\t\t$amount\t";
590 my @credits = grep { scalar(my @array = $_->cust_credit_refund) }
591 qsearch('cust_credit',{'custnum'=>$custnum});
592 foreach my $credit (@credits) {
593 my($cref)=$credit->hashref;
594 my(@cust_credit_refund)=
595 qsearch('cust_credit_refund', { 'crednum'=> $cref->{crednum} } );
596 foreach my $cust_credit_refund (@cust_credit_refund) {
597 my $cust_refund = $cust_credit_refund->cust_credit;
598 my($date, $crednum, $amount, $reason, $app_date ) = (
601 $cust_credit_refund->amount,
603 time2str("%D", $cust_credit_refund->_date),
606 "$date\tCredit #$crednum: $reason<BR>".
607 "(applied to refund on $app_date)\t\t\t$amount\t";
611 @credits = grep { $_->credited > 0 }
612 qsearch('cust_credit',{'custnum'=>$custnum});
613 foreach my $credit (@credits) {
614 my($cref)=$credit->hashref;
616 $cref->{_date} . "\t" .
617 qq!<A HREF="! . popurl(2). qq!edit/cust_credit_bill.cgi?!. $cref->{crednum} . qq!">!.
618 '<b><font size="+1" color="#ff0000">Unapplied credit #' .
619 $cref->{crednum} . "</font></b></A>: ".
620 $cref->{reason} . "\t\t\t" . $credit->credited . "\t";
623 my(@refunds)=qsearch('cust_refund',{'custnum'=> $custnum } );
624 foreach my $refund (@refunds) {
625 my($rref)=$refund->hashref;
631 $rref->{_date} . "\tRefund #$refundnum, (" .
632 $rref->{payby} . " " . $rref->{payinfo} . ") by " .
633 $rref->{otaker} . " - ". $rref->{reason} . "\t\t\t\t" .
637 my @unapplied_payments =
638 grep { $_->unapplied > 0 } qsearch('cust_pay', { 'custnum' => $custnum } );
639 foreach my $payment (@unapplied_payments) {
640 my $payby = $payment->payby;
641 my $payinfo = $payment->payinfo;
642 #false laziness w/above
643 $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4))
645 my $target = "$payby$payinfo";
646 $payby =~ s/^BILL$/Check #/ if $payinfo;
647 $payby =~ s/^(CARD|COMP)$/$1 /;
648 my $delete = $payment->closed !~ /^Y/i && $conf->exists('deletepayments')
649 ? qq! (<A HREF="javascript:cust_pay_areyousure('${p}misc/delete-cust_pay.cgi?!. $payment->paynum. qq!')">delete</A>)!
652 $payment->_date. "\t".
653 '<b><font size="+1" color="#ff0000">Unapplied payment #' .
654 $payment->paynum . " ($payby$payinfo)</font></b> ".
655 '(<A HREF="'. popurl(2). 'edit/cust_bill_pay.cgi?'. $payment->paynum. '">'.
657 "\t\t" . $payment->unapplied . "\t\t\t$target";
661 print &table(), <<END;
665 <TH><FONT SIZE=-1>Charge</FONT></TH>
666 <TH><FONT SIZE=-1>Payment</FONT></TH>
667 <TH><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
668 <TH><FONT SIZE=-1>Refund</FONT></TH>
669 <TH><FONT SIZE=-1>Balance</FONT></TH>
673 #display payment history
676 foreach my $item (sort keyfield_numerically @history) {
677 my($date,$desc,$charge,$payment,$credit,$refund,$target)=split(/\t/,$item);
682 $balance += $charge - $payment;
683 $balance -= $credit - $refund;
684 $balance = sprintf("%.2f", $balance);
685 $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
686 $target = '' unless defined $target;
688 print "<TR><TD><FONT SIZE=-1>";
689 print qq!<A NAME="$target">! unless $target && $target{$target}++;
690 print time2str("%D",$date);
691 print '</A>' if $target && $target{$target} == 1;
692 print "</FONT></TD>",
693 "<TD><FONT SIZE=-1>$desc</FONT></TD>",
694 "<TD><FONT SIZE=-1>",
695 ( $charge ? "\$".sprintf("%.2f",$charge) : '' ),
697 "<TD><FONT SIZE=-1>",
698 ( $payment ? "- \$".sprintf("%.2f",$payment) : '' ),
700 "<TD><FONT SIZE=-1>",
701 ( $credit ? "- \$".sprintf("%.2f",$credit) : '' ),
703 "<TD><FONT SIZE=-1>",
704 ( $refund ? "\$".sprintf("%.2f",$refund) : '' ),
706 "<TD><FONT SIZE=-1>\$" . $balance,
715 print '</BODY></HTML>';
718 sub keyfield_numerically { (split(/\t/,$a))[0] <=> (split(/\t/,$b))[0]; }