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 areyousure(href, message) {
40 if (confirm(message) == true)
41 window.location.href = href;
47 print qq! | <A HREF="javascript:areyousure('${p}misc/cust_main-cancel.cgi?$custnum', 'Perminantly delete all services and cancel this customer?')">!.
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>";
75 <A NAME="cust_main"></A>
79 <%= include('cust_main/contacts.html', $cust_main ) %>
82 <%= include('cust_main/misc.html', $cust_main ) %>
83 <% if ( $conf->config('payby-default') ne 'HIDE' ) { %>
85 <%= include('cust_main/billing.html', $cust_main ) %>
92 if ( defined $cust_main->dbdef_table->column('comments')
93 && $cust_main->comments =~ /[^\s\n\r]/ ) {
97 <%= ntable("#cccccc") %><TR><TD><%= ntable("#cccccc",2) %>
99 <TD BGCOLOR="#ffffff">
100 <PRE><%= encode_entities($cust_main->comments) %></PRE>
106 <% if ( $conf->config('ticket_system') ) { %>
108 <%= include('cust_main/tickets.html', $cust_main ) %>
112 <SCRIPT TYPE="text/javascript">
113 function enable_order_pkg () {
114 if ( document.OrderPkgForm.pkgpart.selectedIndex > 0 ) {
115 document.OrderPkgForm.submit.disabled = false;
117 document.OrderPkgForm.submit.disabled = true;
121 <FORM NAME="OrderPkgForm" ACTION="<%= $p %>edit/process/quick-cust_pkg.cgi" METHOD="POST">
122 <INPUT TYPE="hidden" NAME="custnum" VALUE="<%= $custnum %>">
123 <SELECT NAME="pkgpart" onChange="enable_order_pkg()"><OPTION>Order additional package
127 my @agents = qsearch( 'agent', {} );
129 unless ( scalar(@agents) == 1 ) {
130 $agent = qsearchs('agent',{ 'agentnum' => $cust_main->agentnum } );
135 foreach my $part_pkg (
136 qsearch( 'part_pkg', { 'disabled' => '' }, '',
137 ' AND 0 < ( SELECT COUNT(*) FROM type_pkgs '.
138 ' WHERE typenum = '. $agent->typenum.
139 ' AND type_pkgs.pkgpart = part_pkg.pkgpart )'
143 <OPTION VALUE="<%= $part_pkg->pkgpart %>"><%= $part_pkg->pkg %> - <%= $part_pkg->comment %>
146 </SELECT><INPUT NAME="submit" TYPE="submit" VALUE="Order Package" disabled></FORM>
150 if ( $conf->config('payby-default') ne 'HIDE' ) {
153 qq!<FORM ACTION="${p}edit/process/quick-charge.cgi" METHOD="POST">!.
154 qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!.
155 qq!Description:<INPUT TYPE="text" NAME="pkg">!.
156 qq! Amount:<INPUT TYPE="text" NAME="amount" SIZE=6>!.
159 #false laziness w/ edit/part_pkg.cgi
160 if ( $conf->exists('enable_taxclasses') ) {
161 print '<SELECT NAME="taxclass">';
162 my $sth = dbh->prepare('SELECT DISTINCT taxclass FROM cust_main_county')
164 $sth->execute or die $sth->errstr;
165 foreach my $taxclass ( map $_->[0], @{$sth->fetchall_arrayref} ) {
166 print qq!<OPTION VALUE="$taxclass"!;
167 #print ' SELECTED' if $taxclass eq $hashref->{taxclass};
168 print qq!>$taxclass</OPTION>!;
172 print '<INPUT TYPE="hidden" NAME="taxclass" VALUE="">';
175 print qq!<INPUT TYPE="submit" VALUE="One-time charge"></FORM><BR>!;
179 print qq!<A NAME="cust_pkg">Packages</A> !,
180 qq!( <A HREF="!, popurl(2), qq!edit/cust_pkg.cgi?$custnum">Bulk order and cancel packages</A> (preserves services) )!,
183 #begin display packages
187 my $packages = get_packages($cust_main, $conf);
191 <TABLE CLASS="package" BORDER=1 CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">
195 <TH COLSPAN=2>Services</TH>
198 foreach my $pkg (sort pkgsort_pkgnum_cancel @$packages) {
201 if ($pkg->{cancel}) {
204 foreach my $svcpart (@{$pkg->{svcparts}}) {
205 $rowspan += $svcpart->{count};
206 $rowspan++ if ($svcpart->{count} < $svcpart->{quantity});
211 <!--pkgnum: <%=$pkg->{pkgnum}%>-->
213 <TD ROWSPAN=<%=$rowspan%>>
214 <A NAME="cust_pkg<%=$pkg->{pkgnum}%>"><%=$pkg->{pkgnum}%></A>:
215 <%=$pkg->{pkg}%> - <%=$pkg->{comment}%><BR>
216 <% unless ($pkg->{cancel}) { %>
217 ( <%=pkg_change_link($pkg)%> )
218 ( <%=pkg_dates_link($pkg)%> | <%=pkg_customize_link($pkg,$custnum)%> )
222 #foreach (qw(setup last_bill next_bill susp expire cancel)) {
223 # print qq! <TD ROWSPAN=$rowspan>! . pkg_datestr($pkg,$_,$conf) . qq!</TD>\n!;
225 print "<TD ROWSPAN=$rowspan>". &itable('');
228 my $part_pkg = shift;
229 my $freq = $part_pkg->freq_pretty;
230 $freq =~ s/ / /g;
234 if ( $pkg->{cancel} ) { #status: cancelled
236 print '<TR><TD><FONT COLOR="#ff0000"><B>Cancelled </B></FONT></TD>'.
237 '<TD>'. pkg_datestr($pkg,'cancel',$conf). '</TD></TR>';
238 unless ( $pkg->{setup} ) {
239 print '<TR><TD COLSPAN=2>Never billed</TD></TR>';
241 print "<TR><TD>Setup </TD><TD>".
242 pkg_datestr($pkg, 'setup',$conf). '</TD></TR>';
243 print "<TR><TD>Last bill </TD><TD>".
244 pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>'
245 if $pkg->{'last_bill'};
246 print "<TR><TD>Suspended </TD><TD>".
247 pkg_datestr($pkg, 'susp',$conf). '</TD></TR>'
253 if ( $pkg->{susp} ) { #status: suspended
254 print '<TR><TD><FONT COLOR="#FF9900"><B>Suspended</B> </FONT></TD>'.
255 '<TD>'. pkg_datestr($pkg,'susp',$conf). '</TD></TR>';
256 unless ( $pkg->{setup} ) {
257 print '<TR><TD COLSPAN=2>Never billed</TD></TR>';
259 print "<TR><TD>Setup </TD><TD>".
260 pkg_datestr($pkg, 'setup',$conf). '</TD></TR>';
262 print "<TR><TD>Last bill </TD><TD>".
263 pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>'
264 if $pkg->{'last_bill'};
266 print "<TR><TD>Expires </TD><TD>".
267 pkg_datestr($pkg, 'expire',$conf). '</TD></TR>'
269 print '<TR><TD COLSPAN=2>( '. pkg_unsuspend_link($pkg).
270 ' | '. pkg_cancel_link($pkg). ' )</TD></TR>';
272 } else { #status: active
274 unless ( $pkg->{setup} ) { #not setup
276 print '<TR><TD COLSPAN=2>Not yet billed (';
277 unless ( $pkg->{freq} ) {
278 print 'one-time charge)</TD></TR>';
279 print '<TR><TD COLSPAN=2>( '. pkg_cancel_link($pkg).
282 print 'billed '. myfreq($pkg->{part_pkg}). ')</TD></TR>';
287 unless ( $pkg->{freq} ) {
288 print "<TR><TD COLSPAN=2>One-time charge</TD></TR>".
289 '<TR><TD>Billed </TD><TD>'.
290 pkg_datestr($pkg,'setup',$conf). '</TD></TR>';
292 print '<TR><TD COLSPAN=2><FONT COLOR="#00CC00"><B>Active</B></FONT>'.
293 ', billed '. myfreq($pkg->{part_pkg}). '</TD></TR>'.
294 '<TR><TD>Setup </TD><TD>'.
295 pkg_datestr($pkg, 'setup',$conf). '</TD></TR>';
300 print "<TR><TD>Last bill </TD><TD>".
301 pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>'
302 if $pkg->{'last_bill'};
303 print "<TR><TD>Next bill </TD><TD>".
304 pkg_datestr($pkg, 'next_bill',$conf). '</TD></TR>'
305 if $pkg->{'next_bill'};
306 print "<TR><TD>Expires </TD><TD>".
307 pkg_datestr($pkg, 'expire',$conf). '</TD></TR>'
309 if ( $pkg->{freq} ) {
310 print '<TR><TD COLSPAN=2>( '. pkg_suspend_link($pkg).
311 ' | '. pkg_cancel_link($pkg). ' )</TD></TR>';
318 print "</TABLE></TD>\n";
320 if ($rowspan == 0) { print qq!</TR>\n!; next; }
323 foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
324 foreach my $service (@{$svcpart->{services}}) {
325 print '<TR>' if ($cnt > 0);
327 <TD><%=svc_link($svcpart,$service)%></TD>
328 <TD><%=svc_label_link($svcpart,$service)%><BR>( <%=svc_unprovision_link($service)%> )</TD>
333 if ($svcpart->{count} < $svcpart->{quantity}) {
334 print qq!<TR>\n! if ($cnt > 0);
335 print qq! <TD COLSPAN=2>!.svc_provision_link($pkg, $svcpart, $conf).qq!</TD>\n</TR>\n!;
342 #end display packages
345 <% if ( $conf->config('payby-default') ne 'HIDE' ) { %>
347 <BR><BR><A NAME="history"><FONT SIZE="+2">Payment History</FONT></A><BR>
348 <A HREF="<%= $p %>edit/cust_pay.cgi?custnum=<%= $custnum %>">Post cash/check payment</A>
349 | <A HREF="<%= $p %>misc/payment.cgi?payby=CARD;custnum=<%= $custnum %>">Process credit card payment</A>
350 | <A HREF="<%= $p %>misc/payment.cgi?payby=CHEK;custnum=<%= $custnum %>">Process electronic check (ACH) payment</A>
351 <BR><A HREF="<%= $p %>edit/cust_credit.cgi?<%= $custnum %>">Post credit</A>
359 foreach my $cust_bill ($cust_main->cust_bill) {
360 my $pre = ( $cust_bill->owed > 0 )
361 ? '<B><FONT SIZE="+1" COLOR="#FF0000">Open '
363 my $post = ( $cust_bill->owed > 0 ) ? '</FONT></B>' : '';
364 my $invnum = $cust_bill->invnum;
366 'date' => $cust_bill->_date,
367 'desc' => qq!<A HREF="${p}view/cust_bill.cgi?$invnum">!. $pre.
368 "Invoice #$invnum (Balance \$". $cust_bill->owed. ')'.
370 'charge' => $cust_bill->charged,
374 #payments (some false laziness w/credits)
375 foreach my $cust_pay ($cust_main->cust_pay) {
377 my $payby = $cust_pay->payby;
378 my $payinfo = $payby eq 'CARD'
379 ? $cust_pay->payinfo_masked
380 : $cust_pay->payinfo;
381 my @cust_bill_pay = $cust_pay->cust_bill_pay;
382 my @cust_pay_refund = $cust_pay->cust_pay_refund;
384 my $target = "$payby$payinfo";
385 $payby =~ s/^BILL$/Check #/ if $payinfo;
386 $payby =~ s/^CHEK$/Electronic check /;
387 $payby =~ s/^BILL$//;
388 $payby =~ s/^(CARD|COMP)$/$1 /;
389 my $info = $payby ? " ($payby$payinfo)" : '';
391 my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
392 if ( scalar(@cust_bill_pay) == 0
393 && scalar(@cust_pay_refund) == 0 ) {
394 #completely unapplied
395 $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
396 $post = '</FONT></B>';
397 $apply = qq! (<A HREF="${p}edit/cust_bill_pay.cgi?!.
398 $cust_pay->paynum. '">apply</A>)';
399 } elsif ( scalar(@cust_bill_pay) == 1
400 && scalar(@cust_pay_refund) == 0
401 && $cust_pay->unapplied == 0 ) {
402 #applied to one invoice, the usual situation
403 $desc = ' applied to Invoice #'. $cust_bill_pay[0]->invnum;
404 } elsif ( scalar(@cust_bill_pay) == 0
405 && scalar(@cust_pay_refund) == 1
406 && $cust_pay->unapplied == 0 ) {
407 #applied to one refund
408 $desc = ' refunded on '. time2str("%D", $cust_pay_refund[0]->_date);
412 foreach my $app ( sort { $a->_date <=> $b->_date }
413 ( @cust_bill_pay, @cust_pay_refund ) ) {
414 if ( $app->isa('FS::cust_bill_pay') ) {
415 $desc .= ' '.
417 ' applied to Invoice #'. $app->invnum.
419 #' on '. time2str("%D", $cust_bill_pay->_date).
420 } elsif ( $app->isa('FS::cust_pay_refund') ) {
421 $desc .= ' '.
423 ' refunded on'. time2str("%D", $app->_date).
426 die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
429 if ( $cust_pay->unapplied > 0 ) {
430 $desc .= ' '.
431 '<B><FONT COLOR="#FF0000">$'.
432 $cust_pay->unapplied. ' unapplied</FONT></B>'.
433 qq! (<A HREF="${p}edit/cust_bill_pay.cgi?!.
434 $cust_pay->paynum. '">apply</A>)'.
440 my $refund_days = $conf->config('card_refund-days') || 120;
441 if ( $cust_pay->closed !~ /^Y/i
442 && $cust_pay->payby =~ /^(CARD|CHEK)$/
443 && time-$cust_pay->_date < $refund_days*86400
444 && $cust_pay->unrefunded > 0
446 $refund = qq! (<A HREF="!. qq!${p}edit/cust_refund.cgi?payby=$1;!.
447 qq!paynum=!. $cust_pay->paynum. qq!">refund</A>)!;
451 if ( $cust_pay->closed !~ /^Y/i
452 && $cust_pay->payby !~ /^(CARD|CHEK)$/
454 $void = qq! (<A HREF="javascript:areyousure('!.
455 qq!${p}misc/void-cust_pay.cgi?!. $cust_pay->paynum.
456 qq!', 'Are you sure you want to void this payment?')">!.
461 if ( $cust_pay->closed !~ /^Y/i && $conf->exists('deletepayments') ) {
462 $delete = qq! (<A HREF="javascript:areyousure('!.
463 qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
464 qq!', 'Are you sure you want to delete this payment?')">!.
469 if ( $cust_pay->closed !~ /^Y/i
470 && $conf->exists('unapplypayments')
471 && scalar(@cust_bill_pay) ) {
472 $unapply = qq! (<A HREF="javascript:areyousure('!.
473 qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
474 qq!', 'Are you sure you want to unapply this payment?')">!.
479 'date' => $cust_pay->_date,
480 'desc' => $pre. "Payment$post$info$desc".
481 "$apply$refund$void$delete$unapply",
482 'payment' => $cust_pay->paid,
488 foreach my $cust_pay_void ($cust_main->cust_pay_void) {
490 my $payby = $cust_pay_void->payby;
491 my $payinfo = $payby eq 'CARD'
492 ? $cust_pay_void->payinfo_masked
493 : $cust_pay_void->payinfo;
495 $payby =~ s/^BILL$/Check #/ if $payinfo;
496 $payby =~ s/^CHEK$/Electronic check /;
497 $payby =~ s/^BILL$//;
498 $payby =~ s/^(CARD|COMP)$/$1 /;
499 my $info = $payby ? " ($payby$payinfo)" : '';
502 'date' => $cust_pay_void->_date,
503 'desc' => "<DEL>Payment $info</DEL> <I>voided ".
504 time2str("%D", $cust_pay_void->void_date).
505 " by ". $cust_pay_void->otaker. '</i>',
506 'void_payment' => $cust_pay_void->paid,
511 #credits (some false laziness w/payments)
512 foreach my $cust_credit ($cust_main->cust_credit) {
514 my @cust_credit_bill = $cust_credit->cust_credit_bill;
515 my @cust_credit_refund = $cust_credit->cust_credit_refund;
517 my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
518 if ( scalar(@cust_credit_bill) == 0
519 && scalar(@cust_credit_refund) == 0 ) {
520 #completely unapplied
521 $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
522 $post = '</FONT></B>';
523 $apply = qq! (<A HREF="${p}edit/cust_credit_bill.cgi?!.
524 $cust_credit->crednum. '">apply</A>)';
525 } elsif ( scalar(@cust_credit_bill) == 1
526 && scalar(@cust_credit_refund) == 0
527 && $cust_credit->credited == 0 ) {
528 #applied to one invoice, the usual situation
529 $desc = ' applied to Invoice #'. $cust_credit_bill[0]->invnum;
530 } elsif ( scalar(@cust_credit_bill) == 0
531 && scalar(@cust_credit_refund) == 1
532 && $cust_credit->credited == 0 ) {
533 #applied to one refund
534 $desc = ' refunded on '. time2str("%D", $cust_credit_refund[0]->_date);
538 foreach my $app ( sort { $a->_date <=> $b->_date }
539 ( @cust_credit_bill, @cust_credit_refund ) ) {
540 if ( $app->isa('FS::cust_credit_bill') ) {
541 $desc .= ' '.
543 ' applied to Invoice #'. $app->invnum.
545 #' on '. time2str("%D", $app->_date).
546 } elsif ( $app->isa('FS::cust_credit_refund') ) {
547 $desc .= ' '.
549 ' refunded on'. time2str("%D", $app->_date).
552 die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
555 if ( $cust_credit->credited > 0 ) {
556 $desc .= ' <B><FONT COLOR="#FF0000">$'.
557 $cust_credit->credited. ' unapplied</FONT></B>'.
558 qq! (<A HREF="${p}edit/cust_credit_bill.cgi?!.
559 $cust_credit->crednum. '">apply</A>)'.
565 if ( $cust_credit->closed !~ /^Y/i && $conf->exists('deletecredits') ) {
566 $delete = qq! (<A HREF="javascript:areyousure('!.
567 qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
568 qq!', 'Are you sure you want to delete this credit?')">!.
573 if ( $cust_credit->closed !~ /^Y/i
574 && $conf->exists('unapplycredits')
575 && scalar(@cust_credit_bill) ) {
576 $unapply = qq! (<A HREF="javascript:areyousure('!.
577 qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
578 qq!', 'Are you sure you want to unapply this credit?')">!.
583 'date' => $cust_credit->_date,
584 'desc' => $pre. "Credit$post by ". $cust_credit->otaker.
585 ' ('. $cust_credit->reason. ')'.
586 "$desc$apply$delete$unapply",
587 'credit' => $cust_credit->amount,
593 foreach my $cust_refund ($cust_main->cust_refund) {
595 my $payby = $cust_refund->payby;
596 my $payinfo = $payby eq 'CARD'
597 ? $cust_refund->payinfo_masked
598 : $cust_refund->payinfo;
600 $payby =~ s/^BILL$/Check #/ if $payinfo;
601 $payby =~ s/^CHEK$/Electronic check /;
602 $payby =~ s/^(CARD|COMP)$/$1 /;
605 'date' => $cust_refund->_date,
606 'desc' => "Refund ($payby$payinfo) by ". $cust_refund->otaker,
607 'refund' => $cust_refund->refund,
618 <TH><FONT SIZE=-1>Charge</FONT></TH>
619 <TH><FONT SIZE=-1>Payment</FONT></TH>
620 <TH><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
621 <TH><FONT SIZE=-1>Refund</FONT></TH>
622 <TH><FONT SIZE=-1>Balance</FONT></TH>
626 #display payment history
630 foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
632 my $charge = exists($item->{'charge'})
633 ? sprintf('$%.2f', $item->{'charge'})
635 my $payment = exists($item->{'payment'})
636 ? sprintf('- $%.2f', $item->{'payment'})
638 $payment ||= sprintf('<DEL>- $%.2f</DEL>', $item->{'void_payment'})
639 if exists($item->{'void_payment'});
640 my $credit = exists($item->{'credit'})
641 ? sprintf('- $%.2f', $item->{'credit'})
643 my $refund = exists($item->{'refund'})
644 ? sprintf('$%.2f', $item->{'refund'})
647 my $target = exists($item->{'target'}) ? $item->{'target'} : '';
649 $balance += $item->{'charge'} if exists $item->{'charge'};
650 $balance -= $item->{'payment'} if exists $item->{'payment'};
651 $balance -= $item->{'credit'} if exists $item->{'credit'};
652 $balance += $item->{'refund'} if exists $item->{'refund'};
653 $balance = sprintf("%.2f", $balance);
654 $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
655 ( my $showbalance = '$'. $balance ) =~ s/^\$\-/- \$/;
661 <% unless ( !$target || $target{$target}++ ) { %>
662 <A NAME="<%= $target %>">
664 <%= time2str("%D",$item->{'date'}) %>
665 <% if ( $target && $target{$target} == 1 ) { %>
670 <TD><%= $item->{'desc'} %></TD>
671 <TD ALIGN="right"><%= $charge %></TD>
672 <TD ALIGN="right"><%= $payment %></TD>
673 <TD ALIGN="right"><%= $credit %></TD>
674 <TD ALIGN="right"><%= $refund %></TD>
675 <TD ALIGN="right"><%= $showbalance %></TD>
690 my $cust_main = shift or return undef;
695 foreach my $cust_pkg (
696 $conf->exists('hidecancelledpackages')
697 ? $cust_main->ncancelled_pkgs
698 : $cust_main->all_pkgs
701 my $part_pkg = $cust_pkg->part_pkg;
705 #to get back to the original object... should use it in the first place!!
706 $pkg{cust_pkg} = $cust_pkg;
707 $pkg{part_pkg} = $part_pkg;
709 $pkg{pkgnum} = $cust_pkg->pkgnum;
710 $pkg{pkg} = $part_pkg->pkg;
711 $pkg{pkgpart} = $part_pkg->pkgpart;
712 $pkg{comment} = $part_pkg->getfield('comment');
713 $pkg{freq} = $part_pkg->freq;
714 $pkg{setup} = $cust_pkg->getfield('setup');
715 $pkg{last_bill} = $cust_pkg->getfield('last_bill');
716 $pkg{next_bill} = $cust_pkg->getfield('bill');
717 $pkg{susp} = $cust_pkg->getfield('susp');
718 $pkg{expire} = $cust_pkg->getfield('expire');
719 $pkg{cancel} = $cust_pkg->getfield('cancel');
725 'quantity' => $_->quantity,
726 'count' => $cust_pkg->num_cust_svc($_->svcpart),
729 } $part_pkg->pkg_svc;
731 foreach my $cust_svc ( $cust_pkg->cust_svc ) {
732 #warn "svcnum ". $cust_svc->svcnum. " / svcpart ". $cust_svc->svcpart. "\n";
734 'svcnum' => $cust_svc->svcnum,
735 'label' => ($cust_svc->label)[1],
738 #false laziness with above, to catch extraneous services. whole
739 #damn thing should be OO...
740 my $svcpart = ( $svcparts{$cust_svc->svcpart} ||= {
741 $cust_svc->part_svc->hash,
743 'count' => $cust_pkg->num_cust_svc($cust_svc->svcpart),
747 push @{$svcpart->{services}}, $svc;
751 $pkg{svcparts} = [ values %svcparts ];
753 push @packages, \%pkg;
763 my ($svcpart, $svc) = (shift,shift) or return '';
764 return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svcpart->{svc}</A>!;
770 my ($svcpart, $svc) = (shift,shift) or return '';
771 return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svc->{label}</A>!;
775 sub svc_provision_link {
776 my ($pkg, $svcpart, $conf) = @_;
777 ( my $svc_nbsp = $svcpart->{svc} ) =~ s/\s+/ /g;
778 my $num_left = $svcpart->{quantity} - $svcpart->{count};
779 my $pkgnum_svcpart = "pkgnum$pkg->{pkgnum}-svcpart$svcpart->{svcpart}";
782 if ( $svcpart->{svcdb} eq 'svc_external'
783 && $conf->exists('svc_external-skip_manual')
785 $url = "${p}edit/process/$svcpart->{svcdb}.cgi?".
786 "pkgnum=$pkg->{pkgnum}&".
787 "svcpart=$svcpart->{svcpart}";
789 $url = "${p}edit/$svcpart->{svcdb}.cgi?$pkgnum_svcpart";
792 my $link = qq!<A CLASS="provision" HREF="$url">!.
793 "Provision $svc_nbsp ($num_left)</A>";
794 if ( $conf->exists('legacy_link') ) {
796 qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
797 qq!$pkgnum_svcpart">!.
798 "Link to legacy $svc_nbsp ($num_left)</A>";
803 sub svc_unprovision_link {
804 my $svc = shift or return '';
805 qq!<A HREF="javascript:areyousure('${p}misc/unprovision.cgi?$svc->{svcnum}',!.
806 qq!'Permanently unprovision and delete this service?')">Unprovision</A>!;
809 # This should be generalized to use config options to determine order.
810 sub pkgsort_pkgnum_cancel {
811 if ($a->{cancel} and $b->{cancel}) {
812 return ($a->{pkgnum} <=> $b->{pkgnum});
813 } elsif ($a->{cancel} or $b->{cancel}) {
814 return (-1) if ($b->{cancel});
815 return (1) if ($a->{cancel});
818 return($a->{pkgnum} <=> $b->{pkgnum});
823 my($pkg, $field, $conf) = @_ or return '';
824 return ' ' unless $pkg->{$field};
825 my $format = $conf->exists('pkg_showtimes')
826 ? '<B>%D</B> <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
827 : '<B>%b %o, %Y</B>';
828 ( my $strip = time2str($format, $pkg->{$field}) ) =~ s/ (\d)/$1/g;
832 sub pkg_change_link {
833 my $pkg = shift or return '';
834 return qq!<a href="${p}misc/change_pkg.cgi?$pkg->{pkgnum}">!.
835 qq!Change package</a>!;
838 sub pkg_suspend_link {
839 my $pkg = shift or return '';
840 return qq!<a href="${p}misc/susp_pkg.cgi?$pkg->{pkgnum}">Suspend</a>!;
843 sub pkg_unsuspend_link {
844 my $pkg = shift or return '';
845 return qq!<a href="${p}misc/unsusp_pkg.cgi?$pkg->{pkgnum}">Unsuspend</a>!;
848 sub pkg_cancel_link {
849 my $pkg = shift or return '';
850 qq!<A HREF="javascript:areyousure('${p}misc/cancel_pkg.cgi?$pkg->{pkgnum}', !.
851 qq!'Permanently delete included services and cancel this package?')">!.
852 qq!Cancel now</A> | !.
853 qq!<A HREF="${p}misc/expire_pkg.cgi?$pkg->{pkgnum}">Cancel later</A>!;
857 my $pkg = shift or return '';
858 qq!<A HREF="${p}edit/REAL_cust_pkg.cgi?$pkg->{pkgnum}">Edit dates</A>!;
861 sub pkg_customize_link {
862 my $pkg = shift or return '';
864 qq!<A HREF="${p}edit/part_pkg.cgi?keywords=$custnum;clone=$pkg->{pkgpart};!.
865 qq!pkgnum=$pkg->{pkgnum}">Customize</A>!;