3 # $Id: cust_main.cgi,v 1.4 1998-12-30 00:57:50 ivan Exp $
6 # http://server.name/path/cust_main.cgi
8 # Note: Should be run setuid freeside as user nobody.
10 # ivan@voicenet.com 96-dec-12
12 # rewrite ivan@sisd.com 98-mar-4
14 # now does browsing too ivan@sisd.com 98-mar-6
16 # Changes to allow page to work at a relative position in server
17 # bmccane@maxbaud.net 98-apr-3
19 # display total, use FS::CGI ivan@sisd.com 98-jul-17
21 # $Log: cust_main.cgi,v $
22 # Revision 1.4 1998-12-30 00:57:50 ivan
25 # Revision 1.3 1998/12/17 09:41:08 ivan
26 # s/CGI::(Base|Request)/CGI.pm/;
28 # Revision 1.2 1998/11/12 08:10:22 ivan
29 # CGI.pm instead of CGI-modules
30 # relative URLs using popurl
31 # got rid of lots of little tables
32 # s/agrep/String::Approx/;
33 # bubble up packages and services and link (slow)
37 use vars qw(%ncancelled_pkgs %all_pkgs);
39 use CGI::Carp qw(fatalsToBrowser);
41 use String::Approx qw(amatch);
42 use FS::UID qw(cgisuidsetup);
43 use FS::Record qw(qsearch qsearchs);
44 use FS::CGI qw(header menubar idiot popurl table);
53 if ( $cgi->keywords ) {
54 my($query)=$cgi->keywords;
55 if ( $query eq 'custnum' ) {
56 $sortby=\*custnum_sort;
57 @cust_main=qsearch('cust_main',{});
58 } elsif ( $query eq 'last' ) {
60 @cust_main=qsearch('cust_main',{});
61 } elsif ( $query eq 'company' ) {
62 $sortby=\*company_sort;
63 @cust_main=qsearch('cust_main',{});
66 &cardsearch if ( $cgi->param('card_on') && $cgi->param('card') );
67 &lastsearch if ( $cgi->param('last_on') && $cgi->param('last_text') );
68 &companysearch if ( $cgi->param('company_on') && $cgi->param('company_text') );
71 my(%ncancelled_pkgs) =
72 map { $_->custnum => [ $_->ncancelled_pkgs ] } @cust_main;
74 map { $_->custnum => [ $_->all_pkgs ] } @cust_main;
76 if ( scalar(@cust_main) == 1 ) {
77 print $cgi->redirect(popurl(2). "view/cust_main.cgi?". $cust_main[0]->custnum);
79 } elsif ( scalar(@cust_main) == 0 ) {
80 idiot "No matching customers found!\n";
84 my($total)=scalar(@cust_main);
85 print $cgi->header, header("Customer Search Results",menubar(
86 'Main Menu', popurl(2)
87 )), "$total matching customers found<BR>", table, <<END;
93 <TH COLSPAN=2>Services</TH>
99 sort $sortby grep(!$saw{$_->custnum}++, @cust_main)
101 my($custnum,$last,$first,$company)=(
103 $cust_main->getfield('last'),
104 $cust_main->getfield('first'),
109 my($rowspan)=0;#scalar( @{$all_pkgs{$custnum}} );
110 foreach ( @{$all_pkgs{$custnum}} ) {
111 my(@cust_svc) = qsearch( 'cust_svc', { 'pkgnum' => $_->pkgnum } );
112 push @lol_cust_svc, \@cust_svc;
113 $rowspan += scalar(@cust_svc) || 1;
116 #my($rowspan) = scalar(@{$all_pkgs{$custnum}});
117 my($view) = popurl(2). "view/cust_main.cgi?$custnum";
120 <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$custnum</FONT></A></TD>
121 <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$last, $first</FONT></A></TD>
122 <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$company</FONT></A></TD>
126 foreach ( @{$all_pkgs{$custnum}} ) {
127 my($pkgnum) = ($_->pkgnum);
128 my($pkg) = $_->part_pkg->pkg;
129 my($pkgview) = popurl(2). "/view/cust_pkg.cgi?$pkgnum";
130 #my(@cust_svc) = shift @lol_cust_svc;
131 my(@cust_svc) = qsearch( 'cust_svc', { 'pkgnum' => $_->pkgnum } );
132 my($rowspan) = scalar(@cust_svc) || 1;
134 print $n1, qq!<TD ROWSPAN=$rowspan><A HREF="$pkgview"><FONT SIZE=-1>$pkg</FONT></A></TD>!;
136 foreach my $cust_svc ( @cust_svc ) {
137 my($label, $value, $svcdb) = $cust_svc->label;
138 my($svcnum) = $cust_svc->svcnum;
139 my($sview) = popurl(2). "/view";
140 print $n2,qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$label</FONT></A></TD>!,
141 qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$value</FONT></A></TD>!;
144 #print qq!</TR><TR>\n!;
162 $a->getfield('last') cmp $b->getfield('last');
166 return -1 if $a->company && ! $b->company;
167 return 1 if ! $a->company && $b->company;
168 $a->getfield('company') cmp $b->getfield('company');
172 $a->getfield('custnum') <=> $b->getfield('custnum');
177 my($card)=$cgi->param('card');
179 $card =~ /^(\d{13,16})$/ or do { idiot "Illegal card number\n"; exit; };
182 push @cust_main, qsearch('cust_main',{'payinfo'=>$payinfo, 'payby'=>'CARD'});
188 foreach ( $cgi->param('last_type') ) {
192 $cgi->param('last_text') =~ /^([\w \,\.\-\']*)$/
193 or do { idiot "Illegal last name"; exit; };
196 if ( $last_type{'Exact'}
197 && ! $last_type{'Fuzzy'}
198 # && ! $last_type{'Sound-alike'}
201 push @cust_main, qsearch('cust_main',{'last'=>$last});
207 my(@all_last)=map $_->getfield('last'), qsearch('cust_main',{});
208 if ($last_type{'Fuzzy'}) {
209 foreach ( amatch($last, [ qw(i) ], @all_last) ) {
214 #if ($last_type{'Sound-alike'}) {
217 foreach ( keys %last ) {
218 push @cust_main, qsearch('cust_main',{'last'=>$_});
228 foreach ( $cgi->param('company_type') ) {
232 $cgi->param('company_text') =~ /^([\w \,\.\-\']*)$/
233 or do { idiot "Illegal company"; exit; };
236 if ( $company_type{'Exact'}
237 && ! $company_type{'Fuzzy'}
238 # && ! $company_type{'Sound-alike'}
241 push @cust_main, qsearch('cust_main',{'company'=>$company});
246 my(@all_company)=map $_->company, qsearch('cust_main',{});
248 if ($company_type{'Fuzzy'}) {
249 foreach ( amatch($company, [ qw(i) ], @all_company ) ) {
254 #if ($company_type{'Sound-alike'}) {
257 foreach ( keys %company ) {
258 push @cust_main, qsearch('cust_main',{'company'=>$_});
262 $sortby=\*company_sort;