search by state (and county, country), RT#30312
authorIvan Kohler <ivan@freeside.biz>
Thu, 31 Jul 2014 20:17:55 +0000 (13:17 -0700)
committerIvan Kohler <ivan@freeside.biz>
Thu, 31 Jul 2014 20:17:55 +0000 (13:17 -0700)
FS/FS/Misc.pm
FS/FS/cust_main/Search.pm
httemplate/elements/select-country.html
httemplate/search/cust_main.html
httemplate/search/report_cust_main.html

index 380f895..f597058 100644 (file)
@@ -548,7 +548,7 @@ sub states_hash {
 
   #it could throw a fatal "Invalid country code" error (for example "AX")
   my $subcountry = eval { new Locale::SubCountry($country) }
-    or return ( '', '(n/a)' );
+    or return (); # ( '', '(n/a)' );
 
   #"i see your schwartz is as big as mine!"
   map  { ( $_->[0] => $_->[1] ) }
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
   ###
index e5656dc..724afe3 100644 (file)
@@ -2,7 +2,7 @@
 
 Example:
 
-  include( '/elements/select-country.html',
+  <& /elements/select-country.html,
     #recommended
     country    => $current_country,
 
@@ -14,9 +14,15 @@ Example:
     empty_label   => 'all', #label for empty option
     disable_stateupdate => 0, #bool - disabled update of the select-state.html
     style         => [ 'attribute:value', 'another:value' ],
-  );
+
+    state_disable_empty => 1, #defaults to 1, disable the state empty option
+    state_empty_label   => 'all', #label for state empty option
+  &>
 
 </%doc>
+% #maybe this makes more sense in select-state.html?
+% # (county update is in select-county... and we wouldn't have to pass "state_"
+% #  options)
 % unless ( $opt{'disable_stateupdate'} ) {
 
   <% include('/elements/xmlhttp.html',
@@ -45,10 +51,14 @@ Example:
   
         // add the new states
         var statesArray = eval('(' + states + ')' );
+%       unless ( $opt{'disable_empty'} ) {
+          statesArray.unshift('', '');
+%       }
+
         for ( var s = 0; s < statesArray.length; s=s+2 ) {
             var stateLabel = statesArray[s+1];
             if ( stateLabel == "" )
-                stateLabel = '(n/a)';
+                stateLabel = <% $opt{state_empty_label} || '(n/a)' |js_string %>;
             opt(what.form.<% $pre %>state, statesArray[s], stateLabel);
         }
   
index c0292aa..a307463 100755 (executable)
@@ -41,7 +41,8 @@ my %search_hash = ();
 
 #scalars
 my @scalars = qw (
-  agentnum salesnum status address zip paydate_year paydate_month invoice_terms
+  agentnum salesnum status address county state zip country
+  paydate_year paydate_month invoice_terms
   no_censustract with_geocode with_email POST no_POST
   custbatch usernum
   cancelled_pkgs
index 4309fbb..16a8122 100755 (executable)
       <TD ALIGN="right" VALIGN="center"><% mt('Address') |h %></TD>
       <TD><INPUT TYPE="text" NAME="address" SIZE=54></TD>
     </TR>
+
+    <TR>
+      <TD ALIGN="right" VALIGN="center"><% mt('County') |h %></TD>
+      <TD>
+        <& /elements/select-county.html,
+             disable_empty => 0,
+             empty_label   => '(all)',
+        &>
+      </TD>
+    </TR>
+    
+
+    <TR>
+      <TD ALIGN="right" VALIGN="center"><% mt('State') |h %></TD>
+      <TD>
+        <& /elements/select-state.html,
+             disable_empty => 0,
+             empty_label   => '(all)',
+        &>
+      </TD>
+    </TR>
     
     <TR>
       <TD ALIGN="right" VALIGN="center"><% mt('Zip') |h %></TD>
     </TR>
 
     <TR>
+      <TD ALIGN="right" VALIGN="center"><% mt('Country') |h %></TD>
+      <TD>
+        <& /elements/select-country.html,
+             disable_empty       => 0,
+             state_disable_empty => 0,
+             state_empty_label   => '(all)',
+        &>
+      </TD>
+    </TR>
+
+    <TR>
         <TD ALIGN="right" VALIGN="center"><% mt('Signup date') |h %></TD>
         <TD>
         <TABLE>