search by state (and county, country), RT#30312
[freeside.git] / FS / FS / cust_main / Search.pm
index 046e959..0c00477 100644 (file)
@@ -727,6 +727,30 @@ sub search {
   }
 
   ##
+  # 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
+    )";
+  }
+
+  ##
+  # 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
+    )";
+  }
+
+  ##
   # zipcode
   ##
   if ( $params->{'zip'} =~ /\S/ ) {
@@ -738,6 +762,18 @@ sub search {
     )";
   }
 
+  ##
+  # 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'
+    )";
+  }
+
   ###
   # refnum
   ###