From: Jonathan Prykop Date: Tue, 30 Jun 2015 08:24:08 +0000 (-0500) Subject: RT##29285: State field not needed for New Zealand X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=622c72770c971ae44d37dfb59a0f25972051a25a RT##29285: State field not needed for New Zealand --- diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index fa612c065..4c6b1e485 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -3397,14 +3397,6 @@ and customer address. Include units.', }, { - 'key' => 'city_not_required', - 'section' => 'required', - 'description' => 'Turn off requirement for a City to be entered for billing & shipping addresses', - 'type' => 'checkbox', - 'per_agent' => 1, - }, - - { 'key' => 'echeck-void', 'section' => 'deprecated', 'description' => 'DEPRECATED, now controlled by ACLs. Used to enable local-only voiding of echeck payments in addition to refunds against the payment gateway', @@ -4561,6 +4553,13 @@ and customer address. Include units.', }, { + 'key' => 'cust_main-no_city_in_address', + 'section' => 'UI', + 'description' => 'Turn off City for billing & shipping addresses', + 'type' => 'checkbox', + }, + + { 'key' => 'census_year', 'section' => 'UI', 'description' => 'The year to use in census tract lookups. NOTE: you need to select 2012 or 2013 for Year 2010 Census tract codes. A selection of 2011 provides Year 2000 Census tract codes. Use the freeside-censustract-update tool if exisitng customers need to be changed.', diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index fc6d301f0..40c61bbaa 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1420,7 +1420,7 @@ sub tables_hashref { 'locationname', 'varchar', 'NULL', $char_d, '', '', 'address1', 'varchar', '', $char_d, '', '', 'address2', 'varchar', 'NULL', $char_d, '', '', - 'city', 'varchar', '', $char_d, '', '', + 'city', 'varchar', 'NULL', $char_d, '', '', 'county', 'varchar', 'NULL', $char_d, '', '', 'state', 'varchar', 'NULL', $char_d, '', '', 'zip', 'varchar', 'NULL', 10, '', '', @@ -1868,7 +1868,7 @@ sub tables_hashref { 'first', 'varchar', '', $char_d, '', '', 'address1', 'varchar', '', $char_d, '', '', 'address2', 'varchar', 'NULL', $char_d, '', '', - 'city', 'varchar', '', $char_d, '', '', + 'city', 'varchar', 'NULL', $char_d, '', '', 'state', 'varchar', 'NULL', $char_d, '', '', 'zip', 'varchar', 'NULL', 10, '', '', 'country', 'char', '', 2, '', '', diff --git a/FS/FS/UI/Web/small_custview.pm b/FS/FS/UI/Web/small_custview.pm index b98bca072..1e9ddb172 100644 --- a/FS/FS/UI/Web/small_custview.pm +++ b/FS/FS/UI/Web/small_custview.pm @@ -127,7 +127,9 @@ sub small_custview { $html .= encode_entities($cust_main->address1). '
'; $html .= encode_entities($cust_main->address2). '
' if $cust_main->address2; - $html .= encode_entities($cust_main->city). ', '. $cust_main->state. ' '. + $html .= encode_entities($cust_main->city) . ', ' if $cust_main->city; + $html .= $cust_main->state. ' '. + $cust_main->zip. '
'; $cust_main->zip. '
'; $html .= $cust_main->country. '
' if $cust_main->country && $cust_main->country ne $countrydefault; @@ -156,7 +158,7 @@ sub small_custview { $cust_main->ship_company, $ship->address1, $ship->address2, - ($ship->city . ', ' . $ship->state . ' ' . $ship->zip), + (($ship->city ? $ship->city . ', ' : '') . $ship->state . ' ' . $ship->zip), ($ship->country eq $countrydefault ? '' : $ship->country ), ); diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm index ad6d706bb..4f0bd9bbe 100644 --- a/FS/FS/cust_location.pm +++ b/FS/FS/cust_location.pm @@ -68,7 +68,7 @@ Address line two (optional) =item city -City +City (optional only if cust_main-no_city_in_address config is set) =item county @@ -144,9 +144,20 @@ sub find_or_insert { warn "find_or_insert:\n".Dumper($self) if $DEBUG; - my @essential = (qw(custnum address1 address2 city county state zip country + my @essential = (qw(custnum address1 address2 county state zip country location_number location_type location_kind disabled)); + # Just in case this conf was accidentally/temporarily set, + # we'll never overwrite existing city; see city method + if ($conf->exists('cust_main-no_city_in_address')) { + warn "Warning: find_or_insert specified city when cust_main-no_city_in_address was configured" + if $self->get('city'); + $self->set('city',''); # won't end up in %nonempty, hence old value is preserved + } else { + # otherwise, of course, city is essential + push(@essential,'city') + } + # I don't think this is necessary #if ( !$self->coord_auto and $self->latitude and $self->longitude ) { # push @essential, qw(latitude longitude); @@ -202,6 +213,11 @@ otherwise returns false. sub insert { my $self = shift; + # Ideally, this should never happen, + # but throw a warning and save the value anyway, to avoid data loss + warn "Warning: inserting city when cust_main-no_city_in_address is configured" + if $conf->exists('cust_main-no_city_in_address') && $self->get('city'); + if ( $self->censustract ) { $self->set('censusyear' => $conf->config('census_year') || 2012); } @@ -266,6 +282,15 @@ sub replace { my $self = shift; my $old = shift; $old ||= $self->replace_old; + + # Just in case this conf was accidentally/temporarily set, + # we'll never overwrite existing city; see city method + if ($conf->exists('cust_main-no_city_in_address')) { + warn "Warning: replace attempted to change city when cust_main-no_city_in_address was configured" + if $self->get('city') && ($old->get('city') != $self->get('city')); + $self->set('city',$old->get('city')); + } + # the following fields are immutable foreach (qw(address1 address2 city state zip country)) { if ( $self->$_ ne $old->$_ ) { @@ -325,7 +350,9 @@ sub check { || $self->ut_textn('locationname') || $self->ut_text('address1') || $self->ut_textn('address2') - || $self->ut_text('city') + || ($conf->exists('cust_main-no_city_in_address') + ? $self->ut_textn('city') + : $self->ut_text('city')) || $self->ut_textn('county') || $self->ut_textn('state') || $self->ut_country('country') @@ -386,6 +413,30 @@ sub check { $self->SUPER::check; } +=item city + +When the I config is set, the +city method will return a blank string no matter the previously +set value of the field. You can still use the get method to +access the contents of the field directly. + +Just in case this config was accidentally/temporarily set, +we'll never overwrite existing city while the config is active. +L will throw a warning if passed any true value for city, +ignore the city field when finding, and preserve the existing value. +L will only throw a warning if passed a true value that is +different than the existing value of city, and will preserve the existing value. +L will throw a warning but still insert a true city value, +to avoid unnecessary data loss. + +=cut + +sub city { + my $self = shift; + return '' if $conf->exists('cust_main-no_city_in_address'); + return $self->get('city'); +} + =item country_full Returns this locations's full country name @@ -735,25 +786,29 @@ names in order. =cut +### Is this actually used for anything anymore? Grep doesn't show anything... sub in_county_sql { # replaces FS::cust_pkg::location_sql my ($class, %opt) = @_; my $ornull = $opt{ornull} ? ' OR ? IS NULL' : ''; my $x = $ornull ? 3 : 2; my @fields = (('district') x 3, - ('city') x 3, ('county') x $x, ('state') x $x, 'country'); + unless ($conf->exists('cust_main-no_city_in_address')) { + push( @fields, (('city') x 3) ); + } + my $text = (driver_name =~ /^mysql/i) ? 'char' : 'text'; my @where = ( "cust_location.district = ? OR ? = '' OR CAST(? AS $text) IS NULL", - "cust_location.city = ? OR ? = '' OR CAST(? AS $text) IS NULL", "cust_location.county = ? OR (? = '' AND cust_location.county IS NULL) $ornull", "cust_location.state = ? OR (? = '' AND cust_location.state IS NULL ) $ornull", - "cust_location.country = ?" + "cust_location.country = ?", + "cust_location.city = ? OR ? = '' OR CAST(? AS $text) IS NULL" ); my $sql = join(' AND ', map "($_)\n", @where); if ( $opt{param} ) { diff --git a/FS/FS/cust_pay_batch.pm b/FS/FS/cust_pay_batch.pm index 2ab76d5b5..d28085cbd 100644 --- a/FS/FS/cust_pay_batch.pm +++ b/FS/FS/cust_pay_batch.pm @@ -130,6 +130,8 @@ and replace methods. sub check { my $self = shift; + my $conf = new FS::Conf; + my $error = $self->ut_numbern('paybatchnum') || $self->ut_numbern('trancode') #deprecated @@ -138,7 +140,9 @@ sub check { || $self->ut_number('custnum') || $self->ut_text('address1') || $self->ut_textn('address2') - || $self->ut_text('city') + || ($conf->exists('cust_main-no_city_in_address') + ? $self->ut_textn('city') + : $self->ut_text('city')) || $self->ut_textn('state') ; diff --git a/httemplate/edit/cust_main/top_misc.html b/httemplate/edit/cust_main/top_misc.html index 8f8a96a0c..c19f347c3 100644 --- a/httemplate/edit/cust_main/top_misc.html +++ b/httemplate/edit/cust_main/top_misc.html @@ -40,7 +40,7 @@ var ship_locked_agents = <% encode_json(\%ship_locked_agents) %>; var ship_fields = [ - 'locationname', 'address1', 'city', 'state', 'zip', 'country', + 'locationname', 'address1',<% $conf->exists('cust_main-no_city_in_address') ? '' : q( 'city',) %> 'state', 'zip', 'country', 'latitude', 'longitude', 'district' ]; @@ -276,7 +276,10 @@ foreach (qsearch('agent',{})) { my $agent_ship_location = $cust_main->ship_location; $ship_locked_agents{$agentnum} = +{ map { $_ => $agent_ship_location->$_ } - qw(locationname address1 city state zip country latitude longitude district) + ( + qw(locationname address1 state zip country latitude longitude district), + ($conf->exists('cust_main-no_city_in_address') ? () : 'city') + ) }; } diff --git a/httemplate/elements/city.html b/httemplate/elements/city.html index 5f4d4e09e..4e9a60940 100644 --- a/httemplate/elements/city.html +++ b/httemplate/elements/city.html @@ -159,6 +159,11 @@ my $disable_select = 1 if $conf->config('tax_district_method'); $opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'}); +if ($conf->exists('cust_main-no_city_in_address')) { + $opt{'disable_text'} = 1; + $disable_select = 1; +} + my $text_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : []; my $select_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : []; diff --git a/httemplate/elements/location.html b/httemplate/elements/location.html index 357a91db7..b50509aea 100644 --- a/httemplate/elements/location.html +++ b/httemplate/elements/location.html @@ -169,15 +169,14 @@ Example: -% if ($conf->exists('city_not_required')) { - -%} else { - <<%$th%> ALIGN="right"><%$r%><% mt('City') |h %>> + <<%$th%> ALIGN="right"> +% unless ($conf->exists('cust_main-no_city_in_address')) { + <% $r %><% mt('City') |h %> +% } + > <% include('/elements/city.html', %select_hash, 'text_style' => \@style ) %> - <<%$th%> ALIGN="right" WIDTH="1" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County> <% include('/elements/select-county.html', %select_hash ) %> -% } <<%$th%> ALIGN="right" WIDTH="1"><%$r%><% mt('State') |h %>> <% include('/elements/select-state.html', %select_hash ) %> @@ -290,7 +289,7 @@ Example: var clear_coords_on_change = [ '<%$pre%>address1', '<%$pre%>address2', - '<%$pre%>city', + <% $conf->exists('cust_main-no_city_in_address') ? '' : qq('${pre}city',) %> '<%$pre%>state', '<%$pre%>zip', '<%$pre%>country' diff --git a/httemplate/elements/standardize_locations.js b/httemplate/elements/standardize_locations.js index f114e341c..56b2be990 100644 --- a/httemplate/elements/standardize_locations.js +++ b/httemplate/elements/standardize_locations.js @@ -13,7 +13,7 @@ function form_address_info() { % } % for my $pre (@prefixes) { % # normal case -% for my $field (qw(address1 address2 city state zip country)) { +% for my $field (qw(address1 address2 state zip country), ($conf->exists('cust_main-no_city_in_address') ? () : 'city')) { returnobj['<% $pre %><% $field %>'] = cf.elements['<% $pre %><% $field %>'].value; % } #for $field % if ( $withcensus ) { @@ -145,7 +145,7 @@ function replace_address() { var clean = newaddr['<% $pre %>addr_clean'] == 'Y'; var error = newaddr['<% $pre %>error']; if ( clean ) { -% foreach my $field (qw(address1 address2 city state zip addr_clean )) { +% foreach my $field (qw(address1 address2 state zip addr_clean ),($conf->exists('cust_main-no_city_in_address') ? () : 'city')) { cf.elements['<% $pre %><% $field %>'].value = newaddr['<% $pre %><% $field %>']; % } #foreach $field