summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2015-12-04 14:37:24 -0800
committerIvan Kohler <ivan@freeside.biz>2015-12-04 14:37:24 -0800
commit11a4787e386291574aca2357421b586e365252d9 (patch)
tree469896d1b29787b05674f3a478b88bb37007ae2d /FS
parent7fe341f7e83648feecf0b221e7a370a5818be753 (diff)
add northern cyprus, RT#39335
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Misc.pm24
-rw-r--r--FS/FS/Template_Mixin.pm3
-rw-r--r--FS/FS/cust_location.pm8
-rw-r--r--FS/FS/cust_main.pm17
-rw-r--r--FS/FS/geocode_Mixin.pm46
5 files changed, 60 insertions, 38 deletions
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');
}
}