summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2015-12-04 14:37:41 -0800
committerIvan Kohler <ivan@freeside.biz>2015-12-04 14:37:41 -0800
commitd72d57ec3b5c9f8d0115f84c02943994d93436ca (patch)
tree95e522984b59ed0569c1e960d200330664c4bb78
parent716d5a444011bbd0683f4bad0c8e6ca91c895c4c (diff)
add northern cyprus, RT#39335
-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
-rwxr-xr-xbin/enable-kktc21
-rwxr-xr-xhttemplate/browse/cust_main_county.cgi2
-rw-r--r--httemplate/edit/bulk-cust_main_county.html2
-rw-r--r--httemplate/elements/select-country.html4
-rw-r--r--httemplate/view/cust_main/contacts.html4
10 files changed, 87 insertions, 44 deletions
diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm
index 8049fde..164f1ba 100644
--- a/FS/FS/Misc.pm
+++ b/FS/FS/Misc.pm
@@ -534,6 +534,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; $_; }
@@ -556,6 +559,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 c331800..679f4c7 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 );
@@ -649,7 +648,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 74b1bd1..c140827 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;
@@ -406,14 +405,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 5691d83..9cf0ba6 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -33,7 +33,6 @@ use Date::Format;
#use Date::Manip;
use File::Temp; #qw( tempfile );
use Business::CreditCard 0.28;
-use Locale::Country;
use FS::UID qw( getotaker dbh driver_name );
use FS::Record qw( qsearchs qsearch dbdef regexp_sql );
use FS::Misc qw( generate_email send_email generate_ps do_print money_pretty );
@@ -4221,26 +4220,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 611b9e5..0625b5a 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 0000000..f6f2ea4
--- /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 e8c09e4..5226148 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). "&nbsp;($country)";
+ FS::geocode_Mixin->code2country($country). "&nbsp;($country)";
},
#state
diff --git a/httemplate/edit/bulk-cust_main_county.html b/httemplate/edit/bulk-cust_main_county.html
index 6b5a7c2..8b12348 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($_)."&nbsp;($_)",
+my @countries = map FS::geocode_Mixin->code2country($_)."&nbsp;($_)",
grep !$seen_country{$_}++,
map $_->country,
@cust_main_county;
diff --git a/httemplate/elements/select-country.html b/httemplate/elements/select-country.html
index f3d9876..c981479 100644
--- a/httemplate/elements/select-country.html
+++ b/httemplate/elements/select-country.html
@@ -98,7 +98,7 @@ Example:
<OPTION VALUE="<% $country |h %>"
<% $country eq $opt{'country'} ? ' SELECTED' : '' %>
- ><% code2country($country). " ($country)" %>
+ ><% FS::geocode_Mixin->code2country($country). " ($country)" %>
% }
@@ -130,7 +130,7 @@ my $default = $conf->config('countrydefault') || 'US';
my @all_countries = (
sort { ($b eq $default) <=> ($a eq $default)
- or code2country($a) cmp code2country($b)
+ or FS::geocode_Mixin->code2country($a) cmp FS::geocode_Mixin->code2country($b)
}
map { $_->country }
qsearch({
diff --git a/httemplate/view/cust_main/contacts.html b/httemplate/view/cust_main/contacts.html
index 136f634..053f039 100644
--- a/httemplate/view/cust_main/contacts.html
+++ b/httemplate/view/cust_main/contacts.html
@@ -106,11 +106,11 @@
<TD ALIGN="right"><% mt('State') |h %></TD>
<TD BGCOLOR="#ffffff"><% state_label( $location->state, $location->country ) |h %></TD>
<TD ALIGN="right"><% mt('Zip') |h %></TD>
- <TD BGCOLOR="#ffffff"><% $location->zip %></TD>
+ <TD BGCOLOR="#ffffff"><% $location->zip |h %></TD>
</TR>
<TR>
<TD ALIGN="right"><% mt('Country') |h %></TD>
- <TD BGCOLOR="#ffffff"><% code2country( $location->country ) %></TD>
+ <TD BGCOLOR="#ffffff"><% $location->country_full |h %></TD>
</TR>
% if ( $location->latitude && $location->longitude ) {