4 my $conf = new FS::Conf;
8 foreach my $part_svc ( qsearch('part_svc',{}) ) {
9 $uiview{$part_svc->svcpart} = popurl(2). "view/". $part_svc->svcdb . ".cgi";
10 $uiadd{$part_svc->svcpart}= popurl(2). "edit/". $part_svc->svcdb . ".cgi";
13 print header("Customer View", menubar(
14 'Main Menu' => popurl(2)
19 <STYLE TYPE="text/css">
20 .package TH { font-size: medium }
21 .package TR { font-size: smaller }
22 .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>!;
39 function cancel_areyousure(href) {
40 if (confirm("Perminantly delete all services and cancel this customer?") == true)
41 window.location.href = href;
47 print qq! | <A HREF="javascript:cancel_areyousure('${p}misc/cust_main-cancel.cgi?$custnum')">!.
48 'Cancel this customer</A>'
49 if $cust_main->ncancelled_pkgs;
51 print qq! | <A HREF="${p}misc/delete-customer.cgi?$custnum">!.
52 'Delete this customer</A>'
53 if $conf->exists('deletecustomers');
55 unless ( $conf->exists('disable_customer_referrals') ) {
56 print qq! | <A HREF="!, popurl(2),
57 qq!edit/cust_main.cgi?referral_custnum=$custnum">!,
58 qq!Refer a new customer</A>!;
60 print qq! | <A HREF="!, popurl(2),
61 qq!search/cust_main.cgi?referral_custnum=$custnum">!,
62 qq!View this customer's referrals</A>!;
67 my $signupurl = $conf->config('signupurl');
69 print "This customer's signup URL: ".
70 "<a href=\"$signupurl?ref=$custnum\">$signupurl?ref=$custnum</a><BR><BR>";
73 print '<A NAME="cust_main"></A>';
75 print &itable(), '<TR>';
77 print '<TD VALIGN="top">';
79 print "Billing address", &ntable("#cccccc"), "<TR><TD>",
81 '<TR><TD ALIGN="right">Contact name</TD>',
82 '<TD COLSPAN=3 BGCOLOR="#ffffff">',
83 $cust_main->last, ', ', $cust_main->first,
85 print '<TD ALIGN="right">SS#</TD><TD BGCOLOR="#ffffff">',
86 $cust_main->ss || ' ', '</TD>'
87 if $conf->exists('show_ss');
90 '<TR><TD ALIGN="right">Company</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
93 '<TR><TD ALIGN="right">Address</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
97 print '<TR><TD ALIGN="right"> </TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
98 $cust_main->address2, '</TD></TR>'
99 if $cust_main->address2;
100 print '<TR><TD ALIGN="right">City</TD><TD BGCOLOR="#ffffff">',
102 '</TD><TD ALIGN="right">State</TD><TD BGCOLOR="#ffffff">',
104 '</TD><TD ALIGN="right">Zip</TD><TD BGCOLOR="#ffffff">',
105 $cust_main->zip, '</TD></TR>',
106 '<TR><TD ALIGN="right">Country</TD><TD BGCOLOR="#ffffff">',
110 my $daytime_label = FS::Msgcat::_gettext('daytime') || 'Day Phone';
111 my $night_label = FS::Msgcat::_gettext('night') || 'Night Phone';
112 print '<TR><TD ALIGN="right">'. $daytime_label.
113 '</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
114 $cust_main->daytime || ' ', '</TD></TR>',
115 '<TR><TD ALIGN="right">'. $night_label.
116 '</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
117 $cust_main->night || ' ', '</TD></TR>',
118 '<TR><TD ALIGN="right">Fax</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
119 $cust_main->fax || ' ', '</TD></TR>',
120 '</TABLE>', "</TD></TR></TABLE>"
123 if ( defined $cust_main->dbdef_table->column('ship_last') ) {
125 my $pre = $cust_main->ship_last ? 'ship_' : '';
127 print "<BR>Service address", &ntable("#cccccc"), "<TR><TD>",
128 &ntable("#cccccc",2),
129 '<TR><TD ALIGN="right">Contact name</TD>',
130 '<TD COLSPAN=5 BGCOLOR="#ffffff">',
131 $cust_main->get("${pre}last"), ', ', $cust_main->get("${pre}first"),
133 '<TR><TD ALIGN="right">Company</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
134 $cust_main->get("${pre}company"),
136 '<TR><TD ALIGN="right">Address</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
137 $cust_main->get("${pre}address1"),
140 print '<TR><TD ALIGN="right"> </TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
141 $cust_main->get("${pre}address2"), '</TD></TR>'
142 if $cust_main->get("${pre}address2");
143 print '<TR><TD ALIGN="right">City</TD><TD BGCOLOR="#ffffff">',
144 $cust_main->get("${pre}city"),
145 '</TD><TD ALIGN="right">State</TD><TD BGCOLOR="#ffffff">',
146 $cust_main->get("${pre}state"),
147 '</TD><TD ALIGN="right">Zip</TD><TD BGCOLOR="#ffffff">',
148 $cust_main->get("${pre}zip"), '</TD></TR>',
149 '<TR><TD ALIGN="right">Country</TD><TD BGCOLOR="#ffffff">',
150 $cust_main->get("${pre}country"),
153 print '<TR><TD ALIGN="right">'. $daytime_label. '</TD>',
154 '<TD COLSPAN=5 BGCOLOR="#ffffff">',
155 $cust_main->get("${pre}daytime") || ' ', '</TD></TR>',
156 '<TR><TD ALIGN="right">'. $night_label. '</TD>'.
157 '<TD COLSPAN=5 BGCOLOR="#ffffff">',
158 $cust_main->get("${pre}night") || ' ', '</TD></TR>',
159 '<TR><TD ALIGN="right">Fax</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
160 $cust_main->get("${pre}fax") || ' ', '</TD></TR>',
161 '</TABLE>', "</TD></TR></TABLE>"
168 print '<TD VALIGN="top">';
170 print &ntable("#cccccc"), "<TR><TD>", &ntable("#cccccc",2),
171 '<TR><TD ALIGN="right">Customer number</TD><TD BGCOLOR="#ffffff">',
172 $custnum, '</TD></TR>',
175 my @agents = qsearch( 'agent', {} );
177 unless ( scalar(@agents) == 1 ) {
178 $agent = qsearchs('agent',{ 'agentnum' => $cust_main->agentnum } );
179 print '<TR><TD ALIGN="right">Agent</TD><TD BGCOLOR="#ffffff">',
180 $agent->agentnum, ": ", $agent->agent, '</TD></TR>';
184 my @referrals = qsearch( 'part_referral', {} );
185 unless ( scalar(@referrals) == 1 ) {
186 my $referral = qsearchs('part_referral', {
187 'refnum' => $cust_main->refnum
189 print '<TR><TD ALIGN="right">Advertising source</TD><TD BGCOLOR="#ffffff">',
190 $referral->refnum, ": ", $referral->referral, '</TD></TR>';
192 print '<TR><TD ALIGN="right">Order taker</TD><TD BGCOLOR="#ffffff">',
193 $cust_main->otaker, '</TD></TR>';
195 print '<TR><TD ALIGN="right">Referring Customer</TD><TD BGCOLOR="#ffffff">';
196 my $referring_cust_main = '';
197 if ( $cust_main->referral_custnum
198 && ( $referring_cust_main =
199 qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
202 print '<A HREF="'. popurl(1). 'cust_main.cgi?'.
203 $cust_main->referral_custnum. '">'.
204 $cust_main->referral_custnum. ': '.
205 ( $referring_cust_main->company
206 ? $referring_cust_main->company. ' ('.
207 $referring_cust_main->last. ', '. $referring_cust_main->first.
209 : $referring_cust_main->last. ', '. $referring_cust_main->first
215 print '</TABLE></TD></TR></TABLE>';
219 if ( $conf->config('payby-default') ne 'HIDE' ) {
221 my @invoicing_list = $cust_main->invoicing_list;
222 print "Billing information (",
223 qq!<A HREF="!, popurl(2), qq!misc/bill.cgi?$custnum">!, "Bill now</A>)",
224 &ntable("#cccccc"), "<TR><TD>", &ntable("#cccccc",2),
225 '<TR><TD ALIGN="right">Tax exempt</TD><TD BGCOLOR="#ffffff">',
226 $cust_main->tax ? 'yes' : 'no',
228 '<TR><TD ALIGN="right">Postal invoices</TD><TD BGCOLOR="#ffffff">',
229 ( grep { $_ eq 'POST' } @invoicing_list ) ? 'yes' : 'no',
231 '<TR><TD ALIGN="right">Email invoices</TD><TD BGCOLOR="#ffffff">',
232 join(', ', grep { $_ ne 'POST' } @invoicing_list ) || 'no',
234 '<TR><TD ALIGN="right">Billing type</TD><TD BGCOLOR="#ffffff">',
237 if ( $cust_main->payby eq 'CARD' || $cust_main->payby eq 'DCRD' ) {
238 my $payinfo = $cust_main->payinfo;
239 $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4));
240 print 'Credit card ',
241 ( $cust_main->payby eq 'CARD' ? '(automatic)' : '(on-demand)' ),
243 '<TR><TD ALIGN="right">Card number</TD><TD BGCOLOR="#ffffff">',
244 $payinfo, '</TD></TR>',
245 '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
246 $cust_main->paydate, '</TD></TR>',
247 '<TR><TD ALIGN="right">Name on card</TD><TD BGCOLOR="#ffffff">',
248 $cust_main->payname, '</TD></TR>'
250 } elsif ( $cust_main->payby eq 'CHEK' || $cust_main->payby eq 'DCHK') {
251 my( $account, $aba ) = split('@', $cust_main->payinfo );
252 print 'Electronic check ',
253 ( $cust_main->payby eq 'CHEK' ? '(automatic)' : '(on-demand)' ),
255 '<TR><TD ALIGN="right">Account number</TD><TD BGCOLOR="#ffffff">',
256 $account, '</TD></TR>',
257 '<TR><TD ALIGN="right">ABA/Routing code</TD><TD BGCOLOR="#ffffff">',
259 '<TR><TD ALIGN="right">Bank name</TD><TD BGCOLOR="#ffffff">',
260 $cust_main->payname, '</TD></TR>'
262 } elsif ( $cust_main->payby eq 'LECB' ) {
263 $cust_main->payinfo =~ /^(\d{3})(\d{3})(\d{4})$/;
264 my $payinfo = "$1-$2-$3";
265 print 'Phone bill billing</TD></TR>',
266 '<TR><TD ALIGN="right">Phone number</TD><TD BGCOLOR="#ffffff">',
267 $payinfo, '</TD></TR>',
269 } elsif ( $cust_main->payby eq 'BILL' ) {
270 print 'Billing</TD></TR>';
271 print '<TR><TD ALIGN="right">P.O. </TD><TD BGCOLOR="#ffffff">',
272 $cust_main->payinfo, '</TD></TR>',
273 if $cust_main->payinfo;
274 print '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
275 $cust_main->paydate, '</TD></TR>',
276 '<TR><TD ALIGN="right">Attention</TD><TD BGCOLOR="#ffffff">',
277 $cust_main->payname, '</TD></TR>',
279 } elsif ( $cust_main->payby eq 'COMP' ) {
280 print 'Complimentary</TD></TR>',
281 '<TR><TD ALIGN="right">Authorized by</TD><TD BGCOLOR="#ffffff">',
282 $cust_main->payinfo, '</TD></TR>',
283 '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
284 $cust_main->paydate, '</TD></TR>',
288 print "</TABLE></TD></TR></TABLE>";
292 print '</TD></TR></TABLE>';
294 if ( defined $cust_main->dbdef_table->column('comments')
295 && $cust_main->comments =~ /[^\s\n\r]/ )
297 print "<BR>Comments". &ntable("#cccccc"). "<TR><TD>".
298 &ntable("#cccccc",2).
299 '<TR><TD BGCOLOR="#ffffff"><PRE>'.
300 encode_entities($cust_main->comments).
301 '</PRE></TD></TR></TABLE></TABLE>';
309 <SCRIPT TYPE="text/javascript">
310 function enable_order_pkg () {
311 if ( document.OrderPkgForm.pkgpart.selectedIndex > 0 ) {
312 document.OrderPkgForm.submit.disabled = false;
314 document.OrderPkgForm.submit.disabled = true;
318 <FORM NAME="OrderPkgForm" ACTION="<%= $p %>edit/process/quick-cust_pkg.cgi" METHOD="POST">
319 <INPUT TYPE="hidden" NAME="custnum" VALUE="<%= $custnum %>">
320 <SELECT NAME="pkgpart" onChange="enable_order_pkg()"><OPTION>Order additional package
323 foreach my $part_pkg (
324 qsearch( 'part_pkg', { 'disabled' => '' }, '',
325 ' AND 0 < ( SELECT COUNT(*) FROM type_pkgs '.
326 ' WHERE typenum = '. $agent->typenum.
327 ' AND type_pkgs.pkgpart = part_pkg.pkgpart )'
331 <OPTION VALUE="<%= $part_pkg->pkgpart %>"><%= $part_pkg->pkg %> - <%= $part_pkg->comment %>
334 </SELECT><INPUT NAME="submit" TYPE="submit" VALUE="Order Package" disabled></FORM><BR>
338 if ( $conf->config('payby-default') ne 'HIDE' ) {
341 qq!<FORM ACTION="${p}edit/process/quick-charge.cgi" METHOD="POST">!.
342 qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!.
343 qq!Description:<INPUT TYPE="text" NAME="pkg">!.
344 qq! Amount:<INPUT TYPE="text" NAME="amount" SIZE=6>!.
347 #false laziness w/ edit/part_pkg.cgi
348 if ( $conf->exists('enable_taxclasses') ) {
349 print '<SELECT NAME="taxclass">';
350 my $sth = dbh->prepare('SELECT DISTINCT taxclass FROM cust_main_county')
352 $sth->execute or die $sth->errstr;
353 foreach my $taxclass ( map $_->[0], @{$sth->fetchall_arrayref} ) {
354 print qq!<OPTION VALUE="$taxclass"!;
355 #print ' SELECTED' if $taxclass eq $hashref->{taxclass};
356 print qq!>$taxclass</OPTION>!;
360 print '<INPUT TYPE="hidden" NAME="taxclass" VALUE="">';
363 print qq!<INPUT TYPE="submit" VALUE="One-time charge"></FORM><BR>!;
370 function cust_pkg_areyousure(href) {
371 if (confirm("Permanently delete included services and cancel this package?") == true)
372 window.location.href = href;
374 function svc_areyousure(href) {
375 if (confirm("Permanently unprovision and delete this service?") == true)
376 window.location.href = href;
382 print qq!<A NAME="cust_pkg">Packages</A> !,
383 qq!( <A HREF="!, popurl(2), qq!edit/cust_pkg.cgi?$custnum">Order and cancel packages</A> (preserves services) )!,
386 #begin display packages
390 my $packages = get_packages($cust_main, $conf);
394 <TABLE CLASS="package" BORDER=1 CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">
398 <TH COLSPAN=2>Services</TH>
401 foreach my $pkg (sort pkgsort_pkgnum_cancel @$packages) {
404 if ($pkg->{cancel}) {
407 foreach my $svcpart (@{$pkg->{svcparts}}) {
408 $rowspan += $svcpart->{count};
409 $rowspan++ if ($svcpart->{count} < $svcpart->{quantity});
414 <!--pkgnum: <%=$pkg->{pkgnum}%>-->
416 <TD ROWSPAN=<%=$rowspan%>>
417 <A NAME="cust_pkg<%=$pkg->{pkgnum}%>"><%=$pkg->{pkgnum}%></A>:
418 <%=$pkg->{pkg}%> - <%=$pkg->{comment}%><BR>
419 <% unless ($pkg->{cancel}) { %>
420 ( <%=pkg_change_link($pkg)%> )
421 ( <%=pkg_dates_link($pkg)%> | <%=pkg_customize_link($pkg,$custnum)%> )
425 #foreach (qw(setup last_bill next_bill susp expire cancel)) {
426 # print qq! <TD ROWSPAN=$rowspan>! . pkg_datestr($pkg,$_,$conf) . qq!</TD>\n!;
428 print "<TD ROWSPAN=$rowspan>". &itable('');
432 #false laziness w/edit/part_pkg.cgi
433 my %freq = ( #move this
436 '2w' => 'biweekly (every 2 weeks)',
438 '2' => 'bimonthly (every 2 months)',
439 '3' => 'quarterly (every 3 months)',
440 '6' => 'semiannually (every 6 months)',
442 '24' => 'biannually (every 2 years)',
446 exists $freq{$freq} ? $freq{$freq} : "every $freq months";
451 if ( $pkg->{cancel} ) { #status: cancelled
453 print '<TR><TD><FONT COLOR="#ff0000"><B>Cancelled </B></FONT></TD>'.
454 '<TD>'. pkg_datestr($pkg,'cancel',$conf). '</TD></TR>';
455 unless ( $pkg->{setup} ) {
456 print '<TR><TD COLSPAN=2>Never billed</TD></TR>';
458 print "<TR><TD>Setup </TD><TD>".
459 pkg_datestr($pkg, 'setup',$conf). '</TD></TR>';
460 print "<TR><TD>Last bill </TD><TD>".
461 pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>'
462 if $pkg->{'last_bill'};
463 print "<TR><TD>Suspended </TD><TD>".
464 pkg_datestr($pkg, 'susp',$conf). '</TD></TR>'
470 if ( $pkg->{susp} ) { #status: suspended
471 print '<TR><TD><FONT COLOR="#FF9900"><B>Suspended</B> </FONT></TD>'.
472 '<TD>'. pkg_datestr($pkg,'susp',$conf). '</TD></TR>';
473 unless ( $pkg->{setup} ) {
474 print '<TR><TD COLSPAN=2>Never billed</TD></TR>';
476 print "<TR><TD>Setup </TD><TD>".
477 pkg_datestr($pkg, 'setup',$conf). '</TD></TR>';
479 print "<TR><TD>Last bill </TD><TD>".
480 pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>'
481 if $pkg->{'last_bill'};
483 print "<TR><TD>Expires </TD><TD>".
484 pkg_datestr($pkg, 'expire',$conf). '</TD></TR>'
486 print '<TR><TD COLSPAN=2>( '. pkg_unsuspend_link($pkg).
487 ' | '. pkg_cancel_link($pkg). ' )</TD></TR>';
489 } else { #status: active
491 unless ( $pkg->{setup} ) { #not setup
493 print '<TR><TD COLSPAN=2>Not yet billed (';
494 unless ( $pkg->{freq} ) {
495 print 'one-time charge)</TD></TR>';
496 print '<TR><TD COLSPAN=2>( '. pkg_cancel_link($pkg).
499 print 'billed '. freq($pkg->{freq}). ')</TD></TR>';
504 unless ( $pkg->{freq} ) {
505 print "<TR><TD COLSPAN=2>One-time charge</TD></TR>".
506 '<TR><TD>Billed </TD><TD>'.
507 pkg_datestr($pkg,'setup',$conf). '</TD></TR>';
509 print '<TR><TD COLSPAN=2><FONT COLOR="#00CC00"><B>Active</B></FONT>'.
510 ', billed '. freq($pkg->{freq}). '</TD></TR>'.
511 '<TR><TD>Setup </TD><TD>'.
512 pkg_datestr($pkg, 'setup',$conf). '</TD></TR>';
517 print "<TR><TD>Last bill </TD><TD>".
518 pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>'
519 if $pkg->{'last_bill'};
520 print "<TR><TD>Next bill </TD><TD>".
521 pkg_datestr($pkg, 'next_bill',$conf). '</TD></TR>'
522 if $pkg->{'next_bill'};
523 print "<TR><TD>Expires </TD><TD>".
524 pkg_datestr($pkg, 'expire',$conf). '</TD></TR>'
526 if ( $pkg->{freq} ) {
527 print '<TR><TD COLSPAN=2>( '. pkg_suspend_link($pkg).
528 ' | '. pkg_cancel_link($pkg). ' )</TD></TR>';
535 print "</TABLE></TD>\n";
537 if ($rowspan == 0) { print qq!</TR>\n!; next; }
540 foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
541 foreach my $service (@{$svcpart->{services}}) {
542 print '<TR>' if ($cnt > 0);
544 <TD><%=svc_link($svcpart,$service)%></TD>
545 <TD><%=svc_label_link($svcpart,$service)%><BR>( <%=svc_unprovision_link($service)%> )</TD>
550 if ($svcpart->{count} < $svcpart->{quantity}) {
551 print qq!<TR>\n! if ($cnt > 0);
552 print qq! <TD COLSPAN=2>!.svc_provision_link($pkg, $svcpart, $conf).qq!</TD>\n</TR>\n!;
559 #end display packages
563 function cust_pay_areyousure(href) {
564 if (confirm("Are you sure you want to delete this payment?")
566 window.location.href = href;
568 function cust_pay_unapply_areyousure(href) {
569 if (confirm("Are you sure you want to unapply this payment?")
571 window.location.href = href;
573 function cust_credit_unapply_areyousure(href) {
574 if (confirm("Are you sure you want to unapply this credit?")
576 window.location.href = href;
578 function cust_credit_areyousure(href) {
579 if (confirm("Are you sure you want to delete this credit?")
581 window.location.href = href;
585 <% if ( $conf->config('payby-default') ne 'HIDE' ) { %>
587 <BR><BR><A NAME="history">Payment History</A>
588 (<A HREF="<%= $p %>edit/cust_pay.cgi?custnum=<%= $custnum %>">Post payment</A>
589 | <A HREF="<%= $p %>edit/cust_credit.cgi?<%= $custnum %>">Post credit</A>)
596 foreach my $cust_bill ($cust_main->cust_bill) {
597 my $pre = ( $cust_bill->owed > 0 )
598 ? '<B><FONT SIZE="+1" COLOR="#FF0000">Open '
600 my $post = ( $cust_bill->owed > 0 ) ? '</FONT></B>' : '';
601 my $invnum = $cust_bill->invnum;
603 'date' => $cust_bill->_date,
604 'desc' => qq!<A HREF="${p}view/cust_bill.cgi?$invnum">!. $pre.
605 "Invoice #$invnum (Balance \$". $cust_bill->owed. ')'.
607 'charge' => $cust_bill->charged,
611 #payments (some false laziness w/credits)
612 foreach my $cust_pay ($cust_main->cust_pay) {
614 my $payby = $cust_pay->payby;
615 my $payinfo = $cust_pay->payinfo;
616 my @cust_bill_pay = $cust_pay->cust_bill_pay;
618 $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4))
620 my $target = "$payby$payinfo";
621 $payby =~ s/^BILL$/Check #/ if $payinfo;
622 $payby =~ s/^BILL$//;
623 $payby =~ s/^(CARD|COMP)$/$1 /;
624 my $info = $payby ? " ($payby$payinfo)" : '';
626 my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
627 if ( scalar(@cust_bill_pay) == 0 ) {
628 #completely unapplied
629 $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
630 $post = '</FONT></B>';
631 $apply = qq! (<A HREF="${p}edit/cust_bill_pay.cgi?!.
632 $cust_pay->paynum. '">apply</A>)';
633 } elsif ( scalar(@cust_bill_pay) == 1 && $cust_pay->unapplied == 0 ) {
634 #applied to one invoice
635 $desc = ' applied to Invoice #'. $cust_bill_pay[0]->invnum;
639 foreach my $cust_bill_pay (@cust_bill_pay) {
640 $desc .= ' '.
641 '$'. $cust_bill_pay->amount.
642 ' applied to Invoice #'. $cust_bill_pay->invnum.
644 #' on '. time2str("%D", $cust_bill_pay->_date).
647 if ( $cust_pay->unapplied > 0 ) {
648 $desc .= ' '.
649 '<B><FONT COLOR="#FF0000">$'.
650 $cust_pay->unapplied. ' unapplied</FONT></B>'.
651 qq! (<A HREF="${p}edit/cust_bill_pay.cgi?!.
652 $cust_pay->paynum. '">apply</A>)'.
658 if ( $cust_pay->closed !~ /^Y/i && $conf->exists('deletepayments') ) {
659 $delete = qq! (<A HREF="javascript:cust_pay_areyousure('!.
660 qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
665 if ( $cust_pay->closed !~ /^Y/i
666 && $conf->exists('unapplypayments')
667 && scalar(@cust_bill_pay) ) {
668 $unapply = qq! (<A HREF="javascript:cust_pay_unapply_areyousure('!.
669 qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
670 qq!')">unapply</A>)!;
674 'date' => $cust_pay->_date,
675 'desc' => $pre. "Payment$post$info$desc".
676 "$apply$delete$unapply",
677 'payment' => $cust_pay->paid,
682 #credits (some false laziness w/payments)
683 foreach my $cust_credit ($cust_main->cust_credit) {
685 my @cust_credit_bill = $cust_credit->cust_credit_bill;
686 my @cust_credit_refund = $cust_credit->cust_credit_refund;
688 my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
689 if ( scalar(@cust_credit_bill) == 0
690 && scalar(@cust_credit_refund) == 0 ) {
691 #completely unapplied
692 $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
693 $post = '</FONT></B>';
694 $apply = qq! (<A HREF="${p}edit/cust_credit_bill.cgi?!.
695 $cust_credit->crednum. '">apply</A>)';
696 } elsif ( scalar(@cust_credit_bill) == 1
697 && scalar(@cust_credit_refund) == 0
698 && $cust_credit->credited == 0 ) {
699 #applied to one invoice
700 $desc = ' applied to Invoice #'. $cust_credit_bill[0]->invnum;
701 } elsif ( scalar(@cust_credit_bill) == 0
702 && scalar(@cust_credit_refund) == 1
703 && $cust_credit->credited == 0 ) {
704 #applied to one refund
705 $desc = ' refunded on '. time2str("%D", $cust_credit_refund[0]->_date);
709 foreach my $app ( sort { $a->_date <=> $b->_date }
710 ( @cust_credit_bill, @cust_credit_refund ) ) {
711 if ( $app->isa('FS::cust_credit_bill') ) {
712 $desc .= ' '.
714 ' applied to Invoice #'. $app->invnum.
716 #' on '. time2str("%D", $app->_date).
717 } elsif ( $app->isa('FS::cust_credit_refund') ) {
718 $desc .= ' '.
720 ' refunded on'. time2str("%D", $app->_date).
723 die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
726 if ( $cust_credit->credited > 0 ) {
727 $desc .= ' <B><FONT COLOR="#FF0000">$'.
728 $cust_credit->credited. ' unapplied</FONT></B>'.
729 qq! (<A HREF="${p}edit/cust_credit_bill.cgi?!.
730 $cust_credit->crednum. '">apply</A>)'.
736 if ( $cust_credit->closed !~ /^Y/i && $conf->exists('deletecredits') ) {
737 $delete = qq! (<A HREF="javascript:cust_credit_areyousure('!.
738 qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
743 if ( $cust_credit->closed !~ /^Y/i
744 && $conf->exists('unapplycredits')
745 && scalar(@cust_credit_bill) ) {
746 $unapply = qq! (<A HREF="javascript:cust_credit_unapply_areyousure('!.
747 qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
748 qq!')">unapply</A>)!;
752 'date' => $cust_credit->_date,
753 'desc' => $pre. "Credit$post by ". $cust_credit->otaker.
754 ' ('. $cust_credit->reason. ')'.
755 "$desc$apply$delete$unapply",
756 'credit' => $cust_credit->amount,
762 foreach my $cust_refund ($cust_main->cust_refund) {
764 my $payby = $cust_refund->payby;
765 my $payinfo = $cust_refund->payinfo;
767 $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4))
769 $payby =~ s/^BILL$/Check #/ if $payinfo;
770 $payby =~ s/^(CARD|COMP)$/$1 /;
773 'date' => $cust_refund->_date,
774 'desc' => "Refund ($payby$payinfo) by ". $cust_refund->otaker,
775 'refund' => $cust_refund->refund,
786 <TH><FONT SIZE=-1>Charge</FONT></TH>
787 <TH><FONT SIZE=-1>Payment</FONT></TH>
788 <TH><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
789 <TH><FONT SIZE=-1>Refund</FONT></TH>
790 <TH><FONT SIZE=-1>Balance</FONT></TH>
794 #display payment history
798 foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
800 my $charge = exists($item->{'charge'})
801 ? sprintf('$%.2f', $item->{'charge'})
803 my $payment = exists($item->{'payment'})
804 ? sprintf('- $%.2f', $item->{'payment'})
806 my $credit = exists($item->{'credit'})
807 ? sprintf('- $%.2f', $item->{'credit'})
809 my $refund = exists($item->{'refund'})
810 ? sprintf('$%.2f', $item->{'refund'})
813 my $target = exists($item->{'target'}) ? $item->{'target'} : '';
815 $balance += $item->{'charge'} if exists $item->{'charge'};
816 $balance -= $item->{'payment'} if exists $item->{'payment'};
817 $balance -= $item->{'credit'} if exists $item->{'credit'};
818 $balance += $item->{'refund'} if exists $item->{'refund'};
819 $balance = sprintf("%.2f", $balance);
820 $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
821 ( my $showbalance = '$'. $balance ) =~ s/^\$\-/- \$/;
827 <% unless ( !$target || $target{$target}++ ) { %>
828 <A NAME="<%= $target %>">
830 <%= time2str("%D",$item->{'date'}) %>
831 <% if ( $target && $target{$target} == 1 ) { %>
836 <TD><%= $item->{'desc'} %></TD>
837 <TD ALIGN="right"><%= $charge %></TD>
838 <TD ALIGN="right"><%= $payment %></TD>
839 <TD ALIGN="right"><%= $credit %></TD>
840 <TD ALIGN="right"><%= $refund %></TD>
841 <TD ALIGN="right"><%= $showbalance %></TD>
856 my $cust_main = shift or return undef;
861 foreach my $cust_pkg (
862 $conf->exists('hidecancelledpackages')
863 ? $cust_main->ncancelled_pkgs
864 : $cust_main->all_pkgs
867 my $part_pkg = $cust_pkg->part_pkg;
870 $pkg{pkgnum} = $cust_pkg->pkgnum;
871 $pkg{pkg} = $part_pkg->pkg;
872 $pkg{pkgpart} = $part_pkg->pkgpart;
873 $pkg{comment} = $part_pkg->getfield('comment');
874 $pkg{freq} = $part_pkg->freq;
875 $pkg{setup} = $cust_pkg->getfield('setup');
876 $pkg{last_bill} = $cust_pkg->getfield('last_bill');
877 $pkg{next_bill} = $cust_pkg->getfield('bill');
878 $pkg{susp} = $cust_pkg->getfield('susp');
879 $pkg{expire} = $cust_pkg->getfield('expire');
880 $pkg{cancel} = $cust_pkg->getfield('cancel');
884 foreach my $pkg_svc (
885 qsearch('pkg_svc', { 'pkgpart' => $part_pkg->pkgpart })
888 next if ($pkg_svc->quantity == 0);
890 my $part_svc = qsearchs('part_svc', { 'svcpart' => $pkg_svc->svcpart });
893 $svcpart->{svcpart} = $part_svc->svcpart;
894 $svcpart->{svc} = $part_svc->svc;
895 $svcpart->{svcdb} = $part_svc->svcdb;
896 $svcpart->{quantity} = $pkg_svc->quantity;
897 $svcpart->{count} = 0;
899 $svcpart->{services} = [];
901 $svcparts{$svcpart->{svcpart}} = $svcpart;
905 foreach my $cust_svc (
906 qsearch( 'cust_svc', {
907 'pkgnum' => $cust_pkg->pkgnum,
908 #'svcpart' => $part_svc->svcpart,
913 #warn "svcnum ". $cust_svc->svcnum. " / svcpart ". $cust_svc->svcpart. "\n";
915 'svcnum' => $cust_svc->svcnum,
916 'label' => ($cust_svc->label)[1],
919 #false laziness with above, to catch extraneous services. whole
920 #damn thing should be OO...
921 my $svcpart = ( $svcparts{$cust_svc->svcpart} ||= {
922 'svcpart' => $cust_svc->svcpart,
923 'svc' => $cust_svc->part_svc->svc,
924 'svcdb' => $cust_svc->part_svc->svcdb,
930 push @{$svcpart->{services}}, $svc;
936 $pkg{svcparts} = [ values %svcparts ];
938 push @packages, \%pkg;
948 my ($svcpart, $svc) = (shift,shift) or return '';
949 return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svcpart->{svc}</A>!;
955 my ($svcpart, $svc) = (shift,shift) or return '';
956 return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svc->{label}</A>!;
960 sub svc_provision_link {
961 my ($pkg, $svcpart, $conf) = @_;
962 ( my $svc_nbsp = $svcpart->{svc} ) =~ s/\s+/ /g;
963 my $pkgnum_svcpart = "pkgnum$pkg->{pkgnum}-svcpart$svcpart->{svcpart}";
964 my $num_left = $svcpart->{quantity} - $svcpart->{count};
966 my $link = qq!<A CLASS="provision" HREF="${p}edit/$svcpart->{svcdb}.cgi?!.
967 qq!$pkgnum_svcpart">!.
968 "Provision $svc_nbsp ($num_left)</A>";
969 if ( $conf->exists('legacy_link') ) {
971 qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
972 qq!$pkgnum_svcpart">!.
973 "Link to legacy $svc_nbsp ($num_left)</A>";
978 sub svc_unprovision_link {
979 my $svc = shift or return '';
980 return qq!<A HREF="javascript:svc_areyousure('${p}misc/unprovision.cgi?$svc->{svcnum}')">Unprovision</A>!;
983 # This should be generalized to use config options to determine order.
984 sub pkgsort_pkgnum_cancel {
985 if ($a->{cancel} and $b->{cancel}) {
986 return ($a->{pkgnum} <=> $b->{pkgnum});
987 } elsif ($a->{cancel} or $b->{cancel}) {
988 return (-1) if ($b->{cancel});
989 return (1) if ($a->{cancel});
992 return($a->{pkgnum} <=> $b->{pkgnum});
997 my($pkg, $field, $conf) = @_ or return '';
998 return ' ' unless $pkg->{$field};
999 my $format = $conf->exists('pkg_showtimes')
1000 ? '<B>%D</B> <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
1001 : '<B>%b %o, %Y</B>';
1002 ( my $strip = time2str($format, $pkg->{$field}) ) =~ s/ (\d)/$1/g;
1006 sub pkg_change_link {
1007 my $pkg = shift or return '';
1008 return qq!<a href="${p}misc/change_pkg.cgi?$pkg->{pkgnum}">Change package</a>!;
1011 sub pkg_suspend_link {
1012 my $pkg = shift or return '';
1013 return qq!<a href="${p}misc/susp_pkg.cgi?$pkg->{pkgnum}">Suspend</a>!;
1016 sub pkg_unsuspend_link {
1017 my $pkg = shift or return '';
1018 return qq!<a href="${p}misc/unsusp_pkg.cgi?$pkg->{pkgnum}">Unsuspend</a>!;
1021 sub pkg_cancel_link {
1022 my $pkg = shift or return '';
1023 qq!<A HREF="javascript:cust_pkg_areyousure('${p}misc/cancel_pkg.cgi?$pkg->{pkgnum}')">Cancel now</A> | !.
1024 qq!<A HREF="${p}misc/expire_pkg.cgi?$pkg->{pkgnum}">Cancel later</A>!;
1027 sub pkg_dates_link {
1028 my $pkg = shift or return '';
1029 return qq!<A HREF="${p}edit/REAL_cust_pkg.cgi?$pkg->{pkgnum}">Edit dates</A>!;
1032 sub pkg_customize_link {
1033 my $pkg = shift or return '';
1034 my $custnum = shift;
1035 return qq!<A HREF="${p}edit/part_pkg.cgi?keywords=$custnum;clone=$pkg->{pkgpart};pkgnum=$pkg->{pkgnum}">Customize</A>!;