From 11a4787e386291574aca2357421b586e365252d9 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Fri, 4 Dec 2015 14:37:24 -0800 Subject: [PATCH] add northern cyprus, RT#39335 --- FS/FS/Misc.pm | 24 ++++++++++++++++ FS/FS/Template_Mixin.pm | 3 +- FS/FS/cust_location.pm | 8 ++---- FS/FS/cust_main.pm | 17 ++--------- FS/FS/geocode_Mixin.pm | 46 ++++++++++++++++++++---------- bin/enable-kktc | 21 ++++++++++++++ httemplate/browse/cust_main_county.cgi | 2 +- httemplate/edit/bulk-cust_main_county.html | 2 +- httemplate/elements/select-country.html | 4 +-- httemplate/view/cust_main/contacts.html | 4 +-- 10 files changed, 87 insertions(+), 44 deletions(-) create mode 100755 bin/enable-kktc diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm index 18cb275bf..9a4318086 100644 --- a/FS/FS/Misc.pm +++ b/FS/FS/Misc.pm @@ -510,6 +510,9 @@ use Locale::SubCountry; sub states_hash { my($country) = @_; + #a hash? not expecting an explosion of business from unrecognized countries.. + return states_hash_nosubcountry($country) if $country eq 'XC'; + my @states = # sort map { s/[\n\r]//g; $_; } @@ -532,6 +535,27 @@ sub states_hash { @states; } +sub states_hash_nosubcountry { + my($country) = @_; + + my @states = +# sort + map { s/[\n\r]//g; $_; } + map { $_->state; } + qsearch({ + 'select' => 'state', + 'table' => 'cust_main_county', + 'hashref' => { 'country' => $country }, + 'extra_sql' => 'GROUP BY state', + }); + + #"i see your schwartz is as big as mine!" + map { ( $_->[0] => $_->[1] ) } + sort { $a->[1] cmp $b->[1] } + map { [ $_ => $_ ] } + @states; +} + =item counties STATE COUNTRY Returns a list of counties for this state and country. diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm index e889142a5..65a848451 100644 --- a/FS/FS/Template_Mixin.pm +++ b/FS/FS/Template_Mixin.pm @@ -13,7 +13,6 @@ use Date::Language; use Text::Template 1.20; use File::Temp 0.14; use HTML::Entities; -use Locale::Country; use Cwd; use FS::UID; use FS::Misc qw( send_email ); @@ -648,7 +647,7 @@ sub print_generic { if ( $cust_main->country eq $countrydefault ) { $invoice_data{'country'} = ''; } else { - $invoice_data{'country'} = &$escape_function(code2country($cust_main->country)); + $invoice_data{'country'} = &$escape_function($cust_main->bill_country_full); } my @address = (); diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm index ae24fc2ba..b0a4feae2 100644 --- a/FS/FS/cust_location.pm +++ b/FS/FS/cust_location.pm @@ -5,7 +5,6 @@ use strict; use vars qw( $import $DEBUG $conf $label_prefix ); use Data::Dumper; use Date::Format qw( time2str ); -use Locale::Country; use FS::UID qw( dbh driver_name ); use FS::Record qw( qsearch qsearchs ); use FS::Conf; @@ -412,14 +411,11 @@ sub check { =item country_full -Returns this locations's full country name +Returns this location's full country name =cut -sub country_full { - my $self = shift; - code2country($self->country); -} +#moved to geocode_Mixin.pm =item line diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index dcf642b98..4fb4f520a 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -28,7 +28,6 @@ use Date::Format; #use Date::Manip; use File::Temp; #qw( tempfile ); use Business::CreditCard 0.28; -use Locale::Country; use FS::UID qw( dbh driver_name ); use FS::Record qw( qsearchs qsearch dbdef regexp_sql ); use FS::Cursor; @@ -3869,26 +3868,14 @@ sub ship_contact_firstlast { $contact->get('first') . ' '. $contact->get('last'); } -#XXX this doesn't work in 3.x+ -#=item country_full -# -#Returns this customer's full country name -# -#=cut -# -#sub country_full { -# my $self = shift; -# code2country($self->country); -#} - sub bill_country_full { my $self = shift; - code2country($self->bill_location->country); + $self->bill_location->country_full; } sub ship_country_full { my $self = shift; - code2country($self->ship_location->country); + $self->ship_location->country_full; } =item county_state_county [ PREFIX ] diff --git a/FS/FS/geocode_Mixin.pm b/FS/FS/geocode_Mixin.pm index 611b9e5c1..0625b5ac3 100644 --- a/FS/FS/geocode_Mixin.pm +++ b/FS/FS/geocode_Mixin.pm @@ -3,7 +3,7 @@ package FS::geocode_Mixin; use strict; use vars qw( $DEBUG $me ); use Carp; -use Locale::Country; +use Locale::Country (); use Geo::Coder::Googlev3; #compile time for now, until others are supported use FS::Record qw( qsearchs qsearch ); use FS::Conf; @@ -126,25 +126,41 @@ sub location_label { $notfirst++; } } - $line .= $separator. &$escape(code2country($self->country)) + $line .= $separator. &$escape($self->country_full) if $self->country ne $cydefault; $line; } -=item set_coord [ PREFIX ] +=item country_full + +Returns the full country name. + +=cut + +sub country_full { + my $self = shift; + $self->code2country($self->country); +} + +sub code2country { + my( $self, $country ) = @_; + + #a hash? not expecting an explosion of business from unrecognized countries.. + return 'KKTC' if $country eq 'XC'; + + Locale::Country::code2country($country); +} + +=item set_coord Look up the coordinates of the location using (currently) the Google Maps API and set the 'latitude' and 'longitude' fields accordingly. -PREFIX, if specified, will be prepended to all location field names, -including latitude and longitude. - =cut sub set_coord { my $self = shift; - my $pre = scalar(@_) ? shift : ''; #my $module = FS::Conf->new->config('geocode_module') || 'Geo::Coder::Googlev3'; @@ -152,11 +168,11 @@ sub set_coord { my $location = eval { $geocoder->geocode( location => - $self->get($pre.'address1'). ','. - ( $self->get($pre.'address2') ? $self->get($pre.'address2').',' : '' ). - $self->get($pre.'city'). ','. - $self->get($pre.'state'). ','. - code2country($self->get($pre.'country')) + $self->get('address1'). ','. + ( $self->get('address2') ? $self->get('address2').',' : '' ). + $self->get('city'). ','. + $self->get('state'). ','. + $self->country_full ); }; if ( $@ ) { @@ -166,9 +182,9 @@ sub set_coord { my $geo_loc = $location->{'geometry'}{'location'} or return; if ( $geo_loc->{'lat'} && $geo_loc->{'lng'} ) { - $self->set($pre.'latitude', $geo_loc->{'lat'} ); - $self->set($pre.'longitude', $geo_loc->{'lng'} ); - $self->set($pre.'coord_auto', 'Y'); + $self->set('latitude', $geo_loc->{'lat'} ); + $self->set('longitude', $geo_loc->{'lng'} ); + $self->set('coord_auto', 'Y'); } } diff --git a/bin/enable-kktc b/bin/enable-kktc new file mode 100755 index 000000000..f6f2ea41b --- /dev/null +++ b/bin/enable-kktc @@ -0,0 +1,21 @@ +#!/usr/bin/perl + +use FS::UID qw( adminsuidsetup ); +use FS::cust_main_county; +use FS::Setup; + +adminsuidsetup shift or die "Usage: enable-kktc username\n"; + +my %states = ( + 'Gazimagosa' => 'Gazimagosa', + 'Girne' => 'Girne', + 'Guzelyurt' => 'Guzelyurt', + 'Iskele' => 'Iskele', + 'Lefkosa' => 'Lefkosa', +); + +foreach my $state ( keys %states ) { + FS::Setup::_add_locale( country=>'XC', state=>$state ); +} + +1; diff --git a/httemplate/browse/cust_main_county.cgi b/httemplate/browse/cust_main_county.cgi index e8c09e434..522614886 100755 --- a/httemplate/browse/cust_main_county.cgi +++ b/httemplate/browse/cust_main_county.cgi @@ -456,7 +456,7 @@ my %seen_county = (); my @fields = ( sub { my $country = shift->country; return '' if $seen_country{$country}++; - code2country($country). " ($country)"; + FS::geocode_Mixin->code2country($country). " ($country)"; }, #state diff --git a/httemplate/edit/bulk-cust_main_county.html b/httemplate/edit/bulk-cust_main_county.html index 6b5a7c26e..8b1234825 100644 --- a/httemplate/edit/bulk-cust_main_county.html +++ b/httemplate/edit/bulk-cust_main_county.html @@ -109,7 +109,7 @@ my @cust_main_county = @taxnum; my %seen_country = {}; -my @countries = map code2country($_)." ($_)", +my @countries = map FS::geocode_Mixin->code2country($_)." ($_)", grep !$seen_country{$_}++, map $_->country, @cust_main_county; diff --git a/httemplate/elements/select-country.html b/httemplate/elements/select-country.html index f3d98767a..c98147907 100644 --- a/httemplate/elements/select-country.html +++ b/httemplate/elements/select-country.html @@ -98,7 +98,7 @@ Example: