[freeside-commits] branch master updated. 11a4787e386291574aca2357421b586e365252d9

Ivan ivan at 420.am
Fri Dec 4 14:37:30 PST 2015


The branch, master has been updated
       via  11a4787e386291574aca2357421b586e365252d9 (commit)
      from  7fe341f7e83648feecf0b221e7a370a5818be753 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 11a4787e386291574aca2357421b586e365252d9
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Fri Dec 4 14:37:24 2015 -0800

    add northern cyprus, RT#39335

diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm
index 18cb275..9a43180 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 e889142..65a8484 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 ae24fc2..b0a4fea 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 dcf642b..4fb4f52 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 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). " ($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 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($_)." ($_)",
+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 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 a41a483..3feff2f 100644
--- a/httemplate/view/cust_main/contacts.html
+++ b/httemplate/view/cust_main/contacts.html
@@ -122,12 +122,12 @@
  (<% $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 ) {

-----------------------------------------------------------------------

Summary of changes:
 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




More information about the freeside-commits mailing list