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;
380 % foreach my $svc ( $cust_pkg->cust_svc ) {
381 % push @{ $cust_svc_by_svcpart{$svc->svcpart} ||= [] }, $svc;
383 % push @all_cust_svc, \%cust_svc_by_svcpart;
384 % if ( !keys %cust_svc_by_svcpart ) {
386 % push @pkg_rowspans, 1;
390 % foreach (values %cust_svc_by_svcpart) {
391 % # summarizing takes two rows per svcpart,
392 % # full display takes one per cust_svc
393 % $rows += ( $large_pkg_size > 0 && $large_pkg_size <= scalar @$_ ) ?
396 % push @pkg_rowspans, $rows;
399 % my $rowspan = List::Util::sum(@pkg_rowspans) || 1;
402 % if ( defined $cgi->param('quickpay') && $cgi->param('quickpay') eq 'yes' ) {
403 % $view = $p. 'edit/cust_pay.cgi?quickpay=yes;custnum='. $custnum;
405 % $view = $p. 'view/cust_main.cgi?'. $custnum;
407 % my $pcompany = $company
408 % ? qq!<A HREF="$view"><FONT SIZE=-1>$company</FONT></A>!
409 % : '<FONT SIZE=-1> </FONT>';
411 % my $status = $cust_main->status;
412 % my $statuscol = $cust_main->statuscolor;
415 <TD CLASS="grid" ALIGN="right" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %>><A HREF="<% $view %>"><FONT SIZE=-1><% $cust_main->display_custnum %></FONT></A></TD>
416 <TD CLASS="grid" ALIGN="center" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %>><FONT SIZE="-1" COLOR="#<% $statuscol %>"><B><% ucfirst($status) %></B></FONT></TD>
417 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %>><A HREF="<% $view %>"><FONT SIZE=-1><% "$last, $first" %></FONT></A></TD>
418 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %>><% $pcompany %></TD>
420 % if ( defined dbdef->table('cust_main')->column('ship_last') ) {
421 % my($ship_last,$ship_first,$ship_company)=(
422 % $cust_main->ship_last || $cust_main->getfield('last'),
423 % $cust_main->ship_last ? $cust_main->ship_first : $cust_main->first,
424 % $cust_main->ship_last ? $cust_main->ship_company : $cust_main->company,
426 % my $pship_company = $ship_company
427 % ? qq!<A HREF="$view"><FONT SIZE=-1>$ship_company</FONT></A>!
428 % : '<FONT SIZE=-1> </FONT>';
432 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %>><A HREF="<% $view %>"><FONT SIZE=-1><% "$ship_last, $ship_first" %></FONT></A></TD>
433 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %>><% $pship_company %></A></TD>
436 % foreach my $addl_col ( @addl_cols ) {
437 % if ( $addl_col eq 'tickets' ) {
438 % if ( @custom_priorities ) {
441 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %> ALIGN=right><FONT SIZE=-1>
443 <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
444 % foreach my $priority ( @custom_priorities, '' ) {
447 % FS::TicketSystem->num_customer_tickets($custnum,$priority);
449 % $ahref= '<A HREF="'.
450 % FS::TicketSystem->href_customer_tickets($custnum,$priority).
458 <FONT SIZE=-1><% $ahref.$num %></A></FONT>
461 <FONT SIZE=-1><% $ahref %><% $priority || '<i>(none)</i>' %></A></FONT>
468 <TH ALIGN=right STYLE="border-top: dashed 1px black">
473 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %> ALIGN=right><FONT SIZE=-1>
477 % $ahref = '<A HREF="'.
478 % FS::TicketSystem->href_customer_tickets($custnum).
480 % if $cust_main->get($addl_col);
484 <% $ahref %><% $cust_main->get($addl_col) %></A>
485 % if ( @custom_priorities ) {
489 <TH ALIGN=left STYLE="border-top: dashed 1px black">
490 <FONT SIZE=-1><% ${ahref} %>Total</A><FONT>
501 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ROWSPAN=<% $rowspan %> ALIGN=right><FONT SIZE=-1>
502 <% $cust_main->get($addl_col) %>
509 % foreach ( @{$all_pkgs{$custnum}} ) {
510 % my $pkgnum = $_->pkgnum;
511 %# my $part_pkg = qsearchs( 'part_pkg', { pkgpart => $_->pkgpart } );
512 % my $part_pkg = $_->part_pkg;
514 % my $pkg_comment = $part_pkg->pkg_comment(nopkgpart => 1);
515 % my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
517 % : ';show=packages';
518 % my $frag = "cust_pkg$pkgnum"; #hack for IE ignoring real #fragment
519 % my $pkgview = "${p}view/cust_main.cgi?custnum=$custnum$show;fragment=$frag#$frag";
520 % # cust_svc stuff, built earlier
521 % my %cust_svc_by_svcpart = %{ shift @all_cust_svc };
522 % my $pkg_rowspan = shift @pkg_rowspans;
524 <% $n1 %><TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ROWSPAN="<% $pkg_rowspan %>">
525 <A HREF="$pkgview"><FONT SIZE=-1><% $pkg_comment %></FONT></A></TD>
528 % my $td = '<TD CLASS="grid" BGCOLOR="'.$bgcolor.'">';
530 % foreach my $svcpart ( sort keys %cust_svc_by_svcpart ) { #sort order?
531 % my $these = $cust_svc_by_svcpart{$svcpart};
532 % my $num_cust_svc = scalar @$these; # always at least 1
533 % if ( $large_pkg_size > 0 && $num_cust_svc >= $large_pkg_size ) {
536 % # link opens a new search for this pkgnum/svcnum combo
537 % my $href = $p.'search/cust_pkg_svc.html?svcpart='.$svcpart.
538 % ';pkgnum='.$pkgnum;
540 <A HREF="<% $href %>"><% $these->[0]->part_svc->svc %></A>
543 <A HREF="<% $href %>"><B>(view all <% $num_cust_svc %>)</B></A>
547 <% $td %><& /elements/search-cust_svc.html,
548 'svcpart' => $svcpart,
553 % else { # do not summarize
554 % foreach my $cust_svc ( @$these ) {
557 <% FS::UI::Web::svc_link($m, $cust_svc->part_svc, $cust_svc) %>
560 <% FS::UI::Web::svc_label_link($m, $cust_svc->part_svc, $cust_svc) %>
563 % } # foreach $cust_svc
565 % } # foreach $svcpart
567 % unless ( %cust_svc_by_svcpart ) {
568 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" COLSPAN=2> </TD>
571 % #print qq!</TR><TR>\n!;
575 % unless ( @{$all_pkgs{$custnum}} ) {
576 % print qq!<TD CLASS="grid" BGCOLOR="$bgcolor" COLSPAN=3> </TD>!;
587 <% include('/elements/footer.html') %>
590 %#undef $cache; #does this help?
595 % lc($a->getfield('last')) cmp lc($b->getfield('last'))
596 % || lc($a->first) cmp lc($b->first);
600 % return -1 if $a->company && ! $b->company;
601 % return 1 if ! $a->company && $b->company;
602 % lc($a->company) cmp lc($b->company)
603 % || lc($a->getfield('last')) cmp lc($b->getfield('last'))
604 % || lc($a->first) cmp lc($b->first);;
607 %sub display_custnum_sort {
608 % $a->display_custnum <=> $b->display_custnum;
612 % $a->getfield('custnum') <=> $b->getfield('custnum');
616 % $b->getfield('tickets') <=> $a->getfield('tickets');
621 % my $custnum = $cgi->param('custnum_text');
622 % $custnum =~ s/\D//g;
623 % $custnum =~ /^(\d{1,23})$/ or errorpage("Illegal customer number");
626 % [ qsearchs('cust_main', { 'custnum' => $custnum } ) ];
631 % my($card)=$cgi->param('card');
633 % $card =~ /^(\d{13,16})$/ or errorpage("Illegal card number");
636 % [ qsearch('cust_main',{'payinfo'=>$payinfo, 'payby'=>'CARD'}),
637 % qsearch('cust_main',{'payinfo'=>$payinfo, 'payby'=>'DCRD'})
641 %sub referralsearch {
642 % $cgi->param('referral_custnum') =~ /^(\d+)$/
643 % or errorpage("Illegal referral_custnum");
644 % my $cust_main = qsearchs('cust_main', { 'custnum' => $1 } )
645 % or errorpage("Customer $1 not found");
647 % if ( $cgi->param('referral_depth') ) {
648 % $cgi->param('referral_depth') =~ /^(\d+)$/
649 % or errorpage("Illegal referral_depth");
654 % [ $cust_main->referral_cust_main($depth) ];
660 % foreach ( $cgi->param('last_type') ) {
664 % $cgi->param('last_text') =~ /^([\w \,\.\-\']*)$/
665 % or errorpage("Illegal last name");
668 % if ( $last_type{'Exact'} || $last_type{'Fuzzy'} ) {
669 % push @cust_main, qsearch( 'cust_main',
670 % { 'last' => { 'op' => 'ILIKE',
671 % 'value' => $last } } );
673 % push @cust_main, qsearch( 'cust_main',
674 % { 'ship_last' => { 'op' => 'ILIKE',
675 % 'value' => $last } } )
676 % if defined dbdef->table('cust_main')->column('ship_last');
679 % if ( $last_type{'Substring'} || $last_type{'All'} ) {
681 % push @cust_main, qsearch( 'cust_main',
682 % { 'last' => { 'op' => 'ILIKE',
683 % 'value' => "%$last%" } } );
685 % push @cust_main, qsearch( 'cust_main',
686 % { 'ship_last' => { 'op' => 'ILIKE',
687 % 'value' => "%$last%" } } )
688 % if defined dbdef->table('cust_main')->column('ship_last');
692 % if ( $last_type{'Fuzzy'} || $last_type{'All'} ) {
693 % push @cust_main, FS::cust_main::Search->fuzzy_search( { 'last' => $last } );
696 % #if ($last_type{'Sound-alike'}) {
706 % foreach ( $cgi->param('company_type') ) {
707 % $company_type{$_}++
710 % $cgi->param('company_text') =~
711 % /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=]*)$/
712 % or errorpage("Illegal company");
715 % if ( $company_type{'Exact'} || $company_type{'Fuzzy'} ) {
716 % push @cust_main, qsearch( 'cust_main',
717 % { 'company' => { 'op' => 'ILIKE',
718 % 'value' => $company } } );
720 % push @cust_main, qsearch( 'cust_main',
721 % { 'ship_company' => { 'op' => 'ILIKE',
722 % 'value' => $company } } )
723 % if defined dbdef->table('cust_main')->column('ship_last');
726 % if ( $company_type{'Substring'} || $company_type{'All'} ) {
728 % push @cust_main, qsearch( 'cust_main',
729 % { 'company' => { 'op' => 'ILIKE',
730 % 'value' => "%$company%" } } );
732 % push @cust_main, qsearch( 'cust_main',
733 % { 'ship_company' => { 'op' => 'ILIKE',
734 % 'value' => "%$company%" } })
735 % if defined dbdef->table('cust_main')->column('ship_last');
739 % if ( $company_type{'Fuzzy'} || $company_type{'All'} ) {
740 % push @cust_main, FS::cust_main::Search->fuzzy_search( { 'company' => $company } );
743 % if ($company_type{'Sound-alike'}) {
749 %sub address2search {
752 % $cgi->param('address2_text') =~
753 % /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=]*)$/
754 % or errorpage("Illegal address2");
757 % push @cust_main, qsearch( 'cust_main',
758 % { 'address2' => { 'op' => 'ILIKE',
759 % 'value' => $address2 } } );
760 % push @cust_main, qsearch( 'cust_main',
761 % { 'ship_address2' => { 'op' => 'ILIKE',
762 % 'value' => $address2 } } );
770 % my $phone = $cgi->param('phone_text');
772 % #(no longer really) false laziness with Record::ut_phonen
773 % #only works with US/CA numbers...
775 % if ( $phone =~ /^(\d{3})(\d{3})(\d{4})(\d*)$/ ) {
776 % $phone = "$1-$2-$3";
777 % $phone .= " x$4" if $4;
778 % } elsif ( $phone =~ /^(\d{3})(\d{4})$/ ) {
780 % } elsif ( $phone =~ /^(\d{3,4})$/ ) {
783 % errorpage(gettext('illegal_phone'). ": $phone");
786 % my @fields = qw(daytime night fax);
787 % push @fields, qw(ship_daytime ship_night ship_fax)
788 % if defined dbdef->table('cust_main')->column('ship_last');
790 % for my $field ( @fields ) {
791 % push @cust_main, qsearch ( 'cust_main',
792 % { $field => { 'op' => 'LIKE',
793 % 'value' => "%$phone%" } } );