+ if ( $params->{'address'} ) {
+ # allow this to be an arrayref
+ my @values = ($params->{'address'});
+ @values = @{$values[0]} if ref($values[0]);
+ my @orwhere;
+ foreach (grep /\S/, @values) {
+ my $address = dbh->quote('%'. lc($_). '%');
+ push @orwhere,
+ "LOWER(cust_location.address1) LIKE $address",
+ "LOWER(cust_location.address2) LIKE $address";
+ }
+ if (@orwhere) {
+ push @where, "EXISTS(
+ SELECT 1 FROM cust_location
+ WHERE cust_location.custnum = cust_main.custnum
+ AND (".join(' OR ',@orwhere).")
+ $current
+ )";
+ }
+ }
+
+ ##
+ # city
+ ##
+ if ( $params->{'city'} =~ /\S/ ) {
+ my $city = dbh->quote($params->{'city'});
+ push @where, "EXISTS(
+ SELECT 1 FROM cust_location
+ WHERE cust_location.custnum = cust_main.custnum
+ AND cust_location.city = $city
+ $current
+ )";
+ }
+
+ ##
+ # county
+ ##
+ if ( $params->{'county'} =~ /\S/ ) {
+ my $county = dbh->quote($params->{'county'});
+ push @where, "EXISTS(
+ SELECT 1 FROM cust_location
+ WHERE cust_location.custnum = cust_main.custnum
+ AND cust_location.county = $county
+ $current
+ )";
+ }
+
+ ##
+ # state
+ ##
+ if ( $params->{'state'} =~ /\S/ ) {
+ my $state = dbh->quote($params->{'state'});
+ push @where, "EXISTS(
+ SELECT 1 FROM cust_location
+ WHERE cust_location.custnum = cust_main.custnum
+ AND cust_location.state = $state
+ $current
+ )";
+ }
+
+ ##
+ # zipcode
+ ##
+ if ( $params->{'zip'} =~ /\S/ ) {
+ my $zip = dbh->quote($params->{'zip'} . '%');
+ push @where, "EXISTS(
+ SELECT 1 FROM cust_location
+ WHERE cust_location.custnum = cust_main.custnum
+ AND cust_location.zip LIKE $zip
+ $current
+ )";
+ }
+
+ ##
+ # country
+ ##
+ if ( $params->{'country'} =~ /^(\w\w)$/ ) {
+ my $country = uc($1);
+ push @where, "EXISTS(
+ SELECT 1 FROM cust_location
+ WHERE cust_location.custnum = cust_main.custnum
+ AND cust_location.country = '$country'
+ $current
+ )";
+ }
+
+ ###
+ # refnum
+ ###
+ if ( $params->{'refnum'} ) {
+
+ my @refnum = ref( $params->{'refnum'} )
+ ? @{ $params->{'refnum'} }
+ : ( $params->{'refnum'} );
+
+ @refnum = grep /^(\d*)$/, @refnum;
+
+ push @where, '( '. join(' OR ', map "cust_main.refnum = $_", @refnum ). ' )'
+ if @refnum;
+