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