fix date range for old perl, count tax exempt and COMP customers correctly
[freeside.git] / httemplate / search / cust_main.cgi
1 <%
2
3 my $conf = new FS::Conf;
4 my $maxrecords = $conf->config('maxsearchrecordsperpage');
5
6 #my $cache;
7
8 #my $monsterjoin = <<END;
9 #cust_main left outer join (
10 #  ( cust_pkg left outer join part_pkg using(pkgpart)
11 #  ) left outer join (
12 #    (
13 #      (
14 #        ( cust_svc left outer join part_svc using (svcpart)
15 #        ) left outer join svc_acct using (svcnum)
16 #      ) left outer join svc_domain using(svcnum)
17 #    ) left outer join svc_forward using(svcnum)
18 #  ) using (pkgnum)
19 #) using (custnum)
20 #END
21
22 #my $monsterjoin = <<END;
23 #cust_main left outer join (
24 #  ( cust_pkg left outer join part_pkg using(pkgpart)
25 #  ) left outer join (
26 #    (
27 #      (
28 #        ( cust_svc left outer join part_svc using (svcpart)
29 #        ) left outer join (
30 #          svc_acct left outer join (
31 #            select svcnum, domain, catchall from svc_domain
32 #            ) as svc_acct_domsvc (
33 #              svc_acct_svcnum, svc_acct_domain, svc_acct_catchall
34 #          ) on svc_acct.domsvc = svc_acct_domsvc.svc_acct_svcnum
35 #        ) using (svcnum)
36 #      ) left outer join svc_domain using(svcnum)
37 #    ) left outer join svc_forward using(svcnum)
38 #  ) using (pkgnum)
39 #) using (custnum)
40 #END
41
42 my $limit = '';
43 $limit .= "LIMIT $maxrecords" if $maxrecords;
44
45 my $offset = $cgi->param('offset') || 0;
46 $limit .= " OFFSET $offset" if $offset;
47
48 my $total = 0;
49
50 my(@cust_main, $sortby, $orderby);
51 if ( $cgi->param('browse')
52      || $cgi->param('otaker_on')
53      || $cgi->param('agentnum_on')
54 ) {
55
56   my %search = ();
57   if ( $cgi->param('browse') ) {
58     my $query = $cgi->param('browse');
59     if ( $query eq 'custnum' ) {
60       $sortby=\*custnum_sort;
61       $orderby = "ORDER BY custnum";
62     } elsif ( $query eq 'last' ) {
63       $sortby=\*last_sort;
64       $orderby = "ORDER BY LOWER(last || ' ' || first)";
65     } elsif ( $query eq 'company' ) {
66       $sortby=\*company_sort;
67       $orderby = "ORDER BY LOWER(company || ' ' || last || ' ' || first )";
68     } else {
69       die "unknown browse field $query";
70     }
71   } else {
72     $sortby = \*last_sort; #??
73     $orderby = "ORDER BY LOWER(last || ' ' || first)"; #??
74     if ( $cgi->param('otaker_on') ) {
75       $cgi->param('otaker') =~ /^(\w{1,32})$/ or eidiot "Illegal otaker\n";
76       $search{otaker} = $1;
77     } elsif ( $cgi->param('agentnum_on') ) {
78       $cgi->param('agentnum') =~ /^(\d+)$/ or eidiot "Illegal agentnum\n";
79       $search{agentnum} = $1;
80     } else {
81       die "unknown query...";
82     }
83   }
84
85   my @qual = ();
86
87   my $ncancelled = '';
88
89   if (  $cgi->param('showcancelledcustomers') eq '0' #see if it was set by me
90        || ( $conf->exists('hidecancelledcustomers')
91              && ! $cgi->param('showcancelledcustomers') )
92      ) {
93     #grep { $_->ncancelled_pkgs || ! $_->all_pkgs }
94     push @qual, "
95        ( 0 < ( SELECT COUNT(*) FROM cust_pkg
96                       WHERE cust_pkg.custnum = cust_main.custnum
97                         AND ( cust_pkg.cancel IS NULL
98                               OR cust_pkg.cancel = 0
99                             )
100              )
101          OR 0 = ( SELECT COUNT(*) FROM cust_pkg
102                     WHERE cust_pkg.custnum = cust_main.custnum
103                 )
104        )
105     ";
106    }
107
108   push @qual, FS::cust_main->cancel_sql   if $cgi->param('cancelled');
109   push @qual, FS::cust_main->prospect_sql if $cgi->param('prospect');
110   push @qual, FS::cust_main->active_sql   if $cgi->param('active');
111   push @qual, FS::cust_main->susp_sql     if $cgi->param('suspended');
112
113   #EWWWWWW
114   my $qual = join(' AND ',
115             map { "$_ = ". dbh->quote($search{$_}) } keys %search );
116
117   my $addl_qual = join(' AND ', @qual);
118
119   if ( $addl_qual ) {
120     $qual .= ' AND ' if $qual;
121     $qual .= $addl_qual;
122   }
123     
124   $qual = " WHERE $qual" if $qual;
125   my $statement = "SELECT COUNT(*) FROM cust_main $qual";
126   my $sth = dbh->prepare($statement) or die dbh->errstr." preparing $statement";
127   $sth->execute or die "Error executing \"$statement\": ". $sth->errstr;
128
129   $total = $sth->fetchrow_arrayref->[0];
130
131   if ( $addl_qual ) {
132     if ( %search ) {
133       $addl_qual = " AND $addl_qual";
134     } else {
135       $addl_qual = " WHERE $addl_qual";
136     }
137   }
138
139   @cust_main = qsearch('cust_main', \%search, '',   
140                          "$addl_qual $orderby $limit" );
141
142 #  foreach my $cust_main ( @just_cust_main ) {
143 #
144 #    my @one_cust_main;
145 #    $FS::Record::DEBUG=1;
146 #    ( $cache, @one_cust_main ) = jsearch(
147 #      "$monsterjoin",
148 #      { 'custnum' => $cust_main->custnum },
149 #      '',
150 #      '',
151 #      'cust_main',
152 #      'custnum',
153 #    );
154 #    push @cust_main, @one_cust_main;
155 #  }
156
157 } else {
158   @cust_main=();
159   $sortby = \*last_sort;
160
161   push @cust_main, @{&custnumsearch}
162     if $cgi->param('custnum_on') && $cgi->param('custnum_text');
163   push @cust_main, @{&cardsearch}
164     if $cgi->param('card_on') && $cgi->param('card');
165   push @cust_main, @{&lastsearch}
166     if $cgi->param('last_on') && $cgi->param('last_text');
167   push @cust_main, @{&companysearch}
168     if $cgi->param('company_on') && $cgi->param('company_text');
169   push @cust_main, @{&address2search}
170     if $cgi->param('address2_on') && $cgi->param('address2_text');
171   push @cust_main, @{&phonesearch}
172     if $cgi->param('phone_on') && $cgi->param('phone_text');
173   push @cust_main, @{&referralsearch}
174     if $cgi->param('referral_custnum');
175
176   if ( $cgi->param('company_on') && $cgi->param('company_text') ) {
177     $sortby = \*company_sort;
178     push @cust_main, @{&companysearch};
179   }
180
181   @cust_main = grep { $_->ncancelled_pkgs || ! $_->all_pkgs } @cust_main
182     if ! $cgi->param('cancelled')
183        && (
184          $cgi->param('showcancelledcustomers') eq '0' #see if it was set by me
185          || ( $conf->exists('hidecancelledcustomers')
186                && ! $cgi->param('showcancelledcustomers') )
187        );
188
189   my %saw = ();
190   @cust_main = grep { !$saw{$_->custnum}++ } @cust_main;
191 }
192
193 my %all_pkgs;
194 if ( $conf->exists('hidecancelledpackages' ) ) {
195   %all_pkgs = map { $_->custnum => [ $_->ncancelled_pkgs ] } @cust_main;
196 } else {
197   %all_pkgs = map { $_->custnum => [ $_->all_pkgs ] } @cust_main;
198 }
199 #%all_pkgs = ();
200
201 if ( scalar(@cust_main) == 1 && ! $cgi->param('referral_custnum') ) {
202   if ( $cgi->param('quickpay') eq 'yes' ) {
203     print $cgi->redirect(popurl(2). "edit/cust_pay.cgi?quickpay=yes;custnum=". $cust_main[0]->custnum);
204   } else {
205     print $cgi->redirect(popurl(2). "view/cust_main.cgi?". $cust_main[0]->custnum);
206   }
207   #exit;
208 } elsif ( scalar(@cust_main) == 0 ) {
209 %>
210 <!-- mason kludge -->
211 <%
212   eidiot "No matching customers found!\n";
213 } else { 
214 %>
215 <!-- mason kludge -->
216 <%
217
218   $total ||= scalar(@cust_main);
219   print header("Customer Search Results",menubar(
220     'Main Menu', popurl(2)
221   )), "$total matching customers found ";
222
223   #begin pager
224   my $pager = '';
225   if ( $total != scalar(@cust_main) && $maxrecords ) {
226     unless ( $offset == 0 ) {
227       $cgi->param('offset', $offset - $maxrecords);
228       $pager .= '<A HREF="'. $cgi->self_url.
229                 '"><B><FONT SIZE="+1">Previous</FONT></B></A> ';
230     }
231     my $poff;
232     my $page;
233     for ( $poff = 0; $poff < $total; $poff += $maxrecords ) {
234       $page++;
235       if ( $offset == $poff ) {
236         $pager .= qq!<FONT SIZE="+2">$page</FONT> !;
237       } else {
238         $cgi->param('offset', $poff);
239         $pager .= qq!<A HREF="!. $cgi->self_url. qq!">$page</A> !;
240       }
241     }
242     unless ( $offset + $maxrecords > $total ) {
243       $cgi->param('offset', $offset + $maxrecords);
244       $pager .= '<A HREF="'. $cgi->self_url.
245                 '"><B><FONT SIZE="+1">Next</FONT></B></A> ';
246     }
247   }
248   #end pager
249
250   unless ( $cgi->param('cancelled') ) {
251     if ( $cgi->param('showcancelledcustomers') eq '0' #see if it was set by me
252          || ( $conf->exists('hidecancelledcustomers')
253               && ! $cgi->param('showcancelledcustomers')
254             )
255        ) {
256       $cgi->param('showcancelledcustomers', 1);
257       $cgi->param('offset', 0);
258       print qq!( <a href="!. $cgi->self_url. qq!">show!;
259     } else {
260       $cgi->param('showcancelledcustomers', 0);
261       $cgi->param('offset', 0);
262       print qq!( <a href="!. $cgi->self_url. qq!">hide!;
263     }
264     print ' cancelled customers</a> )';
265   }
266   if ( $cgi->param('referral_custnum') ) {
267     $cgi->param('referral_custnum') =~ /^(\d+)$/
268       or eidiot "Illegal referral_custnum\n";
269     my $referral_custnum = $1;
270     my $cust_main = qsearchs('cust_main', { custnum => $referral_custnum } );
271     print '<FORM METHOD=POST>'.
272           qq!<INPUT TYPE="hidden" NAME="referral_custnum" VALUE="$referral_custnum">!.
273           'referrals of <A HREF="'. popurl(2).
274           "view/cust_main.cgi?$referral_custnum\">$referral_custnum: ".
275           ( $cust_main->company
276             || $cust_main->last. ', '. $cust_main->first ).
277           '</A>';
278     print "\n",<<END;
279       <SCRIPT>
280       function changed(what) {
281         what.form.submit();
282       }
283       </SCRIPT>
284 END
285     print ' <SELECT NAME="referral_depth" SIZE="1" onChange="changed(this)">';
286     my $max = 8; #config file
287     $cgi->param('referral_depth') =~ /^(\d*)$/ 
288       or eidiot "Illegal referral_depth";
289     my $referral_depth = $1;
290
291     foreach my $depth ( 1 .. $max ) {
292       print '<OPTION',
293             ' SELECTED'x($depth == $referral_depth),
294             ">$depth";
295     }
296     print "</SELECT> levels deep".
297           '<NOSCRIPT> <INPUT TYPE="submit" VALUE="change"></NOSCRIPT>'.
298           '</FORM>';
299   }
300
301   print "<BR><BR>". $pager. &table(). <<END;
302       <TR>
303         <TH></TH>
304         <TH>(bill) name</TH>
305         <TH>company</TH>
306 END
307
308 if ( defined dbdef->table('cust_main')->column('ship_last') ) {
309   print <<END;
310       <TH>(service) name</TH>
311       <TH>company</TH>
312 END
313 }
314
315 print <<END;
316         <TH>Packages</TH>
317         <TH COLSPAN=2>Services</TH>
318       </TR>
319 END
320
321   my(%saw,$cust_main);
322   my $p = popurl(2);
323   foreach $cust_main (
324     sort $sortby grep(!$saw{$_->custnum}++, @cust_main)
325   ) {
326     my($custnum,$last,$first,$company)=(
327       $cust_main->custnum,
328       $cust_main->getfield('last'),
329       $cust_main->getfield('first'),
330       $cust_main->company,
331     );
332
333     my(@lol_cust_svc);
334     my($rowspan)=0;#scalar( @{$all_pkgs{$custnum}} );
335     foreach ( @{$all_pkgs{$custnum}} ) {
336       #my(@cust_svc) = qsearch( 'cust_svc', { 'pkgnum' => $_->pkgnum } );
337       my @cust_svc = $_->cust_svc;
338       push @lol_cust_svc, \@cust_svc;
339       $rowspan += scalar(@cust_svc) || 1;
340     }
341
342     #my($rowspan) = scalar(@{$all_pkgs{$custnum}});
343     my $view;
344     if ( defined $cgi->param('quickpay') && $cgi->param('quickpay') eq 'yes' ) {
345       $view = $p. 'edit/cust_pay.cgi?quickpay=yes;custnum='. $custnum;
346     } else {
347       $view = $p. 'view/cust_main.cgi?'. $custnum;
348     }
349     my $pcompany = $company
350       ? qq!<A HREF="$view"><FONT SIZE=-1>$company</FONT></A>!
351       : '<FONT SIZE=-1>&nbsp;</FONT>';
352     print <<END;
353     <TR>
354       <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$custnum</FONT></A></TD>
355       <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$last, $first</FONT></A></TD>
356       <TD ROWSPAN=$rowspan>$pcompany</TD>
357 END
358     if ( defined dbdef->table('cust_main')->column('ship_last') ) {
359       my($ship_last,$ship_first,$ship_company)=(
360         $cust_main->ship_last || $cust_main->getfield('last'),
361         $cust_main->ship_last ? $cust_main->ship_first : $cust_main->first,
362         $cust_main->ship_last ? $cust_main->ship_company : $cust_main->company,
363       );
364       my $pship_company = $ship_company
365         ? qq!<A HREF="$view"><FONT SIZE=-1>$ship_company</FONT></A>!
366         : '<FONT SIZE=-1>&nbsp;</FONT>';
367       print <<END;
368       <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$ship_last, $ship_first</FONT></A></TD>
369       <TD ROWSPAN=$rowspan>$pship_company</A></TD>
370 END
371     }
372
373     my($n1)='';
374     foreach ( @{$all_pkgs{$custnum}} ) {
375       my $pkgnum = $_->pkgnum;
376 #      my $part_pkg = qsearchs( 'part_pkg', { pkgpart => $_->pkgpart } );
377       my $part_pkg = $_->part_pkg;
378
379       my $pkg = $part_pkg->pkg;
380       my $comment = $part_pkg->comment;
381       my $pkgview = "${p}view/cust_main.cgi?$custnum#cust_pkg$pkgnum";
382       my @cust_svc = @{shift @lol_cust_svc};
383       #my(@cust_svc) = qsearch( 'cust_svc', { 'pkgnum' => $_->pkgnum } );
384       my $rowspan = scalar(@cust_svc) || 1;
385
386       print $n1, qq!<TD ROWSPAN=$rowspan><A HREF="$pkgview"><FONT SIZE=-1>$pkg - $comment</FONT></A></TD>!;
387       my($n2)='';
388       foreach my $cust_svc ( @cust_svc ) {
389          my($label, $value, $svcdb) = $cust_svc->label;
390          my($svcnum) = $cust_svc->svcnum;
391          my($sview) = $p.'view';
392          print $n2,qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$label</FONT></A></TD>!,
393                qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$value</FONT></A></TD>!;
394          $n2="</TR><TR>";
395       }
396       #print qq!</TR><TR>\n!;
397       $n1="</TR><TR>";
398     }
399     print "</TR>";
400   }
401  
402   print "</TABLE>$pager</BODY></HTML>";
403
404 }
405
406 #undef $cache; #does this help?
407
408 #
409
410 sub last_sort {
411   lc($a->getfield('last')) cmp lc($b->getfield('last'))
412   || lc($a->first) cmp lc($b->first);
413 }
414
415 sub company_sort {
416   return -1 if $a->company && ! $b->company;
417   return 1 if ! $a->company && $b->company;
418   lc($a->company) cmp lc($b->company)
419   || lc($a->getfield('last')) cmp lc($b->getfield('last'))
420   || lc($a->first) cmp lc($b->first);;
421 }
422
423 sub custnum_sort {
424   $a->getfield('custnum') <=> $b->getfield('custnum');
425 }
426
427 sub custnumsearch {
428
429   my $custnum = $cgi->param('custnum_text');
430   $custnum =~ s/\D//g;
431   $custnum =~ /^(\d{1,23})$/ or eidiot "Illegal customer number\n";
432   $custnum = $1;
433   
434   [ qsearchs('cust_main', { 'custnum' => $custnum } ) ];
435 }
436
437 sub cardsearch {
438
439   my($card)=$cgi->param('card');
440   $card =~ s/\D//g;
441   $card =~ /^(\d{13,16})$/ or eidiot "Illegal card number\n";
442   my($payinfo)=$1;
443
444   [ qsearch('cust_main',{'payinfo'=>$payinfo, 'payby'=>'CARD'}),
445     qsearch('cust_main',{'payinfo'=>$payinfo, 'payby'=>'DCRD'})
446   ];
447 }
448
449 sub referralsearch {
450   $cgi->param('referral_custnum') =~ /^(\d+)$/
451     or eidiot "Illegal referral_custnum";
452   my $cust_main = qsearchs('cust_main', { 'custnum' => $1 } )
453     or eidiot "Customer $1 not found";
454   my $depth;
455   if ( $cgi->param('referral_depth') ) {
456     $cgi->param('referral_depth') =~ /^(\d+)$/
457       or eidiot "Illegal referral_depth";
458     $depth = $1;
459   } else {
460     $depth = 1;
461   }
462   [ $cust_main->referral_cust_main($depth) ];
463 }
464
465 sub lastsearch {
466   my(%last_type);
467   my @cust_main;
468   foreach ( $cgi->param('last_type') ) {
469     $last_type{$_}++;
470   }
471
472   $cgi->param('last_text') =~ /^([\w \,\.\-\']*)$/
473     or eidiot "Illegal last name";
474   my($last)=$1;
475
476   if ( $last_type{'Exact'} || $last_type{'Fuzzy'} ) {
477     push @cust_main, qsearch( 'cust_main',
478                               { 'last' => { 'op'    => 'ILIKE',
479                                             'value' => $last    } } );
480
481     push @cust_main, qsearch( 'cust_main',
482                               { 'ship_last' => { 'op'    => 'ILIKE',
483                                                  'value' => $last    } } )
484       if defined dbdef->table('cust_main')->column('ship_last');
485   }
486
487   if ( $last_type{'Substring'} || $last_type{'All'} ) {
488
489     push @cust_main, qsearch( 'cust_main',
490                               { 'last' => { 'op'    => 'ILIKE',
491                                             'value' => "%$last%" } } );
492
493     push @cust_main, qsearch( 'cust_main',
494                               { 'ship_last' => { 'op'    => 'ILIKE',
495                                                  'value' => "%$last%" } } )
496       if defined dbdef->table('cust_main')->column('ship_last');
497
498   }
499
500   if ( $last_type{'Fuzzy'} || $last_type{'All'} ) {
501
502     &FS::cust_main::check_and_rebuild_fuzzyfiles;
503     my $all_last = &FS::cust_main::all_last;
504
505     my %last;
506     if ( $last_type{'Fuzzy'} || $last_type{'All'} ) { 
507       foreach ( amatch($last, [ qw(i) ], @$all_last) ) {
508         $last{$_}++; 
509       }
510     }
511
512     #if ($last_type{'Sound-alike'}) {
513     #}
514
515     foreach ( keys %last ) {
516       push @cust_main, qsearch('cust_main',{'last'=>$_});
517       push @cust_main, qsearch('cust_main',{'ship_last'=>$_})
518         if defined dbdef->table('cust_main')->column('ship_last');
519     }
520
521   }
522
523   \@cust_main;
524 }
525
526 sub companysearch {
527
528   my(%company_type);
529   my @cust_main;
530   foreach ( $cgi->param('company_type') ) {
531     $company_type{$_}++ 
532   };
533
534   $cgi->param('company_text') =~
535     /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=]*)$/
536       or eidiot "Illegal company";
537   my $company = $1;
538
539   if ( $company_type{'Exact'} || $company_type{'Fuzzy'} ) {
540     push @cust_main, qsearch( 'cust_main',
541                               { 'company' => { 'op'    => 'ILIKE',
542                                                'value' => $company } } );
543
544     push @cust_main, qsearch( 'cust_main',
545                               { 'ship_company' => { 'op'    => 'ILIKE',
546                                                     'value' => $company } } )
547       if defined dbdef->table('cust_main')->column('ship_last');
548   }
549
550   if ( $company_type{'Substring'} || $company_type{'All'} ) {
551
552     push @cust_main, qsearch( 'cust_main',
553                               { 'company' => { 'op'    => 'ILIKE',
554                                                'value' => "%$company%" } } );
555
556     push @cust_main, qsearch( 'cust_main',
557                               { 'ship_company' => { 'op'    => 'ILIKE',
558                                                     'value' => "%$company%" } })
559       if defined dbdef->table('cust_main')->column('ship_last');
560
561   }
562
563   if ( $company_type{'Fuzzy'} || $company_type{'All'} ) {
564
565     &FS::cust_main::check_and_rebuild_fuzzyfiles;
566     my $all_company = &FS::cust_main::all_company;
567
568     my %company;
569     if ( $company_type{'Fuzzy'} || $company_type{'All'} ) { 
570       foreach ( amatch($company, [ qw(i) ], @$all_company ) ) {
571         $company{$_}++;
572       }
573     }
574
575     #if ($company_type{'Sound-alike'}) {
576     #}
577
578     foreach ( keys %company ) {
579       push @cust_main, qsearch('cust_main',{'company'=>$_});
580       push @cust_main, qsearch('cust_main',{'ship_company'=>$_})
581         if defined dbdef->table('cust_main')->column('ship_last');
582     }
583
584   }
585
586   \@cust_main;
587 }
588
589 sub address2search {
590   my @cust_main;
591
592   $cgi->param('address2_text') =~
593     /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=]*)$/
594       or eidiot "Illegal address2";
595   my $address2 = $1;
596
597   push @cust_main, qsearch( 'cust_main',
598                             { 'address2' => { 'op'    => 'ILIKE',
599                                               'value' => $address2 } } );
600   push @cust_main, qsearch( 'cust_main',
601                             { 'address2' => { 'op'    => 'ILIKE',
602                                               'value' => $address2 } } )
603     if defined dbdef->table('cust_main')->column('ship_last');
604
605   \@cust_main;
606 }
607
608 sub phonesearch {
609   my @cust_main;
610
611   my $phone = $cgi->param('phone_text');
612
613   #(no longer really) false laziness with Record::ut_phonen
614   #only works with US/CA numbers...
615   $phone =~ s/\D//g;
616   if ( $phone =~ /^(\d{3})(\d{3})(\d{4})(\d*)$/ ) {
617     $phone = "$1-$2-$3";
618     $phone .= " x$4" if $4;
619   } elsif ( $phone =~ /^(\d{3})(\d{4})$/ ) {
620     $phone = "$1-$2";
621   } elsif ( $phone =~ /^(\d{3,4})$/ ) {
622     $phone = $1;
623   } else {
624     eidiot gettext('illegal_phone'). ": $phone";
625   }
626
627   my @fields = qw(daytime night fax);
628   push @fields, qw(ship_daytime ship_night ship_fax)
629     if defined dbdef->table('cust_main')->column('ship_last');
630
631   for my $field ( @fields ) {
632     push @cust_main, qsearch ( 'cust_main', 
633                                { $field => { 'op'    => 'LIKE',
634                                              'value' => "%$phone%" } } );
635   }
636
637   \@cust_main;
638 }
639
640 %>