From c2348ef600465a77dc9dc8445784853145243828 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Thu, 29 Dec 2011 18:07:41 +0100
Subject: [PATCH] Uniformize field country_id, country_code, country

---
 dev/initdata/generate-societe.php             |  4 +-
 htdocs/adherents/class/adherent.class.php     | 37 ++++----
 htdocs/adherents/fiche.php                    | 87 +++++++++---------
 htdocs/admin/company.php                      |  4 +-
 htdocs/admin/prelevement.php                  |  2 +-
 htdocs/cashdesk/facturation.php               |  2 +-
 htdocs/categories/categorie.php               |  6 +-
 htdocs/comm/address.php                       | 71 ++++++---------
 htdocs/comm/contact.php                       |  2 +-
 htdocs/comm/fiche.php                         |  2 +-
 htdocs/comm/index.php                         | 23 ++---
 htdocs/comm/propal.php                        |  8 +-
 htdocs/comm/prospect/fiche.php                | 10 +--
 htdocs/commande/fiche.php                     | 49 +++++++++--
 htdocs/compta/bank/bankid_fr.php              |  2 +-
 htdocs/compta/bank/class/account.class.php    | 21 +++--
 htdocs/compta/bank/fiche.php                  | 18 ++--
 htdocs/compta/facture/prelevement.php         |  6 +-
 htdocs/compta/localtax/clients.php            | 12 +--
 htdocs/compta/localtax/fiche.php              |  4 +-
 htdocs/compta/localtax/index.php              |  4 +-
 htdocs/compta/localtax/reglement.php          |  2 +-
 .../class/bon-prelevement.class.php           |  4 +-
 htdocs/compta/propal.php                      |  8 +-
 .../actions_contactcard_common.class.php      | 36 ++++----
 htdocs/contact/class/contact.class.php        | 14 ++-
 htdocs/contact/fiche.php                      | 88 ++++++++-----------
 htdocs/core/class/html.form.class.php         | 26 +++---
 htdocs/core/class/html.formcompany.class.php  | 44 +++++-----
 htdocs/core/lib/functions.lib.php             | 14 +--
 htdocs/core/lib/pdf.lib.php                   | 22 ++---
 htdocs/core/lib/price.lib.php                 |  2 +-
 htdocs/core/menus/standard/eldy.lib.php       |  4 +-
 .../societe/doc/doc_generic_odt.modules.php   |  2 +-
 .../pdf/pdf_canelle.modules.php               | 10 +--
 .../pdf/pdf_muscadet.modules.php              | 12 +--
 htdocs/fourn/commande/fiche.php               |  8 +-
 htdocs/fourn/facture/fiche.php                | 14 +--
 htdocs/langs/en_US/agenda.lang                |  1 +
 htdocs/langs/en_US/companies.lang             |  1 +
 htdocs/langs/fr_FR/agenda.lang                |  1 +
 htdocs/langs/fr_FR/companies.lang             |  1 +
 htdocs/master.inc.php                         |  2 +-
 htdocs/paybox/lib/paybox.lib.php              | 10 +--
 htdocs/paypal/lib/paypal.lib.php              |  8 +-
 htdocs/product/fiche.php                      |  4 +-
 htdocs/product/stock/class/entrepot.class.php |  3 +-
 htdocs/product/stock/fiche.php                | 24 +++--
 htdocs/product/stock/mouvement.php            |  2 +-
 htdocs/public/members/new.php                 |  4 +-
 htdocs/public/paypal/newpayment.php           |  6 +-
 htdocs/societe/admin/societe.php              |  8 +-
 htdocs/societe/agenda.php                     |  6 +-
 .../canvas/actions_card_common.class.php      | 20 ++---
 .../company/actions_card_company.class.php    |  8 +-
 htdocs/societe/class/address.class.php        | 43 +++++----
 htdocs/societe/class/societe.class.php        | 49 +++++------
 htdocs/societe/commerciaux.php                |  4 +-
 htdocs/societe/lien.php                       | 26 +++---
 htdocs/societe/soc.php                        | 42 ++++-----
 htdocs/societe/societe.php                    |  6 +-
 test/phpunit/SocieteTest.php                  |  2 +-
 62 files changed, 494 insertions(+), 471 deletions(-)

diff --git a/dev/initdata/generate-societe.php b/dev/initdata/generate-societe.php
index 5052ac6bcb3..92db75953bd 100644
--- a/dev/initdata/generate-societe.php
+++ b/dev/initdata/generate-societe.php
@@ -96,8 +96,8 @@ for ($s = 0 ; $s < GEN_NUMBER_SOCIETE ; $s++)
     $soc->code_client='CU'.time()."$s";
     $soc->code_fournisseur='SU'.time()."$s";
     $soc->tva_assuj=1;
-    $soc->pays_id=1;
-    $soc->pays_code='FR';
+    $soc->country_id=1;
+    $soc->country_code='FR';
 	// Un client sur 3 a une remise de 5%
     $user_remise=rand(1,3); if ($user_remise==3) $soc->remise_client=5;
 	print "> client=".$soc->client.", fournisseur=".$soc->fournisseur.", remise=".$soc->remise_client."\n";
diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php
index eb715a4cf40..d80b862bd5b 100644
--- a/htdocs/adherents/class/adherent.class.php
+++ b/htdocs/adherents/class/adherent.class.php
@@ -411,7 +411,7 @@ class Adherent extends CommonObject
         $sql.= ", adresse=" .($this->adresse?"'".$this->db->escape($this->adresse)."'":"null");
         $sql.= ", cp="      .($this->cp?"'".$this->db->escape($this->cp)."'":"null");
         $sql.= ", ville="   .($this->ville?"'".$this->db->escape($this->ville)."'":"null");
-        $sql.= ", pays="          .($this->pays_id>0?"'".$this->pays_id."'":"null");
+        $sql.= ", pays="          .($this->country_id>0?"'".$this->country_id."'":"null");
         $sql.= ", fk_departement=".($this->fk_departement>0?"'".$this->fk_departement."'":"null");
         $sql.= ", email='".$this->email."'";
         $sql.= ", phone="   .($this->phone?"'".$this->db->escape($this->phone)."'":"null");
@@ -547,7 +547,7 @@ class Adherent extends CommonObject
                         $lthirdparty->tel=$this->phone;
                         $lthirdparty->state_id=$this->state_id;
                         $lthirdparty->country_id=$this->country_id;
-                        $lthirdparty->pays_id=$this->pays_id;
+                        $lthirdparty->pays_id=$this->country_id;
                         //$lthirdparty->phone_mobile=$this->phone_mobile;
 
                         $result=$lthirdparty->update($this->fk_soc,$user,0,1,1,'update');	// Use sync to 0 to avoid cyclic updates
@@ -963,7 +963,7 @@ class Adherent extends CommonObject
         $sql.= " d.datevalid as datev,";
         $sql.= " d.pays,";
         $sql.= " d.fk_departement,";
-        $sql.= " p.rowid as pays_id, p.code as pays_code, p.libelle as pays_lib,";
+        $sql.= " p.rowid as country_id, p.code as country_code, p.libelle as country,";
         $sql.= " dep.nom as departement, dep.code_departement as departement_code,";
         $sql.= " t.libelle as type, t.cotisation as cotisation,";
         $sql.= " u.rowid as user_id, u.login as user_login";
@@ -1004,20 +1004,20 @@ class Adherent extends CommonObject
                 $this->town           = $obj->town;
 
                 $this->state_id       = $obj->fk_departement;
-                $this->state_id       = $obj->fk_departement?$obj->departement_code:'';
-                $this->state_id       = $obj->fk_departement?$obj->departement:'';
+                $this->state_code     = $obj->fk_departement?$obj->departement_code:'';
+                $this->state          = $obj->fk_departement?$obj->departement:'';
                 $this->fk_departement = $obj->fk_departement;    // TODO deprecated
                 $this->departement_code = $obj->fk_departement?$obj->departement_code:'';    // TODO deprecated
                 $this->departement	  = $obj->fk_departement?$obj->departement:'';    // TODO deprecated
 
-                $this->country_id     = $obj->pays_id;
-                $this->country_code   = $obj->pays_code;
-                $this->pays_id        = $obj->pays_id;    // TODO deprecated
-                $this->pays_code      = $obj->pays_code;    // TODO deprecated
-                if ($langs->trans("Country".$obj->pays_code) != "Country".$obj->pays_code) $this->pays = $langs->trans("Country".$obj->pays_code);
-                elseif ($obj->pays_lib) $this->pays=$obj->pays_lib;
-                else $this->pays=$obj->pays;
-				$this->country        = $this->pays;
+                $this->country_id     = $obj->country_id;
+                $this->country_code   = $obj->country_code;
+                $this->pays_id        = $obj->country_id;    // TODO deprecated
+                $this->pays_code      = $obj->country_code;    // TODO deprecated
+                if ($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) $this->country = $langs->trans("Country".$obj->country_code);
+                elseif ($obj->country) $this->country=$obj->country;
+                else $this->country=$obj->country;
+				$this->pays           = $this->country;
 
                 $this->phone          = $obj->phone;
                 $this->phone_perso    = $obj->phone_perso;
@@ -1966,15 +1966,12 @@ class Adherent extends CommonObject
         $this->login='dolibspec';
         $this->pass='dolibspec';
         $this->societe = 'Societe ABC';
-        $this->adresse = '61 jump street';
         $this->address = '61 jump street';
-        $this->cp = '75000';
         $this->zip = '75000';
-        $this->ville = 'Paris';
         $this->town = 'Paris';
-        $this->pays_id = 1;
-        $this->pays_code = 'FR';
-        $this->pays = 'France';
+        $this->country_id = 1;
+        $this->country_code = 'FR';
+        $this->country = 'France';
         $this->morphy = 1;
         $this->email = 'specimen@specimen.com';
         $this->phone        = '0999999999';
@@ -2046,7 +2043,7 @@ class Adherent extends CommonObject
         if ($this->adresse && $conf->global->LDAP_MEMBER_FIELD_ADDRESS)  $info[$conf->global->LDAP_MEMBER_FIELD_ADDRESS] = $this->adresse;
         if ($this->cp && $conf->global->LDAP_MEMBER_FIELD_ZIP)           $info[$conf->global->LDAP_MEMBER_FIELD_ZIP] = $this->cp;
         if ($this->ville && $conf->global->LDAP_MEMBER_FIELD_TOWN)       $info[$conf->global->LDAP_MEMBER_FIELD_TOWN] = $this->ville;
-        if ($this->pays_code && $conf->global->LDAP_MEMBER_FIELD_COUNTRY)     $info[$conf->global->LDAP_MEMBER_FIELD_COUNTRY] = $this->pays_code;
+        if ($this->country_code && $conf->global->LDAP_MEMBER_FIELD_COUNTRY)     $info[$conf->global->LDAP_MEMBER_FIELD_COUNTRY] = $this->country_code;
         if ($this->email && $conf->global->LDAP_MEMBER_FIELD_MAIL)       $info[$conf->global->LDAP_MEMBER_FIELD_MAIL] = $this->email;
         if ($this->phone && $conf->global->LDAP_MEMBER_FIELD_PHONE)      $info[$conf->global->LDAP_MEMBER_FIELD_PHONE] = $this->phone;
         if ($this->phone_perso && $conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO) $info[$conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO] = $this->phone_perso;
diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php
index 46d78b4ee96..36e412ac105 100644
--- a/htdocs/adherents/fiche.php
+++ b/htdocs/adherents/fiche.php
@@ -236,9 +236,9 @@ if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->adhe
         $object->ville       = trim($_POST["town"]);       // deprecated
         $object->town        = trim($_POST["town"]);
 		$object->state_id    = $_POST["departement_id"];
-		$object->country_id  = $_POST["pays_id"];
+		$object->country_id  = $_POST["country_id"];
 		$object->fk_departement = $_POST["departement_id"];   // deprecated
-		$object->pays_id        = $_POST["pays_id"];   // deprecated
+		$object->pays_id     = $_POST["country_id"];   // deprecated
 
 		$object->phone       = trim($_POST["phone"]);
 		$object->phone_perso = trim($_POST["phone_perso"]);
@@ -361,8 +361,8 @@ if ($_POST["action"] == 'add' && $user->rights->adherent->creer)
     $address=$_POST["address"];
     $zip=$_POST["zipcode"];
     $town=$_POST["town"];
-	$departement_id=$_POST["departement_id"];
-    $pays_id=$_POST["pays_id"];
+	$state_id=$_POST["departement_id"];
+    $country_id=$_POST["country_id"];
 
     $phone=$_POST["phone"];
     $phone_perso=$_POST["phone_perso"];
@@ -389,8 +389,10 @@ if ($_POST["action"] == 'add' && $user->rights->adherent->creer)
     $object->zip         = $zip;
     $object->ville       = $town;    // deprecated
     $object->town        = $town;
-    $object->fk_departement = $departement_id;
-    $object->pays_id     = $pays_id;
+    $object->fk_departement = $state_id;
+    $object->state_id    = $state_id;
+    $object->pays_id     = $country_id;
+    $object->country_id  = $country_id;
     $object->phone       = $phone;
     $object->phone_perso = $phone_perso;
     $object->phone_mobile= $phone_mobile;
@@ -621,25 +623,15 @@ if ($action == 'create')
     /* ************************************************************************** */
     $object->fk_departement = $_POST["departement_id"];
 
-    // We set pays_id, pays_code and label for the selected country
-    $object->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id;
-    if ($object->pays_id)
+    // We set country_id, country_code and country for the selected country
+    $object->country_id=$_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id;
+    if ($object->country_id)
     {
-        $sql = "SELECT rowid, code, libelle";
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_pays";
-        $sql.= " WHERE rowid = ".$object->pays_id;
-        $resql=$db->query($sql);
-        if ($resql)
-        {
-            $obj = $db->fetch_object($resql);
-        }
-        else
-        {
-            dol_print_error($db);
-        }
-        $object->pays_id=$obj->rowid;
-        $object->pays_code=$obj->code;
-        $object->pays=$obj->libelle;
+    	$tmparray=getCountry($object->country_id,'all');
+        $object->pays_code=$tmparray['code'];
+        $object->pays=$tmparray['code'];
+        $object->country_code=$tmparray['code'];
+        $object->country=$tmparray['label'];
     }
 
     $adht = new AdherentType($db);
@@ -653,7 +645,7 @@ if ($action == 'create')
     {
         print "\n".'<script type="text/javascript" language="javascript">';
         print 'jQuery(document).ready(function () {
-                    jQuery("#selectpays_id").change(function() {
+                    jQuery("#selectcountry_id").change(function() {
                         document.formsoc.action.value="create";
                         document.formsoc.submit();
                     });
@@ -723,15 +715,15 @@ if ($action == 'create')
 
     // Zip / Town
     print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
-    print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectpays_id','departement_id'),6);
+    print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','departement_id'),6);
     print ' ';
-    print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectpays_id','departement_id'));
+    print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','departement_id'));
     print '</td></tr>';
 
     // Country
-    $object->pays_id=$object->pays_id?$object->pays_id:$mysoc->pays_id;
+    $object->country_id=$object->country_id?$object->country_id:$mysoc->country_id;
     print '<tr><td width="25%">'.$langs->trans('Country').'</td><td>';
-    $form->select_pays(isset($_POST["pays_id"])?$_POST["pays_id"]:$object->pays_id,'pays_id');
+    print $form->select_country(isset($_POST["country_id"])?$_POST["country_id"]:$object->country_id,'country_id');
     if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
     print '</td></tr>';
 
@@ -739,9 +731,9 @@ if ($action == 'create')
     if (empty($conf->global->MEMBER_DISABLE_STATE))
     {
         print '<tr><td>'.$langs->trans('State').'</td><td>';
-        if ($object->pays_id)
+        if ($object->country_id)
         {
-            $formcompany->select_departement(isset($_POST["departement_id"])?$_POST["departement_id"]:$object->fk_departement,$object->pays_code);
+            print $formcompany->select_state(isset($_POST["departement_id"])?$_POST["departement_id"]:$object->fk_departement,$object->country_code);
         }
         else
         {
@@ -826,10 +818,10 @@ if ($action == 'edit')
 	$adht = new AdherentType($db);
     $adht->fetch($object->typeid);
 
-	// We set pays_id, and pays_code label of the chosen country
-	if (isset($_POST["pays"]) || $object->pays_id)
+	// We set country_id, and country_code, country of the chosen country
+	if (isset($_POST["pays"]) || $object->country_id)
 	{
-		$sql = "SELECT rowid, code, libelle from ".MAIN_DB_PREFIX."c_pays where rowid = ".(isset($_POST["pays"])?$_POST["pays"]:$object->pays_id);
+		$sql = "SELECT rowid, code, libelle as label from ".MAIN_DB_PREFIX."c_pays where rowid = ".(isset($_POST["pays"])?$_POST["pays"]:$object->country_id);
 		$resql=$db->query($sql);
 		if ($resql)
 		{
@@ -841,7 +833,10 @@ if ($action == 'edit')
 		}
 		$object->pays_id=$obj->rowid;
 		$object->pays_code=$obj->code;
-		$object->pays=$langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->libelle;
+		$object->pays=$langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->label;
+		$object->country_id=$obj->rowid;
+		$object->country_code=$obj->code;
+		$object->country=$langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->label;
 	}
 
 	$head = member_prepare_head($object);
@@ -856,7 +851,7 @@ if ($action == 'edit')
 	{
         print "\n".'<script type="text/javascript" language="javascript">';
         print 'jQuery(document).ready(function () {
-                    jQuery("#selectpays").change(function() {
+                    jQuery("#selectcountry_id").change(function() {
 	               	    document.formsoc.action.value="edit";
                         document.formsoc.submit();
                     });
@@ -948,15 +943,15 @@ if ($action == 'edit')
 
     // Zip / Town
     print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td>';
-    print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectpays_id','departement_id'),6);
+    print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','departement_id'),6);
     print ' ';
-    print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectpays_id','departement_id'));
+    print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','departement_id'));
     print '</td></tr>';
 
     // Country
-    //$object->pays_id=$object->pays_id?$object->pays_id:$mysoc->pays_id;    // In edit mode we don't force to company country if not defined
+    //$object->country_id=$object->country_id?$object->country_id:$mysoc->country_id;    // In edit mode we don't force to company country if not defined
     print '<tr><td width="25%">'.$langs->trans('Country').'</td><td>';
-    $form->select_pays(isset($_POST["pays_id"])?$_POST["pays_id"]:$object->pays_id,'pays_id');
+    print $form->select_country(isset($_POST["country_id"])?$_POST["country_id"]:$object->country_id,'country_id');
     if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
     print '</td></tr>';
 
@@ -964,7 +959,7 @@ if ($action == 'edit')
     if (empty($conf->global->MEMBER_DISABLE_STATE))
     {
     	print '<tr><td>'.$langs->trans('State').'</td><td>';
-    	$formcompany->select_departement($object->fk_departement,$object->pays_code);
+    	print $formcompany->select_state($object->fk_departement,isset($_POST["country_id"])?$_POST["country_id"]:$object->country_id);
     	print '</td></tr>';
     }
 
@@ -1273,22 +1268,22 @@ if ($rowid && $action != 'edit')
 
 	// Country
     print '<tr><td>'.$langs->trans("Country").'</td><td class="valeur">';
-	$img=picto_from_langcode($object->pays_code);
+	$img=picto_from_langcode($object->country_code);
 	if ($img) print $img.' ';
-    print getCountry($object->pays_code);
+    print getCountry($object->country_code);
     print '</td></tr>';
 
 	// State
 	print '<tr><td>'.$langs->trans('State').'</td><td class="valeur">'.$object->departement.'</td>';
 
     // Tel pro.
-    print '<tr><td>'.$langs->trans("PhonePro").'</td><td class="valeur">'.dol_print_phone($object->phone,$object->pays_code,0,$object->fk_soc,1).'</td></tr>';
+    print '<tr><td>'.$langs->trans("PhonePro").'</td><td class="valeur">'.dol_print_phone($object->phone,$object->country_code,0,$object->fk_soc,1).'</td></tr>';
 
     // Tel perso
-    print '<tr><td>'.$langs->trans("PhonePerso").'</td><td class="valeur">'.dol_print_phone($object->phone_perso,$object->pays_code,0,$object->fk_soc,1).'</td></tr>';
+    print '<tr><td>'.$langs->trans("PhonePerso").'</td><td class="valeur">'.dol_print_phone($object->phone_perso,$object->country_code,0,$object->fk_soc,1).'</td></tr>';
 
     // Tel mobile
-    print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td class="valeur">'.dol_print_phone($object->phone_mobile,$object->pays_code,0,$object->fk_soc,1).'</td></tr>';
+    print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td class="valeur">'.dol_print_phone($object->phone_mobile,$object->country_code,0,$object->fk_soc,1).'</td></tr>';
 
     // EMail
     print '<tr><td>'.$langs->trans("EMail").'</td><td class="valeur">'.dol_print_email($object->email,0,$object->fk_soc,1).'</td></tr>';
diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php
index 6d0e2278485..aa4d44d00a3 100644
--- a/htdocs/admin/company.php
+++ b/htdocs/admin/company.php
@@ -685,10 +685,10 @@ else
     print '</td></tr>';
 
     $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Tel").'</td><td>' . dol_print_phone($conf->global->MAIN_INFO_SOCIETE_TEL,$mysoc->pays_code) . '</td></tr>';
+    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Tel").'</td><td>' . dol_print_phone($conf->global->MAIN_INFO_SOCIETE_TEL,$mysoc->country_code) . '</td></tr>';
 
     $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Fax").'</td><td>' . dol_print_phone($conf->global->MAIN_INFO_SOCIETE_FAX,$mysoc->pays_code) . '</td></tr>';
+    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Fax").'</td><td>' . dol_print_phone($conf->global->MAIN_INFO_SOCIETE_FAX,$mysoc->country_code) . '</td></tr>';
 
     $var=!$var;
     print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Mail").'</td><td>' . dol_print_email($conf->global->MAIN_INFO_SOCIETE_MAIL,0,0,0,80) . '</td></tr>';
diff --git a/htdocs/admin/prelevement.php b/htdocs/admin/prelevement.php
index 89fe985d15d..5d7659e454b 100644
--- a/htdocs/admin/prelevement.php
+++ b/htdocs/admin/prelevement.php
@@ -136,7 +136,7 @@ print '</td>';
 print '</tr>';
 
 //Profid1 of Transmitter
-print '<tr class="pair"><td>'.$langs->trans("NumeroNationalEmetter").' - '.$langs->transcountry('ProfId1',$mysoc->pays_code).'</td>';
+print '<tr class="pair"><td>'.$langs->trans("NumeroNationalEmetter").' - '.$langs->transcountry('ProfId1',$mysoc->country_code).'</td>';
 print '<td align="left">';
 print '<input type="hidden" name="nom1" value="PRELEVEMENT_NUMERO_NATIONAL_EMETTEUR">';
 print '<input type="text"   name="value1" value="'.$conf->global->PRELEVEMENT_NUMERO_NATIONAL_EMETTEUR.'" size="9" ></td>';
diff --git a/htdocs/cashdesk/facturation.php b/htdocs/cashdesk/facturation.php
index 5bd2324d17f..f07f239928a 100644
--- a/htdocs/cashdesk/facturation.php
+++ b/htdocs/cashdesk/facturation.php
@@ -128,7 +128,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t";
 $sql.= ", ".MAIN_DB_PREFIX."c_pays as p";
 $sql.= " WHERE t.fk_pays = p.rowid";
 $sql.= " AND t.active = 1";
-$sql.= " AND p.code = '".$mysoc->pays_code."'";
+$sql.= " AND p.code = '".$mysoc->country_code."'";
 //print $request;
 
 $res = $db->query($sql);
diff --git a/htdocs/categories/categorie.php b/htdocs/categories/categorie.php
index c36e9be33c1..5ca949410b6 100644
--- a/htdocs/categories/categorie.php
+++ b/htdocs/categories/categorie.php
@@ -236,15 +236,15 @@ if ($socid)
 	if ($soc->pays)
 	{
 		print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
-		$img=picto_from_langcode($soc->pays_code);
+		$img=picto_from_langcode($soc->country_code);
 		print ($img?$img.' ':'');
 		print $soc->pays;
 		print '</td></tr>';
 	}
 
 	// Phone
-	print '<tr><td>'.$langs->trans('Phone').'</td><td>'.dol_print_phone($soc->tel,$soc->pays_code,0,$soc->id,'AC_TEL').'</td>';
-	print '<td>'.$langs->trans('Fax').'</td><td>'.dol_print_phone($soc->fax,$soc->pays_code,0,$soc->id,'AC_FAX').'</td></tr>';
+	print '<tr><td>'.$langs->trans('Phone').'</td><td>'.dol_print_phone($soc->tel,$soc->country_code,0,$soc->id,'AC_TEL').'</td>';
+	print '<td>'.$langs->trans('Fax').'</td><td>'.dol_print_phone($soc->fax,$soc->country_code,0,$soc->id,'AC_FAX').'</td></tr>';
 
 	// EMail
 	print '<tr><td>'.$langs->trans('EMail').'</td><td>';
diff --git a/htdocs/comm/address.php b/htdocs/comm/address.php
index 99a632263b6..72abc9da7d1 100644
--- a/htdocs/comm/address.php
+++ b/htdocs/comm/address.php
@@ -56,7 +56,10 @@ if ($_POST["action"] == 'add' || $_POST["action"] == 'update')
     $address->address	= $_POST["address"];
     $address->cp		= $_POST["zipcode"];
     $address->ville		= $_POST["town"];
-    $address->pays_id	= $_POST["pays_id"];
+    $address->zip		= $_POST["zipcode"];
+    $address->town		= $_POST["town"];
+    $address->pays_id	= $_POST["country_id"];
+    $address->country_id= $_POST["country_id"];
     $address->tel		= $_POST["tel"];
     $address->fax		= $_POST["fax"];
     $address->note		= $_POST["note"];
@@ -194,24 +197,14 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'create')
         }
 
         // On positionne pays_id, pays_code et libelle du pays choisi
-        $address->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id;
-        if ($address->pays_id)
+        $address->country_id=$_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id;
+        if ($address->country_id)
         {
-            $sql = "SELECT code, libelle";
-            $sql.= " FROM ".MAIN_DB_PREFIX."c_pays";
-            $sql.= " WHERE rowid = ".$address->pays_id;
-
-            $resql=$db->query($sql);
-            if ($resql)
-            {
-                $obj = $db->fetch_object($resql);
-            }
-            else
-            {
-                dol_print_error($db);
-            }
-            $address->pays_code	=	$obj->code;
-            $address->pays		=	$obj->libelle;
+        	$tmparray=getCountry($address->country_id,'all');
+            $address->pays_code	= $tmparray['code'];
+            $address->pays		= $tmparray['label'];
+            $address->country_code	= $tmparray['code'];
+            $address->country		= $tmparray['label'];
         }
 
         print_titre($langs->trans("AddAddress"));
@@ -267,16 +260,16 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'create')
 
         // Zip
         print '<tr><td>'.$langs->trans('Zip').'</td><td>';
-        print $formcompany->select_ziptown($address->cp,'zipcode',array('town','selectpays_id'),6);
+        print $formcompany->select_ziptown($address->cp,'zipcode',array('town','selectcountry_id'),6);
         print '</td></tr>';
 
         // Town
         print '<tr><td>'.$langs->trans('Town').'</td><td>';
-        print $formcompany->select_ziptown($address->ville,'town',array('zipcode','selectpays_id'));
+        print $formcompany->select_ziptown($address->ville,'town',array('zipcode','selectcountry_id'));
         print '</td></tr>';
 
         print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">';
-        $form->select_pays($address->pays_id,'pays_id');
+        print $form->select_country($address->country_id,'selectcountry_id');
         print '</td></tr>';
 
         print '<tr><td>'.$langs->trans('Phone').'</td><td><input type="text" name="tel" value="'.$address->tel.'"></td></tr>';
@@ -328,29 +321,19 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit')
             $address->address	=	$_POST["address"];
             $address->cp		=	$_POST["zipcode"];
             $address->ville		=	$_POST["town"];
-            $address->pays_id	=	$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id;
+            $address->country_id	=	$_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id;
             $address->tel		=	$_POST["tel"];
             $address->fax		=	$_POST["fax"];
             $address->note		=	$_POST["note"];
 
-            // On positionne pays_id, pays_code et libelle du pays choisi
-            if ($address->pays_id)
+            // On positionne country_id, pays_code et libelle du pays choisi
+            if ($address->country_id)
             {
-                $sql = "SELECT code, libelle";
-                $sql.= " FROM ".MAIN_DB_PREFIX."c_pays";
-                $sql.= "WHERE rowid = ".$address->pays_id;
-
-                $resql=$db->query($sql);
-                if ($resql)
-                {
-                    $obj = $db->fetch_object($resql);
-                }
-                else
-                {
-                    dol_print_error($db);
-                }
-                $address->pays_code	=	$obj->code;
-                $address->pays		=	$langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->libelle;
+	        	$tmparray=getCountry($address->country_id,'all');
+	            $address->pays_code	= $tmparray['code'];
+	            $address->pays		= $tmparray['label'];
+	            $address->country_code	= $tmparray['code'];
+	            $address->country		= $tmparray['label'];
             }
         }
 
@@ -380,16 +363,16 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit')
 
         // Zip
         print '<tr><td>'.$langs->trans('Zip').'</td><td>';
-        print $formcompany->select_ziptown($address->cp,'zipcode',array('town','selectpays_id'),6);
+        print $formcompany->select_ziptown($address->cp,'zipcode',array('town','selectcountry_id'),6);
         print '</td></tr>';
 
         // Town
         print '<tr><td>'.$langs->trans('Town').'</td><td>';
-        print $formcompany->select_ziptown($address->ville,'town',array('zipcode','selectpays_id'));
+        print $formcompany->select_ziptown($address->ville,'town',array('zipcode','selectcountry_id'));
         print '</td></tr>';
 
         print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
-        $form->select_pays($address->pays_id,'pays_id');
+        print $form->select_country($address->country_id,'country_id');
         print '</td></tr>';
 
         print '<tr><td>'.$langs->trans('Phone').'</td><td><input type="text" name="tel" value="'.$address->tel.'"></td></tr>';
@@ -460,9 +443,9 @@ else
 
             print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">'.$address->lines[$i]->pays.'</td>';
 
-            print '<tr><td>'.$langs->trans('Phone').'</td><td>'.dol_print_phone($address->lines[$i]->tel,$address->lines[$i]->pays_code,0,$address->socid,'AC_TEL').'</td></tr>';
+            print '<tr><td>'.$langs->trans('Phone').'</td><td>'.dol_print_phone($address->lines[$i]->tel,$address->lines[$i]->country_code,0,$address->socid,'AC_TEL').'</td></tr>';
 
-            print '<tr><td>'.$langs->trans('Fax').'</td><td>'.dol_print_phone($address->lines[$i]->fax,$address->lines[$i]->pays_code,0,$address->socid,'AC_FAX').'</td></tr>';
+            print '<tr><td>'.$langs->trans('Fax').'</td><td>'.dol_print_phone($address->lines[$i]->fax,$address->lines[$i]->country_code,0,$address->socid,'AC_FAX').'</td></tr>';
 
             print '</td></tr>';
 
diff --git a/htdocs/comm/contact.php b/htdocs/comm/contact.php
index b50770dc5fe..62793e86d27 100644
--- a/htdocs/comm/contact.php
+++ b/htdocs/comm/contact.php
@@ -165,7 +165,7 @@ if ($resql)
 
       print '<td>'.dol_print_phone($obj->email,$obj->cidp,$obj->rowid,'AC_EMAIL').'</td>';
 
-      print '<td>'.dol_print_phone($obj->phone,$obj->pays_code,$obj->cidp,$obj->rowid,'AC_TEL').'&nbsp;</td>';
+      print '<td>'.dol_print_phone($obj->phone,$obj->country_code,$obj->cidp,$obj->rowid,'AC_TEL').'&nbsp;</td>';
 
       print "</tr>\n";
       $i++;
diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php
index 4bcd16fb9bc..fcbdf687f3e 100644
--- a/htdocs/comm/fiche.php
+++ b/htdocs/comm/fiche.php
@@ -263,7 +263,7 @@ if ($id > 0)
 	print '</tr>';
 
 	// Local Taxes
-	if($mysoc->pays_code=='ES')
+	if($mysoc->country_code=='ES')
 	{
 		if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
 		{
diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php
index b220e311ed7..025ee92c122 100644
--- a/htdocs/comm/index.php
+++ b/htdocs/comm/index.php
@@ -151,14 +151,14 @@ if ($conf->propal->enabled && $user->rights->propale->lire)
 	$resql=$db->query($sql);
 	if ($resql)
 	{
+		print '<table class="noborder" width="100%">';
+		print '<tr class="liste_titre">';
+		print '<td colspan="3">'.$langs->trans("ProposalsDraft").'</td></tr>';
+
 		$total = 0;
 		$num = $db->num_rows($resql);
 		if ($num > 0)
 		{
-			print '<table class="noborder" width="100%">';
-			print '<tr class="liste_titre">';
-			print '<td colspan="3">'.$langs->trans("ProposalsDraft").'</td></tr>';
-
 			$i = 0;
 			$var=true;
 			while ($i < $num)
@@ -186,8 +186,9 @@ if ($conf->propal->enabled && $user->rights->propale->lire)
 				$var=!$var;
 				print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" align="right">'.price($total)."</td></tr>";
 			}
-			print "</table><br>";
 		}
+		print "</table><br>";
+		
 		$db->free($resql);
 	}
 	else
@@ -217,14 +218,14 @@ if ($conf->commande->enabled && $user->rights->commande->lire)
 	$resql = $db->query($sql);
 	if ($resql)
 	{
+		print '<table class="noborder" width="100%">';
+		print '<tr class="liste_titre">';
+		print '<td colspan="3">'.$langs->trans("DraftOrders").'</td></tr>';
+
 		$total = 0;
 		$num = $db->num_rows($resql);
 		if ($num)
 		{
-			print '<table class="noborder" width="100%">';
-			print '<tr class="liste_titre">';
-			print '<td colspan="3">'.$langs->trans("DraftOrders").'</td></tr>';
-
 			$i = 0;
 			$var = true;
 			while ($i < $num)
@@ -248,8 +249,10 @@ if ($conf->commande->enabled && $user->rights->commande->lire)
 				$var=!$var;
 				print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" align="right">'.price($total)."</td></tr>";
 			}
-			print "</table><br>";
 		}
+		print "</table><br>";
+		
+		$db->free($resql);
 	}
 }
 
diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 0b4bfdddcd3..340f6cdcfc7 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -1227,7 +1227,7 @@ if ($id > 0 || ! empty($ref))
 	if ($conf->global->PROPALE_ADD_DELIVERY_ADDRESS) $rowspan++;
 
 	//Local taxes
-	if ($mysoc->pays_code=='ES')
+	if ($mysoc->country_code=='ES')
 	{
 		if($mysoc->localtax1_assuj=="1") $rowspan++;
 		if($mysoc->localtax2_assuj=="1") $rowspan++;
@@ -1455,17 +1455,17 @@ if ($id > 0 || ! empty($ref))
 	print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
 
 	// Amount Local Taxes
-	if ($mysoc->pays_code=='ES')
+	if ($mysoc->country_code=='ES')
 	{
 		if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
 		{
-			print '<tr><td height="10">'.$langs->transcountry("AmountLT1",$mysoc->pays_code).'</td>';
+			print '<tr><td height="10">'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
 			print '<td align="right" colspan="2" nowrap>'.price($object->total_localtax1).'</td>';
 			print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
 		}
 		if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
 		{
-			print '<tr><td height="10">'.$langs->transcountry("AmountLT2",$mysoc->pays_code).'</td>';
+			print '<tr><td height="10">'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>';
 			print '<td align="right" colspan="2" nowrap>'.price($object->total_localtax2).'</td>';
 			print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
 		}
diff --git a/htdocs/comm/prospect/fiche.php b/htdocs/comm/prospect/fiche.php
index c581aab6fa0..8759e431483 100644
--- a/htdocs/comm/prospect/fiche.php
+++ b/htdocs/comm/prospect/fiche.php
@@ -116,14 +116,14 @@ if ($socid > 0)
 
 	// Country
 	print '<tr><td>'.$langs->trans("Country").'</td><td colspan="3">';
-	$img=picto_from_langcode($societe->pays_code);
-	if ($societe->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$societe->pays,$langs->trans("CountryIsInEEC"),1,0);
-	else print ($img?$img.' ':'').$societe->pays;
+	$img=picto_from_langcode($societe->country_code);
+	if ($societe->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$societe->country,$langs->trans("CountryIsInEEC"),1,0);
+	else print ($img?$img.' ':'').$societe->country;
 	print '</td></tr>';
 
 	// Phone
-	print '<tr><td>'.$langs->trans("Phone").'</td><td style="min-width: 25%;">'.dol_print_phone($societe->tel,$societe->pays_code,0,$societe->id,'AC_TEL').'</td>';
-	print '<td>'.$langs->trans("Fax").'</td><td style="min-width: 25%;">'.dol_print_phone($societe->fax,$societe->pays_code).'</td></tr>';
+	print '<tr><td>'.$langs->trans("Phone").'</td><td style="min-width: 25%;">'.dol_print_phone($societe->tel,$societe->country_code,0,$societe->id,'AC_TEL').'</td>';
+	print '<td>'.$langs->trans("Fax").'</td><td style="min-width: 25%;">'.dol_print_phone($societe->fax,$societe->country_code).'</td></tr>';
 
 	// EMail
 	print '<td>'.$langs->trans('EMail').'</td><td colspan="3">'.dol_print_email($societe->email,0,$societe->id,'AC_EMAIL').'</td></tr>';
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index 0c3103c0801..408e1005069 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -843,9 +843,26 @@ if ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->commande->
 
 if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->commande->valider)
 {
+    $idwarehouse=GETPOST('idwarehouse');
+
     $object->fetch($id);		// Load order and lines
+    $object->fetch_thirdparty();
 
-    $result = $object->cancel($user);
+    // Check parameters
+    if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
+    {
+        if (! $idwarehouse || $idwarehouse == -1)
+        {
+            $error++;
+            $errors[]=$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse"));
+            $action='';
+        }
+    }
+
+	if (! $error)
+	{
+	    $result = $object->cancel($user,$idwarehouse);
+	}
 }
 
 
@@ -1382,16 +1399,16 @@ if ($action == 'create' && $user->rights->commande->creer)
         print '<tr><td>'.$langs->trans($newclassname).'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
         print '<tr><td>'.$langs->trans('TotalHT').'</td><td colspan="2">'.price($objectsrc->total_ht).'</td></tr>';
         print '<tr><td>'.$langs->trans('TotalVAT').'</td><td colspan="2">'.price($objectsrc->total_tva)."</td></tr>";
-        if ($mysoc->pays_code=='ES')
+        if ($mysoc->country_code=='ES')
         {
             if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
             {
-                print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->pays_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
+                print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
             }
 
             if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
             {
-                print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->pays_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
+                print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
             }
         }
         print '<tr><td>'.$langs->trans('TotalTTC').'</td><td colspan="2">'.price($objectsrc->total_ttc)."</td></tr>";
@@ -1564,7 +1581,21 @@ else
              */
             if ($action == 'cancel')
             {
-                $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Cancel'), $langs->trans('ConfirmCancelOrder'), 'confirm_cancel', '', 0, 1);
+                $text=$langs->trans('ConfirmCancelOrder',$object->ref);
+                $formquestion=array();
+                if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
+                {
+                    $langs->load("stocks");
+                    require_once(DOL_DOCUMENT_ROOT."/product/class/html.formproduct.class.php");
+                    $formproduct=new FormProduct($db);
+                    $formquestion=array(
+                    //'text' => $langs->trans("ConfirmClone"),
+                    //array('type' => 'checkbox', 'name' => 'clone_content',   'label' => $langs->trans("CloneMainAttributes"),   'value' => 1),
+                    //array('type' => 'checkbox', 'name' => 'update_prices',   'label' => $langs->trans("PuttingPricesUpToDate"),   'value' => 1),
+                    array('type' => 'other', 'name' => 'idwarehouse',   'label' => $langs->trans("SelectWarehouseForStockIncrease"),   'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1)));
+                }
+
+                $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Cancel'), $text, 'confirm_cancel', $formquestion, 0, 1);
             }
 
             /*
@@ -1605,7 +1636,7 @@ else
             if ($conf->projet->enabled) $nbrow++;
 
             //Local taxes
-            if ($mysoc->pays_code=='ES')
+            if ($mysoc->country_code=='ES')
             {
                 if($mysoc->localtax1_assuj=="1") $nbrow++;
                 if($mysoc->localtax2_assuj=="1") $nbrow++;
@@ -1873,17 +1904,17 @@ else
             print '<td>'.$langs->trans('Currency'.$conf->currency).'</td></tr>';
 
             // Amount Local Taxes
-            if ($mysoc->pays_code=='ES')
+            if ($mysoc->country_code=='ES')
             {
                 if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
                 {
-                    print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->pays_code).'</td>';
+                    print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
                     print '<td align="right">'.price($object->total_localtax1).'</td>';
                     print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
                 }
                 if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
                 {
-                    print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->pays_code).'</td>';
+                    print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>';
                     print '<td align="right">'.price($object->total_localtax2).'</td>';
                     print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
                 }
diff --git a/htdocs/compta/bank/bankid_fr.php b/htdocs/compta/bank/bankid_fr.php
index d482be44d34..63ea7faf7f4 100644
--- a/htdocs/compta/bank/bankid_fr.php
+++ b/htdocs/compta/bank/bankid_fr.php
@@ -218,7 +218,7 @@ if (($_GET["id"] || $_GET["ref"]) && $_GET["action"] != 'edit')
 
 		// Country
 		print '<tr><td valign="top">'.$langs->trans("BankAccountCountry").'</td><td colspan="3">';
-		$img=picto_from_langcode($account->pays_code);
+		$img=picto_from_langcode($account->country_code);
 		print $img?$img.' ':'';
 		print getCountry($account->getCountryCode(),0,$db);
 		print "</td></tr>\n";
diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php
index b27e00bc39e..6e6b3c98673 100644
--- a/htdocs/compta/bank/class/account.class.php
+++ b/htdocs/compta/bank/class/account.class.php
@@ -571,10 +571,10 @@ class Account extends CommonObject
 
         $sql = "SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant, ba.clos, ba.rappro, ba.url,";
         $sql.= " ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
-        $sql.= " ba.domiciliation, ba.proprio, ba.adresse_proprio, ba.fk_departement, ba.fk_pays,";
+        $sql.= " ba.domiciliation, ba.proprio, ba.adresse_proprio, ba.fk_departement, ba.fk_pays as country_id,";
         $sql.= " ba.account_number, ba.currency_code,";
         $sql.= " ba.min_allowed, ba.min_desired, ba.comment,";
-        $sql.= ' p.code as pays_code, p.libelle as pays,';
+        $sql.= ' p.code as country_code, p.libelle as country,';
         $sql.= ' d.code_departement as departement_code, d.nom as departement';
         $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
         $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_pays as p ON ba.fk_pays = p.rowid';
@@ -617,9 +617,12 @@ class Account extends CommonObject
                 $this->departement_code= $obj->departement_code;
                 $this->departement     = $obj->departement;
 
-                $this->fk_pays       = $obj->fk_pays;
-                $this->pays_code     = $obj->pays_code;
-                $this->pays          = $obj->pays;
+                $this->fk_pays       = $obj->country_id;
+                $this->pays_code     = $obj->country_code;
+                $this->pays          = $obj->country;
+                $this->country_id    = $obj->country_id;
+                $this->country_code  = $obj->country_code;
+                $this->country       = $obj->country;
 
                 $this->account_number = $obj->account_number;
 
@@ -942,12 +945,12 @@ class Account extends CommonObject
         global $mysoc;
 
         // We return country code of bank account
-        if (! empty($this->pays_code)) return $this->pays_code;
+        if (! empty($this->country_code)) return $this->country_code;
 
         // For backward compatibility, we try to guess country from other information
         if (! empty($this->iban))
         {
-            if ($mysoc->pays_code === 'IN') return $mysoc->pays_code;	// Test to know if we can trust IBAN
+            if ($mysoc->country_code === 'IN') return $mysoc->country_code;	// Test to know if we can trust IBAN
 
             // If IBAN defined, we can know country of account from it
             if (preg_match("/^([a-zA-Z][a-zA-Z])/i",$this->iban,$reg)) return $reg[1];
@@ -959,11 +962,11 @@ class Account extends CommonObject
             require_once(DOL_DOCUMENT_ROOT ."/societe/class/societe.class.php");
             $company=new Societe($this->db);
             $result=$company->fetch($this->socid);
-            if (! empty($company->pays_code)) return $company->pays_code;
+            if (! empty($company->country_code)) return $company->country_code;
         }
 
         // We return country code of managed company
-        if (! empty($mysoc->pays_code)) return $mysoc->pays_code;
+        if (! empty($mysoc->country_code)) return $mysoc->country_code;
 
         return '';
     }
diff --git a/htdocs/compta/bank/fiche.php b/htdocs/compta/bank/fiche.php
index 28d1bd7b4a4..aad626de33d 100644
--- a/htdocs/compta/bank/fiche.php
+++ b/htdocs/compta/bank/fiche.php
@@ -262,10 +262,10 @@ if ($action == 'create')
 	$selectedcode='';
 	if (isset($_POST["account_country_id"]))
 	{
-		$selectedcode=$_POST["account_country_id"]?$_POST["account_country_id"]:$account->pays_code;
+		$selectedcode=$_POST["account_country_id"]?$_POST["account_country_id"]:$account->country_code;
 	}
-	else if (empty($selectedcode)) $selectedcode=$mysoc->pays_code;
-	$form->select_pays($selectedcode,'account_country_id');
+	else if (empty($selectedcode)) $selectedcode=$mysoc->country_code;
+	print $form->select_country($selectedcode,'account_country_id');
 	if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
 	print '</td></tr>';
 
@@ -398,7 +398,7 @@ else
 		print '<tr><td>'.$langs->trans("Country").'</td><td>';
 		if ($account->fk_pays > 0)
 		{
-			$img=picto_from_langcode($account->pays_code);
+			$img=picto_from_langcode($account->country_code);
 			print $img?$img.' ':'';
 			print getCountry($account->getCountryCode(),0,$db);
 		}
@@ -530,13 +530,13 @@ else
         print '</td></tr>';
 
 		// Country
-		$account->pays_id=$account->pays_id?$account->pays_id:$mysoc->pays_id;
+		$account->country_id=$account->country_id?$account->country_id:$mysoc->country_id;
 		print '<tr><td valign="top" class="fieldrequired">'.$langs->trans("Country").'</td>';
 		print '<td colspan="3">';
-		$selectedcode=$account->pays_code;
+		$selectedcode=$account->country_code;
 		if (isset($_POST["account_country_id"])) $selectedcode=$_POST["account_country_id"];
-		else if (empty($selectedcode)) $selectedcode=$mysoc->pays_code;
-		$form->select_pays($selectedcode,'account_country_id');
+		else if (empty($selectedcode)) $selectedcode=$mysoc->country_code;
+		print $form->select_country($selectedcode,'account_country_id');
 		if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
 		print '</td></tr>';
 
@@ -544,7 +544,7 @@ else
 		print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">';
 		if ($selectedcode)
 		{
-			$formcompany->select_departement(isset($_POST["account_departement_id"])?$_POST["account_departement_id"]:$account->fk_departement,$selectedcode,'account_departement_id');
+			print $formcompany->select_state(isset($_POST["account_departement_id"])?$_POST["account_departement_id"]:$account->fk_departement,$selectedcode,'account_departement_id');
 		}
 		else
 		{
diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php
index 100d8e31b32..30071268484 100644
--- a/htdocs/compta/facture/prelevement.php
+++ b/htdocs/compta/facture/prelevement.php
@@ -366,17 +366,17 @@ if ($_REQUEST["facid"] > 0 || $_REQUEST["ref"])
         print '<td>'.$langs->trans('Currency'.$conf->currency).'</td></tr>';
 
         // Amount Local Taxes
-        if ($mysoc->pays_code=='ES')
+        if ($mysoc->country_code=='ES')
         {
             if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
             {
-                print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->pays_code).'</td>';
+                print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
                 print '<td align="right" colspan="2" nowrap>'.price($fac->total_localtax1).'</td>';
                 print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
             }
             if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
             {
-                print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->pays_code).'</td>';
+                print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>';
                 print '<td align="right" colspan="2" nowrap>'.price($fac->total_localtax2).'</td>';
                 print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
             }
diff --git a/htdocs/compta/localtax/clients.php b/htdocs/compta/localtax/clients.php
index 4e2f110e0ce..ce0dbf389d8 100644
--- a/htdocs/compta/localtax/clients.php
+++ b/htdocs/compta/localtax/clients.php
@@ -104,7 +104,7 @@ $fsearch.='  <input type="text" name="min" id="min" value="'.$min.'" size="6">';
 // Affiche en-tete du rapport
 if ($modetax==1)	// Calculate on invoice for goods and services
 {
-    $nom=$langs->transcountry("LT2ReportByCustomersInInputOutputMode",$mysoc->pays_code);
+    $nom=$langs->transcountry("LT2ReportByCustomersInInputOutputMode",$mysoc->country_code);
     $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
     $description=$langs->trans("RulesVATDue");
     if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
@@ -121,7 +121,7 @@ if ($modetax==1)	// Calculate on invoice for goods and services
 }
 if ($modetax==0) 	// Invoice for goods, payment for services
 {
-    $nom=$langs->transcountry("LT2ReportByCustomersInInputOutputMode",$mysoc->pays_code);
+    $nom=$langs->transcountry("LT2ReportByCustomersInInputOutputMode",$mysoc->country_code);
     $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
     $description=$langs->trans("RulesVATIn");
     if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
@@ -138,8 +138,8 @@ if ($modetax==0) 	// Invoice for goods, payment for services
 }
 report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
 
-$vatcust=$langs->transcountry("LT2",$mysoc->pays_code);
-$vatsup=$langs->transcountry("LT2",$mysoc->pays_code);
+$vatcust=$langs->transcountry("LT2",$mysoc->country_code);
+$vatsup=$langs->transcountry("LT2",$mysoc->country_code);
 
 // IRPF that the customer has retained me
 
@@ -147,7 +147,7 @@ print "<table class=\"noborder\" width=\"100%\">";
 print "<tr class=\"liste_titre\">";
 print '<td align="left">'.$langs->trans("Num")."</td>";
 print '<td align="left">'.$langs->trans("Customer")."</td>";
-print "<td>".$langs->transcountry("ProfId1",$mysoc->pays_code)."</td>";
+print "<td>".$langs->transcountry("ProfId1",$mysoc->country_code)."</td>";
 print "<td align=\"right\">".$langs->trans("TotalHT")."</td>";
 print "<td align=\"right\">".$vatcust."</td>";
 print "</tr>\n";
@@ -214,7 +214,7 @@ else
 print "<tr class=\"liste_titre\">";
 print '<td align="left">'.$langs->trans("Num")."</td>";
 print '<td align="left">'.$langs->trans("Supplier")."</td>";
-print "<td>".$langs->transcountry("ProfId1",$mysoc->pays_code)."</td>";
+print "<td>".$langs->transcountry("ProfId1",$mysoc->country_code)."</td>";
 print "<td align=\"right\">".$langs->trans("TotalHT")."</td>";
 print "<td align=\"right\">".$vatsup."</td>";
 print "</tr>\n";
diff --git a/htdocs/compta/localtax/fiche.php b/htdocs/compta/localtax/fiche.php
index 585fd9057e5..3f7bf5a37fe 100644
--- a/htdocs/compta/localtax/fiche.php
+++ b/htdocs/compta/localtax/fiche.php
@@ -147,7 +147,7 @@ if ($_GET["action"] == 'create')
     print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
     print '<input type="hidden" name="action" value="add">';
 
-    print_fiche_titre($langs->transcountry("newLT2Payment",$mysoc->pays_code));
+    print_fiche_titre($langs->transcountry("newLT2Payment",$mysoc->country_code));
 
     if ($mesg) print $mesg;
 
@@ -163,7 +163,7 @@ if ($_GET["action"] == 'create')
     print '</td></tr>';
 
 	// Label
-	print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" size="40" value="'.($_POST["label"]?$_POST["label"]:$langs->transcountry("LT2Payment",$mysoc->pays_code)).'"></td></tr>';
+	print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" size="40" value="'.($_POST["label"]?$_POST["label"]:$langs->transcountry("LT2Payment",$mysoc->country_code)).'"></td></tr>';
 
 	// Amount
 	print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.$_POST["amount"].'"></td></tr>';
diff --git a/htdocs/compta/localtax/index.php b/htdocs/compta/localtax/index.php
index 8f2239ebc59..c24638d8d72 100644
--- a/htdocs/compta/localtax/index.php
+++ b/htdocs/compta/localtax/index.php
@@ -119,8 +119,8 @@ print '<tr><td width="50%" valign="top">';
 print "<table class=\"noborder\" width=\"100%\">";
 print "<tr class=\"liste_titre\">";
 print "<td width=\"30%\">".$langs->trans("Year")." $y</td>";
-print "<td align=\"right\">".$langs->transcountry("LT2Customer",$mysoc->pays_code)."</td>";
-print "<td align=\"right\">".$langs->transcountry("LT2Supplier",$mysoc->pays_code)."</td>";
+print "<td align=\"right\">".$langs->transcountry("LT2Customer",$mysoc->country_code)."</td>";
+print "<td align=\"right\">".$langs->transcountry("LT2Supplier",$mysoc->country_code)."</td>";
 print "<td align=\"right\">".$langs->trans("TotalToPay")."</td>";
 print "<td>&nbsp;</td>\n";
 print "</tr>\n";
diff --git a/htdocs/compta/localtax/reglement.php b/htdocs/compta/localtax/reglement.php
index bcfc27194e0..6b3a96a92f0 100644
--- a/htdocs/compta/localtax/reglement.php
+++ b/htdocs/compta/localtax/reglement.php
@@ -40,7 +40,7 @@ llxHeader();
 
 $localtax_static = new localtax($db);
 
-print_fiche_titre($langs->transcountry("LT2Payments",$mysoc->pays_code));
+print_fiche_titre($langs->transcountry("LT2Payments",$mysoc->country_code));
 
 $sql = "SELECT rowid, amount, label, f.datev as dm";
 $sql.= " FROM ".MAIN_DB_PREFIX."localtax as f ";
diff --git a/htdocs/compta/prelevement/class/bon-prelevement.class.php b/htdocs/compta/prelevement/class/bon-prelevement.class.php
index a7275205caf..356d2d597af 100644
--- a/htdocs/compta/prelevement/class/bon-prelevement.class.php
+++ b/htdocs/compta/prelevement/class/bon-prelevement.class.php
@@ -1178,7 +1178,7 @@ class BonPrelevement extends CommonObject
         $this->file = fopen($this->filename,"w");
 
         //Build file for Spain
-        if ($mysoc->pays_code=='ES')
+        if ($mysoc->country_code=='ES')
         {
             if ($conf->esaeb->enabled)
             {
@@ -1270,7 +1270,7 @@ class BonPrelevement extends CommonObject
         }
 
         //Build file for France
-        elseif ($mysoc->pays_code=='FR')
+        elseif ($mysoc->country_code=='FR')
         {
             /*
              * En-tete Emetteur
diff --git a/htdocs/compta/propal.php b/htdocs/compta/propal.php
index 3a9b51b7fc6..6bf7088ec5f 100644
--- a/htdocs/compta/propal.php
+++ b/htdocs/compta/propal.php
@@ -181,7 +181,7 @@ if ($id > 0 || ! empty($ref))
 	if ($conf->projet->enabled) $rowspan++;
 
 	//Local taxes
-	if ($mysoc->pays_code=='ES')
+	if ($mysoc->country_code=='ES')
 	{
 		if($mysoc->localtax1_assuj=="1") $rowspan++;
 		if($mysoc->localtax2_assuj=="1") $rowspan++;
@@ -295,17 +295,17 @@ if ($id > 0 || ! empty($ref))
 	print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
 
 	// Amount Local Taxes
-	if ($mysoc->pays_code=='ES')
+	if ($mysoc->country_code=='ES')
 	{
 		if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
 		{
-			print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->pays_code).'</td>';
+			print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
 			print '<td align="right" colspan="2">'.price($object->total_localtax1).'</td>';
 			print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
 		}
 		if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
 		{
-			print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->pays_code).'</td>';
+			print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>';
 			print '<td align="right" colspan="2">'.price($object->total_localtax2).'</td>';
 			print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
 		}
diff --git a/htdocs/contact/canvas/actions_contactcard_common.class.php b/htdocs/contact/canvas/actions_contactcard_common.class.php
index f456f31b5a8..82d62cf598f 100644
--- a/htdocs/contact/canvas/actions_contactcard_common.class.php
+++ b/htdocs/contact/canvas/actions_contactcard_common.class.php
@@ -250,7 +250,7 @@ abstract class ActionsContactCardCommon
 			{
 				$this->tpl['ajax_selectcountry'] = "\n".'<script type="text/javascript" language="javascript">
 				jQuery(document).ready(function () {
-						jQuery("#selectpays_id").change(function() {
+						jQuery("#selectcountry_id").change(function() {
 							document.formsoc.action.value="'.$action.'";
 							document.formsoc.canvas.value="'.$canvas.'";
 							document.formsoc.submit();
@@ -284,21 +284,21 @@ abstract class ActionsContactCardCommon
         	}
 
             // Zip
-            $this->tpl['select_zip'] = $formcompany->select_ziptown($this->object->zip,'zipcode',array('town','selectpays_id','departement_id'),6);
+            $this->tpl['select_zip'] = $formcompany->select_ziptown($this->object->zip,'zipcode',array('town','selectcountry_id','departement_id'),6);
 
             // Town
-            $this->tpl['select_town'] = $formcompany->select_ziptown($this->object->town,'town',array('zipcode','selectpays_id','departement_id'));
+            $this->tpl['select_town'] = $formcompany->select_ziptown($this->object->town,'town',array('zipcode','selectcountry_id','departement_id'));
 
-            if (dol_strlen(trim($this->object->fk_pays)) == 0) $this->object->fk_pays = $objsoc->pays_id;
+            if (dol_strlen(trim($this->object->country_id)) == 0) $this->object->country_id = $objsoc->country_id;
 
             // Country
-            $this->tpl['select_country'] = $form->select_country($this->object->fk_pays,'pays_id');
+            $this->tpl['select_country'] = $form->select_country($this->object->country_id,'country_id');
             $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
 
             if ($user->admin) $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
 
             // State
-            if ($this->object->fk_pays) $this->tpl['select_state'] = $formcompany->select_state($this->object->fk_departement,$this->object->pays_code);
+            if ($this->object->country_id) $this->tpl['select_state'] = $formcompany->select_state($this->object->fk_departement,$this->object->country_code);
             else $this->tpl['select_state'] = $countrynotdefined;
 
             // Public or private
@@ -378,13 +378,13 @@ abstract class ActionsContactCardCommon
 
             $this->tpl['zip'] = ($this->object->zip?$this->object->zip.'&nbsp;':'');
 
-            $img=picto_from_langcode($this->object->pays_code);
-            $this->tpl['country'] = ($img?$img.' ':'').$this->object->pays;
+            $img=picto_from_langcode($this->object->country_code);
+            $this->tpl['country'] = ($img?$img.' ':'').$this->object->country;
 
-            $this->tpl['phone_pro'] 	= dol_print_phone($this->object->phone_pro,$this->object->pays_code,0,$this->object->id,'AC_TEL');
-            $this->tpl['phone_perso'] 	= dol_print_phone($this->object->phone_perso,$this->object->pays_code,0,$this->object->id,'AC_TEL');
-            $this->tpl['phone_mobile'] 	= dol_print_phone($this->object->phone_mobile,$this->object->pays_code,0,$this->object->id,'AC_TEL');
-            $this->tpl['fax'] 			= dol_print_phone($this->object->fax,$this->object->pays_code,0,$this->object->id,'AC_FAX');
+            $this->tpl['phone_pro'] 	= dol_print_phone($this->object->phone_pro,$this->object->country_code,0,$this->object->id,'AC_TEL');
+            $this->tpl['phone_perso'] 	= dol_print_phone($this->object->phone_perso,$this->object->country_code,0,$this->object->id,'AC_TEL');
+            $this->tpl['phone_mobile'] 	= dol_print_phone($this->object->phone_mobile,$this->object->country_code,0,$this->object->id,'AC_TEL');
+            $this->tpl['fax'] 			= dol_print_phone($this->object->fax,$this->object->country_code,0,$this->object->id,'AC_FAX');
             $this->tpl['email'] 		= dol_print_email($this->object->email,0,$this->object->id,'AC_EMAIL');
 
             $this->tpl['visibility'] = $this->object->LibPubPriv($this->object->priv);
@@ -430,8 +430,10 @@ abstract class ActionsContactCardCommon
         $this->object->address				=	$_POST["address"];
         $this->object->zip					=	$_POST["zipcode"];
         $this->object->town					=	$_POST["town"];
-        $this->object->fk_pays				=	$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id;
+        $this->object->fk_pays				=	$_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id;
         $this->object->fk_departement		=	$_POST["departement_id"];
+        $this->object->country_id			=	$_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id;
+        $this->object->state_id        		=	$_POST["departement_id"];
         $this->object->phone_pro			= 	$_POST["phone_pro"];
         $this->object->phone_perso			= 	$_POST["phone_perso"];
         $this->object->phone_mobile			= 	$_POST["phone_mobile"];
@@ -442,10 +444,10 @@ abstract class ActionsContactCardCommon
         $this->object->note					=	$_POST["note"];
         $this->object->canvas				=	$_POST["canvas"];
 
-        // We set pays_id, and pays_code label of the chosen country
-        if ($this->object->fk_pays)
+        // We set country_id, and country_code label of the chosen country
+        if ($this->object->country_id)
         {
-            $sql = "SELECT code, libelle FROM ".MAIN_DB_PREFIX."c_pays WHERE rowid = ".$this->object->fk_pays;
+            $sql = "SELECT code, libelle FROM ".MAIN_DB_PREFIX."c_pays WHERE rowid = ".$this->object->country_id;
             $resql=$this->db->query($sql);
             if ($resql)
             {
@@ -457,6 +459,8 @@ abstract class ActionsContactCardCommon
             }
             $this->object->pays_code	=	$obj->code;
             $this->object->pays			=	$langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->libelle;
+            $this->object->country_code	=	$obj->code;
+            $this->object->country		=	$langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->libelle;
         }
     }
 
diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php
index c37c500828f..fd857f0431d 100644
--- a/htdocs/contact/class/contact.class.php
+++ b/htdocs/contact/class/contact.class.php
@@ -57,6 +57,9 @@ class Contact extends CommonObject
 	var $fk_pays;				// Id of country
 	var $pays_code;				// Code of country
 	var $pays;					// Label of country
+	var $country_id;				// Id of country
+	var $country_code;				// Code of country
+	var $country;					// Label of country
 
 	var $socid;					// fk_soc
 	var $status;				// 0=brouillon, 1=4=actif, 5=inactif
@@ -214,6 +217,7 @@ class Contact extends CommonObject
 		$this->phone_perso=trim($this->phone_perso);
 		$this->phone_mobile=trim($this->phone_mobile);
 		$this->fax=trim($this->fax);
+		$this->country_id=($this->country_id > 0?$this->country_id:$this->fk_pays);
 
 		$this->db->begin();
 
@@ -226,7 +230,7 @@ class Contact extends CommonObject
 		$sql .= ", address='".$this->db->escape($this->address)."'";
 		$sql .= ", cp='".$this->db->escape($this->zip)."'";
 		$sql .= ", ville='".$this->db->escape($this->town)."'";
-		$sql .= ", fk_pays=".($this->fk_pays>0?$this->fk_pays:'NULL');
+		$sql .= ", fk_pays=".($this->country_id>0?$this->country_id:'NULL');
 		$sql .= ", fk_departement=".($this->fk_departement>0?$this->fk_departement:'NULL');
 		$sql .= ", poste='".$this->db->escape($this->poste)."'";
 		$sql .= ", fax='".$this->db->escape($this->fax)."'";
@@ -331,7 +335,7 @@ class Contact extends CommonObject
 		if ($this->address && $conf->global->LDAP_CONTACT_FIELD_ADDRESS) $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
 		if ($this->cp && $conf->global->LDAP_CONTACT_FIELD_ZIP)          $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->cp;
 		if ($this->ville && $conf->global->LDAP_CONTACT_FIELD_TOWN)      $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->ville;
-		if ($this->pays_code && $conf->global->LDAP_CONTACT_FIELD_COUNTRY)      $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->pays_code;
+		if ($this->country_code && $conf->global->LDAP_CONTACT_FIELD_COUNTRY)      $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
 		if ($this->phone_pro && $conf->global->LDAP_CONTACT_FIELD_PHONE) $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
 		if ($this->phone_perso && $conf->global->LDAP_CONTACT_FIELD_HOMEPHONE) $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
 		if ($this->phone_mobile && $conf->global->LDAP_CONTACT_FIELD_MOBILE) $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
@@ -488,12 +492,16 @@ class Contact extends CommonObject
 				$this->town				= $obj->ville;
 
 				$this->fk_departement	= $obj->fk_departement;
-				$this->departement_code = $obj->departement_code;
+				$this->state_id			= $obj->fk_departement;
+				$this->departement_code = $obj->departement_code;	// TODO deprecated
+				$this->state_code       = $obj->departement_code;
 				$this->departement		= $obj->departement;	// TODO deprecated
 				$this->state			= $obj->departement;
 
 				$this->fk_pays			= $obj->fk_pays;
+				$this->country_id 		= $obj->fk_pays;
 				$this->pays_code		= $obj->fk_pays?$obj->pays_code:'';
+				$this->country_code		= $obj->fk_pays?$obj->pays_code:'';
 				$this->pays				= ($obj->fk_pays > 0)?$langs->transnoentitiesnoconv("Country".$obj->pays_code):'';
 				$this->country			= ($obj->fk_pays > 0)?$langs->transnoentitiesnoconv("Country".$obj->pays_code):'';
 
diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php
index d4e44e2d2cf..487cc1788b8 100644
--- a/htdocs/contact/fiche.php
+++ b/htdocs/contact/fiche.php
@@ -136,8 +136,10 @@ if (empty($reshook))
         $object->address		= $_POST["address"];
         $object->zip			= $_POST["zipcode"];
         $object->town			= $_POST["town"];
-        $object->fk_pays		= $_POST["pays_id"];
+        $object->fk_pays		= $_POST["country_id"];
         $object->fk_departement = $_POST["departement_id"];
+        $object->country_id		= $_POST["country_id"];
+        $object->state_id       = $_POST["departement_id"];
         $object->email			= $_POST["email"];
         $object->phone_pro		= $_POST["phone_pro"];
         $object->phone_perso	= $_POST["phone_perso"];
@@ -227,7 +229,9 @@ if (empty($reshook))
             $object->zip			= $_POST["zipcode"];
             $object->town			= $_POST["town"];
             $object->fk_departement	= $_POST["departement_id"];
-            $object->fk_pays		= $_POST["pays_id"];
+            $object->fk_pays		= $_POST["country_id"];
+            $object->state_id   	= $_POST["departement_id"];
+            $object->country_id		= $_POST["country_id"];
 
             $object->email			= $_POST["email"];
             $object->phone_pro		= $_POST["phone_pro"];
@@ -332,24 +336,15 @@ else
 
             $object->fk_departement = $_POST["departement_id"];
 
-            // We set pays_id, pays_code and label for the selected country
-            $object->fk_pays=$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id;
-            if ($object->fk_pays)
+            // We set country_id, country_code and label for the selected country
+            $object->country_id=$_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id;
+            if ($object->country_id)
             {
-                $sql = "SELECT code, libelle";
-                $sql.= " FROM ".MAIN_DB_PREFIX."c_pays";
-                $sql.= " WHERE rowid = ".$object->fk_pays;
-                $resql=$db->query($sql);
-                if ($resql)
-                {
-                    $obj = $db->fetch_object($resql);
-                }
-                else
-                {
-                    dol_print_error($db);
-                }
-                $object->pays_code=$obj->code;
-                $object->pays=$obj->libelle;
+            	$tmparray=getCountry($object->country_id,'all');
+                $object->pays_code    = $tmparray['code'];
+                $object->pays         = $tmparray['label'];
+                $object->country_code = $tmparray['code'];
+                $object->country      = $tmparray['label'];
             }
 
             print_fiche_titre($langs->trans("AddContact"));
@@ -361,7 +356,7 @@ else
             {
                 print "\n".'<script type="text/javascript" language="javascript">';
                 print 'jQuery(document).ready(function () {
-							jQuery("#selectpays_id").change(function() {
+							jQuery("#selectcountry_id").change(function() {
 								document.formsoc.action.value="create";
 								document.formsoc.submit();
                         	});
@@ -416,14 +411,14 @@ else
             if (($objsoc->typent_code == 'TE_PRIVATE' || ! empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->zip)) == 0) $object->zip = $objsoc->zip;			// Predefined with third party
             if (($objsoc->typent_code == 'TE_PRIVATE' || ! empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->town)) == 0) $object->town = $objsoc->town;	// Predefined with third party
             print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td colspan="3">';
-            print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectpays_id','departement_id'),6).'&nbsp;';
-            print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectpays_id','departement_id'));
+            print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','departement_id'),6).'&nbsp;';
+            print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','departement_id'));
             print '</td></tr>';
 
             // Country
-            if (dol_strlen(trim($object->fk_pays)) == 0) $object->fk_pays = $objsoc->pays_id;	// Predefined with third party
+            if (dol_strlen(trim($object->fk_pays)) == 0) $object->fk_pays = $objsoc->country_id;	// Predefined with third party
             print '<tr><td>'.$langs->trans("Country").'</td><td colspan="3">';
-            $form->select_pays((isset($_POST["pays_id"])?$_POST["pays_id"]:$object->fk_pays),'pays_id');
+            print $form->select_country((isset($_POST["country_id"])?$_POST["country_id"]:$object->country_id),'country_id');
             if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
             print '</td></tr>';
 
@@ -431,9 +426,9 @@ else
             if (empty($conf->global->SOCIETE_DISABLE_STATE))
             {
                 print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">';
-                if ($object->fk_pays)
+                if ($object->country_id)
                 {
-                    $formcompany->select_departement(isset($_POST["departement_id"])?$_POST["departement_id"]:$object->fk_departement,$object->pays_code);
+                    print $formcompany->select_state(isset($_POST["departement_id"])?$_POST["departement_id"]:$object->fk_departement,$object->country_code);
                 }
                 else
                 {
@@ -519,21 +514,14 @@ else
              * Fiche en mode edition
              */
 
-            // We set pays_id, and pays_code label of the chosen country
-            if (isset($_POST["pays_id"]) || $object->fk_pays)
+            // We set country_id, and country_code label of the chosen country
+            if (isset($_POST["country_id"]) || $object->country_id)
             {
-                $sql = "SELECT code, libelle from ".MAIN_DB_PREFIX."c_pays where rowid = ".(isset($_POST["pays_id"])?$_POST["pays_id"]:$object->fk_pays);
-                $resql=$db->query($sql);
-                if ($resql)
-                {
-                    $obj = $db->fetch_object($resql);
-                }
-                else
-                {
-                    dol_print_error($db);
-                }
-                $object->pays_code=$obj->code;
-                $object->pays=$langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->libelle;
+	            $tmparray=getCountry($object->country_id,'all');
+	            $object->pays_code    =	$tmparray['code'];
+	            $object->pays         =	$tmparray['label'];
+	            $object->country_code =	$tmparray['code'];
+	            $object->country      =	$tmparray['label'];
             }
 
             // Affiche les erreurs
@@ -543,7 +531,7 @@ else
             {
                 print '<script type="text/javascript" language="javascript">';
                 print 'jQuery(document).ready(function () {
-							jQuery("#selectpays_id").change(function() {
+							jQuery("#selectcountry_id").change(function() {
 								document.formsoc.action.value="edit";
 								document.formsoc.submit();
 							});
@@ -592,13 +580,13 @@ else
 
             // Zip / Town
             print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td colspan="3">';
-            print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectpays_id','departement_id'),6).'&nbsp;';
-            print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectpays_id','departement_id'));
+            print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','departement_id'),6).'&nbsp;';
+            print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','departement_id'));
             print '</td></tr>';
 
             // Country
             print '<tr><td>'.$langs->trans("Country").'</td><td colspan="3">';
-            $form->select_pays(isset($_POST["pays_id"])?$_POST["pays_id"]:$object->fk_pays,'pays_id');
+            print $form->select_country(isset($_POST["country_id"])?$_POST["country_id"]:$object->country_id,'country_id');
             if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
             print '</td></tr>';
 
@@ -606,7 +594,7 @@ else
             if (empty($conf->global->SOCIETE_DISABLE_STATE))
             {
                 print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">';
-                $formcompany->select_departement($object->fk_departement,$object->pays_code);
+                print $formcompany->select_state($object->fk_departement,isset($_POST["country_id"])?$_POST["country_id"]:$object->country_id);
                 print '</td></tr>';
             }
 
@@ -785,7 +773,7 @@ else
 
         // Country
         print '<tr><td>'.$langs->trans("Country").'</td><td colspan="3">';
-        $img=picto_from_langcode($object->pays_code);
+        $img=picto_from_langcode($object->country_code);
         if ($img) print $img.' ';
         print $object->pays;
         print '</td></tr>';
@@ -797,11 +785,11 @@ else
         }
 
         // Phone
-        print '<tr><td>'.$langs->trans("PhonePro").'</td><td>'.dol_print_phone($object->phone_pro,$object->pays_code,$object->id,$object->socid,'AC_TEL').'</td>';
-        print '<td>'.$langs->trans("PhonePerso").'</td><td>'.dol_print_phone($object->phone_perso,$object->pays_code,$object->id,$object->socid,'AC_TEL').'</td></tr>';
+        print '<tr><td>'.$langs->trans("PhonePro").'</td><td>'.dol_print_phone($object->phone_pro,$object->country_code,$object->id,$object->socid,'AC_TEL').'</td>';
+        print '<td>'.$langs->trans("PhonePerso").'</td><td>'.dol_print_phone($object->phone_perso,$object->country_code,$object->id,$object->socid,'AC_TEL').'</td></tr>';
 
-        print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td>'.dol_print_phone($object->phone_mobile,$object->pays_code,$object->id,$object->socid,'AC_TEL').'</td>';
-        print '<td>'.$langs->trans("Fax").'</td><td>'.dol_print_phone($object->fax,$object->pays_code,$object->id,$object->socid,'AC_FAX').'</td></tr>';
+        print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td>'.dol_print_phone($object->phone_mobile,$object->country_code,$object->id,$object->socid,'AC_TEL').'</td>';
+        print '<td>'.$langs->trans("Fax").'</td><td>'.dol_print_phone($object->fax,$object->country_code,$object->id,$object->socid,'AC_FAX').'</td></tr>';
 
         // Email
         print '<tr><td>'.$langs->trans("EMail").'</td><td>'.dol_print_email($object->email,$object->id,$object->socid,'AC_EMAIL').'</td>';
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 70c61bc5891..dfd61738c86 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -513,7 +513,7 @@ class Form
 
     /**
      *		Return list of social contributions.
-     * 		Use mysoc->pays_id or mysoc->pays_code so they must be defined.
+     * 		Use mysoc->country_id or mysoc->country_code so they must be defined.
      *
      *		@param      selected        Preselected type
      *		@param      htmlname        Name of field in form
@@ -525,18 +525,18 @@ class Form
     {
         global $db,$langs,$user,$mysoc;
 
-        if (empty($mysoc->pays_id) && empty($mysoc->pays_code))
+        if (empty($mysoc->country_id) && empty($mysoc->country_code))
         {
             dol_print_error('','Call to select_type_socialcontrib with mysoc country not yet defined');
             exit;
         }
 
-        if (! empty($mysoc->pays_id))
+        if (! empty($mysoc->country_id))
         {
             $sql = "SELECT c.id, c.libelle as type";
             $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
             $sql.= " WHERE c.active = 1";
-            $sql.= " AND c.fk_pays = ".$mysoc->pays_id;
+            $sql.= " AND c.fk_pays = ".$mysoc->country_id;
             $sql.= " ORDER BY c.libelle ASC";
         }
         else
@@ -544,7 +544,7 @@ class Form
             $sql = "SELECT c.id, c.libelle as type";
             $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."c_pays as p";
             $sql.= " WHERE c.active = 1 AND c.fk_pays = p.rowid";
-            $sql.= " AND p.code = '".$mysoc->pays_code."'";
+            $sql.= " AND p.code = '".$mysoc->country_code."'";
             $sql.= " ORDER BY c.libelle ASC";
         }
 
@@ -572,7 +572,7 @@ class Form
             }
             else
             {
-                print $langs->trans("ErrorNoSocialContributionForSellerCountry",$mysoc->pays_code);
+                print $langs->trans("ErrorNoSocialContributionForSellerCountry",$mysoc->country_code);
             }
         }
         else
@@ -3018,7 +3018,7 @@ class Form
         $defaulttx=str_replace('*','',$selectedrate);
 
         // Check parameters
-        if (is_object($societe_vendeuse) && ! $societe_vendeuse->pays_code)
+        if (is_object($societe_vendeuse) && ! $societe_vendeuse->country_code)
         {
             if ($societe_vendeuse->id == $mysoc->id)
             {
@@ -3032,18 +3032,18 @@ class Form
         }
 
         //var_dump($societe_acheteuse);
-        //print "name=$name, selectedrate=$selectedrate, seller=".$societe_vendeuse->pays_code." buyer=".$societe_acheteuse->pays_code." buyer is company=".$societe_acheteuse->isACompany()." idprod=$idprod, info_bits=$info_bits type=$type";
+        //print "name=$name, selectedrate=$selectedrate, seller=".$societe_vendeuse->country_code." buyer=".$societe_acheteuse->country_code." buyer is company=".$societe_acheteuse->isACompany()." idprod=$idprod, info_bits=$info_bits type=$type";
         //exit;
 
         // Get list of all VAT rates to show
         // First we defined code_pays to use to find list
         if (is_object($societe_vendeuse))
         {
-            $code_pays="'".$societe_vendeuse->pays_code."'";
+            $code_pays="'".$societe_vendeuse->country_code."'";
         }
         else
         {
-            $code_pays="'".$mysoc->pays_code."'";   // Pour compatibilite ascendente
+            $code_pays="'".$mysoc->country_code."'";   // Pour compatibilite ascendente
         }
         if (! empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC))    // If option to have vat for end customer for services is on
         {
@@ -3054,12 +3054,12 @@ class Form
                 {
                     if ($type == 1) // We know product is a service
                     {
-                        $code_pays.=",'".$societe_acheteuse->pays_code."'";
+                        $code_pays.=",'".$societe_acheteuse->country_code."'";
                     }
                 }
                 else if (! $idprod)  // We don't know type of product
                 {
-                    $code_pays.=",'".$societe_acheteuse->pays_code."'";
+                    $code_pays.=",'".$societe_acheteuse->country_code."'";
                 }
                 else
                 {
@@ -3067,7 +3067,7 @@ class Form
                     $prodstatic->fetch($idprod);
                     if ($prodstatic->type == 1)   // We know product is a service
                     {
-                        $code_pays.=",'".$societe_acheteuse->pays_code."'";
+                        $code_pays.=",'".$societe_acheteuse->country_code."'";
                     }
                 }
             }
diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php
index b0247ad25aa..7d2d4cc98a5 100644
--- a/htdocs/core/class/html.formcompany.class.php
+++ b/htdocs/core/class/html.formcompany.class.php
@@ -190,32 +190,34 @@ class FormCompany
 	}
 
 	/**
-	 *    \brief      Retourne la liste deroulante des departements/province/cantons tout pays confondu ou pour un pays donne.
-	 *    \remarks    Dans le cas d'une liste tout pays confondus, l'affichage fait une rupture sur le pays.
-	 *    \remarks    La cle de la liste est le code (il peut y avoir plusieurs entree pour
-	 *                un code donnee mais dans ce cas, le champ pays differe).
-	 *                Ainsi les liens avec les departements se font sur un departement independemment de son nom.
-	 *    \param      selected        	Code state preselected
-	 *    \param      pays_code       	0=list for all countries, otherwise country code or country rowid to show
-	 *    \param      departement_id	Id of department
+	 *    Retourne la liste deroulante des departements/province/cantons tout pays confondu ou pour un pays donne.
+	 *    Dans le cas d'une liste tout pays confondus, l'affichage fait une rupture sur le pays.
+	 *    La cle de la liste est le code (il peut y avoir plusieurs entree pour
+	 *    un code donnee mais dans ce cas, le champ pays differe).
+	 *    Ainsi les liens avec les departements se font sur un departement independemment de son nom.
+	 * 
+	 *    @param	string	$selected        	Code state preselected
+	 *    @param    string	$country_codeid    	Country code or id: 0=list for all countries, otherwise country code or country rowid to show
+	 *    @param    int		$departement_id		Id of department
+	 * 	  @return	void
 	 */
-	function select_state($selected='',$pays_code=0, $htmlname='departement_id')
+	function select_state($selected='',$country_codeid=0, $htmlname='departement_id')
 	{
 		global $conf,$langs,$user;
 
-		dol_syslog("FormCompany::select_departement selected=$selected, pays_code=$pays_code",LOG_DEBUG);
+		dol_syslog("FormCompany::select_departement selected=$selected, country_codeid=$country_codeid",LOG_DEBUG);
 
 		$langs->load("dict");
 
 		$out='';
 
 		// On recherche les departements/cantons/province active d'une region et pays actif
-		$sql = "SELECT d.rowid, d.code_departement as code , d.nom, d.active, p.libelle as libelle_pays, p.code as code_pays FROM";
+		$sql = "SELECT d.rowid, d.code_departement as code , d.nom, d.active, p.libelle as libelle_pays, p.code as country_code FROM";
 		$sql .= " ".MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_pays as p";
 		$sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=p.rowid";
 		$sql .= " AND d.active = 1 AND r.active = 1 AND p.active = 1";
-		if ($pays_code && is_numeric($pays_code)) $sql .= " AND p.rowid = '".$pays_code."'";
-		if ($pays_code && ! is_numeric($pays_code)) $sql .= " AND p.code = '".$pays_code."'";
+		if ($country_codeid && is_numeric($country_codeid)) $sql .= " AND p.rowid = '".$country_codeid."'";
+		if ($country_codeid && ! is_numeric($country_codeid)) $sql .= " AND p.code = '".$country_codeid."'";
 		$sql .= " ORDER BY p.code, d.code_departement";
 
 		dol_syslog("FormCompany::select_departement sql=".$sql);
@@ -223,10 +225,10 @@ class FormCompany
 		if ($result)
 		{
 			if (!empty($htmlname)) $out.= '<select id="'.$htmlname.'" class="flat" name="'.$htmlname.'">';
-			if ($pays_code) $out.= '<option value="0">&nbsp;</option>';
+			if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';
 			$num = $this->db->num_rows($result);
 			$i = 0;
-			dol_syslog("FormCompany::select_departement num=$num",LOG_DEBUG);
+			dol_syslog("FormCompany::select_departement num=".$num,LOG_DEBUG);
 			if ($num)
 			{
 				$pays='';
@@ -241,7 +243,7 @@ class FormCompany
 						if (! $pays || $pays != $obj->libelle_pays)
 						{
 							// Affiche la rupture si on est en mode liste multipays
-							if (! $pays_code && $obj->code_pays)
+							if (! $country_codeid && $obj->country_code)
 							{
 								$out.= '<option value="-1" disabled="disabled">----- '.$obj->libelle_pays." -----</option>\n";
 								$pays=$obj->libelle_pays;
@@ -288,7 +290,7 @@ class FormCompany
 		global $conf,$langs;
 		$langs->load("dict");
 
-		$sql = "SELECT r.rowid, r.code_region as code, r.nom as libelle, r.active, p.code as pays_code, p.libelle as libelle_pays FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_pays as p";
+		$sql = "SELECT r.rowid, r.code_region as code, r.nom as libelle, r.active, p.code as country_code, p.libelle as country FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_pays as p";
 		$sql .= " WHERE r.fk_pays=p.rowid AND r.active = 1 and p.active = 1 ORDER BY pays_code, libelle ASC";
 
 		dol_syslog("Form::select_region sql=".$sql);
@@ -308,13 +310,13 @@ class FormCompany
 						print '<option value="0">&nbsp;</option>';
 					}
 					else {
-						if ($pays == '' || $pays != $obj->libelle_pays)
+						if ($pays == '' || $pays != $obj->country)
 						{
 							// Show break
-							$key=$langs->trans("Country".strtoupper($obj->pays_code));
-							$valuetoshow=($key != "Country".strtoupper($obj->pays_code))?$obj->pays_code." - ".$key:$obj->libelle_pays;
+							$key=$langs->trans("Country".strtoupper($obj->country_code));
+							$valuetoshow=($key != "Country".strtoupper($obj->country_code))?$obj->country_code." - ".$key:$obj->country;
 							print '<option value="-1" disabled="disabled">----- '.$valuetoshow." -----</option>\n";
-							$pays=$obj->libelle_pays;
+							$pays=$obj->country;
 						}
 
 						if ($selected > 0 && $selected == $obj->code)
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 9bae445901f..113818a21bb 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -3319,14 +3319,14 @@ function get_default_tva($societe_vendeuse, $societe_acheteuse, $idprod=0)
         return 0;
     }
 
-    //if (is_object($societe_acheteuse) && ($societe_vendeuse->pays_id == $societe_acheteuse->pays_id) && ($societe_acheteuse->tva_assuj == 1 || $societe_acheteuse->tva_assuj == 'reel'))
+    //if (is_object($societe_acheteuse) && ($societe_vendeuse->country_id == $societe_acheteuse->country_id) && ($societe_acheteuse->tva_assuj == 1 || $societe_acheteuse->tva_assuj == 'reel'))
     // Le test ci-dessus ne devrait pas etre necessaire. Me signaler l'exemple du cas juridique concerne si le test suivant n'est pas suffisant.
 
     // Si le (pays vendeur = pays acheteur) alors la TVA par defaut=TVA du produit vendu. Fin de regle.
-    if ($societe_vendeuse->pays_code == $societe_acheteuse->pays_code) // Warning ->pays_code not always defined
+    if ($societe_vendeuse->country_code == $societe_acheteuse->country_code) // Warning ->country_code not always defined
     {
         //print 'VATRULE 3';
-        return get_product_vat_for_country($idprod,$societe_vendeuse->pays_code);
+        return get_product_vat_for_country($idprod,$societe_vendeuse->country_code);
     }
 
     // Si (vendeur et acheteur dans Communaute europeenne) et (bien vendu = moyen de transports neuf comme auto, bateau, avion) alors TVA par defaut=0 (La TVA doit etre paye par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de regle.
@@ -3345,7 +3345,7 @@ function get_default_tva($societe_vendeuse, $societe_acheteuse, $idprod=0)
         else
         {
             //print 'VATRULE 5';
-            return get_product_vat_for_country($idprod,$societe_vendeuse->pays_code);
+            return get_product_vat_for_country($idprod,$societe_vendeuse->country_code);
         }
     }
 
@@ -3357,7 +3357,7 @@ function get_default_tva($societe_vendeuse, $societe_acheteuse, $idprod=0)
         if (! $societe_vendeuse->isInEEC() && $societe_acheteuse->isInEEC() && ! $societe_acheteuse->isACompany())
         {
             //print 'VATRULE 6';
-            return get_product_vat_for_country($idprod,$societe_acheteuse->pays_code);
+            return get_product_vat_for_country($idprod,$societe_acheteuse->country_code);
         }
     }
 
@@ -3395,7 +3395,7 @@ function get_default_localtax($societe_vendeuse, $societe_acheteuse, $local, $id
     if (!is_object($societe_vendeuse)) return -1;
     if (!is_object($societe_acheteuse)) return -1;
 
-    if ($societe_vendeuse->pays_id=='ES' || $societe_vendeuse->pays_code=='ES')
+    if ($societe_vendeuse->country_id=='ES' || $societe_vendeuse->country_code=='ES')
     {
         if ($local==1) //RE
         {
@@ -3410,7 +3410,7 @@ function get_default_localtax($societe_vendeuse, $societe_acheteuse, $local, $id
             if (! is_numeric($societe_vendeuse->localtax2_assuj) && $societe_vendeuse->localtax2_assuj=='localtax2off') return 0;
         } else return -1;
 
-        if ($idprod) return get_product_localtax_for_country($idprod, $local, $societe_vendeuse->pays_code);
+        if ($idprod) return get_product_localtax_for_country($idprod, $local, $societe_vendeuse->country_code);
         else return -1;
     }
     return 0;
diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php
index 0a304401647..37b7728791b 100644
--- a/htdocs/core/lib/pdf.lib.php
+++ b/htdocs/core/lib/pdf.lib.php
@@ -209,13 +209,13 @@ function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$target
 			$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs,1));
 			$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcontact))."\n";
 			// Country
-			if ($targetcontact->pays_code && $targetcontact->pays_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->pays_code))."\n";
+			if ($targetcontact->country_code && $targetcontact->country_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->pays_code))."\n";
 		}
 		else
 		{
 			$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcompany))."\n";
 			// Country
-			if ($targetcompany->pays_code && $targetcompany->pays_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->pays_code))."\n";
+			if ($targetcompany->country_code && $targetcompany->country_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->pays_code))."\n";
 		}
 
 		// Intra VAT
@@ -224,25 +224,25 @@ function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$target
 		// Professionnal Ids
 		if ($conf->global->MAIN_PROFID1_IN_ADDRESS)
 		{
-			$tmp=$outputlangs->transcountrynoentities("ProfId1",$targetcompany->pays_code);
+			$tmp=$outputlangs->transcountrynoentities("ProfId1",$targetcompany->country_code);
 			if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
 			$stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof1);
 		}
 		if ($conf->global->MAIN_PROFID2_IN_ADDRESS)
 		{
-			$tmp=$outputlangs->transcountrynoentities("ProfId2",$targetcompany->pays_code);
+			$tmp=$outputlangs->transcountrynoentities("ProfId2",$targetcompany->country_code);
 			if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
 			$stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof2);
 		}
 		if ($conf->global->MAIN_PROFID3_IN_ADDRESS)
 		{
-			$tmp=$outputlangs->transcountrynoentities("ProfId3",$targetcompany->pays_code);
+			$tmp=$outputlangs->transcountrynoentities("ProfId3",$targetcompany->country_code);
 			if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
 			$stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof3);
 		}
 		if ($conf->global->MAIN_PROFID4_IN_ADDRESS)
 		{
-			$tmp=$outputlangs->transcountrynoentities("ProfId4",$targetcompany->pays_code);
+			$tmp=$outputlangs->transcountrynoentities("ProfId4",$targetcompany->country_code);
 			if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
 			$stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof4);
 		}
@@ -563,16 +563,16 @@ function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_bass
 		$line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf",$fromcompany->capital)." ".$outputlangs->transnoentities("Currency".$conf->currency);
 	}
 	// Prof Id 1
-	if ($fromcompany->idprof1 && ($fromcompany->pays_code != 'FR' || ! $fromcompany->idprof2))
+	if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
 	{
-		$field=$outputlangs->transcountrynoentities("ProfId1",$fromcompany->pays_code);
+		$field=$outputlangs->transcountrynoentities("ProfId1",$fromcompany->country_code);
 		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
 		$line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof1);
 	}
 	// Prof Id 2
 	if ($fromcompany->idprof2)
 	{
-		$field=$outputlangs->transcountrynoentities("ProfId2",$fromcompany->pays_code);
+		$field=$outputlangs->transcountrynoentities("ProfId2",$fromcompany->country_code);
 		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
 		$line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof2);
 	}
@@ -582,14 +582,14 @@ function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_bass
 	// Prof Id 3
 	if ($fromcompany->idprof3)
 	{
-		$field=$outputlangs->transcountrynoentities("ProfId3",$fromcompany->pays_code);
+		$field=$outputlangs->transcountrynoentities("ProfId3",$fromcompany->country_code);
 		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
 		$line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof3);
 	}
 	// Prof Id 4
 	if ($fromcompany->idprof4)
 	{
-		$field=$outputlangs->transcountrynoentities("ProfId4",$fromcompany->pays_code);
+		$field=$outputlangs->transcountrynoentities("ProfId4",$fromcompany->country_code);
 		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
 		$line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof4);
 	}
diff --git a/htdocs/core/lib/price.lib.php b/htdocs/core/lib/price.lib.php
index 6c2eb310525..caaeb2e6ca1 100644
--- a/htdocs/core/lib/price.lib.php
+++ b/htdocs/core/lib/price.lib.php
@@ -116,7 +116,7 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $txlocalta
 		$result[12] = price2num(($pu * (1 + ( $txlocaltax2 / 100))) - $pu, 'MT');
 
 		//If Country is Spain, localtax2 (IRPF) will be subtracted
-		if ($mysoc->pays_code=='ES')
+		if ($mysoc->country_code=='ES')
 		{
 			$result[8] = $result[8] - $result[15];
 			$result[2] = $result[2] - $result[10];
diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php
index e78341b70fb..9d7f4df5918 100644
--- a/htdocs/core/menus/standard/eldy.lib.php
+++ b/htdocs/core/menus/standard/eldy.lib.php
@@ -944,9 +944,9 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after)
                     global $mysoc;
 
                     //Local Taxes
-                    if($mysoc->pays_code=='ES' && $mysoc->localtax2_assuj=="1")
+                    if($mysoc->country_code=='ES' && $mysoc->localtax2_assuj=="1")
                     {
-                    	if (preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/index.php?leftmenu=tax_vat&amp;mainmenu=accountancy",$langs->transcountry("LT2",$mysoc->pays_code),1,$user->rights->tax->charges->lire);
+                    	if (preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/index.php?leftmenu=tax_vat&amp;mainmenu=accountancy",$langs->transcountry("LT2",$mysoc->country_code),1,$user->rights->tax->charges->lire);
                     	if (preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/fiche.php?leftmenu=tax_vat&action=create",$langs->trans("NewPayment"),2,$user->rights->tax->charges->creer);
                     	if (preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/reglement.php?leftmenu=tax_vat",$langs->trans("Payments"),2,$user->rights->tax->charges->lire);
                     	if (preg_match('/^tax/i',$leftmenu)) $newmenu->add("/compta/localtax/clients.php?leftmenu=tax_vat", $langs->trans("ReportByCustomers"), 2, $user->rights->tax->charges->lire);
diff --git a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php
index 1831e4cff2c..657095da255 100644
--- a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php
+++ b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php
@@ -71,7 +71,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc
 
 		// Recupere emmetteur
 		$this->emetteur=$mysoc;
-		if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2);    // Par defaut, si n'etait pas defini
+		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // Par defaut, si n'etait pas defini
 	}
 
 
diff --git a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php
index 1cdcc83c2f1..dd039c62ccc 100755
--- a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php
+++ b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php
@@ -94,7 +94,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
         // Get source company
         if (! is_object($object->thirdparty)) $object->fetch_thirdparty();
         $this->emetteur=$object->thirdparty;
-        if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2);    // By default, if was not defined
+        if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
 
         // Defini position des colonnes
 		$this->posxdesc=$this->marge_gauche+1;
@@ -408,7 +408,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
 
 		$pdf->SetXY($this->marge_gauche, $tab2_top + 0);
 		// If France, show VAT mention if not applicable
-		if ($this->emetteur->pays_code == 'FR' && $this->franchise == 1)
+		if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
 		{
 			$pdf->MultiCell(100, $tab2_hl, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
 		}
@@ -465,7 +465,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
 			{
 				$index++;
 				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT1".$mysoc->pays_code), 0, 'L', 1);
+				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT1".$mysoc->country_code), 0, 'L', 1);
 				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
 				$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), 0, 'R', 1);
 			}
@@ -475,7 +475,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
 			{
 				$index++;
 				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT2".$mysoc->pays_code), 0, 'L', 1);
+				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT2".$mysoc->country_code), 0, 'L', 1);
 				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
 				$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), 0, 'R', 1);
 			}
@@ -500,7 +500,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
 							$tvakey=str_replace('*','',$tvakey);
 							$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
 						}
-						$totalvat =$outputlangs->transnoentities("TotalLT1".$mysoc->pays_code).' ';
+						$totalvat =$outputlangs->transnoentities("TotalLT1".$mysoc->country_code).' ';
 						$totalvat.=vatrate($tvakey,1).$tvacompl;
 						$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
 
diff --git a/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php b/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php
index 846c3de4c16..dc1b53ab67c 100644
--- a/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php
+++ b/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php
@@ -95,7 +95,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 
 		// Recupere emmetteur
 		$this->emetteur=$mysoc;
-		if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2);    // Par defaut, si n'etait pas defini
+		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // Par defaut, si n'etait pas defini
 
 		// Defini position des colonnes
 		$this->posxdesc=$this->marge_gauche+1;
@@ -409,7 +409,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 		$pdf->SetXY($this->marge_gauche, $tab2_top + 0);
 
 		// If France, show VAT mention if not applicable
-		if ($this->emetteur->pays_code == 'FR' && $this->franchise == 1)
+		if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
 		{
 			$pdf->MultiCell(100, $tab2_hl, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
 		}
@@ -468,7 +468,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 			{
 				$index++;
 				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT1".$mysoc->pays_code), 0, 'L', 1);
+				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT1".$mysoc->country_code), 0, 'L', 1);
 				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
 				$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), 0, 'R', 1);
 			}
@@ -478,7 +478,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 			{
 				$index++;
 				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
-				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT2".$mysoc->pays_code), 0, 'L', 1);
+				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT2".$mysoc->country_code), 0, 'L', 1);
 				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
 				$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), 0, 'R', 1);
 			}
@@ -503,7 +503,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 							$tvakey=str_replace('*','',$tvakey);
 							$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
 						}
-						$totalvat =$outputlangs->transnoentities("TotalLT1".$mysoc->pays_code).' ';
+						$totalvat =$outputlangs->transnoentities("TotalLT1".$mysoc->country_code).' ';
 						$totalvat.=vatrate($tvakey,1).$tvacompl;
 						$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
 
@@ -531,7 +531,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 							$tvakey=str_replace('*','',$tvakey);
 							$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
 						}
-						$totalvat =$outputlangs->transnoentities("TotalLT2".$mysoc->pays_code).' ';
+						$totalvat =$outputlangs->transnoentities("TotalLT2".$mysoc->country_code).' ';
 						$totalvat.=vatrate($tvakey,1).$tvacompl;
 						$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
 
diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php
index 2a3038f298a..0613ba96248 100644
--- a/htdocs/fourn/commande/fiche.php
+++ b/htdocs/fourn/commande/fiche.php
@@ -923,7 +923,7 @@ if ($id > 0 || ! empty($ref))
         if ($conf->projet->enabled)	$nbrow++;
 
         //Local taxes
-        if ($mysoc->pays_code=='ES')
+        if ($mysoc->country_code=='ES')
         {
             if($mysoc->localtax1_assuj=="1") $nbrow++;
             if($mysoc->localtax2_assuj=="1") $nbrow++;
@@ -1050,17 +1050,17 @@ if ($id > 0 || ! empty($ref))
         print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
 
         // Amount Local Taxes
-        if ($mysoc->pays_code=='ES')
+        if ($mysoc->country_code=='ES')
         {
             if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
             {
-                print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->pays_code).'</td>';
+                print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
                 print '<td align="right">'.price($object->total_localtax1).'</td>';
                 print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
             }
             if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
             {
-                print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->pays_code).'</td>';
+                print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>';
                 print '<td align="right">'.price($object->total_localtax2).'</td>';
                 print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
             }
diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php
index fc173d0ec6e..e90393bdb15 100644
--- a/htdocs/fourn/facture/fiche.php
+++ b/htdocs/fourn/facture/fiche.php
@@ -1093,16 +1093,16 @@ if ($action == 'create')
         print '<tr><td>'.$txt.'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
         print '<tr><td>'.$langs->trans('TotalHT').'</td><td colspan="2">'.price($objectsrc->total_ht).'</td></tr>';
         print '<tr><td>'.$langs->trans('TotalVAT').'</td><td colspan="2">'.price($objectsrc->total_tva)."</td></tr>";
-        if ($mysoc->pays_code=='ES')
+        if ($mysoc->country_code=='ES')
         {
             if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
             {
-                print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->pays_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
+                print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
             }
 
             if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
             {
-                print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->pays_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
+                print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
             }
         }
         print '<tr><td>'.$langs->trans('TotalTTC').'</td><td colspan="2">'.price($objectsrc->total_ttc)."</td></tr>";
@@ -1315,7 +1315,7 @@ else
         if ($conf->projet->enabled) $nbrows++;
 
         // Local taxes
-        if ($mysoc->pays_code=='ES')
+        if ($mysoc->country_code=='ES')
         {
             if($mysoc->localtax1_assuj=="1") $nbrow++;
             if($mysoc->localtax2_assuj=="1") $nbrow++;
@@ -1406,17 +1406,17 @@ else
         print '<tr><td>'.$langs->trans('AmountVAT').'</td><td align="right">'.price($object->total_tva).'</td><td colspan="2" align="left">'.$langs->trans('Currency'.$conf->currency).'</td></tr>';
 
         // Amount Local Taxes
-        if ($mysoc->pays_code=='ES')
+        if ($mysoc->country_code=='ES')
         {
             if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
             {
-                print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->pays_code).'</td>';
+                print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
                 print '<td align="right">'.price($object->total_localtax1).'</td>';
                 print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
             }
             if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
             {
-                print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->pays_code).'</td>';
+                print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>';
                 print '<td align="right">'.price($object->total_localtax2).'</td>';
                 print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
             }
diff --git a/htdocs/langs/en_US/agenda.lang b/htdocs/langs/en_US/agenda.lang
index 8a28ba667bc..97523809dc3 100644
--- a/htdocs/langs/en_US/agenda.lang
+++ b/htdocs/langs/en_US/agenda.lang
@@ -39,6 +39,7 @@ InvoiceBackToDraftInDolibarr=Invoice %s go back to draft status
 OrderValidatedInDolibarr= Order %s validated
 OrderApprovedInDolibarr=Order %s approved
 OrderBackToDraftInDolibarr=Order %s go back to draft status
+OrderCanceledInDolibarr=Order %s canceled
 InterventionValidatedInDolibarr=Intervention %s validated
 ProposalSentByEMail=Commercial proposal %s sent by EMail
 OrderSentByEMail=Customer order %s sent by EMail
diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang
index 191fe83bf9e..c41523584a2 100644
--- a/htdocs/langs/en_US/companies.lang
+++ b/htdocs/langs/en_US/companies.lang
@@ -220,6 +220,7 @@ DiscountNone=None
 Supplier=Supplier
 CompanyList=Company's list
 AddContact=Add contact/address
+EditContact=Edit contact/address
 Contact=Contact
 ContactsAddresses=Contacts/Addresses
 NoContactDefined=No contact defined for this third party
diff --git a/htdocs/langs/fr_FR/agenda.lang b/htdocs/langs/fr_FR/agenda.lang
index b4ef15f0ae9..88f5446531e 100644
--- a/htdocs/langs/fr_FR/agenda.lang
+++ b/htdocs/langs/fr_FR/agenda.lang
@@ -39,6 +39,7 @@ InvoiceBackToDraftInDolibarr=Facture %s repassée en brouillon
 OrderValidatedInDolibarr=Commande %s validée
 OrderApprovedInDolibarr=Commande %s approuvée
 OrderBackToDraftInDolibarr=Commande %s repassée en brouillon
+OrderCanceledInDolibarr=Commande %s annulée
 InterventionValidatedInDolibarr=Intervention %s validée
 ProposalSentByEMail=Proposition commerciale %s envoyée par EMail
 OrderSentByEMail=Commande client %s envoyée par EMail
diff --git a/htdocs/langs/fr_FR/companies.lang b/htdocs/langs/fr_FR/companies.lang
index f7877936f52..28a53fe89ac 100644
--- a/htdocs/langs/fr_FR/companies.lang
+++ b/htdocs/langs/fr_FR/companies.lang
@@ -222,6 +222,7 @@ DiscountNone=Aucune
 Supplier=Fournisseur
 CompanyList=Liste des sociétés
 AddContact=Créer contact/adresse
+EditContact=Editer contact/adresse
 Contact=Contact
 NoContactDefined=Aucun contact défini pour ce tiers
 DefaultContact=Contact par défaut
diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php
index 030f70c01d8..996d9aac197 100644
--- a/htdocs/master.inc.php
+++ b/htdocs/master.inc.php
@@ -267,7 +267,7 @@ if (! defined('NOREQUIREDB') && ! defined('NOREQUIRESOC'))
 	$mysoc->localtax2_assuj=((isset($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')?1:0);
 
 	// For some countries, we need to invert our address with customer address
-	if ($mysoc->pays_code == 'DE' && ! isset($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $conf->global->MAIN_INVERT_SENDER_RECIPIENT=1;
+	if ($mysoc->country_code == 'DE' && ! isset($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $conf->global->MAIN_INVERT_SENDER_RECIPIENT=1;
 }
 
 
diff --git a/htdocs/paybox/lib/paybox.lib.php b/htdocs/paybox/lib/paybox.lib.php
index dd1b627a28d..8e156b8ef5d 100755
--- a/htdocs/paybox/lib/paybox.lib.php
+++ b/htdocs/paybox/lib/paybox.lib.php
@@ -266,16 +266,16 @@ function html_print_paybox_footer($fromcompany,$langs)
 		$line1.=($line1?" - ":"").$langs->transnoentities("CapitalOf",$fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
 	}
 	// Prof Id 1
-	if ($fromcompany->idprof1 && ($fromcompany->pays_code != 'FR' || ! $fromcompany->idprof2))
+	if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
 	{
-		$field=$langs->transcountrynoentities("ProfId1",$fromcompany->pays_code);
+		$field=$langs->transcountrynoentities("ProfId1",$fromcompany->country_code);
 		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
 		$line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof1;
 	}
 	// Prof Id 2
 	if ($fromcompany->idprof2)
 	{
-		$field=$langs->transcountrynoentities("ProfId2",$fromcompany->pays_code);
+		$field=$langs->transcountrynoentities("ProfId2",$fromcompany->country_code);
 		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
 		$line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof2;
 	}
@@ -285,14 +285,14 @@ function html_print_paybox_footer($fromcompany,$langs)
 	// Prof Id 3
 	if ($fromcompany->idprof3)
 	{
-		$field=$langs->transcountrynoentities("ProfId3",$fromcompany->pays_code);
+		$field=$langs->transcountrynoentities("ProfId3",$fromcompany->country_code);
 		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
 		$line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof3;
 	}
 	// Prof Id 4
 	if ($fromcompany->idprof4)
 	{
-		$field=$langs->transcountrynoentities("ProfId4",$fromcompany->pays_code);
+		$field=$langs->transcountrynoentities("ProfId4",$fromcompany->country_code);
 		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
 		$line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof4;
 	}
diff --git a/htdocs/paypal/lib/paypal.lib.php b/htdocs/paypal/lib/paypal.lib.php
index 06270d06e64..dfb68d581a7 100755
--- a/htdocs/paypal/lib/paypal.lib.php
+++ b/htdocs/paypal/lib/paypal.lib.php
@@ -96,14 +96,14 @@ function html_print_paypal_footer($fromcompany,$langs)
 	// Prof Id 1
 	if ($fromcompany->idprof1 && ($fromcompany->pays_code != 'FR' || ! $fromcompany->idprof2))
 	{
-		$field=$langs->transcountrynoentities("ProfId1",$fromcompany->pays_code);
+		$field=$langs->transcountrynoentities("ProfId1",$fromcompany->country_code);
 		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
 		$line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof1;
 	}
 	// Prof Id 2
 	if ($fromcompany->idprof2)
 	{
-		$field=$langs->transcountrynoentities("ProfId2",$fromcompany->pays_code);
+		$field=$langs->transcountrynoentities("ProfId2",$fromcompany->country_code);
 		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
 		$line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof2;
 	}
@@ -113,14 +113,14 @@ function html_print_paypal_footer($fromcompany,$langs)
 	// Prof Id 3
 	if ($fromcompany->idprof3)
 	{
-		$field=$langs->transcountrynoentities("ProfId3",$fromcompany->pays_code);
+		$field=$langs->transcountrynoentities("ProfId3",$fromcompany->country_code);
 		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
 		$line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof3;
 	}
 	// Prof Id 4
 	if ($fromcompany->idprof4)
 	{
-		$field=$langs->transcountrynoentities("ProfId4",$fromcompany->pays_code);
+		$field=$langs->transcountrynoentities("ProfId4",$fromcompany->country_code);
 		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
 		$line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof4;
 	}
diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php
index 1d9a652768e..690f6c8ea7f 100644
--- a/htdocs/product/fiche.php
+++ b/htdocs/product/fiche.php
@@ -776,7 +776,7 @@ else
 
         // Origin country
         print '<tr><td>'.$langs->trans("CountryOrigin").'</td><td>';
-        $form->select_pays($_POST["country_id"],'country_id');
+        print $form->select_country($_POST["country_id"],'country_id');
         if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
         print '</td></tr>';
 
@@ -966,7 +966,7 @@ else
 
             // Origin country
             print '<tr><td>'.$langs->trans("CountryOrigin").'</td><td colspan="2">';
-            $form->select_pays($object->country_id,'country_id');
+            print $form->select_country($object->country_id,'country_id');
             if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
             print '</td></tr>';
 
diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php
index 00a3951f27a..19c40b4f935 100644
--- a/htdocs/product/stock/class/entrepot.class.php
+++ b/htdocs/product/stock/class/entrepot.class.php
@@ -136,10 +136,9 @@ class Entrepot extends CommonObject
 		$this->address=$this->db->escape(trim($this->address));
 		$this->cp=trim($this->cp);
 		$this->ville=$this->db->escape(trim($this->ville));
-		$this->pays_id=trim($this->pays_id?$this->pays_id:0);
 		$this->zip=trim($this->cp);
 		$this->town=$this->db->escape(trim($this->ville));
-		$this->country_id=trim($this->pays_id?$this->pays_id:0);
+		$this->country_id=($this->country_id > 0 ? $this->country_id:$this->pays_id);
 
 		$sql = "UPDATE ".MAIN_DB_PREFIX."entrepot ";
 		$sql .= " SET label = '" . $this->libelle ."'";
diff --git a/htdocs/product/stock/fiche.php b/htdocs/product/stock/fiche.php
index 20ef429d4c8..8cb4c17c5c2 100644
--- a/htdocs/product/stock/fiche.php
+++ b/htdocs/product/stock/fiche.php
@@ -62,10 +62,10 @@ if ($action == 'add' && $user->rights->stock->creer)
 	$object->address     = $_POST["address"];
 	$object->cp          = $_POST["zipcode"];
 	$object->ville       = $_POST["town"];
-	$object->pays_id     = $_POST["pays_id"];
+	$object->pays_id     = $_POST["country_id"];
 	$object->zip         = $_POST["zipcode"];
 	$object->town        = $_POST["town"];
-	$object->country_id  = $_POST["pays_id"];
+	$object->country_id  = $_POST["country_id"];
 
 	if ($object->libelle) {
 		$id = $object->create($user);
@@ -115,10 +115,10 @@ if ($action == 'update' && $_POST["cancel"] <> $langs->trans("Cancel"))
 		$object->address     = $_POST["address"];
 		$object->cp          = $_POST["zipcode"];
 		$object->ville       = $_POST["town"];
-		$object->pays_id     = $_POST["pays_id"];
+		$object->pays_id     = $_POST["country_id"];
 		$object->zip         = $_POST["zipcode"];
 		$object->town        = $_POST["town"];
-		$object->country_id  = $_POST["pays_id"];
+		$object->country_id  = $_POST["country_id"];
 
 		if ( $object->update($_POST["id"], $user) > 0)
 		{
@@ -193,14 +193,14 @@ if ($action == 'create')
 
 	// Zip / Town
 	print '<tr><td>'.$langs->trans('Zip').'</td><td>';
-	print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectpays_id','departement_id'),6);
+	print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectcountry_id','departement_id'),6);
 	print '</td><td>'.$langs->trans('Town').'</td><td>';
-	print $formcompany->select_ziptown($object->town,'town',array('zipcode','selectpays_id','departement_id'));
+	print $formcompany->select_ziptown($object->town,'town',array('zipcode','selectcountry_id','departement_id'));
 	print '</td></tr>';
 
 	// Country
 	print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">';
-	$form->select_pays($object->country_id?$object->country_id:$mysoc->country_code,'pays_id');
+	print $form->select_country($object->country_id?$object->country_id:$mysoc->country_code,'country_id');
 	if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
 	print '</td></tr>';
 
@@ -512,14 +512,14 @@ else
 
 			// Zip / Town
 			print '<tr><td>'.$langs->trans('Zip').'</td><td>';
-			print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectpays_id','departement_id'),6);
+			print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectcountry_id','departement_id'),6);
 			print '</td><td>'.$langs->trans('Town').'</td><td>';
-			print $formcompany->select_ziptown($object->town,'town',array('zipcode','selectpays_id','departement_id'));
+			print $formcompany->select_ziptown($object->town,'town',array('zipcode','selectcountry_id','departement_id'));
 			print '</td></tr>';
 
 			// Country
 			print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">';
-			$form->select_pays($object->country_id?$object->country_id:$mysoc->country_code,'pays_id');
+			print $form->select_country($object->country_id?$object->country_id:$mysoc->country_code,'country_id');
 			if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
 			print '</td></tr>';
 
@@ -542,9 +542,7 @@ else
 }
 
 
-
+llxFooter();
 
 $db->close();
-
-llxFooter();
 ?>
diff --git a/htdocs/product/stock/mouvement.php b/htdocs/product/stock/mouvement.php
index 8eb06a963d5..142b3c39233 100644
--- a/htdocs/product/stock/mouvement.php
+++ b/htdocs/product/stock/mouvement.php
@@ -186,7 +186,7 @@ if ($resql)
 
 		// Country
 		print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
-		$img=picto_from_langcode($entrepot->pays_code);
+		$img=picto_from_langcode($entrepot->country_code);
 		print ($img?$img.' ':'');
 		print $entrepot->pays;
 		print '</td></tr>';
diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php
index 1923eff7c71..4c9477dd871 100644
--- a/htdocs/public/members/new.php
+++ b/htdocs/public/members/new.php
@@ -228,8 +228,8 @@ if ($action == 'add')
         }
         $adh->photo       = $_POST["photo"];
         $adh->note        = $_POST["note"];
-        $adh->country_id  = $_POST["pays_id"];
-        $adh->pays_id     = $_POST["pays_id"];    // TODO deprecated
+        $adh->country_id  = $_POST["country_id"];
+        $adh->pays_id     = $_POST["country_id"];    // TODO deprecated
         $adh->state_id    = $_POST["state_id"];
         $adh->typeid      = $_POST["type"];
         $adh->note        = $_POST["comment"];
diff --git a/htdocs/public/paypal/newpayment.php b/htdocs/public/paypal/newpayment.php
index e098fbf43cc..8c99f63f5d9 100755
--- a/htdocs/public/paypal/newpayment.php
+++ b/htdocs/public/paypal/newpayment.php
@@ -439,7 +439,7 @@ if (GETPOST("source") == 'order' && $valid)
     $shipToStreet=$order->client->address;
     $shipToCity=$order->client->ville;
     $shipToState=$order->client->departement_code;
-    $shipToCountryCode=$order->client->pays_code;
+    $shipToCountryCode=$order->client->country_code;
     $shipToZip=$order->client->cp;
     $shipToStreet2='';
     $phoneNum=$order->client->tel;
@@ -542,7 +542,7 @@ if (GETPOST("source") == 'invoice' && $valid)
     $shipToStreet=$invoice->client->address;
     $shipToCity=$invoice->client->ville;
     $shipToState=$invoice->client->departement_code;
-    $shipToCountryCode=$invoice->client->pays_code;
+    $shipToCountryCode=$invoice->client->country_code;
     $shipToZip=$invoice->client->cp;
     $shipToStreet2='';
     $phoneNum=$invoice->client->tel;
@@ -852,7 +852,7 @@ if (GETPOST("source") == 'membersubscription' && $valid)
     $shipToStreet=$member->address;
     $shipToCity=$member->ville;
     $shipToState=$member->departement_code;
-    $shipToCountryCode=$member->pays_code;
+    $shipToCountryCode=$member->country_code;
     $shipToZip=$member->cp;
     $shipToStreet2='';
     $phoneNum=$member->tel;
diff --git a/htdocs/societe/admin/societe.php b/htdocs/societe/admin/societe.php
index 681ede25112..d00749093d5 100644
--- a/htdocs/societe/admin/societe.php
+++ b/htdocs/societe/admin/societe.php
@@ -506,13 +506,13 @@ print '<td align="center">'.$langs->trans("MustBeUnique").'</td>';
 print "</tr>\n";
 
 $profid[0][0]=$langs->trans("ProfId1");
-$profid[0][1]=$langs->transcountry('ProfId1', $mysoc->pays_code);
+$profid[0][1]=$langs->transcountry('ProfId1', $mysoc->country_code);
 $profid[1][0]=$langs->trans("ProfId2");
-$profid[1][1]=$langs->transcountry('ProfId2', $mysoc->pays_code);
+$profid[1][1]=$langs->transcountry('ProfId2', $mysoc->country_code);
 $profid[2][0]=$langs->trans("ProfId3");
-$profid[2][1]=$langs->transcountry('ProfId3', $mysoc->pays_code);
+$profid[2][1]=$langs->transcountry('ProfId3', $mysoc->country_code);
 $profid[3][0]=$langs->trans("ProfId4");
-$profid[3][1]=$langs->transcountry('ProfId4', $mysoc->pays_code);
+$profid[3][1]=$langs->transcountry('ProfId4', $mysoc->country_code);
 
 $var = true;
 $i=0;
diff --git a/htdocs/societe/agenda.php b/htdocs/societe/agenda.php
index c0f90fc6c58..907b9cff53a 100644
--- a/htdocs/societe/agenda.php
+++ b/htdocs/societe/agenda.php
@@ -121,14 +121,14 @@ if ($_GET["socid"])
 	// Country
 	if ($soc->pays) {
 		print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
-		$img=picto_from_langcode($soc->pays_code);
+		$img=picto_from_langcode($soc->country_code);
 		print ($img?$img.' ':'');
 		print $soc->pays;
 		print '</td></tr>';
 	}
 
-	print '<tr><td>'.$langs->trans('Phone').'</td><td>'.dol_print_phone($soc->tel,$soc->pays_code,0,$soc->id,'AC_TEL').'</td>';
-	print '<td>'.$langs->trans('Fax').'</td><td>'.dol_print_phone($soc->fax,$soc->pays_code,0,$soc->id,'AC_FAX').'</td></tr>';
+	print '<tr><td>'.$langs->trans('Phone').'</td><td>'.dol_print_phone($soc->tel,$soc->country_code,0,$soc->id,'AC_TEL').'</td>';
+	print '<td>'.$langs->trans('Fax').'</td><td>'.dol_print_phone($soc->fax,$soc->country_code,0,$soc->id,'AC_FAX').'</td></tr>';
 
 	// EMail
 	print '<tr><td>'.$langs->trans('EMail').'</td><td>';
diff --git a/htdocs/societe/canvas/actions_card_common.class.php b/htdocs/societe/canvas/actions_card_common.class.php
index 001cdd63bc5..a1f311b018f 100644
--- a/htdocs/societe/canvas/actions_card_common.class.php
+++ b/htdocs/societe/canvas/actions_card_common.class.php
@@ -422,7 +422,7 @@ abstract class ActionsCardCommon
 			{
 				$this->tpl['ajax_selectcountry'] = "\n".'<script type="text/javascript" language="javascript">
 				jQuery(document).ready(function () {
-						jQuery("#selectpays_id").change(function() {
+						jQuery("#selectcountry_id").change(function() {
 							document.formsoc.action.value="'.$action.'";
 							document.formsoc.canvas.value="'.$canvas.'";
 							document.formsoc.submit();
@@ -490,19 +490,19 @@ abstract class ActionsCardCommon
             }
 
             // Zip
-            $this->tpl['select_zip'] = $formcompany->select_ziptown($this->object->zip,'zipcode',array('town','selectpays_id','departement_id'),6);
+            $this->tpl['select_zip'] = $formcompany->select_ziptown($this->object->zip,'zipcode',array('town','selectcountry_id','departement_id'),6);
 
             // Town
-            $this->tpl['select_town'] = $formcompany->select_ziptown($this->object->town,'town',array('zipcode','selectpays_id','departement_id'));
+            $this->tpl['select_town'] = $formcompany->select_ziptown($this->object->town,'town',array('zipcode','selectcountry_id','departement_id'));
 
             // Country
-            $this->tpl['select_country'] = $form->select_country($this->object->pays_id,'pays_id');
+            $this->tpl['select_country'] = $form->select_country($this->object->country_id,'country_id');
             $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
 
             if ($user->admin) $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
 
             // State
-            if ($this->object->pays_id) $this->tpl['select_state'] = $formcompany->select_state($this->object->state_id,$this->object->pays_code);
+            if ($this->object->country_id) $this->tpl['select_state'] = $formcompany->select_state($this->object->state_id,$this->object->country_code);
             else $this->tpl['select_state'] = $countrynotdefined;
 
             // Language
@@ -516,7 +516,7 @@ abstract class ActionsCardCommon
 
             // Local Tax
             // TODO mettre dans une classe propre au pays
-            if($mysoc->pays_code=='ES')
+            if($mysoc->country_code=='ES')
             {
                 $this->tpl['localtax'] = '';
 
@@ -560,8 +560,8 @@ abstract class ActionsCardCommon
             if ($this->object->isInEEC()) $this->tpl['country'] = $form->textwithpicto(($img?$img.' ':'').$this->object->country,$langs->trans("CountryIsInEEC"),1,0);
             $this->tpl['country'] = ($img?$img.' ':'').$this->object->country;
 
-            $this->tpl['phone'] 	= dol_print_phone($this->object->tel,$this->object->pays_code,0,$this->object->id,'AC_TEL');
-            $this->tpl['fax'] 		= dol_print_phone($this->object->fax,$this->object->pays_code,0,$this->object->id,'AC_FAX');
+            $this->tpl['phone'] 	= dol_print_phone($this->object->tel,$this->object->country_code,0,$this->object->id,'AC_TEL');
+            $this->tpl['fax'] 		= dol_print_phone($this->object->fax,$this->object->country_code,0,$this->object->id,'AC_FAX');
             $this->tpl['email'] 	= dol_print_email($this->object->email,0,$this->object->id,'AC_EMAIL');
             $this->tpl['url'] 		= dol_print_url($this->object->url);
 
@@ -629,7 +629,7 @@ abstract class ActionsCardCommon
 
             // Local Tax
             // TODO mettre dans une classe propre au pays
-            if($mysoc->pays_code=='ES')
+            if($mysoc->country_code=='ES')
             {
                 $this->tpl['localtax'] = '';
 
@@ -674,7 +674,7 @@ abstract class ActionsCardCommon
         $this->object->address				=	$_POST["adresse"];
         $this->object->zip					=	$_POST["zipcode"];
         $this->object->town					=	$_POST["town"];
-        $this->object->country_id			=	$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->country_id;
+        $this->object->country_id			=	$_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id;
         $this->object->state_id		        =	$_POST["departement_id"];
         $this->object->tel					=	$_POST["tel"];
         $this->object->fax					=	$_POST["fax"];
diff --git a/htdocs/societe/canvas/company/actions_card_company.class.php b/htdocs/societe/canvas/company/actions_card_company.class.php
index 0cfc7033369..0e01557eb30 100644
--- a/htdocs/societe/canvas/company/actions_card_company.class.php
+++ b/htdocs/societe/canvas/company/actions_card_company.class.php
@@ -128,15 +128,15 @@ class ActionsCardCompany extends ActionsCardCommon
 		{
 			for ($i=1; $i<=4; $i++)
 			{
-				$this->tpl['langprofid'.$i]		= $langs->transcountry('ProfId'.$i,$this->object->pays_code);
-				$this->tpl['showprofid'.$i]		= $formcompany->get_input_id_prof($i,'idprof'.$i,$this->tpl['profid'.$i],$this->object->pays_code);
+				$this->tpl['langprofid'.$i]		= $langs->transcountry('ProfId'.$i,$this->object->country_code);
+				$this->tpl['showprofid'.$i]		= $formcompany->get_input_id_prof($i,'idprof'.$i,$this->tpl['profid'.$i],$this->object->country_code);
 			}
 
 			// Type
 			$this->tpl['select_companytype']	= $form->selectarray("typent_id",$formcompany->typent_array(0), $this->object->typent_id);
 
 			// Juridical Status
-			$this->tpl['select_juridicalstatus'] = $formcompany->select_juridicalstatus($this->object->forme_juridique_code,$this->object->pays_code);
+			$this->tpl['select_juridicalstatus'] = $formcompany->select_juridicalstatus($this->object->forme_juridique_code,$this->object->country_code);
 
 			// Workforce
 			$this->tpl['select_workforce'] = $form->selectarray("effectif_id",$formcompany->effectif_array(0), $this->object->effectif_id);
@@ -172,7 +172,7 @@ class ActionsCardCompany extends ActionsCardCommon
 
 			for ($i=1; $i<=4; $i++)
 			{
-				$this->tpl['langprofid'.$i]		= $langs->transcountry('ProfId'.$i,$this->object->pays_code);
+				$this->tpl['langprofid'.$i]		= $langs->transcountry('ProfId'.$i,$this->object->country_code);
 				$this->tpl['checkprofid'.$i]	= $this->object->id_prof_check($i,$this->object);
 				$this->tpl['urlprofid'.$i]		= $this->object->id_prof_url($i,$this->object);
 			}
diff --git a/htdocs/societe/class/address.class.php b/htdocs/societe/class/address.class.php
index 354acc4a241..5203481fa94 100644
--- a/htdocs/societe/class/address.class.php
+++ b/htdocs/societe/class/address.class.php
@@ -172,6 +172,7 @@ class Address
 		$this->cp		= trim($this->cp);
 		$this->ville	= trim($this->ville);
 		$this->pays_id	= trim($this->pays_id);
+		$this->country_id	= trim($this->country_id);
 		$this->tel		= trim($this->tel);
 		$this->tel		= preg_replace("/\s/","",$this->tel);
 		$this->tel		= preg_replace("/\./","",$this->tel);
@@ -197,7 +198,7 @@ class Address
 			if ($this->ville)
 			{ $sql .= ",ville = '" . $this->db->escape($this->ville) ."'"; }
 
-			$sql .= ",fk_pays = '" . ($this->pays_id?$this->pays_id:'0') ."'";
+			$sql .= ",fk_pays = '" . ($this->country_id?$this->country_id:'0') ."'";
 			$sql.= ",note = '" . $this->db->escape($this->note) ."'";
 
 			if ($this->tel)
@@ -275,8 +276,8 @@ class Address
 			{
 				$sql = 'SELECT a.rowid as id, a.label, a.name, a.address, a.datec as dc';
 				$sql .= ', a.tms as date_update, a.fk_soc';
-				$sql .= ', a.cp, a.ville, a.note, a.fk_pays, a.tel, a.fax';
-				$sql .= ', p.code as pays_code, p.libelle as pays';
+				$sql .= ', a.cp as zip, a.ville as town, a.note, a.fk_pays as country_id, a.tel, a.fax';
+				$sql .= ', p.code as country_code, p.libelle as country';
 				$sql .= ' FROM '.MAIN_DB_PREFIX.'societe_address as a';
 				$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_pays as p ON a.fk_pays = p.rowid';
 				$sql .= ' WHERE a.fk_soc = '.$this->socid;
@@ -298,11 +299,16 @@ class Address
 						$line->label			= $objp->label;
 						$line->name				= $objp->name;
 						$line->address			= $objp->address;
-						$line->cp				= $objp->cp;
-						$line->ville			= $objp->ville;
-						$line->pays_id			= $objp->fk_pays;
-						$line->pays_code		= $objp->fk_pays?$objp->pays_code:'';
-						$line->pays				= $objp->fk_pays?($langs->trans('Country'.$objp->pays_code)!='Country'.$objp->pays_code?strtoupper($langs->trans('Country'.$objp->pays_code)):$objp->pays):'';
+						$line->cp				= $objp->zip;
+						$line->ville			= $objp->town;
+						$line->zip				= $objp->zip;
+						$line->town				= $objp->town;
+						$line->pays_id			= $objp->country_id;
+						$line->pays_code		= $objp->country_id?$objp->country_code:'';
+						$line->pays				= $objp->country_id?($langs->trans('Country'.$objp->country_code)!='Country'.$objp->country_code?strtoupper($langs->trans('Country'.$objp->country_code)):$objp->country):'';
+						$line->country_id		= $objp->country_id;
+						$line->country_code		= $objp->country_id?$objp->country_code:'';
+						$line->country			= $objp->country_id?($langs->trans('Country'.$objp->country_code)!='Country'.$objp->country_code?strtoupper($langs->trans('Country'.$objp->country_code)):$objp->country):'';
 						$line->tel				= $objp->tel;
 						$line->fax				= $objp->fax;
 						$line->note				= $objp->note;
@@ -346,8 +352,8 @@ class Address
 
 		$sql = 'SELECT a.rowid, a.fk_soc, a.label, a.name, a.address, a.datec as date_creation';
 		$sql .= ', a.tms as date_update';
-		$sql .= ', a.cp,a.ville, a.note, a.fk_pays, a.tel, a.fax';
-		$sql .= ', p.code as pays_code, p.libelle as pays';
+		$sql .= ', a.cp as zip, a.ville as town, a.note, a.fk_pays as country_id, a.tel, a.fax';
+		$sql .= ', p.code as country_code, p.libelle as country';
 		$sql .= ' FROM '.MAIN_DB_PREFIX.'societe_address as a';
 		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_pays as p ON a.fk_pays = p.rowid';
 		$sql .= ' WHERE a.rowid = '.$id;
@@ -367,12 +373,17 @@ class Address
 				$this->label 			= $obj->label;
 				$this->name 			= $obj->name;
 				$this->address 			= $obj->address;
-				$this->cp 				= $obj->cp;
-				$this->ville 			= $obj->ville;
-
-				$this->pays_id 			= $obj->fk_pays;
-				$this->pays_code 		= $obj->fk_pays?$obj->pays_code:'';
-				$this->pays				= $obj->fk_pays?($langs->trans('Country'.$obj->pays_code)!='Country'.$obj->pays_code?$langs->trans('Country'.$obj->pays_code):$obj->pays):'';
+				$this->cp 				= $obj->zip;
+				$this->ville 			= $obj->town;
+				$this->zip 				= $obj->zip;
+				$this->town 			= $obj->town;
+
+				$this->pays_id 			= $obj->country_id;
+				$this->pays_code 		= $obj->country_id?$obj->country_code:'';
+				$this->pays				= $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->trans('Country'.$obj->country_code):$obj->country):'';
+				$this->country_id 			= $obj->country_id;
+				$this->country_code 		= $obj->country_id?$obj->country_code:'';
+				$this->country				= $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->trans('Country'.$obj->country_code):$obj->country):'';
 
 				$this->tel				= $obj->tel;
 				$this->fax				= $obj->fax;
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index 1e6a45722ae..f7538120dc1 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -400,8 +400,8 @@ class Societe extends CommonObject
         $this->town=$this->town?trim($this->town):trim($this->ville);
         $this->ville=$this->town;       // TODO obsolete
         $this->state_id=trim($this->state_id);
-        $this->pays_id=trim($this->pays_id);
-        $this->country_id	= trim($this->country_id);
+        $this->country_id	= ($this->country_id > 0)?$this->country_id:$this->pays_id;
+        $this->pays_id      = $this->country_id; 
         $this->tel			= trim($this->tel);
         $this->fax			= trim($this->fax);
         $this->tel			= preg_replace("/\s/","",$this->tel);
@@ -633,12 +633,12 @@ class Societe extends CommonObject
         $sql .= ', s.fk_effectif as effectif_id';
         $sql .= ', s.fk_forme_juridique as forme_juridique_code';
         $sql .= ', s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur, s.parent, s.barcode';
-        $sql .= ', s.fk_departement, s.fk_pays, s.fk_stcomm, s.remise_client, s.mode_reglement, s.cond_reglement, s.tva_assuj';
+        $sql .= ', s.fk_departement, s.fk_pays as country_id, s.fk_stcomm, s.remise_client, s.mode_reglement, s.cond_reglement, s.tva_assuj';
         $sql .= ', s.localtax1_assuj, s.localtax2_assuj, s.fk_prospectlevel, s.default_lang, s.logo';
         $sql .= ', s.import_key';
         $sql .= ', fj.libelle as forme_juridique';
         $sql .= ', e.libelle as effectif';
-        $sql .= ', p.code as pays_code, p.libelle as pays';
+        $sql .= ', p.code as country_code, p.libelle as country';
         $sql .= ', d.code_departement as departement_code, d.nom as departement';
         $sql .= ', st.libelle as stcomm';
         $sql .= ', te.code as typent_code';
@@ -692,12 +692,13 @@ class Societe extends CommonObject
                 $this->town 		= $obj->town;
                 $this->ville        = $obj->town;		// TODO obsolete
 
-                $this->pays_id 		= $obj->fk_pays;	// TODO obsolete
-                $this->country_id   = $obj->fk_pays;
-                $this->pays_code 	= $obj->fk_pays?$obj->pays_code:'';		// TODO obsolete
-                $this->country_code = $obj->fk_pays?$obj->pays_code:'';
-                $this->pays 		= $obj->fk_pays?($langs->trans('Country'.$obj->pays_code)!='Country'.$obj->pays_code?$langs->trans('Country'.$obj->pays_code):$obj->pays):''; // TODO obsolete
-                $this->country 		= $obj->fk_pays?($langs->trans('Country'.$obj->pays_code)!='Country'.$obj->pays_code?$langs->trans('Country'.$obj->pays_code):$obj->pays):'';
+                $this->pays_id 		= $obj->country_id;	// TODO obsolete
+                $this->country_id   = $obj->country_id;
+                $this->pays_code 	= $obj->country_id?$obj->country_code:'';		// TODO obsolete
+                $this->country_code = $obj->country_id?$obj->country_code:'';
+                $this->pays 		= $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->trans('Country'.$obj->country_code):$obj->country):''; // TODO obsolete
+                $this->country 		= $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->trans('Country'.$obj->country_code):$obj->country):'';
+                
                 $this->state_id     = $obj->fk_departement;
                 $this->state_code   = $obj->departement_code;
                 $this->state        = $obj->departement;
@@ -1972,7 +1973,7 @@ class Societe extends CommonObject
         if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1;
 
         // Verifie SIREN si pays FR
-        if ($idprof == 1 && $soc->pays_code == 'FR')
+        if ($idprof == 1 && $soc->country_code == 'FR')
         {
             $chaine=trim($this->idprof1);
             $chaine=preg_replace('/(\s)/','',$chaine);
@@ -2001,7 +2002,7 @@ class Societe extends CommonObject
         }
 
         // Verifie SIRET si pays FR
-        if ($idprof == 2 && $soc->pays_code == 'FR')
+        if ($idprof == 2 && $soc->country_code == 'FR')
         {
             $chaine=trim($this->idprof1);
             $chaine=preg_replace('/(\s)/','',$chaine);
@@ -2011,7 +2012,7 @@ class Societe extends CommonObject
 
         //Verify CIF/NIF/NIE if pays ES
         //Returns: 1 if NIF ok, 2 if CIF ok, 3 if NIE ok, -1 if NIF bad, -2 if CIF bad, -3 if NIE bad, 0 if unexpected bad
-        if ($idprof == 1 && $soc->pays_code == 'ES')
+        if ($idprof == 1 && $soc->country_code == 'ES')
         {
             $string=trim($this->idprof1);
             $string=preg_replace('/(\s)/','',$string);
@@ -2087,9 +2088,9 @@ class Societe extends CommonObject
 
         $url='';
 
-        if ($idprof == 1 && $soc->pays_code == 'FR') $url='http://www.societe.com/cgi-bin/recherche?rncs='.$soc->idprof1;
-        if ($idprof == 1 && $soc->pays_code == 'GB') $url='http://www.companieshouse.gov.uk/WebCHeck/findinfolink/';
-        if ($idprof == 1 && $soc->pays_code == 'ES') $url='http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$soc->idprof1;
+        if ($idprof == 1 && $soc->country_code == 'FR') $url='http://www.societe.com/cgi-bin/recherche?rncs='.$soc->idprof1;
+        if ($idprof == 1 && $soc->country_code == 'GB') $url='http://www.companieshouse.gov.uk/WebCHeck/findinfolink/';
+        if ($idprof == 1 && $soc->country_code == 'ES') $url='http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$soc->idprof1;
 
         if ($url) return '<a target="_blank" href="'.$url.'">['.$langs->trans("Check").']</a>';
         return '';
@@ -2242,8 +2243,8 @@ class Societe extends CommonObject
 			'SI',	// Slovenia
         //'CH',	// Switzerland - No. Swizerland in not in EEC
         );
-        //print "dd".$this->pays_code;
-        return in_array($this->pays_code,$country_code_in_EEC);
+        //print "dd".$this->country_code;
+        return in_array($this->country_code,$country_code_in_EEC);
     }
 
     /**
@@ -2316,10 +2317,10 @@ class Societe extends CommonObject
         $this->zip=$member->cp;
         $this->ville=$member->ville;	// TODO obsolete
         $this->town=$member->ville;
-        $this->pays_code=$member->pays_code;	// TODO obsolete
-        $this->country_code=$member->pays_code;
-        $this->pays_id=$member->pays_id;	// TODO obsolete
-        $this->country_id=$member->pays_id;
+        $this->pays_code=$member->country_code;	// TODO obsolete
+        $this->country_code=$member->country_code;
+        $this->pays_id=$member->country_id;	// TODO obsolete
+        $this->country_id=$member->country_id;
         $this->tel=$member->phone;				// Prof phone
         $this->email=$member->email;
 
@@ -2382,13 +2383,9 @@ class Societe extends CommonObject
         $this->name = 'THIRDPARTY SPECIMEN '.dol_print_date($now,'dayhourlog');
         $this->nom = $this->name;   // For backward compatibility
         $this->specimen=1;
-        $this->cp='99999';
         $this->zip='99999';
-        $this->ville='MyTown';
         $this->town='MyTown';
-        $this->pays_id=1;
         $this->country_id=1;
-        $this->pays_code='FR';
         $this->country_code='FR';
 
         $this->code_client='CC-'.dol_print_date($now,'dayhourlog');
diff --git a/htdocs/societe/commerciaux.php b/htdocs/societe/commerciaux.php
index c9998acc84b..d2f78a4ad07 100644
--- a/htdocs/societe/commerciaux.php
+++ b/htdocs/societe/commerciaux.php
@@ -130,8 +130,8 @@ if ($_GET["socid"])
 
 	print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">'.$soc->pays.'</td>';
 
-	print '<tr><td>'.$langs->trans('Phone').'</td><td>'.dol_print_phone($soc->tel,$soc->pays_code,0,$soc->id,'AC_TEL').'</td>';
-	print '<td>'.$langs->trans('Fax').'</td><td>'.dol_print_phone($soc->fax,$soc->pays_code,0,$soc->id,'AC_FAX').'</td></tr>';
+	print '<tr><td>'.$langs->trans('Phone').'</td><td>'.dol_print_phone($soc->tel,$soc->country_code,0,$soc->id,'AC_TEL').'</td>';
+	print '<td>'.$langs->trans('Fax').'</td><td>'.dol_print_phone($soc->fax,$soc->country_code,0,$soc->id,'AC_FAX').'</td></tr>';
 
 	print '<tr><td>'.$langs->trans('Web').'</td><td colspan="3">';
 	if ($soc->url) { print '<a href="http://'.$soc->url.'">http://'.$soc->url.'</a>'; }
diff --git a/htdocs/societe/lien.php b/htdocs/societe/lien.php
index ffd72051172..4b52f35ac13 100644
--- a/htdocs/societe/lien.php
+++ b/htdocs/societe/lien.php
@@ -128,13 +128,13 @@ if ($socid)
 
 	print "<tr><td valign=\"top\">".$langs->trans('Address')."</td><td colspan=\"3\">".nl2br($soc->address)."</td></tr>";
 
-	print "<tr><td>".$langs->trans('Zip').'</td><td width="20%">'.$soc->cp."</td>";
-	print "<td>".$langs->trans('Town')."</td><td>".$soc->ville."</td></tr>";
+	print "<tr><td>".$langs->trans('Zip').'</td><td width="20%">'.$soc->zip."</td>";
+	print "<td>".$langs->trans('Town')."</td><td>".$soc->town."</td></tr>";
 
-	print "<tr><td>".$langs->trans('Country')."</td><td colspan=\"3\">".$soc->pays."</td></tr>";
+	print "<tr><td>".$langs->trans('Country')."</td><td colspan=\"3\">".$soc->country."</td></tr>";
 
-	print '<tr><td>'.$langs->trans('Phone').'</td><td>'.dol_print_phone($soc->tel,$soc->pays_code,0,$soc->id,'AC_TEL').'</td>';
-	print '<td>'.$langs->trans('Fax').'</td><td>'.dol_print_phone($soc->fax,$soc->pays_code,0,$soc->id,'AC_FAX').'</td></tr>';
+	print '<tr><td>'.$langs->trans('Phone').'</td><td>'.dol_print_phone($soc->tel,$soc->country_code,0,$soc->id,'AC_TEL').'</td>';
+	print '<td>'.$langs->trans('Fax').'</td><td>'.dol_print_phone($soc->fax,$soc->country_code,0,$soc->id,'AC_FAX').'</td></tr>';
 
 	print '<tr><td>'.$langs->trans('Web').'</td><td colspan="3">';
 	if ($soc->url) { print '<a href="http://'.$soc->url.'">http://'.$soc->url.'</a>'; }
@@ -143,40 +143,40 @@ if ($socid)
 	$object=$soc;
     print '<tr>';
     // IdProf1 (SIREN for France)
-    $idprof=$langs->transcountry('ProfId1',$object->pays_code);
+    $idprof=$langs->transcountry('ProfId1',$object->country_code);
     if ($idprof!='-')
     {
         print '<td>'.$idprof.'</td><td>';
-        print $formcompany->get_input_id_prof(1,'idprof1',$object->idprof1,$object->pays_code);
+        print $formcompany->get_input_id_prof(1,'idprof1',$object->idprof1,$object->country_code);
         print '</td>';
     }
     else print '<td>&nbsp;</td><td>&nbsp;</td>';
     // IdProf2 (SIRET for France)
-    $idprof=$langs->transcountry('ProfId2',$object->pays_code);
+    $idprof=$langs->transcountry('ProfId2',$object->country_code);
     if ($idprof!='-')
     {
         print '<td>'.$idprof.'</td><td>';
-        print $formcompany->get_input_id_prof(2,'idprof2',$object->idprof2,$object->pays_code);
+        print $formcompany->get_input_id_prof(2,'idprof2',$object->idprof2,$object->paycountry_codes_code);
         print '</td>';
     }
     else print '<td>&nbsp;</td><td>&nbsp;</td>';
     print '</tr>';
     print '<tr>';
     // IdProf3 (APE for France)
-    $idprof=$langs->transcountry('ProfId3',$object->pays_code);
+    $idprof=$langs->transcountry('ProfId3',$object->country_code);
     if ($idprof!='-')
     {
         print '<td>'.$idprof.'</td><td>';
-        print $formcompany->get_input_id_prof(3,'idprof3',$object->idprof3,$object->pays_code);
+        print $formcompany->get_input_id_prof(3,'idprof3',$object->idprof3,$object->country_code);
         print '</td>';
     }
     else print '<td>&nbsp;</td><td>&nbsp;</td>';
     // IdProf4 (NU for France)
-    $idprof=$langs->transcountry('ProfId4',$object->pays_code);
+    $idprof=$langs->transcountry('ProfId4',$object->country_code);
     if ($idprof!='-')
     {
         print '<td>'.$idprof.'</td><td>';
-        print $formcompany->get_input_id_prof(4,'idprof4',$object->idprof4,$object->pays_code);
+        print $formcompany->get_input_id_prof(4,'idprof4',$object->idprof4,$object->country_code);
         print '</td>';
     }
     else print '<td>&nbsp;</td><td>&nbsp;</td>';
diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php
index 94d04daaa0b..d205cfefb3d 100644
--- a/htdocs/societe/soc.php
+++ b/htdocs/societe/soc.php
@@ -206,7 +206,7 @@ if (empty($reshook))
 					if($object->id_prof_exists($i,$_POST["$slabel"],$object->id))
 					{
 						$langs->load("errors");
-                		$error++; $errors[] = $langs->transcountry('ProfId'.$i ,$object->pays_code)." ".$langs->trans("ErrorProdIdAlreadyExist",$_POST["$slabel"]);
+                		$error++; $errors[] = $langs->transcountry('ProfId'.$i ,$object->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist",$_POST["$slabel"]);
                 		$action = ($action=='add'?'create':'edit');
 					}
 				}
@@ -595,7 +595,7 @@ else
         $object->pays_id=$_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id;
         if ($object->country_id)
         {
-            $tmparray=getCountry($object->country_id,'all',$db,$langs,0);
+            $tmparray=getCountry($object->country_id,'all');
             $object->pays_code=$tmparray['code'];
             $object->pays=$tmparray['label'];
             $object->country_code=$tmparray['code'];
@@ -798,40 +798,40 @@ else
 
         print '<tr>';
         // IdProf1 (SIREN for France)
-        $idprof=$langs->transcountry('ProfId1',$object->pays_code);
+        $idprof=$langs->transcountry('ProfId1',$object->country_code);
         if ($idprof!='-')
         {
             print '<td>'.$idprof.'</td><td>';
-            print $formcompany->get_input_id_prof(1,'idprof1',$object->idprof1,$object->pays_code);
+            print $formcompany->get_input_id_prof(1,'idprof1',$object->idprof1,$object->country_code);
             print '</td>';
         }
         else print '<td>&nbsp;</td><td>&nbsp;</td>';
         // IdProf2 (SIRET for France)
-        $idprof=$langs->transcountry('ProfId2',$object->pays_code);
+        $idprof=$langs->transcountry('ProfId2',$object->country_code);
         if ($idprof!='-')
         {
             print '<td>'.$idprof.'</td><td>';
-            print $formcompany->get_input_id_prof(2,'idprof2',$object->idprof2,$object->pays_code);
+            print $formcompany->get_input_id_prof(2,'idprof2',$object->idprof2,$object->country_code);
             print '</td>';
         }
         else print '<td>&nbsp;</td><td>&nbsp;</td>';
         print '</tr>';
         print '<tr>';
         // IdProf3 (APE for France)
-        $idprof=$langs->transcountry('ProfId3',$object->pays_code);
+        $idprof=$langs->transcountry('ProfId3',$object->country_code);
         if ($idprof!='-')
         {
             print '<td>'.$idprof.'</td><td>';
-            print $formcompany->get_input_id_prof(3,'idprof3',$object->idprof3,$object->pays_code);
+            print $formcompany->get_input_id_prof(3,'idprof3',$object->idprof3,$object->country_code);
             print '</td>';
         }
         else print '<td>&nbsp;</td><td>&nbsp;</td>';
         // IdProf4 (NU for France)
-        $idprof=$langs->transcountry('ProfId4',$object->pays_code);
+        $idprof=$langs->transcountry('ProfId4',$object->country_code);
         if ($idprof!='-')
         {
             print '<td>'.$idprof.'</td><td>';
-            print $formcompany->get_input_id_prof(4,'idprof4',$object->idprof4,$object->pays_code);
+            print $formcompany->get_input_id_prof(4,'idprof4',$object->idprof4,$object->country_code);
             print '</td>';
         }
         else print '<td>&nbsp;</td><td>&nbsp;</td>';
@@ -887,7 +887,7 @@ else
         print '<td colspan="3">';
         if ($object->country_id)
         {
-            $formcompany->select_forme_juridique($object->forme_juridique_code,$object->pays_code);
+            $formcompany->select_forme_juridique($object->forme_juridique_code,$object->country_code);
         }
         else
         {
@@ -900,7 +900,7 @@ else
 
         // Local Taxes
         // TODO add specific function by country
-        if($mysoc->pays_code=='ES')
+        if($mysoc->country_code=='ES')
         {
             if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
             {
@@ -1356,7 +1356,7 @@ else
             print '</td></tr>';
 
             print '<tr><td>'.$langs->trans('JuridicalStatus').'</td><td colspan="3">';
-            $formcompany->select_forme_juridique($object->forme_juridique_code,$object->pays_code);
+            $formcompany->select_forme_juridique($object->forme_juridique_code,$object->country_code);
             print '</td></tr>';
 
             // Capital
@@ -1541,7 +1541,7 @@ else
 
         // Country
         print '<tr><td>'.$langs->trans("Country").'</td><td colspan="'.(2+(($showlogo || $showbarcode)?0:1)).'" nowrap="nowrap">';
-        $img=picto_from_langcode($object->pays_code);
+        $img=picto_from_langcode($object->country_code);
         if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->pays,$langs->trans("CountryIsInEEC"),1,0);
         else print ($img?$img.' ':'').$object->pays;
         print '</td></tr>';
@@ -1549,8 +1549,8 @@ else
         // State
         if (empty($conf->global->SOCIETE_DISABLE_STATE)) print '<tr><td>'.$langs->trans('State').'</td><td colspan="'.(2+(($showlogo || $showbarcode)?0:1)).'">'.$object->state.'</td>';
 
-        print '<tr><td>'.$langs->trans('Phone').'</td><td style="min-width: 25%;">'.dol_print_phone($object->tel,$object->pays_code,0,$object->id,'AC_TEL').'</td>';
-        print '<td>'.$langs->trans('Fax').'</td><td style="min-width: 25%;">'.dol_print_phone($object->fax,$object->pays_code,0,$object->id,'AC_FAX').'</td></tr>';
+        print '<tr><td>'.$langs->trans('Phone').'</td><td style="min-width: 25%;">'.dol_print_phone($object->tel,$object->country_code,0,$object->id,'AC_TEL').'</td>';
+        print '<td>'.$langs->trans('Fax').'</td><td style="min-width: 25%;">'.dol_print_phone($object->fax,$object->country_code,0,$object->id,'AC_FAX').'</td></tr>';
 
         // EMail
         print '<tr><td>'.$langs->trans('EMail').'</td><td width="25%">';
@@ -1563,7 +1563,7 @@ else
         print '</td></tr>';
 
         // ProfId1 (SIREN for France)
-        $profid=$langs->transcountry('ProfId1',$object->pays_code);
+        $profid=$langs->transcountry('ProfId1',$object->country_code);
         if ($profid!='-')
         {
             print '<tr><td>'.$profid.'</td><td>';
@@ -1577,7 +1577,7 @@ else
         }
         else print '<tr><td>&nbsp;</td><td>&nbsp;</td>';
         // ProfId2 (SIRET for France)
-        $profid=$langs->transcountry('ProfId2',$object->pays_code);
+        $profid=$langs->transcountry('ProfId2',$object->country_code);
         if ($profid!='-')
         {
             print '<td>'.$profid.'</td><td>';
@@ -1592,7 +1592,7 @@ else
         else print '<td>&nbsp;</td><td>&nbsp;</td></tr>';
 
         // ProfId3 (APE for France)
-        $profid=$langs->transcountry('ProfId3',$object->pays_code);
+        $profid=$langs->transcountry('ProfId3',$object->country_code);
         if ($profid!='-')
         {
             print '<tr><td>'.$profid.'</td><td>';
@@ -1606,7 +1606,7 @@ else
         }
         else print '<tr><td>&nbsp;</td><td>&nbsp;</td>';
         // ProfId4 (NU for France)
-        $profid=$langs->transcountry('ProfId4',$object->pays_code);
+        $profid=$langs->transcountry('ProfId4',$object->country_code);
         if ($profid!='-')
         {
             print '<td>'.$profid.'</td><td>';
@@ -1668,7 +1668,7 @@ else
 
         // Local Taxes
         // TODO add specific function by country
-        if($mysoc->pays_code=='ES')
+        if($mysoc->country_code=='ES')
         {
             if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
             {
diff --git a/htdocs/societe/societe.php b/htdocs/societe/societe.php
index 589e26003fe..49af8146ee7 100644
--- a/htdocs/societe/societe.php
+++ b/htdocs/societe/societe.php
@@ -278,12 +278,12 @@ if ($resql)
 	$textprofid=array();
 	foreach(array(1,2,3,4) as $key)
 	{
-		$label=$langs->transnoentities("ProfId".$key.$mysoc->pays_code);
+		$label=$langs->transnoentities("ProfId".$key.$mysoc->country_code);
 		$textprofid[$key]='';
-		if ($label != "ProfId".$key.$mysoc->pays_code)
+		if ($label != "ProfId".$key.$mysoc->country_code)
 		{	// Get only text between ()
 			if (preg_match('/\((.*)\)/i',$label,$reg)) $label=$reg[1];
-			$textprofid[$key]=$langs->trans("ProfIdShortDesc",$key,$mysoc->pays_code,$label);
+			$textprofid[$key]=$langs->trans("ProfIdShortDesc",$key,$mysoc->country_code,$label);
 		}
 	}
 
diff --git a/test/phpunit/SocieteTest.php b/test/phpunit/SocieteTest.php
index 126ed136477..d43ad86471d 100755
--- a/test/phpunit/SocieteTest.php
+++ b/test/phpunit/SocieteTest.php
@@ -248,7 +248,7 @@ class SocieteTest extends PHPUnit_Framework_TestCase
         $this->assertContains("New address\nNew zip New town", $result);
 
         $result=$localobject->isInEEC();
-        print __METHOD__." id=".$localobject->id." pays_code=".$this->pays_code." result=".$result."\n";
+        print __METHOD__." id=".$localobject->id." country_code=".$this->country_code." result=".$result."\n";
         $this->assertTrue(true, $result);
 
         $localobject->info($localobject->id);
-- 
GitLab