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; $_; }
@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.
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 );
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 = ();
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;
=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
#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;
$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 ]
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;
$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';
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 ( $@ ) {
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');
}
}
--- /dev/null
+#!/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;
my @fields = (
sub { my $country = shift->country;
return '' if $seen_country{$country}++;
- code2country($country). " ($country)";
+ FS::geocode_Mixin->code2country($country). " ($country)";
},
#state
@taxnum;
my %seen_country = {};
-my @countries = map code2country($_)." ($_)",
+my @countries = map FS::geocode_Mixin->code2country($_)." ($_)",
grep !$seen_country{$_}++,
map $_->country,
@cust_main_county;
<OPTION VALUE="<% $country |h %>"
<% $country eq $opt{'country'} ? ' SELECTED' : '' %>
- ><% code2country($country). " ($country)" %>
+ ><% FS::geocode_Mixin->code2country($country). " ($country)" %>
% }
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({
(<% $location->county |h %> county)\
% }
<% ($location->city || $location->county) ? ', ' : ''%><% state_label( $location->state, $location->country ) |h %>
- <% $location->zip %>
+ <% $location->zip |h %>
</TD>
</TR>
<TR>
<TH></TH>
- <TD><% code2country( $location->country ) %></TD>
+ <TD><% $location->country_full |h %></TD>
</TR>
% if ( $location->latitude && $location->longitude ) {