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=d13dae1c37c36c27f1ac9fd134c5d8b3a4fb9754 RT#29285: State field not needed for New Zealand --- diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 17030d20c..b384d85af 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -3383,14 +3383,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', @@ -4525,6 +4517,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 0bdc99539..24ca85821 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -2009,7 +2009,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, '', '', @@ -2639,7 +2639,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 72af03ea4..329e5f7eb 100644 --- a/FS/FS/UI/Web/small_custview.pm +++ b/FS/FS/UI/Web/small_custview.pm @@ -129,7 +129,8 @@ 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. '
'; $html .= $cust_main->country. '
' if $cust_main->country && $cust_main->country ne $countrydefault; @@ -162,7 +163,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 a863e5df7..9ab94f207 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 @@ -149,9 +149,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); @@ -207,6 +218,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); } @@ -271,6 +287,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->$_ ) { @@ -330,7 +355,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') @@ -392,6 +419,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 @@ -731,25 +782,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 13b2eefe5..8f31e4dda 100644 --- a/FS/FS/cust_pay_batch.pm +++ b/FS/FS/cust_pay_batch.pm @@ -129,6 +129,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 @@ -137,7 +139,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/basics.html b/httemplate/edit/cust_main/basics.html index e16aafafc..32a03bbe6 100644 --- a/httemplate/edit/cust_main/basics.html +++ b/httemplate/edit/cust_main/basics.html @@ -46,7 +46,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' ]; @@ -307,7 +307,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 90f20265a..b5f0a963c 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 ) %> @@ -291,7 +290,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 ff7183b26..1a01daa6f 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 diff --git a/httemplate/view/cust_main/contacts.html b/httemplate/view/cust_main/contacts.html index 22a7b9584..e3d5d63cb 100644 --- a/httemplate/view/cust_main/contacts.html +++ b/httemplate/view/cust_main/contacts.html @@ -100,7 +100,7 @@ % if ( $location->county ) { (<% $location->county |h %> county)\ % } -,<% state_label( $location->state, $location->country ) |h %> +<% ($location->city || $location->county) ? ', ' : ''%><% state_label( $location->state, $location->country ) |h %> <% $location->zip %>