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)
19 <STYLE TYPE="text/css">
20 .package TH { font-size: medium }
21 .package TR { font-size: smaller }
22 .package .pkgnum { font-size: medium }
23 .package .provision { font-weight: bold }
27 die "No customer specified (bad URL)!" unless $cgi->keywords;
28 my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
31 my $cust_main = qsearchs('cust_main',{'custnum'=>$custnum});
32 die "Customer not found!" unless $cust_main;
34 print qq!<A HREF="${p}edit/cust_main.cgi?$custnum">Edit this customer</A>!;
38 function cancel_areyousure(href) {
39 if (confirm("Perminantly delete all services and cancel this customer?") == true)
40 window.location.href = href;
45 print qq! | <A HREF="javascript:cancel_areyousure('${p}misc/cust_main-cancel.cgi?$custnum')">!.
46 'Cancel this customer</A>'
47 if $cust_main->ncancelled_pkgs;
49 print qq! | <A HREF="${p}misc/delete-customer.cgi?$custnum">!.
50 'Delete this customer</A>'
51 if $conf->exists('deletecustomers');
53 unless ( $conf->exists('disable_customer_referrals') ) {
54 print qq! | <A HREF="!, popurl(2),
55 qq!edit/cust_main.cgi?referral_custnum=$custnum">!,
56 qq!Refer a new customer</A>!;
58 print qq! | <A HREF="!, popurl(2),
59 qq!search/cust_main.cgi?referral_custnum=$custnum">!,
60 qq!View this customer's referrals</A>!;
65 my $signupurl = $conf->config('signupurl');
67 print "This customer's signup URL: ".
68 "<a href=\"$signupurl?ref=$custnum\">$signupurl?ref=$custnum</a><BR><BR>";
71 print '<A NAME="cust_main"></A>';
73 print &itable(), '<TR>';
75 print '<TD VALIGN="top">';
77 print "Billing address", &ntable("#cccccc"), "<TR><TD>",
79 '<TR><TD ALIGN="right">Contact name</TD>',
80 '<TD COLSPAN=3 BGCOLOR="#ffffff">',
81 $cust_main->last, ', ', $cust_main->first,
83 print '<TD ALIGN="right">SS#</TD><TD BGCOLOR="#ffffff">',
84 $cust_main->ss || ' ', '</TD>'
85 if $conf->exists('show_ss');
88 '<TR><TD ALIGN="right">Company</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
91 '<TR><TD ALIGN="right">Address</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
95 print '<TR><TD ALIGN="right"> </TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
96 $cust_main->address2, '</TD></TR>'
97 if $cust_main->address2;
98 print '<TR><TD ALIGN="right">City</TD><TD BGCOLOR="#ffffff">',
100 '</TD><TD ALIGN="right">State</TD><TD BGCOLOR="#ffffff">',
102 '</TD><TD ALIGN="right">Zip</TD><TD BGCOLOR="#ffffff">',
103 $cust_main->zip, '</TD></TR>',
104 '<TR><TD ALIGN="right">Country</TD><TD BGCOLOR="#ffffff">',
108 my $daytime_label = FS::Msgcat::_gettext('daytime') || 'Day Phone';
109 my $night_label = FS::Msgcat::_gettext('night') || 'Night Phone';
110 print '<TR><TD ALIGN="right">'. $daytime_label.
111 '</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
112 $cust_main->daytime || ' ', '</TD></TR>',
113 '<TR><TD ALIGN="right">'. $night_label.
114 '</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
115 $cust_main->night || ' ', '</TD></TR>',
116 '<TR><TD ALIGN="right">Fax</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
117 $cust_main->fax || ' ', '</TD></TR>',
118 '</TABLE>', "</TD></TR></TABLE>"
121 if ( defined $cust_main->dbdef_table->column('ship_last') ) {
123 my $pre = $cust_main->ship_last ? 'ship_' : '';
125 print "<BR>Service address", &ntable("#cccccc"), "<TR><TD>",
126 &ntable("#cccccc",2),
127 '<TR><TD ALIGN="right">Contact name</TD>',
128 '<TD COLSPAN=5 BGCOLOR="#ffffff">',
129 $cust_main->get("${pre}last"), ', ', $cust_main->get("${pre}first"),
131 '<TR><TD ALIGN="right">Company</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
132 $cust_main->get("${pre}company"),
134 '<TR><TD ALIGN="right">Address</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
135 $cust_main->get("${pre}address1"),
138 print '<TR><TD ALIGN="right"> </TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
139 $cust_main->get("${pre}address2"), '</TD></TR>'
140 if $cust_main->get("${pre}address2");
141 print '<TR><TD ALIGN="right">City</TD><TD BGCOLOR="#ffffff">',
142 $cust_main->get("${pre}city"),
143 '</TD><TD ALIGN="right">State</TD><TD BGCOLOR="#ffffff">',
144 $cust_main->get("${pre}state"),
145 '</TD><TD ALIGN="right">Zip</TD><TD BGCOLOR="#ffffff">',
146 $cust_main->get("${pre}zip"), '</TD></TR>',
147 '<TR><TD ALIGN="right">Country</TD><TD BGCOLOR="#ffffff">',
148 $cust_main->get("${pre}country"),
151 print '<TR><TD ALIGN="right">'. $daytime_label. '</TD>',
152 '<TD COLSPAN=5 BGCOLOR="#ffffff">',
153 $cust_main->get("${pre}daytime") || ' ', '</TD></TR>',
154 '<TR><TD ALIGN="right">'. $night_label. '</TD>'.
155 '<TD COLSPAN=5 BGCOLOR="#ffffff">',
156 $cust_main->get("${pre}night") || ' ', '</TD></TR>',
157 '<TR><TD ALIGN="right">Fax</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
158 $cust_main->get("${pre}fax") || ' ', '</TD></TR>',
159 '</TABLE>', "</TD></TR></TABLE>"
166 print '<TD VALIGN="top">';
168 print &ntable("#cccccc"), "<TR><TD>", &ntable("#cccccc",2),
169 '<TR><TD ALIGN="right">Customer number</TD><TD BGCOLOR="#ffffff">',
170 $custnum, '</TD></TR>',
173 my @agents = qsearch( 'agent', {} );
175 unless ( scalar(@agents) == 1 ) {
176 $agent = qsearchs('agent',{ 'agentnum' => $cust_main->agentnum } );
177 print '<TR><TD ALIGN="right">Agent</TD><TD BGCOLOR="#ffffff">',
178 $agent->agentnum, ": ", $agent->agent, '</TD></TR>';
182 my @referrals = qsearch( 'part_referral', {} );
183 unless ( scalar(@referrals) == 1 ) {
184 my $referral = qsearchs('part_referral', {
185 'refnum' => $cust_main->refnum
187 print '<TR><TD ALIGN="right">Advertising source</TD><TD BGCOLOR="#ffffff">',
188 $referral->refnum, ": ", $referral->referral, '</TD></TR>';
190 print '<TR><TD ALIGN="right">Order taker</TD><TD BGCOLOR="#ffffff">',
191 $cust_main->otaker, '</TD></TR>';
193 print '<TR><TD ALIGN="right">Referring Customer</TD><TD BGCOLOR="#ffffff">';
194 my $referring_cust_main = '';
195 if ( $cust_main->referral_custnum
196 && ( $referring_cust_main =
197 qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
200 print '<A HREF="'. popurl(1). 'cust_main.cgi?'.
201 $cust_main->referral_custnum. '">'.
202 $cust_main->referral_custnum. ': '.
203 ( $referring_cust_main->company
204 ? $referring_cust_main->company. ' ('.
205 $referring_cust_main->last. ', '. $referring_cust_main->first.
207 : $referring_cust_main->last. ', '. $referring_cust_main->first
213 print '</TABLE></TD></TR></TABLE>';
217 if ( $conf->config('payby-default') ne 'HIDE' ) {
219 my @invoicing_list = $cust_main->invoicing_list;
220 print "Billing information (",
221 qq!<A HREF="!, popurl(2), qq!misc/bill.cgi?$custnum">!, "Bill now</A>)",
222 &ntable("#cccccc"), "<TR><TD>", &ntable("#cccccc",2),
223 '<TR><TD ALIGN="right">Tax exempt</TD><TD BGCOLOR="#ffffff">',
224 $cust_main->tax ? 'yes' : 'no',
226 '<TR><TD ALIGN="right">Postal invoices</TD><TD BGCOLOR="#ffffff">',
227 ( grep { $_ eq 'POST' } @invoicing_list ) ? 'yes' : 'no',
229 '<TR><TD ALIGN="right">Email invoices</TD><TD BGCOLOR="#ffffff">',
230 join(', ', grep { $_ ne 'POST' } @invoicing_list ) || 'no',
232 '<TR><TD ALIGN="right">Billing type</TD><TD BGCOLOR="#ffffff">',
235 if ( $cust_main->payby eq 'CARD' || $cust_main->payby eq 'DCRD' ) {
236 my $payinfo = $cust_main->payinfo;
237 $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4));
238 print 'Credit card ',
239 ( $cust_main->payby eq 'CARD' ? '(automatic)' : '(on-demand)' ),
241 '<TR><TD ALIGN="right">Card number</TD><TD BGCOLOR="#ffffff">',
242 $payinfo, '</TD></TR>',
243 '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
244 $cust_main->paydate, '</TD></TR>',
245 '<TR><TD ALIGN="right">Name on card</TD><TD BGCOLOR="#ffffff">',
246 $cust_main->payname, '</TD></TR>'
248 } elsif ( $cust_main->payby eq 'CHEK' || $cust_main->payby eq 'DCHK') {
249 my( $account, $aba ) = split('@', $cust_main->payinfo );
250 print 'Electronic check ',
251 ( $cust_main->payby eq 'CHEK' ? '(automatic)' : '(on-demand)' ),
253 '<TR><TD ALIGN="right">Account number</TD><TD BGCOLOR="#ffffff">',
254 $account, '</TD></TR>',
255 '<TR><TD ALIGN="right">ABA/Routing code</TD><TD BGCOLOR="#ffffff">',
257 '<TR><TD ALIGN="right">Bank name</TD><TD BGCOLOR="#ffffff">',
258 $cust_main->payname, '</TD></TR>'
260 } elsif ( $cust_main->payby eq 'LECB' ) {
261 $cust_main->payinfo =~ /^(\d{3})(\d{3})(\d{4})$/;
262 my $payinfo = "$1-$2-$3";
263 print 'Phone bill billing</TD></TR>',
264 '<TR><TD ALIGN="right">Phone number</TD><TD BGCOLOR="#ffffff">',
265 $payinfo, '</TD></TR>',
267 } elsif ( $cust_main->payby eq 'BILL' ) {
268 print 'Billing</TD></TR>';
269 print '<TR><TD ALIGN="right">P.O. </TD><TD BGCOLOR="#ffffff">',
270 $cust_main->payinfo, '</TD></TR>',
271 if $cust_main->payinfo;
272 print '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
273 $cust_main->paydate, '</TD></TR>',
274 '<TR><TD ALIGN="right">Attention</TD><TD BGCOLOR="#ffffff">',
275 $cust_main->payname, '</TD></TR>',
277 } elsif ( $cust_main->payby eq 'COMP' ) {
278 print 'Complimentary</TD></TR>',
279 '<TR><TD ALIGN="right">Authorized by</TD><TD BGCOLOR="#ffffff">',
280 $cust_main->payinfo, '</TD></TR>',
281 '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
282 $cust_main->paydate, '</TD></TR>',
286 print "</TABLE></TD></TR></TABLE>";
290 print '</TD></TR></TABLE>';
292 if ( defined $cust_main->dbdef_table->column('comments')
293 && $cust_main->comments =~ /[^\s\n\r]/ )
295 print "<BR>Comments". &ntable("#cccccc"). "<TR><TD>".
296 &ntable("#cccccc",2).
297 '<TR><TD BGCOLOR="#ffffff"><PRE>'.
298 encode_entities($cust_main->comments).
299 '</PRE></TD></TR></TABLE></TABLE>';
302 print '</TD></TR></TABLE>';
305 '<FORM ACTION="'.popurl(2).'edit/process/quick-cust_pkg.cgi" METHOD="POST">'.
306 qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!.
307 '<SELECT NAME="pkgpart"><OPTION> ';
309 foreach my $part_pkg (
310 qsearch( 'part_pkg', { 'disabled' => '' }, '',
311 ' AND 0 < ( SELECT COUNT(*) FROM type_pkgs '.
312 ' WHERE typenum = '. $agent->typenum.
313 ' AND type_pkgs.pkgpart = part_pkg.pkgpart )'
316 print '<OPTION VALUE="'. $part_pkg->pkgpart. '">'. $part_pkg->pkg. ' - '.
320 print '</SELECT><INPUT TYPE="submit" VALUE="Order Package"></FORM><BR>';
322 if ( $conf->config('payby-default') ne 'HIDE' ) {
325 qq!<FORM ACTION="${p}edit/process/quick-charge.cgi" METHOD="POST">!.
326 qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!.
327 qq!Description:<INPUT TYPE="text" NAME="pkg">!.
328 qq! Amount:<INPUT TYPE="text" NAME="amount" SIZE=6>!.
331 #false laziness w/ edit/part_pkg.cgi
332 if ( $conf->exists('enable_taxclasses') ) {
333 print '<SELECT NAME="taxclass">';
334 my $sth = dbh->prepare('SELECT DISTINCT taxclass FROM cust_main_county')
336 $sth->execute or die $sth->errstr;
337 foreach my $taxclass ( map $_->[0], @{$sth->fetchall_arrayref} ) {
338 print qq!<OPTION VALUE="$taxclass"!;
339 #print ' SELECTED' if $taxclass eq $hashref->{taxclass};
340 print qq!>$taxclass</OPTION>!;
344 print '<INPUT TYPE="hidden" NAME="taxclass" VALUE="">';
347 print qq!<INPUT TYPE="submit" VALUE="One-time charge"></FORM><BR>!;
353 function cust_pkg_areyousure(href) {
354 if (confirm("Permanently delete included services and cancel this package?") == true)
355 window.location.href = href;
357 function svc_areyousure(href) {
358 if (confirm("Permanently unprovision and delete this service?") == true)
359 window.location.href = href;
364 print qq!<BR><A NAME="cust_pkg">Packages</A> !,
365 # qq!<BR>Click on package number to view/edit package.!,
366 qq!( <A HREF="!, popurl(2), qq!edit/cust_pkg.cgi?$custnum">Order and cancel packages</A> (preserves services) )!,
369 #begin display packages
373 my $packages = get_packages($cust_main, $conf);
377 <TABLE CLASS="package" BORDER=1 CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">
379 <TH COLSPAN=2>Package</TH>
381 <TH COLSPAN=2>Services</TH>
384 foreach my $pkg (sort pkgsort_pkgnum_cancel @$packages) {
387 if ($pkg->{cancel}) {
390 foreach my $svcpart (@{$pkg->{svcparts}}) {
391 $rowspan += $svcpart->{count};
392 $rowspan++ if ($svcpart->{count} < $svcpart->{quantity});
397 <!--pkgnum: <%=$pkg->{pkgnum}%>-->
399 <TD ROWSPAN=<%=$rowspan%> CLASS="pkgnum"><%=$pkg->{pkgnum}%></TD>
400 <TD ROWSPAN=<%=$rowspan%>>
401 <%=$pkg->{pkg}%> - <%=$pkg->{comment}%> ( <%=pkg_details_link($pkg)%> )<BR>
402 <% unless ($pkg->{cancel}) { %>
403 ( <%=pkg_change_link($pkg)%> )
404 ( <%=pkg_dates_link($pkg)%> | <%=pkg_customize_link($pkg,$custnum)%> )
408 #foreach (qw(setup last_bill next_bill susp expire cancel)) {
409 # print qq! <TD ROWSPAN=$rowspan>! . pkg_datestr($pkg,$_,$conf) . qq!</TD>\n!;
411 print "<TD ROWSPAN=$rowspan>". &itable('');
415 #false laziness w/edit/part_pkg.cgi
416 my %freq = ( #move this
419 '2w' => 'biweekly (every 2 weeks)',
421 '2' => 'bimonthly (every 2 months)',
422 '3' => 'quarterly (every 3 months)',
423 '6' => 'semiannually (every 6 months)',
425 '24' => 'biannually (every 2 years)',
429 exists $freq{$freq} ? $freq{$freq} : "every $freq months";
434 if ( $pkg->{cancel} ) { #status: cancelled
436 print '<TR><TD><FONT COLOR="#ff0000"><B>Cancelled </B></FONT></TD>'.
437 '<TD>'. pkg_datestr($pkg,'cancel',$conf). '</TD></TR>';
438 unless ( $pkg->{setup} ) {
439 print '<TR><TD COLSPAN=2>Never billed</TD></TR>';
441 print "<TR><TD>Setup </TD><TD>".
442 pkg_datestr($pkg, 'setup',$conf). '</TD></TR>';
443 print "<TR><TD>Last bill </TD><TD>".
444 pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>'
445 if $pkg->{'last_bill'};
446 print "<TR><TD>Suspended </TD><TD>".
447 pkg_datestr($pkg, 'susp',$conf). '</TD></TR>'
453 if ( $pkg->{susp} ) { #status: suspended
454 print '<TR><TD><FONT COLOR="#FF9900"><B>Suspended</B> </FONT></TD>'.
455 '<TD>'. pkg_datestr($pkg,'susp',$conf). '</TD></TR>';
456 unless ( $pkg->{setup} ) {
457 print '<TR><TD COLSPAN=2>Never billed</TD></TR>';
459 print "<TR><TD>Setup </TD><TD>".
460 pkg_datestr($pkg, 'setup',$conf). '</TD></TR>';
462 print "<TR><TD>Last bill </TD><TD>".
463 pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>'
464 if $pkg->{'last_bill'};
466 print "<TR><TD>Expires </TD><TD>".
467 pkg_datestr($pkg, 'expire',$conf). '</TD></TR>'
469 print '<TR><TD COLSPAN=2>( '. pkg_unsuspend_link($pkg).
470 ' | '. pkg_cancel_link($pkg). ' )</TD></TR>';
472 } else { #status: active
474 unless ( $pkg->{setup} ) { #not setup
476 print '<TR><TD COLSPAN=2>Not yet billed (';
477 unless ( $pkg->{freq} ) {
478 print 'one-time charge)</TD></TR>';
479 print '<TR><TD COLSPAN=2>( '. pkg_cancel_link($pkg).
482 print 'billed '. freq($pkg->{freq}). ')</TD></TR>';
487 unless ( $pkg->{freq} ) {
488 print "<TR><TD COLSPAN=2>One-time charge</TD></TR>".
489 '<TR><TD>Billed </TD><TD>'.
490 pkg_datestr($pkg,'setup',$conf). '</TD></TR>';
492 print '<TR><TD COLSPAN=2><FONT COLOR="#00CC00"><B>Active</B></FONT>'.
493 ', billed '. freq($pkg->{freq}). '</TD></TR>'.
494 '<TR><TD>Setup </TD><TD>'.
495 pkg_datestr($pkg, 'setup',$conf). '</TD></TR>';
500 print "<TR><TD>Last bill </TD><TD>".
501 pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>'
502 if $pkg->{'last_bill'};
503 print "<TR><TD>Next bill </TD><TD>".
504 pkg_datestr($pkg, 'next_bill',$conf). '</TD></TR>'
505 if $pkg->{'next_bill'};
506 print "<TR><TD>Expires </TD><TD>".
507 pkg_datestr($pkg, 'expire',$conf). '</TD></TR>'
509 if ( $pkg->{freq} ) {
510 print '<TR><TD COLSPAN=2>( '. pkg_suspend_link($pkg).
511 ' | '. pkg_cancel_link($pkg). ' )</TD></TR>';
518 print "</TABLE></TD>\n";
520 if ($rowspan == 0) { print qq!</TR>\n!; next; }
523 foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
524 foreach my $service (@{$svcpart->{services}}) {
525 print '<TR>' if ($cnt > 0);
527 <TD><%=svc_link($svcpart,$service)%></TD>
528 <TD><%=svc_label_link($svcpart,$service)%><BR>( <%=svc_unprovision_link($service)%> )</TD>
533 if ($svcpart->{count} < $svcpart->{quantity}) {
534 print qq!<TR>\n! if ($cnt > 0);
535 print qq! <TD COLSPAN=2>!.svc_provision_link($pkg,$svcpart).qq!</TD>\n</TR>\n!;
542 #end display packages
547 function cust_pay_areyousure(href) {
548 if (confirm("Are you sure you want to delete this payment?")
550 window.location.href = href;
552 function cust_pay_unapply_areyousure(href) {
553 if (confirm("Are you sure you want to unapply this payment?")
555 window.location.href = href;
557 function cust_credit_unapply_areyousure(href) {
558 if (confirm("Are you sure you want to unapply this credit?")
560 window.location.href = href;
562 function cust_credit_areyousure(href) {
563 if (confirm("Are you sure you want to delete this credit?")
565 window.location.href = href;
570 if ( $conf->config('payby-default') ne 'HIDE' ) {
573 print qq!<BR><BR><A NAME="history">Payment History!.
575 qq!<A HREF="!. popurl(2). qq!edit/cust_pay.cgi?custnum=$custnum">!.
576 qq!Post payment</A> | !.
577 qq!<A HREF="!. popurl(2). qq!edit/cust_credit.cgi?$custnum">!.
578 qq!Post credit</A> )!;
582 # major problem: this whole thing is way too sloppy.
583 # minor problem: the description lines need better formatting.
585 my @history = (); #needed for mod_perl :)
589 my @bills = qsearch('cust_bill',{'custnum'=>$custnum});
590 foreach my $bill (@bills) {
591 my($bref)=$bill->hashref;
592 my $bpre = ( $bill->owed > 0 )
593 ? '<b><font size="+1" color="#ff0000"> Open '
595 my $bpost = ( $bill->owed > 0 ) ? '</font></b>' : '';
597 $bref->{_date} . qq!\t<A HREF="!. popurl(2). qq!view/cust_bill.cgi?! .
598 $bref->{invnum} . qq!">${bpre}Invoice #! . $bref->{invnum} .
599 qq! (Balance \$! . $bill->owed . qq!)$bpost</A>\t! .
600 $bref->{charged} . qq!\t\t\t!;
602 my(@cust_bill_pay)=qsearch('cust_bill_pay',{'invnum'=> $bref->{invnum} } );
603 # my(@payments)=qsearch('cust_pay',{'invnum'=> $bref->{invnum} } );
605 foreach my $cust_bill_pay (@cust_bill_pay) {
606 my $payment = $cust_bill_pay->cust_pay;
607 my($date,$invnum,$payby,$payinfo,$paid)=($payment->_date,
608 $cust_bill_pay->invnum,
611 $cust_bill_pay->amount,
613 $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4))
615 my $target = "$payby$payinfo";
616 $payby =~ s/^BILL$/Check #/ if $payinfo;
617 $payby =~ s/^(CARD|COMP)$/$1 /;
618 my $delete = $payment->closed !~ /^Y/i && $conf->exists('deletepayments')
619 ? qq! (<A HREF="javascript:cust_pay_areyousure('${p}misc/delete-cust_pay.cgi?!. $payment->paynum. qq!')">delete</A>)!
622 $payment->closed !~ /^Y/i && $conf->exists('unapplypayments')
623 ? qq! (<A HREF="javascript:cust_pay_unapply_areyousure('${p}misc/unapply-cust_pay.cgi?!. $payment->paynum. qq!')">unapply</A>)!
626 "$date\tPayment, Invoice #$invnum ($payby$payinfo)$delete$unapply\t\t$paid\t\t\t$target";
629 my(@cust_credit_bill)=
630 qsearch('cust_credit_bill', { 'invnum'=> $bref->{invnum} } );
631 foreach my $cust_credit_bill (@cust_credit_bill) {
632 my $cust_credit = $cust_credit_bill->cust_credit;
633 my($date, $invnum, $crednum, $amount, $reason, $app_date ) = (
635 $cust_credit_bill->invnum,
636 $cust_credit_bill->crednum,
637 $cust_credit_bill->amount,
638 $cust_credit->reason,
639 time2str("%D", $cust_credit_bill->_date),
642 $cust_credit->closed !~ /^Y/i && $conf->exists('deletecredits')
643 ? qq! (<A HREF="javascript:cust_credit_areyousure('${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum. qq!')">delete</A>)!
646 $cust_credit->closed !~ /^Y/i && $conf->exists('unapplycredits')
647 ? qq! (<A HREF="javascript:cust_credit_unapply_areyousure('${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum. qq!')">unapply</A>)!
650 "$date\tCredit #$crednum: $reason<BR>".
651 "(applied to invoice #$invnum on $app_date)$delete$unapply\t\t\t$amount\t";
655 my @credits = grep { scalar(my @array = $_->cust_credit_refund) }
656 qsearch('cust_credit',{'custnum'=>$custnum});
657 foreach my $credit (@credits) {
658 my($cref)=$credit->hashref;
659 my(@cust_credit_refund)=
660 qsearch('cust_credit_refund', { 'crednum'=> $cref->{crednum} } );
661 foreach my $cust_credit_refund (@cust_credit_refund) {
662 my $cust_refund = $cust_credit_refund->cust_credit;
663 my($date, $crednum, $amount, $reason, $app_date ) = (
666 $cust_credit_refund->amount,
668 time2str("%D", $cust_credit_refund->_date),
671 "$date\tCredit #$crednum: $reason<BR>".
672 "(applied to refund on $app_date)\t\t\t$amount\t";
676 @credits = grep { $_->credited > 0 }
677 qsearch('cust_credit',{'custnum'=>$custnum});
678 foreach my $credit (@credits) {
679 my($cref)=$credit->hashref;
681 $credit->closed !~ /^Y/i && $conf->exists('deletecredits')
682 ? qq! (<A HREF="javascript:cust_credit_areyousure('${p}misc/delete-cust_credit.cgi?!. $credit->crednum. qq!')">delete</A>)!
685 $cref->{_date} . "\t" .
686 qq!<A HREF="! . popurl(2). qq!edit/cust_credit_bill.cgi?!. $cref->{crednum} . qq!">!.
687 '<b><font size="+1" color="#ff0000">Unapplied credit #' .
688 $cref->{crednum} . "</font></b></A>: ".
689 $cref->{reason} . "$delete\t\t\t" . $credit->credited . "\t";
692 my(@refunds)=qsearch('cust_refund',{'custnum'=> $custnum } );
693 foreach my $refund (@refunds) {
694 my($rref)=$refund->hashref;
700 $rref->{_date} . "\tRefund #$refundnum, (" .
701 $rref->{payby} . " " . $rref->{payinfo} . ") by " .
702 $rref->{otaker} . " - ". $rref->{reason} . "\t\t\t\t" .
706 my @unapplied_payments =
707 grep { $_->unapplied > 0 } qsearch('cust_pay', { 'custnum' => $custnum } );
708 foreach my $payment (@unapplied_payments) {
709 my $payby = $payment->payby;
710 my $payinfo = $payment->payinfo;
711 #false laziness w/above
712 $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4))
714 my $target = "$payby$payinfo";
715 $payby =~ s/^BILL$/Check #/ if $payinfo;
716 $payby =~ s/^(CARD|COMP)$/$1 /;
717 my $delete = $payment->closed !~ /^Y/i && $conf->exists('deletepayments')
718 ? qq! (<A HREF="javascript:cust_pay_areyousure('${p}misc/delete-cust_pay.cgi?!. $payment->paynum. qq!')">delete</A>)!
721 $payment->_date. "\t".
722 '<b><font size="+1" color="#ff0000">Unapplied payment #' .
723 $payment->paynum . " ($payby$payinfo)</font></b> ".
724 '(<A HREF="'. popurl(2). 'edit/cust_bill_pay.cgi?'. $payment->paynum. '">'.
726 "\t\t" . $payment->unapplied . "\t\t\t$target";
730 print &table(), <<END;
734 <TH><FONT SIZE=-1>Charge</FONT></TH>
735 <TH><FONT SIZE=-1>Payment</FONT></TH>
736 <TH><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
737 <TH><FONT SIZE=-1>Refund</FONT></TH>
738 <TH><FONT SIZE=-1>Balance</FONT></TH>
742 #display payment history
745 foreach my $item (sort keyfield_numerically @history) {
746 my($date,$desc,$charge,$payment,$credit,$refund,$target)=split(/\t/,$item);
751 $balance += $charge - $payment;
752 $balance -= $credit - $refund;
753 $balance = sprintf("%.2f", $balance);
754 $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
755 $target = '' unless defined $target;
757 print "<TR><TD><FONT SIZE=-1>";
758 print qq!<A NAME="$target">! unless $target && $target{$target}++;
759 print time2str("%D",$date);
760 print '</A>' if $target && $target{$target} == 1;
761 print "</FONT></TD>",
762 "<TD><FONT SIZE=-1>$desc</FONT></TD>",
763 "<TD><FONT SIZE=-1>",
764 ( $charge ? "\$".sprintf("%.2f",$charge) : '' ),
766 "<TD><FONT SIZE=-1>",
767 ( $payment ? "- \$".sprintf("%.2f",$payment) : '' ),
769 "<TD><FONT SIZE=-1>",
770 ( $credit ? "- \$".sprintf("%.2f",$credit) : '' ),
772 "<TD><FONT SIZE=-1>",
773 ( $refund ? "\$".sprintf("%.2f",$refund) : '' ),
775 "<TD><FONT SIZE=-1>\$" . $balance,
784 print '</BODY></HTML>';
787 sub keyfield_numerically { (split(/\t/,$a))[0] <=> (split(/\t/,$b))[0]; }
795 my $cust_main = shift or return undef;
800 foreach my $cust_pkg (
801 $conf->exists('hidecancelledpackages')
802 ? $cust_main->ncancelled_pkgs
803 : $cust_main->all_pkgs
806 my $part_pkg = $cust_pkg->part_pkg;
809 $pkg{pkgnum} = $cust_pkg->pkgnum;
810 $pkg{pkg} = $part_pkg->pkg;
811 $pkg{pkgpart} = $part_pkg->pkgpart;
812 $pkg{comment} = $part_pkg->getfield('comment');
813 $pkg{freq} = $part_pkg->freq;
814 $pkg{setup} = $cust_pkg->getfield('setup');
815 $pkg{last_bill} = $cust_pkg->getfield('last_bill');
816 $pkg{next_bill} = $cust_pkg->getfield('bill');
817 $pkg{susp} = $cust_pkg->getfield('susp');
818 $pkg{expire} = $cust_pkg->getfield('expire');
819 $pkg{cancel} = $cust_pkg->getfield('cancel');
823 foreach my $pkg_svc (
824 qsearch('pkg_svc', { 'pkgpart' => $part_pkg->pkgpart })
827 next if ($pkg_svc->quantity == 0);
829 my $part_svc = qsearchs('part_svc', { 'svcpart' => $pkg_svc->svcpart });
832 $svcpart->{svcpart} = $part_svc->svcpart;
833 $svcpart->{svc} = $part_svc->svc;
834 $svcpart->{svcdb} = $part_svc->svcdb;
835 $svcpart->{quantity} = $pkg_svc->quantity;
836 $svcpart->{count} = 0;
838 $svcpart->{services} = [];
840 $svcparts{$svcpart->{svcpart}} = $svcpart;
844 foreach my $cust_svc (
845 qsearch( 'cust_svc', {
846 'pkgnum' => $cust_pkg->pkgnum,
847 #'svcpart' => $part_svc->svcpart,
852 warn "svcnum ". $cust_svc->svcnum. " / svcpart ". $cust_svc->svcpart. "\n";
854 'svcnum' => $cust_svc->svcnum,
855 'label' => ($cust_svc->label)[1],
858 #false laziness with above, to catch extraneous services. whole
859 #damn thing should be OO...
860 my $svcpart = ( $svcparts{$cust_svc->svcpart} ||= {
861 'svcpart' => $cust_svc->svcpart,
862 'svc' => $cust_svc->part_svc->svc,
863 'svcdb' => $cust_svc->part_svc->svcdb,
869 push @{$svcpart->{services}}, $svc;
875 $pkg{svcparts} = [ values %svcparts ];
877 push @packages, \%pkg;
887 my ($svcpart, $svc) = (shift,shift) or return '';
888 return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svcpart->{svc}</A>!;
894 my ($svcpart, $svc) = (shift,shift) or return '';
895 return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svc->{label}</A>!;
899 sub svc_provision_link {
900 my ($pkg, $svcpart) = (shift,shift) or return '';
901 ( my $svc_nbsp = $svcpart->{svc} ) =~ s/\s+/ /g;
902 return qq!<A CLASS="provision" HREF="${p}edit/$svcpart->{svcdb}.cgi?! .
903 qq!pkgnum$pkg->{pkgnum}-svcpart$svcpart->{svcpart}">! .
904 "Provision $svc_nbsp (".
905 ($svcpart->{quantity} - $svcpart->{count}).
909 sub svc_unprovision_link {
910 my $svc = shift or return '';
911 return qq!<A HREF="javascript:svc_areyousure('${p}misc/unprovision.cgi?$svc->{svcnum}')">Unprovision</A>!;
914 # This should be generalized to use config options to determine order.
915 sub pkgsort_pkgnum_cancel {
916 if ($a->{cancel} and $b->{cancel}) {
917 return ($a->{pkgnum} <=> $b->{pkgnum});
918 } elsif ($a->{cancel} or $b->{cancel}) {
919 return (-1) if ($b->{cancel});
920 return (1) if ($a->{cancel});
923 return($a->{pkgnum} <=> $b->{pkgnum});
928 my($pkg, $field, $conf) = @_ or return '';
929 return ' ' unless $pkg->{$field};
930 my $format = $conf->exists('pkg_showtimes')
931 ? '<B>%D</B> <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
932 : '<B>%b %o, %Y</B>';
933 ( my $strip = time2str($format, $pkg->{$field}) ) =~ s/ (\d)/$1/g;
937 sub pkg_details_link {
938 my $pkg = shift or return '';
939 return qq!<a href="${p}view/cust_pkg.cgi?$pkg->{pkgnum}">Details</a>!;
942 sub pkg_change_link {
943 my $pkg = shift or return '';
944 return qq!<a href="${p}misc/change_pkg.cgi?$pkg->{pkgnum}">Change package</a>!;
947 sub pkg_suspend_link {
948 my $pkg = shift or return '';
949 return qq!<a href="${p}misc/susp_pkg.cgi?$pkg->{pkgnum}">Suspend</a>!;
952 sub pkg_unsuspend_link {
953 my $pkg = shift or return '';
954 return qq!<a href="${p}misc/unsusp_pkg.cgi?$pkg->{pkgnum}">Unsuspend</a>!;
957 sub pkg_cancel_link {
958 my $pkg = shift or return '';
959 return qq!<A HREF="javascript:cust_pkg_areyousure('${p}misc/cancel_pkg.cgi?$pkg->{pkgnum}')">Cancel</A>!;
963 my $pkg = shift or return '';
964 return qq!<A HREF="${p}edit/REAL_cust_pkg.cgi?$pkg->{pkgnum}">Edit dates</A>!;
967 sub pkg_customize_link {
968 my $pkg = shift or return '';
970 return qq!<A HREF="${p}edit/part_pkg.cgi?keywords=$custnum;clone=$pkg->{pkgpart};pkgnum=$pkg->{pkgnum}">Customize</A>!;