-<!-- mason kludge -->
-<%
+<% include("/elements/header.html","Customer View: ". $cust_main->name ) %>
-my $conf = new FS::Conf;
+% if ( $curuser->access_right('Edit customer') ) {
+ <A HREF="<% $p %>edit/cust_main.cgi?<% $custnum %>">Edit this customer</A> |
+% }
+
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws.js"></SCRIPT>
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws_iframe.js"></SCRIPT>
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws_draggable.js"></SCRIPT>
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/iframecontentmws.js"></SCRIPT>
-#false laziness with view/cust_pkg.cgi, but i'm trying to make that go away so
-my %uiview = ();
-my %uiadd = ();
-foreach my $part_svc ( qsearch('part_svc',{}) ) {
- $uiview{$part_svc->svcpart} = popurl(2). "view/". $part_svc->svcdb . ".cgi";
- $uiadd{$part_svc->svcpart}= popurl(2). "edit/". $part_svc->svcdb . ".cgi";
+<SCRIPT TYPE="text/javascript">
+function areyousure(href, message) {
+ if (confirm(message) == true)
+ window.location.href = href;
}
+</SCRIPT>
-print header("Customer View", menubar(
- 'Main Menu' => popurl(2)
-));
+<SCRIPT TYPE="text/javascript">
+%
+%my $ban = '';
+%if ( $cust_main->payby =~ /^(CARD|DCRD|CHEK|DCHK)$/ ) {
+% $ban = '<BR><P ALIGN="center">'.
+% '<INPUT TYPE="checkbox" NAME="ban" VALUE="1"> Ban this customer\\\'s ';
+% if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) {
+% $ban .= 'credit card';
+% } elsif ( $cust_main->payby =~ /^(CHEK|DCHK)$/ ) {
+% $ban .= 'ACH account';
+% }
+%}
+%
-die "No customer specified (bad URL)!" unless $cgi->keywords;
-my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
-$query =~ /^(\d+)$/;
-my $custnum = $1;
-my $cust_main = qsearchs('cust_main',{'custnum'=>$custnum});
-die "Customer not found!" unless $cust_main;
-print qq!<A HREF="!, popurl(2),
- qq!edit/cust_main.cgi?$custnum">Edit this customer</A>!;
-print qq! | <A HREF="!, popurl(2),
- qq!misc/delete-customer.cgi?$custnum"> Delete this customer</A>!
- if $conf->exists('deletecustomers');
+var confirm_cancel = '<FORM METHOD="POST" ACTION="<% $p %>misc/cust_main-cancel.cgi"> <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>"> <BR><P ALIGN="center"><B>Permanently delete all services and cancel this customer?</B> <% $ban%><BR><P ALIGN="CENTER"> <INPUT TYPE="submit" VALUE="Cancel customer"> <INPUT TYPE="BUTTON" VALUE="Don\'t cancel" onClick="cClick()"> </FORM> ';
-unless ( $conf->exists('disable_customer_referrals') ) {
- print qq! | <A HREF="!, popurl(2),
- qq!edit/cust_main.cgi?referral_custnum=$custnum">!,
- qq!Refer a new customer</A>!;
+</SCRIPT>
+% if ( $curuser->access_right('Cancel customer')
+% && $cust_main->ncancelled_pkgs
+% ) {
+%
- print qq! | <A HREF="!, popurl(2),
- qq!search/cust_main.cgi?referral_custnum=$custnum">!,
- qq!View this customer's referrals</A>!;
-}
+ <A HREF="javascript:void(0);" onClick="overlib(confirm_cancel, CAPTION, 'Confirm cancellation', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, 128, TEXTSIZE, 3, BGCOLOR, '#ff0000', CGCOLOR, '#ff0000' ); return false; ">Cancel this customer</A> |
+% }
+% if ( $conf->exists('deletecustomers')
+% && $curuser->access_right('Delete customer')
+% ) {
+%
-print '<BR><BR>';
+ <A HREF="<% $p %>misc/delete-customer.cgi?<% $custnum%>">Delete this customer</A> |
+% }
+% unless ( $conf->exists('disable_customer_referrals') ) {
-my $signupurl = $conf->config('signupurl');
-if ( $signupurl ) {
-print "This customer's signup URL: ".
- "<a href=\"$signupurl?ref=$custnum\">$signupurl?ref=$custnum</a><BR><BR>";
-}
+ <A HREF="<% popurl(2) %>edit/cust_main.cgi?referral_custnum=<% $custnum %>">Refer a new customer</A> |
+ <A HREF="<% popurl(2) %>search/cust_main.cgi?referral_custnum=<% $custnum %>">View this customer's referrals</A>
+% }
-print '<A NAME="cust_main"></A>';
-
-print &itable(), '<TR>';
-
-print '<TD VALIGN="top">';
-
- print "Billing address", &ntable("#cccccc"), "<TR><TD>",
- &ntable("#cccccc",2),
- '<TR><TD ALIGN="right">Contact name</TD>',
- '<TD COLSPAN=3 BGCOLOR="#ffffff">',
- $cust_main->last, ', ', $cust_main->first,
- '</TD>';
-print '<TD ALIGN="right">SS#</TD><TD BGCOLOR="#ffffff">',
- $cust_main->ss || ' ', '</TD>'
- if $conf->exists('show_ss');
-
-print '</TR>',
- '<TR><TD ALIGN="right">Company</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
- $cust_main->company,
- '</TD></TR>',
- '<TR><TD ALIGN="right">Address</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
- $cust_main->address1,
- '</TD></TR>',
- ;
- print '<TR><TD ALIGN="right"> </TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
- $cust_main->address2, '</TD></TR>'
- if $cust_main->address2;
- print '<TR><TD ALIGN="right">City</TD><TD BGCOLOR="#ffffff">',
- $cust_main->city,
- '</TD><TD ALIGN="right">State</TD><TD BGCOLOR="#ffffff">',
- $cust_main->state,
- '</TD><TD ALIGN="right">Zip</TD><TD BGCOLOR="#ffffff">',
- $cust_main->zip, '</TD></TR>',
- '<TR><TD ALIGN="right">Country</TD><TD BGCOLOR="#ffffff">',
- $cust_main->country,
- '</TD></TR>',
- ;
- print '<TR><TD ALIGN="right">Day Phone</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
- $cust_main->daytime || ' ', '</TD></TR>',
- '<TR><TD ALIGN="right">Night Phone</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
- $cust_main->night || ' ', '</TD></TR>',
- '<TR><TD ALIGN="right">Fax</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
- $cust_main->fax || ' ', '</TD></TR>',
- '</TABLE>', "</TD></TR></TABLE>"
- ;
-
- if ( defined $cust_main->dbdef_table->column('ship_last') ) {
-
- my $pre = $cust_main->ship_last ? 'ship_' : '';
-
- print "<BR>Service address", &ntable("#cccccc"), "<TR><TD>",
- &ntable("#cccccc",2),
- '<TR><TD ALIGN="right">Contact name</TD>',
- '<TD COLSPAN=5 BGCOLOR="#ffffff">',
- $cust_main->get("${pre}last"), ', ', $cust_main->get("${pre}first"),
- '</TD></TR>',
- '<TR><TD ALIGN="right">Company</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
- $cust_main->get("${pre}company"),
- '</TD></TR>',
- '<TR><TD ALIGN="right">Address</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
- $cust_main->get("${pre}address1"),
- '</TD></TR>',
- ;
- print '<TR><TD ALIGN="right"> </TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
- $cust_main->get("${pre}address2"), '</TD></TR>'
- if $cust_main->get("${pre}address2");
- print '<TR><TD ALIGN="right">City</TD><TD BGCOLOR="#ffffff">',
- $cust_main->get("${pre}city"),
- '</TD><TD ALIGN="right">State</TD><TD BGCOLOR="#ffffff">',
- $cust_main->get("${pre}state"),
- '</TD><TD ALIGN="right">Zip</TD><TD BGCOLOR="#ffffff">',
- $cust_main->get("${pre}zip"), '</TD></TR>',
- '<TR><TD ALIGN="right">Country</TD><TD BGCOLOR="#ffffff">',
- $cust_main->get("${pre}country"),
- '</TD></TR>',
- ;
- print '<TR><TD ALIGN="right">Day Phone</TD>',
- '<TD COLSPAN=5 BGCOLOR="#ffffff">',
- $cust_main->get("${pre}daytime") || ' ', '</TD></TR>',
- '<TR><TD ALIGN="right">Night Phone</TD>'.
- '<TD COLSPAN=5 BGCOLOR="#ffffff">',
- $cust_main->get("${pre}night") || ' ', '</TD></TR>',
- '<TR><TD ALIGN="right">Fax</TD><TD COLSPAN=5 BGCOLOR="#ffffff">',
- $cust_main->get("${pre}fax") || ' ', '</TD></TR>',
- '</TABLE>', "</TD></TR></TABLE>"
- ;
-
- }
-
-print '</TD>';
-
-print '<TD VALIGN="top">';
-
- print &ntable("#cccccc"), "<TR><TD>", &ntable("#cccccc",2),
- '<TR><TD ALIGN="right">Customer number</TD><TD BGCOLOR="#ffffff">',
- $custnum, '</TD></TR>',
- ;
-
- my @agents = qsearch( 'agent', {} );
- my $agent;
- unless ( scalar(@agents) == 1 ) {
- $agent = qsearchs('agent',{ 'agentnum' => $cust_main->agentnum } );
- print '<TR><TD ALIGN="right">Agent</TD><TD BGCOLOR="#ffffff">',
- $agent->agentnum, ": ", $agent->agent, '</TD></TR>';
- } else {
- $agent = $agents[0];
- }
- my @referrals = qsearch( 'part_referral', {} );
- unless ( scalar(@referrals) == 1 ) {
- my $referral = qsearchs('part_referral', {
- 'refnum' => $cust_main->refnum
- } );
- print '<TR><TD ALIGN="right">Advertising source</TD><TD BGCOLOR="#ffffff">',
- $referral->refnum, ": ", $referral->referral, '</TD></TR>';
- }
- print '<TR><TD ALIGN="right">Order taker</TD><TD BGCOLOR="#ffffff">',
- $cust_main->otaker, '</TD></TR>';
-
- print '<TR><TD ALIGN="right">Referring Customer</TD><TD BGCOLOR="#ffffff">';
- my $referring_cust_main = '';
- if ( $cust_main->referral_custnum
- && ( $referring_cust_main =
- qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
- )
- ) {
- print '<A HREF="'. popurl(1). 'cust_main.cgi?'.
- $cust_main->referral_custnum. '">'.
- $cust_main->referral_custnum. ': '.
- ( $referring_cust_main->company
- ? $referring_cust_main->company. ' ('.
- $referring_cust_main->last. ', '. $referring_cust_main->first.
- ')'
- : $referring_cust_main->last. ', '. $referring_cust_main->first
- ).
- '</A>';
- }
- print '</TD></TR>';
-
- print '</TABLE></TD></TR></TABLE>';
-
-print '<BR>';
-
- my @invoicing_list = $cust_main->invoicing_list;
- print "Billing information (",
- qq!<A HREF="!, popurl(2), qq!misc/bill.cgi?$custnum">!, "Bill now</A>)",
- &ntable("#cccccc"), "<TR><TD>", &ntable("#cccccc",2),
- '<TR><TD ALIGN="right">Tax exempt</TD><TD BGCOLOR="#ffffff">',
- $cust_main->tax ? 'yes' : 'no',
- '</TD></TR>',
- '<TR><TD ALIGN="right">Postal invoices</TD><TD BGCOLOR="#ffffff">',
- ( grep { $_ eq 'POST' } @invoicing_list ) ? 'yes' : 'no',
- '</TD></TR>',
- '<TR><TD ALIGN="right">Email invoices</TD><TD BGCOLOR="#ffffff">',
- join(', ', grep { $_ ne 'POST' } @invoicing_list ) || 'no',
- '</TD></TR>',
- '<TR><TD ALIGN="right">Billing type</TD><TD BGCOLOR="#ffffff">',
- ;
-
- if ( $cust_main->payby eq 'CARD' ) {
- my $payinfo = $cust_main->payinfo;
- $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4));
- print 'Credit card</TD></TR>',
- '<TR><TD ALIGN="right">Card number</TD><TD BGCOLOR="#ffffff">',
- $payinfo, '</TD></TR>',
- '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
- $cust_main->paydate, '</TD></TR>',
- '<TR><TD ALIGN="right">Name on card</TD><TD BGCOLOR="#ffffff">',
- $cust_main->payname, '</TD></TR>'
- ;
- } elsif ( $cust_main->payby eq 'BILL' ) {
- print 'Billing</TD></TR>';
- print '<TR><TD ALIGN="right">P.O. </TD><TD BGCOLOR="#ffffff">',
- $cust_main->payinfo, '</TD></TR>',
- if $cust_main->payinfo;
- print '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
- $cust_main->paydate, '</TD></TR>',
- '<TR><TD ALIGN="right">Attention</TD><TD BGCOLOR="#ffffff">',
- $cust_main->payname, '</TD></TR>',
- ;
- } elsif ( $cust_main->payby eq 'COMP' ) {
- print 'Complimentary</TD></TR>',
- '<TR><TD ALIGN="right">Authorized by</TD><TD BGCOLOR="#ffffff">',
- $cust_main->payinfo, '</TD></TR>',
- '<TR><TD ALIGN="right">Expiration</TD><TD BGCOLOR="#ffffff">',
- $cust_main->paydate, '</TD></TR>',
- ;
- }
-
- print "</TABLE></TD></TR></TABLE>";
-
-print '</TD></TR></TABLE>';
-
-if ( defined $cust_main->dbdef_table->column('comments')
- && $cust_main->comments )
-{
- print "<BR>Comments". &ntable("#cccccc"). "<TR><TD>".
- &ntable("#cccccc",2).
- '<TR><TD BGCOLOR="#ffffff"><PRE>'.
- encode_entities($cust_main->comments).
- '</PRE></TD></TR></TABLE></TABLE>';
-}
-print '</TD></TR></TABLE>';
-
-print '<BR>'.
- '<FORM ACTION="'.popurl(2).'edit/process/quick-cust_pkg.cgi" METHOD="POST">'.
- qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!.
- '<SELECT NAME="pkgpart"><OPTION> ';
-
-foreach my $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) {
- my $pkgpart = $type_pkgs->pkgpart;
-# my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
-# or do { warn "unknown type_pkgs.pkgpart $pkgpart"; next; };
- my $part_pkg =
- qsearchs('part_pkg', { 'pkgpart' => $pkgpart, 'disabled' => '' } )
- or next;
- print qq!<OPTION VALUE="$pkgpart">!. $part_pkg->pkg. ' - '.
- $part_pkg->comment;
-}
-print '</SELECT><INPUT TYPE="submit" VALUE="Order Package"></FORM><BR>';
-
-print '<BR>'.
- qq!<FORM ACTION="${p}edit/process/quick-charge.cgi" METHOD="POST">!.
- qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!.
- qq!Description:<INPUT TYPE="text" NAME="pkg">!.
- qq! Amount:<INPUT TYPE="text" NAME="amount" SIZE=6>!.
- qq! !;
-
-#false laziness w/ edit/part_pkg.cgi
-if ( $conf->exists('enable_taxclasses') ) {
- print '<SELECT NAME="taxclass">';
- my $sth = dbh->prepare('SELECT DISTINCT taxclass FROM cust_main_county')
- or die dbh->errstr;
- $sth->execute or die $sth->errstr;
- foreach my $taxclass ( map $_->[0], @{$sth->fetchall_arrayref} ) {
- print qq!<OPTION VALUE="$taxclass"!;
- #print ' SELECTED' if $taxclass eq $hashref->{taxclass};
- print qq!>$taxclass</OPTION>!;
- }
- print '</SELECT>';
-} else {
- print '<INPUT TYPE="hidden" NAME="taxclass" VALUE="">';
-}
+<BR><BR>
+%
+%my $signupurl = $conf->config('signupurl');
+%if ( $signupurl ) {
+%
-print qq!<INPUT TYPE="submit" VALUE="One-time charge"></FORM><BR>!;
+ This customer's signup URL: <A HREF="<% $signupurl %>?ref=<% $custnum %>"><% $signupurl %>?ref=<% $custnum %></A><BR><BR>
+% }
-print <<END;
-<SCRIPT>
-function cust_pkg_areyousure(href) {
- if (confirm("Permanently delete included services and cancel this package?") == true)
- window.location.href = href;
-}
-</SCRIPT>
-END
-
-print qq!<BR><A NAME="cust_pkg">Packages</A> !,
-# qq!<BR>Click on package number to view/edit package.!,
- qq!( <A HREF="!, popurl(2), qq!edit/cust_pkg.cgi?$custnum">Order and cancel packages</A> (preserves services) )!,
-;
-
-#display packages
-
-#formatting
-print qq!!, &table(), "\n",
- qq!<TR><TH COLSPAN=2 ROWSPAN=2>Package</TH><TH COLSPAN=5>!,
- qq!Dates</TH><TH COLSPAN=2 ROWSPAN=2>Services</TH></TR>\n!,
- qq!<TR><TH><FONT SIZE=-1>Setup</FONT></TH><TH>!,
- qq!<FONT SIZE=-1>Next bill</FONT>!,
- qq!</TH><TH><FONT SIZE=-1>Susp.</FONT></TH><TH><FONT SIZE=-1>Expire!,
- qq!</FONT></TH>!,
- qq!<TH><FONT SIZE=-1>Cancel</FONT></TH>!,
- qq!</TR>\n!;
-
-#get package info
-my @packages;
-if ( $conf->exists('hidecancelledpackages') ) {
- @packages = sort { $a->pkgnum <=> $b->pkgnum } ($cust_main->ncancelled_pkgs);
-} else {
- @packages = sort { $a->pkgnum <=> $b->pkgnum } ($cust_main->all_pkgs);
-}
-my $n1 = '<TR>';
-foreach my $package (@packages) {
- my $pkgnum = $package->pkgnum;
- my $pkg = $package->part_pkg->pkg;
- my $comment = $package->part_pkg->comment;
- my $pkgview = popurl(2). "view/cust_pkg.cgi?$pkgnum";
-
- #my @cust_svc = qsearch( 'cust_svc', { 'pkgnum' => $pkgnum } );
- #my $rowspan = scalar(@cust_svc) || 1;
- my @cust_svc = ();
- my $rowspan = 0;
- my %pkg_svc = ();
- unless ( $package->getfield('cancel') ) {
- foreach my $pkg_svc (
- grep { $_->quantity }
- qsearch('pkg_svc',{'pkgpart'=> $package->pkgpart })
- ) {
- $rowspan += ( $pkg_svc{$pkg_svc->svcpart} = $pkg_svc->quantity );
- }
- } else {
- #@cust_svc = qsearch( 'cust_svc', { 'pkgnum' => $pkgnum } );
- @cust_svc = ();
- $rowspan = scalar(@cust_svc) || 1;
- }
- $rowspan ||= 1;
-
- my $button_cgi = new CGI;
- $button_cgi->param('clone', $package->part_pkg->pkgpart);
- $button_cgi->param('pkgnum', $package->pkgnum);
- my $button_url = popurl(2). "edit/part_pkg.cgi?". $button_cgi->query_string;
-
- #print $n1, qq!<TD ROWSPAN=$rowspan><A HREF="$pkgview">$pkgnum</A></TD>!,
- print $n1, qq!<TD ROWSPAN=$rowspan>$pkgnum</TD>!,
- qq!<TD ROWSPAN=$rowspan><FONT SIZE=-1>!,
- #qq!<A HREF="$pkgview">$pkg - $comment</A>!,
- qq!$pkg - $comment ( <a href="$pkgview">Details</a> )!;
- # | !;
-
- #false laziness with view/cust_pkg.cgi, but i'm trying to make that go away so
- unless ( $package->getfield('cancel') ) {
- print ' ( ';
- if ( $package->getfield('susp') ) {
- print qq!<A HREF="${p}misc/unsusp_pkg.cgi?$pkgnum">Unsuspend</A>!;
- } else {
- print qq!<A HREF="${p}misc/susp_pkg.cgi?$pkgnum">Suspend</A>!;
- }
- print ' | <A HREF="javascript:cust_pkg_areyousure(\''. popurl(2).
- 'misc/cancel_pkg.cgi?'. $pkgnum. '\')">Cancel</A>';
-
- print ' ) ';
-
- print ' ( <A HREF="'. popurl(2). 'edit/REAL_cust_pkg.cgi?'. $pkgnum.
- '">Edit dates</A> | ';
-
- print qq!<A HREF="$button_url">Customize</A> )!;
-
- }
- print '</FONT></TD>';
-
- for ( qw( setup bill susp expire cancel ) ) {
- print "<TD ROWSPAN=$rowspan><FONT SIZE=-1>", ( $package->getfield($_)
- ? time2str("%D</FONT><BR><FONT SIZE=-3>%l:%M:%S%P %z</FONT>",
- $package->getfield($_) )
- : ' '
- ), '</FONT></TD>',
- ;
- }
-
- my $n2 = '';
- #false laziness with view/cust_pkg.cgi, but i'm trying to make that go away so
- #foreach my $cust_svc ( @cust_svc ) {
- foreach my $svcpart ( sort { $a<=>$b } keys %pkg_svc ) {
- my $svc = qsearchs('part_svc',{'svcpart'=>$svcpart})->getfield('svc');
- $svc =~ s/ / /g;
- my(@cust_svc)=qsearch('cust_svc',{'pkgnum'=>$pkgnum,
- 'svcpart'=>$svcpart,
- });
- for my $enum ( 1 .. $pkg_svc{$svcpart} ) {
- my $cust_svc;
- if ( $cust_svc = shift @cust_svc ) {
- my($label, $value, $svcdb) = $cust_svc->label;
- my($svcnum) = $cust_svc->svcnum;
- my($sview) = popurl(2). "view";
- print $n2,qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$label</FONT></A></TD>!,
- qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$value</FONT></A></TD>!;
- } else {
- print $n2, qq!<TD COLSPAN=2><A HREF="$uiadd{$svcpart}?pkgnum$pkgnum-svcpart$svcpart"><b><font size="+1" color="#ff0000">!.
- qq!Provision $svc</A></b></font>!;
-
- print qq!<BR><A HREF="../misc/link.cgi?pkgnum$pkgnum-svcpart$svcpart">!.
- qq!<b><font size="+1" color="#ff0000">Link to legacy $svc</A></b></font>!
- if $conf->exists('legacy_link');
-
- print '</TD>';
- }
- $n2="</TR><TR>";
- }
- }
-
- $n1="</TR><TR>";
-}
-print "</TR>";
-
-#formatting
-print "</TABLE>";
-
-print <<END;
-<SCRIPT>
-function cust_pay_areyousure(href) {
- if (confirm("Are you sure you want to delete this payment?")
- == true)
- window.location.href = href;
-}
-</SCRIPT>
-END
-
-#formatting
-print qq!<BR><BR><A NAME="history">Payment History!.
- qq!</A> ( !.
- qq!<A HREF="!. popurl(2). qq!edit/cust_pay.cgi?custnum=$custnum">!.
- qq!Post payment</A> | !.
- qq!<A HREF="!. popurl(2). qq!edit/cust_credit.cgi?$custnum">!.
- qq!Post credit</A> )!;
-
-#get payment history
-#
-# major problem: this whole thing is way too sloppy.
-# minor problem: the description lines need better formatting.
-
-my @history = (); #needed for mod_perl :)
-
-my %target = ();
-
-my @bills = qsearch('cust_bill',{'custnum'=>$custnum});
-foreach my $bill (@bills) {
- my($bref)=$bill->hashref;
- my $bpre = ( $bill->owed > 0 )
- ? '<b><font size="+1" color="#ff0000"> Open '
- : '';
- my $bpost = ( $bill->owed > 0 ) ? '</font></b>' : '';
- push @history,
- $bref->{_date} . qq!\t<A HREF="!. popurl(2). qq!view/cust_bill.cgi?! .
- $bref->{invnum} . qq!">${bpre}Invoice #! . $bref->{invnum} .
- qq! (Balance \$! . $bill->owed . qq!)$bpost</A>\t! .
- $bref->{charged} . qq!\t\t\t!;
-
- my(@cust_bill_pay)=qsearch('cust_bill_pay',{'invnum'=> $bref->{invnum} } );
-# my(@payments)=qsearch('cust_pay',{'invnum'=> $bref->{invnum} } );
-# my($payment);
-# foreach $payment (@payments) {
- foreach my $cust_bill_pay (@cust_bill_pay) {
- my $payment = $cust_bill_pay->cust_pay;
- my($date,$invnum,$payby,$payinfo,$paid)=($payment->_date,
- $cust_bill_pay->invnum,
- $payment->payby,
- $payment->payinfo,
- $cust_bill_pay->amount,
- );
- $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4))
- if $payby eq 'CARD';
- my $target = "$payby$payinfo";
- $payby =~ s/^BILL$/Check #/ if $payinfo;
- $payby =~ s/^(CARD|COMP)$/$1 /;
- my $delete = $payment->closed !~ /^Y/i && $conf->exists('deletepayments')
- ? qq! (<A HREF="javascript:cust_pay_areyousure('${p}misc/delete-cust_pay.cgi?!. $payment->paynum. qq!')">delete</A>)!
- : '';
- push @history,
- "$date\tPayment, Invoice #$invnum ($payby$payinfo)$delete\t\t$paid\t\t\t$target";
- }
-
- my(@cust_credit_bill)=
- qsearch('cust_credit_bill', { 'invnum'=> $bref->{invnum} } );
- foreach my $cust_credit_bill (@cust_credit_bill) {
- my $cust_credit = $cust_credit_bill->cust_credit;
- my($date, $invnum, $crednum, $amount, $reason, $app_date ) = (
- $cust_credit->_date,
- $cust_credit_bill->invnum,
- $cust_credit_bill->crednum,
- $cust_credit_bill->amount,
- $cust_credit->reason,
- time2str("%D", $cust_credit_bill->_date),
- );
- push @history,
- "$date\tCredit #$crednum: $reason<BR>".
- "(applied to invoice #$invnum on $app_date)\t\t\t$amount\t";
- }
-}
+<A NAME="cust_main"></A>
+<TABLE BORDER=0>
+<TR>
+ <TD VALIGN="top">
+ <% include('cust_main/contacts.html', $cust_main ) %>
+ </TD>
+ <TD VALIGN="top" STYLE="padding-left: 54px">
+ <% include('cust_main/misc.html', $cust_main ) %>
+% if ( $conf->config('payby-default') ne 'HIDE' ) {
+
+ <BR>
+ <% include('cust_main/billing.html', $cust_main ) %>
+% }
+
+ </TD>
+</TR>
+</TABLE>
+%
+%if ( $cust_main->comments =~ /[^\s\n\r]/ ) {
+%
+
+<BR>
+Comments
+<% ntable("#cccccc") %><TR><TD><% ntable("#cccccc",2) %>
+<TR>
+ <TD BGCOLOR="#ffffff">
+ <PRE><% encode_entities($cust_main->comments) %></PRE>
+ </TD>
+</TR>
+</TABLE></TABLE>
+% }
+<BR><BR>
+% my $notecount = scalar($cust_main->notes());
+% if ( ! $conf->exists('cust_main-disable_notes') || $notecount) {
-my @credits = grep { scalar(my @array = $_->cust_credit_refund) }
- qsearch('cust_credit',{'custnum'=>$custnum});
-foreach my $credit (@credits) {
- my($cref)=$credit->hashref;
- my(@cust_credit_refund)=
- qsearch('cust_credit_refund', { 'crednum'=> $cref->{crednum} } );
- foreach my $cust_credit_refund (@cust_credit_refund) {
- my $cust_refund = $cust_credit_refund->cust_credit;
- my($date, $crednum, $amount, $reason, $app_date ) = (
- $credit->_date,
- $credit->crednum,
- $cust_credit_refund->amount,
- $credit->reason,
- time2str("%D", $cust_credit_refund->_date),
- );
- push @history,
- "$date\tCredit #$crednum: $reason<BR>".
- "(applied to refund on $app_date)\t\t\t$amount\t";
- }
-}
+<A NAME="cust_main_note"><FONT SIZE="+2">Notes</FONT></A><BR>
+% if ( $curuser->access_right('Add customer note') &&
+% ! $conf->exists('cust_main-disable_notes')
+% ) {
-@credits = grep { $_->credited > 0 }
- qsearch('cust_credit',{'custnum'=>$custnum});
-foreach my $credit (@credits) {
- my($cref)=$credit->hashref;
- push @history,
- $cref->{_date} . "\t" .
- qq!<A HREF="! . popurl(2). qq!edit/cust_credit_bill.cgi?!. $cref->{crednum} . qq!">!.
- '<b><font size="+1" color="#ff0000">Unapplied credit #' .
- $cref->{crednum} . "</font></b></A>: ".
- $cref->{reason} . "\t\t\t" . $credit->credited . "\t";
-}
+ <A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('<% $p %>edit/cust_main_note.cgi?custnum=<% $cust_main->custnum %>', 616, 386, 'cust_main_note_popup' ), CAPTION, 'Enter customer note', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;">Add customer note</A>
-my(@refunds)=qsearch('cust_refund',{'custnum'=> $custnum } );
-foreach my $refund (@refunds) {
- my($rref)=$refund->hashref;
- my($refundnum) = (
- $refund->refundnum,
- );
-
- push @history,
- $rref->{_date} . "\tRefund #$refundnum, (" .
- $rref->{payby} . " " . $rref->{payinfo} . ") by " .
- $rref->{otaker} . " - ". $rref->{reason} . "\t\t\t\t" .
- $rref->{refund};
-}
+% }
-my @unapplied_payments =
- grep { $_->unapplied > 0 } qsearch('cust_pay', { 'custnum' => $custnum } );
-foreach my $payment (@unapplied_payments) {
- my $payby = $payment->payby;
- my $payinfo = $payment->payinfo;
- #false laziness w/above
- $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4))
- if $payby eq 'CARD';
- my $target = "$payby$payinfo";
- $payby =~ s/^BILL$/Check #/ if $payinfo;
- $payby =~ s/^(CARD|COMP)$/$1 /;
- my $delete = $payment->closed !~ /^Y/i && $conf->exists('deletepayments')
- ? qq! (<A HREF="javascript:cust_pay_areyousure('${p}misc/delete-cust_pay.cgi?!. $payment->paynum. qq!')">delete</A>)!
- : '';
- push @history,
- $payment->_date. "\t".
- '<b><font size="+1" color="#ff0000">Unapplied payment #' .
- $payment->paynum . " ($payby$payinfo)</font></b> ".
- '(<A HREF="'. popurl(2). 'edit/cust_bill_pay.cgi?'. $payment->paynum. '">'.
- "apply</A>)$delete".
- "\t\t" . $payment->unapplied . "\t\t\t$target";
-}
+<BR>
- #formatting
- print &table(), <<END;
-<TR>
- <TH>Date</TH>
- <TH>Description</TH>
- <TH><FONT SIZE=-1>Charge</FONT></TH>
- <TH><FONT SIZE=-1>Payment</FONT></TH>
- <TH><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
- <TH><FONT SIZE=-1>Refund</FONT></TH>
- <TH><FONT SIZE=-1>Balance</FONT></TH>
-</TR>
-END
-
-#display payment history
-
-my $balance = 0;
-foreach my $item (sort keyfield_numerically @history) {
- my($date,$desc,$charge,$payment,$credit,$refund,$target)=split(/\t/,$item);
- $charge ||= 0;
- $payment ||= 0;
- $credit ||= 0;
- $refund ||= 0;
- $balance += $charge - $payment;
- $balance -= $credit - $refund;
- $balance = sprintf("%.2f", $balance);
- $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
- $target = '' unless defined $target;
-
- print "<TR><TD><FONT SIZE=-1>";
- print qq!<A NAME="$target">! unless $target && $target{$target}++;
- print time2str("%D",$date);
- print '</A>' if $target && $target{$target} == 1;
- print "</FONT></TD>",
- "<TD><FONT SIZE=-1>$desc</FONT></TD>",
- "<TD><FONT SIZE=-1>",
- ( $charge ? "\$".sprintf("%.2f",$charge) : '' ),
- "</FONT></TD>",
- "<TD><FONT SIZE=-1>",
- ( $payment ? "- \$".sprintf("%.2f",$payment) : '' ),
- "</FONT></TD>",
- "<TD><FONT SIZE=-1>",
- ( $credit ? "- \$".sprintf("%.2f",$credit) : '' ),
- "</FONT></TD>",
- "<TD><FONT SIZE=-1>",
- ( $refund ? "\$".sprintf("%.2f",$refund) : '' ),
- "</FONT></TD>",
- "<TD><FONT SIZE=-1>\$" . $balance,
- "</FONT></TD>",
- "\n";
-}
+% if ($notecount) {
+
+<iframe src="<% $p %>view/cust_main/notes.html?custnum=<% $cust_main->custnum %>" height="186" width="616" name="cust_main_notes" frameborder="0" marginborder="0" marginheight="0" scrolling="auto">
+ <div><br>[iframe not supported]<br><br></div>
+</iframe>
+
+% }else{ # make firefox happy wrt POSTDATA
+
+<iframe src="<% $p %>view/cust_main/notes.html?custnum=<% $cust_main->custnum %>" height="24" width="616" name="cust_main_notes" frameborder="0" marginborder="0" marginheight="0" scrolling="auto">
+ <div><br>[iframe not supported]<br><br></div>
+</iframe>
+
+% }
+
+% }
+
+
+% if ( $conf->config('ticket_system') ) {
-#formatting
-print "</TABLE>";
+ <BR><BR>
+ <% include('cust_main/tickets.html', $cust_main ) %>
+% }
-#end
-#formatting
-print <<END;
+<BR><BR>
- </BODY>
-</HTML>
-END
+% #XXX enable me# if ( $curuser->access_right('View customer packages') {
+<% include('cust_main/packages.html', $cust_main ) %>
+% #}
-#subroutiens
-sub keyfield_numerically { (split(/\t/,$a))[0] <=> (split(/\t/,$b))[0] ; }
+% if ( $conf->config('payby-default') ne 'HIDE' ) {
+ <% include('cust_main/payment_history.html', $cust_main ) %>
+% }
+
+
+<% include('/elements/footer.html') %>
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access denied"
+ unless $curuser->access_right('View customer');
+
+my $conf = new FS::Conf;
+
+die "No customer specified (bad URL)!" unless $cgi->keywords;
+my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
+$query =~ /^(\d+)$/;
+my $custnum = $1;
+my $cust_main = qsearchs({
+ 'table' => 'cust_main',
+ 'hashref' => {'custnum'=>$custnum},
+ 'extra_sql' => ' AND '. $curuser->agentnums_sql,
+});
+die "Customer not found!" unless $cust_main;
-%>
+</%init>