1 %my $curuser = $FS::CurrentUser::CurrentUser;
4 % unless $curuser->access_right('List customers');
6 %my $conf = new FS::Conf;
7 %my $maxrecords = $conf->config('maxsearchrecordsperpage');
8 %my $large_pkg_size = $conf->config('cust_pkg-large_pkg_size') || 0;
12 %#my $monsterjoin = <<END;
13 %#cust_main left outer join (
14 %# ( cust_pkg left outer join part_pkg using(pkgpart)
15 %# ) left outer join (
18 %# ( cust_svc left outer join part_svc using (svcpart)
19 %# ) left outer join svc_acct using (svcnum)
20 %# ) left outer join svc_domain using(svcnum)
21 %# ) left outer join svc_forward using(svcnum)
26 %#my $monsterjoin = <<END;
27 %#cust_main left outer join (
28 %# ( cust_pkg left outer join part_pkg using(pkgpart)
29 %# ) left outer join (
32 %# ( cust_svc left outer join part_svc using (svcpart)
33 %# ) left outer join (
34 %# svc_acct left outer join (
35 %# select svcnum, domain, catchall from svc_domain
36 %# ) as svc_acct_domsvc (
37 %# svc_acct_svcnum, svc_acct_domain, svc_acct_catchall
38 %# ) on svc_acct.domsvc = svc_acct_domsvc.svc_acct_svcnum
40 %# ) left outer join svc_domain using(svcnum)
41 %# ) left outer join svc_forward using(svcnum)
47 %$limit .= "LIMIT $maxrecords" if $maxrecords;
49 %my $offset = $cgi->param('offset') || 0;
50 %$limit .= " OFFSET $offset" if $offset;
54 %my(@cust_main, $sortby, $orderby);
56 %my @addl_headers = ();
58 %if ( $cgi->param('browse')
59 % || $cgi->param('otaker_on')
60 % || $cgi->param('agentnum_on')
65 % if ( $cgi->param('browse') ) {
66 % my $query = $cgi->param('browse');
67 % if ( $query eq 'custnum' ) {
68 % if ( $conf->exists('cust_main-default_agent_custid') ) {
69 % $sortby=\*display_custnum_sort;
70 % $orderby = "ORDER BY CASE WHEN agent_custid IS NOT NULL AND agent_custid != '' THEN CAST(agent_custid AS BIGINT) ELSE custnum END";
72 % $sortby=\*custnum_sort;
73 % $orderby = "ORDER BY custnum";
75 % } elsif ( $query eq 'last' ) {
76 % $sortby=\*last_sort;
77 % $orderby = "ORDER BY LOWER(last || ' ' || first)";
78 % } elsif ( $query eq 'company' ) {
79 % $sortby=\*company_sort;
80 % $orderby = "ORDER BY LOWER(company || ' ' || last || ' ' || first )";
81 % } elsif ( $query eq 'tickets' ) {
82 % $sortby = \*tickets_sort;
83 % $orderby = "ORDER BY tickets DESC";
84 % push @select, FS::TicketSystem->sql_num_customer_tickets. " as tickets";
85 % push @addl_headers, 'Tickets';
86 % push @addl_cols, 'tickets';
87 % } elsif ( $query eq 'uspsunvalid' ) {
88 % $search{'country'} = 'US';
89 % $sortby=\*custnum_sort;
90 % $orderby = "ORDER BY custnum";
92 % die "unknown browse field $query";
95 % $sortby = \*last_sort; #??
96 % $orderby = "ORDER BY LOWER(last || ' ' || first)"; #??
99 % if ( $cgi->param('otaker_on') ) {
100 % die "access denied"
101 % unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
102 % $cgi->param('otaker') =~ /^(\w{1,32})$/ or errorpage("Illegal otaker");
103 % $search{otaker} = $1;
104 % } elsif ( $cgi->param('agentnum_on') ) {
105 % $cgi->param('agentnum') =~ /^(\d+)$/ or errorpage("Illegal agentnum");
106 % $search{agentnum} = $1;
108 %# die "unknown query...";
113 % my $ncancelled = '';
115 % if ( $cgi->param('showcancelledcustomers') eq '0' #see if it was set by me
116 % || ( $conf->exists('hidecancelledcustomers')
117 % && ! $cgi->param('showcancelledcustomers') )
119 % #grep { $_->ncancelled_pkgs || ! $_->all_pkgs }
120 % push @qual, FS::cust_main->uncancel_sql;
124 % push @qual, FS::cust_main->cancel_sql if $cgi->param('cancelled');
125 % push @qual, FS::cust_main->prospect_sql if $cgi->param('prospect');
126 % push @qual, FS::cust_main->active_sql if $cgi->param('active');
127 % push @qual, FS::cust_main->inactive_sql if $cgi->param('inactive');
128 % push @qual, FS::cust_main->susp_sql if $cgi->param('suspended');
131 % my $qual = join(' AND ',
132 % map { "$_ = ". dbh->quote($search{$_}) } keys %search );
134 % my $addl_qual = join(' AND ', @qual);
136 % #here is the agent virtualization
137 % $addl_qual .= ( $addl_qual ? ' AND ' : '' ).
138 % $FS::CurrentUser::CurrentUser->agentnums_sql;
140 % if ( $cgi->param('browse') && $cgi->param('browse') eq 'uspsunvalid' ) {
141 % $addl_qual .= ' AND ( length(zip) < 9 OR upper(address1) != address1 OR upper(city) != city ) ';
144 % if ( $addl_qual ) {
145 % $qual .= ' AND ' if $qual;
146 % $qual .= $addl_qual;
149 % $qual = " WHERE $qual" if $qual;
150 % my $statement = "SELECT COUNT(*) FROM cust_main $qual";
151 % my $sth = dbh->prepare($statement) or die dbh->errstr." preparing $statement";
152 % $sth->execute or die "Error executing \"$statement\": ". $sth->errstr;
154 % $total = $sth->fetchrow_arrayref->[0];
156 % if ( $addl_qual ) {
158 % $addl_qual = " AND $addl_qual";
160 % $addl_qual = " WHERE $addl_qual";
166 % $select = 'cust_main.*, '. join (', ', @select);
171 % @cust_main = qsearch('cust_main', \%search, $select,
172 % "$addl_qual $orderby $limit" );
174 %# foreach my $cust_main ( @just_cust_main ) {
176 %# my @one_cust_main;
177 %# $FS::Record::DEBUG=1;
178 %# ( $cache, @one_cust_main ) = jsearch(
180 %# { 'custnum' => $cust_main->custnum },
186 %# push @cust_main, @one_cust_main;
191 % $sortby = \*last_sort;
193 % push @cust_main, @{&custnumsearch}
194 % if $cgi->param('custnum_on') && $cgi->param('custnum_text');
195 % push @cust_main, @{&cardsearch}
196 % if $cgi->param('card_on') && $cgi->param('card');
197 % push @cust_main, @{&lastsearch}
198 % if $cgi->param('last_on') && $cgi->param('last_text');
199 % push @cust_main, @{&companysearch}
200 % if $cgi->param('company_on') && $cgi->param('company_text');
201 % push @cust_main, @{&address2search}
202 % if $cgi->param('address2_on') && $cgi->param('address2_text');
203 % push @cust_main, @{&phonesearch}
204 % if $cgi->param('phone_on') && $cgi->param('phone_text');
205 % push @cust_main, @{&referralsearch}
206 % if $cgi->param('referral_custnum');
208 % if ( $cgi->param('company_on') && $cgi->param('company_text') ) {
209 % $sortby = \*company_sort;
210 % push @cust_main, @{&companysearch};
213 % if ( $cgi->param('search_cust') ) {
214 % $sortby = \*company_sort;
215 % $orderby = "ORDER BY LOWER(company || ' ' || last || ' ' || first )";
216 % push @cust_main, smart_search( 'search' => scalar($cgi->param('search_cust')),
217 % 'no_fuzzy_on_exact' => 1, #pref?
221 % @cust_main = grep { $_->ncancelled_pkgs || ! $_->all_pkgs } @cust_main
222 % if ! $cgi->param('cancelled')
224 % $cgi->param('showcancelledcustomers') eq '0' #see if it was set by me
225 % || ( $conf->exists('hidecancelledcustomers')
226 % && ! $cgi->param('showcancelledcustomers') )
230 % @cust_main = grep { !$saw{$_->custnum}++ } @cust_main;
234 %if ( $conf->exists('hidecancelledpackages' ) ) {
235 % %all_pkgs = map { $_->custnum => [ $_->ncancelled_pkgs ] } @cust_main;
237 % %all_pkgs = map { $_->custnum => [ $_->all_pkgs ] } @cust_main;
241 %if ( scalar(@cust_main) == 1 && ! $cgi->param('referral_custnum') ) {
242 % if ( $cgi->param('quickpay') eq 'yes' ) {
243 % print $cgi->redirect(popurl(2). "edit/cust_pay.cgi?quickpay=yes;custnum=". $cust_main[0]->custnum);
245 % print $cgi->redirect(popurl(2). "view/cust_main.cgi?". $cust_main[0]->custnum);
248 %} elsif ( scalar(@cust_main) == 0 ) {
251 <!-- mason kludge -->
253 % errorpage("No matching customers found!");
257 <% include('/elements/header.html', "Customer Search Results", '' ) %>
258 % $total ||= scalar(@cust_main);
261 <% $total %> matching customers found
263 % my $pager = include( '/elements/pager.html',
264 % 'offset' => $offset,
265 % 'num_rows' => scalar(@cust_main),
267 % 'maxrecords' => $maxrecords,
270 % unless ( $cgi->param('cancelled') ) {
271 % if ( $cgi->param('showcancelledcustomers') eq '0' #see if it was set by me
272 % || ( $conf->exists('hidecancelledcustomers')
273 % && ! $cgi->param('showcancelledcustomers')
276 % $cgi->param('showcancelledcustomers', 1);
277 % $cgi->param('offset', 0);
278 % print qq!( <a href="!. $cgi->self_url. qq!">show!;
280 % $cgi->param('showcancelledcustomers', 0);
281 % $cgi->param('offset', 0);
282 % print qq!( <a href="!. $cgi->self_url. qq!">hide!;
284 % print ' canceled customers</a> )';
287 % if ( $cgi->param('referral_custnum') ) {
288 % $cgi->param('referral_custnum') =~ /^(\d+)$/
289 % or errorpage("Illegal referral_custnum");
290 % my $referral_custnum = $1;
291 % my $cust_main = qsearchs('cust_main', { custnum => $referral_custnum } );
292 % print '<FORM METHOD="GET">'.
293 % qq!<INPUT TYPE="hidden" NAME="referral_custnum" VALUE="$referral_custnum">!.
294 % 'referrals of <A HREF="'. popurl(2).
295 % "view/cust_main.cgi?$referral_custnum\">$referral_custnum: ".
296 % ( $cust_main->company
297 % || $cust_main->last. ', '. $cust_main->first ).
301 % function changed(what) {
302 % what.form.submit();
306 % print ' <SELECT NAME="referral_depth" SIZE="1" onChange="changed(this)">';
307 % my $max = 8; #config file
308 % $cgi->param('referral_depth') =~ /^(\d*)$/
309 % or errorpage("Illegal referral_depth");
310 % my $referral_depth = $1;
312 % foreach my $depth ( 1 .. $max ) {
314 % ' SELECTED'x($depth == $referral_depth),
317 % print "</SELECT> levels deep".
318 % '<NOSCRIPT> <INPUT TYPE="submit" VALUE="change"></NOSCRIPT>'.
322 % my @custom_priorities = ();
323 % if ( $conf->config('ticket_system-custom_priority_field')
324 % && @{[ $conf->config('ticket_system-custom_priority_field-values') ]} ) {
325 % @custom_priorities =
326 % $conf->config('ticket_system-custom_priority_field-values');
329 % print "<BR><BR>". $pager. include('/elements/table-grid.html'). <<END;
331 % <TH CLASS="grid" BGCOLOR="#cccccc">#</TH>
332 % <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
333 % <TH CLASS="grid" BGCOLOR="#cccccc">(bill) name</TH>
334 % <TH CLASS="grid" BGCOLOR="#cccccc">company</TH>
337 %if ( defined dbdef->table('cust_main')->column('ship_last') ) {
339 % <TH CLASS="grid" BGCOLOR="#cccccc">(service) name</TH>
340 % <TH CLASS="grid" BGCOLOR="#cccccc">company</TH>
344 %foreach my $addl_header ( @addl_headers ) {
345 % print '<TH CLASS="grid" BGCOLOR="#cccccc">'. "$addl_header</TH>";
349 % <TH CLASS="grid" BGCOLOR="#cccccc">Packages</TH>
350 % <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2>Services</TH>
354 % my $bgcolor1 = '#eeeeee';
355 % my $bgcolor2 = '#ffffff';
358 % my(%saw,$cust_main);
359 % foreach $cust_main (
360 % sort $sortby grep(!$saw{$_->custnum}++, @cust_main)
363 % if ( $bgcolor eq $bgcolor1 ) {
364 % $bgcolor = $bgcolor2;
366 % $bgcolor = $bgcolor1;
369 % my($custnum,$last,$first,$company)=(
370 % $cust_main->custnum,
371 % $cust_main->getfield('last'),
372 % $cust_main->getfield('first'),
373 % $cust_main->company,
378 % foreach my $cust_pkg ( @{$all_pkgs{$custnum}} ) {
379 % my %cust_svc_by_svcpart;
381 % foreach my $part_svc ( $cust_pkg->part_svc ) {
382 % my $svcpart = $part_svc->svcpart;
383 % my $num_cust_svc = $cust_pkg->num_cust_svc($svcpart);
384 % if ( $large_pkg_size > 0 and $num_cust_svc >= $large_pkg_size ) {
385 % # don't retrieve the cust_svc records, just stash the
386 % # part_svc and num_cust_svc for later
387 % $cust_svc_by_svcpart{$svcpart} =
388 % [ 'summarize', $part_svc, $num_cust_svc ];
391 % elsif ( $num_cust_svc ) {
392 % $cust_svc_by_svcpart{$svcpart} = [ $cust_pkg->cust_svc($svcpart) ];
393 % $rows += $num_cust_svc;
395 % } #foreach $part_svc
396 % $rows ||= 1; # in case the package has no services
397 % push @all_cust_svc, \%cust_svc_by_svcpart;
398 % push @pkg_rowspans, $rows;
399 % } #foreach $cust_pkg
400 % my $rowspan = List::Util::sum(@pkg_rowspans) || 1;
403 % if ( defined $cgi->param('quickpay') && $cgi->param('quickpay') eq 'yes' ) {
404 % $view = $p. 'edit/cust_pay.cgi?quickpay=yes;custnum='. $custnum;
406 % $view = $p. 'view/cust_main.cgi?'. $custnum;
408 % my $pcompany = $company
409 % ? qq!<A HREF="$view"><FONT SIZE=-1>$company</FONT></A>!
410 % : '<FONT SIZE=-1> </FONT>';
412 % my $status = $cust_main->status;
413 % my $statuscol = $cust_main->statuscolor;
416 <TD CLASS="grid" ALIGN="right" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %>><A HREF="<% $view %>"><FONT SIZE=-1><% $cust_main->display_custnum %></FONT></A></TD>
417 <TD CLASS="grid" ALIGN="center" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %>><FONT SIZE="-1" COLOR="#<% $statuscol %>"><B><% ucfirst($status) %></B></FONT></TD>
418 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %>><A HREF="<% $view %>"><FONT SIZE=-1><% "$last, $first" %></FONT></A></TD>
419 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %>><% $pcompany %></TD>
421 % if ( defined dbdef->table('cust_main')->column('ship_last') ) {
422 % my($ship_last,$ship_first,$ship_company)=(
423 % $cust_main->ship_last || $cust_main->getfield('last'),
424 % $cust_main->ship_last ? $cust_main->ship_first : $cust_main->first,
425 % $cust_main->ship_last ? $cust_main->ship_company : $cust_main->company,
427 % my $pship_company = $ship_company
428 % ? qq!<A HREF="$view"><FONT SIZE=-1>$ship_company</FONT></A>!
429 % : '<FONT SIZE=-1> </FONT>';
433 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %>><A HREF="<% $view %>"><FONT SIZE=-1><% "$ship_last, $ship_first" %></FONT></A></TD>
434 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %>><% $pship_company %></A></TD>
437 % foreach my $addl_col ( @addl_cols ) {
438 % if ( $addl_col eq 'tickets' ) {
439 % if ( @custom_priorities ) {
442 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %> ALIGN=right><FONT SIZE=-1>
444 <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
445 % foreach my $priority ( @custom_priorities, '' ) {
448 % FS::TicketSystem->num_customer_tickets($custnum,$priority);
450 % $ahref= '<A HREF="'.
451 % FS::TicketSystem->href_customer_tickets($custnum,$priority).
459 <FONT SIZE=-1><% $ahref.$num %></A></FONT>
462 <FONT SIZE=-1><% $ahref %><% $priority || '<i>(none)</i>' %></A></FONT>
469 <TH ALIGN=right STYLE="border-top: dashed 1px black">
474 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %> ALIGN=right><FONT SIZE=-1>
478 % $ahref = '<A HREF="'.
479 % FS::TicketSystem->href_customer_tickets($custnum).
481 % if $cust_main->get($addl_col);
485 <% $ahref %><% $cust_main->get($addl_col) %></A>
486 % if ( @custom_priorities ) {
490 <TH ALIGN=left STYLE="border-top: dashed 1px black">
491 <FONT SIZE=-1><% ${ahref} %>Total</A><FONT>
502 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %> ALIGN=right><FONT SIZE=-1>
503 <% $cust_main->get($addl_col) %>
510 % foreach ( @{$all_pkgs{$custnum}} ) {
511 % my $pkgnum = $_->pkgnum;
512 %# my $part_pkg = qsearchs( 'part_pkg', { pkgpart => $_->pkgpart } );
513 % my $part_pkg = $_->part_pkg;
515 % my $pkg_comment = $part_pkg->pkg_comment(nopkgpart => 1);
516 % my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
518 % : ';show=packages';
519 % my $frag = "cust_pkg$pkgnum"; #hack for IE ignoring real #fragment
520 % my $pkgview = "${p}view/cust_main.cgi?custnum=$custnum$show;fragment=$frag#$frag";
521 % # cust_svc stuff, built earlier
522 % my %cust_svc_by_svcpart = %{ shift @all_cust_svc };
523 % my $pkg_rowspan = shift @pkg_rowspans;
525 <% $n1 %><TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ROWSPAN="<% $pkg_rowspan %>">
526 <A HREF="$pkgview"><FONT SIZE=-1><% $pkg_comment %></FONT></A></TD>
529 % my $td = '<TD CLASS="grid" BGCOLOR="'.$bgcolor.'">';
531 % foreach my $svcpart ( sort keys %cust_svc_by_svcpart ) { #sort order?
532 % my $these = $cust_svc_by_svcpart{$svcpart};
533 % if ( $these->[0] eq 'summarize' ) {
534 % my $part_svc = $these->[1];
535 % my $num_cust_svc = $these->[2];
538 % # link opens a new search for this pkgnum/svcnum combo
539 % my $href = $p.'search/cust_pkg_svc.html?svcpart='.$svcpart.
540 % ';pkgnum='.$pkgnum;
542 <A HREF="<% $href %>"><% $part_svc->svc %></A>
545 <A HREF="<% $href %>"><B>(view all <% $num_cust_svc %>)</B></A>
549 <% $td %><& /elements/search-cust_svc.html,
550 'svcpart' => $svcpart,
552 'svcdb' => $part_svc->svcdb,
556 % elsif ( scalar @$these ) { # do not summarize
557 % foreach my $cust_svc ( @$these ) {
560 <% FS::UI::Web::svc_link($m, $cust_svc->part_svc, $cust_svc) %>
563 <% FS::UI::Web::svc_label_link($m, $cust_svc->part_svc, $cust_svc) %>
566 % } # foreach $cust_svc
568 % } # foreach $svcpart
570 % unless ( %cust_svc_by_svcpart ) {
571 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" COLSPAN=2> </TD>
574 % #print qq!</TR><TR>\n!;
578 % unless ( @{$all_pkgs{$custnum}} ) {
579 % print qq!<TD CLASS="grid" BGCOLOR="$bgcolor" COLSPAN=3> </TD>!;
590 <% include('/elements/footer.html') %>
593 %#undef $cache; #does this help?
598 % lc($a->getfield('last')) cmp lc($b->getfield('last'))
599 % || lc($a->first) cmp lc($b->first);
603 % return -1 if $a->company && ! $b->company;
604 % return 1 if ! $a->company && $b->company;
605 % lc($a->company) cmp lc($b->company)
606 % || lc($a->getfield('last')) cmp lc($b->getfield('last'))
607 % || lc($a->first) cmp lc($b->first);;
610 %sub display_custnum_sort {
611 % $a->display_custnum <=> $b->display_custnum;
615 % $a->getfield('custnum') <=> $b->getfield('custnum');
619 % $b->getfield('tickets') <=> $a->getfield('tickets');
624 % my $custnum = $cgi->param('custnum_text');
625 % $custnum =~ s/\D//g;
626 % $custnum =~ /^(\d{1,23})$/ or errorpage("Illegal customer number");
629 % [ qsearchs('cust_main', { 'custnum' => $custnum } ) ];
634 % my($card)=$cgi->param('card');
636 % $card =~ /^(\d{13,16})$/ or errorpage("Illegal card number");
639 % [ qsearch('cust_main',{'payinfo'=>$payinfo, 'payby'=>'CARD'}),
640 % qsearch('cust_main',{'payinfo'=>$payinfo, 'payby'=>'DCRD'})
644 %sub referralsearch {
645 % $cgi->param('referral_custnum') =~ /^(\d+)$/
646 % or errorpage("Illegal referral_custnum");
647 % my $cust_main = qsearchs('cust_main', { 'custnum' => $1 } )
648 % or errorpage("Customer $1 not found");
650 % if ( $cgi->param('referral_depth') ) {
651 % $cgi->param('referral_depth') =~ /^(\d+)$/
652 % or errorpage("Illegal referral_depth");
657 % [ $cust_main->referral_cust_main($depth) ];
663 % foreach ( $cgi->param('last_type') ) {
667 % $cgi->param('last_text') =~ /^([\w \,\.\-\']*)$/
668 % or errorpage("Illegal last name");
671 % if ( $last_type{'Exact'} || $last_type{'Fuzzy'} ) {
672 % push @cust_main, qsearch( 'cust_main',
673 % { 'last' => { 'op' => 'ILIKE',
674 % 'value' => $last } } );
676 % push @cust_main, qsearch( 'cust_main',
677 % { 'ship_last' => { 'op' => 'ILIKE',
678 % 'value' => $last } } )
679 % if defined dbdef->table('cust_main')->column('ship_last');
682 % if ( $last_type{'Substring'} || $last_type{'All'} ) {
684 % push @cust_main, qsearch( 'cust_main',
685 % { 'last' => { 'op' => 'ILIKE',
686 % 'value' => "%$last%" } } );
688 % push @cust_main, qsearch( 'cust_main',
689 % { 'ship_last' => { 'op' => 'ILIKE',
690 % 'value' => "%$last%" } } )
691 % if defined dbdef->table('cust_main')->column('ship_last');
695 % if ( $last_type{'Fuzzy'} || $last_type{'All'} ) {
696 % push @cust_main, FS::cust_main::Search->fuzzy_search( { 'last' => $last } );
699 % #if ($last_type{'Sound-alike'}) {
709 % foreach ( $cgi->param('company_type') ) {
710 % $company_type{$_}++
713 % $cgi->param('company_text') =~
714 % /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=]*)$/
715 % or errorpage("Illegal company");
718 % if ( $company_type{'Exact'} || $company_type{'Fuzzy'} ) {
719 % push @cust_main, qsearch( 'cust_main',
720 % { 'company' => { 'op' => 'ILIKE',
721 % 'value' => $company } } );
723 % push @cust_main, qsearch( 'cust_main',
724 % { 'ship_company' => { 'op' => 'ILIKE',
725 % 'value' => $company } } )
726 % if defined dbdef->table('cust_main')->column('ship_last');
729 % if ( $company_type{'Substring'} || $company_type{'All'} ) {
731 % push @cust_main, qsearch( 'cust_main',
732 % { 'company' => { 'op' => 'ILIKE',
733 % 'value' => "%$company%" } } );
735 % push @cust_main, qsearch( 'cust_main',
736 % { 'ship_company' => { 'op' => 'ILIKE',
737 % 'value' => "%$company%" } })
738 % if defined dbdef->table('cust_main')->column('ship_last');
742 % if ( $company_type{'Fuzzy'} || $company_type{'All'} ) {
743 % push @cust_main, FS::cust_main::Search->fuzzy_search( { 'company' => $company } );
746 % if ($company_type{'Sound-alike'}) {
752 %sub address2search {
755 % $cgi->param('address2_text') =~
756 % /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=]*)$/
757 % or errorpage("Illegal address2");
760 % push @cust_main, qsearch( 'cust_main',
761 % { 'address2' => { 'op' => 'ILIKE',
762 % 'value' => $address2 } } );
763 % push @cust_main, qsearch( 'cust_main',
764 % { 'ship_address2' => { 'op' => 'ILIKE',
765 % 'value' => $address2 } } );
773 % my $phone = $cgi->param('phone_text');
775 % #(no longer really) false laziness with Record::ut_phonen
776 % #only works with US/CA numbers...
778 % if ( $phone =~ /^(\d{3})(\d{3})(\d{4})(\d*)$/ ) {
779 % $phone = "$1-$2-$3";
780 % $phone .= " x$4" if $4;
781 % } elsif ( $phone =~ /^(\d{3})(\d{4})$/ ) {
783 % } elsif ( $phone =~ /^(\d{3,4})$/ ) {
786 % errorpage(gettext('illegal_phone'). ": $phone");
789 % my @fields = qw(daytime night fax);
790 % push @fields, qw(ship_daytime ship_night ship_fax)
791 % if defined dbdef->table('cust_main')->column('ship_last');
793 % for my $field ( @fields ) {
794 % push @cust_main, qsearch ( 'cust_main',
795 % { $field => { 'op' => 'LIKE',
796 % 'value' => "%$phone%" } } );