3 # $Id: cust_main.cgi,v 1.5 1999-01-18 09:41:37 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.5 1999-01-18 09:41:37 ivan
23 # all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl
26 # Revision 1.4 1998/12/30 00:57:50 ivan
29 # Revision 1.3 1998/12/17 09:41:08 ivan
30 # s/CGI::(Base|Request)/CGI.pm/;
32 # Revision 1.2 1998/11/12 08:10:22 ivan
33 # CGI.pm instead of CGI-modules
34 # relative URLs using popurl
35 # got rid of lots of little tables
36 # s/agrep/String::Approx/;
37 # bubble up packages and services and link (slow)
41 use vars qw(%ncancelled_pkgs %all_pkgs);
43 use CGI::Carp qw(fatalsToBrowser);
45 use String::Approx qw(amatch);
46 use FS::UID qw(cgisuidsetup);
47 use FS::Record qw(qsearch qsearchs);
48 use FS::CGI qw(header menubar idiot popurl table);
57 if ( $cgi->keywords ) {
58 my($query)=$cgi->keywords;
59 if ( $query eq 'custnum' ) {
60 $sortby=\*custnum_sort;
61 @cust_main=qsearch('cust_main',{});
62 } elsif ( $query eq 'last' ) {
64 @cust_main=qsearch('cust_main',{});
65 } elsif ( $query eq 'company' ) {
66 $sortby=\*company_sort;
67 @cust_main=qsearch('cust_main',{});
70 &cardsearch if ( $cgi->param('card_on') && $cgi->param('card') );
71 &lastsearch if ( $cgi->param('last_on') && $cgi->param('last_text') );
72 &companysearch if ( $cgi->param('company_on') && $cgi->param('company_text') );
75 my(%ncancelled_pkgs) =
76 map { $_->custnum => [ $_->ncancelled_pkgs ] } @cust_main;
78 map { $_->custnum => [ $_->all_pkgs ] } @cust_main;
80 if ( scalar(@cust_main) == 1 ) {
81 print $cgi->redirect(popurl(2). "view/cust_main.cgi?". $cust_main[0]->custnum);
83 } elsif ( scalar(@cust_main) == 0 ) {
84 idiot "No matching customers found!\n";
88 my($total)=scalar(@cust_main);
89 print $cgi->header( '-expires' => 'now' ), header("Customer Search Results",menubar(
90 'Main Menu', popurl(2)
91 )), "$total matching customers found<BR>", table, <<END;
97 <TH COLSPAN=2>Services</TH>
103 sort $sortby grep(!$saw{$_->custnum}++, @cust_main)
105 my($custnum,$last,$first,$company)=(
107 $cust_main->getfield('last'),
108 $cust_main->getfield('first'),
113 my($rowspan)=0;#scalar( @{$all_pkgs{$custnum}} );
114 foreach ( @{$all_pkgs{$custnum}} ) {
115 my(@cust_svc) = qsearch( 'cust_svc', { 'pkgnum' => $_->pkgnum } );
116 push @lol_cust_svc, \@cust_svc;
117 $rowspan += scalar(@cust_svc) || 1;
120 #my($rowspan) = scalar(@{$all_pkgs{$custnum}});
121 my($view) = popurl(2). "view/cust_main.cgi?$custnum";
124 <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$custnum</FONT></A></TD>
125 <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$last, $first</FONT></A></TD>
126 <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$company</FONT></A></TD>
130 foreach ( @{$all_pkgs{$custnum}} ) {
131 my($pkgnum) = ($_->pkgnum);
132 my($pkg) = $_->part_pkg->pkg;
133 my($pkgview) = popurl(2). "/view/cust_pkg.cgi?$pkgnum";
134 #my(@cust_svc) = shift @lol_cust_svc;
135 my(@cust_svc) = qsearch( 'cust_svc', { 'pkgnum' => $_->pkgnum } );
136 my($rowspan) = scalar(@cust_svc) || 1;
138 print $n1, qq!<TD ROWSPAN=$rowspan><A HREF="$pkgview"><FONT SIZE=-1>$pkg</FONT></A></TD>!;
140 foreach my $cust_svc ( @cust_svc ) {
141 my($label, $value, $svcdb) = $cust_svc->label;
142 my($svcnum) = $cust_svc->svcnum;
143 my($sview) = popurl(2). "/view";
144 print $n2,qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$label</FONT></A></TD>!,
145 qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$value</FONT></A></TD>!;
148 #print qq!</TR><TR>\n!;
166 $a->getfield('last') cmp $b->getfield('last');
170 return -1 if $a->company && ! $b->company;
171 return 1 if ! $a->company && $b->company;
172 $a->getfield('company') cmp $b->getfield('company');
176 $a->getfield('custnum') <=> $b->getfield('custnum');
181 my($card)=$cgi->param('card');
183 $card =~ /^(\d{13,16})$/ or do { idiot "Illegal card number\n"; exit; };
186 push @cust_main, qsearch('cust_main',{'payinfo'=>$payinfo, 'payby'=>'CARD'});
192 foreach ( $cgi->param('last_type') ) {
196 $cgi->param('last_text') =~ /^([\w \,\.\-\']*)$/
197 or do { idiot "Illegal last name"; exit; };
200 if ( $last_type{'Exact'}
201 && ! $last_type{'Fuzzy'}
202 # && ! $last_type{'Sound-alike'}
205 push @cust_main, qsearch('cust_main',{'last'=>$last});
211 my(@all_last)=map $_->getfield('last'), qsearch('cust_main',{});
212 if ($last_type{'Fuzzy'}) {
213 foreach ( amatch($last, [ qw(i) ], @all_last) ) {
218 #if ($last_type{'Sound-alike'}) {
221 foreach ( keys %last ) {
222 push @cust_main, qsearch('cust_main',{'last'=>$_});
232 foreach ( $cgi->param('company_type') ) {
236 $cgi->param('company_text') =~ /^([\w \,\.\-\']*)$/
237 or do { idiot "Illegal company"; exit; };
240 if ( $company_type{'Exact'}
241 && ! $company_type{'Fuzzy'}
242 # && ! $company_type{'Sound-alike'}
245 push @cust_main, qsearch('cust_main',{'company'=>$company});
250 my(@all_company)=map $_->company, qsearch('cust_main',{});
252 if ($company_type{'Fuzzy'}) {
253 foreach ( amatch($company, [ qw(i) ], @all_company ) ) {
258 #if ($company_type{'Sound-alike'}) {
261 foreach ( keys %company ) {
262 push @cust_main, qsearch('cust_main',{'company'=>$_});
266 $sortby=\*company_sort;