- foreach my $prefix ( '', 'ship_' ) {
- push @cust_main, qsearch( {
- 'table' => 'cust_main',
- 'hashref' => { %options, },
- 'extra_sql' =>
- ( keys(%options) ? ' AND ' : ' WHERE ' ).
- " LOWER(SUBSTRING(${prefix}address1 FROM 1 FOR $len)) = '$num' ".
- " AND $agentnums_sql",
- } );
- }
+ # probably the Right Thing: return customers that have any associated
+ # locations matching the string, not just bill/ship location
+ push @cust_main, qsearch( {
+ 'table' => 'cust_main',
+ 'addl_from' => ' JOIN cust_location USING (custnum) ',
+ 'hashref' => { %options, },
+ 'extra_sql' =>
+ ( keys(%options) ? ' AND ' : ' WHERE ' ).
+ " LOWER(SUBSTRING(cust_location.address1 FROM 1 FOR $len)) = '$num' ".
+ " AND $agentnums_sql",
+ } );