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>";
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_masked;
239 print 'Credit card ',
240 ( $cust_main->payby eq 'CARD' ? '(automatic)' : '(on-demand)' ),
242 '<TR><TD ALIGN="right">Card number</TD><TD BGCOLOR="#ffffff">',
243 $payinfo, '</TD></TR>',
244 '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
245 $cust_main->paydate, '</TD></TR>',
246 '<TR><TD ALIGN="right">Name on card</TD><TD BGCOLOR="#ffffff">',
247 $cust_main->payname, '</TD></TR>'
249 } elsif ( $cust_main->payby eq 'CHEK' || $cust_main->payby eq 'DCHK') {
250 my( $account, $aba ) = split('@', $cust_main->payinfo );
251 print 'Electronic check ',
252 ( $cust_main->payby eq 'CHEK' ? '(automatic)' : '(on-demand)' ),
254 '<TR><TD ALIGN="right">Account number</TD><TD BGCOLOR="#ffffff">',
255 $account, '</TD></TR>',
256 '<TR><TD ALIGN="right">ABA/Routing code</TD><TD BGCOLOR="#ffffff">',
258 '<TR><TD ALIGN="right">Bank name</TD><TD BGCOLOR="#ffffff">',
259 $cust_main->payname, '</TD></TR>'
261 } elsif ( $cust_main->payby eq 'LECB' ) {
262 $cust_main->payinfo =~ /^(\d{3})(\d{3})(\d{4})$/;
263 my $payinfo = "$1-$2-$3";
264 print 'Phone bill billing</TD></TR>',
265 '<TR><TD ALIGN="right">Phone number</TD><TD BGCOLOR="#ffffff">',
266 $payinfo, '</TD></TR>',
268 } elsif ( $cust_main->payby eq 'BILL' ) {
269 print 'Billing</TD></TR>';
270 print '<TR><TD ALIGN="right">P.O. </TD><TD BGCOLOR="#ffffff">',
271 $cust_main->payinfo, '</TD></TR>',
272 if $cust_main->payinfo;
273 print '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
274 $cust_main->paydate, '</TD></TR>',
275 '<TR><TD ALIGN="right">Attention</TD><TD BGCOLOR="#ffffff">',
276 $cust_main->payname, '</TD></TR>',
278 } elsif ( $cust_main->payby eq 'COMP' ) {
279 print 'Complimentary</TD></TR>',
280 '<TR><TD ALIGN="right">Authorized by</TD><TD BGCOLOR="#ffffff">',
281 $cust_main->payinfo, '</TD></TR>',
282 '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
283 $cust_main->paydate, '</TD></TR>',
287 print "</TABLE></TD></TR></TABLE>";
291 print '</TD></TR></TABLE>';
293 if ( defined $cust_main->dbdef_table->column('comments')
294 && $cust_main->comments =~ /[^\s\n\r]/ )
296 print "<BR>Comments". &ntable("#cccccc"). "<TR><TD>".
297 &ntable("#cccccc",2).
298 '<TR><TD BGCOLOR="#ffffff"><PRE>'.
299 encode_entities($cust_main->comments).
300 '</PRE></TD></TR></TABLE></TABLE>';
308 <SCRIPT TYPE="text/javascript">
309 function enable_order_pkg () {
310 if ( document.OrderPkgForm.pkgpart.selectedIndex > 0 ) {
311 document.OrderPkgForm.submit.disabled = false;
313 document.OrderPkgForm.submit.disabled = true;
317 <FORM NAME="OrderPkgForm" ACTION="<%= $p %>edit/process/quick-cust_pkg.cgi" METHOD="POST">
318 <INPUT TYPE="hidden" NAME="custnum" VALUE="<%= $custnum %>">
319 <SELECT NAME="pkgpart" onChange="enable_order_pkg()"><OPTION>Order additional package
322 foreach my $part_pkg (
323 qsearch( 'part_pkg', { 'disabled' => '' }, '',
324 ' AND 0 < ( SELECT COUNT(*) FROM type_pkgs '.
325 ' WHERE typenum = '. $agent->typenum.
326 ' AND type_pkgs.pkgpart = part_pkg.pkgpart )'
330 <OPTION VALUE="<%= $part_pkg->pkgpart %>"><%= $part_pkg->pkg %> - <%= $part_pkg->comment %>
333 </SELECT><INPUT NAME="submit" TYPE="submit" VALUE="Order Package" disabled></FORM><BR>
337 if ( $conf->config('payby-default') ne 'HIDE' ) {
340 qq!<FORM ACTION="${p}edit/process/quick-charge.cgi" METHOD="POST">!.
341 qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!.
342 qq!Description:<INPUT TYPE="text" NAME="pkg">!.
343 qq! Amount:<INPUT TYPE="text" NAME="amount" SIZE=6>!.
346 #false laziness w/ edit/part_pkg.cgi
347 if ( $conf->exists('enable_taxclasses') ) {
348 print '<SELECT NAME="taxclass">';
349 my $sth = dbh->prepare('SELECT DISTINCT taxclass FROM cust_main_county')
351 $sth->execute or die $sth->errstr;
352 foreach my $taxclass ( map $_->[0], @{$sth->fetchall_arrayref} ) {
353 print qq!<OPTION VALUE="$taxclass"!;
354 #print ' SELECTED' if $taxclass eq $hashref->{taxclass};
355 print qq!>$taxclass</OPTION>!;
359 print '<INPUT TYPE="hidden" NAME="taxclass" VALUE="">';
362 print qq!<INPUT TYPE="submit" VALUE="One-time charge"></FORM><BR>!;
366 print qq!<A NAME="cust_pkg">Packages</A> !,
367 qq!( <A HREF="!, popurl(2), qq!edit/cust_pkg.cgi?$custnum">Order and cancel packages</A> (preserves services) )!,
370 #begin display packages
374 my $packages = get_packages($cust_main, $conf);
378 <TABLE CLASS="package" BORDER=1 CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">
382 <TH COLSPAN=2>Services</TH>
385 foreach my $pkg (sort pkgsort_pkgnum_cancel @$packages) {
388 if ($pkg->{cancel}) {
391 foreach my $svcpart (@{$pkg->{svcparts}}) {
392 $rowspan += $svcpart->{count};
393 $rowspan++ if ($svcpart->{count} < $svcpart->{quantity});
398 <!--pkgnum: <%=$pkg->{pkgnum}%>-->
400 <TD ROWSPAN=<%=$rowspan%>>
401 <A NAME="cust_pkg<%=$pkg->{pkgnum}%>"><%=$pkg->{pkgnum}%></A>:
402 <%=$pkg->{pkg}%> - <%=$pkg->{comment}%><BR>
403 <% unless ($pkg->{cancel}) { %>
404 ( <%=pkg_change_link($pkg)%> )
405 ( <%=pkg_dates_link($pkg)%> | <%=pkg_customize_link($pkg,$custnum)%> )
409 #foreach (qw(setup last_bill next_bill susp expire cancel)) {
410 # print qq! <TD ROWSPAN=$rowspan>! . pkg_datestr($pkg,$_,$conf) . qq!</TD>\n!;
412 print "<TD ROWSPAN=$rowspan>". &itable('');
415 my $part_pkg = shift;
416 my $freq = $part_pkg->freq_pretty;
417 $freq =~ s/ / /g;
421 if ( $pkg->{cancel} ) { #status: cancelled
423 print '<TR><TD><FONT COLOR="#ff0000"><B>Cancelled </B></FONT></TD>'.
424 '<TD>'. pkg_datestr($pkg,'cancel',$conf). '</TD></TR>';
425 unless ( $pkg->{setup} ) {
426 print '<TR><TD COLSPAN=2>Never billed</TD></TR>';
428 print "<TR><TD>Setup </TD><TD>".
429 pkg_datestr($pkg, 'setup',$conf). '</TD></TR>';
430 print "<TR><TD>Last bill </TD><TD>".
431 pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>'
432 if $pkg->{'last_bill'};
433 print "<TR><TD>Suspended </TD><TD>".
434 pkg_datestr($pkg, 'susp',$conf). '</TD></TR>'
440 if ( $pkg->{susp} ) { #status: suspended
441 print '<TR><TD><FONT COLOR="#FF9900"><B>Suspended</B> </FONT></TD>'.
442 '<TD>'. pkg_datestr($pkg,'susp',$conf). '</TD></TR>';
443 unless ( $pkg->{setup} ) {
444 print '<TR><TD COLSPAN=2>Never billed</TD></TR>';
446 print "<TR><TD>Setup </TD><TD>".
447 pkg_datestr($pkg, 'setup',$conf). '</TD></TR>';
449 print "<TR><TD>Last bill </TD><TD>".
450 pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>'
451 if $pkg->{'last_bill'};
453 print "<TR><TD>Expires </TD><TD>".
454 pkg_datestr($pkg, 'expire',$conf). '</TD></TR>'
456 print '<TR><TD COLSPAN=2>( '. pkg_unsuspend_link($pkg).
457 ' | '. pkg_cancel_link($pkg). ' )</TD></TR>';
459 } else { #status: active
461 unless ( $pkg->{setup} ) { #not setup
463 print '<TR><TD COLSPAN=2>Not yet billed (';
464 unless ( $pkg->{freq} ) {
465 print 'one-time charge)</TD></TR>';
466 print '<TR><TD COLSPAN=2>( '. pkg_cancel_link($pkg).
469 print 'billed '. myfreq($pkg->{part_pkg}). ')</TD></TR>';
474 unless ( $pkg->{freq} ) {
475 print "<TR><TD COLSPAN=2>One-time charge</TD></TR>".
476 '<TR><TD>Billed </TD><TD>'.
477 pkg_datestr($pkg,'setup',$conf). '</TD></TR>';
479 print '<TR><TD COLSPAN=2><FONT COLOR="#00CC00"><B>Active</B></FONT>'.
480 ', billed '. myfreq($pkg->{part_pkg}). '</TD></TR>'.
481 '<TR><TD>Setup </TD><TD>'.
482 pkg_datestr($pkg, 'setup',$conf). '</TD></TR>';
487 print "<TR><TD>Last bill </TD><TD>".
488 pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>'
489 if $pkg->{'last_bill'};
490 print "<TR><TD>Next bill </TD><TD>".
491 pkg_datestr($pkg, 'next_bill',$conf). '</TD></TR>'
492 if $pkg->{'next_bill'};
493 print "<TR><TD>Expires </TD><TD>".
494 pkg_datestr($pkg, 'expire',$conf). '</TD></TR>'
496 if ( $pkg->{freq} ) {
497 print '<TR><TD COLSPAN=2>( '. pkg_suspend_link($pkg).
498 ' | '. pkg_cancel_link($pkg). ' )</TD></TR>';
505 print "</TABLE></TD>\n";
507 if ($rowspan == 0) { print qq!</TR>\n!; next; }
510 foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
511 foreach my $service (@{$svcpart->{services}}) {
512 print '<TR>' if ($cnt > 0);
514 <TD><%=svc_link($svcpart,$service)%></TD>
515 <TD><%=svc_label_link($svcpart,$service)%><BR>( <%=svc_unprovision_link($service)%> )</TD>
520 if ($svcpart->{count} < $svcpart->{quantity}) {
521 print qq!<TR>\n! if ($cnt > 0);
522 print qq! <TD COLSPAN=2>!.svc_provision_link($pkg, $svcpart, $conf).qq!</TD>\n</TR>\n!;
529 #end display packages
532 <% if ( $conf->config('payby-default') ne 'HIDE' ) { %>
534 <BR><BR><A NAME="history"><FONT SIZE="+2">Payment History</FONT></A><BR>
535 <A HREF="<%= $p %>edit/cust_pay.cgi?custnum=<%= $custnum %>">Post cash/check payment</A>
536 | <A HREF="<%= $p %>misc/payment.cgi?payby=CARD;custnum=<%= $custnum %>">Process credit card payment</A>
537 | <A HREF="<%= $p %>misc/payment.cgi?payby=CHEK;custnum=<%= $custnum %>">Process electronic check (ACH) payment</A>
538 <BR><A HREF="<%= $p %>edit/cust_credit.cgi?<%= $custnum %>">Post credit</A>
546 foreach my $cust_bill ($cust_main->cust_bill) {
547 my $pre = ( $cust_bill->owed > 0 )
548 ? '<B><FONT SIZE="+1" COLOR="#FF0000">Open '
550 my $post = ( $cust_bill->owed > 0 ) ? '</FONT></B>' : '';
551 my $invnum = $cust_bill->invnum;
553 'date' => $cust_bill->_date,
554 'desc' => qq!<A HREF="${p}view/cust_bill.cgi?$invnum">!. $pre.
555 "Invoice #$invnum (Balance \$". $cust_bill->owed. ')'.
557 'charge' => $cust_bill->charged,
561 #payments (some false laziness w/credits)
562 foreach my $cust_pay ($cust_main->cust_pay) {
564 my $payby = $cust_pay->payby;
565 my $payinfo = $payby eq 'CARD'
566 ? $cust_pay->payinfo_masked
567 : $cust_pay->payinfo;
568 my @cust_bill_pay = $cust_pay->cust_bill_pay;
569 my @cust_pay_refund = $cust_pay->cust_pay_refund;
571 my $target = "$payby$payinfo";
572 $payby =~ s/^BILL$/Check #/ if $payinfo;
573 $payby =~ s/^CHEK$/Electronic check /;
574 $payby =~ s/^BILL$//;
575 $payby =~ s/^(CARD|COMP)$/$1 /;
576 my $info = $payby ? " ($payby$payinfo)" : '';
578 my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
579 if ( scalar(@cust_bill_pay) == 0
580 && scalar(@cust_pay_refund) == 0 ) {
581 #completely unapplied
582 $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
583 $post = '</FONT></B>';
584 $apply = qq! (<A HREF="${p}edit/cust_bill_pay.cgi?!.
585 $cust_pay->paynum. '">apply</A>)';
586 } elsif ( scalar(@cust_bill_pay) == 1
587 && scalar(@cust_pay_refund) == 0
588 && $cust_pay->unapplied == 0 ) {
589 #applied to one invoice, the usual situation
590 $desc = ' applied to Invoice #'. $cust_bill_pay[0]->invnum;
591 } elsif ( scalar(@cust_bill_pay) == 0
592 && scalar(@cust_pay_refund) == 1
593 && $cust_pay->unapplied == 0 ) {
594 #applied to one refund
595 $desc = ' refunded on '. time2str("%D", $cust_pay_refund[0]->_date);
599 foreach my $app ( sort { $a->_date <=> $b->_date }
600 ( @cust_bill_pay, @cust_pay_refund ) ) {
601 if ( $app->isa('FS::cust_bill_pay') ) {
602 $desc .= ' '.
604 ' applied to Invoice #'. $app->invnum.
606 #' on '. time2str("%D", $cust_bill_pay->_date).
607 } elsif ( $app->isa('FS::cust_pay_refund') ) {
608 $desc .= ' '.
610 ' refunded on'. time2str("%D", $app->_date).
613 die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
616 if ( $cust_pay->unapplied > 0 ) {
617 $desc .= ' '.
618 '<B><FONT COLOR="#FF0000">$'.
619 $cust_pay->unapplied. ' unapplied</FONT></B>'.
620 qq! (<A HREF="${p}edit/cust_bill_pay.cgi?!.
621 $cust_pay->paynum. '">apply</A>)'.
627 my $refund_days = $conf->config('card_refund-days') || 120;
628 if ( $cust_pay->closed !~ /^Y/i
629 && $cust_pay->payby =~ /^(CARD|CHEK)$/
630 && time-$cust_pay->_date < $refund_days*86400
631 && $cust_pay->unrefunded > 0
633 $refund = qq! (<A HREF="!. qq!${p}edit/cust_refund.cgi?payby=$1;!.
634 qq!paynum=!. $cust_pay->paynum. qq!">refund</A>)!;
638 if ( $cust_pay->closed !~ /^Y/i
639 && $cust_pay->payby !~ /^(CARD|CHEK)$/
641 $void = qq! (<A HREF="javascript:areyousure('!.
642 qq!${p}misc/void-cust_pay.cgi?!. $cust_pay->paynum.
643 qq!', 'Are you sure you want to void this payment?')">!.
648 if ( $cust_pay->closed !~ /^Y/i && $conf->exists('deletepayments') ) {
649 $delete = qq! (<A HREF="javascript:areyousure('!.
650 qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
651 qq!', 'Are you sure you want to delete this payment?')">!.
656 if ( $cust_pay->closed !~ /^Y/i
657 && $conf->exists('unapplypayments')
658 && scalar(@cust_bill_pay) ) {
659 $unapply = qq! (<A HREF="javascript:areyousure('!.
660 qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
661 qq!', 'Are you sure you want to unapply this payment?')">!.
666 'date' => $cust_pay->_date,
667 'desc' => $pre. "Payment$post$info$desc".
668 "$apply$refund$void$delete$unapply",
669 'payment' => $cust_pay->paid,
675 foreach my $cust_pay_void ($cust_main->cust_pay_void) {
677 my $payby = $cust_pay_void->payby;
678 my $payinfo = $payby eq 'CARD'
679 ? $cust_pay_void->payinfo_masked
680 : $cust_pay_void->payinfo;
682 $payby =~ s/^BILL$/Check #/ if $payinfo;
683 $payby =~ s/^CHEK$/Electronic check /;
684 $payby =~ s/^BILL$//;
685 $payby =~ s/^(CARD|COMP)$/$1 /;
686 my $info = $payby ? " ($payby$payinfo)" : '';
689 'date' => $cust_pay_void->_date,
690 'desc' => "<DEL>Payment $info</DEL> <I>voided ".
691 time2str("%D", $cust_pay_void->void_date).
692 " by ". $cust_pay_void->otaker. '</i>',
693 'void_payment' => $cust_pay_void->paid,
698 #credits (some false laziness w/payments)
699 foreach my $cust_credit ($cust_main->cust_credit) {
701 my @cust_credit_bill = $cust_credit->cust_credit_bill;
702 my @cust_credit_refund = $cust_credit->cust_credit_refund;
704 my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
705 if ( scalar(@cust_credit_bill) == 0
706 && scalar(@cust_credit_refund) == 0 ) {
707 #completely unapplied
708 $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
709 $post = '</FONT></B>';
710 $apply = qq! (<A HREF="${p}edit/cust_credit_bill.cgi?!.
711 $cust_credit->crednum. '">apply</A>)';
712 } elsif ( scalar(@cust_credit_bill) == 1
713 && scalar(@cust_credit_refund) == 0
714 && $cust_credit->credited == 0 ) {
715 #applied to one invoice, the usual situation
716 $desc = ' applied to Invoice #'. $cust_credit_bill[0]->invnum;
717 } elsif ( scalar(@cust_credit_bill) == 0
718 && scalar(@cust_credit_refund) == 1
719 && $cust_credit->credited == 0 ) {
720 #applied to one refund
721 $desc = ' refunded on '. time2str("%D", $cust_credit_refund[0]->_date);
725 foreach my $app ( sort { $a->_date <=> $b->_date }
726 ( @cust_credit_bill, @cust_credit_refund ) ) {
727 if ( $app->isa('FS::cust_credit_bill') ) {
728 $desc .= ' '.
730 ' applied to Invoice #'. $app->invnum.
732 #' on '. time2str("%D", $app->_date).
733 } elsif ( $app->isa('FS::cust_credit_refund') ) {
734 $desc .= ' '.
736 ' refunded on'. time2str("%D", $app->_date).
739 die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
742 if ( $cust_credit->credited > 0 ) {
743 $desc .= ' <B><FONT COLOR="#FF0000">$'.
744 $cust_credit->credited. ' unapplied</FONT></B>'.
745 qq! (<A HREF="${p}edit/cust_credit_bill.cgi?!.
746 $cust_credit->crednum. '">apply</A>)'.
752 if ( $cust_credit->closed !~ /^Y/i && $conf->exists('deletecredits') ) {
753 $delete = qq! (<A HREF="javascript:areyousure('!.
754 qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
755 qq!', 'Are you sure you want to delete this credit?')">!.
760 if ( $cust_credit->closed !~ /^Y/i
761 && $conf->exists('unapplycredits')
762 && scalar(@cust_credit_bill) ) {
763 $unapply = qq! (<A HREF="javascript:areyousure('!.
764 qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
765 qq!', 'Are you sure you want to unapply this credit?')">!.
770 'date' => $cust_credit->_date,
771 'desc' => $pre. "Credit$post by ". $cust_credit->otaker.
772 ' ('. $cust_credit->reason. ')'.
773 "$desc$apply$delete$unapply",
774 'credit' => $cust_credit->amount,
780 foreach my $cust_refund ($cust_main->cust_refund) {
782 my $payby = $cust_refund->payby;
783 my $payinfo = $payby eq 'CARD'
784 ? $cust_refund->payinfo_masked
785 : $cust_refund->payinfo;
787 $payby =~ s/^BILL$/Check #/ if $payinfo;
788 $payby =~ s/^CHEK$/Electronic check /;
789 $payby =~ s/^(CARD|COMP)$/$1 /;
792 'date' => $cust_refund->_date,
793 'desc' => "Refund ($payby$payinfo) by ". $cust_refund->otaker,
794 'refund' => $cust_refund->refund,
805 <TH><FONT SIZE=-1>Charge</FONT></TH>
806 <TH><FONT SIZE=-1>Payment</FONT></TH>
807 <TH><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
808 <TH><FONT SIZE=-1>Refund</FONT></TH>
809 <TH><FONT SIZE=-1>Balance</FONT></TH>
813 #display payment history
817 foreach my $item ( sort { $a->{'date'} <=> $b->{'date'} } @history ) {
819 my $charge = exists($item->{'charge'})
820 ? sprintf('$%.2f', $item->{'charge'})
822 my $payment = exists($item->{'payment'})
823 ? sprintf('- $%.2f', $item->{'payment'})
825 $payment ||= sprintf('<DEL>- $%.2f</DEL>', $item->{'void_payment'})
826 if exists($item->{'void_payment'});
827 my $credit = exists($item->{'credit'})
828 ? sprintf('- $%.2f', $item->{'credit'})
830 my $refund = exists($item->{'refund'})
831 ? sprintf('$%.2f', $item->{'refund'})
834 my $target = exists($item->{'target'}) ? $item->{'target'} : '';
836 $balance += $item->{'charge'} if exists $item->{'charge'};
837 $balance -= $item->{'payment'} if exists $item->{'payment'};
838 $balance -= $item->{'credit'} if exists $item->{'credit'};
839 $balance += $item->{'refund'} if exists $item->{'refund'};
840 $balance = sprintf("%.2f", $balance);
841 $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
842 ( my $showbalance = '$'. $balance ) =~ s/^\$\-/- \$/;
848 <% unless ( !$target || $target{$target}++ ) { %>
849 <A NAME="<%= $target %>">
851 <%= time2str("%D",$item->{'date'}) %>
852 <% if ( $target && $target{$target} == 1 ) { %>
857 <TD><%= $item->{'desc'} %></TD>
858 <TD ALIGN="right"><%= $charge %></TD>
859 <TD ALIGN="right"><%= $payment %></TD>
860 <TD ALIGN="right"><%= $credit %></TD>
861 <TD ALIGN="right"><%= $refund %></TD>
862 <TD ALIGN="right"><%= $showbalance %></TD>
877 my $cust_main = shift or return undef;
882 foreach my $cust_pkg (
883 $conf->exists('hidecancelledpackages')
884 ? $cust_main->ncancelled_pkgs
885 : $cust_main->all_pkgs
888 my $part_pkg = $cust_pkg->part_pkg;
892 #to get back to the original object... should use it in the first place!!
893 $pkg{cust_pkg} = $cust_pkg;
894 $pkg{part_pkg} = $part_pkg;
896 $pkg{pkgnum} = $cust_pkg->pkgnum;
897 $pkg{pkg} = $part_pkg->pkg;
898 $pkg{pkgpart} = $part_pkg->pkgpart;
899 $pkg{comment} = $part_pkg->getfield('comment');
900 $pkg{freq} = $part_pkg->freq;
901 $pkg{setup} = $cust_pkg->getfield('setup');
902 $pkg{last_bill} = $cust_pkg->getfield('last_bill');
903 $pkg{next_bill} = $cust_pkg->getfield('bill');
904 $pkg{susp} = $cust_pkg->getfield('susp');
905 $pkg{expire} = $cust_pkg->getfield('expire');
906 $pkg{cancel} = $cust_pkg->getfield('cancel');
912 'quantity' => $_->quantity,
913 'count' => $cust_pkg->num_cust_svc($_->svcpart),
916 } $part_pkg->pkg_svc;
918 foreach my $cust_svc ( $cust_pkg->cust_svc ) {
919 #warn "svcnum ". $cust_svc->svcnum. " / svcpart ". $cust_svc->svcpart. "\n";
921 'svcnum' => $cust_svc->svcnum,
922 'label' => ($cust_svc->label)[1],
925 #false laziness with above, to catch extraneous services. whole
926 #damn thing should be OO...
927 my $svcpart = ( $svcparts{$cust_svc->svcpart} ||= {
928 $cust_svc->part_svc->hash,
930 'count' => $cust_pkg->num_cust_svc($cust_svc->svcpart),
934 push @{$svcpart->{services}}, $svc;
938 $pkg{svcparts} = [ values %svcparts ];
940 push @packages, \%pkg;
950 my ($svcpart, $svc) = (shift,shift) or return '';
951 return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svcpart->{svc}</A>!;
957 my ($svcpart, $svc) = (shift,shift) or return '';
958 return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svc->{label}</A>!;
962 sub svc_provision_link {
963 my ($pkg, $svcpart, $conf) = @_;
964 ( my $svc_nbsp = $svcpart->{svc} ) =~ s/\s+/ /g;
965 my $num_left = $svcpart->{quantity} - $svcpart->{count};
966 my $pkgnum_svcpart = "pkgnum$pkg->{pkgnum}-svcpart$svcpart->{svcpart}";
969 if ( $svcpart->{svcdb} eq 'svc_external'
970 && $conf->exists('svc_external-skip_manual')
972 $url = "${p}edit/process/$svcpart->{svcdb}.cgi?".
973 "pkgnum=$pkg->{pkgnum}&".
974 "svcpart=$svcpart->{svcpart}";
976 $url = "${p}edit/$svcpart->{svcdb}.cgi?$pkgnum_svcpart";
979 my $link = qq!<A CLASS="provision" HREF="$url">!.
980 "Provision $svc_nbsp ($num_left)</A>";
981 if ( $conf->exists('legacy_link') ) {
983 qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
984 qq!$pkgnum_svcpart">!.
985 "Link to legacy $svc_nbsp ($num_left)</A>";
990 sub svc_unprovision_link {
991 my $svc = shift or return '';
992 qq!<A HREF="javascript:areyousure('${p}misc/unprovision.cgi?$svc->{svcnum}',!.
993 qq!'Permanently unprovision and delete this service?')">Unprovision</A>!;
996 # This should be generalized to use config options to determine order.
997 sub pkgsort_pkgnum_cancel {
998 if ($a->{cancel} and $b->{cancel}) {
999 return ($a->{pkgnum} <=> $b->{pkgnum});
1000 } elsif ($a->{cancel} or $b->{cancel}) {
1001 return (-1) if ($b->{cancel});
1002 return (1) if ($a->{cancel});
1005 return($a->{pkgnum} <=> $b->{pkgnum});
1010 my($pkg, $field, $conf) = @_ or return '';
1011 return ' ' unless $pkg->{$field};
1012 my $format = $conf->exists('pkg_showtimes')
1013 ? '<B>%D</B> <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
1014 : '<B>%b %o, %Y</B>';
1015 ( my $strip = time2str($format, $pkg->{$field}) ) =~ s/ (\d)/$1/g;
1019 sub pkg_change_link {
1020 my $pkg = shift or return '';
1021 return qq!<a href="${p}misc/change_pkg.cgi?$pkg->{pkgnum}">!.
1022 qq!Change package</a>!;
1025 sub pkg_suspend_link {
1026 my $pkg = shift or return '';
1027 return qq!<a href="${p}misc/susp_pkg.cgi?$pkg->{pkgnum}">Suspend</a>!;
1030 sub pkg_unsuspend_link {
1031 my $pkg = shift or return '';
1032 return qq!<a href="${p}misc/unsusp_pkg.cgi?$pkg->{pkgnum}">Unsuspend</a>!;
1035 sub pkg_cancel_link {
1036 my $pkg = shift or return '';
1037 qq!<A HREF="javascript:areyousure('${p}misc/cancel_pkg.cgi?$pkg->{pkgnum}', !.
1038 qq!'Permanently delete included services and cancel this package?')">!.
1039 qq!Cancel now</A> | !.
1040 qq!<A HREF="${p}misc/expire_pkg.cgi?$pkg->{pkgnum}">Cancel later</A>!;
1043 sub pkg_dates_link {
1044 my $pkg = shift or return '';
1045 qq!<A HREF="${p}edit/REAL_cust_pkg.cgi?$pkg->{pkgnum}">Edit dates</A>!;
1048 sub pkg_customize_link {
1049 my $pkg = shift or return '';
1050 my $custnum = shift;
1051 qq!<A HREF="${p}edit/part_pkg.cgi?keywords=$custnum;clone=$pkg->{pkgpart};!.
1052 qq!pkgnum=$pkg->{pkgnum}">Customize</A>!;