fix a weird oops with service address editing UI that would leave
[freeside.git] / httemplate / edit / cust_main.cgi
index a0472bd..89a946b 100755 (executable)
@@ -1,3 +1,4 @@
+<!-- mason kludge -->
 <%
 
   #for misplaced logic below
@@ -169,6 +170,7 @@ print <<END;
 <TR><TH ALIGN="right">${r}City</TH><TD><INPUT TYPE="text" NAME="city" VALUE="$city"></TD><TH ALIGN="right">${r}State/Country</TH><TD><SELECT NAME="state" SIZE="1">
 END
 
+#false laziness with ship_state
 my $countrydefault = $conf->config('countrydefault') || 'US';
 $cust_main->country( $countrydefault ) unless $cust_main->country;
 $cust_main->state( $conf->config('statedefault') || 'CA' )
@@ -230,7 +232,8 @@ END
   unless ( $cust_main->ship_last ) {
     print ' CHECKED';
     foreach (
-      qw( last first company address1 address2 city state zip daytime night fax)
+      qw( last first company address1 address2 city county state zip country
+          daytime night fax )
     ) {
       $cust_main->set("ship_$_", $cust_main->get($_) );
     }
@@ -264,11 +267,17 @@ END
   <TR><TH ALIGN="right">${r}City</TH><TD><INPUT TYPE="text" NAME="ship_city" VALUE="$ship_city" onChange="changed(this)"></TD><TH ALIGN="right">${r}State/Country</TH><TD><SELECT NAME="ship_state" SIZE="1" onChange="changed(this)">
 END
 
+  #false laziness with regular state
   $cust_main->ship_country( $conf->config('countrydefault') || 'US' )
     unless $cust_main->ship_country;
   $cust_main->ship_state( $conf->config('statedefault') || 'CA' )
     unless $cust_main->ship_state || $cust_main->ship_country ne 'US';
-  foreach ( qsearch('cust_main_county',{}) ) {
+  foreach ( sort {
+       ( $b->country eq $countrydefault ) <=> ( $a->country eq $countrydefault )
+    or $a->country                        cmp $b->country
+    or $a->state                          cmp $b->state
+    or $a->county                         cmp $b->county
+  } qsearch('cust_main_county',{}) ) {
     print "<OPTION";
     print " SELECTED" if ( $cust_main->ship_state eq $_->state
                            && $cust_main->ship_county eq $_->county