From 59a3a32f78b126a62502186463568482e725da52 Mon Sep 17 00:00:00 2001
From: Regis Houssin <regis@dolibarr.fr>
Date: Mon, 11 Jun 2007 22:51:47 +0000
Subject: [PATCH] Fix: changement de idp en rowid pour llx_societe et
 llx_socpeople afin d'unifier le code.

---
 dev/generate-commande.php                     |  2 +-
 dev/generate-facture.php                      |  2 +-
 dev/generate-produit.php                      |  2 +-
 dev/generate-propale.php                      |  4 +-
 dev/generate-societe.php                      |  2 +-
 doc/wiki/content_wiki.txt                     |  2 +-
 htdocs/bon-prelevement.class.php              |  4 +-
 htdocs/bookmarks/liste.php                    |  6 +-
 htdocs/categories/fiche.php                   | 14 +--
 htdocs/client.class.php                       |  4 +-
 htdocs/comm/action/index.php                  |  8 +-
 htdocs/comm/action/rapport/rapport.pdf.php    |  4 +-
 htdocs/comm/addpropal.php                     |  2 +-
 htdocs/comm/adresse_livraison.class.php       | 16 ++--
 htdocs/comm/bookmark.php                      |  8 +-
 htdocs/comm/clients.php                       | 14 +--
 htdocs/comm/contact.php                       | 22 ++---
 htdocs/comm/fiche.php                         | 58 ++++++------
 htdocs/comm/index.php                         | 92 +++++++++----------
 htdocs/comm/propal.php                        | 12 +--
 htdocs/comm/propal/apercu.php                 |  8 +-
 htdocs/comm/prospect/fiche.php                | 26 +++---
 htdocs/comm/prospect/index.php                | 30 +++---
 htdocs/comm/prospect/prospects.php            | 18 ++--
 htdocs/comm/recap-client.php                  |  2 +-
 htdocs/commande/apercu.php                    |  8 +-
 htdocs/commande/commande.class.php            |  2 +-
 htdocs/commande/fiche.php                     | 13 ++-
 htdocs/commande/index.php                     | 40 ++++----
 htdocs/commande/liste.php                     | 10 +-
 htdocs/commonobject.class.php                 | 26 +++---
 htdocs/compta/bank/account.php                | 10 +-
 htdocs/compta/bank/functions.lib.php          | 10 +-
 htdocs/compta/clients.php                     | 20 ++--
 htdocs/compta/commande/liste.php              | 10 +-
 htdocs/compta/deplacement/index.php           | 10 +-
 .../export/ComptaJournalPaiement.class.php    |  2 +-
 .../export/ComptaJournalVente.class.php       |  2 +-
 .../export/modules/compta.export.class.php    |  8 +-
 htdocs/compta/facture.php                     |  8 +-
 htdocs/compta/facture/fiche-rec.php           |  9 +-
 htdocs/compta/facture/impayees.php            | 18 ++--
 htdocs/compta/fiche.php                       | 34 +++----
 htdocs/compta/index.php                       | 62 ++++++-------
 htdocs/compta/paiement/fiche.php              |  6 +-
 htdocs/compta/prelevement/create.php          |  6 +-
 htdocs/compta/prelevement/demandes.php        |  8 +-
 htdocs/compta/prelevement/factures.php        |  8 +-
 htdocs/compta/prelevement/facturesrejets.php  |  8 +-
 htdocs/compta/prelevement/fiche-rejet.php     |  8 +-
 htdocs/compta/prelevement/index.php           |  8 +-
 htdocs/compta/prelevement/ligne.php           |  8 +-
 htdocs/compta/prelevement/lignes.php          |  8 +-
 htdocs/compta/prelevement/liste.php           |  2 +-
 htdocs/compta/prelevement/liste_factures.php  |  8 +-
 htdocs/compta/prelevement/rejets.php          |  8 +-
 htdocs/compta/propal.php                      | 16 ++--
 htdocs/compta/recap-compta.php                |  6 +-
 htdocs/compta/resultat/clientfourn.php        | 26 +++---
 htdocs/compta/resultat/index.php              |  4 +-
 htdocs/compta/stats/casoc.php                 | 18 ++--
 htdocs/compta/stats/comp.php                  | 29 +++---
 htdocs/compta/stats/exercices.php             | 12 +--
 htdocs/compta/stats/index.php                 | 12 +--
 htdocs/compta/tva/clients.php                 | 12 +--
 htdocs/contact.class.php                      | 26 +++---
 htdocs/contact/exportimport.php               |  2 +-
 htdocs/contact/fiche.php                      |  2 +-
 htdocs/contact/index.php                      | 16 ++--
 htdocs/contact/info.php                       |  2 +-
 htdocs/contact/ldap.php                       |  2 +-
 htdocs/contact/perso.php                      |  2 +-
 htdocs/contrat/fiche.php                      |  8 +-
 htdocs/contrat/index.php                      | 24 ++---
 htdocs/contrat/liste.php                      | 12 +--
 htdocs/contrat/services.php                   | 10 +-
 .../class/courrier-droit-editeur.class.php    | 21 ++---
 htdocs/document.php                           |  2 +-
 htdocs/don.class.php                          |  2 +-
 htdocs/expedition/expedition.class.php        |  2 +-
 htdocs/expedition/index.php                   | 46 +++++-----
 htdocs/expedition/liste.php                   | 10 +-
 htdocs/facture.class.php                      |  2 +-
 htdocs/fichinter/index.php                    | 12 +--
 htdocs/fichinter/rapport.php                  | 10 +-
 htdocs/fourn/commande/index.php               |  2 +-
 htdocs/fourn/commande/liste.php               |  8 +-
 htdocs/fourn/contact.php                      | 10 +-
 htdocs/fourn/facture/impayees.php             | 10 +-
 htdocs/fourn/facture/index.php                | 10 +-
 htdocs/fourn/facture/paiement.php             | 16 ++--
 htdocs/fourn/facture/paiementfourn.class.php  |  2 +-
 htdocs/fourn/fiche-stats.php                  |  2 +-
 htdocs/fourn/fiche.php                        | 16 ++--
 htdocs/fourn/fournisseur.class.php            |  4 +-
 htdocs/fourn/fournisseur.commande.class.php   |  2 +-
 htdocs/fourn/fournisseur.facture.class.php    |  6 +-
 htdocs/fourn/index.php                        | 24 ++---
 htdocs/fourn/liste.php                        | 12 +--
 htdocs/fourn/paiement/fiche.php               |  6 +-
 htdocs/fourn/product/fiche.php                | 16 ++--
 htdocs/fourn/product/liste.php                |  2 +-
 htdocs/fourn/recap-fourn.php                  |  2 +-
 htdocs/fourn/stats.php                        | 18 ++--
 htdocs/html.form.class.php                    | 18 ++--
 htdocs/includes/boxes/box_actions.php         | 10 +-
 htdocs/includes/boxes/box_clients.php         |  8 +-
 htdocs/includes/boxes/box_commandes.php       | 10 +-
 htdocs/includes/boxes/box_factures.php        | 10 +-
 htdocs/includes/boxes/box_factures_fourn.php  | 10 +-
 .../includes/boxes/box_factures_fourn_imp.php | 10 +-
 htdocs/includes/boxes/box_factures_imp.php    |  8 +-
 htdocs/includes/boxes/box_fournisseurs.php    |  8 +-
 htdocs/includes/boxes/box_propales.php        | 10 +-
 htdocs/includes/boxes/box_prospect.php        |  8 +-
 htdocs/includes/boxes/box_services_vendus.php | 10 +-
 .../modules/mailings/poire.modules.php        |  8 +-
 htdocs/includes/modules/modCommande.class.php |  8 +-
 htdocs/includes/modules/modFacture.class.php  | 16 ++--
 .../includes/modules/modFournisseur.class.php | 16 ++--
 htdocs/includes/modules/modSociete.class.php  | 14 +--
 .../modules/societe/mod_codeclient_lion.php   |  2 +-
 .../modules/societe/mod_codeclient_zebre.php  |  2 +-
 .../societe/mod_codecompta_aquarium.php       |  2 +-
 htdocs/lib/functions.inc.php                  |  4 +-
 htdocs/lolix/lolix.societe.class.php          |  2 +-
 htdocs/main.inc.php                           |  2 +-
 htdocs/notify.class.php                       | 18 ++--
 .../clients/osc_customer.class.php            |  2 +-
 htdocs/paiement.class.php                     |  2 +-
 htdocs/product/canvas/product.livre.class.php | 10 +-
 htdocs/product/droitpret/droitpret.class.php  | 10 +-
 htdocs/product/fiche.php                      | 32 +++----
 htdocs/product/fournisseurs.php               | 10 +-
 htdocs/product/stats/commande.php             |  8 +-
 htdocs/product/stats/commande_fournisseur.php |  8 +-
 htdocs/product/stats/contrat.php              |  8 +-
 htdocs/product/stats/facture.php              | 10 +-
 htdocs/product/stats/facture_fournisseur.php  | 10 +-
 htdocs/product/stats/propal.php               |  8 +-
 htdocs/projet/index.php                       |  8 +-
 htdocs/projet/liste.php                       | 10 +-
 htdocs/projet/tasks/index.php                 |  4 +-
 htdocs/propal.class.php                       |  4 +-
 htdocs/prospect.class.php                     |  4 +-
 htdocs/public/dons/depenses_code.php          |  2 +-
 htdocs/societe.class.php                      | 44 ++++-----
 htdocs/societe.php                            | 26 +++---
 htdocs/societe/lien.php                       |  4 +-
 htdocs/societe/notify/fiche.php               |  4 +-
 htdocs/societe/notify/index.php               | 10 +-
 htdocs/socnote.php                            |  2 +-
 htdocs/telephonie/adsl/fiche.php              | 10 +-
 htdocs/telephonie/adsl/liste.php              |  8 +-
 htdocs/telephonie/ca/gain.php                 |  2 +-
 htdocs/telephonie/client/contacts.php         | 12 +--
 htdocs/telephonie/client/factures.php         |  6 +-
 htdocs/telephonie/client/fiche.php            |  4 +-
 htdocs/telephonie/client/index.php            | 24 ++---
 htdocs/telephonie/client/lignes.php           | 10 +-
 htdocs/telephonie/client/liste.php            | 10 +-
 htdocs/telephonie/client/my.php               |  8 +-
 htdocs/telephonie/client/remises.php          |  6 +-
 htdocs/telephonie/client/remisesdone.php      |  6 +-
 htdocs/telephonie/client/tarifs.php           |  4 +-
 htdocs/telephonie/contrat/fiche.php           | 44 ++++-----
 htdocs/telephonie/contrat/index.php           | 12 +--
 htdocs/telephonie/contrat/info.php            |  6 +-
 htdocs/telephonie/contrat/liste.php           | 12 +--
 htdocs/telephonie/contrat/services.php        |  4 +-
 htdocs/telephonie/distributeurs/po.php        |  8 +-
 htdocs/telephonie/distributeurs/remav.php     | 10 +-
 htdocs/telephonie/distributeurs/remconso.php  | 10 +-
 .../telephonie/distributeurs/remuneration.php | 30 +++---
 htdocs/telephonie/facture/liste.php           | 10 +-
 .../commande/commande.tableur.class.php       |  6 +-
 .../commande/commande.text.class.php          |  4 +-
 .../commande/commande.textp.class.php         |  4 +-
 .../commande/commande.web.class.php           |  4 +-
 htdocs/telephonie/index.php                   |  2 +-
 .../ligne/commande/commandetableur.class.php  |  6 +-
 htdocs/telephonie/ligne/commande/fiche.php    | 10 +-
 .../telephonie/ligne/commande/historique.php  |  4 +-
 htdocs/telephonie/ligne/commande/liste.php    |  6 +-
 htdocs/telephonie/ligne/factures.php          |  4 +-
 htdocs/telephonie/ligne/fiche.php             | 12 +--
 htdocs/telephonie/ligne/groupe.php            |  6 +-
 htdocs/telephonie/ligne/index.php             | 10 +-
 htdocs/telephonie/ligne/liste.php             |  6 +-
 htdocs/telephonie/ligne/listecommande.php     |  4 +-
 htdocs/telephonie/lignetel.class.php          |  8 +-
 .../script/api/presel-activation-manuelle.php | 12 +--
 .../api/presel-resiliation-manuelle.php       | 12 +--
 .../script/api/presel-resiliation.php         | 12 +--
 htdocs/telephonie/script/commande_presel.php  |  6 +-
 .../script/cron/presel-resiliation.php        | 12 +--
 htdocs/telephonie/script/delete_presel.php    | 12 +--
 .../script/envoi-emails-speciaux.php          | 10 +-
 .../telephonie/script/facturation-alerte.php  | 12 +--
 .../script/facturation-consolidation.php      |  4 +-
 .../script/facturation-emission.php           |  6 +-
 .../script/graph-statistiques-clients.php     |  2 +-
 .../script/graph-statistiques-makedir.php     |  2 +-
 htdocs/telephonie/script/plan-facturation.php |  2 +-
 .../telephonie/script/recap-commande-week.php |  6 +-
 htdocs/telephonie/script/recap-commande.php   |  6 +-
 .../script/tools/export-adsl-actives.php      |  2 +-
 .../script/tools/export-comms-client52.php    |  2 +-
 .../script/tools/export-recap-client52.php    |  2 +-
 .../telephonie/script/tools/permissions.php   |  2 +-
 htdocs/telephonie/script/update_presel.php    |  4 +-
 htdocs/telephonie/service/contrats.php        |  6 +-
 htdocs/telephonie/service/vendus.php          |  6 +-
 .../llx_telephonie_adsl_fournisseur.key.sql   |  2 +-
 .../sql/llx_telephonie_client_stats.key.sql   |  2 +-
 .../llx_telephonie_contact_facture.key.sql    |  2 +-
 .../sql/llx_telephonie_societe_ligne.key.sql  |  6 +-
 .../sql/llx_telephonie_tarif_client.key.sql   |  2 +-
 .../stats/ProcessGraphClients.class.php       | 10 +-
 htdocs/telephonie/stats/clients/alerte.php    | 12 +--
 htdocs/telephonie/stats/clients/gain.php      | 18 ++--
 .../stats/commerciaux/commercialpo.php        |  8 +-
 htdocs/telephonie/tarifs/config/index.php     |  4 +-
 htdocs/telephonie/tarifs/config/prefixs.php   |  4 +-
 htdocs/telephonie/tarifs/fiche.php            |  6 +-
 htdocs/telephonie/tarifs/index.php            |  4 +-
 .../telephonie/telephonie.contrat.class.php   |  4 +-
 htdocs/user.class.php                         |  4 +-
 htdocs/user/home.php                          |  2 +-
 htdocs/user/index.php                         |  2 +-
 mysql/data/data_dev.sql                       | 58 ++++++------
 mysql/migration/2.1.0-2.2.0.sql               | 68 +++++++++++++-
 mysql/tables/llx_categorie_societe.key.sql    |  2 +-
 mysql/tables/llx_commande.key.sql             |  4 +-
 mysql/tables/llx_commande_fournisseur.key.sql |  4 +-
 mysql/tables/llx_contrat.key.sql              |  6 +-
 mysql/tables/llx_facture.key.sql              |  2 +-
 mysql/tables/llx_facture_fourn.key.sql        |  2 +-
 mysql/tables/llx_fichinter.key.sql            |  2 +-
 mysql/tables/llx_osc_customer.key.sql         | 37 +++++---
 mysql/tables/llx_osc_customer.sql             | 46 ++++++----
 mysql/tables/llx_osc_order.sql                | 48 +++++-----
 mysql/tables/llx_osc_product.sql              | 48 +++++-----
 .../llx_product_fournisseur_price.key.sql     |  2 +-
 mysql/tables/llx_propal.key.sql               |  3 +-
 mysql/tables/llx_societe.sql                  |  2 +-
 .../tables/llx_societe_remise_except.key.sql  |  2 +-
 mysql/tables/llx_socpeople.key.sql            |  2 +-
 mysql/tables/llx_socpeople.sql                |  2 +-
 pgsql/data/data_dev.sql                       | 38 ++++----
 scripts/addons/editeur/droits-nouveautes.php  |  2 +-
 scripts/company/export-csv-example.php        |  2 +-
 scripts/company/import-csv.pl                 |  2 +-
 .../company/sync_contacts_dolibarr2ldap.php   |  2 +-
 scripts/courrier/droits-editeurs.php          |  8 +-
 .../factures-impayees-commerciaux.php         |  6 +-
 scripts/prelevement/prelevement.php           |  2 +-
 257 files changed, 1399 insertions(+), 1307 deletions(-)

diff --git a/dev/generate-commande.php b/dev/generate-commande.php
index e18d4ee1b81..6fbe19ae613 100644
--- a/dev/generate-commande.php
+++ b/dev/generate-commande.php
@@ -42,7 +42,7 @@ include_once(DOL_DOCUMENT_ROOT."/contrat/contrat.class.php");
 define (GEN_NUMBER_COMMANDE, 10);
 
 
-$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe"; $societesid = array();
+$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; $societesid = array();
 if ($db->query($sql)) { $num = $db->num_rows(); $i = 0;
 	while ($i < $num) {
 		$row = $db->fetch_row($i);      $societesid[$i] = $row[0];      $i++;
diff --git a/dev/generate-facture.php b/dev/generate-facture.php
index 9b2744f65d6..ab85e41618c 100644
--- a/dev/generate-facture.php
+++ b/dev/generate-facture.php
@@ -51,7 +51,7 @@ if ($resql)
 }
 
 $socids = array();
-$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe WHERE client=1";
+$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1";
 $resql = $db->query($sql);
 if ($resql) 
 {
diff --git a/dev/generate-produit.php b/dev/generate-produit.php
index 7a610366c7c..1277efaba10 100644
--- a/dev/generate-produit.php
+++ b/dev/generate-produit.php
@@ -46,7 +46,7 @@ if ($db->query($sql)) {
   $num = $db->num_rows(); $i = 0;	
   while ($i < $num) {      $row = $db->fetch_row($i);      $productsid[$i] = $row[0];      $i++; } }
 
-$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe"; $societesid = array();
+$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; $societesid = array();
 if ($db->query($sql)) { $num = $db->num_rows(); $i = 0;	
 while ($i < $num) { $row = $db->fetch_row($i);      $societesid[$i] = $row[0];      $i++; } } else { print "err"; }
 
diff --git a/dev/generate-propale.php b/dev/generate-propale.php
index f41be4c6a2b..2504cf001b5 100644
--- a/dev/generate-propale.php
+++ b/dev/generate-propale.php
@@ -49,7 +49,7 @@ if ($resql)
 }
 
 $socids = array();
-$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe WHERE client=1";
+$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1";
 $resql = $db->query($sql);
 if ($resql) 
 {
@@ -65,7 +65,7 @@ if ($resql)
 }
 
 $contids = array();
-$sql = "SELECT idp, fk_soc FROM ".MAIN_DB_PREFIX."socpeople";
+$sql = "SELECT rowid, fk_soc FROM ".MAIN_DB_PREFIX."socpeople";
 $resql = $db->query($sql);
 if ($resql) 
 {
diff --git a/dev/generate-societe.php b/dev/generate-societe.php
index bc916f4b047..f4920e61668 100644
--- a/dev/generate-societe.php
+++ b/dev/generate-societe.php
@@ -55,7 +55,7 @@ if ($db->query($sql)) {
   $num = $db->num_rows(); $i = 0;	
   while ($i < $num) {      $row = $db->fetch_row($i);      $productsid[$i] = $row[0];      $i++; } }
 
-$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe"; $societesid = array();
+$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; $societesid = array();
 if ($db->query($sql)) { $num = $db->num_rows(); $i = 0;	
 while ($i < $num) { $row = $db->fetch_row($i);      $societesid[$i] = $row[0];      $i++; } } else { print "err"; }
 
diff --git a/doc/wiki/content_wiki.txt b/doc/wiki/content_wiki.txt
index d3366cb8d0b..38cbbe6a5b1 100644
--- a/doc/wiki/content_wiki.txt
+++ b/doc/wiki/content_wiki.txt
@@ -827,7 +827,7 @@ ALTER TABLE llx_facture ADD INDEX idx_facture_fk_user_author (fk_user_author);
 ALTER TABLE llx_facture ADD INDEX idx_facture_fk_user_valid (fk_user_valid);
 ALTER TABLE llx_facture ADD INDEX idx_facture_fk_projet (fk_projet);
 
-ALTER TABLE llx_facture ADD CONSTRAINT fk_facture_fk_soc            FOREIGN KEY (fk_soc) REFERENCES llx_societe (idp);
+ALTER TABLE llx_facture ADD CONSTRAINT fk_facture_fk_soc            FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
 ALTER TABLE llx_facture ADD CONSTRAINT fk_facture_fk_user_author    FOREIGN KEY (fk_user_author) REFERENCES llx_user (rowid);
 ALTER TABLE llx_facture ADD CONSTRAINT fk_facture_fk_user_valid     FOREIGN KEY (fk_user_valid) REFERENCES llx_user (rowid);
 ALTER TABLE llx_facture ADD CONSTRAINT fk_facture_fk_projet         FOREIGN KEY (fk_projet) REFERENCES llx_projet (rowid);
diff --git a/htdocs/bon-prelevement.class.php b/htdocs/bon-prelevement.class.php
index b5f27a37cdb..76fdd9e29c9 100644
--- a/htdocs/bon-prelevement.class.php
+++ b/htdocs/bon-prelevement.class.php
@@ -687,8 +687,8 @@ class BonPrelevement
             $sql .= " , ".MAIN_DB_PREFIX."societe_rib as sr";
 
             $sql .= " WHERE f.rowid = pfd.fk_facture";
-            $sql .= " AND s.idp = f.fk_soc";
-            $sql .= " AND s.idp = sr.fk_soc";
+            $sql .= " AND s.rowid = f.fk_soc";
+            $sql .= " AND s.rowid = sr.fk_soc";
             $sql .= " AND f.fk_statut = 1";
             $sql .= " AND f.paye = 0";
             $sql .= " AND pfd.traite = 0";
diff --git a/htdocs/bookmarks/liste.php b/htdocs/bookmarks/liste.php
index 5f62d9675c6..6f00d98a9fa 100644
--- a/htdocs/bookmarks/liste.php
+++ b/htdocs/bookmarks/liste.php
@@ -72,7 +72,7 @@ print_fiche_titre($langs->trans("Bookmarks"));
  
 if ($mesg) print $mesg;
 
-$sql = "SELECT b.fk_soc as idp, ".$db->pdate("b.dateb")." as dateb, b.rowid as bid, b.fk_user, b.url, b.target, b.title, b.favicon,";
+$sql = "SELECT b.fk_soc as rowid, ".$db->pdate("b.dateb")." as dateb, b.rowid as bid, b.fk_user, b.url, b.target, b.title, b.favicon,";
 $sql.= " u.login, u.name, u.firstname";
 $sql.= " FROM ".MAIN_DB_PREFIX."bookmark as b, ".MAIN_DB_PREFIX."user as u";
 $sql.= " WHERE b.fk_user=u.rowid";
@@ -117,7 +117,7 @@ if ($resql)
 
         // Title
         print "<td>";
-        if ($obj->idp)
+        if ($obj->rowid)
         {
             // Lien interne societe
             $lieninterne=1;
@@ -127,7 +127,7 @@ if ($resql)
                 // Pour compatibilite avec anciens bookmarks
                 require_once(DOL_DOCUMENT_ROOT."/societe.class.php");
                 $societe=new Societe($db);
-                $societe->fetch($obj->idp);
+                $societe->fetch($obj->rowid);
                 $obj->title=$societe->nom;
             }
             $title=img_object($langs->trans("ShowCompany"),"company").' '.$obj->title;
diff --git a/htdocs/categories/fiche.php b/htdocs/categories/fiche.php
index 8dc930d3ded..7f0e869f628 100644
--- a/htdocs/categories/fiche.php
+++ b/htdocs/categories/fiche.php
@@ -44,9 +44,9 @@ else
 
 if ($_REQUEST['origin'])
 {
-	if($_GET['type'] == 0)$idprodorigin = $_REQUEST['origin'];
-	if($_GET['type'] == 1)$idSupplierorigin = $_REQUEST['origin'];
-	if($_GET['type'] == 2)$idCompanyorigin = $_REQUEST['origin'];
+	if($_GET['type'] == 0)$idProdOrigin = $_REQUEST['origin'];
+	if($_GET['type'] == 1)$idSupplierOrigin = $_REQUEST['origin'];
+	if($_GET['type'] == 2)$idCompanyOrigin = $_REQUEST['origin'];
 	
 }
 
@@ -103,13 +103,13 @@ if ($_POST["action"] == 'add' && $user->rights->categorie->creer)
 		print '<div class="ok">'.$langs->trans("CategorySuccessfullyCreated",$categorie->label).'</div>';
 		print '<br>';
 		
-		if ($idprodorigin)
+		if ($idProdOrigin)
 		{
-			print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/categorie.php?id='.$idprodorigin.'">'.$langs->trans("ReturnInProduct").'</a>';
+			print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/categorie.php?id='.$idProdOrigin.'">'.$langs->trans("ReturnInProduct").'</a>';
 		}
-		if ($idSupplierorigin || $idCompanyorigin)
+		if ($idSupplierOrigin || $idCompanyOrigin)
 		{
-			print '<a class="butAction" href="'.DOL_URL_ROOT.'/categories/categorie.php?socid='.$idCompanyorigin.'">'.$langs->trans("ReturnInCompany").'</a>';
+			print '<a class="butAction" href="'.DOL_URL_ROOT.'/categories/categorie.php?socid='.$idCompanyOrigin.'">'.$langs->trans("ReturnInCompany").'</a>';
 		}
 
 		print '</td></tr></table>';
diff --git a/htdocs/client.class.php b/htdocs/client.class.php
index 874e9c16d53..2daa121d6f0 100644
--- a/htdocs/client.class.php
+++ b/htdocs/client.class.php
@@ -93,12 +93,12 @@ class Client extends Societe
         
         $this->nb=array("customers" => 0,"prospects" => 0);
 
-        $sql = "SELECT count(s.idp) as nb, s.client";
+        $sql = "SELECT count(s.rowid) as nb, s.client";
         if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
         if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
         $sql.= " WHERE s.client in (1,2)";
-        if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+        if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
         $sql.= " GROUP BY s.client";
         $resql=$this->db->query($sql);
         if ($resql)
diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php
index 888a4a75a21..f481bf621b5 100644
--- a/htdocs/comm/action/index.php
+++ b/htdocs/comm/action/index.php
@@ -63,14 +63,14 @@ llxHeader();
  *
  */
 
-$sql = "SELECT s.nom as societe, s.idp as socid, s.client,";
+$sql = "SELECT s.nom as societe, s.rowid as socid, s.client,";
 $sql.= " a.id,".$db->pdate("a.datep")." as dp, a.fk_contact, a.note, a.label, a.percent as percent,";
 $sql.= " c.code as acode, c.libelle,";
 $sql.= " u.login, u.rowid as userid";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."user as u";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql.= " WHERE a.fk_soc = s.idp AND c.id=a.fk_action AND a.fk_user_author = u.rowid";
+$sql.= " WHERE a.fk_soc = s.rowid AND c.id = a.fk_action AND a.fk_user_author = u.rowid";
 if ($_GET["type"])
 {
   $sql .= " AND c.id = ".$_GET["type"];
@@ -81,11 +81,11 @@ if ($_GET["time"] == "today")
 }
 if ($socid) 
 {
-  $sql .= " AND s.idp = ".$socid;
+  $sql .= " AND s.rowid = ".$socid;
 }
 if (!$user->rights->commercial->client->voir && !$socid) //restriction
 {
-	$sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 }
 if ($status == 'done') { $sql.= " AND a.percent = 100"; }
 if ($status == 'todo') { $sql.= " AND a.percent < 100"; }
diff --git a/htdocs/comm/action/rapport/rapport.pdf.php b/htdocs/comm/action/rapport/rapport.pdf.php
index b0d7d15f736..b12700f7588 100644
--- a/htdocs/comm/action/rapport/rapport.pdf.php
+++ b/htdocs/comm/action/rapport/rapport.pdf.php
@@ -149,9 +149,9 @@ class CommActionRapport
         $pdf->SetFont('Arial','',8);
         $y=$pdf->GetY()+1;
         
-        $sql = "SELECT s.nom as societe, s.idp as socid, s.client, a.id,".$this->db->pdate("a.datea")." as da, a.datea, c.libelle, u.login, a.fk_contact, a.note, a.percent as percent";
+        $sql = "SELECT s.nom as societe, s.rowid as socid, s.client, a.id,".$this->db->pdate("a.datea")." as da, a.datea, c.libelle, u.login, a.fk_contact, a.note, a.percent as percent";
         $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."user as u";
-        $sql .= " WHERE a.fk_soc = s.idp AND c.id=a.fk_action AND a.fk_user_author = u.rowid";
+        $sql .= " WHERE a.fk_soc = s.rowid AND c.id=a.fk_action AND a.fk_user_author = u.rowid";
 
         $sql .= " AND date_format(a.datea, '%m') = ".$this->month;
         $sql .= " AND date_format(a.datea, '%Y') = ".$this->year;
diff --git a/htdocs/comm/addpropal.php b/htdocs/comm/addpropal.php
index 4ee52466e92..d96bed75b20 100644
--- a/htdocs/comm/addpropal.php
+++ b/htdocs/comm/addpropal.php
@@ -266,7 +266,7 @@ if ($conf->expedition->enabled)
     $liste_propal[0] = '';
     $sql ="SELECT p.rowid as id, CONCAT(p.ref, ' - ', s.nom)  as lib";
     $sql.=" FROM ".MAIN_DB_PREFIX."propal p, ".MAIN_DB_PREFIX."societe s";
-    $sql.=" WHERE s.idp = p.fk_soc AND fk_statut <> 0 ORDER BY Id";
+    $sql.=" WHERE s.rowid = p.fk_soc AND fk_statut <> 0 ORDER BY Id";
     $resql = $db->query($sql);
     if ($resql)
     {
diff --git a/htdocs/comm/adresse_livraison.class.php b/htdocs/comm/adresse_livraison.class.php
index ef43c71ab45..29221f8c247 100644
--- a/htdocs/comm/adresse_livraison.class.php
+++ b/htdocs/comm/adresse_livraison.class.php
@@ -238,9 +238,9 @@ class AdresseLivraison
     {
 		   global $langs, $conf;
 
-		   $sql = 'SELECT idp, nom, client, fournisseur';
+		   $sql = 'SELECT rowid, nom, client, fournisseur';
 		   $sql .= ' FROM '.MAIN_DB_PREFIX.'societe';
-		   $sql .= ' WHERE idp = '.$socid;
+		   $sql .= ' WHERE rowid = '.$socid;
 		   
 		   $resqlsoc=$this->db->query($sql);
     
@@ -251,8 +251,8 @@ class AdresseLivraison
                 $obj = $this->db->fetch_object($resqlsoc);
                 
                 $this->nom_societe = $obj->nom;
-                $this->socid       = $obj->idp;
-                $this->id          = $obj->idp;
+                $this->socid       = $obj->rowid;
+                $this->id          = $obj->rowid;
                 $this->client      = $obj->client;
                 $this->fournisseur = $obj->fournisseur;
              }
@@ -416,7 +416,7 @@ class AdresseLivraison
   function get_nom($id)
   {
 
-    $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE idp='$id';";
+    $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE rowid='".$id."';";
 
     $result = $this->db->query($sql);
 
@@ -442,10 +442,10 @@ class AdresseLivraison
     */
     function info($id)
     {
-        $sql = "SELECT s.idp, s.nom, ".$this->db->pdate("datec")." as datec, ".$this->db->pdate("datea")." as datea,";
+        $sql = "SELECT s.rowid, s.nom, ".$this->db->pdate("datec")." as datec, ".$this->db->pdate("datea")." as datea,";
         $sql.= " fk_user_creat, fk_user_modif";
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
-        $sql.= " WHERE s.idp = ".$id;
+        $sql.= " WHERE s.rowid = ".$id;
 
         $result=$this->db->query($sql);
         if ($result)
@@ -454,7 +454,7 @@ class AdresseLivraison
             {
                 $obj = $this->db->fetch_object($result);
 
-                $this->id = $obj->idp;
+                $this->id = $obj->rowid;
 
                 if ($obj->fk_user_creat) {
                     $cuser = new User($this->db, $obj->fk_user_creat);
diff --git a/htdocs/comm/bookmark.php b/htdocs/comm/bookmark.php
index 448817137e2..7330f127ffe 100644
--- a/htdocs/comm/bookmark.php
+++ b/htdocs/comm/bookmark.php
@@ -92,9 +92,9 @@ if ($_GET["action"] == 'delete')
 
 print_fiche_titre($langs->trans("Bookmarks"));
  
-$sql = "SELECT s.idp, s.nom, ".$db->pdate("b.dateb")." as dateb, b.rowid as bid, b.fk_user, b.url, b.target, u.name, u.firstname";
+$sql = "SELECT s.rowid, s.nom, ".$db->pdate("b.dateb")." as dateb, b.rowid as bid, b.fk_user, b.url, b.target, u.name, u.firstname";
 $sql.= " FROM ".MAIN_DB_PREFIX."bookmark as b, ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."user as u";
-$sql.= " WHERE b.fk_soc = s.idp AND b.fk_user=u.rowid";
+$sql.= " WHERE b.fk_soc = s.rowid AND b.fk_user=u.rowid";
 if (! $user->admin) $sql.= " AND b.fk_user = ".$user->id;
 $sql.= " ORDER BY $sortfield $sortorder " . $db->plimit( $limit, $offset);
 
@@ -131,10 +131,10 @@ if ($resql)
       print "<td align=\"center\"><b>".$obj->bid."</b></td>";
       print "<td><a href='".DOL_URL_ROOT."/user/fiche.php?id=".$obj->fk_user."'>".img_object($langs->trans("ShowUser"),"user").' '.$obj->name." ".$obj->firstname."</a></td>\n";
       print '<td align="center">'.dolibarr_print_date($obj->dateb) ."</td>";
-      print "<td><a href=\"index.php?socid=$obj->idp\">".img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom."</a></td>\n";
+      print "<td><a href=\"index.php?socid=".$obj->rowid."\">".img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom."</a></td>\n";
       print '<td align="center">'.$obj->url."</td>";
       print '<td align="center">'.$obj->target."</td>";
-      print "<td><a href=\"bookmark.php?action=delete&bid=$obj->bid\">".img_delete()."</a></td>\n";
+      print "<td><a href=\"bookmark.php?action=delete&bid=".$obj->bid."\">".img_delete()."</a></td>\n";
       print "</tr>\n";
       $i++;
     }
diff --git a/htdocs/comm/clients.php b/htdocs/comm/clients.php
index 77429b65135..2c901eb3628 100644
--- a/htdocs/comm/clients.php
+++ b/htdocs/comm/clients.php
@@ -46,15 +46,15 @@ $search_ville=isset($_GET["search_ville"])?$_GET["search_ville"]:$_POST["search_
 $search_code=isset($_GET["search_code"])?$_GET["search_code"]:$_POST["search_code"];
 
 
-$sql = "SELECT s.idp, s.nom, s.ville, ".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea, st.libelle as stcomm, s.prefix_comm, s.code_client";
+$sql = "SELECT s.rowid, s.nom, s.ville, ".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea, st.libelle as stcomm, s.prefix_comm, s.code_client";
 if (!$user->rights->commercial->client->voir) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st";
 if (!$user->rights->commercial->client->voir) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 $sql .= " WHERE s.fk_stcomm = st.id AND s.client=1";
 
-if ($socid)           $sql .= " AND s.idp = $socid";
-if ($user->societe_id) $sql .= " AND s.idp = " .$user->societe_id;
-if (!$user->rights->commercial->client->voir) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+if ($socid)           $sql .= " AND s.rowid = ".$socid;
+if ($user->societe_id) $sql .= " AND s.rowid = " .$user->societe_id;
+if (!$user->rights->commercial->client->voir) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 
 if ($search_nom)   $sql .= " AND s.nom like '%".addslashes(strtolower($search_nom))."%'";
 if ($search_ville) $sql .= " AND s.ville like '%".addslashes(strtolower($search_ville))."%'";
@@ -119,16 +119,16 @@ if ($result)
       $var=!$var;
       
       print "<tr $bc[$var]>";
-      print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">';
+      print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->rowid.'">';
       print img_object($langs->trans("ShowCustomer"),"company");
-      print '</a>&nbsp;<a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.stripslashes($obj->nom).'</a></td>';
+      print '</a>&nbsp;<a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->rowid.'">'.stripslashes($obj->nom).'</a></td>';
       print '<td>'.$obj->ville.'</td>';
       print '<td>'.$obj->code_client.'</td>';
       print '<td align="center">'.dolibarr_print_date($obj->datec).'</td>';
       print '<td align="center">';
       if (defined("MAIN_MODULE_DOSSIER") && MAIN_MODULE_DOSSIER == 1)
 	{
-	  print '<a href="'.DOL_URL_ROOT.'/dossier/client/fiche.php?id='.$obj->idp.'">';
+	  print '<a href="'.DOL_URL_ROOT.'/dossier/client/fiche.php?id='.$obj->rowid.'">';
 	  print img_folder();
 	  print '</a>';
 	}
diff --git a/htdocs/comm/contact.php b/htdocs/comm/contact.php
index c2947d63a9b..a76f6003aae 100644
--- a/htdocs/comm/contact.php
+++ b/htdocs/comm/contact.php
@@ -71,15 +71,15 @@ if ($type == "f")
  *
  */
 
-$sql = "SELECT s.idp, s.nom,  st.libelle as stcomm";
-$sql .= ", p.idp as cidp, p.name, p.firstname, p.email, p.phone";
+$sql = "SELECT s.rowid, s.nom,  st.libelle as stcomm";
+$sql .= ", p.rowid as cidp, p.name, p.firstname, p.email, p.phone";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql .= " FROM ".MAIN_DB_PREFIX."c_stcomm as st,";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
 $sql .= " ".MAIN_DB_PREFIX."socpeople as p";
-$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.idp = p.fk_soc";
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
 $sql .= " WHERE s.fk_stcomm = st.id";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 if ($type == "c") $sql .= " AND s.client = 1";
 if ($type == "p") $sql .= " AND s.client = 2";
 if ($type == "f") $sql .= " AND s.fournisseur = 1";
@@ -118,7 +118,7 @@ if ($_GET["contactname"]) // acces a partir du module de recherche
 }
 
 if ($socid) {
-  $sql .= " AND s.idp = $socid";
+  $sql .= " AND s.rowid = ".$socid;
 }
 
 $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($limit+1, $offset);
@@ -158,16 +158,16 @@ if ($result)
       $var=!$var;
 
       print "<tr $bc[$var]>";
-      print '<td><a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->cidp.'&socid='.$obj->idp.'">'.img_object($langs->trans("ShowContact"),"contact");
-      print '</a>&nbsp;<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->cidp.'&socid='.$obj->idp.'">'.$obj->name.'</a></td>';
+      print '<td><a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowContact"),"contact");
+      print '</a>&nbsp;<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.$obj->name.'</a></td>';
       print "<td>$obj->firstname</TD>";
       
-      print '<td><a href="'.$_SERVER["PHP_SELF"].'?type='.$type.'&socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").'</a>&nbsp;';
-      print "<a href=\"".$urlfiche."?socid=$obj->idp\">$obj->nom</a></td>\n";
+      print '<td><a href="'.$_SERVER["PHP_SELF"].'?type='.$type.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowCompany"),"company").'</a>&nbsp;';
+      print "<a href=\"".$urlfiche."?socid=".$obj->rowid."\">$obj->nom</a></td>\n";
       
-      print '<td><a href="action/fiche.php?action=create&actioncode=AC_EMAIL&contactid='.$obj->cidp.'&socid='.$obj->idp.'">'.$obj->email.'</a>&nbsp;</td>';
+      print '<td><a href="action/fiche.php?action=create&actioncode=AC_EMAIL&contactid='.$obj->cidp.'&socid='.$obj->rowid.'">'.$obj->email.'</a>&nbsp;</td>';
       
-      print '<td><a href="action/fiche.php?action=create&actioncode=AC_TEL&contactid='.$obj->cidp.'&socid='.$obj->idp.'">'.dolibarr_print_phone($obj->phone).'</a>&nbsp;</td>';
+      print '<td><a href="action/fiche.php?action=create&actioncode=AC_TEL&contactid='.$obj->cidp.'&socid='.$obj->rowid.'">'.dolibarr_print_phone($obj->phone).'</a>&nbsp;</td>';
       
       print "</tr>\n";
       $i++;
diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php
index 6bf0aa86f22..3447238b4d4 100644
--- a/htdocs/comm/fiche.php
+++ b/htdocs/comm/fiche.php
@@ -71,7 +71,7 @@ if ($_POST["action"] == 'setconditions' && $user->rights->societe->creer)
 	$societe = new Societe($db, $_GET["socid"]);
     $societe->cond_reglement=$_POST['cond_reglement_id'];
 	$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET cond_reglement='".$_POST['cond_reglement_id'];
-	$sql.= "' WHERE idp='".$_GET["socid"]."'";
+	$sql.= "' WHERE rowid='".$_GET["socid"]."'";
     $result = $db->query($sql);
     if (! $result) dolibarr_print_error($result);
 }
@@ -81,7 +81,7 @@ if ($_POST["action"] == 'setmode' && $user->rights->societe->creer)
     $societe = new Societe($db, $_GET["socid"]);
     $societe->mode_reglement=$_POST['mode_reglement_id'];
 	$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET mode_reglement='".$_POST['mode_reglement_id'];
-	$sql.= "' WHERE idp='".$_GET["socid"]."'";
+	$sql.= "' WHERE rowid='".$_GET["socid"]."'";
     $result = $db->query($sql);
     if (! $result) dolibarr_print_error($result);
 }
@@ -90,7 +90,7 @@ if ($_POST["action"] == 'setassujtva' && $user->rights->societe->creer)
 {
 	$societe = new Societe($db, $_GET["socid"]);
     $societe->tva_assuj=$_POST['assujtva_value'];
-	$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET tva_assuj='".$_POST['assujtva_value']."' WHERE idp='".$socid."'";
+	$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET tva_assuj='".$_POST['assujtva_value']."' WHERE rowid='".$socid."'";
     $result = $db->query($sql);
     if (! $result) dolibarr_print_error($result);
 }
@@ -105,7 +105,7 @@ if ($action == 'stcomm')
 
         if ($result)
         {
-            $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=$stcommid WHERE idp=".$socid;
+            $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=$stcommid WHERE rowid=".$socid;
             $result = $db->query($sql);
         }
         else
@@ -132,18 +132,18 @@ if ($action == 'stcomm')
  */
 if ($mode == 'search') {
     if ($mode-search == 'soc') {
-        $sql = "SELECT s.idp";
+        $sql = "SELECT s.rowid";
         if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
         $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
         if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
         $sql .= " WHERE lower(s.nom) like '%".strtolower($socname)."%'";
-        if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+        if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
     }
 
     if ( $db->query($sql) ) {
         if ( $db->num_rows() == 1) {
             $obj = $db->fetch_object();
-            $socid = $obj->idp;
+            $socid = $obj->rowid;
         }
         $db->free();
     }
@@ -381,11 +381,11 @@ if ($socid > 0)
 
         print '<table class="noborder" width="100%">';
 
-	    $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.fk_statut, p.price, p.ref, p.remise, ";
+	    $sql = "SELECT s.nom, s.rowid, p.rowid as propalid, p.fk_statut, p.price, p.ref, p.remise, ";
 	    $sql.= " ".$db->pdate("p.datep")." as dp, ".$db->pdate("p.fin_validite")." as datelimite";
         $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c";
-        $sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut = c.id";
-        $sql .= " AND s.idp = ".$objsoc->id;
+        $sql .= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id";
+        $sql .= " AND s.rowid = ".$objsoc->id;
         $sql .= " ORDER BY p.datep DESC";
         
         $resql=$db->query($sql);
@@ -433,12 +433,12 @@ if ($socid > 0)
         
         print '<table class="noborder" width="100%">';
 
-        $sql = "SELECT s.nom, s.idp,";
+        $sql = "SELECT s.nom, s.rowid,";
         $sql.= " c.rowid as cid, c.total_ht, c.ref, c.fk_statut, c.facture,";
         $sql.= " ".$db->pdate("c.date_commande")." as dc";
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
-        $sql.= " WHERE c.fk_soc = s.idp ";
-        $sql.= " AND s.idp = $objsoc->id";
+        $sql.= " WHERE c.fk_soc = s.rowid ";
+        $sql.= " AND s.rowid = ".$objsoc->id;
         $sql.= " ORDER BY c.date_commande DESC";
 
         $resql=$db->query($sql);
@@ -481,10 +481,10 @@ if ($socid > 0)
         
         print '<table class="noborder" width="100%">';
 
-        $sql = "SELECT s.nom, s.idp, c.rowid as id, c.ref as ref, c.statut, ".$db->pdate("c.datec")." as dc";
+        $sql = "SELECT s.nom, s.rowid, c.rowid as id, c.ref as ref, c.statut, ".$db->pdate("c.datec")." as dc";
         $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
-        $sql .= " WHERE c.fk_soc = s.idp ";
-        $sql .= " AND s.idp = $objsoc->id";
+        $sql .= " WHERE c.fk_soc = s.rowid ";
+        $sql .= " AND s.rowid = ".$objsoc->id;
         $sql .= " ORDER BY c.datec DESC";
 
         $resql=$db->query($sql);
@@ -528,10 +528,10 @@ if ($socid > 0)
     {
         print '<table class="noborder" width="100%">';
 
-        $sql = "SELECT s.nom, s.idp, f.rowid as id, f.ref, ".$db->pdate("f.datei")." as di";
+        $sql = "SELECT s.nom, s.rowid, f.rowid as id, f.ref, ".$db->pdate("f.datei")." as di";
         $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as f";
-        $sql .= " WHERE f.fk_soc = s.idp";
-        $sql .= " AND s.idp = ".$objsoc->id;
+        $sql .= " WHERE f.fk_soc = s.rowid";
+        $sql .= " AND s.rowid = ".$objsoc->id;
         $sql .= " ORDER BY f.datei DESC";
         
         $resql=$db->query($sql);
@@ -669,7 +669,7 @@ if ($socid > 0)
     print '<td>&nbsp;</td>';
     print "</tr>";
 
-    $sql = "SELECT p.idp, p.name, p.firstname, p.poste, p.phone, p.fax, p.email, p.note ";
+    $sql = "SELECT p.rowid, p.name, p.firstname, p.poste, p.phone, p.fax, p.email, p.note ";
     $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
     $sql .= " WHERE p.fk_soc = ".$objsoc->id;
     $sql .= " ORDER by p.datec";
@@ -685,9 +685,9 @@ if ($socid > 0)
         $var = !$var;
         print "<tr $bc[$var]>";
 
-        $contactstatic->id=$obj->idp;
-        $contactstatic->name=$obj->name;
-        $contactstatic->firstname=$obj->firstname;
+        $contactstatic->id = $obj->rowid;
+        $contactstatic->name = $obj->name;
+        $contactstatic->firstname = $obj->firstname;
         print '<td>';
         print $contactstatic->getNomUrl(1);
         if (trim($obj->note))
@@ -701,7 +701,7 @@ if ($socid > 0)
         if (strlen($obj->phone) && $user->clicktodial_enabled == 1)
         {
             print '<td>';
-            print '<a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&actioncode=AC_TEL&contactid='.$obj->idp.'&amp;socid='.$objsoc->id.'&amp;call='.$obj->phone.'">';
+            print '<a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&actioncode=AC_TEL&contactid='.$obj->rowid.'&amp;socid='.$objsoc->id.'&amp;call='.$obj->phone.'">';
             print img_phone_out("Appel �mis") ;
             print '</td><td>';
         }
@@ -710,16 +710,16 @@ if ($socid > 0)
         	print '<td colspan="2">';
         }
         
-        print '<a href="action/fiche.php?action=create&actioncode=AC_TEL&contactid='.$obj->idp.'&socid='.$objsoc->id.'">'.dolibarr_print_phone($obj->phone).'</a>&nbsp;</td>';
-        print '<td><a href="action/fiche.php?action=create&actioncode=AC_FAX&contactid='.$obj->idp.'&socid='.$objsoc->id.'">'.dolibarr_print_phone($obj->fax).'</a>&nbsp;</td>';
-        print '<td><a href="action/fiche.php?action=create&actioncode=AC_EMAIL&contactid='.$obj->idp.'&socid='.$objsoc->id.'">'.$obj->email.'</a>&nbsp;</td>';
+        print '<a href="action/fiche.php?action=create&actioncode=AC_TEL&contactid='.$obj->rowid.'&socid='.$objsoc->id.'">'.dolibarr_print_phone($obj->phone).'</a>&nbsp;</td>';
+        print '<td><a href="action/fiche.php?action=create&actioncode=AC_FAX&contactid='.$obj->rowid.'&socid='.$objsoc->id.'">'.dolibarr_print_phone($obj->fax).'</a>&nbsp;</td>';
+        print '<td><a href="action/fiche.php?action=create&actioncode=AC_EMAIL&contactid='.$obj->rowid.'&socid='.$objsoc->id.'">'.$obj->email.'</a>&nbsp;</td>';
 
         print '<td align="center">';
-        print "<a href=\"../contact/fiche.php?action=edit&amp;id=$obj->idp\">";
+        print "<a href=\"../contact/fiche.php?action=edit&amp;id=".$obj->rowid."\">";
         print img_edit();
         print '</a></td>';
 
-        print '<td align="center"><a href="action/fiche.php?action=create&actioncode=AC_RDV&contactid='.$obj->idp.'&socid='.$objsoc->id.'">';
+        print '<td align="center"><a href="action/fiche.php?action=create&actioncode=AC_RDV&contactid='.$obj->rowid.'&socid='.$objsoc->id.'">';
         print img_object($langs->trans("Rendez-Vous"),"action");
         print '</a></td>';
 
diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php
index b5450e5b2cb..fab4cef530c 100644
--- a/htdocs/comm/index.php
+++ b/htdocs/comm/index.php
@@ -131,16 +131,16 @@ if ($conf->contrat->enabled)
  */
 if ($conf->propal->enabled && $user->rights->propale->lire)
 {
-    $sql = "SELECT p.rowid, p.ref, p.price, s.idp, s.nom";
+    $sql = "SELECT p.rowid, p.ref, p.price, s.rowid as socid, s.nom";
     if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
     $sql.= " FROM ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."societe as s";
     if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-    $sql.= " WHERE p.fk_statut = 0 and p.fk_soc = s.idp";
+    $sql.= " WHERE p.fk_statut = 0 and p.fk_soc = s.rowid";
     if ($socid) 
     {
-       $sql .= " AND s.idp = $socid";
+       $sql .= " AND s.rowid = ".$socid;
     }
-    if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+    if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  
     $resql=$db->query($sql);
     if ($resql)
@@ -160,7 +160,7 @@ if ($conf->propal->enabled && $user->rights->propale->lire)
                 $obj = $db->fetch_object($resql);
                 $var=!$var;
                 print '<tr '.$bc[$var].'><td nowrap>'."<a href=\"".DOL_URL_ROOT."/comm/propal.php?propalid=".$obj->rowid."\">".img_object($langs->trans("ShowPropal"),"propal")." ".$obj->ref.'</a></td>';
-                print '<td><a href="fiche.php?socid='.$obj->idp.'">'.dolibarr_trunc($obj->nom,18).'</a></td>';
+                print '<td><a href="fiche.php?socid='.$obj->socid.'">'.dolibarr_trunc($obj->nom,18).'</a></td>';
                 print '<td align="right" nowrap="nowrap">'.price($obj->price).'</td></tr>';
                 $i++;
                 $total += $obj->price;
@@ -183,12 +183,12 @@ if ($conf->propal->enabled && $user->rights->propale->lire)
 if ($conf->commande->enabled)
 {
     $langs->load("orders");
-    $sql = "SELECT c.rowid, c.ref, c.total_ttc, s.nom, s.idp";
+    $sql = "SELECT c.rowid, c.ref, c.total_ttc, s.nom, s.rowid as socid";
     if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
     $sql.= " FROM ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s";
     if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-    $sql.= " WHERE c.fk_soc = s.idp AND c.fk_statut = 0";
-    if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+    $sql.= " WHERE c.fk_soc = s.rowid AND c.fk_statut = 0";
+    if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
     if ($socid)
     {
         $sql .= " AND c.fk_soc = ".$socid;
@@ -212,7 +212,7 @@ if ($conf->commande->enabled)
                 $var=!$var;
                 $obj = $db->fetch_object($resql);
                 print "<tr $bc[$var]><td nowrap><a href=\"../commande/fiche.php?id=$obj->rowid\">".img_object($langs->trans("ShowOrder"),"order")." ".$obj->ref."</a></td>";
-                print '<td><a href="fiche.php?socid='.$obj->idp.'">'.dolibarr_trunc($obj->nom,18).'</a></td>';
+                print '<td><a href="fiche.php?socid='.$obj->socid.'">'.dolibarr_trunc($obj->nom,18).'</a></td>';
                 print '<td align="right" nowrap="nowrap">'.price($obj->total_ttc).'</td></tr>';
                 $i++;
                 $total += $obj->total_ttc;
@@ -233,12 +233,12 @@ if ($conf->commande->enabled)
  */
  if ($conf->bookmark->enabled)
  {
- 	$sql = "SELECT s.idp, s.nom,b.rowid as bid";
+ 	$sql = "SELECT s.rowid, s.nom,b.rowid as bid";
  	$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."bookmark as b";
- 	$sql .= " WHERE b.fk_soc = s.idp AND b.fk_user = ".$user->id;
+ 	$sql .= " WHERE b.fk_soc = s.rowid AND b.fk_user = ".$user->id;
  	if ($socid)
   { 
-    $sql .= " AND s.idp = $socid"; 
+    $sql .= " AND s.rowid = ".$socid; 
   }
   $sql .= " ORDER BY lower(s.nom) ASC";
 
@@ -262,7 +262,7 @@ if ($conf->commande->enabled)
 	      $obj = $db->fetch_object();
 	      $var = !$var;
 	      print "<tr $bc[$var]>";
-	      print '<td><a href="fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td>';
+	      print '<td><a href="fiche.php?socid='.$obj->rowid.'">'.$obj->nom.'</a></td>';
 	      print '<td align="right"><a href="index.php?action=del_bookmark&bid='.$obj->bid.'">';
 	      print img_delete();
 	      print '</a></td>';
@@ -284,15 +284,15 @@ print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
 
 $sql = "SELECT a.id, a.label, ".$db->pdate("a.datep")." as dp, a.fk_user_author,";
 $sql.= " c.code, c.libelle,";
-$sql.= " s.nom as sname, s.idp, s.client";
+$sql.= " s.nom as sname, s.rowid, s.client";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."societe as s";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql.= " WHERE c.id=a.fk_action AND a.percent < 100 AND s.idp = a.fk_soc";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+$sql.= " WHERE c.id=a.fk_action AND a.percent < 100 AND s.rowid = a.fk_soc";
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 if ($socid)
 {
-    $sql .= " AND s.idp = ".$socid;
+    $sql .= " AND s.rowid = ".$socid;
 }
 $sql .= " ORDER BY a.datep DESC, a.id DESC";
 
@@ -324,7 +324,7 @@ if ($resql)
 
             print '<td>'.dolibarr_trunc($obj->label,24).'</td>';
 
-            $customerstatic->id=$obj->idp;
+            $customerstatic->id=$obj->rowid;
             $customerstatic->nom=$obj->sname;
             $customerstatic->client=$obj->client;
             print '<td>'.$customerstatic->getNomUrl(1,'',16).'</td>';
@@ -362,18 +362,18 @@ else
 
 $sql = "SELECT a.id, a.percent, ".$db->pdate("a.datea")." as da, a.fk_user_author,";
 $sql.= " c.code, c.libelle,";
-$sql.= " s.idp, s.nom as sname, s.client";
+$sql.= " s.rowid, s.nom as sname, s.client";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."societe as s";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql .= " WHERE c.id=a.fk_action AND a.percent >= 100 AND s.idp = a.fk_soc";
+$sql .= " WHERE c.id = a.fk_action AND a.percent >= 100 AND s.rowid = a.fk_soc";
 if ($socid)
 {
-	$sql .= " AND s.idp = ".$socid;
+	$sql .= " AND s.rowid = ".$socid;
 }
 if (!$user->rights->commercial->client->voir && !$socid) //restriction
 {
-	$sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 }
 $sql .= " ORDER BY a.datea DESC";
 $sql .= $db->plimit($max, 0);
@@ -403,7 +403,7 @@ if ($resql)
 		print $libelle;
 		print '</a></td>';
 
-		$customerstatic->id=$obj->idp;
+		$customerstatic->id=$obj->rowid;
 		$customerstatic->nom=$obj->sname;
 		$customerstatic->client=$obj->client;
 		print '<td>'.$customerstatic->getNomUrl(1,'',24).'</td>';
@@ -435,18 +435,18 @@ else
  */
 if ($user->rights->societe->lire)
 {
-    $sql = "SELECT s.idp,s.nom,".$db->pdate("datec")." as datec";
+    $sql = "SELECT s.rowid,s.nom,".$db->pdate("datec")." as datec";
     if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
     $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
     if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
     $sql.= " WHERE s.client = 1";
     if ($socid)
     {
-        $sql .= " AND s.idp = $socid";
+        $sql .= " AND s.rowid = $socid";
     }
     if (!$user->rights->commercial->client->voir && !$socid) //restriction
     {
-	      $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+	      $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
     }
     $sql .= " ORDER BY s.datec DESC";
     $sql .= $db->plimit($max, 0);
@@ -469,7 +469,7 @@ if ($user->rights->societe->lire)
             {
                 $objp = $db->fetch_object($resql);
                 print "<tr $bc[$var]>";
-                print "<td nowrap><a href=\"".DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->idp."\">".img_object($langs->trans("ShowCustomer"),"company")." ".$objp->nom."</a></td>";
+                print "<td nowrap><a href=\"".DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->rowid."\">".img_object($langs->trans("ShowCustomer"),"company")." ".$objp->nom."</a></td>";
                 print '<td align="right" nowrap>'.dolibarr_print_date($objp->datec)."</td>";
                 print '</tr>';
                 $i++;
@@ -492,18 +492,18 @@ if ($conf->contrat->enabled && 0) // \todo A REFAIRE DEPUIS NOUVEAU CONTRAT
 {
   $langs->load("contracts");
   
-  $sql = "SELECT s.nom, s.idp, c.statut, c.rowid, p.ref, c.mise_en_service as datemes, c.fin_validite as datefin, c.date_cloture as dateclo";
+  $sql = "SELECT s.nom, s.rowid, c.statut, c.rowid as contratid, p.ref, c.mise_en_service as datemes, c.fin_validite as datefin, c.date_cloture as dateclo";
   if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
   $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."product as p";
   if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-  $sql .= " WHERE c.fk_soc = s.idp and c.fk_product = p.rowid";
+  $sql .= " WHERE c.fk_soc = s.rowid and c.fk_product = p.rowid";
   if ($socid)
-    { 
-      $sql .= " AND s.idp = $socid"; 
-    }
+  { 
+      $sql .= " AND s.rowid = ".$socid; 
+  }
   if (!$user->rights->commercial->client->voir && !$socid) //restriction
   {
-	    $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+	    $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
   }
   $sql .= " ORDER BY c.tms DESC";
   $sql .= $db->plimit(5, 0);
@@ -524,8 +524,8 @@ if ($conf->contrat->enabled && 0) // \todo A REFAIRE DEPUIS NOUVEAU CONTRAT
 	  while ($i < $num)
 	    {
 	      $obj = $db->fetch_object();
-	      print "<tr $bc[$var]><td><a href=\"../contrat/fiche.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowContract","contract"))." ".$obj->ref."</a></td>";
-	      print "<td><a href=\"fiche.php?socid=$obj->idp\">".img_object($langs->trans("ShowCompany","company"))." ".$obj->nom."</a></td>\n";      
+	      print "<tr $bc[$var]><td><a href=\"../contrat/fiche.php?id=".$obj->contratid."\">".img_object($langs->trans("ShowContract","contract"))." ".$obj->ref."</a></td>";
+	      print "<td><a href=\"fiche.php?socid=".$obj->rowid."\">".img_object($langs->trans("ShowCompany","company"))." ".$obj->nom."</a></td>\n";      
 	      print "<td align=\"right\">".$staticcontrat->LibStatut($obj->statut,3)."</td></tr>\n";
 	      $var=!$var;
 	      $i++;
@@ -547,13 +547,13 @@ if ($conf->propal->enabled && $user->rights->propale->lire)
 {
     $langs->load("propal");
     
-    $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price, p.ref, p.fk_statut, ".$db->pdate("p.datep")." as dp";
+    $sql = "SELECT s.nom, s.rowid, p.rowid as propalid, p.price, p.ref, p.fk_statut, ".$db->pdate("p.datep")." as dp";
     if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
     $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p";
     if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-    $sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut = 1";
-    if ($socid) $sql .= " AND s.idp = $socid";
-    if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+    $sql .= " WHERE p.fk_soc = s.rowid AND p.fk_statut = 1";
+    if ($socid) $sql .= " AND s.rowid = ".$socid;
+    if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
     $sql .= " ORDER BY p.rowid DESC";
     
     $result=$db->query($sql);
@@ -575,11 +575,11 @@ if ($conf->propal->enabled && $user->rights->propale->lire)
                 print "<tr $bc[$var]><td width=\"15%\" nowrap><a href=\"propal.php?propalid=".$obj->propalid."\">".img_object($langs->trans("ShowPropal"),"propal")." ".$obj->ref."</a>";
     		    if ($obj->dp < (time() - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late"));
                 print "</td>";
-                print "<td><a href=\"fiche.php?socid=$obj->idp\">".img_object($langs->trans("ShowCompany"),"company")." ".dolibarr_trunc($obj->nom,44)."</a></td>\n";
+                print "<td><a href=\"fiche.php?socid=".$obj->rowid."\">".img_object($langs->trans("ShowCompany"),"company")." ".dolibarr_trunc($obj->nom,44)."</a></td>\n";
                 print "<td align=\"right\">";
                 print dolibarr_print_date($obj->dp)."</td>\n";
                 print "<td align=\"right\">".price($obj->price)."</td>";
-				print "<td align=\"center\" width=\"14\">".$propalstatic->LibStatut($obj->fk_statut,3)."</td>\n";
+				        print "<td align=\"center\" width=\"14\">".$propalstatic->LibStatut($obj->fk_statut,3)."</td>\n";
                 print "</tr>\n";
                 $i++;
                 $total += $obj->price;
@@ -604,16 +604,16 @@ if ($conf->propal->enabled && $user->rights->propale->lire)
 if ($conf->propal->enabled && $user->rights->propale->lire) {
     $NBMAX=5;
     
-	$sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price, p.ref, p.fk_statut, ".$db->pdate("p.datep")." as dp";
+	$sql = "SELECT s.nom, s.rowid, p.rowid as propalid, p.price, p.ref, p.fk_statut, ".$db->pdate("p.datep")." as dp";
 	if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 	$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p";
 	if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-	$sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut > 1";
+	$sql .= " WHERE p.fk_soc = s.rowid AND p.fk_statut > 1";
 	if ($socid)
 	{ 
-	  $sql .= " AND s.idp = $socid"; 
+	  $sql .= " AND s.rowid = ".$socid; 
 	}
-	if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+	if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 	$sql .= " ORDER BY p.rowid DESC";
 	$sql .= $db->plimit($NBMAX, 0);
 	
@@ -632,7 +632,7 @@ if ($conf->propal->enabled && $user->rights->propale->lire) {
 		print '<td nowrap>';
 		print '<a href="propal.php?propalid='.$objp->propalid.'">'.img_object($langs->trans("ShowPropal"),"propal").' ';
 		print $objp->ref.'</a></td>';
-		print '<td><a href="fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44).'</a></td>';
+		print '<td><a href="fiche.php?socid='.$objp->rowid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44).'</a></td>';
         print "<td>&nbsp;</td>";
 		print "<td align=\"right\">";
 		print dolibarr_print_date($objp->dp)."</td>\n";	  
diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index c2e14a48a22..f008e5408eb 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -1672,17 +1672,17 @@ else
   $pageprev = $page - 1;
   $pagenext = $page + 1;
 
-  $sql = 'SELECT s.nom, s.idp, s.client, ';
+  $sql = 'SELECT s.nom, s.rowid, s.client, ';
   $sql.= 'p.rowid as propalid, p.price, p.ref, p.fk_statut, '.$db->pdate('p.datep').' as dp,'.$db->pdate('p.fin_validite').' as dfv';
   if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
   $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p';
   if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
   if ($sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet as pd ON p.rowid=pd.fk_propal';
-  $sql.= ' WHERE p.fk_soc = s.idp';
+  $sql.= ' WHERE p.fk_soc = s.rowid';
 
   if (!$user->rights->commercial->client->voir && !$socid) //restriction
     {
-	    $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+	    $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
     }
   if (!empty($_GET['search_ref']))
     {
@@ -1697,7 +1697,7 @@ else
       $sql .= " AND p.price='".addslashes($_GET['search_montant_ht'])."'";
     }
   if ($sall) $sql.= " AND (s.nom like '%".addslashes($sall)."%' OR p.note like '%".addslashes($sall)."%' OR pd.description like '%".addslashes($sall)."%')";
-  if ($socid) $sql .= ' AND s.idp = '.$socid;
+  if ($socid) $sql .= ' AND s.rowid = '.$socid;
   if ($_GET['viewstatut'] <> '')
     {
       $sql .= ' AND p.fk_statut in ('.$_GET['viewstatut'].')';
@@ -1764,11 +1764,11 @@ else
 
             if ($objp->client == 1)
             {
-                $url = DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->idp;
+                $url = DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->rowid;
             }
             else
             {
-                $url = DOL_URL_ROOT.'/comm/prospect/fiche.php?socid='.$objp->idp;
+                $url = DOL_URL_ROOT.'/comm/prospect/fiche.php?socid='.$objp->rowid;
             }
 
 			// Soci�t�
diff --git a/htdocs/comm/propal/apercu.php b/htdocs/comm/propal/apercu.php
index 5471d5d3c33..13e66bdebe7 100644
--- a/htdocs/comm/propal/apercu.php
+++ b/htdocs/comm/propal/apercu.php
@@ -81,11 +81,11 @@ if ($_GET["propalid"] > 0)
 		/*
 		*   Propal
 		*/
-		$sql = 'SELECT s.nom, s.idp, p.price, p.fk_projet, p.remise, p.tva, p.total, p.ref, p.fk_statut, '.$db->pdate('p.datep').' as dp, p.note,';
+		$sql = 'SELECT s.nom, s.rowid, p.price, p.fk_projet, p.remise, p.tva, p.total, p.ref, p.fk_statut, '.$db->pdate('p.datep').' as dp, p.note,';
 		$sql.= ' p.fk_user_author, p.fk_user_valid, p.fk_user_cloture, p.datec, p.date_valid, p.date_cloture';
 		$sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p';
-		$sql.= ' WHERE p.fk_soc = s.idp AND p.rowid = '.$propal->id;
-		if ($socid) $sql .= ' AND s.idp = '.$socid;
+		$sql.= ' WHERE p.fk_soc = s.rowid AND p.rowid = '.$propal->id;
+		if ($socid) $sql .= ' AND s.rowid = '.$socid;
 
 		$result = $db->query($sql);
 
@@ -95,7 +95,7 @@ if ($_GET["propalid"] > 0)
 				$obj = $db->fetch_object($result);
 
 				$societe = new Societe($db);
-				$societe->fetch($obj->idp);
+				$societe->fetch($obj->rowid);
 
 				print '<table class="border" width="100%">';
 
diff --git a/htdocs/comm/prospect/fiche.php b/htdocs/comm/prospect/fiche.php
index 5f72dd3071e..8f5dca2f3f4 100644
--- a/htdocs/comm/prospect/fiche.php
+++ b/htdocs/comm/prospect/fiche.php
@@ -58,7 +58,7 @@ if (!$user->rights->commercial->client->voir && $socid && !$user->societe_id > 0
 {
         $sql = "SELECT sc.rowid";
         $sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."societe as s";
-        $sql .= " WHERE sc.fk_soc = ".$socid." AND sc.fk_soc = s.idp AND sc.fk_user = ".$user->id." AND s.client = 2";
+        $sql .= " WHERE sc.fk_soc = ".$socid." AND sc.fk_soc = s.rowid AND sc.fk_user = ".$user->id." AND s.client = 2";
 
         if ( $db->query($sql) )
         {
@@ -75,7 +75,7 @@ if (!$user->rights->commercial->client->voir && $socid && !$user->societe_id > 0
 if ($_GET["action"] == 'cstc')
 {
   $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm = ".$_GET["stcomm"];
-  $sql .= " WHERE idp = ".$_GET["id"];
+  $sql .= " WHERE rowid = ".$_GET["id"];
   $db->query($sql);
 }
 
@@ -162,12 +162,12 @@ if ($socid > 0)
      *
      */
     print '<table class="noborder" width="100%">';
-    $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.fk_statut, p.price, p.ref, p.remise, ";
+    $sql = "SELECT s.nom, s.rowid as socid, p.rowid as propalid, p.fk_statut, p.price, p.ref, p.remise, ";
     $sql.= " ".$db->pdate("p.datep")." as dp, ".$db->pdate("p.fin_validite")." as datelimite,";
     $sql.= " c.label as statut, c.id as statutid";
     $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c";
-    $sql.= " WHERE p.fk_soc = s.idp AND p.fk_statut = c.id";
-    $sql.= " AND s.idp = ".$societe->id;
+    $sql.= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id";
+    $sql.= " AND s.rowid = ".$societe->id;
     $sql.= " ORDER BY p.datep DESC";
 
     $resql=$db->query($sql);
@@ -261,7 +261,7 @@ if ($socid > 0)
 		print '<td>&nbsp;</td>';
 		print "</tr>";
 
-        $sql = "SELECT p.idp, p.name, p.firstname, p.poste, p.phone, p.fax, p.email, p.note";
+        $sql = "SELECT p.rowid, p.name, p.firstname, p.poste, p.phone, p.fax, p.email, p.note";
         $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as p";
         $sql.= " WHERE p.fk_soc = ".$societe->id;
         $sql.= " ORDER by p.datec";
@@ -277,7 +277,7 @@ if ($socid > 0)
             print "<tr $bc[$var]>";
 
             print '<td>';
-            print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->idp.'">'.img_object($langs->trans("ShowContact"),"contact").' '.$obj->firstname.' '. $obj->name.'</a>&nbsp;';
+            print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowContact"),"contact").' '.$obj->firstname.' '. $obj->name.'</a>&nbsp;';
 
             if (trim($obj->note))
             {
@@ -285,23 +285,23 @@ if ($socid > 0)
             }
             print '</td>';
             print '<td>'.$obj->poste.'&nbsp;</td>';
-            print '<td><a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&actioncode=AC_TEL&contactid='.$obj->idp.'&socid='.$societe->id.'">'.$obj->phone;
+            print '<td><a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&actioncode=AC_TEL&contactid='.$obj->rowid.'&socid='.$societe->id.'">'.$obj->phone;
 
 	        if (strlen($obj->phone) && $user->clicktodial_enabled == 1)
 	        {
-	            print '<a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&actioncode=AC_TEL&contactid='.$obj->idp.'&amp;socid='.$societe->id.'&amp;call='.$obj->phone.'">';
+	            print '<a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&actioncode=AC_TEL&contactid='.$obj->rowid.'&amp;socid='.$societe->id.'&amp;call='.$obj->phone.'">';
 	            print img_phone_out("Appel �mis") ;
 	        }
 			print '</a></td>';
 
-            print '<td><a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&actioncode=AC_FAX&contactid='.$obj->idp.'&socid='.$societe->id.'">'.$obj->fax.'</a>&nbsp;</td>';
-            print '<td><a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&actioncode=AC_EMAIL&contactid='.$obj->idp.'&socid='.$societe->id.'">'.$obj->email.'</a>&nbsp;</td>';
+            print '<td><a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&actioncode=AC_FAX&contactid='.$obj->rowid.'&socid='.$societe->id.'">'.$obj->fax.'</a>&nbsp;</td>';
+            print '<td><a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&actioncode=AC_EMAIL&contactid='.$obj->rowid.'&socid='.$societe->id.'">'.$obj->email.'</a>&nbsp;</td>';
 
         	print '<td align="center">';
         	
            	if ($user->rights->societe->contact->creer)
     		{
-        		print "<a href=\"".DOL_URL_ROOT."/contact/fiche.php?action=edit&amp;id=$obj->idp\">";
+        		print "<a href=\"".DOL_URL_ROOT."/contact/fiche.php?action=edit&amp;id=".$obj->rowid."\">";
         	 	print img_edit();
         	 	print '</a>';
         	}
@@ -309,7 +309,7 @@ if ($socid > 0)
         		
         	print '</td>';
 
-            print '<td align="center"><a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&actioncode=AC_RDV&contactid='.$obj->idp.'&socid='.$societe->id.'">';
+            print '<td align="center"><a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&actioncode=AC_RDV&contactid='.$obj->rowid.'&socid='.$societe->id.'">';
             print img_object($langs->trans("Rendez-Vous"),"action");
             print '</a></td>';
 
diff --git a/htdocs/comm/prospect/index.php b/htdocs/comm/prospect/index.php
index 3a6ee0acc4f..4cb72180668 100644
--- a/htdocs/comm/prospect/index.php
+++ b/htdocs/comm/prospect/index.php
@@ -77,7 +77,7 @@ if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, s
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st ";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 $sql .= " WHERE s.fk_stcomm = st.id AND s.client=2";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 $sql .= " GROUP BY st.id";
 $sql .= " ORDER BY st.id";
 
@@ -117,8 +117,8 @@ if ($conf->propal->enabled && $user->rights->propale->lire)
     if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
     $sql .= " FROM ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."societe as s";
     if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-    $sql .= " WHERE p.fk_statut = 0 and p.fk_soc = s.idp";
-    if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+    $sql .= " WHERE p.fk_statut = 0 and p.fk_soc = s.rowid";
+    if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 
     $resql=$db->query($sql);
     if ($resql)
@@ -164,12 +164,12 @@ print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
 
 $sql = "SELECT a.id, ".$db->pdate("a.datea")." as da, a.fk_user_author, a.percent,";
 $sql.= " c.code, c.libelle,";
-$sql.= " s.nom as sname, s.idp";
+$sql.= " s.nom as sname, s.rowid";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."societe as s";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql .= " WHERE c.id=a.fk_action AND a.percent < 100 AND s.idp = a.fk_soc AND a.fk_user_action = $user->id";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+$sql .= " WHERE c.id = a.fk_action AND a.percent < 100 AND s.rowid = a.fk_soc AND a.fk_user_action = ".$user->id;
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 $sql .= " ORDER BY a.datea DESC";
 
 $resql=$db->query($sql);
@@ -199,7 +199,7 @@ if ($resql)
 			print '<td><a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?id='.$obj->id."\">".img_object($langs->trans("ShowAction"),"task").' '.$libelle.'</a></td>';
 
 			// Tiers
-			print '<td><a href="'.DOL_URL_ROOT.'/comm/prospect/fiche.php?id='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->sname.'</a></td>';
+			print '<td><a href="'.DOL_URL_ROOT.'/comm/prospect/fiche.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->sname.'</a></td>';
 			$i++;
 		}
 		print "</table><br>";
@@ -217,13 +217,13 @@ else
  */
 if ($conf->propal->enabled && $user->rights->propale->lire)
 {
-    $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price, p.ref,".$db->pdate("p.datep")." as dp, c.label as statut, c.id as statutid";
+    $sql = "SELECT s.nom, s.rowid as socid, p.rowid as propalid, p.price, p.ref,".$db->pdate("p.datep")." as dp, c.label as statut, c.id as statutid";
     if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
     $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c";
     if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-    $sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut = c.id AND p.fk_statut = 1";
-    if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
-    if ($socid) $sql .= " AND s.idp = $socid";
+    $sql .= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id AND p.fk_statut = 1";
+    if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
+    if ($socid) $sql .= " AND s.rowid = ".$socid;
     $sql .= " ORDER BY p.rowid DESC";
     $sql .= $db->plimit(5, 0);
     
@@ -247,7 +247,7 @@ if ($conf->propal->enabled && $user->rights->propale->lire)
                 print "<tr $bc[$var]><td><a href=\"../propal.php?propalid=".$obj->propalid."\">";
                 print img_object($langs->trans("ShowPropal"),"propal").' '.$obj->ref.'</a></td>';
     
-                print "<td><a href=\"fiche.php?id=$obj->idp\">".img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom."</a></td>\n";
+                print "<td><a href=\"fiche.php?id=".$obj->socid."\">".img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom."</a></td>\n";
                 print "<td align=\"right\">";
                 print dolibarr_print_date($obj->dp)."</td>\n";
                 print "<td align=\"right\">".price($obj->price)."</td></tr>\n";
@@ -266,12 +266,12 @@ if ($conf->propal->enabled && $user->rights->propale->lire)
  * Soci�t�s � contacter
  *
  */
-$sql = "SELECT s.nom, s.idp";
+$sql = "SELECT s.nom, s.rowid";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 $sql .= " WHERE s.fk_stcomm = 1";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 $sql .= " ORDER BY s.tms ASC";
 $sql .= $db->plimit(15, 0);
 
@@ -290,7 +290,7 @@ if ( $db->query($sql) )
 	{
 	  $obj = $db->fetch_object();
 	  $var=!$var;
-	  print "<tr $bc[$var]><td width=\"12%\"><a href=\"".DOL_URL_ROOT."/comm/prospect/fiche.php?id=".$obj->idp."\">";
+	  print "<tr $bc[$var]><td width=\"12%\"><a href=\"".DOL_URL_ROOT."/comm/prospect/fiche.php?id=".$obj->rowid."\">";
 	  print img_object($langs->trans("ShowCompany"),"company");
 	  print ' '.$obj->nom.'</a></td></tr>';
 	  $i++;
diff --git a/htdocs/comm/prospect/prospects.php b/htdocs/comm/prospect/prospects.php
index 395f9c52c24..9145caead75 100644
--- a/htdocs/comm/prospect/prospects.php
+++ b/htdocs/comm/prospect/prospects.php
@@ -66,7 +66,7 @@ $pagenext = $page + 1;
 if ($_GET["action"] == 'cstc')
 {
   $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm = ".$_GET["pstcomm"];
-  $sql .= " WHERE idp = ".$_GET["pid"];
+  $sql .= " WHERE rowid = ".$_GET["pid"];
   $db->query($sql);
 }
 
@@ -75,7 +75,7 @@ if ($_GET["action"] == 'cstc')
  * Affichage liste
  */
 
-$sql = "SELECT s.idp, s.nom, s.ville, ".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea,  st.libelle as stcomm, s.prefix_comm, s.fk_stcomm ";
+$sql = "SELECT s.rowid, s.nom, s.ville, ".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea,  st.libelle as stcomm, s.prefix_comm, s.fk_stcomm ";
 $sql .= ", d.nom as departement";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql .= " FROM (".MAIN_DB_PREFIX."c_stcomm as st, ".MAIN_DB_PREFIX."societe as s";
@@ -91,9 +91,9 @@ else
 	$sql .=")";
 }
 
-$sql .= " LEFT join ".MAIN_DB_PREFIX."c_departements as d on (d.rowid = s.fk_departement)";
-$sql .= " WHERE s.fk_stcomm = st.id AND s.client=2";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d on (d.rowid = s.fk_departement)";
+$sql .= " WHERE s.fk_stcomm = st.id AND s.client = 2";
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 
 if (isset($stcomm))
 {
@@ -102,7 +102,7 @@ if (isset($stcomm))
 
 if ($user->societe_id)
 {
-    $sql .= " AND s.idp = " .$user->societe_id;
+    $sql .= " AND s.rowid = " .$user->societe_id;
 }
 
 if ($_GET["search_nom"])
@@ -133,7 +133,7 @@ if ($resql)
     if ($num == 1 && $socname)
     {
         $obj = $db->fetch_object($resql);
-        Header("Location: fiche.php?socid=".$obj->idp);
+        Header("Location: fiche.php?socid=".$obj->rowid);
         exit;
     }
     else
@@ -181,7 +181,7 @@ if ($resql)
         $var=!$var;
 
         print "<tr $bc[$var]>";
-        print '<td><a href="'.DOL_URL_ROOT.'/comm/prospect/fiche.php?id='.$obj->idp.'">';
+        print '<td><a href="'.DOL_URL_ROOT.'/comm/prospect/fiche.php?id='.$obj->rowid.'">';
         print img_object($langs->trans("ShowProspect"),"company");
         print ' '.dolibarr_trunc($obj->nom,44).'</a></td>';
         print "<td>".$obj->ville."&nbsp;</td>";
@@ -199,7 +199,7 @@ if ($resql)
         {
             if ($value <> $obj->fk_stcomm)
             {
-                print '<a href="prospects.php?pid='.$obj->idp.'&amp;pstcomm='.$value.'&amp;action=cstc&amp;'.$urladd.'">';
+                print '<a href="prospects.php?pid='.$obj->rowid.'&amp;pstcomm='.$value.'&amp;action=cstc&amp;'.$urladd.'">';
                 print img_action(0,$value);
                 print '</a>&nbsp;';
             }
diff --git a/htdocs/comm/recap-client.php b/htdocs/comm/recap-client.php
index 1ce073ae773..dc62a1ce4ef 100644
--- a/htdocs/comm/recap-client.php
+++ b/htdocs/comm/recap-client.php
@@ -57,7 +57,7 @@ llxHeader();
 if ($socid > 0)
 {
     $societe = new Societe($db);
-    $societe->fetch($socid, $to);  // si $to='next' ajouter " AND s.idp > $socid ORDER BY idp ASC LIMIT 1";
+    $societe->fetch($socid, $to);  // si $to='next' ajouter " AND s.rowid > $socid ORDER BY idp ASC LIMIT 1";
 
     /*
      * Affichage onglets
diff --git a/htdocs/commande/apercu.php b/htdocs/commande/apercu.php
index 5d518dc7b80..dd60435bb22 100644
--- a/htdocs/commande/apercu.php
+++ b/htdocs/commande/apercu.php
@@ -89,12 +89,12 @@ if ($_GET["id"] > 0) {
 		/*
 		 *   Commande
 		 */
-		$sql = 'SELECT s.nom, s.idp, c.amount_ht, c.fk_projet, c.remise, c.tva, c.total_ttc, c.ref, c.fk_statut, '.$db->pdate('c.date_commande').' as dp, c.note,';
+		$sql = 'SELECT s.nom, s.rowid, c.amount_ht, c.fk_projet, c.remise, c.tva, c.total_ttc, c.ref, c.fk_statut, '.$db->pdate('c.date_commande').' as dp, c.note,';
 		$sql.= ' c.fk_user_author, c.fk_user_valid, c.fk_user_cloture, c.date_creation, c.date_valid, c.date_cloture';
 		$sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'commande as c';
-		$sql.= ' WHERE c.fk_soc = s.idp';
+		$sql.= ' WHERE c.fk_soc = s.rowid';
 		$sql.= ' AND c.rowid = '.$commande->id;
-		if ($socid) $sql .= ' AND s.idp = '.$socid;
+		if ($socid) $sql .= ' AND s.rowid = '.$socid;
 
 		$result = $db->query($sql);
 
@@ -105,7 +105,7 @@ if ($_GET["id"] > 0) {
 				$obj = $db->fetch_object($result);
 
 				$societe = new Societe($db);
-				$societe->fetch($obj->idp);
+				$societe->fetch($obj->rowid);
 
 				print '<table class="border" width="100%">';
 
diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php
index c494c06166a..846d7ccc016 100644
--- a/htdocs/commande/commande.class.php
+++ b/htdocs/commande/commande.class.php
@@ -2200,7 +2200,7 @@ class Commande extends CommonObject
 
 		// Charge tableau des id de soci�t� socids
 		$socids = array();
-		$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10";
+		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10";
 		$resql = $this->db->query($sql);
 		if ($resql)
 		{
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index b7b12ff7556..5c35ad1dfba 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -699,16 +699,19 @@ if ($_GET['action'] == 'create' && $user->rights->commande->creer)
   
   if ($propalid)
     {
-      $sql = 'SELECT s.nom, s.prefix_comm, s.idp, p.price, p.remise, p.remise_percent, p.tva, p.total, p.ref, p.fk_cond_reglement, p.fk_mode_reglement, '.$db->pdate('p.datep').' as dp, c.id as statut, c.label as lst';
+      $sql = 'SELECT s.nom, s.prefix_comm, s.rowid';
+      $sql.= ', p.price, p.remise, p.remise_percent, p.tva, p.total, p.ref, p.fk_cond_reglement, p.fk_mode_reglement';
+      $sql.= ', '.$db->pdate('p.datep').' as dp';
+      $sql.= ', c.id as statut, c.label as lst';
       $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p, '.MAIN_DB_PREFIX.'c_propalst as c';
-      $sql .= ' WHERE p.fk_soc = s.idp AND p.fk_statut = c.id';
+      $sql .= ' WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id';
       $sql .= ' AND p.rowid = '.$propalid;
     }
   else
     {
-      $sql = 'SELECT s.nom, s.prefix_comm, s.idp, s.mode_reglement, s.cond_reglement ';
+      $sql = 'SELECT s.nom, s.prefix_comm, s.rowid, s.mode_reglement, s.cond_reglement ';
       $sql .= 'FROM '.MAIN_DB_PREFIX.'societe as s ';
-      $sql .= 'WHERE s.idp = '.$_GET['socid'];
+      $sql .= 'WHERE s.rowid = '.$_GET['socid'];
     }
   $resql = $db->query($sql);
   if ( $resql )
@@ -719,7 +722,7 @@ if ($_GET['action'] == 'create' && $user->rights->commande->creer)
 	  $obj = $db->fetch_object($resql);
 	  
 	  $soc = new Societe($db);
-	  $soc->fetch($obj->idp);
+	  $soc->fetch($obj->rowid);
 	  
 	  $nbrow=7;
 	  
diff --git a/htdocs/commande/index.php b/htdocs/commande/index.php
index 85d72f156ac..8dc69a86a0d 100644
--- a/htdocs/commande/index.php
+++ b/htdocs/commande/index.php
@@ -72,13 +72,13 @@ print "</form></table><br>\n";
 /*
  * Commandes brouillons
  */
-$sql = "SELECT c.rowid, c.ref, s.nom, s.idp";
+$sql = "SELECT c.rowid, c.ref, s.nom, s.rowid as socid";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql .= " WHERE c.fk_soc = s.idp AND c.fk_statut = 0";
+$sql .= " WHERE c.fk_soc = s.rowid AND c.fk_statut = 0";
 if ($socid) $sql .= " AND c.fk_soc = ".$socid;
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 
 if ( $db->query($sql) )
 {
@@ -95,8 +95,8 @@ if ( $db->query($sql) )
         {
             $var=!$var;
             $obj = $db->fetch_object();
-            print "<tr $bc[$var]><td nowrap><a href=\"fiche.php?id=$obj->rowid\">".img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref."</a></td>";
-            print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($obj->nom,24).'</a></td></tr>';
+            print "<tr $bc[$var]><td nowrap><a href=\"fiche.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref."</a></td>";
+            print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($obj->nom,24).'</a></td></tr>';
             $i++;
         }
         print "</table><br>";
@@ -106,13 +106,13 @@ if ( $db->query($sql) )
 /*
  * Commandes � traiter
  */
-$sql = "SELECT c.rowid, c.ref, s.nom, s.idp";
+$sql = "SELECT c.rowid, c.ref, s.nom, s.rowid as socid";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql .=" FROM ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql .= " WHERE c.fk_soc = s.idp AND c.fk_statut = 1";
+$sql .= " WHERE c.fk_soc = s.rowid AND c.fk_statut = 1";
 if ($socid) $sql .= " AND c.fk_soc = ".$socid;
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 $sql .= " ORDER BY c.rowid DESC";
 
 if ( $db->query($sql) )
@@ -130,8 +130,8 @@ if ( $db->query($sql) )
         {
             $var=!$var;
             $obj = $db->fetch_object();
-            print "<tr $bc[$var]><td nowrap><a href=\"fiche.php?id=$obj->rowid\">".img_object($langs->trans("ShowOrder"),"order")." ".$obj->ref."</a></td>";
-            print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($obj->nom,24).'</a></td></tr>';
+            print "<tr $bc[$var]><td nowrap><a href=\"fiche.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"),"order")." ".$obj->ref."</a></td>";
+            print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($obj->nom,24).'</a></td></tr>';
             $i++;
         }
     }
@@ -146,13 +146,13 @@ print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
 /*
  * Commandes en cours
  */
-$sql = "SELECT c.rowid, c.ref, c.fk_statut, c.facture, s.nom, s.idp";
+$sql = "SELECT c.rowid, c.ref, c.fk_statut, c.facture, s.nom, s.rowid as socid";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql .= " WHERE c.fk_soc = s.idp AND c.fk_statut = 2 ";
+$sql .= " WHERE c.fk_soc = s.rowid AND c.fk_statut = 2 ";
 if ($socid) $sql .= " AND c.fk_soc = ".$socid;
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 $sql .= " ORDER BY c.rowid DESC";
 
 if ( $db->query($sql) )
@@ -170,9 +170,9 @@ if ( $db->query($sql) )
         {
             $var=!$var;
             $obj = $db->fetch_object();
-            print "<tr $bc[$var]><td width=\"30%\"><a href=\"fiche.php?id=$obj->rowid\">".img_object($langs->trans("ShowOrder"),"order").' ';
+            print "<tr $bc[$var]><td width=\"30%\"><a href=\"fiche.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"),"order").' ';
             print $obj->ref.'</a></td>';
-            print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
+            print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
             print '<td align="right">'.$commandestatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
             print '</tr>';
             $i++;
@@ -186,14 +186,14 @@ if ( $db->query($sql) )
  */
 $max=5;
 
-$sql = "SELECT c.rowid, c.ref, c.fk_statut, c.facture, s.nom, s.idp,";
+$sql = "SELECT c.rowid, c.ref, c.fk_statut, c.facture, s.nom, s.rowid as socid,";
 $sql.= " ".$db->pdate("date_cloture")." as datec";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql.= " FROM ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql.= " WHERE c.fk_soc = s.idp and c.fk_statut > 2";
+$sql.= " WHERE c.fk_soc = s.rowid and c.fk_statut > 2";
 if ($socid) $sql .= " AND c.fk_soc = ".$socid;
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 $sql.= " ORDER BY c.tms DESC";
 $sql.= $db->plimit($max, 0);
 
@@ -213,9 +213,9 @@ if ($resql)
         {
             $var=!$var;
             $obj = $db->fetch_object($resql);
-            print "<tr $bc[$var]><td><a href=\"fiche.php?id=$obj->rowid\">".img_object($langs->trans("ShowOrders"),"order").' ';
+            print "<tr $bc[$var]><td><a href=\"fiche.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrders"),"order").' ';
             print $obj->ref.'</a></td>';
-            print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
+            print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
             print '<td>'.dolibarr_print_date($obj->datec).'</td>';
             print '<td align="right">'.$commandestatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
             print '</tr>';
diff --git a/htdocs/commande/liste.php b/htdocs/commande/liste.php
index 55f8c8e8920..41d6a56528c 100644
--- a/htdocs/commande/liste.php
+++ b/htdocs/commande/liste.php
@@ -70,15 +70,15 @@ if (! $sortorder) $sortorder='DESC';
 $limit = $conf->liste_limit;
 $offset = $limit * $_GET['page'] ;
 
-$sql = 'SELECT s.nom, s.idp, c.rowid, c.ref, c.total_ht, c.ref_client,';
+$sql = 'SELECT s.nom, s.rowid as socid, c.rowid, c.ref, c.total_ht, c.ref_client,';
 $sql.= ' '.$db->pdate('c.date_commande').' as date_commande, c.fk_statut, c.facture as facturee';
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'commande as c';
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql.= ' WHERE c.fk_soc = s.idp';
+$sql.= ' WHERE c.fk_soc = s.rowid';
 if (!$user->rights->commercial->client->voir && !$socid) //restriction
 {
-  $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 }
 if ($sref)
 {
@@ -90,7 +90,7 @@ if ($sall)
 }
 if ($socid)
 {
-	$sql .= ' AND s.idp = '.$socid;
+	$sql .= ' AND s.rowid = '.$socid;
 }
 if ($viewstatut <> '')
 {
@@ -181,7 +181,7 @@ if ($resql)
 		$var=!$var;
 		print '<tr '.$bc[$var].'>';
 		print '<td><a href="fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans('ShowOrder'),'order').' '.$objp->ref.'</a></td>';
-		print '<td><a href="../comm/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.'</a></td>';
+		print '<td><a href="../comm/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.'</a></td>';
 		print '<td>'.$objp->ref_client.'</td>';
 		print '<td>&nbsp;</td>';
 		print '<td align="right">';
diff --git a/htdocs/commonobject.class.php b/htdocs/commonobject.class.php
index d999f9a8dda..3c3ae0c2bb7 100644
--- a/htdocs/commonobject.class.php
+++ b/htdocs/commonobject.class.php
@@ -170,22 +170,20 @@ class CommonObject
         $sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id,";
         if ($source == 'internal') $sql.=" '-1' as socid,";
         if ($source == 'external') $sql.=" t.fk_soc as socid,";
-        if ($source == 'internal') $sql.=" t.name as nom,";
-        if ($source == 'external') $sql.=" t.name as nom,";
+        $sql.=" t.name as nom,";
         $sql.= "tc.source, tc.element, tc.code, tc.libelle";
         $sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec,";
         if ($source == 'internal') $sql.=" ".MAIN_DB_PREFIX."user t,";
         if ($source == 'external') $sql.=" ".MAIN_DB_PREFIX."socpeople t,";
         $sql.= " ".MAIN_DB_PREFIX."c_type_contact tc";
-        $sql.= " WHERE element_id =".$this->id;
+        $sql.= " WHERE ec.element_id =".$this->id;
         $sql.= " AND ec.fk_c_type_contact=tc.rowid";
         $sql.= " AND tc.element='".$this->element."'";
         if ($source == 'internal') $sql.= " AND tc.source = 'internal'";
         if ($source == 'external') $sql.= " AND tc.source = 'external'";
         $sql.= " AND tc.active=1";
-        if ($source == 'internal') $sql.= " AND ec.fk_socpeople = t.rowid";
-        if ($source == 'external') $sql.= " AND ec.fk_socpeople = t.idp";
-        if ($statut >= 0) $sql.= " AND statut = '$statut'";
+        $sql.= " AND ec.fk_socpeople = t.rowid";
+        if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'";
         $sql.=" ORDER BY t.name ASC";
 
         $resql=$this->db->query($sql);
@@ -222,9 +220,9 @@ class CommonObject
     {
         $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,";
         $sql.= " tc.code, tc.libelle,";
-		$sql.= " s.fk_soc";
+		    $sql.= " s.fk_soc";
         $sql.= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)";
-        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as s ON ec.fk_socpeople=s.idp";	// Si contact de type external, alors il est li� � une societe
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as s ON ec.fk_socpeople=s.rowid";	// Si contact de type external, alors il est li� � une societe
         $sql.= " WHERE ec.rowid =".$rowid;
         $sql.= " AND ec.fk_c_type_contact=tc.rowid";
         $sql.= " AND tc.element = '".$this->element."'";
@@ -385,7 +383,7 @@ class CommonObject
  function selectCompaniesForNewContact($object, $var_id, $selected = '', $htmlname = 'newcompany')
  {
 	 // On recherche les societes
-	 $sql = "SELECT s.idp, s.nom FROM";
+	 $sql = "SELECT s.rowid, s.nom FROM";
 	 $sql .= " ".MAIN_DB_PREFIX."societe as s";
    //if ($filter) $sql .= " WHERE $filter";
 	 $sql .= " ORDER BY nom ASC";
@@ -402,15 +400,15 @@ class CommonObject
 			 while ($i < $num)
 			 {
 				 $obj = $object->db->fetch_object($resql);
-				 if ($i == 0) $firstCompany = $obj->idp;
-				 if ($selected > 0 && $selected == $obj->idp)
+				 if ($i == 0) $firstCompany = $obj->rowid;
+				 if ($selected > 0 && $selected == $obj->rowid)
 				 {
-					 print '<option value="'.$obj->idp.'" selected="true">'.dolibarr_trunc($obj->nom,24).'</option>';
-					 $firstCompany = $obj->idp;
+					 print '<option value="'.$obj->rowid.'" selected="true">'.dolibarr_trunc($obj->nom,24).'</option>';
+					 $firstCompany = $obj->rowid;
 				 }
 				 else
 				 {
-					 print '<option value="'.$obj->idp.'">'.dolibarr_trunc($obj->nom,24).'</option>';
+					 print '<option value="'.$obj->rowid.'">'.dolibarr_trunc($obj->nom,24).'</option>';
 				 }
 				 $i ++;
 			 }
diff --git a/htdocs/compta/bank/account.php b/htdocs/compta/bank/account.php
index 2e1aac106e2..2fd38bbc8b0 100644
--- a/htdocs/compta/bank/account.php
+++ b/htdocs/compta/bank/account.php
@@ -183,7 +183,7 @@ if ($account > 0)
 	if ($mode_search)
 	{
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = b.rowid AND bu.type='company'";
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.idp";
+		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.rowid";
 	}
 	$sql.= " WHERE b.fk_account=".$acct->id;
 	$sql.= $sql_rech;
@@ -355,7 +355,7 @@ if ($account > 0)
 	$sql = "SELECT b.rowid,".$db->pdate("b.dateo")." as do,".$db->pdate("b.datev")." as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type";
 	if ($mode_search)
 	{
-		$sql.= " ,s.idp as socid, s.nom as thirdparty";
+		$sql.= ", s.rowid as socid, s.nom as thirdparty";
 	}
 	if ($mode_search && $conf->adherent->enabled)
 	{
@@ -369,19 +369,19 @@ if ($account > 0)
 	if ($mode_search)
 	{
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = b.rowid AND bu.type='company'";
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.idp";
+		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.rowid";
 	}
 	if ($mode_search && $conf->adherent->enabled)
 	{
 		// \TODO Mettre jointure sur adherent
 		//$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = b.rowid AND bu.type='company'";
-		//$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.idp";
+		//$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.rowid";
 	}
 	if ($mode_search && $conf->tax->enabled)
 	{
 		// \TODO Mettre jointure sur charges sociales
 		//$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = b.rowid AND bu.type='company'";
-		//$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.idp";
+		//$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.rowid";
 	}
 	$sql.= " WHERE fk_account=".$acct->id;
 	$sql.= $sql_rech;
diff --git a/htdocs/compta/bank/functions.lib.php b/htdocs/compta/bank/functions.lib.php
index 0c8732cac84..02a3ea4bef1 100644
--- a/htdocs/compta/bank/functions.lib.php
+++ b/htdocs/compta/bank/functions.lib.php
@@ -213,7 +213,7 @@ function gljCreateCompany($db, $company_name, $address, $cp, $ville, $fkpays, $p
   /*
    * Create a new company
    *  - insert data in table societe 
-   *  - return company's idp
+   *  - return company's rowid
    */
 
   // Check validity
@@ -236,20 +236,20 @@ function gljCreateCompany($db, $company_name, $address, $cp, $ville, $fkpays, $p
       } else {
 	$token = uniqid("SOC");
       }
-      $sql .= ",'$token'";
+      $sql .= ",'".$token."'";
     }
     $sql .= ");";
     
     if ( $db->query($sql) ) {
-      $sql = "SELECT idp FROM societe WHERE id= '$token';";
+      $sql = "SELECT rowid FROM societe WHERE id= '".$token."';";
       if ( $db->query($sql) ) {
 	if ( $db->num_rows() ) {
 	  $obj = $db->fetch_object();
-	  return $obj->idp;
+	  return $obj->rowid;
 	  $db->free();
 	  
 	  $sql = "INSERT INTO socpeople (datec, name, firstname, fk_soc, phone, fax, email)";
-	  $sql .= "VALUES (now(),'$c_nom','$c_prenom', $obj->idp, $phone, $fax,$url, '$c_mail')";
+	  $sql .= "VALUES (now(),'".$c_nom."','".$c_prenom."', ".$obj->rowid.", ".$phone.", ".$fax.", ".$url.", '".$c_mail."')";
 	  if ( $db->query($sql) ) {
 	    
 	  }
diff --git a/htdocs/compta/clients.php b/htdocs/compta/clients.php
index 586ec2fdd1c..dc87c29ec06 100644
--- a/htdocs/compta/clients.php
+++ b/htdocs/compta/clients.php
@@ -68,7 +68,7 @@ if ($action == 'attribute_prefix')
 
 if ($action == 'note')
 {
-  $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET note='$note' WHERE idp=$socid";
+  $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET note='".$note."' WHERE rowid=".$socid;
   $result = $db->query($sql);
 }
 
@@ -82,7 +82,7 @@ if ($action == 'stcomm')
       
       if ($result)
 	{
-	  $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=$stcommid WHERE idp=$socid";
+	  $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=".$stcommid." WHERE rowid=".$socid;
 	  $result = $db->query($sql);
 	}
       else
@@ -109,14 +109,14 @@ if ($action == 'stcomm')
  */
 if ($mode == 'search') {
   if ($mode-search == 'soc') {
-    $sql = "SELECT s.idp FROM ".MAIN_DB_PREFIX."societe as s ";
+    $sql = "SELECT s.rowid FROM ".MAIN_DB_PREFIX."societe as s ";
     $sql .= " WHERE lower(s.nom) like '%".addslashes(strtolower($socname))."%'";
   }
       
   if ( $db->query($sql) ) {
     if ( $db->num_rows() == 1) {
       $obj = $db->fetch_object();
-      $socid = $obj->idp;
+      $socid = $obj->rowid;
     }
     $db->free();
   }
@@ -129,13 +129,13 @@ if ($mode == 'search') {
  *
  */
 
-$sql = "SELECT s.idp, s.nom, s.ville, ".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea";
+$sql = "SELECT s.rowid, s.nom, s.ville, ".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea";
 $sql .= ", st.libelle as stcomm, s.prefix_comm, s.code_client, s.code_compta ";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 $sql .= " WHERE s.fk_stcomm = st.id AND s.client=1";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 
 if (strlen($stcomm))
 {
@@ -171,7 +171,7 @@ if (strlen($begin))
 
 if ($socid)
 {
-  $sql .= " AND s.idp = $socid";
+  $sql .= " AND s.rowid = ".$socid;
 }
 
 $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset);
@@ -232,9 +232,9 @@ if ($result)
       $var=!$var;
 
       print "<tr $bc[$var]>";
-      print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->idp.'">';
+      print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->rowid.'">';
       print img_object($langs->trans("ShowCustomer"),"company");
-      print '&nbsp;<a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td>';
+      print '&nbsp;<a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->rowid.'">'.$obj->nom.'</a></td>';
       print '<td>'.$obj->ville.'&nbsp;</td>';
       print '<td align="left">'.$obj->code_client.'&nbsp;</td>';
       print '<td align="left">'.$obj->code_compta.'&nbsp;</td>';
@@ -242,7 +242,7 @@ if ($result)
       print '<td align="center">';
       if (defined("MAIN_MODULE_DOSSIER") && MAIN_MODULE_DOSSIER == 1)
 	{
-	  print '<a href="'.DOL_URL_ROOT.'/dossier/client/fiche.php?id='.$obj->idp.'">';
+	  print '<a href="'.DOL_URL_ROOT.'/dossier/client/fiche.php?id='.$obj->rowid.'">';
 	  print img_folder();
 	  print '</a>';
 	}
diff --git a/htdocs/compta/commande/liste.php b/htdocs/compta/commande/liste.php
index 411ae7c8f4e..cbe0554c7ea 100644
--- a/htdocs/compta/commande/liste.php
+++ b/htdocs/compta/commande/liste.php
@@ -55,17 +55,17 @@ $langs->load('companies');
 
 llxHeader();
 
-$sql = "SELECT s.nom, s.idp,";
+$sql = "SELECT s.nom, s.rowid as socid,";
 $sql.= " c.rowid, c.ref, c.total_ht,".$db->pdate("c.date_commande")." as date_commande,";
 $sql.= " c.fk_statut, c.facture";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql .= " WHERE c.fk_soc = s.idp";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+$sql .= " WHERE c.fk_soc = s.rowid";
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 if ($socid)
 {
-    $sql .= " AND s.idp = $socid";
+    $sql .= " AND s.rowid = ".$socid;
 }
 if ($_GET["month"] > 0)
 {
@@ -130,7 +130,7 @@ if ($resql)
         $var=!$var;
         print "<tr $bc[$var]>";
         print "<td><a href=\"".$link."?id=$objp->rowid\">".img_object($langs->trans("ShowOrder"),"order")." ".$objp->ref."</a></td>\n";
-        print "<td><a href=\"".DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->idp."\">".img_object($langs->trans("ShowCompany"),"company")." ".$objp->nom."</a>";
+        print "<td><a href=\"".DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->socid."\">".img_object($langs->trans("ShowCompany"),"company")." ".$objp->nom."</a>";
         if (($objp->date_commande < (time() - $conf->commande->traitement->warning_delay)) && $objp->statutid == 1 )
         {
             print img_warning();
diff --git a/htdocs/compta/deplacement/index.php b/htdocs/compta/deplacement/index.php
index 88db305ef36..9743b39a563 100644
--- a/htdocs/compta/deplacement/index.php
+++ b/htdocs/compta/deplacement/index.php
@@ -60,18 +60,18 @@ if ($user->societe_id > 0)
     $socid = $user->societe_id;
 }
 
-$sql = "SELECT s.nom, s.idp,";                                  // Ou
+$sql = "SELECT s.nom, s.rowid as socid,";                       // Ou
 $sql.= " d.rowid, ".$db->pdate("d.dated")." as dd, d.km, ";     // Comment
 $sql.= " u.name, u.firstname";                                  // Qui
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."deplacement as d, ".MAIN_DB_PREFIX."user as u";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql.= " WHERE d.fk_soc = s.idp AND d.fk_user = u.rowid";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+$sql.= " WHERE d.fk_soc = s.rowid AND d.fk_user = u.rowid";
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 
 if ($socid)
 {
-  $sql .= " AND s.idp = $socid";
+  $sql .= " AND s.rowid = ".$socid;
 }
 
 $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit( $limit + 1 ,$offset);
@@ -98,7 +98,7 @@ if ($resql)
     {
       $objp = $db->fetch_object($resql);
       $soc = new Societe($db);
-      $soc->fetch($objp->idp);
+      $soc->fetch($objp->socid);
       $var=!$var;
       print "<tr $bc[$var]>";
       print '<td><a href="fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowTrip"),"trip").' '.$objp->rowid.'</a></td>';
diff --git a/htdocs/compta/export/ComptaJournalPaiement.class.php b/htdocs/compta/export/ComptaJournalPaiement.class.php
index 5c1003889b2..b00d81de62a 100644
--- a/htdocs/compta/export/ComptaJournalPaiement.class.php
+++ b/htdocs/compta/export/ComptaJournalPaiement.class.php
@@ -82,7 +82,7 @@ class ComptaJournalPaiement  {
 	$sql .= " , ".MAIN_DB_PREFIX."societe as s";
 	$sql .= " WHERE p.fk_paiement = c.id";
 	$sql .= " AND pf.fk_paiement = p.rowid";
-	$sql .= " AND f.fk_soc = s.idp";
+	$sql .= " AND f.fk_soc = s.rowid";
 	$sql .= " AND p.statut = 1 ";
 	$sql .= " AND pf.fk_facture = f.rowid";
 	$sql .= " AND p.fk_export_compta = ".$excid;
diff --git a/htdocs/compta/export/ComptaJournalVente.class.php b/htdocs/compta/export/ComptaJournalVente.class.php
index 3f9df6c43c7..e9b75ed76d4 100644
--- a/htdocs/compta/export/ComptaJournalVente.class.php
+++ b/htdocs/compta/export/ComptaJournalVente.class.php
@@ -79,7 +79,7 @@ class ComptaJournalVente  {
 	  $sql .= " , ".MAIN_DB_PREFIX."compta_compte_generaux as c";
 	  
 	  $sql .= " WHERE f.rowid = l.fk_facture ";
-	  $sql .= " AND s.idp = f.fk_soc";
+	  $sql .= " AND s.rowid = f.fk_soc";
 	  $sql .= " AND f.fk_statut = 1 ";
 	  $sql .= " AND l.fk_code_ventilation <> 0 ";
 	  $sql .= " AND l.fk_export_compta <> 0";	  
diff --git a/htdocs/compta/export/modules/compta.export.class.php b/htdocs/compta/export/modules/compta.export.class.php
index 9669f180f2a..9c92c82b091 100644
--- a/htdocs/compta/export/modules/compta.export.class.php
+++ b/htdocs/compta/export/modules/compta.export.class.php
@@ -64,7 +64,7 @@ class ComptaExport
     
     $sql = "SELECT f.rowid as facid, f.facnumber, ".$this->db->pdate("f.datef")." as datef";
     $sql .= " , f.total_ttc, f.tva ";
-    $sql .= " ,s.nom, s.idp, s.code_compta";
+    $sql .= " ,s.nom, s.rowid as socid, s.code_compta";
     $sql .= " , l.price, l.tva_taux";
     $sql .= " , c.numero, f.increment";
     $sql .= " , l.rowid as lrowid";
@@ -75,7 +75,7 @@ class ComptaExport
     $sql .= " , ".MAIN_DB_PREFIX."compta_compte_generaux as c";
     
     $sql .= " WHERE f.rowid = l.fk_facture ";
-    $sql .= " AND s.idp = f.fk_soc";
+    $sql .= " AND s.rowid = f.fk_soc";
     $sql .= " AND f.fk_statut = 1 ";
     
     $sql .= " AND l.fk_code_ventilation <> 0 ";
@@ -114,7 +114,7 @@ class ComptaExport
 	    if ($obj->code_compta == '')
 	      {
 		$societe=new Societe($this->db);
-		$societe->fetch($obj->idp);
+		$societe->fetch($obj->socid);
 		$this->error_message.= $langs->transnoentities("ErrorWrongAccountancyCodeForCompany",$societe->getNomUrl(1))."<br>";
 		$error++;
 	      }
@@ -153,7 +153,7 @@ class ComptaExport
     $sql .= " AND p.rowid = pf.fk_paiement";
     $sql .= " AND cp.id = p.fk_paiement";
     $sql .= " AND f.rowid = pf.fk_facture";
-    $sql .= " AND f.fk_soc = s.idp";
+    $sql .= " AND f.fk_soc = s.rowid";
     $sql .= " AND p.statut = 1 ";
 
     $sql .= " ORDER BY f.rowid ASC, p.rowid ASC";
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 16a39170c41..711d7c8996b 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -2996,14 +2996,14 @@ else
 		$sql.= ' f.rowid as facid, f.facnumber, f.type, f.increment, f.total, f.total_ttc,';
 		$sql.= ' '.$db->pdate('f.datef').' as df, '.$db->pdate('f.date_lim_reglement').' as datelimite,';
 		$sql.= ' f.paye as paye, f.fk_statut,';
-		$sql.= ' s.nom, s.idp';
+		$sql.= ' s.nom, s.rowid as socid';
 		if (! $sall) $sql.= ' ,sum(pf.amount) as am';
 		$sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
 		$sql.= ','.MAIN_DB_PREFIX.'facture as f';
 		if (! $sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture ';
 		if ($sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as fd ON f.rowid=fd.fk_facture ';
-		$sql.= ' WHERE f.fk_soc = s.idp';
-		if ($socid) $sql .= ' AND s.idp = '.$socid;
+		$sql.= ' WHERE f.fk_soc = s.rowid';
+		if ($socid) $sql .= ' AND s.rowid = '.$socid;
 		if ($month > 0) $sql .= ' AND date_format(f.datef, \'%m\') = '.$month;
 		if ($_GET['filtre'])
 		{
@@ -3131,7 +3131,7 @@ else
 					{
 						print '<td align="center"><b>!!!</b></td>';
 					}
-					print '<td><a href="fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans('ShowCompany'),'company').' '.dolibarr_trunc($objp->nom,48).'</a></td>';
+					print '<td><a href="fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'),'company').' '.dolibarr_trunc($objp->nom,48).'</a></td>';
 					print '<td align="right">'.price($objp->total).'</td>';
 					print '<td align="right">'.price($objp->total_ttc).'</td>';
 					print '<td align="right">'.price($objp->am).'</td>';
diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php
index 659ab07a57f..9d66b51347e 100644
--- a/htdocs/compta/facture/fiche-rec.php
+++ b/htdocs/compta/facture/fiche-rec.php
@@ -410,11 +410,12 @@ else
 			if ($user->rights->facture->lire)
 			{
 
-				$sql = "SELECT s.nom,s.idp,f.titre,f.total,f.rowid as facid";
-				$sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f WHERE f.fk_soc = s.idp";
+				$sql = "SELECT s.nom, s.rowid as socid, f.titre, f.total, f.rowid as facid";
+				$sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f";
+				$sql.= " WHERE f.fk_soc = s.rowid";
 
 				if ($socid)
-				$sql .= " AND s.idp = $socid";
+				$sql .= " AND s.rowid = ".$socid;
 
 				//$sql .= " ORDER BY $sortfield $sortorder, rowid DESC ";
 				//	$sql .= $db->plimit($limit + 1,$offset);
@@ -447,7 +448,7 @@ else
 
 						print '<td><a href="fiche-rec.php?facid='.$objp->facid.'">'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->titre;
 						print "</a></td>\n";
-						print '<td><a href="../fiche.php?socid='.$objp->idp.'">'.$objp->nom.'</a></td>';
+						print '<td><a href="../fiche.php?socid='.$objp->socid.'">'.$objp->nom.'</a></td>';
 
 						print "<td align=\"right\">".price($objp->total)."</td>\n";
 
diff --git a/htdocs/compta/facture/impayees.php b/htdocs/compta/facture/impayees.php
index 46f01dcce67..a2df51af43f 100644
--- a/htdocs/compta/facture/impayees.php
+++ b/htdocs/compta/facture/impayees.php
@@ -72,20 +72,20 @@ if ($user->rights->facture->lire)
 	$limit = $conf->liste_limit;
 	$offset = $limit * $page ;
 
-	$sql = "SELECT s.nom, s.idp,";
-	$sql.= " f.facnumber,f.increment,f.total as total_ht,f.total_ttc,";
-	$sql.= $db->pdate("f.datef")." as df, ".$db->pdate("f.date_lim_reglement")." as datelimite, ";
-	$sql.= " f.paye as paye, f.rowid as facid, f.fk_statut";
-	$sql.= " ,sum(pf.amount) as am";
+	$sql = "SELECT s.nom, s.rowid as socid";
+	$sql.= ", f.facnumber,f.increment,f.total as total_ht,f.total_ttc";
+	$sql.= ", ".$db->pdate("f.datef")." as df, ".$db->pdate("f.date_lim_reglement")." as datelimite";
+	$sql.= ", f.paye as paye, f.rowid as facid, f.fk_statut";
+	$sql.= ", sum(pf.amount) as am";
 	if (! $user->rights->commercial->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user ";
 	$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
 	if (! $user->rights->commercial->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 	$sql.= ",".MAIN_DB_PREFIX."facture as f";
 	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid=pf.fk_facture ";
-	$sql.= " WHERE f.fk_soc = s.idp";
+	$sql.= " WHERE f.fk_soc = s.rowid";
 	$sql.= " AND f.paye = 0 AND f.fk_statut = 1";
-	if (! $user->rights->commercial->client->voir && ! $socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
-	if ($socid) $sql .= " AND s.idp = ".$socid;
+	if (! $user->rights->commercial->client->voir && ! $socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
+	if ($socid) $sql .= " AND s.rowid = ".$socid;
 
 	if ($_GET["filtre"])
 	{
@@ -205,7 +205,7 @@ if ($user->rights->facture->lire)
 				print "<td nowrap align=\"center\">".dolibarr_print_date($objp->df)."</td>\n";
 				print "<td nowrap align=\"center\">".dolibarr_print_date($objp->datelimite)."</td>\n";
 
-				print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,32).'</a></td>';
+				print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,32).'</a></td>';
 
 				print "<td align=\"right\">".price($objp->total_ht)."</td>";
 				print "<td align=\"right\">".price($objp->total_ttc)."</td>";
diff --git a/htdocs/compta/fiche.php b/htdocs/compta/fiche.php
index 2d903257b8f..770c13091e3 100644
--- a/htdocs/compta/fiche.php
+++ b/htdocs/compta/fiche.php
@@ -73,7 +73,7 @@ if ($mode == 'search')
 {
     if ($mode-search == 'soc')
     {
-        $sql = "SELECT s.idp FROM ".MAIN_DB_PREFIX."societe as s ";
+        $sql = "SELECT s.rowid FROM ".MAIN_DB_PREFIX."societe as s ";
         $sql .= " WHERE lower(s.nom) like '%".strtolower($socname)."%'";
     }
 
@@ -82,7 +82,7 @@ if ($mode == 'search')
         if ( $db->num_rows() == 1)
         {
             $obj = $db->fetch_object();
-            $socid = $obj->idp;
+            $socid = $obj->rowid;
         }
         $db->free();
     }
@@ -109,7 +109,7 @@ $contactstatic = new Contact($db);
 if ($socid > 0)
 {
     $societe = new Societe($db);
-    $societe->fetch($socid, $to);  // si $to='next' ajouter " AND s.idp > $socid ORDER BY idp ASC LIMIT 1";
+    $societe->fetch($socid, $to);  // si $to='next' ajouter " AND s.rowid > $socid ORDER BY idp ASC LIMIT 1";
 	if ($societe->id <= 0)
 	{
 		dolibarr_print_error($db,$societe->error);
@@ -242,14 +242,14 @@ if ($socid > 0)
 
         print '<table class="noborder" width="100%">';
 
-        $sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.amount, f.total, f.total_ttc,';
-        $sql.= ' '.$db->pdate("f.datef").' as df, f.paye as paye, f.fk_statut as statut,';
-		$sql.= ' s.nom, s.idp,';
-		$sql.= ' sum(pf.amount) as am';
+        $sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.amount, f.total, f.total_ttc';
+        $sql.= ', '.$db->pdate("f.datef").' as df, f.paye as paye, f.fk_statut as statut';
+		    $sql.= ', s.nom, s.rowid as socid';
+		    $sql.= ', sum(pf.amount) as am';
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
-		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture';
-        $sql.= " WHERE f.fk_soc = s.idp AND s.idp = ".$societe->id;
-		$sql.= ' GROUP BY f.rowid';
+		    $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture';
+        $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$societe->id;
+		    $sql.= ' GROUP BY f.rowid';
         $sql.= " ORDER BY f.datef DESC, f.datec DESC";
 
         $resql=$db->query($sql);
@@ -392,7 +392,7 @@ if ($socid > 0)
 	print '<td>&nbsp;</td>';
 	print "</tr>";
 
-    $sql = "SELECT p.idp, p.name, p.firstname, p.poste, p.phone, p.fax, p.email, p.note";
+    $sql = "SELECT p.rowid, p.name, p.firstname, p.poste, p.phone, p.fax, p.email, p.note";
     $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as p";
     $sql.= " WHERE p.fk_soc = ".$societe->id;
     $sql.= " ORDER by p.datec";
@@ -408,7 +408,7 @@ if ($socid > 0)
         print "<tr $bc[$var]>";
 
         print '<td>';
-        print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->idp.'">'.img_object($langs->trans("ShowContact"),"contact").' '.$obj->firstname.' '. $obj->name.'</a>&nbsp;';
+        print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowContact"),"contact").' '.$obj->firstname.' '. $obj->name.'</a>&nbsp;';
 
         if (trim($obj->note))
         {
@@ -416,15 +416,15 @@ if ($socid > 0)
         }
         print '</td>';
         print '<td>'.$obj->poste.'&nbsp;</td>';
-        print '<td><a href="../comm/action/fiche.php?action=create&actioncode=AC_TEL&contactid='.$obj->idp.'&socid='.$societe->id.'">'.$obj->phone.'</a>&nbsp;</td>';
-        print '<td><a href="../comm/action/fiche.php?action=create&actioncode=AC_FAX&contactid='.$obj->idp.'&socid='.$societe->id.'">'.$obj->fax.'</a>&nbsp;</td>';
-        print '<td><a href="../comm/action/fiche.php?action=create&actioncode=AC_EMAIL&contactid='.$obj->idp.'&socid='.$societe->id.'">'.$obj->email.'</a>&nbsp;</td>';
+        print '<td><a href="../comm/action/fiche.php?action=create&actioncode=AC_TEL&contactid='.$obj->rowid.'&socid='.$societe->id.'">'.$obj->phone.'</a>&nbsp;</td>';
+        print '<td><a href="../comm/action/fiche.php?action=create&actioncode=AC_FAX&contactid='.$obj->rowid.'&socid='.$societe->id.'">'.$obj->fax.'</a>&nbsp;</td>';
+        print '<td><a href="../comm/action/fiche.php?action=create&actioncode=AC_EMAIL&contactid='.$obj->rowid.'&socid='.$societe->id.'">'.$obj->email.'</a>&nbsp;</td>';
 
     	print '<td align="center">';
     	
        	if ($user->rights->societe->contact->creer)
 		{
-    		print "<a href=\"../contact/fiche.php?action=edit&amp;id=$obj->idp\">";
+    		print "<a href=\"../contact/fiche.php?action=edit&amp;id=".$obj->rowid."\">";
     	 	print img_edit();
     	 	print '</a>';
     	}
@@ -432,7 +432,7 @@ if ($socid > 0)
     		
     	print '</td>';
 
-        print '<td align="center"><a href="../comm/action/fiche.php?action=create&actioncode=AC_RDV&contactid='.$obj->idp.'&socid='.$societe->id.'">';
+        print '<td align="center"><a href="../comm/action/fiche.php?action=create&actioncode=AC_RDV&contactid='.$obj->rowid.'&socid='.$societe->id.'">';
         print img_object($langs->trans("Rendez-Vous"),"action");
         print '</a></td>';
 
diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php
index d2c74545e6a..8ce8b6e9cb2 100644
--- a/htdocs/compta/index.php
+++ b/htdocs/compta/index.php
@@ -122,12 +122,12 @@ if ($conf->facture->enabled)
 if ($conf->facture->enabled && $user->rights->facture->lire)
 {
 	$sql  = "SELECT f.facnumber, f.rowid, f.total_ttc, f.type,";
-	$sql.= " s.nom, s.idp";
+	$sql.= " s.nom, s.rowid as socid";
 	if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
 	$sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
 	if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-	$sql .= " WHERE s.idp = f.fk_soc AND f.fk_statut = 0";
-	if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+	$sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = 0";
+	if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 
   if ($socid)
     {
@@ -160,7 +160,7 @@ if ($conf->facture->enabled && $user->rights->facture->lire)
 	      print $facturestatic->getNomUrl(1,'');
 	      print '</td>';
 	      print '<td>';
-		  $companystatic->id=$obj->idp;
+		  $companystatic->id=$obj->socid;
 		  $companystatic->nom=$obj->nom;
 		  $companystatic->client=1;
 		  print $companystatic->getNomUrl(1,'',16);
@@ -245,9 +245,9 @@ if ($conf->tax->enabled)
 /**
  * Bookmark
  */
-$sql = "SELECT s.idp, s.nom,b.rowid as bid";
+$sql = "SELECT s.rowid as socid, s.nom, b.rowid as bid";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."bookmark as b";
-$sql .= " WHERE b.fk_soc = s.idp AND b.fk_user = ".$user->id;
+$sql .= " WHERE b.fk_soc = s.rowid AND b.fk_user = ".$user->id;
 $sql .= " ORDER BY lower(s.nom) ASC";
 
 $resql = $db->query($sql);
@@ -266,7 +266,7 @@ if ( $resql )
 	  $obj = $db->fetch_object($resql);
 	  $var = !$var;
 	  print "<tr $bc[$var]>";
-	  print '<td><a href="fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td>';
+	  print '<td><a href="fiche.php?socid='.$obj->socid.'">'.$obj->nom.'</a></td>';
 	  print '<td align="right"><a href="index.php?action=del_bookmark&amp;bid='.$obj->bid.'">'.img_delete().'</a></td>';
 	  print '</tr>';
 	  $i++;
@@ -290,15 +290,15 @@ if ($user->rights->societe->lire)
 	$langs->load("boxes");
 	$max=5;
 
-	$sql = "SELECT s.nom, s.idp, ".$db->pdate("s.datec")." as dc";
+	$sql = "SELECT s.nom, s.rowid, ".$db->pdate("s.datec")." as dc";
 	if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
 	$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 	if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 	$sql .= " WHERE s.client = 1";
-	if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+	if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 	if ($user->societe_id > 0)
 	{
-		$sql .= " AND s.idp = $user->societe_id";
+		$sql .= " AND s.rowid = ".$user->societe_id;
 	}
 	$sql .= " ORDER BY s.datec DESC ";
 	$sql .= $db->plimit($max, 0);
@@ -325,7 +325,7 @@ if ($user->rights->societe->lire)
 			while ($i < $num && $i < $max)
 			{
 				$objp = $db->fetch_object($result);
-				$customerstatic->id=$objp->idp;
+				$customerstatic->id=$objp->rowid;
 				$customerstatic->nom=$objp->nom;
 				$var=!$var;
 				print '<tr '.$bc[$var].'>';
@@ -348,15 +348,15 @@ if ($user->rights->societe->lire)
 	$langs->load("boxes");
 	$max=5;
 
-	$sql = "SELECT s.nom, s.idp, ".$db->pdate("s.datec")." as dc";
+	$sql = "SELECT s.nom, s.rowid, ".$db->pdate("s.datec")." as dc";
 	if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
 	$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 	if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 	$sql .= " WHERE s.fournisseur = 1";
-	if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+	if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 	if ($user->societe_id > 0)
 	{
-		$sql .= " AND s.idp = $user->societe_id";
+		$sql .= " AND s.rowid = ".$user->societe_id;
 	}
 	$sql .= " ORDER BY s.datec DESC ";
 	$sql .= $db->plimit($max, 0);
@@ -383,7 +383,7 @@ if ($user->rights->societe->lire)
 			while ($i < $num && $i < $max)
 			{
 				$objp = $db->fetch_object($result);
-				$customerstatic->id=$objp->idp;
+				$customerstatic->id=$objp->rowid;
 				$customerstatic->nom=$objp->nom;
 				$var=!$var;
 				print '<tr '.$bc[$var].'>';
@@ -408,7 +408,7 @@ if ($conf->facture->enabled && $conf->commande->enabled && $user->rights->comman
 	$langs->load("orders");
 
 	$sql = "SELECT sum(f.total) as tot_fht, sum(f.total_ttc) as tot_fttc,";
-	$sql.= " s.nom, s.idp,";
+	$sql.= " s.nom, s.rowid as socid,";
 	$sql.= " p.rowid, p.ref, p.facture, p.fk_statut, p.total_ht, p.total_ttc";
 	if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
 	$sql.= " FROM (".MAIN_DB_PREFIX."societe AS s, ".MAIN_DB_PREFIX."commande AS p";
@@ -416,11 +416,11 @@ if ($conf->facture->enabled && $conf->commande->enabled && $user->rights->comman
 	if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc)";
 	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid";
 	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid";
-	$sql.= " WHERE p.fk_soc = s.idp";
-	if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+	$sql.= " WHERE p.fk_soc = s.rowid";
+	if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 	if ($socid)
 	{
-		$sql.= " AND p.fk_soc = $socid";
+		$sql.= " AND p.fk_soc = ".$socid;
 	}
 	$sql.= " AND p.fk_statut = 3 AND p.facture=0";
 	$sql.= " GROUP BY p.rowid";
@@ -451,8 +451,8 @@ if ($conf->facture->enabled && $conf->commande->enabled && $user->rights->comman
 				print "<td width=\"20%\"><a href=\"commande/fiche.php?id=$obj->rowid\">".img_object($langs->trans("ShowOrder"),"order").'</a>&nbsp;';
 				print "<a href=\"commande/fiche.php?id=$obj->rowid\">".$obj->ref.'</a></td>';
 
-				print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").'</a>&nbsp;';
-				print '<a href="fiche.php?socid='.$obj->idp.'">'.dolibarr_trunc($obj->nom,44).'</a></td>';
+				print '<td><a href="fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").'</a>&nbsp;';
+				print '<a href="fiche.php?socid='.$obj->socid.'">'.dolibarr_trunc($obj->nom,44).'</a></td>';
 				if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) print '<td align="right">'.price($obj->total_ht).'</td>';
 				print '<td align="right">'.price($obj->total_ttc).'</td>';
 				print '<td align="right">'.price($obj->total_ttc-$obj->tot_fttc).'</td>';
@@ -492,15 +492,15 @@ if ($conf->facture->enabled && $user->rights->facture->lire)
 	$sql = "SELECT f.rowid, f.facnumber, f.fk_statut, f.type, f.total, f.total_ttc, ";
 	$sql.= $db->pdate("f.date_lim_reglement")." as datelimite,";
 	$sql.= " sum(pf.amount) as am,";
-	$sql.= " s.nom, s.idp";
+	$sql.= " s.nom, s.rowid as socid";
 	if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
 	$sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
 	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
 	if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-	$sql.= " WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1";
-	if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+	$sql.= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1";
+	if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 	if ($socid) $sql .= " AND f.fk_soc = ".$socid;
-	$sql.= " GROUP BY f.rowid, f.facnumber, f.fk_statut, f.total, f.total_ttc, s.nom, s.idp";
+	$sql.= " GROUP BY f.rowid, f.facnumber, f.fk_statut, f.total, f.total_ttc, s.nom, s.rowid";
 	$sql.= " ORDER BY f.datef ASC, f.facnumber ASC";
 
 	$resql = $db->query($sql);
@@ -533,7 +533,7 @@ if ($conf->facture->enabled && $user->rights->facture->lire)
 				print $facturestatic->getNomUrl(1,'');
 				if ($obj->datelimite < (time() - $conf->facture->client->warning_delay)) print img_warning($langs->trans("Late"));
 				print '</td>';
-				print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCustomer"),"company").' '.dolibarr_trunc($obj->nom,44).'</a></td>';
+				print '<td><a href="fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCustomer"),"company").' '.dolibarr_trunc($obj->nom,44).'</a></td>';
 				if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) print '<td align="right">'.price($obj->total).'</td>';
 				print '<td align="right">'.price($obj->total_ttc).'</td>';
 				print '<td align="right">'.price($obj->am).'</td>';
@@ -574,15 +574,15 @@ if ($conf->facture->enabled && $user->rights->facture->lire)
 	{
 		$sql = "SELECT ff.rowid, ff.facnumber, ff.fk_statut, ff.fk_statut, ff.libelle, ff.total_ht, ff.total_ttc,";
 		$sql.= " sum(pf.amount) as am,";
-		$sql.= " s.nom, s.idp";
+		$sql.= " s.nom, s.rowid as socid";
 		if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
 		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
 		if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-		$sql.= " WHERE s.idp = ff.fk_soc";
+		$sql.= " WHERE s.rowid = ff.fk_soc";
 		$sql.= " AND ff.paye=0 AND ff.fk_statut = 1";
-		if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
-		$sql.= " GROUP BY ff.rowid, ff.facnumber, ff.fk_statut, ff.total, ff.total_ttc, s.nom, s.idp";
+		if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
+		$sql.= " GROUP BY ff.rowid, ff.facnumber, ff.fk_statut, ff.total, ff.total_ttc, s.nom, s.rowid";
 
 		$resql=$db->query($sql);
 		if ($resql)
@@ -609,7 +609,7 @@ if ($conf->facture->enabled && $user->rights->facture->lire)
 					$facstatic->id=$obj->rowid;
 					print $facstatic->getNomUrl(1,'');
 					print '</td>';
-					print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowSupplier"),"company").' '.dolibarr_trunc($obj->nom,44).'</a></td>';
+					print '<td><a href="fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowSupplier"),"company").' '.dolibarr_trunc($obj->nom,44).'</a></td>';
 					if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) print '<td align="right">'.price($obj->total_ht).'</td>';
 					print '<td align="right">'.price($obj->total_ttc).'</td>';
 					print '<td align="right">'.price($obj->am).'</td>';
diff --git a/htdocs/compta/paiement/fiche.php b/htdocs/compta/paiement/fiche.php
index d0464280d23..8aede00023c 100644
--- a/htdocs/compta/paiement/fiche.php
+++ b/htdocs/compta/paiement/fiche.php
@@ -205,9 +205,9 @@ print '</table>';
  *
  */
 $allow_delete = 1 ;
-$sql = 'SELECT f.facnumber, f.total_ttc, pf.amount, f.rowid as facid, f.paye, f.fk_statut, s.nom, s.idp';
+$sql = 'SELECT f.facnumber, f.total_ttc, pf.amount, f.rowid as facid, f.paye, f.fk_statut, s.nom, s.rowid as socid';
 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture as f,'.MAIN_DB_PREFIX.'societe as s';
-$sql .= ' WHERE pf.fk_facture = f.rowid AND f.fk_soc = s.idp';
+$sql .= ' WHERE pf.fk_facture = f.rowid AND f.fk_soc = s.rowid';
 $sql .= ' AND pf.fk_paiement = '.$paiement->id;
 $resql=$db->query($sql); 			
 if ($resql)
@@ -239,7 +239,7 @@ if ($resql)
 			print $objp->facnumber;
 			print "</a></td>\n";
 			print '<td align="center">'.$facturestatic->LibStatut($objp->paye,$objp->fk_statut,2,1).'</td>';
-			print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.'</a></td>';
+			print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.'</a></td>';
 			print '<td align="right">'.price($objp->amount).'</td>';
 			print "</tr>\n";
 			if ($objp->paye == 1)
diff --git a/htdocs/compta/prelevement/create.php b/htdocs/compta/prelevement/create.php
index ac00be9b1cc..74dd8496422 100644
--- a/htdocs/compta/prelevement/create.php
+++ b/htdocs/compta/prelevement/create.php
@@ -163,10 +163,10 @@ else
  * Factures en attente de pr�l�vement
  *
  */
-$sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp";
+$sql = "SELECT f.facnumber, f.rowid, s.nom, s.rowid as socid";
 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
 $sql .= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
-$sql .= " WHERE s.idp = f.fk_soc";
+$sql .= " WHERE s.rowid = f.fk_soc";
 $sql .= " AND pfd.traite = 0 AND pfd.fk_facture = f.rowid";
 
 if ($socid)
@@ -191,7 +191,7 @@ if ( $db->query($sql) )
 	  $var=!$var;
 	  print '<tr '.$bc[$var].'><td>';
 	  print '<a href="'.DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$obj->rowid.'">'.img_file().' '.$obj->facnumber.'</a></td>';
-      print '<td><a href="'.DOL_URL_ROOT.'/soc.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),'company').' '.$obj->nom.'</a></td>';
+      print '<td><a href="'.DOL_URL_ROOT.'/soc.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),'company').' '.$obj->nom.'</a></td>';
 	  print '</tr>';
 	  $i++;
 	}
diff --git a/htdocs/compta/prelevement/demandes.php b/htdocs/compta/prelevement/demandes.php
index 34089535409..8922a4fe64e 100644
--- a/htdocs/compta/prelevement/demandes.php
+++ b/htdocs/compta/prelevement/demandes.php
@@ -63,15 +63,15 @@ if (! $sortfield) $sortfield="f.facnumber";
  *
  */
 
-$sql= "SELECT f.facnumber, f.rowid, s.nom, s.idp";
+$sql= "SELECT f.facnumber, f.rowid, s.nom, s.rowid as socid";
 $sql.= " , ".$db->pdate("pfd.date_demande")." as date_demande";
 $sql.= " , pfd.fk_user_demande";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
 $sql.= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql.= " WHERE s.idp = f.fk_soc";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+$sql.= " WHERE s.rowid = f.fk_soc";
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 if (! $statut) $sql.= " AND pfd.traite = 0";
 if ($statut) $sql.= " AND pfd.traite = ".$statut;
 $sql.= " AND pfd.fk_facture = f.rowid";
@@ -126,7 +126,7 @@ else
       // Ref facture
       print '<td><a href="'.DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$obj->rowid.'">'.img_file().' '.$obj->facnumber.'</a></td>';
 
-      print '<td><a href="'.DOL_URL_ROOT.'/soc.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),'company').' '.$obj->nom.'</a></td>';
+      print '<td><a href="'.DOL_URL_ROOT.'/soc.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),'company').' '.$obj->nom.'</a></td>';
 
       print '<td align="center">'.dolibarr_print_date($obj->date_demande).'</td>';
 
diff --git a/htdocs/compta/prelevement/factures.php b/htdocs/compta/prelevement/factures.php
index a677ce1ba41..ef74590b0bb 100644
--- a/htdocs/compta/prelevement/factures.php
+++ b/htdocs/compta/prelevement/factures.php
@@ -97,7 +97,7 @@ $offset = $conf->liste_limit * $page ;
  */
 $sql = "SELECT pf.rowid";
 $sql .= " ,f.rowid as facid, f.facnumber as ref, f.total_ttc";
-$sql .= " , s.idp, s.nom";
+$sql .= " , s.rowid as socid, s.nom";
 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
 $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
 $sql .= " , ".MAIN_DB_PREFIX."prelevement_facture as pf";
@@ -105,7 +105,7 @@ $sql .= " , ".MAIN_DB_PREFIX."facture as f";
 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
 $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid";
 $sql .= " AND pl.fk_prelevement_bons = p.rowid";
-$sql .= " AND f.fk_soc = s.idp";
+$sql .= " AND f.fk_soc = s.rowid";
 $sql .= " AND pf.fk_facture = f.rowid";
 if ($_GET["id"])
 {
@@ -114,7 +114,7 @@ if ($_GET["id"])
 
 if ($_GET["socid"])
 {
-  $sql .= " AND s.idp = ".$_GET["socid"];
+  $sql .= " AND s.rowid = ".$_GET["socid"];
 }
 
 $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset);
@@ -154,7 +154,7 @@ if ($result)
 
       print '<a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
 
-      print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->idp.'">';
+      print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->socid.'">';
       print img_object($langs->trans("ShowCompany"),"company"). ' '.stripslashes($obj->nom)."</a></td>\n";
 
       print '<td align="center">'.price($obj->total_ttc)."</td>\n";
diff --git a/htdocs/compta/prelevement/facturesrejets.php b/htdocs/compta/prelevement/facturesrejets.php
index 11762c466e0..a854c2ff512 100644
--- a/htdocs/compta/prelevement/facturesrejets.php
+++ b/htdocs/compta/prelevement/facturesrejets.php
@@ -77,19 +77,19 @@ if ($sortfield == "") {
  */
 $sql = "SELECT p.rowid, pf.statut, p.ref";
 $sql .= " ,f.rowid as facid, f.facnumber, f.total_ttc";
-$sql .= " , s.idp, s.nom";
+$sql .= " , s.rowid as socid, s.nom";
 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement as p";
 $sql .= " , ".MAIN_DB_PREFIX."prelevement_facture as pf";
 $sql .= " , ".MAIN_DB_PREFIX."facture as f";
 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
 $sql .= " WHERE pf.fk_prelevement = p.rowid";
-$sql .= " AND f.fk_soc = s.idp";
+$sql .= " AND f.fk_soc = s.rowid";
 $sql .= " AND pf.fk_facture = f.rowid";
 $sql .= " AND pf.statut = 2 ";
 
 if ($_GET["socid"])
 {
-  $sql .= " AND s.idp = ".$_GET["socid"];
+  $sql .= " AND s.rowid = ".$_GET["socid"];
 }
 
 $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset);
@@ -131,7 +131,7 @@ if ($result)
       print '<a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$obj->facid.'">'.$obj->facnumber."</a></td>\n";
 
 
-      print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->idp.'">'.stripslashes($obj->nom)."</a></td>\n";
+      print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->socid.'">'.stripslashes($obj->nom)."</a></td>\n";
 
       print '<td align="center">'.price($obj->total_ttc)."</td>\n";
 
diff --git a/htdocs/compta/prelevement/fiche-rejet.php b/htdocs/compta/prelevement/fiche-rejet.php
index 8bc29310b61..ed098b1374f 100644
--- a/htdocs/compta/prelevement/fiche-rejet.php
+++ b/htdocs/compta/prelevement/fiche-rejet.php
@@ -86,7 +86,7 @@ $rej = new RejetPrelevement($db, $user);
  *
  */
 $sql = "SELECT pl.rowid, pl.amount, pl.statut";
-$sql .= " , s.idp, s.nom";
+$sql .= " , s.rowid as socid, s.nom";
 $sql .= " , pr.motif, pr.afacturer, pr.fk_facture";
 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
 $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
@@ -94,13 +94,13 @@ $sql .= " , ".MAIN_DB_PREFIX."societe as s";
 $sql .= " , ".MAIN_DB_PREFIX."prelevement_rejet as pr";
 $sql .= " WHERE p.rowid=".$prev_id;
 $sql .= " AND pl.fk_prelevement_bons = p.rowid";
-$sql .= " AND pl.fk_soc = s.idp";
+$sql .= " AND pl.fk_soc = s.rowid";
 $sql .= " AND pl.statut = 3 ";
 $sql .= " AND pr.fk_prelevement_lignes = pl.rowid";
 
 if ($_GET["socid"])
 {
-  $sql .= " AND s.idp = ".$_GET["socid"];
+  $sql .= " AND s.rowid = ".$_GET["socid"];
 }
 
 $sql .= " ORDER BY pl.amount DESC";
@@ -130,7 +130,7 @@ if ($resql)
 
       print substr('000000'.$obj->rowid, -6);
       print '</a></td>';
-      print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->idp.'">'.stripslashes($obj->nom)."</a></td>\n";
+      print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->socid.'">'.stripslashes($obj->nom)."</a></td>\n";
 
       print '<td align="right">'.price($obj->amount)."</td>\n";
       print '<td>'.$rej->motifs[$obj->motif].'</td>';
diff --git a/htdocs/compta/prelevement/index.php b/htdocs/compta/prelevement/index.php
index 3a58fadef1e..0b2a05cc9e7 100644
--- a/htdocs/compta/prelevement/index.php
+++ b/htdocs/compta/prelevement/index.php
@@ -127,15 +127,15 @@ print '</td><td valign="top" width="70%">';
  * Factures
  *
  */
-$sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp";
+$sql = "SELECT f.facnumber, f.rowid, s.nom, s.rowid as socid";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 $sql .= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
-$sql .= " WHERE s.idp = f.fk_soc";
+$sql .= " WHERE s.rowid = f.fk_soc";
 $sql .= " AND pfd.traite = 0 AND pfd.fk_facture = f.rowid";
 
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 
 if ($socid)
 {
@@ -159,7 +159,7 @@ if ( $db->query($sql) )
 	  $var=!$var;
 	  print '<tr '.$bc[$var].'><td>';
 	  print '<a href="'.DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$obj->rowid.'">'.img_file().' '.$obj->facnumber.'</a></td>';
-      print '<td><a href="'.DOL_URL_ROOT.'/soc.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),'company').' '.$obj->nom.'</a></td>';
+      print '<td><a href="'.DOL_URL_ROOT.'/soc.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),'company').' '.$obj->nom.'</a></td>';
 	  print '</tr>';
 	  $i++;
 	}
diff --git a/htdocs/compta/prelevement/ligne.php b/htdocs/compta/prelevement/ligne.php
index 9520cd71357..09034293ab0 100644
--- a/htdocs/compta/prelevement/ligne.php
+++ b/htdocs/compta/prelevement/ligne.php
@@ -195,7 +195,7 @@ if ($_GET["id"])
    */
   $sql = "SELECT pf.rowid";
   $sql .= " ,f.rowid as facid, f.facnumber as ref, f.total_ttc";
-  $sql .= " , s.idp, s.nom";
+  $sql .= " , s.rowid as socid, s.nom";
   $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
   $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
   $sql .= " , ".MAIN_DB_PREFIX."prelevement_facture as pf";
@@ -203,13 +203,13 @@ if ($_GET["id"])
   $sql .= " , ".MAIN_DB_PREFIX."societe as s";
   $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid";
   $sql .= " AND pl.fk_prelevement_bons = p.rowid";
-  $sql .= " AND f.fk_soc = s.idp";
+  $sql .= " AND f.fk_soc = s.rowid";
   $sql .= " AND pf.fk_facture = f.rowid";
   $sql .= " AND pl.rowid=".$_GET["id"];
 
   if ($_GET["socid"])
     {
-      $sql .= " AND s.idp = ".$_GET["socid"];
+      $sql .= " AND s.rowid = ".$_GET["socid"];
     }
 
   $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset);
@@ -246,7 +246,7 @@ if ($_GET["id"])
 
 	  print '<a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
 
-	  print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->idp.'">';
+	  print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->socid.'">';
 	  print img_object($langs->trans("ShowCompany"),"company"). ' '.stripslashes($obj->nom)."</a></td>\n";
 
 	  print '<td align="center">'.price($obj->total_ttc)."</td>\n";
diff --git a/htdocs/compta/prelevement/lignes.php b/htdocs/compta/prelevement/lignes.php
index 2651ada8ecf..5942c163858 100644
--- a/htdocs/compta/prelevement/lignes.php
+++ b/htdocs/compta/prelevement/lignes.php
@@ -105,15 +105,15 @@ if ($sortfield == "") {
  *
  */
 $sql = "SELECT pl.rowid, pl.statut, pl.amount";
-$sql .= " , s.idp, s.nom";
+$sql .= " , s.rowid as socid, s.nom";
 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
 $sql .= " WHERE pl.fk_prelevement_bons=".$prev_id;
-$sql .= " AND pl.fk_soc = s.idp";
+$sql .= " AND pl.fk_soc = s.rowid";
 
 if ($_GET["socid"])
 {
-  $sql .= " AND s.idp = ".$_GET["socid"];
+  $sql .= " AND s.rowid = ".$_GET["socid"];
 }
 
 $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset);
@@ -151,7 +151,7 @@ if ($result)
       print substr('000000'.$obj->rowid, -6);
       print '</a></td>';
 
-      print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->idp.'">'.stripslashes($obj->nom)."</a></td>\n";
+      print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->socid.'">'.stripslashes($obj->nom)."</a></td>\n";
 
       print '<td align="center">'.price($obj->amount)."</td>\n";
 
diff --git a/htdocs/compta/prelevement/liste.php b/htdocs/compta/prelevement/liste.php
index febf1e606df..7e7be9acbd8 100644
--- a/htdocs/compta/prelevement/liste.php
+++ b/htdocs/compta/prelevement/liste.php
@@ -62,7 +62,7 @@ $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
 $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
 $sql .= " WHERE pl.fk_prelevement_bons = p.rowid";
-$sql .= " AND s.idp = pl.fk_soc";
+$sql .= " AND s.rowid = pl.fk_soc";
 
 if ($_GET["search_ligne"])
 {
diff --git a/htdocs/compta/prelevement/liste_factures.php b/htdocs/compta/prelevement/liste_factures.php
index 0cabedce825..32fbac681aa 100644
--- a/htdocs/compta/prelevement/liste_factures.php
+++ b/htdocs/compta/prelevement/liste_factures.php
@@ -49,7 +49,7 @@ $offset = $conf->liste_limit * $page ;
  */
 $sql = "SELECT p.rowid, p.ref, p.statut";
 $sql .= " ,f.rowid as facid, f.facnumber, f.total_ttc";
-$sql .= " , s.idp, s.nom";
+$sql .= " , s.rowid as socid, s.nom";
 $sql .= " , pl.statut as statut_ligne, pl.rowid as rowid_ligne";
 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
 $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
@@ -58,12 +58,12 @@ $sql .= " , ".MAIN_DB_PREFIX."facture as f";
 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
 $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid";
 $sql .= " AND pl.fk_prelevement_bons = p.rowid";
-$sql .= " AND f.fk_soc = s.idp";
+$sql .= " AND f.fk_soc = s.rowid";
 $sql .= " AND pf.fk_facture = f.rowid";
 
 if ($_GET["socid"])
 {
-  $sql .= " AND s.idp = ".$_GET["socid"];
+  $sql .= " AND s.rowid = ".$_GET["socid"];
 }
 
 if ($_GET["search_fac"])
@@ -131,7 +131,7 @@ if ($result)
 
       print '<a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$obj->facid.'">'.$obj->facnumber."</a></td>\n";
 
-      print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->idp.'">';
+      print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->socid.'">';
       print img_object($langs->trans("ShowCompany"),"company"). ' '.stripslashes($obj->nom)."</a></td>\n";
 
       print '<td align="right">'.price($obj->total_ttc)."</td>\n";
diff --git a/htdocs/compta/prelevement/rejets.php b/htdocs/compta/prelevement/rejets.php
index 77fe163f49b..41983719062 100644
--- a/htdocs/compta/prelevement/rejets.php
+++ b/htdocs/compta/prelevement/rejets.php
@@ -70,18 +70,18 @@ $rej = new RejetPrelevement($db, $user);
  *
  */
 $sql = "SELECT pl.rowid, pr.motif, p.ref, pl.statut";
-$sql .= " , s.idp, s.nom";
+$sql .= " , s.rowid as socid, s.nom";
 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
 $sql .= " , ".MAIN_DB_PREFIX."prelevement_rejet as pr";
 $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
 $sql .= " WHERE pr.fk_prelevement_lignes = pl.rowid";
 $sql .= " AND pl.fk_prelevement_bons = p.rowid";
-$sql .= " AND pl.fk_soc = s.idp";
+$sql .= " AND pl.fk_soc = s.rowid";
 
 if ($_GET["socid"])
 {
-  $sql .= " AND s.idp = ".$_GET["socid"];
+  $sql .= " AND s.rowid = ".$_GET["socid"];
 }
 
 $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset);
@@ -115,7 +115,7 @@ if ($result)
 
       print substr('000000'.$obj->rowid, -6)."</a></td>";
 
-      print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->idp.'">'.stripslashes($obj->nom)."</a></td>\n";
+      print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->socid.'">'.stripslashes($obj->nom)."</a></td>\n";
 
       print '<td>'.$rej->motifs[$obj->motif].'</td>';
       print "</tr>\n";
diff --git a/htdocs/compta/propal.php b/htdocs/compta/propal.php
index 7ac34e0ccc2..ac9c56a2a0b 100644
--- a/htdocs/compta/propal.php
+++ b/htdocs/compta/propal.php
@@ -653,20 +653,20 @@ else
   $pagenext = $page + 1;
 
 
-  $sql = "SELECT s.nom, s.idp, s.client,";
+  $sql = "SELECT s.nom, s.rowid as socid, s.client,";
   $sql.= " p.rowid as propalid, p.price, p.ref, p.fk_statut,";
   $sql.= $db->pdate("p.datep")." as dp, ";
   $sql.= $db->pdate("p.fin_validite")." as dfin";
   if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
   $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p";
   if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-  $sql.= " WHERE p.fk_soc = s.idp";
-  if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
-  if ($socid)           $sql .= " AND s.idp = $socid";
+  $sql.= " WHERE p.fk_soc = s.rowid";
+  if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
+  if ($socid)           $sql .= " AND s.rowid = ".$socid;
   if ($viewstatut <> '') $sql .= " AND p.fk_statut in ($viewstatut)"; // viewstatut peut etre combinaisons s�par� par virgules
-  if ($month > 0)        $sql .= " AND date_format(p.datep, '%Y-%m') = '$year-$month'";
-  if ($year > 0)         $sql .= " AND date_format(p.datep, '%Y') = $year";
-  $sql .= " ORDER BY $sortfield $sortorder, p.rowid DESC ";
+  if ($month > 0)        $sql .= " AND date_format(p.datep, '%Y-%m') = '".$year-$month."'";
+  if ($year > 0)         $sql .= " AND date_format(p.datep, '%Y') = ".$year;
+  $sql .= " ORDER BY ".$sortfield." ".$sortorder.", p.rowid DESC ";
   $sql .= $db->plimit($limit + 1,$offset);
 
 	if ( $db->query($sql) )
@@ -704,7 +704,7 @@ else
 			// Societe
 			print "<td>";
 			$societestatic->nom=$objp->nom;
-			$societestatic->id=$objp->idp;
+			$societestatic->id=$objp->socid;
 			$societestatic->client=$objp->client;
 			print $societestatic->getNomUrl(1,'customer',44);
 			print "</td>";
diff --git a/htdocs/compta/recap-compta.php b/htdocs/compta/recap-compta.php
index a62e6c219e9..c327f22f670 100644
--- a/htdocs/compta/recap-compta.php
+++ b/htdocs/compta/recap-compta.php
@@ -55,7 +55,7 @@ llxHeader();
 if ($socid > 0)
 {
     $societe = new Societe($db);
-    $societe->fetch($socid, $to);  // si $to='next' ajouter " AND s.idp > $socid ORDER BY idp ASC LIMIT 1";
+    $societe->fetch($socid, $to);  // si $to='next' ajouter " AND s.rowid > $socid ORDER BY idp ASC LIMIT 1";
 
     /*
      * Affichage onglets
@@ -91,11 +91,11 @@ if ($socid > 0)
     
         print '<table class="noborder" width="100%">';
     
-        $sql = "SELECT s.nom, s.idp, f.facnumber, f.amount, ".$db->pdate("f.datef")." as df,";
+        $sql = "SELECT s.nom, s.rowid as socid, f.facnumber, f.amount, ".$db->pdate("f.datef")." as df,";
         $sql.= " f.paye as paye, f.fk_statut as statut, f.rowid as facid,";
         $sql.= " u.login, u.rowid as userid";
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."user as u";
-        $sql.= " WHERE f.fk_soc = s.idp AND s.idp = ".$societe->id;
+        $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$societe->id;
         $sql.= " AND f.fk_user_valid = u.rowid";
         $sql.= " ORDER BY f.datef DESC";
     
diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php
index 56563415bd6..40c947b9f21 100644
--- a/htdocs/compta/resultat/clientfourn.php
+++ b/htdocs/compta/resultat/clientfourn.php
@@ -85,18 +85,18 @@ print '<tr><td colspan="4">&nbsp;</td></tr>';
 print '<tr><td colspan="4">Facturation clients</td></tr>';
 
 if ($modecompta == 'CREANCES-DETTES') { 
-    $sql = "SELECT s.nom, s.idp, sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc";
+    $sql = "SELECT s.nom, s.rowid as socid, sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc";
     $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f";
-    $sql .= " WHERE f.fk_soc = s.idp AND f.fk_statut in (1,2)";
+    $sql .= " WHERE f.fk_soc = s.rowid AND f.fk_statut in (1,2)";
     if ($year) $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
 } else {
     /*
      * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
      * vieilles versions, ils n'�taient pas li�s via paiement_facture. On les ajoute plus loin)
      */
-	$sql = "SELECT s.nom as nom, s.idp as idp, sum(pf.amount) as amount_ttc";
+	$sql = "SELECT s.nom as nom, s.rowid as socid, sum(pf.amount) as amount_ttc";
 	$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
-    $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid AND f.fk_soc = s.idp";
+    $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid AND f.fk_soc = s.rowid";
     if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
 }    
 if ($socid) $sql .= " AND f.fk_soc = $socid";
@@ -114,7 +114,7 @@ if ($result) {
         $var=!$var;
             
         print "<tr $bc[$var]><td>&nbsp;</td>";
-        print "<td>".$langs->trans("Bills")." <a href=\"../facture.php?socid=$objp->idp\">$objp->nom</td>\n";
+        print "<td>".$langs->trans("Bills")." <a href=\"../facture.php?socid=".$objp->socid."\">$objp->nom</td>\n";
         
         if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($objp->amount_ht)."</td>\n";
         print "<td align=\"right\">".price($objp->amount_ttc)."</td>\n";
@@ -187,19 +187,19 @@ print '</tr>';
  */
 if ($modecompta == 'CREANCES-DETTES')
 { 
-    $sql = "SELECT s.nom, s.idp, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
+    $sql = "SELECT s.nom, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
     $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f";
-    $sql .= " WHERE f.fk_soc = s.idp AND f.fk_statut in (1,2)";
+    $sql .= " WHERE f.fk_soc = s.rowid AND f.fk_statut in (1,2)";
    if ($year) {
     	$sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
     }
 } else {
-	$sql = "SELECT s.nom, s.idp, date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc";
+	$sql = "SELECT s.nom, s.rowid as socid, date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc";
 	$sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p, ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
 	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f";
 	$sql .= " ON pf.fk_facturefourn = f.rowid";
 	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s";
-	$sql .= " ON f.fk_soc = s.idp";
+	$sql .= " ON f.fk_soc = s.rowid";
     $sql .= " WHERE p.rowid = pf.fk_paiementfourn ";
     if ($year) {
     	$sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
@@ -207,10 +207,10 @@ if ($modecompta == 'CREANCES-DETTES')
 }
 if ($socid)
 {
-  $sql .= " AND f.fk_soc = $socid";
+  $sql .= " AND f.fk_soc = ".$socid;
 }
-$sql .= " GROUP BY nom, idp";
-$sql .= " ORDER BY nom, idp";
+$sql .= " GROUP BY nom, s.rowid";
+$sql .= " ORDER BY nom, s.rowid";
 
 print '<tr><td colspan="4">Facturation fournisseurs</td></tr>';
 $subtotal_ht = 0;
@@ -226,7 +226,7 @@ if ($result) {
       $var=!$var;
             
       print "<tr $bc[$var]><td>&nbsp;</td>";
-      print "<td>".$langs->trans("Bills")." <a href=\"../../fourn/facture/index.php?socid=".$objp->idp."\">$objp->nom</a></td>\n";
+      print "<td>".$langs->trans("Bills")." <a href=\"".DOL_URL_ROOT."/fourn/facture/index.php?socid=".$objp->socid."\">".$objp->nom."</a></td>\n";
       
       if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price(-$objp->amount_ht)."</td>\n";
       print "<td align=\"right\">".price(-$objp->amount_ttc)."</td>\n";
diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php
index 8aeccadb0e7..d1e29a4e6ab 100644
--- a/htdocs/compta/resultat/index.php
+++ b/htdocs/compta/resultat/index.php
@@ -84,7 +84,7 @@ $html->report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$
 if ($modecompta == 'CREANCES-DETTES') { 
     $sql  = "SELECT sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
     $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
-    $sql .= " WHERE f.fk_soc = s.idp AND f.fk_statut in (1,2)";
+    $sql .= " WHERE f.fk_soc = s.rowid AND f.fk_statut in (1,2)";
 } else {
     /*
      * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
@@ -151,7 +151,7 @@ if ($modecompta != 'CREANCES-DETTES') {
 if ($modecompta == 'CREANCES-DETTES') { 
     $sql  = "SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
     $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f";
-    $sql .= " WHERE f.fk_soc = s.idp AND f.fk_statut in (1,2)";
+    $sql .= " WHERE f.fk_soc = s.rowid AND f.fk_statut in (1,2)";
 } else {
 	$sql = "SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
 	$sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p";
diff --git a/htdocs/compta/stats/casoc.php b/htdocs/compta/stats/casoc.php
index d8acb0f7bbb..5a045a525ca 100644
--- a/htdocs/compta/stats/casoc.php
+++ b/htdocs/compta/stats/casoc.php
@@ -76,9 +76,9 @@ $html->report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$
 $catotal=0;
 if ($modecompta == 'CREANCES-DETTES')
 {
-    $sql = "SELECT s.idp as rowid, s.nom as name, sum(f.total) as amount, sum(f.total_ttc) as amount_ttc";
+    $sql = "SELECT s.rowid as socid, s.nom as name, sum(f.total) as amount, sum(f.total_ttc) as amount_ttc";
     $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
-    $sql .= " WHERE f.fk_statut in (1,2) AND f.fk_soc = s.idp";
+    $sql .= " WHERE f.fk_statut in (1,2) AND f.fk_soc = s.rowid";
     if ($year) $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
 }
 else
@@ -87,14 +87,14 @@ else
      * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
      * vieilles versions, ils n'�taient pas li�s via paiement_facture. On les ajoute plus loin)
      */
-	$sql = "SELECT s.idp as rowid, s.nom as name, sum(pf.amount) as amount_ttc";
+	$sql = "SELECT s.rowid as socid, s.nom as name, sum(pf.amount) as amount_ttc";
 	$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
-    $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid AND f.fk_soc = s.idp";
+    $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid AND f.fk_soc = s.rowid";
     if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
 }
-if ($socid) $sql .= " AND f.fk_soc = $socid";
-$sql .= " GROUP BY rowid";
-$sql .= " ORDER BY rowid";
+if ($socid) $sql .= " AND f.fk_soc = ".$socid;
+$sql .= " GROUP BY s.rowid";
+$sql .= " ORDER BY s.rowid";
 
 $result = $db->query($sql);
 if ($result)
@@ -104,8 +104,8 @@ if ($result)
     while ($i < $num)
     {
          $obj = $db->fetch_object($result);
-         $amount[$obj->rowid] += $obj->amount_ttc;
-         $name[$obj->rowid] = $obj->name;
+         $amount[$obj->socid] += $obj->amount_ttc;
+         $name[$obj->socid] = $obj->name;
          $catotal+=$obj->amount_ttc;
          $i++;
     }
diff --git a/htdocs/compta/stats/comp.php b/htdocs/compta/stats/comp.php
index 7c7fa39f968..981c9727edb 100644
--- a/htdocs/compta/stats/comp.php
+++ b/htdocs/compta/stats/comp.php
@@ -26,11 +26,12 @@ require("./lib.inc.php");
 
 function propals ($db, $year, $month) {
   global $bc,$langs;
-  $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price, p.ref,".$db->pdate("p.datep")." as dp, c.label as statut, c.id as statutid";
-  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c WHERE p.fk_soc = s.idp AND p.fk_statut = c.id";
+  $sql = "SELECT s.nom, s.rowid as socid, p.rowid as propalid, p.price, p.ref,".$db->pdate("p.datep")." as dp, c.label as statut, c.id as statutid";
+  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c";
+  $sql.= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id";
   $sql .= " AND c.id in (1,2,4)";
-  $sql .= " AND date_format(p.datep, '%Y') = $year ";
-  $sql .= " AND round(date_format(p.datep, '%m')) = $month ";
+  $sql .= " AND date_format(p.datep, '%Y') = ".$year;
+  $sql .= " AND round(date_format(p.datep, '%m')) = ".$month;
 
 
   $sql .= " ORDER BY p.fk_statut";
@@ -68,14 +69,14 @@ function propals ($db, $year, $month) {
     $var=!$var;
     print "<tr $bc[$var]>";
     
-    print "<td><a href=\"comp.php?socid=$objp->idp\">$objp->nom</a></td>\n";
+    print "<td><a href=\"comp.php?socid=".$objp->socid."\">".$objp->nom."</a></td>\n";
     
-    print "<td><a href=\"../../comm/propal.php?propalid=$objp->propalid\">$objp->ref</a></td>\n";
+    print "<td><a href=\"".DOL_URL_ROOT."/comm/propal.php?propalid=".$objp->propalid."\">".$objp->ref."</a></td>\n";
     
     print "<td align=\"right\">".dolibarr_print_date($objp->dp)."</td>\n";
     
     print "<td align=\"right\">".price($objp->price)."</td>\n";
-    print "<td align=\"center\">$objp->statut</td>\n";
+    print "<td align=\"center\">".$objp->statut."</td>\n";
     print "</tr>\n";
     
     $total = $total + $objp->price;
@@ -97,15 +98,15 @@ function propals ($db, $year, $month) {
 function factures ($db, $year, $month, $paye) {
   global $bc,$conf;
 
-  $sql = "SELECT s.nom, s.idp, f.facnumber, f.total,".$db->pdate("f.datef")." as df, f.paye, f.rowid as facid ";
+  $sql = "SELECT s.nom, s.rowid as socid, f.facnumber, f.total,".$db->pdate("f.datef")." as df, f.paye, f.rowid as facid ";
   $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
   $sql .= " WHERE f.fk_statut = 1";
   if ($conf->compta->mode != 'CREANCES-DETTES') { 
-	$sql .= " AND f.paye = $paye";
+	$sql .= " AND f.paye = ".$paye;
   }
-  $sql .= " AND f.fk_soc = s.idp";
-  $sql .= " AND date_format(f.datef, '%Y') = $year ";
-  $sql .= " AND round(date_format(f.datef, '%m')) = $month ";
+  $sql .= " AND f.fk_soc = s.rowid";
+  $sql .= " AND date_format(f.datef, '%Y') = ".$year;
+  $sql .= " AND round(date_format(f.datef, '%m')) = ".$month;
   $sql .= " ORDER BY f.datef DESC ";
 
   $result = $db->query($sql);
@@ -130,8 +131,8 @@ function factures ($db, $year, $month, $paye) {
 	      $objp = $db->fetch_object($result);
 	      $var=!$var;
 	      print "<tr $bc[$var]>";
-	      print "<td><a href=\"comp.php?socid=$objp->idp\">$objp->nom</a></td>\n";
-	      print "<td><a href=\"../facture.php?facid=$objp->facid\">$objp->facnumber</a></td>\n";
+	      print "<td><a href=\"comp.php?socid=".$objp->socid."\">".$objp->nom."</a></td>\n";
+	      print "<td><a href=\"../facture.php?facid=".$objp->facid."\">".$objp->facnumber."</a></td>\n";
 	      if ($objp->df > 0 )
 		{
 		  print "<td align=\"right\">".dolibarr_print_date($objp->df)."</td>\n";
diff --git a/htdocs/compta/stats/exercices.php b/htdocs/compta/stats/exercices.php
index 4a624ad56d9..734d047a2dc 100644
--- a/htdocs/compta/stats/exercices.php
+++ b/htdocs/compta/stats/exercices.php
@@ -49,10 +49,10 @@ function factures ($db, $year, $month, $paye)
 {
   global $bc,$langs;
 
-  $sql = "SELECT s.nom, s.idp, f.facnumber, f.total as amount,".$db->pdate("f.datef")." as df, f.paye, f.rowid as facid ";
-  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = s.idp AND f.paye = $paye";
-  $sql .= " AND date_format(f.datef, '%Y') = $year ";
-  $sql .= " AND round(date_format(f.datef, '%m')) = $month ";
+  $sql = "SELECT s.nom, s.rowid as socid, f.facnumber, f.total as amount,".$db->pdate("f.datef")." as df, f.paye, f.rowid as facid ";
+  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = s.rowid AND f.paye = ".$paye;
+  $sql .= " AND date_format(f.datef, '%Y') = ".$year;
+  $sql .= " AND round(date_format(f.datef, '%m')) = ".$month;
   $sql .= " ORDER BY f.datef DESC ";
 
   $result = $db->query($sql);
@@ -74,8 +74,8 @@ function factures ($db, $year, $month, $paye)
 	$objp = $db->fetch_object($result);
 	$var=!$var;
 	print "<TR $bc[$var]>";
-	print "<TD><a href=\"comp.php?socid=$objp->idp\">$objp->nom</a></TD>\n";
-	print "<TD><a href=\"facture.php?facid=$objp->facid\">$objp->facnumber</a></TD>\n";
+	print "<TD><a href=\"comp.php?socid=".$objp->socid."\">".$objp->nom."</a></TD>\n";
+	print "<TD><a href=\"facture.php?facid=".$objp->facid."\">".$objp->facnumber."</a></TD>\n";
 	if ($objp->df > 0 ) {
 	  print "<TD align=\"right\">".dolibarr_print_date($objp->df)."</TD>\n";
 	} else {
diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php
index 1d5250fe63c..2fd934ff4e7 100644
--- a/htdocs/compta/stats/index.php
+++ b/htdocs/compta/stats/index.php
@@ -305,14 +305,14 @@ if ($modecompta != 'CREANCES-DETTES')
   // Factures non r�gl�es
   // \todo Y a bug ici. Il faut prendre le reste � payer et non le total des factures non r�gl�es !
 
-  $sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp, f.total_ttc, sum(pf.amount) as am";
+  $sql = "SELECT f.facnumber, f.rowid, s.nom, s.rowid as socid, f.total_ttc, sum(pf.amount) as am";
   $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f left join ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
-  $sql .= " WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1";
+  $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1";
   if ($socid)
     {
       $sql .= " AND f.fk_soc = $socid";
     }
-  $sql .= " GROUP BY f.facnumber,f.rowid,s.nom, s.idp, f.total_ttc";   
+  $sql .= " GROUP BY f.facnumber,f.rowid,s.nom, s.rowid, f.total_ttc";   
   
   if ( $db->query($sql) )
     {
@@ -352,16 +352,16 @@ if ($modecompta != 'CREANCES-DETTES')
 Je commente toute cette partie car les chiffres affich�es sont faux - Eldy.
 En attendant correction.
 
-  $sql = "SELECT sum(f.total) as tot_fht,sum(f.total_ttc) as tot_fttc, p.rowid, p.ref, s.nom, s.idp, p.total_ht, p.total_ttc
+  $sql = "SELECT sum(f.total) as tot_fht,sum(f.total_ttc) as tot_fttc, p.rowid, p.ref, s.nom, s.rowid as socid, p.total_ht, p.total_ttc
 			FROM ".MAIN_DB_PREFIX."commande AS p, llx_societe AS s
 			LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid
 			LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid
-			WHERE p.fk_soc = s.idp
+			WHERE p.fk_soc = s.rowid
 					AND p.fk_statut >=1
 					AND p.facture =0";
   if ($socid)
     {
-      $sql .= " AND f.fk_soc = $socid";
+      $sql .= " AND f.fk_soc = ".$socid;
     }
 	$sql .= " GROUP BY p.rowid";
 
diff --git a/htdocs/compta/tva/clients.php b/htdocs/compta/tva/clients.php
index daa45df53cb..bd8125193cf 100644
--- a/htdocs/compta/tva/clients.php
+++ b/htdocs/compta/tva/clients.php
@@ -62,13 +62,13 @@ function tva_coll($db,$y)
     if ($conf->compta->mode == "CREANCES-DETTES")
     {
         // Si on paye la tva sur les factures dues (non brouillon)
-        $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra, sum(f.total) as amount, sum(f.tva) as tva, s.tva_assuj as assuj, s.idp as id_soc";
+        $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra, sum(f.total) as amount, sum(f.tva) as tva, s.tva_assuj as assuj, s.rowid as socid";
         $sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
         $sql.= " WHERE ";
         $sql.= " f.fk_statut in (1,2)";
         $sql.= " AND date_format(f.datef,'%Y') = ".$y;
-        $sql.= " AND s.idp = f.fk_soc ";
-        $sql.= " GROUP BY s.idp";
+        $sql.= " AND s.rowid = f.fk_soc ";
+        $sql.= " GROUP BY s.rowid";
     }
     else
     {
@@ -120,13 +120,13 @@ function tva_paye($db, $y)
     if ($conf->compta->mode == "CREANCES-DETTES")
     {
         // Si on paye la tva sur les factures dues (non brouillon)
-        $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra, sum(f.total_ht) as amount, sum(f.tva) as tva, s.tva_assuj as assuj, s.idp as id_soc";
+        $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra, sum(f.total_ht) as amount, sum(f.tva) as tva, s.tva_assuj as assuj, s.rowid as socid";
         $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s";
         $sql.= " WHERE ";
         $sql.= " f.fk_statut in (1,2)";
         $sql.= " AND date_format(f.datef,'%Y') = ".$y;
-        $sql.= " AND s.idp = f.fk_soc ";
-        $sql.= " GROUP BY s.idp";
+        $sql.= " AND s.rowid = f.fk_soc ";
+        $sql.= " GROUP BY s.rowid";
     }
     else
     {
diff --git a/htdocs/contact.class.php b/htdocs/contact.class.php
index adb31aa485c..7ce936b8f31 100644
--- a/htdocs/contact.class.php
+++ b/htdocs/contact.class.php
@@ -182,7 +182,7 @@ class Contact
         $sql .= ", phone_mobile = '".addslashes($this->phone_mobile)."'";
         $sql .= ", jabberid = '".addslashes($this->jabberid)."'";
         if ($user) $sql .= ", fk_user_modif=".$user->id;
-        $sql .= " WHERE idp=".$id;
+        $sql .= " WHERE rowid=".$id;
         dolibarr_syslog("Contact.class::update sql=".$sql,LOG_DEBUG);
     
         $result = $this->db->query($sql);
@@ -300,7 +300,7 @@ class Contact
 	function update_perso($id, $user=0)
 	{
 		// Mis a jour contact
-		$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET idp=".$id;
+		$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET rowid=".$id;
 	
 		if ($this->birthday)	// <0 si avant 1970, >0 si apres 1970
 		{
@@ -316,7 +316,7 @@ class Contact
             }
 		}
         if ($user) $sql .= ", fk_user_modif=".$user->id;
-		$sql .= " WHERE idp=$id";
+		$sql .= " WHERE rowid=".$id;
 
 		dolibarr_syslog("Contact::update_perso this->birthday=".$this->birthday." - sql=".$sql);	
 		$resql = $this->db->query($sql);
@@ -371,7 +371,7 @@ class Contact
     {
     	global $langs;
     	$langs->load("companies");
-        $sql = "SELECT c.idp, c.fk_soc, c.civilite as civilite_id, c.name, c.firstname,";
+        $sql = "SELECT c.rowid, c.fk_soc, c.civilite as civilite_id, c.name, c.firstname,";
         $sql.= " c.address, c.cp, c.ville,";
         $sql.= " c.fk_pays, p.libelle as pays, p.code as pays_code,";
         $sql.= " c.birthday,";
@@ -379,8 +379,8 @@ class Contact
         $sql.= " u.rowid as user_id, u.login as user_login";
         $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c";
         $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON c.fk_pays = p.rowid";
-        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.idp = u.fk_socpeople";
-        $sql.= " WHERE c.idp = ". $id;
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
+        $sql.= " WHERE c.rowid = ". $id;
     
     	dolibarr_syslog("Contact::fetch sql=".$sql);
         $resql=$this->db->query($sql);
@@ -390,7 +390,7 @@ class Contact
             {
                 $obj = $this->db->fetch_object($resql);
     
-                $this->id             = $obj->idp;
+                $this->id             = $obj->rowid;
                 $this->civilite_id    = $obj->civilite_id;
                 $this->name           = $obj->name;
                 $this->firstname      = $obj->firstname;
@@ -540,7 +540,7 @@ class Contact
 		global $conf, $langs;
 	
 		$sql = "SELECT c.name, c.firstname FROM ".MAIN_DB_PREFIX."socpeople as c";
-		$sql .= " WHERE c.idp = ". $id;
+		$sql .= " WHERE c.rowid = ". $id;
 		$resql=$this->db->query($sql);
 		if ($resql)
 		{
@@ -554,7 +554,7 @@ class Contact
 		}
 	
 		$sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople";
-		$sql .= " WHERE idp=$id";
+		$sql .= " WHERE rowid=".$id;
 	
 		$result = $this->db->query($sql);
 		if (! $result)
@@ -580,10 +580,10 @@ class Contact
      */
     function info($id)
     {
-        $sql = "SELECT c.idp, ".$this->db->pdate("c.datec")." as datec, c.fk_user_creat";
+        $sql = "SELECT c.rowid, ".$this->db->pdate("c.datec")." as datec, c.fk_user_creat";
         $sql .= ", ".$this->db->pdate("c.tms")." as tms, c.fk_user_modif";
         $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
-        $sql .= " WHERE c.idp = ".$id;
+        $sql .= " WHERE c.rowid = ".$id;
         
         $resql=$this->db->query($sql);
         if ($resql)
@@ -592,7 +592,7 @@ class Contact
             {
                 $obj = $this->db->fetch_object($resql);
     
-                $this->id                = $obj->idp;
+                $this->id                = $obj->rowid;
     
                 if ($obj->fk_user_creat) {
                     $cuser = new User($this->db, $obj->fk_user_creat);
@@ -747,7 +747,7 @@ class Contact
 
 		// Charge tableau des id de soci�t� socids
 		$socids = array();
-		$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe LIMIT 10";
+		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe LIMIT 10";
 		$resql = $this->db->query($sql);
 		if ($resql)
 		{
diff --git a/htdocs/contact/exportimport.php b/htdocs/contact/exportimport.php
index 01eb9e9e04b..f53265a0483 100644
--- a/htdocs/contact/exportimport.php
+++ b/htdocs/contact/exportimport.php
@@ -49,7 +49,7 @@ if ($contactid && ! $user->rights->commercial->client->voir)
 {
     $sql = "SELECT sc.fk_soc, sp.fk_soc";
     $sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."socpeople as sp";
-    $sql .= " WHERE sp.idp = ".$contactid;
+    $sql .= " WHERE sp.rowid = ".$contactid;
     if (! $user->rights->commercial->client->voir && ! $socid)
     {
     	$sql .= " AND sc.fk_soc = sp.fk_soc AND sc.fk_user = ".$user->id;
diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php
index 32f744c99b2..b32e698e2e5 100644
--- a/htdocs/contact/fiche.php
+++ b/htdocs/contact/fiche.php
@@ -58,7 +58,7 @@ if ($contactid && !$user->rights->commercial->client->voir)
 {
 	$sql = "SELECT sc.fk_soc, sp.fk_soc";
 	$sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."socpeople as sp";
-	$sql .= " WHERE sp.idp = ".$contactid;
+	$sql .= " WHERE sp.rowid = ".$contactid;
 	if (!$user->rights->commercial->client->voir && !$user->societe_id > 0)
 	{
 		$sql .= " AND sc.fk_soc = sp.fk_soc AND sc.fk_user = ".$user->id;
diff --git a/htdocs/contact/index.php b/htdocs/contact/index.php
index cd16d4e1d1c..81b8939e5ed 100644
--- a/htdocs/contact/index.php
+++ b/htdocs/contact/index.php
@@ -104,13 +104,13 @@ if ($_POST["button_removefilter"])
  
 llxHeader();
 
-$sql = "SELECT s.idp, s.nom, ";
-$sql.= " p.idp as cidp, p.name, p.firstname, p.email, p.phone, p.phone_mobile, p.fax";
+$sql = "SELECT s.rowid as socid, s.nom, ";
+$sql.= " p.rowid as cidp, p.name, p.firstname, p.email, p.phone, p.phone_mobile, p.fax";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql.= " FROM ";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= MAIN_DB_PREFIX."societe_commerciaux as sc,";
 $sql.= " ".MAIN_DB_PREFIX."socpeople as p";
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.idp = p.fk_soc";
+$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
 $sql.= " WHERE 1=1 ";
 
 if ($_GET["userid"])    // statut commercial
@@ -119,7 +119,7 @@ if ($_GET["userid"])    // statut commercial
 }
 if (!$user->rights->commercial->client->voir && !$socid) //restriction
 {
-	$sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 }
 if ($search_nom)        // filtre sur le nom
 {
@@ -155,7 +155,7 @@ if ($sall)
 }
 if ($socid)
 {
-    $sql .= " AND s.idp = $socid";
+    $sql .= " AND s.rowid = ".$socid;
 }
 
 if($_GET["view"] == "recent")
@@ -261,9 +261,9 @@ if ($result)
         print ' '.$obj->name.'</a></td>';
         print '<td>'.$obj->firstname.'</td>';
         print '<td>';
-        if ($obj->idp)
+        if ($obj->socid)
         {
-            print '<a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">';
+            print '<a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">';
             print img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($obj->nom,40).'</a>';
         }
         else
@@ -271,7 +271,7 @@ if ($result)
             print '&nbsp;';
         }
         print '</td>';
-        print '<td><a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&amp;actioncode=AC_TEL&amp;contactid='.$obj->cidp.'&amp;socid='.$obj->idp.'">'.dolibarr_print_phone($obj->phone).'</a>&nbsp;</td>';
+        print '<td><a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&amp;actioncode=AC_TEL&amp;contactid='.$obj->cidp.'&amp;socid='.$obj->socid.'">'.dolibarr_print_phone($obj->phone).'</a>&nbsp;</td>';
 
         if ($_GET["view"] == 'phone')
         {
diff --git a/htdocs/contact/info.php b/htdocs/contact/info.php
index 6109d40d0b8..5bf70dcb468 100644
--- a/htdocs/contact/info.php
+++ b/htdocs/contact/info.php
@@ -50,7 +50,7 @@ if ($contactid && ! $user->rights->commercial->client->voir)
 {
     $sql = "SELECT sc.fk_soc, sp.fk_soc";
     $sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."socpeople as sp";
-    $sql .= " WHERE sp.idp = ".$contactid;
+    $sql .= " WHERE sp.rowid = ".$contactid;
     if (! $user->rights->commercial->client->voir && ! $socid)
     {
     	$sql .= " AND sc.fk_soc = sp.fk_soc AND sc.fk_user = ".$user->id;
diff --git a/htdocs/contact/ldap.php b/htdocs/contact/ldap.php
index 49f1a8f7651..85ff6e709d7 100644
--- a/htdocs/contact/ldap.php
+++ b/htdocs/contact/ldap.php
@@ -51,7 +51,7 @@ if ($contactid && ! $user->rights->commercial->client->voir)
 {
     $sql = "SELECT sc.fk_soc, sp.fk_soc";
     $sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."socpeople as sp";
-    $sql .= " WHERE sp.idp = ".$contactid;
+    $sql .= " WHERE sp.rowid = ".$contactid;
     if (! $user->rights->commercial->client->voir && ! $socid)
     {
     	$sql .= " AND sc.fk_soc = sp.fk_soc AND sc.fk_user = ".$user->id;
diff --git a/htdocs/contact/perso.php b/htdocs/contact/perso.php
index 98068cc4182..92f6c67b2f3 100644
--- a/htdocs/contact/perso.php
+++ b/htdocs/contact/perso.php
@@ -50,7 +50,7 @@ if ($contactid && ! $user->rights->commercial->client->voir)
 {
     $sql = "SELECT sc.fk_soc, sp.fk_soc";
     $sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."socpeople as sp";
-    $sql .= " WHERE sp.idp = ".$contactid;
+    $sql .= " WHERE sp.rowid = ".$contactid;
     if (! $user->rights->commercial->client->voir && ! $socid)
     {
     	$sql .= " AND sc.fk_soc = sp.fk_soc AND sc.fk_user = ".$user->id;
diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php
index bf8d4163e90..ffbac60c287 100644
--- a/htdocs/contrat/fiche.php
+++ b/htdocs/contrat/fiche.php
@@ -319,9 +319,9 @@ if ($_GET["action"] == 'create')
 
     $new_contrat = new Contrat($db);
 
-    $sql = "SELECT s.nom, s.prefix_comm, s.idp ";
-    $sql .= "FROM ".MAIN_DB_PREFIX."societe as s ";
-    $sql .= "WHERE s.idp = ".$_GET["socid"];
+    $sql = "SELECT s.nom, s.prefix_comm, s.rowid";
+    $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
+    $sql.= " WHERE s.rowid = ".$_GET["socid"];
 
     $resql=$db->query($sql);
     if ($resql)
@@ -332,7 +332,7 @@ if ($_GET["action"] == 'create')
             $obj = $db->fetch_object($resql);
 
             $soc = new Societe($db);
-            $soc->fetch($obj->idp);
+            $soc->fetch($obj->rowid);
 
             print '<form name="contrat" action="fiche.php" method="post">';
 
diff --git a/htdocs/contrat/index.php b/htdocs/contrat/index.php
index 7bd5d418a4b..3e9095f9a5d 100644
--- a/htdocs/contrat/index.php
+++ b/htdocs/contrat/index.php
@@ -105,16 +105,16 @@ $sql.= ' sum('.$db->ifsql("cd.statut=0",1,0).') as nb_initial,';
 $sql.= ' sum('.$db->ifsql("cd.statut=4 AND cd.date_fin_validite > sysdate()",1,0).') as nb_running,';
 $sql.= ' sum('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite <= sysdate())",1,0).') as nb_late,';
 $sql.= ' sum('.$db->ifsql("cd.statut=5",1,0).') as nb_closed,';
-$sql.= " c.rowid as cid, c.ref, c.datec, c.statut, s.nom, s.idp as sidp";
+$sql.= " c.rowid as cid, c.ref, c.datec, c.statut, s.nom, s.rowid as socid";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
 $sql.= " ".MAIN_DB_PREFIX."contrat as c";
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
-$sql.= " WHERE c.fk_soc = s.idp ";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
-if ($socid > 0) $sql .= " AND s.idp = ".$socid;
-$sql.= " GROUP BY c.rowid, c.datec, c.statut, s.nom, s.idp";
+$sql.= " WHERE c.fk_soc = s.rowid ";
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
+if ($socid > 0) $sql .= " AND s.rowid = ".$socid;
+$sql.= " GROUP BY c.rowid, c.datec, c.statut, s.nom, s.rowid";
 $sql.= " ORDER BY c.datec DESC";
 $sql.= " LIMIT $max";
 
@@ -146,7 +146,7 @@ if ($result)
         . (isset($obj->ref) ? $obj->ref : $obj->cid).'</a>';
         if ($obj->nb_late) print img_warning($langs->trans("Late"));
         print '</td>';
-        print '<td><a href="../comm/fiche.php?socid='.$obj->sidp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
+        print '<td><a href="../comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
         print '<td align="center">'.dolibarr_print_date($obj->datec).'</td>';
         print '<td align="left">'.$staticcontrat->LibStatut($obj->statut,2).'</td>';
         print '<td align="center">'.($obj->nb_initial>0?$obj->nb_initial:'').'</td>';
@@ -174,9 +174,9 @@ if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, s
 $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 $sql.= " WHERE c.statut=1 AND cd.statut = 0";
-$sql.= " AND cd.fk_contrat = c.rowid AND c.fk_soc = s.idp";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
-if ($socid > 0) $sql.= " AND s.idp = ".$socid;
+$sql.= " AND cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
+if ($socid > 0) $sql.= " AND s.rowid = ".$socid;
 $sql.= " ORDER BY cd.tms DESC";
 
 if ( $db->query($sql) )
@@ -227,9 +227,9 @@ $sql = "SELECT cd.rowid as cid, c.ref, cd.statut, cd.label, cd.description as no
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql.= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.idp";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
-if ($socid > 0) $sql.= " AND s.idp = ".$socid;
+$sql.= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid";
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
+if ($socid > 0) $sql.= " AND s.rowid = ".$socid;
 $sql.= " ORDER BY cd.tms DESC";
 
 if ( $db->query($sql) )
diff --git a/htdocs/contrat/liste.php b/htdocs/contrat/liste.php
index dc22a6e4327..e64f9140a40 100644
--- a/htdocs/contrat/liste.php
+++ b/htdocs/contrat/liste.php
@@ -72,18 +72,18 @@ $sql.= ' sum('.$db->ifsql("cd.statut=0",1,0).') as nb_initial,';
 $sql.= ' sum('.$db->ifsql("cd.statut=4 AND cd.date_fin_validite > sysdate()",1,0).') as nb_running,';
 $sql.= ' sum('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite <= sysdate())",1,0).') as nb_late,';
 $sql.= ' sum('.$db->ifsql("cd.statut=5",1,0).') as nb_closed,';
-$sql.= " c.rowid as cid, c.ref, c.datec, c.statut, s.nom, s.idp as sidp";
+$sql.= " c.rowid as cid, c.ref, c.datec, c.statut, s.nom, s.rowid as socid";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
-$sql.= " WHERE c.fk_soc = s.idp ";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+$sql.= " WHERE c.fk_soc = s.rowid ";
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 if ($search_nom)      $sql.= " AND s.nom like '%".addslashes($search_nom)."%'";
 if ($search_contract) $sql.= " AND c.rowid = '".addslashes($search_contract)."'";
 if ($sall)            $sql.= " AND (s.nom like '%".addslashes($sall)."%' OR cd.label like '%".addslashes($sall)."%' OR cd.description like '%".addslashes($sall)."%')";
-if ($socid > 0)       $sql.= " AND s.idp = ".$socid;
-$sql.= " GROUP BY c.rowid, c.datec, c.statut, s.nom, s.idp";
+if ($socid > 0)       $sql.= " AND s.rowid = ".$socid;
+$sql.= " GROUP BY c.rowid, c.datec, c.statut, s.nom, s.rowid";
 $sql.= " ORDER BY $sortfield $sortorder";
 $sql.= $db->plimit($limit + 1 ,$offset);
 
@@ -135,7 +135,7 @@ if ($resql)
         print img_object($langs->trans("ShowContract"),"contract").' '.(isset($obj->ref) ? $obj->ref : $obj->cid) .'</a>';
         if ($obj->nb_late) print img_warning($langs->trans("Late"));
         print '</td>';
-        print '<td><a href="../comm/fiche.php?socid='.$obj->sidp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
+        print '<td><a href="../comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
         print '<td align="center">'.dolibarr_print_date($obj->datec).'</td>';
         print '<td align="center">'.$staticcontrat->LibStatut($obj->statut,3).'</td>';
         print '<td align="center">'.($obj->nb_initial>0?$obj->nb_initial:'').'</td>';
diff --git a/htdocs/contrat/services.php b/htdocs/contrat/services.php
index 7701211e187..6f4217aef64 100644
--- a/htdocs/contrat/services.php
+++ b/htdocs/contrat/services.php
@@ -68,7 +68,7 @@ $staticcontratligne=new ContratLigne($db);
 llxHeader();
 
 
-$sql = "SELECT s.idp as sidp, s.nom, c.rowid as cid,";
+$sql = "SELECT s.rowid as socid, s.nom, c.rowid as cid,";
 $sql.= " cd.rowid, cd.description, cd.statut, p.rowid as pid, p.label as label,";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= " sc.fk_soc, sc.fk_user,";
 $sql.= " ".$db->pdate("cd.date_ouverture_prevue")." as date_ouverture_prevue,";
@@ -82,8 +82,8 @@ if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PR
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
 $sql.= " WHERE c.statut > 0";
 $sql.= " AND c.rowid = cd.fk_contrat";
-$sql.= " AND c.fk_soc = s.idp";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+$sql.= " AND c.fk_soc = s.rowid";
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 if ($mode == "0") $sql.= " AND cd.statut = 0";
 if ($mode == "4") $sql.= " AND cd.statut = 4";
 if ($mode == "5") $sql.= " AND cd.statut = 5";
@@ -91,7 +91,7 @@ if ($filter == "expired") $sql.= " AND date_fin_validite < sysdate()";
 if ($search_nom)      $sql.= " AND s.nom like '%".addslashes($search_nom)."%'";
 if ($search_contract) $sql.= " AND c.rowid = '".addslashes($search_contract)."'";
 if ($search_service)  $sql.= " AND (p.ref like '%".addslashes($search_service)."%' OR p.description like '%".addslashes($search_service)."%')";
-if ($socid > 0)       $sql.= " AND s.idp = ".$socid;
+if ($socid > 0)       $sql.= " AND s.rowid = ".$socid;
 $sql .= " ORDER BY $sortfield $sortorder";
 $sql .= $db->plimit($limit + 1 ,$offset);
 
@@ -163,7 +163,7 @@ if ($resql)
         	print dolibarr_trunc($obj->description,20);
     	}
         print '</td>';
-        print '<td><a href="../comm/fiche.php?socid='.$obj->sidp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($obj->nom,44).'</a></td>';
+        print '<td><a href="../comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($obj->nom,44).'</a></td>';
         // Date debut
         if ($mode == "0") {
             print '<td align="center">';
diff --git a/htdocs/docs/class/courrier-droit-editeur.class.php b/htdocs/docs/class/courrier-droit-editeur.class.php
index d016f3ad5a1..16454661804 100644
--- a/htdocs/docs/class/courrier-droit-editeur.class.php
+++ b/htdocs/docs/class/courrier-droit-editeur.class.php
@@ -72,7 +72,7 @@ class pdf_courrier_droit_editeur
     $year = strftime("%Y", time());
     
     // 
-    $sql = "SELECT s.idp,s.nom";
+    $sql = "SELECT s.rowid,s.nom";
     $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
     //$sql .= " , ".MAIN_DB_PREFIX."categorie_fournisseur as cf";
     $sql .= " WHERE s.fournisseur = 1 ";
@@ -104,7 +104,7 @@ class pdf_courrier_droit_editeur
 
 	    while ($obj = $this->db->fetch_object($resql) )
 	    {
-	      $id = $obj->idp;
+	      $id = $obj->rowid;
 	    
 	      dolibarr_syslog("droits-editeurs.php id:$id", LOG_DEBUG );
 	    
@@ -198,15 +198,14 @@ class pdf_courrier_droit_editeur
 	  {
 	    $i = 0;
 	    while ($obj = $this->db->fetch_object($resql) )
-	      {
-		$id       = $obj->idp;
-		$books[$i]['title'] = $obj->label;
-		$books[$i]['id'] = $obj->rowid;
-		$books[$i]['taux'] = $obj->taux;
-		$books[$i]['qty'] = $obj->quantite;
-
-		$i++;           
-	      }   
+	    {
+		    $books[$i]['title'] = $obj->label;
+		    $books[$i]['id'] = $obj->rowid;
+		    $books[$i]['taux'] = $obj->taux;
+		    $books[$i]['qty'] = $obj->quantite;
+
+		    $i++;
+	    }   
 	    $this->db->free($resql);
 	  }
 	else
diff --git a/htdocs/document.php b/htdocs/document.php
index 4a434c56aa9..0eec9ede693 100644
--- a/htdocs/document.php
+++ b/htdocs/document.php
@@ -183,7 +183,7 @@ if ($modulepart)
             $accessallowed=1;
         }
         $original_file=$conf->societe->dir_output.'/'.$original_file;
-		$sqlprotectagainstexternals = "SELECT idp as fk_soc FROM ".MAIN_DB_PREFIX."societe WHERE idp='$refname'";
+		$sqlprotectagainstexternals = "SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX."societe WHERE idp='$refname'";
     }
 
     // Wrapping pour les expedition
diff --git a/htdocs/don.class.php b/htdocs/don.class.php
index bf9da0e3e8a..8bc52241ce7 100644
--- a/htdocs/don.class.php
+++ b/htdocs/don.class.php
@@ -145,7 +145,7 @@ class Don
 
 		// Charge tableau des id de soci�t� socids
 		$socids = array();
-		$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10";
+		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10";
 		$resql = $this->db->query($sql);
 		if ($resql)
 		{
diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php
index dbb4384f743..4ac15727ade 100644
--- a/htdocs/expedition/expedition.class.php
+++ b/htdocs/expedition/expedition.class.php
@@ -660,7 +660,7 @@ class Expedition extends CommonObject
 
 		// Charge tableau des id de soci�t� socids
 		$socids = array();
-		$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10";
+		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10";
 		$resql = $this->db->query($sql);
 		if ($resql)
 		{
diff --git a/htdocs/expedition/index.php b/htdocs/expedition/index.php
index 451eb0f115e..03a9f88e4b5 100644
--- a/htdocs/expedition/index.php
+++ b/htdocs/expedition/index.php
@@ -50,18 +50,18 @@ print "</form></table><br />\n";
 /*
  * Expeditions � valider
  */
-$sql = "SELECT e.rowid, e.ref, s.nom, s.idp, c.ref as commande_ref, c.rowid as commande_id";
+$sql = "SELECT e.rowid, e.ref, s.nom, s.rowid as socid, c.ref as commande_ref, c.rowid as commande_id";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql.= " FROM ".MAIN_DB_PREFIX."expedition as e, ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql.= " WHERE e.fk_commande = c.rowid AND c.fk_soc = s.idp AND e.fk_statut = 0";
+$sql.= " WHERE e.fk_commande = c.rowid AND c.fk_soc = s.rowid AND e.fk_statut = 0";
 if ($socid)
 {
-    $sql .= " AND c.fk_soc = $socid";
+    $sql .= " AND c.fk_soc = ".$socid;
 }
 if (!$user->rights->commercial->client->voir && !$socid) //restriction
 {
-	  $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+	  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 }
 $resql=$db->query($sql);
 if ($resql)
@@ -78,8 +78,8 @@ if ($resql)
         {
             $var=!$var;
             $obj = $db->fetch_object($resql);
-            print "<tr $bc[$var]><td nowrap=\"nowrap\"><a href=\"fiche.php?id=$obj->rowid\">".$obj->ref."</a></td>";
-            print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td>';
+            print "<tr $bc[$var]><td nowrap=\"nowrap\"><a href=\"fiche.php?id=".$obj->rowid."\">".$obj->ref."</a></td>";
+            print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.$obj->nom.'</a></td>';
             print '<td><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$obj->commande_id.'">'.$obj->commande_ref.'</a></td></tr>';
             $i++;
         }
@@ -91,13 +91,13 @@ if ($resql)
 /*
  * Commandes � traiter
  */
-$sql = "SELECT c.rowid, c.ref, s.nom, s.idp";
+$sql = "SELECT c.rowid, c.ref, s.nom, s.rowid as socid";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql.= " FROM ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql.= " WHERE c.fk_soc = s.idp AND c.fk_statut = 1";
-if ($socid) $sql .= " AND c.fk_soc = $socid";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+$sql.= " WHERE c.fk_soc = s.rowid AND c.fk_statut = 1";
+if ($socid) $sql .= " AND c.fk_soc = ".$socid;
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 $sql.= " ORDER BY c.rowid ASC";
 
 if ( $db->query($sql) ) 
@@ -118,8 +118,8 @@ if ( $db->query($sql) )
 	  $obj = $db->fetch_object();
 	  print "<tr $bc[$var]>";
 	  print '<td nowrap="nowrap">';
-	  print "<a href=\"commande.php?id=$obj->rowid\">".img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref.'</a></td>';
-	  print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.dolibarr_trunc($obj->nom,20).'</a></td></tr>';
+	  print "<a href=\"commande.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref.'</a></td>';
+	  print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.dolibarr_trunc($obj->nom,20).'</a></td></tr>';
 	  $i++;
 	}
       print "</table><br>";
@@ -136,13 +136,13 @@ print '</td><td valign="top" width="70%">';
 /*
  * Commandes en traitement
  */
-$sql = "SELECT c.rowid, c.ref, s.nom, s.idp";
+$sql = "SELECT c.rowid, c.ref, s.nom, s.rowid as socid";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql .= " WHERE c.fk_soc = s.idp AND c.fk_statut = 2";
-if ($socid) $sql .= " AND c.fk_soc = $socid";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+$sql .= " WHERE c.fk_soc = s.rowid AND c.fk_statut = 2";
+if ($socid) $sql .= " AND c.fk_soc = ".$socid;
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 $resql = $db->query($sql);
 if ( $resql ) 
 {
@@ -160,9 +160,9 @@ if ( $resql )
 	{
 	  $var=!$var;
 	  $obj = $db->fetch_object($resql);
-	  print "<tr $bc[$var]><td width=\"30%\"><a href=\"commande.php?id=$obj->rowid\">".img_object($langs->trans("ShowOrder"),"order").' ';
+	  print "<tr $bc[$var]><td width=\"30%\"><a href=\"commande.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"),"order").' ';
 	  print $obj->ref.'</a></td>';
-	  print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td></tr>';
+	  print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.$obj->nom.'</a></td></tr>';
 	  $i++;
 	}
       print "</table><br>";
@@ -173,13 +173,13 @@ if ( $resql )
 /*
  * Expeditions � valider
  */
-$sql = "SELECT e.rowid, e.ref, s.nom, s.idp, c.ref as commande_ref, c.rowid as commande_id";
+$sql = "SELECT e.rowid, e.ref, s.nom, s.rowid as socid, c.ref as commande_ref, c.rowid as commande_id";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e, ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql .= " WHERE e.fk_commande = c.rowid AND c.fk_soc = s.idp AND e.fk_statut = 1";
-if ($socid) $sql .= " AND c.fk_soc = $socid";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+$sql .= " WHERE e.fk_commande = c.rowid AND c.fk_soc = s.rowid AND e.fk_statut = 1";
+if ($socid) $sql .= " AND c.fk_soc = ".$socid;
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 $sql .= " ORDER BY e.date_expedition DESC";
 $sql .= $db->plimit(5, 0);
 
@@ -200,7 +200,7 @@ if ($resql)
 	  $obj = $db->fetch_object($resql);
 	  print "<tr $bc[$var]><td width=\"20%\"><a href=\"fiche.php?id=$obj->rowid\">".img_object($langs->trans("ShowSending"),"sending").' ';
 	  print $obj->ref.'</a></td>';
-	  print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
+	  print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
 	  print '<td><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$obj->commande_id.'">'.img_object($langs->trans("ShowOrder"),"order").' '.$obj->commande_ref.'</a></td></tr>';
 	  $i++;
 	}
diff --git a/htdocs/expedition/liste.php b/htdocs/expedition/liste.php
index 0b1e4122395..e372f1eff66 100644
--- a/htdocs/expedition/liste.php
+++ b/htdocs/expedition/liste.php
@@ -57,13 +57,13 @@ $offset = $limit * $_GET["page"] ;
 
 llxHeader('',$langs->trans('ListOfSendings'),'ch-expedition.html');
 
-$sql = "SELECT e.rowid, e.ref,".$db->pdate("e.date_expedition")." as date_expedition, e.fk_statut, s.nom as socname, s.idp, c.ref as comref, c.rowid as comid";
+$sql = "SELECT e.rowid, e.ref,".$db->pdate("e.date_expedition")." as date_expedition, e.fk_statut, s.nom as socname, s.rowid as socid, c.ref as comref, c.rowid as comid";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."commande as c";
 if ($socid) $sql.=", ".MAIN_DB_PREFIX."commande as c";
 if ($user->rights->commercial->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON c.rowid = e.fk_commande";
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.idp = c.fk_soc";
+$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = c.fk_soc";
 
 $sql_add = " WHERE ";
 if ($socid)
@@ -111,9 +111,9 @@ if ($resql)
       
       $var=!$var;
       print "<tr $bc[$var]>";
-      print "<td><a href=\"fiche.php?id=$objp->rowid\">".img_object($langs->trans("ShowSending"),"sending").'</a>&nbsp;';
-      print "<a href=\"fiche.php?id=$objp->rowid\">".$objp->ref."</a></td>\n";
-      print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->idp.'">'.$objp->socname.'</a></td>';
+      print "<td><a href=\"fiche.php?id=".$objp->rowid."\">".img_object($langs->trans("ShowSending"),"sending").'</a>&nbsp;';
+      print "<a href=\"fiche.php?id=".$objp->rowid."\">".$objp->ref."</a></td>\n";
+      print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->socid.'">'.$objp->socname.'</a></td>';
       print '<td><a href="'.DOL_URL_ROOT.'/expedition/commande.php?id='.$objp->comid.'">'.$objp->comref.'</a></td>';
 
       $now = time();
diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php
index dc205a57f14..4afb9beb812 100644
--- a/htdocs/facture.class.php
+++ b/htdocs/facture.class.php
@@ -2582,7 +2582,7 @@ class Facture extends CommonObject
 
     // Charge tableau des id de soci�t� socids
     $socids = array();
-    $sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10";
+    $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10";
     $resql = $this->db->query($sql);
     if ($resql)
       {
diff --git a/htdocs/fichinter/index.php b/htdocs/fichinter/index.php
index 1c92d72895e..f3adef93972 100644
--- a/htdocs/fichinter/index.php
+++ b/htdocs/fichinter/index.php
@@ -65,15 +65,15 @@ if ($user->societe_id > 0)
 llxHeader();
 
 
-$sql = "SELECT s.nom,s.idp, f.ref,".$db->pdate("f.datei")." as dp, f.rowid as fichid, f.fk_statut, f.note, f.duree";
+$sql = "SELECT s.nom,s.rowid as socid, f.ref,".$db->pdate("f.datei")." as dp, f.rowid as fichid, f.fk_statut, f.note, f.duree";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as f ";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql.= " WHERE f.fk_soc = s.idp ";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+$sql.= " WHERE f.fk_soc = s.rowid ";
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 if ($socid > 0)
 {
-	$sql .= " AND s.idp = " . $socid;
+	$sql .= " AND s.rowid = " . $socid;
 }
 $sql.= " ORDER BY $sortfield $sortorder ";
 $sql.= $db->plimit( $limit + 1 ,$offset);
@@ -105,8 +105,8 @@ if ($result)
         $objp = $db->fetch_object($result);
         $var=!$var;
         print "<tr $bc[$var]>";
-        print "<td><a href=\"fiche.php?id=$objp->fichid\">".img_object($langs->trans("Show"),"task").' '.$objp->ref."</a></td>\n";
-        print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44)."</a></td>\n";
+        print "<td><a href=\"fiche.php?id=".$objp->fichid."\">".img_object($langs->trans("Show"),"task").' '.$objp->ref."</a></td>\n";
+        print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44)."</a></td>\n";
         print '<td>'.nl2br($objp->note).'</td>';
         print '<td align="center">'.dolibarr_print_date($objp->dp)."</td>\n";
         print '<td align="right">'.price($objp->duree).'</td>';
diff --git a/htdocs/fichinter/rapport.php b/htdocs/fichinter/rapport.php
index 1566d5503ab..15ed581e3ab 100644
--- a/htdocs/fichinter/rapport.php
+++ b/htdocs/fichinter/rapport.php
@@ -52,14 +52,14 @@ $offset = $limit * $page ;
 $pageprev = $page - 1;
 $pagenext = $page + 1;
 
-$sql = "SELECT s.nom,s.idp, f.note, f.ref,".$db->pdate("f.datei")." as dp, f.rowid as fichid, f.fk_statut, f.duree";
+$sql = "SELECT s.nom,s.rowid as socid, f.note, f.ref,".$db->pdate("f.datei")." as dp, f.rowid as fichid, f.fk_statut, f.duree";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as f ";
-$sql .= " WHERE f.fk_soc = s.idp";
+$sql .= " WHERE f.fk_soc = s.rowid";
 
 
 if ($socid > 0)
 {
-  $sql .= " AND s.idp = " . $socid;
+  $sql .= " AND s.rowid = " . $socid;
 }
 
 if (empty ($MM))
@@ -120,8 +120,8 @@ if ( $db->query($sql) )
       {
 	if (!empty($MM))
 	  $filter="&MM=$MM&YY=$YY";
-        print '<td><a href="rapport.php?socid='.$objp->idp.$filter.'"><img src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/filter.png" border="0"></a>&nbsp;';
-        print "<a href=\"../comm/fiche.php?socid=$objp->idp$filter\">$objp->nom</a></TD>\n";
+        print '<td><a href="rapport.php?socid='.$objp->socid.$filter.'"><img src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/filter.png" border="0"></a>&nbsp;';
+        print "<a href=\"".DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->rowid.$filter."\">".$objp->nom."</a></TD>\n";
       }
       print '<td>'.nl2br($objp->note).'</td>';
       print "<td>".strftime("%d %B %Y",$objp->dp)."</td>\n";
diff --git a/htdocs/fourn/commande/index.php b/htdocs/fourn/commande/index.php
index 41fff09e712..c05632a6715 100644
--- a/htdocs/fourn/commande/index.php
+++ b/htdocs/fourn/commande/index.php
@@ -51,7 +51,7 @@ $sql = "SELECT count(cf.rowid), fk_statut,";
 $sql.= " cf.rowid,cf.ref";
 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,";
 $sql.= " ".MAIN_DB_PREFIX."commande_fournisseur as cf";
-$sql.= " WHERE cf.fk_soc = s.idp ";
+$sql.= " WHERE cf.fk_soc = s.rowid ";
 $sql.= " GROUP BY cf.fk_statut";
 
 $resql = $db->query($sql);
diff --git a/htdocs/fourn/commande/liste.php b/htdocs/fourn/commande/liste.php
index 02f9e9fc246..9c4cf478121 100644
--- a/htdocs/fourn/commande/liste.php
+++ b/htdocs/fourn/commande/liste.php
@@ -69,15 +69,15 @@ $offset = $conf->liste_limit * $page ;
  * Mode Liste
  */
 
-$sql = "SELECT s.idp, s.nom, ".$db->pdate("cf.date_commande")." as dc,";
+$sql = "SELECT s.rowid as socid, s.nom, ".$db->pdate("cf.date_commande")." as dc,";
 $sql .= " cf.rowid,cf.ref, cf.fk_statut";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,";
 $sql .= " ".MAIN_DB_PREFIX."commande_fournisseur as cf";
-$sql .= " WHERE cf.fk_soc = s.idp ";
+$sql .= " WHERE cf.fk_soc = s.rowid ";
 
 if ($socid)
 {
-    $sql .= " AND s.idp=".$socid;
+    $sql .= " AND s.rowid = ".$socid;
 }
 
 if (strlen($_GET["statut"]))
@@ -138,7 +138,7 @@ if ($resql)
         print '<td><a href="'.DOL_URL_ROOT.'/fourn/commande/fiche.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref.'</a></td>'."\n";
 
         // Soci�t�
-        print '<td><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' ';
+        print '<td><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' ';
         print $obj->nom.'</a></td>'."\n";
 
         // Date
diff --git a/htdocs/fourn/contact.php b/htdocs/fourn/contact.php
index 3c8ce3772d3..d6464d8a566 100644
--- a/htdocs/fourn/contact.php
+++ b/htdocs/fourn/contact.php
@@ -60,12 +60,12 @@ $offset = $limit * $page ;
  *
  */
 
-$sql = "SELECT s.idp, s.nom, st.libelle as stcomm, p.idp as cidp, p.name, p.firstname, p.email, p.phone";
+$sql = "SELECT s.rowid as socid, s.nom, st.libelle as stcomm, p.rowid as cidp, p.name, p.firstname, p.email, p.phone";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."socpeople as p, ".MAIN_DB_PREFIX."c_stcomm as st";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql .= " WHERE s.fk_stcomm = st.id AND s.fournisseur = 1 AND s.idp = p.fk_soc";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+$sql .= " WHERE s.fk_stcomm = st.id AND s.fournisseur = 1 AND s.rowid = p.fk_soc";
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 
 if (strlen($stcomm)) {
   $sql .= " AND s.fk_stcomm=$stcomm";
@@ -82,7 +82,7 @@ if ($contactname) {
 }
 
 if ($socid) {
-  $sql .= " AND s.idp = $socid";
+  $sql .= " AND s.rowid = ".$socid;
 }
 
 $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit( $limit, $offset);
@@ -113,7 +113,7 @@ if ($result) {
 
       print '<td><a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->cidp.'">'.img_object($langs->trans("ShowContact"),"contact").' '.$obj->name.'</a></td>';
       print '<td>'.$obj->firstname.'</td>';
-      print '<td><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
+      print '<td><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
       print '<td>'.$obj->email.'</td>';
       print '<td>'.$obj->phone.'</td>';
       
diff --git a/htdocs/fourn/facture/impayees.php b/htdocs/fourn/facture/impayees.php
index fc3805f6747..9cdb3ed50e2 100644
--- a/htdocs/fourn/facture/impayees.php
+++ b/htdocs/fourn/facture/impayees.php
@@ -73,7 +73,7 @@ if ($user->rights->fournisseur->facture->lire)
 	$limit = $conf->liste_limit;
 	$offset = $limit * $page ;
 
-	$sql = "SELECT s.nom, s.idp,";
+	$sql = "SELECT s.nom, s.rowid as socid,";
 	$sql.= " f.facnumber,f.total_ht,f.total_ttc,";
 	$sql.= $db->pdate("f.datef")." as df, ".$db->pdate("f.date_lim_reglement")." as datelimite, ";
 	$sql.= " f.paye as paye, f.rowid as facid, f.fk_statut";
@@ -83,10 +83,10 @@ if ($user->rights->fournisseur->facture->lire)
 	if (! $user->rights->commercial->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 	$sql.= ",".MAIN_DB_PREFIX."facture_fourn as f";
 	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf ON f.rowid=pf.fk_facturefourn ";
-	$sql.= " WHERE f.fk_soc = s.idp";
+	$sql.= " WHERE f.fk_soc = s.rowid";
 	$sql.= " AND f.paye = 0 AND f.fk_statut = 1";
-	if (! $user->rights->commercial->client->voir && ! $socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
-	if ($socid) $sql .= " AND s.idp = ".$socid;
+	if (! $user->rights->commercial->client->voir && ! $socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
+	if ($socid) $sql .= " AND s.rowid = ".$socid;
 
 	if ($_GET["filtre"])
 	{
@@ -206,7 +206,7 @@ if ($user->rights->fournisseur->facture->lire)
 				print "<td nowrap align=\"center\">".dolibarr_print_date($objp->df)."</td>\n";
 				print "<td nowrap align=\"center\">".dolibarr_print_date($objp->datelimite)."</td>\n";
 
-				print '<td><a href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,32).'</a></td>';
+				print '<td><a href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,32).'</a></td>';
 
 				print "<td align=\"right\">".price($objp->total_ht)."</td>";
 				print "<td align=\"right\">".price($objp->total_ttc)."</td>";
diff --git a/htdocs/fourn/facture/index.php b/htdocs/fourn/facture/index.php
index 691da68ee7d..483a16a2a50 100644
--- a/htdocs/fourn/facture/index.php
+++ b/htdocs/fourn/facture/index.php
@@ -64,7 +64,7 @@ if ($_POST["mode"] == 'search')
 {
   if ($_POST["mode-search"] == 'soc')
     {
-      $sql = "SELECT s.idp FROM ".MAIN_DB_PREFIX."societe as s ";
+      $sql = "SELECT s.rowid FROM ".MAIN_DB_PREFIX."societe as s ";
       $sql.= " WHERE s.nom like '%".addslashes(strtolower($socname))."%'";
     }
       
@@ -73,7 +73,7 @@ if ($_POST["mode"] == 'search')
       if ( $db->num_rows() == 1)
 	{
 	  $obj = $db->fetch_object();
-	  $socid = $obj->idp;
+	  $socid = $obj->rowid;
 	}
       $db->free();
     }
@@ -89,17 +89,17 @@ if ($_POST["mode"] == 'search')
  
 llxHeader();
 
-$sql = "SELECT s.idp as socid, s.nom, ";
+$sql = "SELECT s.rowid as socid, s.nom, ";
 $sql.= " ".$db->pdate("fac.datef")." as datef, ".$db->pdate("fac.date_lim_reglement")." as date_echeance,";
 $sql.= " fac.total_ht, fac.total_ttc, fac.paye as paye, fac.fk_statut as fk_statut, fac.libelle, fac.rowid as facid, fac.facnumber";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as fac";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql.= " WHERE fac.fk_soc = s.idp";
+$sql.= " WHERE fac.fk_soc = s.rowid";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
 if ($socid)
 {
-  $sql .= " AND s.idp = ".$socid;
+  $sql .= " AND s.rowid = ".$socid;
 }
 if ($_GET["filtre"])
   {
diff --git a/htdocs/fourn/facture/paiement.php b/htdocs/fourn/facture/paiement.php
index 7aac6e0a01c..2a7ac664bea 100644
--- a/htdocs/fourn/facture/paiement.php
+++ b/htdocs/fourn/facture/paiement.php
@@ -200,13 +200,13 @@ if ($action == 'create' || $action == 'add_paiement')
 	$facture = new FactureFournisseur($db);
 	$facture->fetch($facid);
 
-	$sql = 'SELECT s.nom,s.idp, f.amount, f.total_ttc as total, f.facnumber';
+	$sql = 'SELECT s.nom, s.rowid as socid, f.amount, f.total_ttc as total, f.facnumber';
 	if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
 	$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'facture_fourn as f';
 	if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-	$sql .= ' WHERE f.fk_soc = s.idp';
+	$sql .= ' WHERE f.fk_soc = s.rowid';
 	$sql .= ' AND f.rowid = '.$facid;
-	if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+	if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 	$resql = $db->query($sql);
 	if ($resql)
 	{
@@ -221,7 +221,7 @@ if ($action == 'create' || $action == 'add_paiement')
 			print '<input type="hidden" name="action" value="add_paiement">';
 			print '<input type="hidden" name="facid" value="'.$facid.'">';
 			print '<input type="hidden" name="facnumber" value="'.$obj->facnumber.'">';
-			print '<input type="hidden" name="socid" value="'.$obj->idp.'">';
+			print '<input type="hidden" name="socid" value="'.$obj->socid.'">';
 			print '<input type="hidden" name="societe" value="'.$obj->nom.'">';
 
 			print '<table class="border" width="100%">';
@@ -355,7 +355,7 @@ if (! $_GET['action'] && ! $_POST['action'])
 
 	$sql = 'SELECT p.rowid, '.$db->pdate('p.datep').' as dp, p.amount as pamount,';
 	$sql.= ' f.amount, f.facnumber, f.rowid as facid,';
-	$sql.= ' s.idp, s.nom,';
+	$sql.= ' s.rowid as socid, s.nom,';
 	$sql.= ' c.libelle as paiement_type, p.num_paiement,';
 	$sql.= ' ba.rowid as bid, ba.label';
 	if (!$user->rights->commercial->client->voir) $sql .= ", sc.fk_soc, sc.fk_user ";
@@ -364,10 +364,10 @@ if (! $_GET['action'] && ! $_POST['action'])
 	$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn AS pf ON p.rowid=pf.fk_paiementfourn';
 	$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn AS f ON f.rowid=pf.fk_facturefourn ';
 	$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement AS c ON p.fk_paiement = c.id';
-	$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON s.idp = f.fk_soc';
+	$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON s.rowid = f.fk_soc';
 	$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
 	$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
-	if (!$user->rights->commercial->client->voir) $sql .= " WHERE s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+	if (!$user->rights->commercial->client->voir) $sql .= " WHERE s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 	if ($socid)
 	{
 		$sql .= ' WHERE f.fk_soc = '.$socid;
@@ -406,7 +406,7 @@ if (! $_GET['action'] && ! $_POST['action'])
 			else print '&nbsp;';
 			print '</td>';
 			print '<td>';
-			if ($objp->idp) print '<a href="'.DOL_URL_ROOT.'/soc.php?socid='.$objp->idp.'">'.img_object($langs->trans('ShowCompany'),'company').' '.dolibarr_trunc($objp->nom,32).'</a>';
+			if ($objp->socid) print '<a href="'.DOL_URL_ROOT.'/soc.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'),'company').' '.dolibarr_trunc($objp->nom,32).'</a>';
 			else print '&nbsp;';
 			print '</td>';
 			print '<td nowrap="nowrap" align="center">'.dolibarr_print_date($objp->dp)."</td>\n";
diff --git a/htdocs/fourn/facture/paiementfourn.class.php b/htdocs/fourn/facture/paiementfourn.class.php
index edc1e3fbe31..0cc44bfcb95 100644
--- a/htdocs/fourn/facture/paiementfourn.class.php
+++ b/htdocs/fourn/facture/paiementfourn.class.php
@@ -343,7 +343,7 @@ class PaiementFourn
 			if ($num)
 			{
 				$obj = $this->db->fetch_object($resql);
-				$this->id = $obj->idp;
+				$this->id = $obj->rowid;
 				if ($obj->fk_user_creat)
 				{
 					$cuser = new User($this->db, $obj->fk_user_creat);
diff --git a/htdocs/fourn/fiche-stats.php b/htdocs/fourn/fiche-stats.php
index 6fbd4dcdcc5..30f07fa38c4 100644
--- a/htdocs/fourn/fiche-stats.php
+++ b/htdocs/fourn/fiche-stats.php
@@ -59,7 +59,7 @@ if (!$user->rights->commercial->client->voir && $socid && !$user->societe_id > 0
 {
   $sql = "SELECT sc.rowid";
   $sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."societe as s";
-  $sql .= " WHERE sc.fk_soc = ".$socid." AND sc.fk_soc = s.idp AND sc.fk_user = ".$user->id." AND s.fournisseur = 1";
+  $sql .= " WHERE sc.fk_soc = ".$socid." AND sc.fk_soc = s.rowid AND sc.fk_user = ".$user->id." AND s.fournisseur = 1";
   
   if ( $db->query($sql) )
     {
diff --git a/htdocs/fourn/fiche.php b/htdocs/fourn/fiche.php
index aae778bde75..f391f0cd85a 100644
--- a/htdocs/fourn/fiche.php
+++ b/htdocs/fourn/fiche.php
@@ -59,7 +59,7 @@ if (!$user->rights->commercial->client->voir && $socid && !$user->societe_id > 0
 {
   $sql = "SELECT sc.rowid";
   $sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."societe as s";
-  $sql .= " WHERE sc.fk_soc = ".$socid." AND sc.fk_soc = s.idp AND sc.fk_user = ".$user->id." AND s.fournisseur = 1";
+  $sql .= " WHERE sc.fk_soc = ".$socid." AND sc.fk_soc = s.rowid AND sc.fk_user = ".$user->id." AND s.fournisseur = 1";
   
   if ( $db->query($sql) )
     {
@@ -311,7 +311,7 @@ if ( $societe->fetch($socid) )
 	print '<td>&nbsp;</td>';
 	print "</tr>";
 
-	$sql = "SELECT p.idp, p.name, p.firstname, p.poste, p.phone, p.fax, p.email, p.note";
+	$sql = "SELECT p.rowid, p.name, p.firstname, p.poste, p.phone, p.fax, p.email, p.note";
 	$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as p";
 	$sql.= " WHERE p.fk_soc = ".$societe->id;
 	$sql.= "  ORDER by p.datec";
@@ -330,7 +330,7 @@ if ( $societe->fetch($socid) )
 		print "<tr $bc[$var]>";
 
 		print '<td>';
-		print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->idp.'">';
+		print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->rowid.'">';
 		print img_object($langs->trans("ShowContact"),"contact");
 		print ' '.$obj->firstname.' '. $obj->name.'</a>&nbsp;';
 
@@ -340,16 +340,16 @@ if ( $societe->fetch($socid) )
 		}
 		print "</td>";
 		print "<td>$obj->poste&nbsp;</td>";
-		print '<td><a href="../comm/action/fiche.php?action=create&actioncode=AC_TEL&contactid='.$obj->idp.'&socid='.$societe->id.'">'.$obj->phone.'</a>&nbsp;</td>';
-		print '<td><a href="../comm/action/fiche.php?action=create&actioncode=AC_FAX&contactid='.$obj->idp.'&socid='.$societe->id.'">'.$obj->fax.'</a>&nbsp;</td>';
-		print '<td><a href="../comm/action/fiche.php?action=create&actioncode=AC_EMAIL&contactid='.$obj->idp.'&socid='.$societe->id.'">'.$obj->email.'</a>&nbsp;</td>';
+		print '<td><a href="../comm/action/fiche.php?action=create&actioncode=AC_TEL&contactid='.$obj->rowid.'&socid='.$societe->id.'">'.$obj->phone.'</a>&nbsp;</td>';
+		print '<td><a href="../comm/action/fiche.php?action=create&actioncode=AC_FAX&contactid='.$obj->rowid.'&socid='.$societe->id.'">'.$obj->fax.'</a>&nbsp;</td>';
+		print '<td><a href="../comm/action/fiche.php?action=create&actioncode=AC_EMAIL&contactid='.$obj->rowid.'&socid='.$societe->id.'">'.$obj->email.'</a>&nbsp;</td>';
 
 		if ($user->rights->societe->contact->creer)
 		{
-			print "<td align=\"center\"><a href=\"../contact/fiche.php?action=edit&amp;id=$obj->idp\">".img_edit()."</a></td>";
+			print "<td align=\"center\"><a href=\"../contact/fiche.php?action=edit&amp;id=".$obj->rowid."\">".img_edit()."</a></td>";
 		}
 
-		print '<td align="center"><a href="../comm/action/fiche.php?action=create&actionid=5&contactid='.$obj->idp.'&socid='.$societe->id.'">';
+		print '<td align="center"><a href="../comm/action/fiche.php?action=create&actionid=5&contactid='.$obj->rowid.'&socid='.$societe->id.'">';
 		print img_object($langs->trans("Rendez-Vous"),"action");
 		print '</a></td>';
 
diff --git a/htdocs/fourn/fournisseur.class.php b/htdocs/fourn/fournisseur.class.php
index ebb10e13119..d11412df47a 100644
--- a/htdocs/fourn/fournisseur.class.php
+++ b/htdocs/fourn/fournisseur.class.php
@@ -188,12 +188,12 @@ class Fournisseur extends Societe
         
         $this->nb=array();
 
-        $sql = "SELECT count(s.idp) as nb, s.fournisseur";
+        $sql = "SELECT count(s.rowid) as nb, s.fournisseur";
         if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
         if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
         $sql.= " WHERE s.fournisseur = 1";
-        if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+        if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
         $sql.= " GROUP BY s.fournisseur";
         $resql=$this->db->query($sql);
         if ($resql)
diff --git a/htdocs/fourn/fournisseur.commande.class.php b/htdocs/fourn/fournisseur.commande.class.php
index e5f1320356c..089b0102854 100644
--- a/htdocs/fourn/fournisseur.commande.class.php
+++ b/htdocs/fourn/fournisseur.commande.class.php
@@ -1317,7 +1317,7 @@ class CommandeFournisseur extends Commande
 
 		// Charge tableau des id de soci�t� socids
 		$socids = array();
-		$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe WHERE fournisseur=1 LIMIT 10";
+		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE fournisseur=1 LIMIT 10";
 		$resql = $this->db->query($sql);
 		if ($resql)
 		{
diff --git a/htdocs/fourn/fournisseur.facture.class.php b/htdocs/fourn/fournisseur.facture.class.php
index 97a2335cdc0..8ab408a2d66 100644
--- a/htdocs/fourn/fournisseur.facture.class.php
+++ b/htdocs/fourn/fournisseur.facture.class.php
@@ -169,9 +169,9 @@ class FactureFournisseur extends Facture
 		$sql.= ' total_ht, total_tva, total_ttc, fk_user_author,';
 		$sql.= ' fk_statut, paye, f.note, f.note_public,';
 		$sql.= ' '.$this->db->pdate('date_lim_reglement').'as de,';
-		$sql.= ' s.nom as socnom, s.idp as socid';
+		$sql.= ' s.nom as socnom, s.rowid as socid';
 		$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f,'.MAIN_DB_PREFIX.'societe as s';
-		$sql.= ' WHERE f.rowid='.$rowid.' AND f.fk_soc = s.idp';
+		$sql.= ' WHERE f.rowid='.$rowid.' AND f.fk_soc = s.rowid';
 
 		dolibarr_syslog("FactureFourn::Fetch sql=".$sql, LOG_DEBUG);
 		$resql = $this->db->query($sql);
@@ -653,7 +653,7 @@ class FactureFournisseur extends Facture
 
 		// Charge tableau des id de soci�t� socids
 		$socids = array();
-		$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe WHERE fournisseur=1 LIMIT 10";
+		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE fournisseur=1 LIMIT 10";
 		$resql = $this->db->query($sql);
 		if ($resql)
 		{
diff --git a/htdocs/fourn/index.php b/htdocs/fourn/index.php
index 58b9b250e6d..9388f9102b8 100644
--- a/htdocs/fourn/index.php
+++ b/htdocs/fourn/index.php
@@ -115,7 +115,7 @@ $sql = "SELECT count(cf.rowid), fk_statut,";
 $sql.= " cf.rowid,cf.ref";
 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,";
 $sql.= " ".MAIN_DB_PREFIX."commande_fournisseur as cf";
-$sql.= " WHERE cf.fk_soc = s.idp ";
+$sql.= " WHERE cf.fk_soc = s.rowid ";
 $sql.= " GROUP BY cf.fk_statut";
 
 $resql = $db->query($sql);
@@ -158,9 +158,9 @@ else
 if ($conf->fournisseur->enabled)
 {
     $langs->load("orders");
-    $sql = "SELECT c.rowid, c.ref, c.total_ttc, s.nom, s.idp";
+    $sql = "SELECT c.rowid, c.ref, c.total_ttc, s.nom, s.rowid as socid";
     $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c, ".MAIN_DB_PREFIX."societe as s";
-    $sql.= " WHERE c.fk_soc = s.idp AND c.fk_statut = 0";
+    $sql.= " WHERE c.fk_soc = s.rowid AND c.fk_statut = 0";
     if ($socid)
     {
         $sql .= " AND c.fk_soc = ".$socid;
@@ -189,7 +189,7 @@ if ($conf->fournisseur->enabled)
 				print $commandestatic->getNomUrl(1,'',16);
 				print '</td>';
                 print '<td>';
-				$companystatic->id=$obj->idp;
+				$companystatic->id=$obj->socid;
 				$companystatic->nom=$obj->nom;
 				$companystatic->client=0;
 				print $companystatic->getNomUrl(1,'',16);
@@ -215,9 +215,9 @@ if ($conf->fournisseur->enabled)
 if ($conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire)
 {
 	$sql  = "SELECT f.facnumber, f.rowid, f.total_ttc, f.type,";
-	$sql.= " s.nom, s.idp";
+	$sql.= " s.nom, s.rowid as socid";
 	$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s";
-	$sql .= " WHERE s.idp = f.fk_soc AND f.fk_statut = 0";
+	$sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = 0";
 	if ($socid)
 	{
 		$sql .= " AND f.fk_soc = ".$socid;
@@ -247,7 +247,7 @@ if ($conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire)
 				print $facturestatic->getNomUrl(1,'');
 				print '</td>';
 				print '<td>';
-				$companystatic->id=$obj->idp;
+				$companystatic->id=$obj->rowid;
 				$companystatic->nom=$obj->nom;
 				$companystatic->client=0;
 				print $companystatic->getNomUrl(1,'',16);
@@ -284,14 +284,14 @@ print '<td valign="top" width="70%" class="notopnoleft">';
  * Liste des 10 derniers saisis
  *
  */
-$sql = "SELECT s.idp, s.nom, s.ville,".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea,  st.libelle as stcomm, s.prefix_comm";
+$sql = "SELECT s.rowid as socid, s.nom, s.ville,".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea,  st.libelle as stcomm, s.prefix_comm";
 $sql.= " , code_fournisseur, code_compta_fournisseur";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 $sql.= " WHERE s.fk_stcomm = st.id AND s.fournisseur=1";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
-if ($socid) $sql .= " AND s.idp=".$socid;
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
+if ($socid) $sql .= " AND s.rowid = ".$socid;
 
 $sql .= " ORDER BY s.datec DESC LIMIT 10; ";
 
@@ -315,8 +315,8 @@ if ($resql)
       $var=!$var;
 
       print "<tr $bc[$var]>";
-      print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowSupplier"),"company").'</a>';
-      print "&nbsp;<a href=\"fiche.php?socid=$obj->idp\">$obj->nom</a></td>\n";
+      print '<td><a href="fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowSupplier"),"company").'</a>';
+      print "&nbsp;<a href=\"fiche.php?socid=".$obj->socid."\">".$obj->nom."</a></td>\n";
       print '<td align="left">'.$obj->code_fournisseur.'&nbsp;</td>';
       print '<td align="right">'.dolibarr_print_date($obj->datec,'day').'</td>';
       print "</tr>\n";
diff --git a/htdocs/fourn/liste.php b/htdocs/fourn/liste.php
index 478a193eda3..4a0f465ff77 100644
--- a/htdocs/fourn/liste.php
+++ b/htdocs/fourn/liste.php
@@ -65,16 +65,16 @@ if (! $sortfield) $sortfield="nom";
  * Mode Liste
  *
  */
-$sql = "SELECT s.idp, s.nom, s.ville,".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea,  st.libelle as stcomm, s.prefix_comm";
+$sql = "SELECT s.rowid as socid, s.nom, s.ville,".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea,  st.libelle as stcomm, s.prefix_comm";
 $sql.= " , code_fournisseur, code_compta_fournisseur";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st";
 if ($_GET["cat"]) $sql .= ", ".MAIN_DB_PREFIX."categorie_fournisseur as cf";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 $sql.= " WHERE s.fk_stcomm = st.id AND s.fournisseur=1";
-if ($_GET["cat"]) $sql .= " AND cf.fk_societe=s.idp AND cf.fk_categorie='".$_GET["cat"]."'";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
-if ($socid) $sql .= " AND s.idp=".$socid;
+if ($_GET["cat"]) $sql .= " AND cf.fk_societe = s.rowid AND cf.fk_categorie='".$_GET["cat"]."'";
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
+if ($socid) $sql .= " AND s.rowid = ".$socid;
 if ($socname) {
   $sql .= " AND lower(s.nom) like '%".strtolower($socname)."%'";
   $sortfield = "lower(s.nom)";
@@ -137,8 +137,8 @@ if ($resql)
       $var=!$var;
 
       print "<tr $bc[$var]>";
-      print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowSupplier"),"company").'</a>';
-      print "&nbsp;<a href=\"fiche.php?socid=$obj->idp\">$obj->nom</a></td>\n";
+      print '<td><a href="fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowSupplier"),"company").'</a>';
+      print "&nbsp;<a href=\"fiche.php?socid=".$obj->socid."\">".$obj->nom."</a></td>\n";
       print "<td>".$obj->ville."</td>\n";       
       print '<td align="left">'.$obj->code_fournisseur.'&nbsp;</td>';
       print '<td align="left">'.$obj->code_compta_fournisseur.'&nbsp;</td>';
diff --git a/htdocs/fourn/paiement/fiche.php b/htdocs/fourn/paiement/fiche.php
index b86b3664567..d14077346d2 100644
--- a/htdocs/fourn/paiement/fiche.php
+++ b/htdocs/fourn/paiement/fiche.php
@@ -173,9 +173,9 @@ print '</table>';
  *	Liste des factures
  */
 $allow_delete = 1 ;
-$sql = 'SELECT f.facnumber, f.total_ttc, pf.amount, f.rowid as facid, f.paye, f.fk_statut, s.nom, s.idp';
+$sql = 'SELECT f.facnumber, f.total_ttc, pf.amount, f.rowid as facid, f.paye, f.fk_statut, s.nom, s.rowid as socid';
 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.'facture_fourn as f,'.MAIN_DB_PREFIX.'societe as s';
-$sql .= ' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.idp';
+$sql .= ' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
 $sql .= ' AND pf.fk_paiementfourn = '.$paiement->id;
 $resql=$db->query($sql);
 if ($resql)
@@ -207,7 +207,7 @@ if ($resql)
 			print $objp->facnumber;
 			print "</a></td>\n";
 			print '<td align="center">'.$facturestatic->LibStatut($objp->paye,$objp->fk_statut,2,1).'</td>';
-			print '<td><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.'</a></td>';
+			print '<td><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.'</a></td>';
 			print '<td align="right">'.price($objp->amount).'</td>';
 			print "</tr>\n";
 			if ($objp->paye == 1)
diff --git a/htdocs/fourn/product/fiche.php b/htdocs/fourn/product/fiche.php
index 769f86528db..07cff1f35f4 100644
--- a/htdocs/fourn/product/fiche.php
+++ b/htdocs/fourn/product/fiche.php
@@ -425,11 +425,11 @@ else
 	      print '<td align="center">'.$langs->trans("Quantity").'</td>';
 	      print '</tr>';
 
-	      $sql = "SELECT s.nom, s.idp, pf.ref_fourn, pfp.price, pfp.quantity";
+	      $sql = "SELECT s.nom, s.rowid as socid, pf.ref_fourn, pfp.price, pfp.quantity";
 	      $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur as pf";
-	      $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON s.idp = pfp.fk_soc";
+	      $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON s.rowid = pfp.fk_soc";
 	      $sql .= " AND pfp.fk_product =".$product->id; 
-	      $sql .= " WHERE pf.fk_soc = s.idp AND pf.fk_product = ".$product->id;
+	      $sql .= " WHERE pf.fk_soc = s.rowid AND pf.fk_product = ".$product->id;
 	      $sql .= " ORDER BY pfp.price ASC, lower(s.nom)";
 	      
 	      if ( $db->query($sql) )
@@ -442,11 +442,11 @@ else
 		      $objp = $db->fetch_object($resql);
 		      $var=!$var;
 		      print "<tr $bc[$var]>";
-		      print '<td><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$objp->idp.'">'.$objp->nom.'</a></td>';
+		      print '<td><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$objp->socid.'">'.$objp->nom.'</a></td>';
 		      print '<td>';
-		      print '<a href="fourn.php?id='.$product->id.'&amp;id_fourn='.$objp->idp.'">';
+		      print '<a href="fourn.php?id='.$product->id.'&amp;id_fourn='.$objp->socid.'">';
 		      print img_edit($langs->trans("Edit"));
-		      print '&nbsp;<a href="fourn.php?id='.$product->id.'&amp;id_fourn='.$objp->idp.'">';
+		      print '&nbsp;<a href="fourn.php?id='.$product->id.'&amp;id_fourn='.$objp->socid.'">';
 		      print $objp->ref_fourn.'</a></td>';
 
 		      print '<td align="right">';
@@ -476,7 +476,7 @@ else
 		  print '<table class="border" width="100%"><tr>';
 		  print '<td>'.$langs->trans("Suppliers").'</td><td><select name="id_fourn">';
 		  
-		  $sql = "SELECT s.idp, s.nom, s.ville";
+		  $sql = "SELECT s.rowid as socid, s.nom, s.ville";
 		  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s WHERE s.fournisseur=1";	     
 		  $sql .= " ORDER BY lower(s.nom)";
 		  
@@ -488,7 +488,7 @@ else
 		      while ($i < $num)
 			{
 			  $obj = $db->fetch_object($resql);
-			  print '<option value="'.$obj->idp.'">'.$obj->nom . ($obj->ville?" ($obj->ville)":"");
+			  print '<option value="'.$obj->socid.'">'.$obj->nom . ($obj->ville?" ($obj->ville)":"");
 			  $i++;
 			}
 		      $db->free($resql);
diff --git a/htdocs/fourn/product/liste.php b/htdocs/fourn/product/liste.php
index 9f20ac803df..d5cda255c33 100644
--- a/htdocs/fourn/product/liste.php
+++ b/htdocs/fourn/product/liste.php
@@ -84,7 +84,7 @@ if ($catid)
 	$sql .= ", ".MAIN_DB_PREFIX."categorie_product as cp";
 }
 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur as pf ON p.rowid = pf.fk_product";
-$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.idp = pf.fk_soc";
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = pf.fk_soc";
 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as ppf ON ppf.fk_soc = pf.fk_soc AND ppf.fk_product = p.rowid AND ppf.quantity = 1";
 
 if ($_POST["mode"] == 'search')
diff --git a/htdocs/fourn/recap-fourn.php b/htdocs/fourn/recap-fourn.php
index 1212e453241..332c8eff881 100644
--- a/htdocs/fourn/recap-fourn.php
+++ b/htdocs/fourn/recap-fourn.php
@@ -57,7 +57,7 @@ llxHeader();
 if ($socid > 0)
 {
     $societe = new Societe($db);
-    $societe->fetch($socid, $to);  // si $to='next' ajouter " AND s.idp > $socid ORDER BY idp ASC LIMIT 1";
+    $societe->fetch($socid, $to);  // si $to='next' ajouter " AND s.rowid > $socid ORDER BY idp ASC LIMIT 1";
 
     /*
      * Affichage onglets
diff --git a/htdocs/fourn/stats.php b/htdocs/fourn/stats.php
index 2c539869455..64687a1d816 100644
--- a/htdocs/fourn/stats.php
+++ b/htdocs/fourn/stats.php
@@ -70,16 +70,16 @@ $fourns=array();
 
 llxHeader();
 
-$sql = "SELECT s.idp, s.nom, s.ville, ca.ca_genere as ca, ca.year";
+$sql = "SELECT s.rowid as socid, s.nom, s.ville, ca.ca_genere as ca, ca.year";
 $sql.= " , code_fournisseur, code_compta_fournisseur";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st, ".MAIN_DB_PREFIX."fournisseur_ca as ca";
 if ($_GET["cat"]) $sql .= ", ".MAIN_DB_PREFIX."categorie_fournisseur as cf";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql.= " WHERE s.fk_stcomm = st.id AND s.fournisseur=1 AND s.idp = ca.fk_societe";
-if ($_GET["cat"]) $sql .= " AND cf.fk_societe=s.idp AND cf.fk_categorie='".$_GET["cat"]."'";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
-if ($socid) $sql .= " AND s.idp=".$socid;
+$sql.= " WHERE s.fk_stcomm = st.id AND s.fournisseur=1 AND s.rowid = ca.fk_societe";
+if ($_GET["cat"]) $sql .= " AND cf.fk_societe = s.rowid AND cf.fk_categorie = '".$_GET["cat"]."'";
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
+if ($socid) $sql .= " AND s.rowid = ".$socid;
 if ($socname) {
   $sql .= " AND lower(s.nom) like '%".strtolower($socname)."%'";
   $sortfield = "lower(s.nom)";
@@ -109,9 +109,9 @@ if ($resql)
       $var=!$var;
       $i++;
 
-      $fourns[$obj->idp] = $obj->nom;
+      $fourns[$obj->socid] = $obj->nom;
       $years[$obj->year] = $obj->year;
-      $ca[$obj->idp][$obj->year] = $obj->ca;
+      $ca[$obj->socid][$obj->year] = $obj->ca;
     }
 
 }
@@ -158,8 +158,8 @@ foreach($fourns as $fid => $fnom)
   $var=!$var;
   
   print "<tr $bc[$var]>";
-  print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowSupplier"),"company").'</a>';
-  print "&nbsp;<a href=\"fiche.php?socid=$fid\">$fnom</a></td>\n";
+  print '<td><a href="fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowSupplier"),"company").'</a>';
+  print "&nbsp;<a href=\"fiche.php?socid=".$fid."\">".$fnom."</a></td>\n";
   print "<td>".$obj->ville."</td>\n";       
   print '<td align="left">'.$obj->code_fournisseur.'&nbsp;</td>';
   
diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php
index c57615bc98a..bc6e9a7d00d 100644
--- a/htdocs/html.form.class.php
+++ b/htdocs/html.form.class.php
@@ -636,7 +636,7 @@ class Form
 	function select_societes($selected='',$htmlname='socid',$filter='',$showempty=0)
     {
         // On recherche les societes
-        $sql = "SELECT s.idp, s.nom FROM";
+        $sql = "SELECT s.rowid, s.nom FROM";
         $sql.= " ".MAIN_DB_PREFIX ."societe as s";
         if ($filter) $sql.= " WHERE $filter";
         $sql.= " ORDER BY nom ASC";
@@ -653,13 +653,13 @@ class Form
                 while ($i < $num)
                 {
                     $obj = $this->db->fetch_object($resql);
-                    if ($selected > 0 && $selected == $obj->idp)
+                    if ($selected > 0 && $selected == $obj->rowid)
                     {
-                        print '<option value="'.$obj->idp.'" selected="true">'.$obj->nom.'</option>';
+                        print '<option value="'.$obj->rowid.'" selected="true">'.$obj->nom.'</option>';
                     }
                     else
                     {
-                        print '<option value="'.$obj->idp.'">'.$obj->nom.'</option>';
+                        print '<option value="'.$obj->rowid.'">'.$obj->nom.'</option>';
                     }
                     $i++;
                 }
@@ -734,7 +734,7 @@ class Form
     function select_contacts($socid,$selected='',$htmlname='contactid',$showempty=0)
     {
 	        // On recherche les societes
-	        $sql = "SELECT s.idp, s.name, s.firstname FROM";
+	        $sql = "SELECT s.rowid, s.name, s.firstname FROM";
 	        $sql.= " ".MAIN_DB_PREFIX ."socpeople as s";
 	        $sql.= " WHERE fk_soc=".$socid;
 	        $sql.= " ORDER BY s.name ASC";
@@ -757,18 +757,18 @@ class Form
 
 			            if ($htmlname != 'none')
 			            {
-		                    if ($selected && $selected == $obj->idp)
+		                    if ($selected && $selected == $obj->rowid)
 		                    {
-		                        print '<option value="'.$obj->idp.'" selected="true">'.$obj->name.' '.$obj->firstname.'</option>';
+		                        print '<option value="'.$obj->rowid.'" selected="true">'.$obj->name.' '.$obj->firstname.'</option>';
 		                    }
 		                    else
 		                    {
-		                        print '<option value="'.$obj->idp.'">'.$obj->name.' '.$obj->firstname.'</option>';
+		                        print '<option value="'.$obj->rowid.'">'.$obj->name.' '.$obj->firstname.'</option>';
 		                    }
 						}
 						else
 						{
-							if ($selected == $obj->idp) print $obj->name.' '.$obj->firstname;
+							if ($selected == $obj->rowid) print $obj->name.' '.$obj->firstname;
 						}
 	                    $i++;
 	                }
diff --git a/htdocs/includes/boxes/box_actions.php b/htdocs/includes/boxes/box_actions.php
index 2b5be2e3625..3ea4c4d8947 100644
--- a/htdocs/includes/boxes/box_actions.php
+++ b/htdocs/includes/boxes/box_actions.php
@@ -73,18 +73,18 @@ class box_actions extends ModeleBoxes {
 		{
 			$sql = "SELECT a.id, a.label, ".$db->pdate("a.datep")." as dp , a.percent,";
 			$sql.= " ta.code,";
-			$sql.= " s.nom, s.idp";
+			$sql.= " s.nom, s.rowid as socid";
 			if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
 			$sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm AS ta, ";
 			if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux AS sc, ";
 			$sql.= MAIN_DB_PREFIX."actioncomm AS a";
-			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe AS s ON a.fk_soc = s.idp";
+			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe AS s ON a.fk_soc = s.rowid";
 			$sql.= " WHERE a.fk_action = ta.id";
 			$sql.= " AND a.percent <> 100";
-			if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+			if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 			if($user->societe_id)
 			{
-				$sql .= " AND s.idp = ".$user->societe_id;
+				$sql .= " AND s.rowid = ".$user->societe_id;
 			}
 			$sql.= " ORDER BY a.datec DESC";
 			$sql.= $db->plimit($max, 0);
@@ -113,7 +113,7 @@ class box_actions extends ModeleBoxes {
 	
 					$this->info_box_contents[$i][1] = array('align' => 'left',
 					'text' => dolibarr_trunc($objp->nom,20),
-					'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->idp);
+					'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->socid);
 	
 					$this->info_box_contents[$i][2] = array('align' => 'right',
 					'text' => dolibarr_print_date($objp->dp, "dayhour"));
diff --git a/htdocs/includes/boxes/box_clients.php b/htdocs/includes/boxes/box_clients.php
index e0dab25bcee..2b147c8a61d 100644
--- a/htdocs/includes/boxes/box_clients.php
+++ b/htdocs/includes/boxes/box_clients.php
@@ -67,15 +67,15 @@ class box_clients extends ModeleBoxes {
 
         if ($user->rights->societe->lire)
         {
-            $sql = "SELECT s.nom, s.idp, ".$db->pdate("s.datec")." as dc";
+            $sql = "SELECT s.nom, s.rowid as socid, ".$db->pdate("s.datec")." as dc";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
             $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
             $sql .= " WHERE s.client = 1";
-            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
             if ($user->societe_id > 0)
             {
-                $sql .= " AND s.idp = $user->societe_id";
+                $sql .= " AND s.rowid = $user->societe_id";
             }
             $sql .= " ORDER BY s.datec DESC ";
             $sql .= $db->plimit($max, 0);
@@ -95,7 +95,7 @@ class box_clients extends ModeleBoxes {
                     $this->info_box_contents[$i][0] = array('align' => 'left',
                     'logo' => $this->boximg,
                     'text' => stripslashes($objp->nom),
-                    'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->idp);
+                    'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->socid);
 
 					          $this->info_box_contents[$i][1] = array('align' => 'right',
 					          'text' => dolibarr_print_date($objp->dc, "day"));
diff --git a/htdocs/includes/boxes/box_commandes.php b/htdocs/includes/boxes/box_commandes.php
index 237a439a916..d6ffa24d329 100644
--- a/htdocs/includes/boxes/box_commandes.php
+++ b/htdocs/includes/boxes/box_commandes.php
@@ -70,17 +70,17 @@ class box_commandes extends ModeleBoxes {
         if ($user->rights->commande->lire)
         {
 
-            $sql = "SELECT s.nom, s.idp,";
+            $sql = "SELECT s.nom, s.rowid as socid,";
             $sql.= " p.ref, ".$db->pdate("p.date_commande")." as dp, p.rowid,";
             $sql.= " p.fk_statut, p.facture";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
             $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as p";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-            $sql .= " WHERE p.fk_soc = s.idp";
-            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+            $sql .= " WHERE p.fk_soc = s.rowid";
+            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
             if($user->societe_id)
             {
-                $sql .= " AND s.idp = $user->societe_id";
+                $sql .= " AND s.rowid = ".$user->societe_id;
             }
             $sql .= " ORDER BY p.date_commande DESC, p.ref DESC ";
             $sql .= $db->plimit($max, 0);
@@ -104,7 +104,7 @@ class box_commandes extends ModeleBoxes {
 
                     $this->info_box_contents[$i][1] = array('align' => 'left',
                     'text' => $objp->nom,
-                    'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->idp);
+                    'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->socid);
                     
                     $this->info_box_contents[$i][2] = array(
                     'align' => 'right',
diff --git a/htdocs/includes/boxes/box_factures.php b/htdocs/includes/boxes/box_factures.php
index f8cfde67baf..0f514686be1 100644
--- a/htdocs/includes/boxes/box_factures.php
+++ b/htdocs/includes/boxes/box_factures.php
@@ -73,15 +73,15 @@ class box_factures extends ModeleBoxes {
         {
             $sql = "SELECT f.rowid as facid, f.facnumber, f.type, f.amount, ".$db->pdate("f.datef")." as df,";
             $sql.= " f.paye, f.fk_statut,";
-            $sql.= " s.nom, s.idp";
+            $sql.= " s.nom, s.rowid as socid";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
             $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-            $sql.= " WHERE f.fk_soc = s.idp";
-            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+            $sql.= " WHERE f.fk_soc = s.rowid";
+            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
             if($user->societe_id)
             {
-                $sql.= " AND s.idp = $user->societe_id";
+                $sql.= " AND s.rowid = ".$user->societe_id;
             }
             $sql.= " ORDER BY f.datef DESC, f.facnumber DESC ";
             $sql.= $db->plimit($max, 0);
@@ -110,7 +110,7 @@ class box_factures extends ModeleBoxes {
                     $this->info_box_contents[$i][1] = array('align' => 'left',
                     'text' => $objp->nom,
                     'maxlength'=>44,
-                    'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->idp);
+                    'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->socid);
 
                     $this->info_box_contents[$i][2] = array(
                     'align' => 'right',
diff --git a/htdocs/includes/boxes/box_factures_fourn.php b/htdocs/includes/boxes/box_factures_fourn.php
index 1ee4b85b088..c29e822f8fc 100644
--- a/htdocs/includes/boxes/box_factures_fourn.php
+++ b/htdocs/includes/boxes/box_factures_fourn.php
@@ -72,17 +72,17 @@ class box_factures_fourn extends ModeleBoxes {
 
         if ($user->rights->fournisseur->facture->lire)
         {
-            $sql = "SELECT s.nom, s.idp,";
+            $sql = "SELECT s.nom, s.rowid as socid,";
             $sql.= " f.facnumber, f.amount,".$db->pdate("f.datef")." as df,";
             $sql.= " f.paye, f.fk_statut, f.rowid as facid";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
             $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-            $sql .= " WHERE f.fk_soc = s.idp";
-            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+            $sql .= " WHERE f.fk_soc = s.rowid";
+            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
             if($user->societe_id)
             {
-                $sql .= " AND s.idp = $user->societe_id";
+                $sql .= " AND s.rowid = ".$user->societe_id;
             }
             $sql .= " ORDER BY f.datef DESC, f.facnumber DESC ";
             $sql .= $db->plimit($max, 0);
@@ -106,7 +106,7 @@ class box_factures_fourn extends ModeleBoxes {
 
                     $this->info_box_contents[$i][1] = array('align' => 'left',
                     'text' => $objp->nom,
-                    'url' => DOL_URL_ROOT."/fourn/fiche.php?socid=".$objp->idp);
+                    'url' => DOL_URL_ROOT."/fourn/fiche.php?socid=".$objp->socid);
 
                     $this->info_box_contents[$i][2] = array(
                     'align' => 'right',
diff --git a/htdocs/includes/boxes/box_factures_fourn_imp.php b/htdocs/includes/boxes/box_factures_fourn_imp.php
index cc734659fac..1eda115c410 100644
--- a/htdocs/includes/boxes/box_factures_fourn_imp.php
+++ b/htdocs/includes/boxes/box_factures_fourn_imp.php
@@ -70,18 +70,18 @@ class box_factures_fourn_imp extends ModeleBoxes {
         if ($user->rights->fournisseur->facture->lire)
         {
 
-            $sql = "SELECT s.nom, s.idp,";
+            $sql = "SELECT s.nom, s.rowid as socid,";
             $sql.= " f.facnumber,".$db->pdate("f.date_lim_reglement")." as datelimite,";
 			$sql.= " f.amount,".$db->pdate("f.datef")." as df,";
             $sql.= " f.paye, f.fk_statut, f.rowid as facid";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
             $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-            $sql .= " WHERE f.fk_soc = s.idp AND f.paye=0 AND fk_statut = 1";
-            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+            $sql .= " WHERE f.fk_soc = s.rowid AND f.paye=0 AND fk_statut = 1";
+            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
             if($user->societe_id)
             {
-                $sql .= " AND s.idp = $user->societe_id";
+                $sql .= " AND s.rowid = ".$user->societe_id;
             }
             $sql .= " ORDER BY f.datef DESC, f.facnumber DESC ";
             $sql .= $db->plimit($max, 0);
@@ -108,7 +108,7 @@ class box_factures_fourn_imp extends ModeleBoxes {
 
                     $this->info_box_contents[$i][1] = array('align' => 'left',
                     'text' => $objp->nom,
-                    'url' => DOL_URL_ROOT."/fourn/fiche.php?socid=".$objp->idp);
+                    'url' => DOL_URL_ROOT."/fourn/fiche.php?socid=".$objp->socid);
 
                     $this->info_box_contents[$i][2] = array(
                     'align' => 'right',
diff --git a/htdocs/includes/boxes/box_factures_imp.php b/htdocs/includes/boxes/box_factures_imp.php
index e040f5d20a4..62dfcbc79c0 100644
--- a/htdocs/includes/boxes/box_factures_imp.php
+++ b/htdocs/includes/boxes/box_factures_imp.php
@@ -70,18 +70,18 @@ class box_factures_imp extends ModeleBoxes {
 
         if ($user->rights->facture->lire)
         {
-            $sql = "SELECT s.nom, s.idp,";
+            $sql = "SELECT s.nom, s.rowid as socid,";
             $sql.= " f.facnumber,".$db->pdate("f.date_lim_reglement")." as datelimite,";
             $sql.= " f.amount,".$db->pdate("f.datef")." as df,";
             $sql.= " f.paye, f.fk_statut, f.rowid as facid";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
             $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-            $sql .= " WHERE f.fk_soc = s.idp AND f.paye=0 AND fk_statut = 1";
+            $sql .= " WHERE f.fk_soc = s.rowid AND f.paye=0 AND fk_statut = 1";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
             if($user->societe_id)
             {
-                $sql .= " AND s.idp = $user->societe_id";
+                $sql .= " AND s.rowid = ".$user->societe_id;
             }
             //$sql .= " ORDER BY f.datef DESC, f.facnumber DESC ";
             $sql .= " ORDER BY f.datef ASC, f.facnumber ASC ";
@@ -110,7 +110,7 @@ class box_factures_imp extends ModeleBoxes {
                     $this->info_box_contents[$i][1] = array('align' => 'left',
                     'text' => $objp->nom,
                     'maxlength'=>44,
-                    'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->idp);
+                    'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->socid);
 
                     $this->info_box_contents[$i][2] = array(
                     'align' => 'right',
diff --git a/htdocs/includes/boxes/box_fournisseurs.php b/htdocs/includes/boxes/box_fournisseurs.php
index db51080f187..6097cd5528b 100644
--- a/htdocs/includes/boxes/box_fournisseurs.php
+++ b/htdocs/includes/boxes/box_fournisseurs.php
@@ -66,15 +66,15 @@ class box_fournisseurs extends ModeleBoxes {
 
         if ($user->rights->societe->lire)
         {
-            $sql = "SELECT s.nom, s.idp, ".$db->pdate("s.datec")." as dc";
+            $sql = "SELECT s.nom, s.rowid as socid, ".$db->pdate("s.datec")." as dc";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
             $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
             $sql .= " WHERE s.fournisseur = 1";
-            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
             if ($user->societe_id > 0)
             {
-                $sql .= " AND s.idp = $user->societe_id";
+                $sql .= " AND s.rowid = ".$user->societe_id;
             }
             $sql .= " ORDER BY s.datec DESC ";
             $sql .= $db->plimit($max, 0);
@@ -94,7 +94,7 @@ class box_fournisseurs extends ModeleBoxes {
                     $this->info_box_contents[$i][0] = array('align' => 'left',
                     'logo' => $this->boximg,
                     'text' => $objp->nom,
-                    'url' => DOL_URL_ROOT."/fourn/fiche.php?socid=".$objp->idp);
+                    'url' => DOL_URL_ROOT."/fourn/fiche.php?socid=".$objp->socid);
 
 					$this->info_box_contents[$i][1] = array('align' => 'right',
 					'text' => dolibarr_print_date($objp->dc, "day"));
diff --git a/htdocs/includes/boxes/box_propales.php b/htdocs/includes/boxes/box_propales.php
index 1f7d3f82644..b6a2a9f3621 100644
--- a/htdocs/includes/boxes/box_propales.php
+++ b/htdocs/includes/boxes/box_propales.php
@@ -72,16 +72,16 @@ class box_propales extends ModeleBoxes {
         if ($user->rights->propale->lire)
         {
 
-            $sql = "SELECT s.nom, s.idp,";
+            $sql = "SELECT s.nom, s.rowid as socid,";
             $sql.= " p.ref, p.fk_statut, ".$db->pdate("p.datep")." as dp, p.rowid";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
             $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."propal as p";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-            $sql .= " WHERE p.fk_soc = s.idp";
-            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+            $sql .= " WHERE p.fk_soc = s.rowid";
+            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
             if($user->societe_id)
             {
-                $sql .= " AND s.idp = $user->societe_id";
+                $sql .= " AND s.rowid = ".$user->societe_id;
             }
             $sql .= " ORDER BY p.datep DESC, p.ref DESC ";
             $sql .= $db->plimit($max, 0);
@@ -105,7 +105,7 @@ class box_propales extends ModeleBoxes {
 
                     $this->info_box_contents[$i][1] = array('align' => 'left',
                     'text' => dolibarr_trunc($objp->nom,40),
-                    'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->idp);
+                    'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->socid);
                     
                     $this->info_box_contents[$i][2] = array(
                     'align' => 'right',
diff --git a/htdocs/includes/boxes/box_prospect.php b/htdocs/includes/boxes/box_prospect.php
index da712309f73..eb7a47e1f60 100644
--- a/htdocs/includes/boxes/box_prospect.php
+++ b/htdocs/includes/boxes/box_prospect.php
@@ -69,15 +69,15 @@ class box_prospect extends ModeleBoxes {
 
         if ($user->rights->societe->lire) 
         {
-            $sql = "SELECT s.nom, s.idp, s.fk_stcomm, ".$db->pdate("s.datec")." as dc";
+            $sql = "SELECT s.nom, s.rowid as socid, s.fk_stcomm, ".$db->pdate("s.datec")." as dc";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
             $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
             $sql .= " WHERE s.client = 2";
-            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
             if ($user->societe_id > 0)
             {
-                $sql .= " AND s.idp = $user->societe_id";
+                $sql .= " AND s.rowid = ".$user->societe_id;
             }
             $sql .= " ORDER BY s.datec DESC ";
             $sql .= $db->plimit($max, 0);
@@ -97,7 +97,7 @@ class box_prospect extends ModeleBoxes {
                     $this->info_box_contents[$i][0] = array('align' => 'left',
                     'logo' => $this->boximg,
                     'text' => stripslashes($objp->nom),
-                    'url' => DOL_URL_ROOT."/comm/prospect/fiche.php?id=".$objp->idp);
+                    'url' => DOL_URL_ROOT."/comm/prospect/fiche.php?id=".$objp->socid);
 
 					$this->info_box_contents[$i][1] = array('align' => 'ce,ter',
 					'text' => dolibarr_print_date($objp->dc, "day"));
diff --git a/htdocs/includes/boxes/box_services_vendus.php b/htdocs/includes/boxes/box_services_vendus.php
index ed6963b9fc4..2819d857be5 100644
--- a/htdocs/includes/boxes/box_services_vendus.php
+++ b/htdocs/includes/boxes/box_services_vendus.php
@@ -67,7 +67,7 @@ class box_services_vendus extends ModeleBoxes {
 
         if ($user->rights->produit->lire && $user->rights->contrat->lire)
         {
-            $sql  = "SELECT s.nom, s.idp, c.rowid, cd.rowid as cdid, p.rowid as pid, p.label, p.fk_product_type";
+            $sql  = "SELECT s.nom, s.rowid as socid, c.rowid, cd.rowid as cdid, p.rowid as pid, p.label, p.fk_product_type";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
             $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."product as p";
             if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
@@ -76,15 +76,15 @@ class box_services_vendus extends ModeleBoxes {
 	           $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
 	           $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as ca ON cp.fk_categorie = ca.rowid";
 	        }
-            $sql .= " WHERE s.idp = c.fk_soc AND c.rowid = cd.fk_contrat AND cd.fk_product = p.rowid";
-            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+            $sql .= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND cd.fk_product = p.rowid";
+            if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
             if ($conf->categorie->enabled && !$user->rights->categorie->voir)
             {
 				$sql.= ' AND IFNULL(ca.visible,1)=1';
             }
             if($user->societe_id)
             {
-                $sql .= " AND s.idp = $user->societe_id";
+                $sql .= " AND s.rowid = ".$user->societe_id;
             }
             $sql .= " ORDER BY c.tms DESC ";
             $sql .= $db->plimit($max, 0);
@@ -125,7 +125,7 @@ class box_services_vendus extends ModeleBoxes {
                     $this->info_box_contents[$i][1] = array('align' => 'left',
                     'text' => $objp->nom,
                     'maxlength' => 40,
-                    'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->idp);
+                    'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->socid);
     
                     $i++;
                 }
diff --git a/htdocs/includes/modules/mailings/poire.modules.php b/htdocs/includes/modules/mailings/poire.modules.php
index 4e7f9dd74b6..f71ef5fd572 100644
--- a/htdocs/includes/modules/mailings/poire.modules.php
+++ b/htdocs/includes/modules/mailings/poire.modules.php
@@ -73,7 +73,7 @@ class mailing_poire extends MailingTargets
         $langs->load("commercial");
 
 	    $statssql=array();
-        $statssql[0]="SELECT '".$langs->trans("NbOfCompaniesContacts")."' as label, count(distinct(c.email)) as nb FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."societe as s WHERE s.idp = c.fk_soc AND s.client = 1 AND c.email != ''";
+        $statssql[0]="SELECT '".$langs->trans("NbOfCompaniesContacts")."' as label, count(distinct(c.email)) as nb FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."societe as s WHERE s.rowid = c.fk_soc AND s.client = 1 AND c.email != ''";
 
 		return $statssql;
 	}
@@ -90,7 +90,7 @@ class mailing_poire extends MailingTargets
         $sql  = "SELECT count(distinct(c.email)) as nb";
         $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
         $sql .= ", ".MAIN_DB_PREFIX."societe as s";
-        $sql .= " WHERE s.idp = c.fk_soc";
+        $sql .= " WHERE s.rowid = c.fk_soc";
         $sql .= " AND c.email != ''";
 
         // La requete doit retourner un champ "nb" pour etre comprise
@@ -144,10 +144,10 @@ class mailing_poire extends MailingTargets
         $cibles = array();
 
         // La requete doit retourner: id, email, fk_contact, name, firstname
-        $sql = "SELECT c.idp as id, c.email as email, c.idp as fk_contact, c.name as name, c.firstname as firstname";
+        $sql = "SELECT c.rowid as id, c.email as email, c.rowid as fk_contact, c.name as name, c.firstname as firstname";
         $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
         $sql .= ", ".MAIN_DB_PREFIX."societe as s";
-        $sql .= " WHERE s.idp = c.fk_soc";
+        $sql .= " WHERE s.rowid = c.fk_soc";
         $sql .= " AND c.email != ''";
         foreach($filtersarray as $key)
         {
diff --git a/htdocs/includes/modules/modCommande.class.php b/htdocs/includes/modules/modCommande.class.php
index 9b77b2e0606..4b054117f62 100644
--- a/htdocs/includes/modules/modCommande.class.php
+++ b/htdocs/includes/modules/modCommande.class.php
@@ -163,9 +163,9 @@ class modCommande extends DolibarrModules
         $r++;
         $this->export_code[$r]=$this->id.'_'.$r;
         $this->export_label[$r]='Commandes clients et lignes de commande';
-        $this->export_fields_array[$r]=array('s.idp'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.cp'=>'Zip','s.ville'=>'Town','s.fk_pays'=>'Country','s.tel'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','c.rowid'=>"Id",'c.ref'=>"Ref",'c.ref_client'=>"RefClient",'c.fk_soc'=>"IdCompany",'c.date_creation'=>"DateCreation",'c.date_commande'=>"DateOrder",'c.amount_ht'=>"Amount",'c.remise_percent'=>"GlobalDiscount",'c.total_ht'=>"TotalHT",'c.total_ttc'=>"TotalTTC",'c.facture'=>"OrderShortStatusInvoicee",'c.fk_statut'=>'Status','c.note'=>"Note",'c.date_livraison'=>'DateDelivery','p.ref'=>'RefProduct','p.label'=>'Label','cd.rowid'=>'LineId','cd.description'=>"LineDescription",'cd.total_ht'=>"LineTotalHT",'cd.tva_tx'=>"LineVATRate",'cd.qty'=>"LineQty");
-        $this->export_entities_array[$r]=array('s.idp'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','s.fk_pays'=>'company','s.tel'=>'company','s.siren'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.siret'=>'company','c.rowid'=>"order",'c.ref'=>"order",'c.ref_client'=>"order",'c.fk_soc'=>"order",'c.date_creation'=>"order",'c.date_commande'=>"order",'c.amount_ht'=>"order",'c.remise_percent'=>"order",'c.total_ht'=>"order",'c.total_ttc'=>"order",'c.facture'=>"order",'c.fk_statut'=>'order','c.note'=>"order",'c.date_livraison'=>"order",'p.ref'=>'product','p.label'=>'product','cd.rowid'=>'order_line','cd.description'=>"order_line",'cd.total_ht'=>"order_line",'cd.tva_tx'=>"order_line",'cd.qty'=>"order_line");
-        $this->export_alias_array[$r]=array('s.idp'=>"socid",'s.nom'=>'soc_name','s.address'=>'soc_adres','s.cp'=>'soc_zip','s.ville'=>'soc_ville','s.fk_pays'=>'soc_pays','s.tel'=>'soc_tel','s.siren'=>'soc_siren','s.siret'=>'soc_siret','s.ape'=>'soc_ape','s.idprof4'=>'soc_idprof4','c.rowid'=>"orderid",'c.ref'=>"ref",'c.ref_client'=>"refclient",'c.fk_soc'=>"fk_soc",'c.date_creation'=>"datecreation",'c.date_commande'=>"dateorder",'c.amount_ht'=>"amount",'c.remise_percent'=>"globaldiscount",'c.total_ht'=>"totalht",'c.total_ttc'=>"totalttc",'c.facture'=>"invoicee",'c.fk_statut'=>'status','c.note'=>"note",'c.date_livraison'=>'datedelivery','p.ref'=>'refproduct','p.label'=>'label','cd.rowid'=>'lineid','cd.description'=>"linedescription",'cd.total_ht'=>"linetotalht",'cd.tva_tx'=>"linevatrate",'cd.qty'=>"lineqty");
+        $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.cp'=>'Zip','s.ville'=>'Town','s.fk_pays'=>'Country','s.tel'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','c.rowid'=>"Id",'c.ref'=>"Ref",'c.ref_client'=>"RefClient",'c.fk_soc'=>"IdCompany",'c.date_creation'=>"DateCreation",'c.date_commande'=>"DateOrder",'c.amount_ht'=>"Amount",'c.remise_percent'=>"GlobalDiscount",'c.total_ht'=>"TotalHT",'c.total_ttc'=>"TotalTTC",'c.facture'=>"OrderShortStatusInvoicee",'c.fk_statut'=>'Status','c.note'=>"Note",'c.date_livraison'=>'DateDelivery','p.ref'=>'RefProduct','p.label'=>'Label','cd.rowid'=>'LineId','cd.description'=>"LineDescription",'cd.total_ht'=>"LineTotalHT",'cd.tva_tx'=>"LineVATRate",'cd.qty'=>"LineQty");
+        $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','s.fk_pays'=>'company','s.tel'=>'company','s.siren'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.siret'=>'company','c.rowid'=>"order",'c.ref'=>"order",'c.ref_client'=>"order",'c.fk_soc'=>"order",'c.date_creation'=>"order",'c.date_commande'=>"order",'c.amount_ht'=>"order",'c.remise_percent'=>"order",'c.total_ht'=>"order",'c.total_ttc'=>"order",'c.facture'=>"order",'c.fk_statut'=>'order','c.note'=>"order",'c.date_livraison'=>"order",'p.ref'=>'product','p.label'=>'product','cd.rowid'=>'order_line','cd.description'=>"order_line",'cd.total_ht'=>"order_line",'cd.tva_tx'=>"order_line",'cd.qty'=>"order_line");
+        $this->export_alias_array[$r]=array('s.rowid'=>"socid",'s.nom'=>'soc_name','s.address'=>'soc_adres','s.cp'=>'soc_zip','s.ville'=>'soc_ville','s.fk_pays'=>'soc_pays','s.tel'=>'soc_tel','s.siren'=>'soc_siren','s.siret'=>'soc_siret','s.ape'=>'soc_ape','s.idprof4'=>'soc_idprof4','c.rowid'=>"orderid",'c.ref'=>"ref",'c.ref_client'=>"refclient",'c.fk_soc'=>"fk_soc",'c.date_creation'=>"datecreation",'c.date_commande'=>"dateorder",'c.amount_ht'=>"amount",'c.remise_percent'=>"globaldiscount",'c.total_ht'=>"totalht",'c.total_ttc'=>"totalttc",'c.facture'=>"invoicee",'c.fk_statut'=>'status','c.note'=>"note",'c.date_livraison'=>'datedelivery','p.ref'=>'refproduct','p.label'=>'label','cd.rowid'=>'lineid','cd.description'=>"linedescription",'cd.total_ht'=>"linetotalht",'cd.tva_tx'=>"linevatrate",'cd.qty'=>"lineqty");
         $this->export_sql[$r]="select distinct ";
         $i=0;
         foreach ($this->export_alias_array[$r] as $key => $value)
@@ -174,7 +174,7 @@ class modCommande extends DolibarrModules
             else $i++;
             $this->export_sql[$r].=$key.' as '.$value;
         }
-        $this->export_sql[$r].=' from '.MAIN_DB_PREFIX.'commande as c, '.MAIN_DB_PREFIX.'commandedet as cd, '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'product as p WHERE c.fk_soc = s.idp AND c.rowid = cd.fk_commande AND cd.fk_product = p.rowid';
+        $this->export_sql[$r].=' from '.MAIN_DB_PREFIX.'commande as c, '.MAIN_DB_PREFIX.'commandedet as cd, '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'product as p WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_commande AND cd.fk_product = p.rowid';
         $this->export_permission[$r]=array(array("commande","commande","export"));
 
   }
diff --git a/htdocs/includes/modules/modFacture.class.php b/htdocs/includes/modules/modFacture.class.php
index fe4e150d573..c1a98352456 100644
--- a/htdocs/includes/modules/modFacture.class.php
+++ b/htdocs/includes/modules/modFacture.class.php
@@ -177,9 +177,9 @@ class modFacture extends DolibarrModules
         $r++;
         $this->export_code[$r]=$this->id.'_'.$r;
         $this->export_label[$r]='Factures clients et lignes de facture';
-        $this->export_fields_array[$r]=array('s.idp'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.cp'=>'Zip','s.ville'=>'Town','s.fk_pays'=>'Country','s.tel'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','f.rowid'=>"Id",'f.facnumber'=>"Ref",'f.datec'=>"DateCreation",'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"BillShortStatusPayed",'f.fk_statut'=>'Status','f.note'=>"Note",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LinePrice",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.tva_taux'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.date_start'=>"DateStart",'fd.date_end'=>"DateEnd");
-		$this->export_entities_array[$r]=array('s.idp'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','s.fk_pays'=>'company','s.tel'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_taux'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line");
-        $this->export_alias_array[$r]=array('s.idp'=>"socid",'s.nom'=>'soc_name','s.address'=>'soc_adres','s.cp'=>'soc_zip','s.ville'=>'soc_ville','s.fk_pays'=>'soc_pays','s.tel'=>'soc_tel','s.siren'=>'soc_siren','s.siret'=>'soc_siret','s.ape'=>'soc_ape','s.idprof4'=>'soc_idprof4','f.rowid'=>"invoiceid",'f.facnumber'=>"ref",'f.datec'=>"datecreation",'f.datef'=>"dateinvoice",'f.total'=>"totalht",'f.total_ttc'=>"totalttc",'f.tva'=>"totalvat",'f.paye'=>"paid",'f.fk_statut'=>'status','f.note'=>"note",'fd.rowid'=>'lineid','fd.description'=>"linedescription",'fd.price'=>"lineprice",'fd.total_ht'=>"linetotalht",'fd.total_tva'=>"linetotaltva",'fd.total_ttc'=>"linetotalttc",'fd.tva_taux'=>"linevatrate",'fd.qty'=>"lineqty",'fd.date_start'=>"linedatestart",'fd.date_end'=>"linedateend");
+        $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.cp'=>'Zip','s.ville'=>'Town','s.fk_pays'=>'Country','s.tel'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','f.rowid'=>"Id",'f.facnumber'=>"Ref",'f.datec'=>"DateCreation",'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"BillShortStatusPayed",'f.fk_statut'=>'Status','f.note'=>"Note",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LinePrice",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.tva_taux'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.date_start'=>"DateStart",'fd.date_end'=>"DateEnd");
+		$this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','s.fk_pays'=>'company','s.tel'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_taux'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line");
+        $this->export_alias_array[$r]=array('s.rowid'=>"socid",'s.nom'=>'soc_name','s.address'=>'soc_adres','s.cp'=>'soc_zip','s.ville'=>'soc_ville','s.fk_pays'=>'soc_pays','s.tel'=>'soc_tel','s.siren'=>'soc_siren','s.siret'=>'soc_siret','s.ape'=>'soc_ape','s.idprof4'=>'soc_idprof4','f.rowid'=>"invoiceid",'f.facnumber'=>"ref",'f.datec'=>"datecreation",'f.datef'=>"dateinvoice",'f.total'=>"totalht",'f.total_ttc'=>"totalttc",'f.tva'=>"totalvat",'f.paye'=>"paid",'f.fk_statut'=>'status','f.note'=>"note",'fd.rowid'=>'lineid','fd.description'=>"linedescription",'fd.price'=>"lineprice",'fd.total_ht'=>"linetotalht",'fd.total_tva'=>"linetotaltva",'fd.total_ttc'=>"linetotalttc",'fd.tva_taux'=>"linevatrate",'fd.qty'=>"lineqty",'fd.date_start'=>"linedatestart",'fd.date_end'=>"linedateend");
         $this->export_sql[$r]="select distinct ";
         $i=0;
         foreach ($this->export_alias_array[$r] as $key => $value)
@@ -188,15 +188,15 @@ class modFacture extends DolibarrModules
             else $i++;
             $this->export_sql[$r].=$key.' as '.$value;
         }
-        $this->export_sql[$r].=' from '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s WHERE f.fk_soc = s.idp AND f.rowid = fd.fk_facture';
+        $this->export_sql[$r].=' from '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
         $this->export_permission[$r]=array(array("facture","facture","export"));
 
         $r++;
         $this->export_code[$r]=$this->id.'_'.$r;
         $this->export_label[$r]='Factures clients et r�glements';
-        $this->export_fields_array[$r]=array('s.idp'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.cp'=>'Zip','s.ville'=>'Town','s.fk_pays'=>'Country','s.tel'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','f.rowid'=>"Id",'f.facnumber'=>"Ref",'f.datec'=>"DateCreation",'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"BillShortStatusPayed",'f.fk_statut'=>'Status','f.note'=>"Note",'pf.amount'=>'AmountPayment','p.datep'=>'DatePayment','p.num_paiement'=>'Numero');
-		$this->export_entities_array[$r]=array('s.idp'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','s.fk_pays'=>'company','s.tel'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'pf.amount'=>'payment','p.datep'=>'payment','p.num_paiement'=>'payment');
-        $this->export_alias_array[$r]=array('s.idp'=>"socid",'s.nom'=>'soc_name','s.address'=>'soc_adres','s.cp'=>'soc_zip','s.ville'=>'soc_ville','s.fk_pays'=>'soc_pays','s.tel'=>'soc_tel','s.siren'=>'soc_siren','s.siret'=>'soc_siret','s.ape'=>'soc_ape','s.idprof4'=>'soc_idprof4','f.rowid'=>"invoiceid",'f.facnumber'=>"ref",'f.datec'=>"datecreation",'f.datef'=>"dateinvoice",'f.total'=>"totalht",'f.total_ttc'=>"totalttc",'f.tva'=>"totalvat",'f.paye'=>"paid",'f.fk_statut'=>'status','f.note'=>"note",'pf.amount'=>'amount_payment','p.datep'=>'date_payment','p.num_paiement'=>'num_payment');
+        $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.cp'=>'Zip','s.ville'=>'Town','s.fk_pays'=>'Country','s.tel'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','f.rowid'=>"Id",'f.facnumber'=>"Ref",'f.datec'=>"DateCreation",'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"BillShortStatusPayed",'f.fk_statut'=>'Status','f.note'=>"Note",'pf.amount'=>'AmountPayment','p.datep'=>'DatePayment','p.num_paiement'=>'Numero');
+		$this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','s.fk_pays'=>'company','s.tel'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'pf.amount'=>'payment','p.datep'=>'payment','p.num_paiement'=>'payment');
+        $this->export_alias_array[$r]=array('s.rowid'=>"socid",'s.nom'=>'soc_name','s.address'=>'soc_adres','s.cp'=>'soc_zip','s.ville'=>'soc_ville','s.fk_pays'=>'soc_pays','s.tel'=>'soc_tel','s.siren'=>'soc_siren','s.siret'=>'soc_siret','s.ape'=>'soc_ape','s.idprof4'=>'soc_idprof4','f.rowid'=>"invoiceid",'f.facnumber'=>"ref",'f.datec'=>"datecreation",'f.datef'=>"dateinvoice",'f.total'=>"totalht",'f.total_ttc'=>"totalttc",'f.tva'=>"totalvat",'f.paye'=>"paid",'f.fk_statut'=>'status','f.note'=>"note",'pf.amount'=>'amount_payment','p.datep'=>'date_payment','p.num_paiement'=>'num_payment');
         $this->export_sql[$r]="select distinct ";
         $i=0;
         foreach ($this->export_alias_array[$r] as $key => $value)
@@ -205,7 +205,7 @@ class modFacture extends DolibarrModules
             else $i++;
             $this->export_sql[$r].=$key.' as '.$value;
         }
-        $this->export_sql[$r].=' from ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'societe as s) LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON pf.fk_paiement = p.rowid WHERE f.fk_soc = s.idp';
+        $this->export_sql[$r].=' from ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'societe as s) LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON pf.fk_paiement = p.rowid WHERE f.fk_soc = s.rowid';
         $this->export_permission[$r]=array(array("facture","facture","export"));
 		
     }
diff --git a/htdocs/includes/modules/modFournisseur.class.php b/htdocs/includes/modules/modFournisseur.class.php
index c166023ef02..e39eb2d2037 100644
--- a/htdocs/includes/modules/modFournisseur.class.php
+++ b/htdocs/includes/modules/modFournisseur.class.php
@@ -224,9 +224,9 @@ class modFournisseur extends DolibarrModules
         $r++;
         $this->export_code[$r]=$this->id.'_'.$r;
         $this->export_label[$r]='Factures fournisseurs et lignes de facture';
-        $this->export_fields_array[$r]=array('s.idp'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.cp'=>'Zip','s.ville'=>'Town','s.fk_pays'=>'Country','s.tel'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','f.rowid'=>"Id",'f.facnumber'=>"Ref",'f.datec'=>"DateCreation",'f.datef'=>"DateInvoice",'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.total_tva'=>"TotalVAT",'f.paye'=>"BillShortStatusPayed",'f.fk_statut'=>'Status','f.note'=>"Note",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.tva_taux'=>"LineVATRate",'fd.qty'=>"LineQty");
-        $this->export_entities_array[$r]=array('s.idp'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','s.fk_pays'=>'company','s.tel'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total_ht'=>"invoice",'f.total_ttc'=>"invoice",'f.total_tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.tva_taux'=>"invoice_line",'fd.qty'=>"invoice_line");
-        $this->export_alias_array[$r]=array('s.idp'=>"socid",'s.nom'=>'soc_name','s.address'=>'soc_adres','s.cp'=>'soc_zip','s.ville'=>'soc_ville','s.fk_pays'=>'soc_pays','s.tel'=>'soc_tel','s.siren'=>'soc_siren','s.siret'=>'soc_siret','s.ape'=>'soc_ape','s.idprof4'=>'soc_idprof4','f.rowid'=>"invoiceid",'f.facnumber'=>"ref",'f.datec'=>"datecreation",'f.datef'=>"dateinvoice",'f.total_ht'=>"totalht",'f.total_ttc'=>"totalttc",'f.total_tva'=>"totalvat",'f.paye'=>"paid",'f.fk_statut'=>'status','f.note'=>"note",'fd.rowid'=>'lineid','fd.description'=>"linedescription",'fd.tva_taux'=>"linevatrate",'fd.qty'=>"lineqty");
+        $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.cp'=>'Zip','s.ville'=>'Town','s.fk_pays'=>'Country','s.tel'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','f.rowid'=>"Id",'f.facnumber'=>"Ref",'f.datec'=>"DateCreation",'f.datef'=>"DateInvoice",'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.total_tva'=>"TotalVAT",'f.paye'=>"BillShortStatusPayed",'f.fk_statut'=>'Status','f.note'=>"Note",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.tva_taux'=>"LineVATRate",'fd.qty'=>"LineQty");
+        $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','s.fk_pays'=>'company','s.tel'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total_ht'=>"invoice",'f.total_ttc'=>"invoice",'f.total_tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.tva_taux'=>"invoice_line",'fd.qty'=>"invoice_line");
+        $this->export_alias_array[$r]=array('s.rowid'=>"socid",'s.nom'=>'soc_name','s.address'=>'soc_adres','s.cp'=>'soc_zip','s.ville'=>'soc_ville','s.fk_pays'=>'soc_pays','s.tel'=>'soc_tel','s.siren'=>'soc_siren','s.siret'=>'soc_siret','s.ape'=>'soc_ape','s.idprof4'=>'soc_idprof4','f.rowid'=>"invoiceid",'f.facnumber'=>"ref",'f.datec'=>"datecreation",'f.datef'=>"dateinvoice",'f.total_ht'=>"totalht",'f.total_ttc'=>"totalttc",'f.total_tva'=>"totalvat",'f.paye'=>"paid",'f.fk_statut'=>'status','f.note'=>"note",'fd.rowid'=>'lineid','fd.description'=>"linedescription",'fd.tva_taux'=>"linevatrate",'fd.qty'=>"lineqty");
         $this->export_sql[$r]="select distinct ";
         $i=0;
         foreach ($this->export_alias_array[$r] as $key => $value)
@@ -235,15 +235,15 @@ class modFournisseur extends DolibarrModules
             else $i++;
             $this->export_sql[$r].=$key.' as '.$value;
         }
-        $this->export_sql[$r].=' from '.MAIN_DB_PREFIX.'facture_fourn as f, '.MAIN_DB_PREFIX.'facture_fourn_det as fd, '.MAIN_DB_PREFIX.'societe as s WHERE f.fk_soc = s.idp AND f.rowid = fd.fk_facture_fourn';
+        $this->export_sql[$r].=' from '.MAIN_DB_PREFIX.'facture_fourn as f, '.MAIN_DB_PREFIX.'facture_fourn_det as fd, '.MAIN_DB_PREFIX.'societe as s WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn';
         $this->export_permission[$r]=array(array("fournisseur","facture","export"));
 
         $r++;
         $this->export_code[$r]=$this->id.'_'.$r;
         $this->export_label[$r]='Factures fournisseurs et r�glements';
-        $this->export_fields_array[$r]=array('s.idp'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.cp'=>'Zip','s.ville'=>'Town','s.fk_pays'=>'Country','s.tel'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','f.rowid'=>"Id",'f.facnumber'=>"Ref",'f.datec'=>"DateCreation",'f.datef'=>"DateInvoice",'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.total_tva'=>"TotalVAT",'f.paye'=>"BillShortStatusPayed",'f.fk_statut'=>'Status','f.note'=>"Note",'pf.amount'=>'AmountPayment','p.datep'=>'DatePayment','p.num_paiement'=>'Numero');
-        $this->export_entities_array[$r]=array('s.idp'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','s.fk_pays'=>'company','s.tel'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total_ht'=>"invoice",'f.total_ttc'=>"invoice",'f.total_tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'pf.amount'=>'payment','p.datep'=>'payment','p.num_paiement'=>'payment');
-        $this->export_alias_array[$r]=array('s.idp'=>"socid",'s.nom'=>'soc_name','s.address'=>'soc_adres','s.cp'=>'soc_zip','s.ville'=>'soc_ville','s.fk_pays'=>'soc_pays','s.tel'=>'soc_tel','s.siren'=>'soc_siren','s.siret'=>'soc_siret','s.ape'=>'soc_ape','s.idprof4'=>'soc_idprof4','f.rowid'=>"invoiceid",'f.facnumber'=>"ref",'f.datec'=>"datecreation",'f.datef'=>"dateinvoice",'f.total_ht'=>"totalht",'f.total_ttc'=>"totalttc",'f.total_tva'=>"totalvat",'f.paye'=>"paid",'f.fk_statut'=>'status','f.note'=>"note",'pf.amount'=>'amount_payment','p.datep'=>'date_payment','p.num_paiement'=>'num_payment');
+        $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.cp'=>'Zip','s.ville'=>'Town','s.fk_pays'=>'Country','s.tel'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','f.rowid'=>"Id",'f.facnumber'=>"Ref",'f.datec'=>"DateCreation",'f.datef'=>"DateInvoice",'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.total_tva'=>"TotalVAT",'f.paye'=>"BillShortStatusPayed",'f.fk_statut'=>'Status','f.note'=>"Note",'pf.amount'=>'AmountPayment','p.datep'=>'DatePayment','p.num_paiement'=>'Numero');
+        $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','s.fk_pays'=>'company','s.tel'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total_ht'=>"invoice",'f.total_ttc'=>"invoice",'f.total_tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'pf.amount'=>'payment','p.datep'=>'payment','p.num_paiement'=>'payment');
+        $this->export_alias_array[$r]=array('s.rowid'=>"socid",'s.nom'=>'soc_name','s.address'=>'soc_adres','s.cp'=>'soc_zip','s.ville'=>'soc_ville','s.fk_pays'=>'soc_pays','s.tel'=>'soc_tel','s.siren'=>'soc_siren','s.siret'=>'soc_siret','s.ape'=>'soc_ape','s.idprof4'=>'soc_idprof4','f.rowid'=>"invoiceid",'f.facnumber'=>"ref",'f.datec'=>"datecreation",'f.datef'=>"dateinvoice",'f.total_ht'=>"totalht",'f.total_ttc'=>"totalttc",'f.total_tva'=>"totalvat",'f.paye'=>"paid",'f.fk_statut'=>'status','f.note'=>"note",'pf.amount'=>'amount_payment','p.datep'=>'date_payment','p.num_paiement'=>'num_payment');
         $this->export_sql[$r]="select distinct ";
         $i=0;
         foreach ($this->export_alias_array[$r] as $key => $value)
@@ -252,7 +252,7 @@ class modFournisseur extends DolibarrModules
             else $i++;
             $this->export_sql[$r].=$key.' as '.$value;
         }
-        $this->export_sql[$r].=' from ('.MAIN_DB_PREFIX.'facture_fourn as f, '.MAIN_DB_PREFIX.'societe as s) LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid WHERE f.fk_soc = s.idp';
+        $this->export_sql[$r].=' from ('.MAIN_DB_PREFIX.'facture_fourn as f, '.MAIN_DB_PREFIX.'societe as s) LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid WHERE f.fk_soc = s.rowid';
         $this->export_permission[$r]=array(array("fournisseur","facture","export"));
 		
     }
diff --git a/htdocs/includes/modules/modSociete.class.php b/htdocs/includes/modules/modSociete.class.php
index 254fedc12ac..8a50a448488 100644
--- a/htdocs/includes/modules/modSociete.class.php
+++ b/htdocs/includes/modules/modSociete.class.php
@@ -175,9 +175,9 @@ class modSociete extends DolibarrModules
     $r++;
     $this->export_code[$r]=$this->id.'_'.$r;
     $this->export_label[$r]='Liste des societes et attributs';
-    $this->export_fields_array[$r]=array('s.idp'=>"Id",'s.nom'=>"Name",'s.prefix_comm'=>"Prefix",'s.client'=>"Customer",'s.fournisseur'=>"Supplier",'s.datec'=>"DateCreation",'s.tms'=>"DateLastModification",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'p.libelle'=>"Country",'p.code'=>"CountryCode",'s.tel'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.siret'=>"IdProf1",'s.siren'=>"IdProf2",'s.ape'=>"IdProf3",'s.idprof4'=>"IdProf4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note'=>"Note");
-    $this->export_entities_array[$r]=array('s.idp'=>"company",'s.nom'=>"company",'s.prefix_comm'=>"company",'s.client'=>"company",'s.fournisseur'=>"company",'s.datec'=>"company",'s.tms'=>"company",'s.code_client'=>"company",'s.code_fournisseur'=>"company",'s.address'=>"company",'s.cp'=>"company",'s.ville'=>"company",'p.libelle'=>"company",'p.code'=>"company",'s.tel'=>"company",'s.fax'=>"company",'s.url'=>"company",'s.siret'=>"company",'s.siren'=>"company",'s.ape'=>"company",'s.idprof4'=>"company",'s.tva_intra'=>"company",'s.capital'=>"company",'s.note'=>"company");
-    $this->export_alias_array[$r]=array('s.idp'=>"idsoc",'s.nom'=>"name",'s.prefix_comm'=>"prefix",'s.client'=>"iscustomer",'s.fournisseur'=>"issupplier",'s.datec'=>"datecreation",'s.tms'=>"datelastmodification",'s.code_client'=>"customercode",'s.code_fournisseur'=>"suppliercode",'s.address'=>"address",'s.cp'=>"zip",'s.ville'=>"town",'p.libelle'=>"country",'p.code'=>"countrycode",'s.tel'=>"phone",'s.fax'=>"fax",'s.url'=>"url",'s.siret'=>"idprof1",'s.siren'=>"idprof2",'s.ape'=>"idprof3",'s.idprof4'=>"idprof4",'s.tva_intra'=>"vatintra",'s.capital'=>"capital",'s.note'=>"note");
+    $this->export_fields_array[$r]=array('s.rowid'=>"Id",'s.nom'=>"Name",'s.prefix_comm'=>"Prefix",'s.client'=>"Customer",'s.fournisseur'=>"Supplier",'s.datec'=>"DateCreation",'s.tms'=>"DateLastModification",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'p.libelle'=>"Country",'p.code'=>"CountryCode",'s.tel'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.siret'=>"IdProf1",'s.siren'=>"IdProf2",'s.ape'=>"IdProf3",'s.idprof4'=>"IdProf4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note'=>"Note");
+    $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>"company",'s.prefix_comm'=>"company",'s.client'=>"company",'s.fournisseur'=>"company",'s.datec'=>"company",'s.tms'=>"company",'s.code_client'=>"company",'s.code_fournisseur'=>"company",'s.address'=>"company",'s.cp'=>"company",'s.ville'=>"company",'p.libelle'=>"company",'p.code'=>"company",'s.tel'=>"company",'s.fax'=>"company",'s.url'=>"company",'s.siret'=>"company",'s.siren'=>"company",'s.ape'=>"company",'s.idprof4'=>"company",'s.tva_intra'=>"company",'s.capital'=>"company",'s.note'=>"company");
+    $this->export_alias_array[$r]=array('s.rowid'=>"socid",'s.nom'=>"name",'s.prefix_comm'=>"prefix",'s.client'=>"iscustomer",'s.fournisseur'=>"issupplier",'s.datec'=>"datecreation",'s.tms'=>"datelastmodification",'s.code_client'=>"customercode",'s.code_fournisseur'=>"suppliercode",'s.address'=>"address",'s.cp'=>"zip",'s.ville'=>"town",'p.libelle'=>"country",'p.code'=>"countrycode",'s.tel'=>"phone",'s.fax'=>"fax",'s.url'=>"url",'s.siret'=>"idprof1",'s.siren'=>"idprof2",'s.ape'=>"idprof3",'s.idprof4'=>"idprof4",'s.tva_intra'=>"vatintra",'s.capital'=>"capital",'s.note'=>"note");
     $this->export_sql[$r]="select ";
     $i=0;
     foreach ($this->export_alias_array[$r] as $key => $value)
@@ -193,9 +193,9 @@ class modSociete extends DolibarrModules
     $r++;
     $this->export_code[$r]=$this->id.'_'.$r;
     $this->export_label[$r]='Liste des contacts et attributs';
-    $this->export_fields_array[$r]=array('c.civilite'=>"CivilityCode",'c.name'=>'Lastname','c.firstname'=>'Firstname','c.datec'=>"DateCreation",'c.tms'=>"DateLastModification",'c.address'=>"Address",'c.cp'=>"Zip",'c.ville'=>"Town",'c.phone'=>"Phone",'c.fax'=>"Fax",'c.email'=>"EMail",'p.libelle'=>"Country",'p.code'=>"CountryCode",'s.idp'=>"IdCompany",'s.nom'=>"CompanyName",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode");
-    $this->export_entities_array[$r]=array('c.civilite'=>"contact",'c.name'=>'contact','c.firstname'=>'contact','c.datec'=>"contact",'c.tms'=>"contact",'c.address'=>"contact",'c.cp'=>"contact",'c.ville'=>"contact",'c.phone'=>"contact",'c.fax'=>"contact",'c.email'=>"contact",'p.libelle'=>"contact",'p.code'=>"contact",'s.idp'=>"company",'s.nom'=>"company",'s.code_client'=>"company",'s.code_fournisseur'=>"company");
-    $this->export_alias_array[$r]=array('c.civilite'=>"civilitycode",'c.name'=>'lastname','c.firstname'=>'firstname','c.datec'=>"datecreation",'c.tms'=>"datelastmodification",'c.address'=>"address",'c.cp'=>"zip",'c.ville'=>"town",'c.phone'=>"phone",'c.fax'=>"fax",'c.email'=>"email",'p.libelle'=>"country",'p.code'=>"countrycode",'s.idp'=>"idcompany",'s.nom'=>"companyname",'s.code_client'=>"customercode",'s.code_fournisseur'=>"suppliercode");
+    $this->export_fields_array[$r]=array('c.civilite'=>"CivilityCode",'c.name'=>'Lastname','c.firstname'=>'Firstname','c.datec'=>"DateCreation",'c.tms'=>"DateLastModification",'c.address'=>"Address",'c.cp'=>"Zip",'c.ville'=>"Town",'c.phone'=>"Phone",'c.fax'=>"Fax",'c.email'=>"EMail",'p.libelle'=>"Country",'p.code'=>"CountryCode",'s.rowid'=>"IdCompany",'s.nom'=>"CompanyName",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode");
+    $this->export_entities_array[$r]=array('c.civilite'=>"contact",'c.name'=>'contact','c.firstname'=>'contact','c.datec'=>"contact",'c.tms'=>"contact",'c.address'=>"contact",'c.cp'=>"contact",'c.ville'=>"contact",'c.phone'=>"contact",'c.fax'=>"contact",'c.email'=>"contact",'p.libelle'=>"contact",'p.code'=>"contact",'s.rowid'=>"company",'s.nom'=>"company",'s.code_client'=>"company",'s.code_fournisseur'=>"company");
+    $this->export_alias_array[$r]=array('c.civilite'=>"civilitycode",'c.name'=>'lastname','c.firstname'=>'firstname','c.datec'=>"datecreation",'c.tms'=>"datelastmodification",'c.address'=>"address",'c.cp'=>"zip",'c.ville'=>"town",'c.phone'=>"phone",'c.fax'=>"fax",'c.email'=>"email",'p.libelle'=>"country",'p.code'=>"countrycode",'s.idp'=>"socid",'s.nom'=>"companyname",'s.code_client'=>"customercode",'s.code_fournisseur'=>"suppliercode");
     $this->export_sql[$r]="select ";
     $i=0;
     foreach ($this->export_alias_array[$r] as $key => $value)
@@ -204,7 +204,7 @@ class modSociete extends DolibarrModules
         else $i++;
         $this->export_sql[$r].=$key.' as '.$value;
     }
-    $this->export_sql[$r].=' from '.MAIN_DB_PREFIX.'c_pays as p, '.MAIN_DB_PREFIX.'socpeople as c LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.idp WHERE c.fk_pays = p.rowid';
+    $this->export_sql[$r].=' from '.MAIN_DB_PREFIX.'c_pays as p, '.MAIN_DB_PREFIX.'socpeople as c LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.rowid WHERE c.fk_pays = p.rowid';
     $this->export_permission[$r]=array(array("societe","contact","export"));
 
 }
diff --git a/htdocs/includes/modules/societe/mod_codeclient_lion.php b/htdocs/includes/modules/societe/mod_codeclient_lion.php
index 7c1da554945..5a3f677e59d 100644
--- a/htdocs/includes/modules/societe/mod_codeclient_lion.php
+++ b/htdocs/includes/modules/societe/mod_codeclient_lion.php
@@ -161,7 +161,7 @@ class mod_codeclient_lion extends ModeleThirdPartyCode
 	{
 		$sql = "SELECT code_client FROM ".MAIN_DB_PREFIX."societe";
 		$sql.= " WHERE code_client = '".$code."'";
-		$sql.= " AND idp != '".$soc->id."'";
+		$sql.= " AND rowid != '".$soc->id."'";
 
 		$resql=$db->query($sql);
 		if ($resql)
diff --git a/htdocs/includes/modules/societe/mod_codeclient_zebre.php b/htdocs/includes/modules/societe/mod_codeclient_zebre.php
index 5bb2e73087a..a32fceda551 100644
--- a/htdocs/includes/modules/societe/mod_codeclient_zebre.php
+++ b/htdocs/includes/modules/societe/mod_codeclient_zebre.php
@@ -178,7 +178,7 @@ class mod_codeclient_zebre extends ModeleThirdPartyCode
 	{
 		$sql = "SELECT code_client FROM ".MAIN_DB_PREFIX."societe";
 		$sql.= " WHERE code_client = '".$code."'";
-		$sql.= " AND idp != '".$soc->id."'";
+		$sql.= " AND rowid != '".$soc->id."'";
 
 		$resql=$db->query($sql);
 		if ($resql)
diff --git a/htdocs/includes/modules/societe/mod_codecompta_aquarium.php b/htdocs/includes/modules/societe/mod_codecompta_aquarium.php
index 85a9019b9ef..9a5cbf5b321 100644
--- a/htdocs/includes/modules/societe/mod_codecompta_aquarium.php
+++ b/htdocs/includes/modules/societe/mod_codecompta_aquarium.php
@@ -119,7 +119,7 @@ class mod_codecompta_aquarium extends ModeleAccountancyCode
     if ($type == 'customer') $sql.= "code_compta";
     if ($type == 'supplier') $sql.= "code_compta_fournisseur";
     $sql.= " = '".$code."'";
-    $sql.= " AND idp != ".$societe->id;
+    $sql.= " AND rowid != ".$societe->id;
     
     $resql=$db->query($sql);
     if ($resql)
diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php
index 2533d11ad95..8b57fafc949 100644
--- a/htdocs/lib/functions.inc.php
+++ b/htdocs/lib/functions.inc.php
@@ -1307,7 +1307,7 @@ function dol_loginfunction($notused,$pearstatus)
       }
       if ($socid > 0) $sql .= " AND dbt.fk_soc = ".$socid;
     }
-
+//print $sql;
     if ($sql && $db->query($sql))
     {
       if ($db->num_rows() == 0)
@@ -1316,7 +1316,7 @@ function dol_loginfunction($notused,$pearstatus)
       }
     }
   }
-  else if ((!$objectid && $modulename == 'societe' && $list==0) && $nocreate == 1)
+  else if ((!$objectid && $list==0) && $nocreate == 1)
   {
   	accessforbidden();
   }
diff --git a/htdocs/lolix/lolix.societe.class.php b/htdocs/lolix/lolix.societe.class.php
index 290fc06a6bf..024b79f1b89 100644
--- a/htdocs/lolix/lolix.societe.class.php
+++ b/htdocs/lolix/lolix.societe.class.php
@@ -96,7 +96,7 @@ class LolixSociete {
       $sql = "SELECT s.nom,s.active,s.siren,s.tel,s.url,s.fax,";
       $sql .= $this->db->pdate("s.datec")." as dc";
       $sql .= " FROM lolixfr.societe as s";
-      $sql .= " WHERE s.idp = ".$this->id;
+      $sql .= " WHERE s.rowid = ".$this->id;
 
       if ($this->db->query($sql)) 
 	{
diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php
index b4aecfc67f7..64d128682bc 100644
--- a/htdocs/main.inc.php
+++ b/htdocs/main.inc.php
@@ -389,7 +389,7 @@ if (! session_id() || ! isset($_SESSION["dol_login"]))
 		  		$user->login = $ldap->login;
 		  		$user->update();
 		  	}
-		    //$resultUpdate = $user->update_ldap2dolibarr($attributs);
+		    //$resultUpdate = $user->update_ldap2dolibarr();
 		  }
 		}
 		else
diff --git a/htdocs/notify.class.php b/htdocs/notify.class.php
index 02bd2e07989..c547932cdd1 100644
--- a/htdocs/notify.class.php
+++ b/htdocs/notify.class.php
@@ -86,12 +86,12 @@ class Notify
 	{
         $num=-1;
         
-        $sql = "SELECT n.rowid, c.email, c.idp, c.name, c.firstname, a.titre, s.nom";
+        $sql = "SELECT n.rowid, c.email, c.rowid, c.name, c.firstname, a.titre, s.nom";
         $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify_def as n, ".MAIN_DB_PREFIX."societe as s";
-        $sql.= " WHERE n.fk_contact = c.idp AND a.rowid = n.fk_action";
-        $sql.= " AND n.fk_soc = s.idp";
+        $sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
+        $sql.= " AND n.fk_soc = s.rowid";
         $sql.= " AND n.fk_action = ".$action;
-        $sql.= " AND s.idp = ".$socid;
+        $sql.= " AND s.rowid = ".$socid;
 
 		dolibarr_syslog("Notify.class::countDefinedNotifications $action, $socid");
 
@@ -117,11 +117,11 @@ class Notify
     {
         global $conf,$langs;
 
-        $sql = "SELECT s.nom, c.email, c.idp, c.name, c.firstname, a.titre,n.rowid";
+        $sql = "SELECT s.nom, c.email, c.rowid, c.name, c.firstname, a.titre,n.rowid";
         $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify_def as n, ".MAIN_DB_PREFIX."societe as s";
-        $sql .= " WHERE n.fk_contact = c.idp AND a.rowid = n.fk_action";
-        $sql .= " AND n.fk_soc = s.idp AND n.fk_action = ".$action;
-        $sql .= " AND s.idp = ".$socid;
+        $sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
+        $sql .= " AND n.fk_soc = s.rowid AND n.fk_action = ".$action;
+        $sql .= " AND s.rowid = ".$socid;
 
 		dolibarr_syslog("Notify.class::send $action, $socid, $texte, $objet_type, $objet_id, $file");
 
@@ -160,7 +160,7 @@ class Notify
                         $sendto = htmlentities($sendto);
 
                         $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_contact, objet_type, objet_id)";
-                        $sql .= " VALUES (now(), $action ,$obj->idp , '$objet_type', $objet_id);";
+                        $sql .= " VALUES (now(), ".$action." ,".$obj->rowid." , '".$objet_type."', ".$objet_id.");";
                         if (! $this->db->query($sql) )
                         {
                             dolibarr_print_error($db);
diff --git a/htdocs/oscommerce_ws/clients/osc_customer.class.php b/htdocs/oscommerce_ws/clients/osc_customer.class.php
index 6c7fc1fe149..81908b24fd7 100644
--- a/htdocs/oscommerce_ws/clients/osc_customer.class.php
+++ b/htdocs/oscommerce_ws/clients/osc_customer.class.php
@@ -134,7 +134,7 @@ class Osc_customer
 /**
 *      \brief      Mise � jour de la table de transition
 *      \param      oscid      Id du client dans OsC 
-*	   \param	   socid	  champ soci�t�.idp 	
+*	   \param	   socid	  champ soci�t�.rowid 	
 *      \return     int     <0 si ko, >0 si ok
 */
 	function transcode($oscid, $socid)
diff --git a/htdocs/paiement.class.php b/htdocs/paiement.class.php
index f891b8480bb..c09e5da05db 100644
--- a/htdocs/paiement.class.php
+++ b/htdocs/paiement.class.php
@@ -351,7 +351,7 @@ class Paiement
 			if ($this->db->num_rows($result))
 			{
 				$obj = $this->db->fetch_object($result);
-				$this->id = $obj->idp;
+				$this->id = $obj->rowid;
 				if ($obj->fk_user_creat)
 				{
 					$cuser = new User($this->db, $obj->fk_user_creat);
diff --git a/htdocs/product/canvas/product.livre.class.php b/htdocs/product/canvas/product.livre.class.php
index 6af94b12964..90e69b2caa3 100644
--- a/htdocs/product/canvas/product.livre.class.php
+++ b/htdocs/product/canvas/product.livre.class.php
@@ -215,8 +215,8 @@ class ProductLivre extends Product
     if ($result >= 0)
       {
 	$sql = "SELECT l.rowid,l.isbn,l.ean,l.pages,l.fk_couverture,l.format,l.fk_contrat";
-	$sql.= ",l.px_feuillet,l.px_revient,l.px_couverture,l.px_reliure, s.nom, s.idp";
-	$sql.= " FROM ".MAIN_DB_PREFIX."product_cnv_livre as l LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.idp=l.fk_auteur";
+	$sql.= ",l.px_feuillet,l.px_revient,l.px_couverture,l.px_reliure, s.nom, s.rowid as socid";
+	$sql.= " FROM ".MAIN_DB_PREFIX."product_cnv_livre as l LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = l.fk_auteur";
 	if ($id) $sql.= " WHERE l.rowid = '".$id."'";
 	if ($ref) $sql.= " WHERE l.ref = '".addslashes($ref)."'";
 	
@@ -236,7 +236,7 @@ class ProductLivre extends Product
 	    $this->px_couverture      = $result["px_couverture"];
 	    $this->couverture_id      = $result["fk_couverture"];
 	    $this->auteur             = stripslashes($result["nom"]);
-	    $this->auteur_id          = $result["idp"];
+	    $this->auteur_id          = $result["socid"];
 
 	    $this->db->free();
 	  }
@@ -583,13 +583,13 @@ class ProductLivre extends Product
   {
     $this->available_auteurs = array();
 
-    $sql = "SELECT idp,nom FROM ".MAIN_DB_PREFIX."societe ";
+    $sql = "SELECT rowid, nom FROM ".MAIN_DB_PREFIX."societe ";
 
     $resql = $this->db->query($sql);
 
     while ($obj = $this->db->fetch_object($resql) )
       {
-	$this->available_auteurs[$obj->idp] = stripslashes($obj->nom);
+	$this->available_auteurs[$obj->rowid] = stripslashes($obj->nom);
       }
 
     $this->db->free($resql);
diff --git a/htdocs/product/droitpret/droitpret.class.php b/htdocs/product/droitpret/droitpret.class.php
index cc6e842b696..27934b2855d 100644
--- a/htdocs/product/droitpret/droitpret.class.php
+++ b/htdocs/product/droitpret/droitpret.class.php
@@ -102,8 +102,8 @@ class DroitPret
    
     		$sql = "SELECT f.rowid, f.facnumber, f.datec, f.total_ttc, f.total ";
     		$sql.= "FROM llx_facture AS f, llx_facturedet AS d, llx_product AS p, llx_societe AS s, llx_categorie_societe AS c ";
-    		$sql.= "WHERE f.fk_soc = s.idp ";
-    		$sql.= "AND c.fk_societe = s.idp ";
+    		$sql.= "WHERE f.fk_soc = s.rowid ";
+    		$sql.= "AND c.fk_societe = s.rowid ";
     		$sql.= "AND d.fk_product = p.rowid ";
       		$sql.= "AND f.rowid = d.fk_facture ";
       		$sql.= "AND f.datec >= '".date("Y-m-d H:i:s",$this->dated)."' ";
@@ -140,9 +140,9 @@ class DroitPret
     function WriteINT($fac)
     {
     	global $conf;
-		$sql = "SELECT f.rowid, s.idp ";
+		$sql = "SELECT f.rowid, s.rowid as socid ";
 		$sql.= "FROM llx_facture AS f, llx_societe AS s ";
-		$sql.= "WHERE f.fk_soc = s.idp ";
+		$sql.= "WHERE f.fk_soc = s.rowid ";
 		$sql.= "AND f.rowid = ".$fac." ";
 		
 		$result = $this->db->query($sql);
@@ -155,7 +155,7 @@ class DroitPret
 		    while ($i < $num)
     		{
         		$obj = $this->db->fetch_object($result);
-				$ligne = "INT".$this->ComplChar($conf->global->MAIN_INFO_SOCIETE_GENCOD,"0",13).$this->ComplChar($obj->idp,"0",13);
+				$ligne = "INT".$this->ComplChar($conf->global->MAIN_INFO_SOCIETE_GENCOD,"0",13).$this->ComplChar($obj->socid,"0",13);
         		fwrite($this->fp,$ligne."\n");
         		$i++;
     		}
diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php
index 3bd0d86ab84..fbb32e10abc 100644
--- a/htdocs/product/fiche.php
+++ b/htdocs/product/fiche.php
@@ -1021,9 +1021,9 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status)
       // Liste de "Mes propals"
       print '<tr><td width="50%" valign="top">';
 
-      $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.ref,".$db->pdate("p.datep")." as dp";
+      $sql = "SELECT s.nom, s.rowid as socid, p.rowid as propalid, p.ref,".$db->pdate("p.datep")." as dp";
       $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p";
-      $sql .=" WHERE p.fk_soc = s.idp AND p.fk_statut = 0 AND p.fk_user_author = ".$user->id;
+      $sql .=" WHERE p.fk_soc = s.rowid AND p.fk_statut = 0 AND p.fk_user_author = ".$user->id;
       $sql .= " ORDER BY p.datec DESC, tms DESC";
 
       $result=$db->query($sql);
@@ -1043,8 +1043,8 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status)
 		  print "<tr $bc[$var]>";
 		  print "<td nowrap>";
 		  print '<input type="hidden" name="action" value="addinpropal">';
-		  print "<a href=\"../comm/propal.php?propalid=$objp->propalid\">".img_object($langs->trans("ShowPropal"),"propal")." ".$objp->ref."</a></td>\n";
-		  print "<td><a href=\"../comm/fiche.php?socid=$objp->idp\">".dolibarr_trunc($objp->nom,18)."</a></td>\n";
+		  print "<a href=\"../comm/propal.php?propalid=".$objp->propalid."\">".img_object($langs->trans("ShowPropal"),"propal")." ".$objp->ref."</a></td>\n";
+		  print "<td><a href=\"../comm/fiche.php?socid=".$objp->socid."\">".dolibarr_trunc($objp->nom,18)."</a></td>\n";
 		  print "<td nowrap=\"nowrap\">".dolibarr_print_date($objp->dp,"%d %b")."</td>\n";
 		  print '<td><input type="hidden" name="propalid" value="'.$objp->propalid.'">';
 		  print '<input type="text" class="flat" name="qty" size="1" value="1"></td><td nowrap>'.$langs->trans("ReductionShort");
@@ -1134,9 +1134,9 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status)
 
       // Liste de "Mes commandes"
       print '<tr><td width="50%" valign="top">';
-      $sql = "SELECT s.nom, s.idp, c.rowid as commandeid, c.ref,".$db->pdate("c.date_commande")." as dc";
+      $sql = "SELECT s.nom, s.rowid as socid, c.rowid as commandeid, c.ref,".$db->pdate("c.date_commande")." as dc";
       $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
-      $sql .=" WHERE c.fk_soc = s.idp AND c.fk_statut = 0 AND c.fk_user_author = ".$user->id;
+      $sql .=" WHERE c.fk_soc = s.rowid AND c.fk_statut = 0 AND c.fk_user_author = ".$user->id;
       $sql .= " ORDER BY c.date_creation DESC";
 
       $result=$db->query($sql);
@@ -1156,8 +1156,8 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status)
 		  print "<tr $bc[$var]>";
 		  print "<td nowrap>";
 		  print '<input type="hidden" name="action" value="addincommande">';
-		  print "<a href=\"../commande/fiche.php?id=$objc->commandeid\">".img_object($langs->trans("ShowOrder"),"order")." ".$objc->ref."</a></td>\n";
-		  print "<td><a href=\"../comm/fiche.php?socid=$objc->idp\">".dolibarr_trunc($objc->nom,18)."</a></td>\n";
+		  print "<a href=\"../commande/fiche.php?id=".$objc->commandeid."\">".img_object($langs->trans("ShowOrder"),"order")." ".$objc->ref."</a></td>\n";
+		  print "<td><a href=\"../comm/fiche.php?socid=".$objc->socid."\">".dolibarr_trunc($objc->nom,18)."</a></td>\n";
 		  print "<td nowrap=\"nowrap\">".dolibarr_print_date($objc->dc,"%d %b")."</td>\n";
 		  print '<td><input type="hidden" name="commandeid" value="'.$objc->commandeid.'">';
 		  print '<input type="text" class="flat" name="qty" size="1" value="1"></td><td nowrap>'.$langs->trans("ReductionShort");
@@ -1243,9 +1243,9 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status)
 
       // Liste de Mes factures
       print '<tr><td width="50%" valign="top">';
-      $sql = "SELECT s.nom, s.idp, f.rowid as factureid, f.facnumber,".$db->pdate("f.datef")." as df";
+      $sql = "SELECT s.nom, s.rowid as socid, f.rowid as factureid, f.facnumber,".$db->pdate("f.datef")." as df";
       $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f";
-      $sql .=" WHERE f.fk_soc = s.idp AND f.fk_statut = 0 AND f.fk_user_author = ".$user->id;
+      $sql .=" WHERE f.fk_soc = s.rowid AND f.fk_statut = 0 AND f.fk_user_author = ".$user->id;
       $sql .= " ORDER BY f.datec DESC, f.rowid DESC";
 
       $result=$db->query($sql);
@@ -1265,8 +1265,8 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status)
 		  print "<tr $bc[$var]>";
 		  print "<td nowrap>";
 		  print '<input type="hidden" name="action" value="addinfacture">';
-		  print "<a href=\"../compta/facture.php?facid=$objp->factureid\">".img_object($langs->trans("ShowBills"),"bill")." ".$objp->facnumber."</a></td>\n";
-		  print "<td><a href=\"../comm/fiche.php?socid=$objp->idp\">".dolibarr_trunc($objp->nom,18)."</a></td>\n";
+		  print "<a href=\"../compta/facture.php?facid=".$objp->factureid."\">".img_object($langs->trans("ShowBills"),"bill")." ".$objp->facnumber."</a></td>\n";
+		  print "<td><a href=\"../comm/fiche.php?socid=".$objp->socid."\">".dolibarr_trunc($objp->nom,18)."</a></td>\n";
 		  print "<td nowrap=\"nowrap\">".dolibarr_print_date($objp->df,"%d %b")."</td>\n";
 		  print '<td><input type="hidden" name="factureid" value="'.$objp->factureid.'">';
 		  print '<input type="text" class="flat" name="qty" size="1" value="1"></td><td nowrap>'.$langs->trans("ReductionShort");
@@ -1301,9 +1301,9 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status)
 	  // Liste de Autres factures
 	  $var=true;
 
-	  $sql = "SELECT s.nom, s.idp, f.rowid as factureid, f.facnumber,".$db->pdate("f.datef")." as df";
+	  $sql = "SELECT s.nom, s.rowid as socid, f.rowid as factureid, f.facnumber,".$db->pdate("f.datef")." as df";
 	  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f";
-	  $sql .=" WHERE f.fk_soc = s.idp AND f.fk_statut = 0 AND f.fk_user_author <> ".$user->id;
+	  $sql .=" WHERE f.fk_soc = s.rowid AND f.fk_statut = 0 AND f.fk_user_author <> ".$user->id;
 	  $sql .= " ORDER BY f.datec DESC, f.rowid DESC";
 
 	  $result=$db->query($sql);
@@ -1321,8 +1321,8 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status)
 		    $var=!$var;
 		    print '<form method="POST" action="fiche.php?id='.$product->id.'">';
 		    print "<tr $bc[$var]>";
-		    print "<td><a href=\"../compta/facture.php?facid=$objp->factureid\">$objp->facnumber</a></td>\n";
-		    print "<td><a href=\"../comm/fiche.php?socid=$objp->idp\">".dolibarr_trunc($objp->nom,24)."</a></td>\n";
+		    print "<td><a href=\"../compta/facture.php?facid=".$objp->factureid."\">$objp->facnumber</a></td>\n";
+		    print "<td><a href=\"../comm/fiche.php?socid=".$objp->socid."\">".dolibarr_trunc($objp->nom,24)."</a></td>\n";
 		    print "<td colspan=\"2\">".$langs->trans("Qty");
 		    print '<input type="hidden" name="action" value="addinfacture">';
 		    print "</td>";
diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php
index 0be31e6dec0..7abbf0c5071 100644
--- a/htdocs/product/fournisseurs.php
+++ b/htdocs/product/fournisseurs.php
@@ -289,11 +289,11 @@ if ($_GET["id"] || $_GET["ref"])
 				print '</tr>';
 
 				// Liste des fournisseurs
-				$sql = "SELECT s.nom, s.idp, pf.ref_fourn, pfp.price, pfp.quantity";
+				$sql = "SELECT s.nom, s.rowid as socid, pf.ref_fourn, pfp.price, pfp.quantity";
 				$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur as pf";
 				$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
 				$sql.= " ON pf.fk_soc = pfp.fk_soc AND pf.fk_product = pfp.fk_product";
-				$sql.= " WHERE pf.fk_soc = s.idp AND pf.fk_product = ".$product->id;
+				$sql.= " WHERE pf.fk_soc = s.rowid AND pf.fk_product = ".$product->id;
 				$sql.= " ORDER BY lower(s.nom), pfp.quantity";
 
 				$resql="";
@@ -310,7 +310,7 @@ if ($_GET["id"] || $_GET["ref"])
 						$var=!$var;
 						
 						print "<tr $bc[$var]>";
-						print '<td><a href="../fourn/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans("ShowCompany"),'company').' '.$objp->nom.'</a></td>';
+						print '<td><a href="../fourn/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),'company').' '.$objp->nom.'</a></td>';
 
 						// Fournisseur
 						print '<td align="left">'.$objp->ref_fourn.'</td>';
@@ -333,8 +333,8 @@ if ($_GET["id"] || $_GET["ref"])
 						// Modifier-Supprimer
 						print '<td align="center">';
 						if ($user->rights->produit->creer) {
-							print '<a href="fournisseurs.php?id='.$product->id.'&amp;action=add_price&amp;id_fourn='.$objp->idp.'&amp;qty='.$objp->quantity.'&amp;price='.$objp->price.'">'.img_edit()."</a>";
-							print '<a href="fournisseurs.php?id='.$product->id.'&amp;action=remove_fourn&amp;id_fourn='.$objp->idp.'&amp;qty='.$objp->quantity.'">';
+							print '<a href="fournisseurs.php?id='.$product->id.'&amp;action=add_price&amp;id_fourn='.$objp->socid.'&amp;qty='.$objp->quantity.'&amp;price='.$objp->price.'">'.img_edit()."</a>";
+							print '<a href="fournisseurs.php?id='.$product->id.'&amp;action=remove_fourn&amp;id_fourn='.$objp->socid.'&amp;qty='.$objp->quantity.'">';
 							print img_disable($langs->trans("Remove")).'</a>';
 						}
 
diff --git a/htdocs/product/stats/commande.php b/htdocs/product/stats/commande.php
index 826dc7e6d99..0162b0ac360 100644
--- a/htdocs/product/stats/commande.php
+++ b/htdocs/product/stats/commande.php
@@ -121,14 +121,14 @@ if ($_GET["id"] || $_GET["ref"])
         print '</div>';
         
 
-        $sql = "SELECT distinct(s.nom), s.idp, s.code_client, c.rowid, c.total_ht as amount, c.ref,";
+        $sql = "SELECT distinct(s.nom), s.rowid as socid, s.code_client, c.rowid, c.total_ht as amount, c.ref,";
         $sql.= " ".$db->pdate("c.date_creation")." as date, c.fk_statut as statut, c.facture, c.rowid as commandeid";
         if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."commandedet as d";
         if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-		    $sql.= " WHERE c.fk_soc = s.idp";
+		    $sql.= " WHERE c.fk_soc = s.rowid";
         $sql.= " AND d.fk_commande = c.rowid AND d.fk_product =".$product->id;
-        if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+        if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
         if ($socid)
         {
             $sql .= " AND c.fk_soc = $socid";
@@ -169,7 +169,7 @@ if ($_GET["id"] || $_GET["ref"])
                     print '<td><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$objp->commandeid.'">'.img_object($langs->trans("ShowOrder"),"order").' ';
                     print $objp->ref;
                     print "</a></td>\n";
-                    print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44).'</a></td>';
+                    print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44).'</a></td>';
                     print "<td>".$objp->code_client."</td>\n";
                     print "<td align=\"center\">";
                     print dolibarr_print_date($objp->date)."</td>";
diff --git a/htdocs/product/stats/commande_fournisseur.php b/htdocs/product/stats/commande_fournisseur.php
index 589f292014b..5ceefe64b5a 100644
--- a/htdocs/product/stats/commande_fournisseur.php
+++ b/htdocs/product/stats/commande_fournisseur.php
@@ -114,14 +114,14 @@ if ($_GET["id"] || $_GET["ref"])
       print "</table>";
       print '</div>';
       
-      $sql = "SELECT distinct(s.nom), s.idp, s.code_client, c.rowid, c.total_ht as amount, c.ref,";
+      $sql = "SELECT distinct(s.nom), s.rowid as socid, s.code_client, c.rowid, c.total_ht as amount, c.ref,";
       $sql.= " ".$db->pdate("c.date_creation")." as date, c.fk_statut as statut, c.rowid as commandeid";
       if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
       $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."commande_fournisseur as c, ".MAIN_DB_PREFIX."commande_fournisseurdet as d";
       if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-      $sql.= " WHERE c.fk_soc = s.idp";
+      $sql.= " WHERE c.fk_soc = s.rowid";
       $sql.= " AND d.fk_commande = c.rowid AND d.fk_product =".$product->id;
-      if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+      if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
       if ($socid)
         {
 	  $sql .= " AND c.fk_soc = ".$socid;
@@ -162,7 +162,7 @@ if ($_GET["id"] || $_GET["ref"])
 		  print '<td><a href="'.DOL_URL_ROOT.'/fourn/commande/fiche.php?id='.$objp->commandeid.'">'.img_object($langs->trans("ShowOrder"),"order").' ';
 		  print $objp->ref;
 		  print "</a></td>\n";
-		  print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44).'</a></td>';
+		  print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44).'</a></td>';
 		  print "<td>".$objp->code_client."</td>\n";
 		  print "<td align=\"center\">";
 		  print dolibarr_print_date($objp->date)."</td>";
diff --git a/htdocs/product/stats/contrat.php b/htdocs/product/stats/contrat.php
index 751f50100ae..8cf3276811c 100644
--- a/htdocs/product/stats/contrat.php
+++ b/htdocs/product/stats/contrat.php
@@ -118,14 +118,14 @@ if ($_GET["id"] || $_GET["ref"])
         print '</div>';
         
 
-        $sql = "SELECT distinct(s.nom), s.idp, s.code_client, c.rowid, ";
+        $sql = "SELECT distinct(s.nom), s.rowid as socid, s.code_client, c.rowid, ";
         $sql.= " ".$db->pdate("c.datec")." as date, c.statut as statut, c.rowid as contratid";
         if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."contratdet as d";
         if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-		    $sql.= " WHERE c.fk_soc = s.idp";
+		    $sql.= " WHERE c.fk_soc = s.rowid";
         $sql.= " AND d.fk_contrat = c.rowid AND d.fk_product =".$product->id;
-        if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+        if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
         if ($socid)
         {
             $sql .= " AND c.fk_soc = $socid";
@@ -166,7 +166,7 @@ if ($_GET["id"] || $_GET["ref"])
                     print '<td><a href="'.DOL_URL_ROOT.'/contrat/fiche.php?id='.$objp->contratid.'">'.img_object($langs->trans("ShowContract"),"contract").' ';
                     print $objp->rowid;
                     print "</a></td>\n";
-                    print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44).'</a></td>';
+                    print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44).'</a></td>';
                     print "<td>".$objp->code_client."</td>\n";
                     print "<td align=\"center\">";
                     print dolibarr_print_date($objp->date)."</td>";
diff --git a/htdocs/product/stats/facture.php b/htdocs/product/stats/facture.php
index 7bb226e7b3d..70ecc07d11b 100644
--- a/htdocs/product/stats/facture.php
+++ b/htdocs/product/stats/facture.php
@@ -115,14 +115,14 @@ if ($_GET["id"] || $_GET["ref"])
         print '</div>';
         
 
-        $sql = "SELECT distinct(s.nom), s.idp, s.code_client, f.facnumber, f.amount as amount,";
+        $sql = "SELECT distinct(s.nom), s.rowid as socid, s.code_client, f.facnumber, f.amount as amount,";
         $sql.= " ".$db->pdate("f.datef")." as date, f.paye, f.fk_statut as statut, f.rowid as facid";
         if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as d";
         if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-        $sql.= " WHERE f.fk_soc = s.idp";
+        $sql.= " WHERE f.fk_soc = s.rowid";
         $sql.= " AND d.fk_facture = f.rowid AND d.fk_product =".$product->id;
-        if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+        if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
         if ($socid)
         {
             $sql .= " AND f.fk_soc = $socid";
@@ -141,7 +141,7 @@ if ($_GET["id"] || $_GET["ref"])
             print "<table class=\"noborder\" width=\"100%\">";
 
             print '<tr class="liste_titre">';
-            print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"s.idp","","&amp;id=".$_GET["id"],'',$sortfield);
+            print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"s.rowid","","&amp;id=".$_GET["id"],'',$sortfield);
             print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&amp;id=".$_GET["id"],'',$sortfield);
             print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","","&amp;id=".$_GET["id"],'',$sortfield);
             print_liste_field_titre($langs->trans("DateCreation"),$_SERVER["PHP_SELF"],"f.datef","","&amp;id=".$_GET["id"],'align="center"',$sortfield);
@@ -161,7 +161,7 @@ if ($_GET["id"] || $_GET["ref"])
                     print '<td><a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$objp->facid.'">'.img_object($langs->trans("ShowBill"),"bill").' ';
                     print $objp->facnumber;
                     print "</a></td>\n";
-                    print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44).'</a></td>';
+                    print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44).'</a></td>';
                     print "<td>".$objp->code_client."</td>\n";
                     print "<td align=\"center\">";
                     print dolibarr_print_date($objp->date)."</td>";
diff --git a/htdocs/product/stats/facture_fournisseur.php b/htdocs/product/stats/facture_fournisseur.php
index b7b9fa15f11..dd186934b90 100644
--- a/htdocs/product/stats/facture_fournisseur.php
+++ b/htdocs/product/stats/facture_fournisseur.php
@@ -116,14 +116,14 @@ if ($_GET["id"] || $_GET["ref"])
         print '</div>';
         
 
-        $sql = "SELECT distinct(s.nom), s.idp, s.code_client, f.facnumber, f.amount as amount,";
+        $sql = "SELECT distinct(s.nom), s.rowid as socid, s.code_client, f.facnumber, f.amount as amount,";
         $sql.= " ".$db->pdate("f.datef")." as date, f.paye, f.fk_statut as statut, f.rowid as facid";
         if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."facture_fourn_det as d";
         if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-        $sql.= " WHERE f.fk_soc = s.idp";
+        $sql.= " WHERE f.fk_soc = s.rowid";
         $sql.= " AND d.fk_facture_fourn = f.rowid AND d.fk_product =".$product->id;
-        if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+        if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
         if ($socid)
         {
             $sql .= " AND f.fk_soc = $socid";
@@ -142,7 +142,7 @@ if ($_GET["id"] || $_GET["ref"])
             print "<table class=\"noborder\" width=\"100%\">";
 
             print '<tr class="liste_titre">';
-            print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"s.idp","","&amp;id=".$_GET["id"],'',$sortfield);
+            print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"s.rowid","","&amp;id=".$_GET["id"],'',$sortfield);
             print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&amp;id=".$_GET["id"],'',$sortfield);
             print_liste_field_titre($langs->trans("SupplierCode"),$_SERVER["PHP_SELF"],"s.code_client","","&amp;id=".$_GET["id"],'',$sortfield);
             print_liste_field_titre($langs->trans("DateCreation"),$_SERVER["PHP_SELF"],"f.datef","","&amp;id=".$_GET["id"],'align="center"',$sortfield);
@@ -162,7 +162,7 @@ if ($_GET["id"] || $_GET["ref"])
                     print '<td><a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$objp->facid.'">'.img_object($langs->trans("ShowBill"),"bill").' ';
                     print $objp->facnumber;
                     print "</a></td>\n";
-                    print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44).'</a></td>';
+                    print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44).'</a></td>';
                     print "<td>".$objp->code_client."</td>\n";
                     print "<td align=\"center\">";
                     print dolibarr_print_date($objp->date)."</td>";
diff --git a/htdocs/product/stats/propal.php b/htdocs/product/stats/propal.php
index 84ab83a85d0..1a1f7164185 100644
--- a/htdocs/product/stats/propal.php
+++ b/htdocs/product/stats/propal.php
@@ -119,14 +119,14 @@ if ($_GET["id"] || $_GET["ref"])
         print '</div>';
 
 
-        $sql = "SELECT distinct(s.nom), s.idp, p.rowid as propalid, p.ref, p.total as amount,";
+        $sql = "SELECT distinct(s.nom), s.rowid as socid, p.rowid as propalid, p.ref, p.total as amount,";
 				$sql.= $db->pdate("p.datec")." as date, p.fk_statut as statut";
 				if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."propaldet as d";
         if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-				$sql.= " WHERE p.fk_soc = s.idp";
+				$sql.= " WHERE p.fk_soc = s.rowid";
         $sql.= " AND d.fk_propal = p.rowid AND d.fk_product =".$product->id;
-        if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+        if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
         if ($socid)
         {
             $sql .= " AND p.fk_soc = $socid";
@@ -165,7 +165,7 @@ if ($_GET["id"] || $_GET["ref"])
                     print '<td><a href="'.DOL_URL_ROOT.'/comm/propal.php?propalid='.$objp->propalid.'">'.img_object($langs->trans("ShowPropal"),"propal").' ';
                     print $objp->ref;
                     print "</a></td>\n";
-                    print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44).'</a></td>';
+                    print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44).'</a></td>';
                     print "<td align=\"center\">";
                     print dolibarr_print_date($objp->date)."</td>";
                     print "<td align=\"right\">".price($objp->amount)."</td>\n";
diff --git a/htdocs/projet/index.php b/htdocs/projet/index.php
index 9ae0bb01a2f..f39367ce9a5 100644
--- a/htdocs/projet/index.php
+++ b/htdocs/projet/index.php
@@ -111,15 +111,15 @@ print_liste_field_titre($langs->trans("Company"),"index.php","s.nom","","","",$s
 print '<td align="right">'.$langs->trans("Nb").'</td>';
 print "</tr>\n";
 
-$sql = "SELECT s.nom, s.idp, count(p.rowid)";
+$sql = "SELECT s.nom, s.rowid as socid, count(p.rowid)";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."projet as p";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql .= " WHERE p.fk_soc = s.idp";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+$sql .= " WHERE p.fk_soc = s.rowid";
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 if ($socid)
 { 
-  $sql .= " AND s.idp = $socid"; 
+  $sql .= " AND s.rowid = ".$socid; 
 }
 $sql .= " GROUP BY s.nom";
 //$sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit, $offset);
diff --git a/htdocs/projet/liste.php b/htdocs/projet/liste.php
index 2de6192adc8..335f3a0859d 100644
--- a/htdocs/projet/liste.php
+++ b/htdocs/projet/liste.php
@@ -70,15 +70,15 @@ $pagenext = $page + 1;
 llxHeader();
 
 $sql = "SELECT p.rowid as projectid, p.ref, p.title, ".$db->pdate("p.dateo")." as do";
-$sql .= " , s.nom, s.idp, s.client";
+$sql .= ", s.nom, s.rowid as socid, s.client";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."projet as p";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql .= " WHERE p.fk_soc = s.idp";
-if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+$sql .= " WHERE p.fk_soc = s.rowid";
+if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 if ($socid)
 { 
-  $sql .= " AND s.idp = ".$socid; 
+  $sql .= " AND s.rowid = ".$socid; 
 }
 if ($_GET["search_ref"])
 {
@@ -136,7 +136,7 @@ if ($resql)
       print '<td>';
       print img_object($langs->trans("ShowCompany"),"company");
       
-      print '&nbsp;<a href="'.DOL_URL_ROOT.'/soc.php?socid='.$objp->idp.'">'.$objp->nom.'</a></td>';
+      print '&nbsp;<a href="'.DOL_URL_ROOT.'/soc.php?socid='.$objp->socid.'">'.$objp->nom.'</a></td>';
       print '<td>&nbsp;</td>';
       print "</tr>\n";
       
diff --git a/htdocs/projet/tasks/index.php b/htdocs/projet/tasks/index.php
index ffc49c2b49f..6f949ee1408 100644
--- a/htdocs/projet/tasks/index.php
+++ b/htdocs/projet/tasks/index.php
@@ -68,7 +68,7 @@ if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND p.fk_soc
 
 if ($socid)
 { 
-  $sql .= " AND s.idp = $socid"; 
+  $sql .= " AND s.rowid = ".$socid; 
 }
 $sql .= " GROUP BY p.rowid";
 
@@ -124,7 +124,7 @@ if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND p.fk_soc
 
 if ($socid)
 { 
-  $sql .= " AND s.idp = $socid"; 
+  $sql .= " AND s.rowid = ".$socid; 
 }
 $sql .= " GROUP BY p.rowid";
 
diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php
index e39cf6b2c4c..b9ff715d71f 100644
--- a/htdocs/propal.class.php
+++ b/htdocs/propal.class.php
@@ -525,7 +525,7 @@ class Propal extends CommonObject
                 // Affectation au projet
                 if ($resql && $this->projetidp)
                 {
-                    $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_projet=$this->projetidp WHERE ref='$this->ref'";
+                    $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_projet=".$this->projetidp." WHERE ref='".$this->ref."'";
                     $result=$this->db->query($sql);
                 }
 
@@ -1962,7 +1962,7 @@ class Propal extends CommonObject
 
 		// Charge tableau des id de soci�t� socids
 		$socids = array();
-		$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10";
+		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10";
 		$resql = $this->db->query($sql);
 		if ($resql)
 		{
diff --git a/htdocs/prospect.class.php b/htdocs/prospect.class.php
index eeb3664d249..5711cfba6d0 100644
--- a/htdocs/prospect.class.php
+++ b/htdocs/prospect.class.php
@@ -67,12 +67,12 @@ class Prospect extends Societe
         
         $this->nb=array("customers" => 0,"prospects" => 0);
 
-        $sql = "SELECT count(s.idp) as nb, s.client";
+        $sql = "SELECT count(s.rowid) as nb, s.client";
         if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
         if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
         $sql.= " WHERE s.client in (1,2)";
-        if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+        if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
         $sql.= " GROUP BY s.client";
         $resql=$this->db->query($sql);
         if ($resql)
diff --git a/htdocs/public/dons/depenses_code.php b/htdocs/public/dons/depenses_code.php
index 6d8223e6aac..5d6232bb94e 100644
--- a/htdocs/public/dons/depenses_code.php
+++ b/htdocs/public/dons/depenses_code.php
@@ -33,7 +33,7 @@ $conf->db->pass = $dolibarr_main_db_pass;
 $db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name);
 $sql = "SELECT ".$db->pdate("f.datef")." as datef, s.nom, f.total, f.note, f.paye";
 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s";
-$sql .= " WHERE f.fk_soc = s.idp ORDER BY f.datef DESC";
+$sql .= " WHERE f.fk_soc = s.rowid ORDER BY f.datef DESC";
 
 if ( $db->query( $sql) )
 {
diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php
index 07e179735ef..e5c3e697ba3 100644
--- a/htdocs/societe.class.php
+++ b/htdocs/societe.class.php
@@ -401,7 +401,7 @@ class Societe
                 $sql .= ", code_compta_fournisseur = ".($this->code_compta_fournisseur?"'".addslashes($this->code_compta_fournisseur)."'":"null");
             }
             if ($user) $sql .= ",fk_user_modif = '".$user->id."'";
-            $sql .= " WHERE idp = '" . $id ."'";
+            $sql .= " WHERE rowid = '" . $id ."'";
 
         	
 			      dolibarr_syslog("Societe::update sql=".$sql);
@@ -499,7 +499,7 @@ class Societe
 			}
 		}
 
-		$sql = 'SELECT s.idp, s.nom, s.address,'.$this->db->pdate('s.datec').' as dc, prefix_comm';
+		$sql = 'SELECT s.rowid, s.nom, s.address,'.$this->db->pdate('s.datec').' as dc, prefix_comm';
 		// multiprix
 		if($conf->global->PRODUIT_MULTIPRICES == 1)
 			$sql .= ', s.price_level';
@@ -521,7 +521,7 @@ class Societe
 		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
 		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
 		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
-		$sql .= ' WHERE s.idp = '.$socid;
+		$sql .= ' WHERE s.rowid = '.$socid;
 		$resql=$this->db->query($sql);
 		if ($resql)
 		{
@@ -529,7 +529,7 @@ class Societe
 			{
 				$obj = $this->db->fetch_object($resql);
 
-				$this->id = $obj->idp;
+				$this->id = $obj->rowid;
 
 				$this->date_update = $obj->date_update;
 
@@ -636,7 +636,7 @@ class Societe
         $sql .= ", p.libelle as pays, p.code, s.nom as socname";
         $sql .= " FROM ".MAIN_DB_PREFIX."societe_adresse_livraison as l";
         $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON l.fk_pays = p.rowid";
-        $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON l.fk_societe = s.idp";
+        $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON l.fk_societe = s.rowid";
         $sql .= " WHERE l.rowid = ".$id;
 
         $result = $this->db->query($sql) ;
@@ -707,7 +707,7 @@ class Societe
             }
 
             $sql = "DELETE from ".MAIN_DB_PREFIX."societe ";
-            $sql .= " WHERE idp = " . $id .";";
+            $sql .= " WHERE rowid = " . $id .";";
 
             if ($this->db->query($sql))
             {
@@ -811,7 +811,7 @@ class Societe
 	 */
 	function attribute_prefix()
 	{
-		$sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE idp = '".$this->id."'";
+		$sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE rowid = '".$this->id."'";
 		$resql=$this->db->query( $sql);
 		if ($resql)
 		{
@@ -831,7 +831,7 @@ class Societe
 					$this->db->free($resql);
 					if (! $obj->nb)
 					{
-						$sql = "UPDATE ".MAIN_DB_PREFIX."societe set prefix_comm='$prefix' WHERE idp='$this->id'";
+						$sql = "UPDATE ".MAIN_DB_PREFIX."societe set prefix_comm='".$prefix."' WHERE rowid='".$this->id."'";
 	
 						if ( $this->db->query( $sql) )
 						{
@@ -900,7 +900,7 @@ class Societe
       {
 	$sql  = "UPDATE ".MAIN_DB_PREFIX."societe ";
 	$sql .= " SET client = 1";
-	$sql .= " WHERE idp = " . $this->id .";";
+	$sql .= " WHERE rowid = " . $this->id .";";
 
 	return $this->db->query($sql);
       }
@@ -934,7 +934,7 @@ class Societe
 			// Positionne remise courante
 			$sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
 			$sql.= " SET remise_client = '".$remise."'";
-			$sql.= " WHERE idp = " . $this->id .";";
+			$sql.= " WHERE rowid = " . $this->id .";";
 			$resql=$this->db->query($sql);
 			if (! $resql)
 			{
@@ -1062,7 +1062,7 @@ class Societe
       {
 	$sql  = "UPDATE ".MAIN_DB_PREFIX."societe ";
 	$sql .= " SET price_level = '".$price_level."'";
-	$sql .= " WHERE idp = " . $this->id .";";
+	$sql .= " WHERE rowid = " . $this->id .";";
 
 	$this->db->query($sql);
 
@@ -1173,7 +1173,7 @@ class Societe
   function get_nom($id)
   {
 
-    $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE idp='$id';";
+    $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE rowid='".$id."';";
 
     $result = $this->db->query($sql);
 
@@ -1218,7 +1218,7 @@ class Societe
 	{
 		$contact_email = array();
 	
-		$sql = "SELECT idp, email, name, firstname";
+		$sql = "SELECT rowid, email, name, firstname";
 		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
 		$sql.= " WHERE fk_soc = '".$this->id."'";
 		$resql=$this->db->query($sql);
@@ -1231,7 +1231,7 @@ class Societe
 				while ($i < $nump)
 				{
 					$obj = $this->db->fetch_object($resql);
-					$contact_email[$obj->idp] = trim($obj->firstname." ".$obj->name)." &lt;".$obj->email."&gt;";
+					$contact_email[$obj->rowid] = trim($obj->firstname." ".$obj->name)." &lt;".$obj->email."&gt;";
 					$i++;
 				}
 			}
@@ -1252,7 +1252,7 @@ class Societe
 	{
 		$contacts = array();
 	
-		$sql = "SELECT idp, name, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = '$this->id'";
+		$sql = "SELECT rowid, name, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = '".$this->id."'";
 		$resql=$this->db->query($sql);
 		if ($resql)
 		{
@@ -1263,7 +1263,7 @@ class Societe
 				while ($i < $nump)
 				{
 					$obj = $this->db->fetch_object($resql);
-					$contacts[$obj->idp] = "$obj->firstname $obj->name";
+					$contacts[$obj->rowid] = $obj->firstname." ".$obj->name;
 					$i++;
 				}
 			}
@@ -1283,7 +1283,7 @@ class Societe
     function contact_get_email($rowid)
     {
 
-        $sql = "SELECT idp, email, name, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE idp = '$rowid'";
+        $sql = "SELECT rowid, email, name, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE rowid = '".$rowid."'";
 
         if ($this->db->query($sql) )
         {
@@ -1601,7 +1601,7 @@ class Societe
         {
             $sql  = "UPDATE ".MAIN_DB_PREFIX."societe ";
             $sql .= " SET parent = ".$id;
-            $sql .= " WHERE idp = " . $this->id .";";
+            $sql .= " WHERE rowid = " . $this->id .";";
 
             if ( $this->db->query($sql) )
             {
@@ -1625,7 +1625,7 @@ class Societe
         {
             $sql  = "UPDATE ".MAIN_DB_PREFIX."societe ";
             $sql .= " SET parent = null";
-            $sql .= " WHERE idp = " . $this->id .";";
+            $sql .= " WHERE rowid = " . $this->id .";";
 
             if ( $this->db->query($sql) )
             {
@@ -1751,10 +1751,10 @@ class Societe
     */
     function info($id)
     {
-        $sql = "SELECT s.idp, s.nom, ".$this->db->pdate("datec")." as datec, ".$this->db->pdate("datea")." as datea,";
+        $sql = "SELECT s.rowid, s.nom, ".$this->db->pdate("datec")." as datec, ".$this->db->pdate("datea")." as datea,";
         $sql.= " fk_user_creat, fk_user_modif";
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
-        $sql.= " WHERE s.idp = ".$id;
+        $sql.= " WHERE s.rowid = ".$id;
 
         $result=$this->db->query($sql);
         if ($result)
@@ -1763,7 +1763,7 @@ class Societe
             {
                 $obj = $this->db->fetch_object($result);
 
-                $this->id = $obj->idp;
+                $this->id = $obj->rowid;
 
                 if ($obj->fk_user_creat) {
                     $cuser = new User($this->db, $obj->fk_user_creat);
diff --git a/htdocs/societe.php b/htdocs/societe.php
index 2aae951499d..b5ee0495eb2 100644
--- a/htdocs/societe.php
+++ b/htdocs/societe.php
@@ -38,7 +38,7 @@ $langs->load("suppliers");
 
 // S�curit� d'acc�s client et commerciaux
 $socid = restrictedArea($user, 'societe','','',1);
-
+print 'socid '.$socid;
 $search_nom=isset($_GET["search_nom"])?$_GET["search_nom"]:$_POST["search_nom"];
 $search_ville=isset($_GET["search_ville"])?$_GET["search_ville"]:$_POST["search_ville"];
 
@@ -70,7 +70,7 @@ if ($mode == 'search')
 {
     $_POST["search_nom"]="$socname";
 
-    $sql = "SELECT s.idp";
+    $sql = "SELECT s.rowid";
     if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
     $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
     if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
@@ -80,7 +80,7 @@ if ($mode == 'search')
 	$sql.= " OR s.email like '%".$socname."%'";
 	$sql.= " OR s.url like '%".$socname."%'";
     $sql.= ")";
-    if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+    if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 
     $result=$db->query($sql);
     if ($result)
@@ -88,8 +88,8 @@ if ($mode == 'search')
         if ($db->num_rows($result) == 1)
         {
             $obj = $db->fetch_object($result);
-            $socid = $obj->idp;
-            header("Location: soc.php?socid=$socid");
+            $socid = $obj->rowid;
+            header("Location: soc.php?socid=".$socid."");
             exit;
         }
         $db->free($result);
@@ -128,7 +128,7 @@ if (isset($_POST["button_removefilter_x"]))
 */ 
 $title=$langs->trans("ListOfThirdParties");
 
-$sql = "SELECT s.idp, s.nom, s.ville, ".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea";
+$sql = "SELECT s.rowid, s.nom, s.ville, ".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea";
 $sql.= ", st.libelle as stcomm, s.prefix_comm, s.client, s.fournisseur, s.siren";
 if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
@@ -137,7 +137,7 @@ if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PR
 $sql.= " WHERE s.fk_stcomm = st.id";
 if ($socid)
 {
-  $sql .= " AND s.idp = ".$socid;
+  $sql .= " AND s.rowid = ".$socid;
 }
 
 if ($socname)
@@ -151,7 +151,7 @@ if (strlen($stcomm)) {
 
 if (!$user->rights->commercial->client->voir && !$socid) //restriction
 {
-	$sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id;
+	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 }
 
 if ($search_nom)
@@ -219,19 +219,19 @@ if ($result)
       $obj = $db->fetch_object();    
       $var=!$var;    
       print "<tr $bc[$var]><td>";
-      print "<a href=\"soc.php?socid=$obj->idp\">";
+      print "<a href=\"soc.php?socid=".$obj->rowid."\">";
       print img_object($langs->trans("ShowCompany"),"company");
-      print "</a>&nbsp;<a href=\"soc.php?socid=$obj->idp\">".stripslashes($obj->nom)."</a></td>\n";
+      print "</a>&nbsp;<a href=\"soc.php?socid=".$obj->rowid."\">".stripslashes($obj->nom)."</a></td>\n";
       print "<td>".$obj->ville."&nbsp;</td>\n";
       print "<td>".$obj->siren."&nbsp;</td>\n";
       print '<td align="center">';
       if ($obj->client==1)
 	{
-	  print "<a href=\"comm/fiche.php?socid=$obj->idp\">".$langs->trans("Customer")."</a>\n";
+	  print "<a href=\"comm/fiche.php?socid=".$obj->rowid."\">".$langs->trans("Customer")."</a>\n";
 	}
       elseif ($obj->client==2)
 	{
-	  print "<a href=\"comm/prospect/fiche.php?id=$obj->idp\">".$langs->trans("Prospect")."</a>\n";
+	  print "<a href=\"comm/prospect/fiche.php?id=".$obj->rowid."\">".$langs->trans("Prospect")."</a>\n";
 	}
       else
 	{
@@ -240,7 +240,7 @@ if ($result)
       print "</td><td align=\"center\">";
       if ($obj->fournisseur)
 	{
-	  print '<a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$obj->idp.'">'.$langs->trans("Supplier").'</a>';
+	  print '<a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$obj->rowid.'">'.$langs->trans("Supplier").'</a>';
 	}
       else
 	{
diff --git a/htdocs/societe/lien.php b/htdocs/societe/lien.php
index aa42425d6b1..e5b1c0605de 100644
--- a/htdocs/societe/lien.php
+++ b/htdocs/societe/lien.php
@@ -226,7 +226,7 @@ if($_GET["socid"])
     
             $title=$langs->trans("CompanyList");
     
-            $sql = "SELECT s.idp, s.nom, s.ville, s.prefix_comm, s.client, s.fournisseur, te.libelle";
+            $sql = "SELECT s.rowid as socid, s.nom, s.ville, s.prefix_comm, s.client, s.fournisseur, te.libelle";
             $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
             $sql .= " , ".MAIN_DB_PREFIX."c_typent as te";
             $sql .= "  WHERE s.fk_typent = te.id";
@@ -304,7 +304,7 @@ if($_GET["socid"])
     
                     print '</td>';
                     // Lien S�lectionner
-                    print '<td align="center"><a href="lien.php?socid='.$_GET["socid"].'&amp;select='.$obj->idp.'">'.$langs->trans("Select").'</a>';
+                    print '<td align="center"><a href="lien.php?socid='.$_GET["socid"].'&amp;select='.$obj->socid.'">'.$langs->trans("Select").'</a>';
                     print '</td>';
     
                     print '</tr>'."\n";
diff --git a/htdocs/societe/notify/fiche.php b/htdocs/societe/notify/fiche.php
index 10dab857336..406eb8149a9 100644
--- a/htdocs/societe/notify/fiche.php
+++ b/htdocs/societe/notify/fiche.php
@@ -221,9 +221,9 @@ if ( $soc->fetch($soc->id) )
     print '</tr>';
     
     // Liste
-    $sql = "SELECT c.idp as id, c.name, c.firstname, a.titre, n.rowid";
+    $sql = "SELECT c.rowid as id, c.name, c.firstname, a.titre, n.rowid";
     $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify_def as n";
-    $sql.= " WHERE n.fk_contact = c.idp AND a.rowid = n.fk_action AND n.fk_soc = ".$soc->id;
+    $sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action AND n.fk_soc = ".$soc->id;
     
     $resql=$db->query($sql);
     if ($resql)
diff --git a/htdocs/societe/notify/index.php b/htdocs/societe/notify/index.php
index 75b92352582..8a8320e456c 100644
--- a/htdocs/societe/notify/index.php
+++ b/htdocs/societe/notify/index.php
@@ -62,12 +62,12 @@ $pagenext = $page + 1;
 
 llxHeader();
 
-$sql = "SELECT s.nom, s.idp, c.name, c.firstname, a.titre,n.rowid FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify_def as n, ".MAIN_DB_PREFIX."societe as s";
-$sql .= " WHERE n.fk_contact = c.idp AND a.rowid = n.fk_action";
-$sql .= " AND n.fk_soc = s.idp";
+$sql = "SELECT s.nom, s.rowid as socid, c.name, c.firstname, a.titre,n.rowid FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify_def as n, ".MAIN_DB_PREFIX."societe as s";
+$sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
+$sql .= " AND n.fk_soc = s.rowid";
 if ($socid > 0)
 {
-	$sql .= " AND s.idp = " . $user->societe_id;
+	$sql .= " AND s.rowid = " . $user->societe_id;
 }
 $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit, $offset);
 
@@ -94,7 +94,7 @@ if ($result)
 		$var=!$var;
 	
 		print "<tr $bc[$var]>";
-		print "<td><a href=\"fiche.php?socid=$obj->idp\">$obj->nom</A></td>\n";
+		print "<td><a href=\"fiche.php?socid=".$obj->socid."\">$obj->nom</A></td>\n";
 		print "<td>".$obj->firstname." ".$obj->name."</td>\n";
 		print "<td>".$obj->titre."</td>\n";
 		print "</tr>\n";
diff --git a/htdocs/socnote.php b/htdocs/socnote.php
index ca8ecfea9de..0abfcb63899 100644
--- a/htdocs/socnote.php
+++ b/htdocs/socnote.php
@@ -43,7 +43,7 @@ $socid = restrictedArea($user, 'societe', $socid);
 
 if ($_POST["action"] == 'add')
 {
-  $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET note='".addslashes($_POST["note"])."' WHERE idp=".$_POST["socid"];
+  $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET note='".addslashes($_POST["note"])."' WHERE rowid=".$_POST["socid"];
   $result = $db->query($sql);
 
   $_GET["socid"]=$_POST["socid"];   // Pour retour sur fiche
diff --git a/htdocs/telephonie/adsl/fiche.php b/htdocs/telephonie/adsl/fiche.php
index 6a4c3ec7136..4408bd98ee6 100644
--- a/htdocs/telephonie/adsl/fiche.php
+++ b/htdocs/telephonie/adsl/fiche.php
@@ -321,7 +321,7 @@ if ($_GET["action"] == 'create')
 
   print '<tr><td width="20%">Client</td><td >';
   $ff = array();
-  $sql = "SELECT idp, nom, ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1 ORDER BY nom ";
+  $sql = "SELECT rowid, nom, ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1 ORDER BY nom ";
   if ( $db->query( $sql) )
     {
       $num = $db->num_rows();
@@ -412,7 +412,7 @@ elseif ($_GET["action"] == 'create_line' && $_GET["client"] > 0)
 	  
 	  print '<tr><td width="20%">Client (Agence/Filiale)</td><td >';
 	  $ff = array();
-	  $sql = "SELECT idp, nom, ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1 ORDER BY nom ";
+	  $sql = "SELECT rowid, nom, ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1 ORDER BY nom ";
 	  if ( $db->query( $sql) )
 	    {
 	      $num = $db->num_rows();
@@ -433,7 +433,7 @@ elseif ($_GET["action"] == 'create_line' && $_GET["client"] > 0)
 	  
 	  print '<tr><td width="20%">Client � facturer</td><td >';
 	  $ff = array();
-	  $sql = "SELECT idp, nom, ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1 ORDER BY nom ";
+	  $sql = "SELECT rowid, nom, ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1 ORDER BY nom ";
 	  if ( $db->query( $sql) )
 	    {
 	      $num = $db->num_rows();
@@ -485,9 +485,9 @@ elseif ($_GET["action"] == 'create_line' && $_GET["client"] > 0)
 
 	  print '<tr><td width="20%">Fournisseur</td><td >';
 	  $ff = array();
-	  $sql = "SELECT f.idp, f.nom FROM ".MAIN_DB_PREFIX."societe as f";
+	  $sql = "SELECT f.rowid, f.nom FROM ".MAIN_DB_PREFIX."societe as f";
 	  $sql .= " , ".MAIN_DB_PREFIX."telephonie_adsl_fournisseur as fa";
-	  $sql .= " WHERE fa.commande_active = 1 AND fa.fk_soc = f.idp ORDER BY f.nom ";
+	  $sql .= " WHERE fa.commande_active = 1 AND fa.fk_soc = f.rowid ORDER BY f.nom ";
 	  if ( $db->query( $sql) )
 	    {
 	      $num = $db->num_rows();
diff --git a/htdocs/telephonie/adsl/liste.php b/htdocs/telephonie/adsl/liste.php
index 389165298ff..57f9a93e181 100644
--- a/htdocs/telephonie/adsl/liste.php
+++ b/htdocs/telephonie/adsl/liste.php
@@ -54,11 +54,11 @@ if ($sortfield == "") $sortfield="la.statut ASC, s.nom";
  */
 
 $sql = "SELECT la.rowid, fk_client, s.nom as nom, la.numero_ligne, la.statut, t.intitule";
-$sql .= " , s.idp";
+$sql .= " , s.rowid as socid";
 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_adsl_ligne as la";
 $sql .= " ,  ".MAIN_DB_PREFIX."societe as s";
 $sql .= " ,  ".MAIN_DB_PREFIX."telephonie_adsl_type as t";
-$sql .= " WHERE la.fk_client = s.idp";
+$sql .= " WHERE la.fk_client = s.rowid";
 $sql .= " AND t.rowid = la.fk_type";
 
 if ($_GET["search_ligne"])
@@ -133,9 +133,9 @@ if ($resql)
 
       print '<a href="fiche.php?id='.$obj->rowid.'">'.dolibarr_print_phone($obj->numero_ligne)."</a></td>\n";
 
-      print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("Fiche Compta"),"bill")."</a> ";
+      print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("Fiche Compta"),"bill")."</a> ";
 
-      print '&nbsp;<a href="'.DOL_URL_ROOT.'/telephonie/comm/fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td>';
+      print '&nbsp;<a href="'.DOL_URL_ROOT.'/telephonie/comm/fiche.php?socid='.$obj->socid.'">'.$obj->nom.'</a></td>';
       print '<td>'.$obj->intitule.'</td>';
 
       print '<td align="center">'.$ligne->statuts[$obj->statut]."</td>\n";
diff --git a/htdocs/telephonie/ca/gain.php b/htdocs/telephonie/ca/gain.php
index 6aeba54558f..f4419cf7657 100644
--- a/htdocs/telephonie/ca/gain.php
+++ b/htdocs/telephonie/ca/gain.php
@@ -51,7 +51,7 @@ if ($sortfield == "") $sortfield="ca";
 $sql = "SELECT nom, ca, gain, cout, marge, fk_client_comm";
 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_client_stats";
 $sql .= " , " .MAIN_DB_PREFIX."societe";
-$sql .= " WHERE idp = fk_client_comm";
+$sql .= " WHERE rowid = fk_client_comm";
 $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset);
 $resql = $db->query($sql);
 if ($resql)
diff --git a/htdocs/telephonie/client/contacts.php b/htdocs/telephonie/client/contacts.php
index 0babd321126..af898650b24 100644
--- a/htdocs/telephonie/client/contacts.php
+++ b/htdocs/telephonie/client/contacts.php
@@ -58,17 +58,17 @@ $pagenext = $page + 1;
  * Mode Liste
  *
  */
-$sql = "SELECT distinct cont.email, cont.idp, cont.name, cont.firstname, s.nom, s.idp as socid";
+$sql = "SELECT distinct cont.email, cont.rowid, cont.name, cont.firstname, s.nom, s.rowid as socid";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 
 $sql .= ",".MAIN_DB_PREFIX."societe_perms as sp";
 $sql .= ",".MAIN_DB_PREFIX."telephonie_contrat_contact_facture as cf";
 $sql .= ",".MAIN_DB_PREFIX."socpeople as cont";
 
-$sql .= " WHERE cont.fk_soc = s.idp ";
-$sql .= " AND cf.fk_contact = cont.idp";
+$sql .= " WHERE cont.fk_soc = s.rowid ";
+$sql .= " AND cf.fk_contact = cont.rowid";
 
-$sql .= " AND s.idp = sp.fk_soc";
+$sql .= " AND s.rowid = sp.fk_soc";
 $sql .= " AND sp.fk_user = ".$user->id." AND sp.pread = 1";
 
 if ($_GET["search_client"])
@@ -83,7 +83,7 @@ if ($_GET["search_email"])
   $sql .= " AND cont.email LIKE '%".$sel."%'";
 }
 
-//$sql .= " GROUP BY s.idp";
+//$sql .= " GROUP BY s.rowid";
 $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset);
 
 $result = $db->query($sql);
@@ -132,7 +132,7 @@ if ($result)
       print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">'.$obj->nom.'</a></td>';
       print '<td>'.$obj->firstname.' '.$obj->name."</td>\n";
 
-      print '<td><a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->idp.'">';
+      print '<td><a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->rowid.'">';
       print $obj->email."</a></td>\n";
 
       print "</tr>\n";
diff --git a/htdocs/telephonie/client/factures.php b/htdocs/telephonie/client/factures.php
index 8ed14ebc350..d966bc1097f 100644
--- a/htdocs/telephonie/client/factures.php
+++ b/htdocs/telephonie/client/factures.php
@@ -109,13 +109,13 @@ if ($_GET["id"])
 	  $pagenext = $page + 1;
 	  
 	  $sql = "SELECT f.rowid, f.date, sum(f.cout_vente) as cout_vente, f.fk_facture";
-	  $sql .= " ,s.nom, s.idp";
+	  $sql .= " ,s.nom, s.rowid as socid";
 	  $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture as f";
 	  $sql .= " , ".MAIN_DB_PREFIX."societe as s";
 	  $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 	  
-	  $sql .= " WHERE s.idp = l.fk_soc_facture AND l.rowid = f.fk_ligne";
-	  $sql .= " AND s.idp = ".$soc->id;
+	  $sql .= " WHERE s.rowid = l.fk_soc_facture AND l.rowid = f.fk_ligne";
+	  $sql .= " AND s.rowid = ".$soc->id;
 	  $sql .= " GROUP BY f.fk_facture";
 	  $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset);
 	  
diff --git a/htdocs/telephonie/client/fiche.php b/htdocs/telephonie/client/fiche.php
index 7c859d5e468..63452cda0a4 100644
--- a/htdocs/telephonie/client/fiche.php
+++ b/htdocs/telephonie/client/fiche.php
@@ -168,10 +168,10 @@ if ($_GET["id"])
 	  $sql .= " , ".MAIN_DB_PREFIX."telephonie_contrat as c";
 	  $sql .= " , ".MAIN_DB_PREFIX."societe as ss";
 	  $sql .= " WHERE c.fk_client_comm = ".$soc->id;
-	  $sql .= " AND c.fk_soc = ss.idp ";
+	  $sql .= " AND c.fk_soc = ss.rowid ";
 	  $sql .= " AND l.fk_contrat = c.rowid";
 	  $sql .= " GROUP BY c.rowid";
-	  $sql .= " ORDER BY ss.idp ASC";
+	  $sql .= " ORDER BY ss.rowid ASC";
 	  
 	  $resql = $db->query($sql);
 
diff --git a/htdocs/telephonie/client/index.php b/htdocs/telephonie/client/index.php
index 2692cd80154..26ff56e19c6 100644
--- a/htdocs/telephonie/client/index.php
+++ b/htdocs/telephonie/client/index.php
@@ -56,10 +56,10 @@ print '</table>';
 
 print '<br />';
 
-$sql = "SELECT distinct s.idp ";
+$sql = "SELECT distinct s.rowid as socid ";
 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
-$sql .= " WHERE s.idp = l.fk_client_comm ";
+$sql .= " WHERE s.rowid = l.fk_client_comm ";
 $sql .= " AND l.fk_commercial_suiv = ".$user->id;
 $resql = $db->query($sql);
 if ($resql)
@@ -92,12 +92,12 @@ print '<br />';
  * Liste
  *
  */
-$sql = "SELECT s.idp as socid, s.nom, max(sc.datec) as dam";
+$sql = "SELECT s.rowid as socid, s.nom, max(sc.datec) as dam";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= ",".MAIN_DB_PREFIX."societe_consult as sc";
-$sql .= " WHERE s.idp = sc.fk_soc";
+$sql .= " WHERE s.rowid = sc.fk_soc";
 $sql .= " AND sc.fk_user = ".$user->id;
-$sql .= " GROUP BY s.idp";
+$sql .= " GROUP BY s.rowid";
 $sql .= " ORDER BY dam DESC LIMIT 10";
 
 $resql = $db->query($sql);
@@ -138,14 +138,14 @@ print '</td><td valign="top" width="70%" rowspan="3">';
  * Liste
  *
  */
-$sql = "SELECT s.idp as socid, s.nom, count(l.ligne) as ligne";
+$sql = "SELECT s.rowid as socid, s.nom, count(l.ligne) as ligne";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= ",".MAIN_DB_PREFIX."societe_perms as sp";
 
-$sql .= " WHERE l.fk_client_comm = s.idp ";
-$sql .= " AND s.idp = sp.fk_soc";
+$sql .= " WHERE l.fk_client_comm = s.rowid ";
+$sql .= " AND s.rowid = sp.fk_soc";
 $sql .= " AND sp.fk_user = ".$user->id." AND sp.pread = 1";
-$sql .= " GROUP BY s.idp";
+$sql .= " GROUP BY s.rowid";
 $sql .= " ORDER BY s.datec DESC LIMIT 10";
 
 $resql = $db->query($sql);
@@ -191,12 +191,12 @@ else
 print "<br />";
 /* Commentaires */
 
-$sql = "SELECT s.idp as socid, s.nom, c.commentaire";
+$sql = "SELECT s.rowid as socid, s.nom, c.commentaire";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."telephonie_societe_commentaire as c";
 $sql .= ",".MAIN_DB_PREFIX."societe_perms as sp";
 
-$sql .= " WHERE c.fk_soc = s.idp ";
-$sql .= " AND s.idp = sp.fk_soc";
+$sql .= " WHERE c.fk_soc = s.rowid ";
+$sql .= " AND s.rowid = sp.fk_soc";
 $sql .= " AND sp.fk_user = ".$user->id." AND sp.pread = 1";
 $sql .= " ORDER BY c.datec DESC LIMIT 10";
 
diff --git a/htdocs/telephonie/client/lignes.php b/htdocs/telephonie/client/lignes.php
index fbb60b06c5a..9284cac00cf 100644
--- a/htdocs/telephonie/client/lignes.php
+++ b/htdocs/telephonie/client/lignes.php
@@ -113,16 +113,16 @@ if ($_GET["id"])
 	  
 	  /* Lignes */
 	     
-	  $sql = "SELECT s.idp as socid, f.nom as fournisseur, s.nom";
+	  $sql = "SELECT s.rowid as socid, f.nom as fournisseur, s.nom";
 	  $sql .= ", ss.nom as agence, ss.ville, ss.code_client";
 	  $sql .= " , l.ligne,  l.statut, l.rowid, l.remise";
 	  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 	  $sql .= " , ".MAIN_DB_PREFIX."societe as ss";
 	  $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-	  $sql .= " WHERE l.fk_client_comm = s.idp AND l.fk_fournisseur = f.rowid";
-	  $sql .= " AND l.fk_soc = ss.idp ";
-	  $sql .= " AND s.idp = ".$soc->id;
-	  $sql .= " ORDER BY ss.idp ASC";
+	  $sql .= " WHERE l.fk_client_comm = s.rowid AND l.fk_fournisseur = f.rowid";
+	  $sql .= " AND l.fk_soc = ss.rowid ";
+	  $sql .= " AND s.rowid = ".$soc->id;
+	  $sql .= " ORDER BY ss.rowid ASC";
 
 	  $resql =  $db->query($sql);
 	  
diff --git a/htdocs/telephonie/client/liste.php b/htdocs/telephonie/client/liste.php
index 0f6f1f5b73e..27c15f1d989 100644
--- a/htdocs/telephonie/client/liste.php
+++ b/htdocs/telephonie/client/liste.php
@@ -58,11 +58,11 @@ $pagenext = $page + 1;
  *
  *
  */
-$sql = "SELECT s.idp as socid, s.nom, count(l.ligne) as ligne, cs.ca";
+$sql = "SELECT s.rowid as socid, s.nom, count(l.ligne) as ligne, cs.ca";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
-$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_perms as sp ON sp.fk_soc = s.idp ";
-$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."telephonie_client_stats as cs ON cs.fk_client_comm = s.idp";
-$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."telephonie_societe_ligne as l ON l.fk_client_comm = s.idp";
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_perms as sp ON sp.fk_soc = s.rowid ";
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."telephonie_client_stats as cs ON cs.fk_client_comm = s.rowid";
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."telephonie_societe_ligne as l ON l.fk_client_comm = s.rowid";
 
 $sql .= " WHERE sp.fk_user = ".$user->id." AND sp.pread = 1";
 
@@ -72,7 +72,7 @@ if ($_GET["search_client"])
   $sql .= " AND s.nom LIKE '%".$sel."%'";
 }
 
-$sql .= " GROUP BY s.idp";
+$sql .= " GROUP BY s.rowid";
 $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset);
 
 $result = $db->query($sql);
diff --git a/htdocs/telephonie/client/my.php b/htdocs/telephonie/client/my.php
index 340d7c2b664..b0a4b90c6da 100644
--- a/htdocs/telephonie/client/my.php
+++ b/htdocs/telephonie/client/my.php
@@ -58,10 +58,10 @@ $pagenext = $page + 1;
  *
  *
  */
-$sql = "SELECT s.idp as socid, s.nom, count(l.ligne) as ligne, cs.ca";
+$sql = "SELECT s.rowid as socid, s.nom, count(l.ligne) as ligne, cs.ca";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
-$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."telephonie_societe_ligne AS l ON l.fk_client_comm = s.idp";
-$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."telephonie_client_stats as cs ON cs.fk_client_comm = s.idp";
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."telephonie_societe_ligne AS l ON l.fk_client_comm = s.rowid";
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."telephonie_client_stats as cs ON cs.fk_client_comm = s.rowid";
 $sql .= " WHERE l.fk_commercial_suiv = ".$user->id; 
 
 if ($_GET["search_client"])
@@ -70,7 +70,7 @@ if ($_GET["search_client"])
   $sql .= " AND s.nom LIKE '%".$sel."%'";
 }
 
-$sql .= " GROUP BY s.idp";
+$sql .= " GROUP BY s.rowid";
 $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset);
 
 $result = $db->query($sql);
diff --git a/htdocs/telephonie/client/remises.php b/htdocs/telephonie/client/remises.php
index 2559a0d537d..39edce05975 100644
--- a/htdocs/telephonie/client/remises.php
+++ b/htdocs/telephonie/client/remises.php
@@ -55,14 +55,14 @@ $pagenext = $page + 1;
  *
  */
 
-$sql = "SELECT s.idp as socid, s.nom, r.amount";
+$sql = "SELECT s.rowid as socid, s.nom, r.amount";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= ",".MAIN_DB_PREFIX."telephonie_client_remise as r";
 $sql .= ",".MAIN_DB_PREFIX."societe_perms as sp";
 
-$sql .= " WHERE r.fk_client = s.idp ";
+$sql .= " WHERE r.fk_client = s.rowid ";
 $sql .= " AND r.fk_facture = 0";
-$sql .= " AND s.idp = sp.fk_soc";
+$sql .= " AND s.rowid = sp.fk_soc";
 $sql .= " AND sp.fk_user = ".$user->id." AND sp.pread = 1";
 
 if ($_GET["search_client"])
diff --git a/htdocs/telephonie/client/remisesdone.php b/htdocs/telephonie/client/remisesdone.php
index f9edcaae782..3733125482f 100644
--- a/htdocs/telephonie/client/remisesdone.php
+++ b/htdocs/telephonie/client/remisesdone.php
@@ -55,16 +55,16 @@ $pagenext = $page + 1;
  *
  */
 
-$sql = "SELECT s.idp as socid, s.nom, r.amount, f.facnumber, r.fk_facture";
+$sql = "SELECT s.rowid as socid, s.nom, r.amount, f.facnumber, r.fk_facture";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= ",".MAIN_DB_PREFIX."telephonie_client_remise as r";
 $sql .= ",".MAIN_DB_PREFIX."societe_perms as sp";
 $sql .= ",".MAIN_DB_PREFIX."facture as f";
 
-$sql .= " WHERE r.fk_client = s.idp ";
+$sql .= " WHERE r.fk_client = s.rowid ";
 $sql .= " AND r.fk_facture > 0";
 $sql .= " AND r.fk_facture = f.rowid";
-$sql .= " AND s.idp = sp.fk_soc";
+$sql .= " AND s.rowid = sp.fk_soc";
 $sql .= " AND sp.fk_user = ".$user->id." AND sp.pread = 1";
 
 if ($_GET["search_client"])
diff --git a/htdocs/telephonie/client/tarifs.php b/htdocs/telephonie/client/tarifs.php
index 4e0b35042a9..41d380da354 100644
--- a/htdocs/telephonie/client/tarifs.php
+++ b/htdocs/telephonie/client/tarifs.php
@@ -273,9 +273,9 @@ if ($_GET["id"])
 	  $sql .= "," . MAIN_DB_PREFIX."societe as s";
 	  $sql .= "," . MAIN_DB_PREFIX."user as u";
 	  
-	  $sql .= " WHERE t.rowid = tc.fk_tarif AND tc.fk_client = s.idp";
+	  $sql .= " WHERE t.rowid = tc.fk_tarif AND tc.fk_client = s.rowid";
    	  $sql .= " AND u.rowid = tc.fk_user";
-	  $sql .= " AND s.idp = ".$soc->id;
+	  $sql .= " AND s.rowid = ".$soc->id;
 	  $sql .= " ORDER BY t.libelle ASC";
 
 	  if ( $db->query( $sql) )
diff --git a/htdocs/telephonie/contrat/fiche.php b/htdocs/telephonie/contrat/fiche.php
index 586d91a9985..39ca9fee42c 100644
--- a/htdocs/telephonie/contrat/fiche.php
+++ b/htdocs/telephonie/contrat/fiche.php
@@ -156,7 +156,7 @@ if ($_GET["action"] == 'create' && $user->rights->telephonie->ligne->creer)
 
   print '<tr><td width="20%">Client</td><td >';
   $ff = array();
-  $sql = "SELECT idp, nom, ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1 AND (parent = 0 OR parent IS NULL) ORDER BY nom ";
+  $sql = "SELECT rowid, nom, ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1 AND (parent = 0 OR parent IS NULL) ORDER BY nom ";
   if ( $db->query( $sql) )
     {
       $num = $db->num_rows();
@@ -244,9 +244,9 @@ elseif ($_GET["action"] == 'create_line' && $_GET["client_comm"] > 0 && $user->r
 	  
 	  print '<tr><td width="20%">Client (Agence/Filiale)</td><td >';
 	  $ff = array();
-	  $sql = "SELECT idp, nom, ville FROM ".MAIN_DB_PREFIX."societe";
+	  $sql = "SELECT rowid, nom, ville FROM ".MAIN_DB_PREFIX."societe";
 	  $sql .= " WHERE client=1";
-	  $sql .= " AND (idp = $socc->id OR parent = $socc->id)";
+	  $sql .= " AND (rowid = ".$socc->id." OR parent = ".$socc->id.")";
 	  $sql .= " ORDER BY nom ";
 
 	  if ( $db->query( $sql) )
@@ -273,8 +273,8 @@ elseif ($_GET["action"] == 'create_line' && $_GET["client_comm"] > 0 && $user->r
 	  
 	  print '<tr><td width="20%">Client � facturer</td><td >';
 	  $ff = array();
-	  $sql = "SELECT idp, nom, ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1";
-	  $sql .= " AND (idp = $socc->id OR parent = $socc->id)";
+	  $sql = "SELECT rowid, nom, ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1";
+	  $sql .= " AND (rowid = ".$socc->id." OR parent = ".$socc->id.")";
 	  $sql .= " ORDER BY nom ";
 	  if ( $db->query( $sql) )
 	    {
@@ -338,17 +338,17 @@ elseif ($_GET["action"] == 'create_line' && $_GET["client_comm"] > 0 && $user->r
 	  /*
 	   * Contrats existants
 	   */
-	  $sql = "SELECT c.rowid, c.ref, s.idp as socid, s.nom ";
-	  $sql .= ", sf.idp as sfidp, sf.nom as sfnom";
-	  $sql .= ", sa.idp as saidp, sa.nom as sanom";
+	  $sql = "SELECT c.rowid, c.ref, s.rowid as socid, s.nom ";
+	  $sql .= ", sf.rowid as sfidp, sf.nom as sfnom";
+	  $sql .= ", sa.rowid as saidp, sa.nom as sanom";
 	  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 	  $sql .= " , ".MAIN_DB_PREFIX."societe as sf";
 	  $sql .= " , ".MAIN_DB_PREFIX."societe as sa";
 	  $sql .= " , ".MAIN_DB_PREFIX."telephonie_contrat as c";	  	  
-	  $sql .= " WHERE c.fk_client_comm = s.idp";
-	  $sql .= " AND c.fk_soc = sa.idp";
-	  $sql .= " AND c.fk_soc_facture = sf.idp";	  	 
-	  $sql .= " AND s.idp = ".$_GET["client_comm"];
+	  $sql .= " WHERE c.fk_client_comm = s.rowid";
+	  $sql .= " AND c.fk_soc = sa.rowid";
+	  $sql .= " AND c.fk_soc_facture = sf.rowid";	  	 
+	  $sql .= " AND s.rowid = ".$_GET["client_comm"];
 	  
 	  $result = $db->query($sql);
 	  if ($result)
@@ -570,10 +570,10 @@ else
 	      print '<tr><td valign="top" width="20%">Contact facture</td>';
 	      print '<td valign="top" colspan="3">';
 
-	      $sql = "SELECT c.idp, c.name, c.firstname, c.email ";
+	      $sql = "SELECT c.rowid, c.name, c.firstname, c.email ";
 	      $sql .= "FROM ".MAIN_DB_PREFIX."socpeople as c";
 	      $sql .= ",".MAIN_DB_PREFIX."telephonie_contrat_contact_facture as cf";
-	      $sql .= " WHERE c.idp = cf.fk_contact AND cf.fk_contrat = ".$contrat->id." ORDER BY name ";
+	      $sql .= " WHERE c.rowid = cf.fk_contact AND cf.fk_contrat = ".$contrat->id." ORDER BY name ";
 	      if ( $db->query( $sql) )
 		{
 		  $num = $db->num_rows();
@@ -609,7 +609,7 @@ else
 	      $sql .= " , ".MAIN_DB_PREFIX."societe as ss";
 	      $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
 	      $sql .= " WHERE l.fk_fournisseur = f.rowid";
-	      $sql .= " AND l.fk_soc = ss.idp ";
+	      $sql .= " AND l.fk_soc = ss.rowid ";
 	      $sql .= " AND l.fk_contrat = ".$contrat->id;
 	      $sql .= " ORDER BY l.statut ASC, l.ligne ASC";
 	      
@@ -713,8 +713,8 @@ else
 	      print '<tr><td width="20%">Client (Agence/Filiale)</td><td colspan="2">';
 	      print '<select name="client">';
 	      
-	      $sql = "SELECT idp, nom, ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1";
-	      $sql .= " AND (idp = $client_comm->id OR parent = $client_comm->id)";
+	      $sql = "SELECT rowid, nom, ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1";
+	      $sql .= " AND (rowid = ".$client_comm->id." OR parent = ".$client_comm->id.")";
 	      $sql .= "  ORDER BY nom ";
 	      if ( $db->query( $sql) )
 		{
@@ -743,8 +743,8 @@ else
 	      print '<select name="client_facture">'."\n";
 	      
 	      
-	      $sql = "SELECT idp, nom,ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1 ";
-	      $sql .= " AND (idp = $client_comm->id OR parent = $client_comm->id)";
+	      $sql = "SELECT rowid, nom,ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1 ";
+	      $sql .= " AND (rowid = ".$client_comm->id." OR parent = ".$client_comm->id.")";
 	      $sql .= "  ORDER BY nom ";
 	      if ( $db->query( $sql) )
 		{
@@ -904,10 +904,10 @@ else
 
 	      print '<table class="border" width="100%" cellspacing="0" cellpadding="4">';
 
-	      $sql = "SELECT c.idp, c.name, c.firstname, c.email ";
+	      $sql = "SELECT c.rowid, c.name, c.firstname, c.email ";
 	      $sql .= "FROM ".MAIN_DB_PREFIX."socpeople as c";
 	      $sql .= ",".MAIN_DB_PREFIX."telephonie_contrat_contact_facture as cf";
-	      $sql .= " WHERE c.idp = cf.fk_contact ";
+	      $sql .= " WHERE c.rowid = cf.fk_contact ";
 	      $sql .= " AND cf.fk_contrat = ".$contrat->id." ORDER BY name ";
 
 	      if ( $db->query( $sql) )
@@ -940,7 +940,7 @@ else
 
 	      print '<tr><td valign="top" width="20%">Contact</td><td valign="top" colspan="2">';
 	  	 
-	      $sql = "SELECT idp, name, firstname, email ";
+	      $sql = "SELECT rowid, name, firstname, email ";
 	      $sql .= " FROM ".MAIN_DB_PREFIX."socpeople ";
 	      $sql .= " WHERE fk_soc in (".$contrat->client_facture_id.",".$contrat->client_id.")";
 	      $sql .= " ORDER BY name ";
diff --git a/htdocs/telephonie/contrat/index.php b/htdocs/telephonie/contrat/index.php
index 135a7a1b04b..b06e434890c 100644
--- a/htdocs/telephonie/contrat/index.php
+++ b/htdocs/telephonie/contrat/index.php
@@ -61,11 +61,11 @@ print '<br />';
 
 /* Consultations */
 
-$sql = "SELECT s.idp as socid, s.nom, max(sc.datec) as dam, c.ref, c.rowid";
+$sql = "SELECT s.rowid as socid, s.nom, max(sc.datec) as dam, c.ref, c.rowid";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= ",".MAIN_DB_PREFIX."telephonie_contrat as c";
 $sql .= ",".MAIN_DB_PREFIX."telephonie_contrat_consult as sc";
-$sql .= " WHERE s.idp = c.fk_soc";
+$sql .= " WHERE s.rowid = c.fk_soc";
 $sql .= " AND c.rowid = sc.fk_contrat";
 $sql .= " AND sc.fk_user = ".$user->id;
 $sql .= " GROUP BY c.rowid";
@@ -152,16 +152,16 @@ else
 print '</td><td valign="top" width="70%">';
 
 $sql = "SELECT c.ref, c.rowid, c.statut";
-$sql .= " ,s.idp as socid, sf.idp as sfidp, sf.nom as nom_facture,s.nom";
+$sql .= " ,s.rowid as socid, sf.rowid as sfidp, sf.nom as nom_facture,s.nom";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= " , ".MAIN_DB_PREFIX."societe as sf";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_contrat as c";
 $sql .= " , ".MAIN_DB_PREFIX."societe_perms as sp";
 
-$sql .= " WHERE c.fk_soc = s.idp";
-$sql .= " AND c.fk_soc_facture = sf.idp";
+$sql .= " WHERE c.fk_soc = s.rowid";
+$sql .= " AND c.fk_soc_facture = sf.rowid";
 
-$sql .= " AND s.idp = sp.fk_soc";
+$sql .= " AND s.rowid = sp.fk_soc";
 
 $sql .= " AND sp.fk_user = ".$user->id." AND sp.pread = 1";
 
diff --git a/htdocs/telephonie/contrat/info.php b/htdocs/telephonie/contrat/info.php
index 2413f0b9e39..65a44c89f8d 100644
--- a/htdocs/telephonie/contrat/info.php
+++ b/htdocs/telephonie/contrat/info.php
@@ -123,7 +123,7 @@ if ($_GET["id"])
 	  print "</table><br />";
 
 
-  $sql = "SELECT s.idp, s.nom, p.fk_contrat, p.montant, p.avance_duree, p.avance_pourcent";
+  $sql = "SELECT s.rowid as socid, s.nom, p.fk_contrat, p.montant, p.avance_duree, p.avance_pourcent";
   $sql .= ", p.rem_pour_prev, p.rem_pour_autr, p.mode_paiement";
   $sql .= ", u.name, u.firstname, u.login";
   $sql .= " , ".$db->pdate("p.datepo") . " as datepo";
@@ -133,8 +133,8 @@ if ($_GET["id"])
   $sql .= " , ".MAIN_DB_PREFIX."user as u";
   
   $sql .= " WHERE p.fk_commercial =u.rowid";
-  $sql .= " AND p.fk_user =uu.rowid";
-  $sql .= " AND c.fk_soc = s.idp";
+  $sql .= " AND p.fk_user =u.rowid";
+  $sql .= " AND c.fk_soc = s.rowid";
   $sql .= " AND p.fk_contrat = c.rowid";
   $sql .= " AND c.rowid =".$_GET["id"];
 
diff --git a/htdocs/telephonie/contrat/liste.php b/htdocs/telephonie/contrat/liste.php
index f4d01e4f797..0956db8e2e9 100644
--- a/htdocs/telephonie/contrat/liste.php
+++ b/htdocs/telephonie/contrat/liste.php
@@ -46,18 +46,18 @@ $pagenext = $page + 1;
  *
  *
  */
-$sql = "SELECT c.rowid, c.ref, s.idp as socid, c.statut, s.nom ";
-$sql .= ", sf.idp as sfidp, sf.nom as sfnom";
-$sql .= ", sa.idp as saidp, sa.nom as sanom";
+$sql = "SELECT c.rowid, c.ref, s.rowid as socid, c.statut, s.nom ";
+$sql .= ", sf.rowid as sfidp, sf.nom as sfnom";
+$sql .= ", sa.rowid as saidp, sa.nom as sanom";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= " , ".MAIN_DB_PREFIX."societe as sf";
 $sql .= " , ".MAIN_DB_PREFIX."societe as sa";
 $sql .= " , ".MAIN_DB_PREFIX."societe_perms as sp";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_contrat as c";
 
-$sql .= " WHERE c.fk_client_comm = s.idp";
-$sql .= " AND c.fk_soc = sa.idp";
-$sql .= " AND c.fk_soc_facture = sf.idp";
+$sql .= " WHERE c.fk_client_comm = s.rowid";
+$sql .= " AND c.fk_soc = sa.rowid";
+$sql .= " AND c.fk_soc_facture = sf.rowid";
 
 $sql .= " AND c.fk_client_comm = sp.fk_soc";
 $sql .= " AND sp.fk_user = ".$user->id." AND sp.pread = 1";
diff --git a/htdocs/telephonie/contrat/services.php b/htdocs/telephonie/contrat/services.php
index 4ce6d83d3f0..ca9dd464791 100644
--- a/htdocs/telephonie/contrat/services.php
+++ b/htdocs/telephonie/contrat/services.php
@@ -141,10 +141,10 @@ if ($_GET["id"])
 	  print '<tr><td valign="top" width="20%">Contact facture</td>';
 	  print '<td valign="top" colspan="2">';
 
-	  $sql = "SELECT c.idp, c.name, c.firstname, c.email ";
+	  $sql = "SELECT c.rowid, c.name, c.firstname, c.email ";
 	  $sql .= "FROM ".MAIN_DB_PREFIX."socpeople as c";
 	  $sql .= ",".MAIN_DB_PREFIX."telephonie_contrat_contact_facture as cf";
-	  $sql .= " WHERE c.idp = cf.fk_contact AND cf.fk_contrat = ".$contrat->id." ORDER BY name ";
+	  $sql .= " WHERE c.rowid = cf.fk_contact AND cf.fk_contrat = ".$contrat->id." ORDER BY name ";
 	  if ( $db->query( $sql) )
 	    {
 	      $num = $db->num_rows();
diff --git a/htdocs/telephonie/distributeurs/po.php b/htdocs/telephonie/distributeurs/po.php
index 4cbd1d50db6..fcd2143f1a4 100644
--- a/htdocs/telephonie/distributeurs/po.php
+++ b/htdocs/telephonie/distributeurs/po.php
@@ -84,7 +84,7 @@ if ($_GET["id"])
    *
    */
   
-  $sql = "SELECT s.idp, s.nom, p.fk_contrat, p.montant, p.avance_duree, p.avance_pourcent";
+  $sql = "SELECT s.rowid as socid, s.nom, p.fk_contrat, p.montant, p.avance_duree, p.avance_pourcent";
   $sql .= ", p.rem_pour_prev, p.rem_pour_autr, p.mode_paiement";
   $sql .= " , ".$db->pdate("p.datepo") . " as datepo";
   $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_contrat_priseordre as p";
@@ -92,7 +92,7 @@ if ($_GET["id"])
   $sql .= " , ".MAIN_DB_PREFIX."societe as s";
   
   $sql .= " WHERE p.fk_distributeur =".$distri->id;
-  $sql .= " AND c.fk_soc = s.idp";
+  $sql .= " AND c.fk_soc = s.rowid";
   $sql .= " AND p.fk_contrat = c.rowid";
   $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset);
   
@@ -123,11 +123,11 @@ if ($_GET["id"])
 	  
 	  print "<tr $bc[$var]>";
 	  
-	  print '<td><a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->idp.'">';
+	  print '<td><a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">';
 	  print img_file();
 	  print '</a>&nbsp;';
       
-	  print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->idp.'">'.$obj->nom."</a></td>\n";
+	  print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">'.$obj->nom."</a></td>\n";
 	  print '<td><a href="'.DOL_URL_ROOT.'/telephonie/contrat/fiche.php?id='.$obj->fk_contrat.'">'.$obj->fk_contrat."</a></td>\n";
 	  print '<td align="center">'.strftime("%e %b %Y",$obj->datepo)."</td>\n";
 
diff --git a/htdocs/telephonie/distributeurs/remav.php b/htdocs/telephonie/distributeurs/remav.php
index 585f114d769..33fec60ed8d 100644
--- a/htdocs/telephonie/distributeurs/remav.php
+++ b/htdocs/telephonie/distributeurs/remav.php
@@ -104,7 +104,7 @@ if ($_GET["id"])
   $year = strftime("%Y", $datetime);      
   $mois = strftime("%B %Y", $datetime);
 
-  $sql = "SELECT s.idp, s.nom, a.fk_contrat, sum(a.montant) as montant";
+  $sql = "SELECT s.rowid as socid, s.nom, a.fk_contrat, sum(a.montant) as montant";
 
   $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_commission_avance as a";
   $sql .= " , ".MAIN_DB_PREFIX."telephonie_contrat as c";
@@ -112,9 +112,9 @@ if ($_GET["id"])
   
   $sql .= " WHERE a.fk_distributeur =".$distri->id;
   $sql .= " AND a.fk_contrat = c.rowid"; 
-  $sql .= " AND c.fk_soc = s.idp";
+  $sql .= " AND c.fk_soc = s.rowid";
   $sql .= " AND a.date ='".$year.$month."'";
-  $sql .= " GROUP BY s.idp";
+  $sql .= " GROUP BY s.rowid";
   $sql .= " ORDER BY s.nom ASC";
   
   $resql = $db->query($sql);
@@ -138,10 +138,10 @@ if ($_GET["id"])
 	  $var=!$var;
 	  
 	  print "<tr $bc[$var]>";	  
-	  print '<td><a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->idp.'">';
+	  print '<td><a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">';
 	  print img_file();
 	  print '</a>&nbsp;';      
-	  print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->idp.'">'.$obj->nom."</a></td>\n";
+	  print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">'.$obj->nom."</a></td>\n";
 	  print '<td align="right">'.sprintf("%01.2f",$obj->montant)."</td>\n";	  
 	  print "</tr>\n";
 	  $i++;
diff --git a/htdocs/telephonie/distributeurs/remconso.php b/htdocs/telephonie/distributeurs/remconso.php
index 45a1ae6cf45..d3e2005ee5b 100644
--- a/htdocs/telephonie/distributeurs/remconso.php
+++ b/htdocs/telephonie/distributeurs/remconso.php
@@ -104,7 +104,7 @@ if ($_GET["id"])
   $year = strftime("%Y", $datetime);      
   $mois = strftime("%B %Y", $datetime);
 
-  $sql = "SELECT s.idp, s.nom, a.fk_contrat, sum(a.montant) as montant";
+  $sql = "SELECT s.rowid as socid, s.nom, a.fk_contrat, sum(a.montant) as montant";
 
   $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_commission_conso as a";
   $sql .= " , ".MAIN_DB_PREFIX."telephonie_contrat as c";
@@ -112,10 +112,10 @@ if ($_GET["id"])
   
   $sql .= " WHERE a.fk_distributeur =".$distri->id;
   $sql .= " AND a.fk_contrat = c.rowid"; 
-  $sql .= " AND c.fk_soc = s.idp";
+  $sql .= " AND c.fk_soc = s.rowid";
   $sql .= " AND a.date ='".$year.$month."'";
   $sql .= " AND a.avance = 0";
-  $sql .= " GROUP BY s.idp";
+  $sql .= " GROUP BY s.rowid";
   $sql .= " ORDER BY s.nom ASC";
   
   $resql = $db->query($sql);
@@ -139,10 +139,10 @@ if ($_GET["id"])
 	  $var=!$var;
 	  
 	  print "<tr $bc[$var]>";	  
-	  print '<td><a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->idp.'">';
+	  print '<td><a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">';
 	  print img_file();
 	  print '</a>&nbsp;';      
-	  print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->idp.'">'.$obj->nom."</a></td>\n";
+	  print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">'.$obj->nom."</a></td>\n";
 	  print '<td align="right">'.sprintf("%01.2f",$obj->montant)."</td>\n";	  
 	  print "</tr>\n";
 	  $i++;
diff --git a/htdocs/telephonie/distributeurs/remuneration.php b/htdocs/telephonie/distributeurs/remuneration.php
index 1dbfbfb8ab5..95ada13444c 100644
--- a/htdocs/telephonie/distributeurs/remuneration.php
+++ b/htdocs/telephonie/distributeurs/remuneration.php
@@ -116,16 +116,16 @@ if ($_GET["id"])
   $mois = strftime("%B %Y", mktime(12,0,0,$monthprev,1,$yearprev));
 
 
-  $sql = "SELECT s.idp, s.nom, a.fk_contrat, c.statut, sum(a.montant) as montant";
+  $sql = "SELECT s.rowid as socid, s.nom, a.fk_contrat, c.statut, sum(a.montant) as montant";
   $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_commission_avance as a";
   $sql .= " , ".MAIN_DB_PREFIX."telephonie_contrat as c";
   $sql .= " , ".MAIN_DB_PREFIX."societe as s";
   
   $sql .= " WHERE a.fk_distributeur =".$distri->id;
   $sql .= " AND a.fk_contrat = c.rowid"; 
-  $sql .= " AND c.fk_soc = s.idp";
+  $sql .= " AND c.fk_soc = s.rowid";
   $sql .= " AND a.date ='".$yearprev.$monthprev."'";
-  $sql .= " GROUP BY s.idp";
+  $sql .= " GROUP BY s.rowid";
   $sql .= " ORDER BY s.nom ASC";
   
   $resql = $db->query($sql);
@@ -147,11 +147,11 @@ if ($_GET["id"])
 	{
 	  $obj = $db->fetch_object($resql);	 
 	  print "<tr $bc[$var]>";	  
-	  print '<td><a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->idp.'">';
+	  print '<td><a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">';
 	  print img_file();
 	  print '</a>&nbsp;';
 	  print '<img src="../contrat/statut'.$obj->statut.'.png">&nbsp;';
-	  print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->idp.'">'.$obj->nom."</a></td>\n";
+	  print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">'.$obj->nom."</a></td>\n";
 	  print '<td align="right">'.sprintf("%01.2f",$obj->montant)."</td>\n";	  
 	  print "</tr>\n";
 	  $total += $obj->montant;
@@ -181,17 +181,17 @@ if ($_GET["id"])
   
   $total = 0;
 
-  $sql = "SELECT s.idp, s.nom, a.fk_contrat,c.statut,sum(a.montant) as montant";
+  $sql = "SELECT s.rowid as socid, s.nom, a.fk_contrat,c.statut,sum(a.montant) as montant";
   $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_commission_regul as a";
   $sql .= " , ".MAIN_DB_PREFIX."telephonie_contrat as c";
   $sql .= " , ".MAIN_DB_PREFIX."societe as s";
 
   $sql .= " WHERE a.fk_distributeur =".$distri->id;
   $sql .= " AND a.fk_contrat = c.rowid"; 
-  $sql .= " AND c.fk_soc = s.idp";
+  $sql .= " AND c.fk_soc = s.rowid";
   $sql .= " AND a.date ='".$yearprev.$monthprev."'";
 
-  $sql .= " GROUP BY s.idp";
+  $sql .= " GROUP BY s.rowid";
   $sql .= " ORDER BY s.nom ASC";
 
   $resql = $db->query($sql);
@@ -201,11 +201,11 @@ if ($_GET["id"])
       while ($obj = $db->fetch_object($resql))
 	{
 	  print "<tr $bc[$var]>";
-	  print '<td><a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->idp.'">';
+	  print '<td><a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">';
 	  print img_file();
 	  print '</a>&nbsp;';
 	  print '<img src="../contrat/statut'.$obj->statut.'.png">&nbsp;';
-	  print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->idp.'">'.$obj->nom."</a></td>\n";
+	  print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">'.$obj->nom."</a></td>\n";
 	  print '<td align="right">'.sprintf("%01.2f",$obj->montant)."</td>\n";	  
 	  print "</tr>\n";
 	  $var=!$var;
@@ -213,17 +213,17 @@ if ($_GET["id"])
 	}
     }
 
-  $sql = "SELECT s.idp, s.nom, a.fk_contrat, sum(a.montant) as montant, c.statut";
+  $sql = "SELECT s.rowid as socid, s.nom, a.fk_contrat, sum(a.montant) as montant, c.statut";
   $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_commission_conso as a";
   $sql .= " , ".MAIN_DB_PREFIX."telephonie_contrat as c";
   $sql .= " , ".MAIN_DB_PREFIX."societe as s";
   
   $sql .= " WHERE a.fk_distributeur =".$distri->id;
   $sql .= " AND a.fk_contrat = c.rowid"; 
-  $sql .= " AND c.fk_soc = s.idp";
+  $sql .= " AND c.fk_soc = s.rowid";
   $sql .= " AND a.date ='".$yearprev.$monthprev."'";
   $sql .= " AND a.avance = 0";
-  $sql .= " GROUP BY s.idp";
+  $sql .= " GROUP BY s.rowid";
   $sql .= " ORDER BY s.nom ASC";
 
   $resql = $db->query($sql);
@@ -237,11 +237,11 @@ if ($_GET["id"])
 	  $obj = $db->fetch_object($resql);
 	  
 	  print "<tr $bc[$var]>";
-	  print '<td><a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->idp.'">';
+	  print '<td><a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">';
 	  print img_file();
 	  print '</a>&nbsp;';
 	  print '<img src="../contrat/statut'.$obj->statut.'.png">&nbsp;';
-	  print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->idp.'">'.$obj->nom."</a></td>\n";
+	  print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">'.$obj->nom."</a></td>\n";
 	  print '<td align="right">'.sprintf("%01.2f",$obj->montant)."</td>\n";	  
 	  print "</tr>\n";
 	  $total += $obj->montant;
diff --git a/htdocs/telephonie/facture/liste.php b/htdocs/telephonie/facture/liste.php
index 84c23e11122..39d4789e1e1 100644
--- a/htdocs/telephonie/facture/liste.php
+++ b/htdocs/telephonie/facture/liste.php
@@ -65,7 +65,7 @@ $pagenext = $page + 1;
  */
 
 $sql = "SELECT f.rowid, f.date, f.ligne, f.fourn_montant, f.cout_vente, f.gain, f.fk_facture";
-$sql .= " ,s.nom, s.idp";
+$sql .= " ,s.nom, s.rowid as socid";
 $sql .= " , fac.facnumber as ref";
 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture as f";
 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
@@ -73,8 +73,8 @@ $sql .= " , ".MAIN_DB_PREFIX."facture as fac";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= ",".MAIN_DB_PREFIX."societe_perms as sp";
 
-$sql .= " WHERE s.idp = l.fk_soc_facture AND l.rowid = f.fk_ligne";
-$sql .= " AND l.fk_soc_facture = s.idp";
+$sql .= " WHERE s.rowid = l.fk_soc_facture AND l.rowid = f.fk_ligne";
+$sql .= " AND l.fk_soc_facture = s.rowid";
 $sql .= " AND l.fk_client_comm = sp.fk_soc";
 $sql .= " AND sp.fk_user = ".$user->id." AND sp.pread = 1";
 
@@ -151,11 +151,11 @@ if ($result)
 
       print "<tr $bc[$var]>";
 
-      print '<td><a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->idp.'">';
+      print '<td><a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">';
       print img_file();      
       print '</a>&nbsp;';
 
-      print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->idp.'">'.$obj->nom."</a></td>\n";
+      print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">'.$obj->nom."</a></td>\n";
       print '<td><a href="'.DOL_URL_ROOT.'/telephonie/ligne/fiche.php?numero='.$obj->ligne.'">'.dolibarr_print_phone($obj->ligne)."</a></td>\n";
       print '<td align="center">'.$obj->date."</td>\n";
       print '<td align="right">'.sprintf("%01.4f",$obj->cout_vente)."</td>\n";
diff --git a/htdocs/telephonie/fournisseur/commande/commande.tableur.class.php b/htdocs/telephonie/fournisseur/commande/commande.tableur.class.php
index 48e26dbc8f4..363b8a67042 100644
--- a/htdocs/telephonie/fournisseur/commande/commande.tableur.class.php
+++ b/htdocs/telephonie/fournisseur/commande/commande.tableur.class.php
@@ -187,7 +187,7 @@ class CommandeMethodeTableur extends CommandeMethode
 
     $this->ligneids = array();
     
-    $sqlall = "SELECT s.nom, s.idp as socid, f.nom as fournisseur";
+    $sqlall = "SELECT s.nom, s.rowid as socid, f.nom as fournisseur";
     $sqlall .= ", l.ligne, l.statut, l.rowid, l.remise";
     $sqlall .= ",".$this->db->pdate("l.date_commande") . " as date_commande";
     $sqlall .= " , comm.name, comm.firstname";
@@ -196,8 +196,8 @@ class CommandeMethodeTableur extends CommandeMethode
     $sqlall .= " , ".MAIN_DB_PREFIX."societe as r";
     $sqlall .= " , ".MAIN_DB_PREFIX."user as comm";
     $sqlall .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-    $sqlall .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
-    $sqlall .= " AND l.fk_soc_facture = r.idp ";
+    $sqlall .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
+    $sqlall .= " AND l.fk_soc_facture = r.rowid ";
     $sqlall .= " AND l.fk_commercial = comm.rowid ";
     $sqlall .= " AND f.rowid =".$this->fourn->id;
     /*
diff --git a/htdocs/telephonie/fournisseur/commande/commande.text.class.php b/htdocs/telephonie/fournisseur/commande/commande.text.class.php
index b08b37560c7..d7432283e61 100644
--- a/htdocs/telephonie/fournisseur/commande/commande.text.class.php
+++ b/htdocs/telephonie/fournisseur/commande/commande.text.class.php
@@ -141,7 +141,7 @@ class CommandeMethodeText extends CommandeMethode
 
 	$this->ligneids = array();
 	
-	$sqlall = "SELECT s.nom, s.idp as socid, l.ligne, l.statut, l.rowid";
+	$sqlall = "SELECT s.nom, s.rowid as socid, l.ligne, l.statut, l.rowid";
 	$sqlall .= " , comm.name, comm.firstname";
 	
 	$sqlall .= " FROM ".MAIN_DB_PREFIX."societe as s";
@@ -149,7 +149,7 @@ class CommandeMethodeText extends CommandeMethode
 	$sqlall .= " , ".MAIN_DB_PREFIX."user as comm";
 	$sqlall .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
 
-	$sqlall .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
+	$sqlall .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
 
 	$sqlall .= " AND l.fk_commercial = comm.rowid ";
 	$sqlall .= " AND f.rowid =".$this->fourn->id;
diff --git a/htdocs/telephonie/fournisseur/commande/commande.textp.class.php b/htdocs/telephonie/fournisseur/commande/commande.textp.class.php
index 5d792254cbd..ba54e2cbc95 100644
--- a/htdocs/telephonie/fournisseur/commande/commande.textp.class.php
+++ b/htdocs/telephonie/fournisseur/commande/commande.textp.class.php
@@ -129,7 +129,7 @@ class CommandeMethodeTextP extends CommandeMethode
 
 	$this->ligneids = array();
 	
-	$sqlall = "SELECT s.nom, s.idp as socid, l.ligne, l.statut, l.rowid";
+	$sqlall = "SELECT s.nom, s.rowid as socid, l.ligne, l.statut, l.rowid";
 	$sqlall .= " , comm.name, comm.firstname";
 	
 	$sqlall .= " FROM ".MAIN_DB_PREFIX."societe as s";
@@ -137,7 +137,7 @@ class CommandeMethodeTextP extends CommandeMethode
 	$sqlall .= " , ".MAIN_DB_PREFIX."user as comm";
 	$sqlall .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
 
-	$sqlall .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
+	$sqlall .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
 
 	$sqlall .= " AND l.fk_commercial = comm.rowid ";
 	$sqlall .= " AND f.rowid =".$this->fourn->id;
diff --git a/htdocs/telephonie/fournisseur/commande/commande.web.class.php b/htdocs/telephonie/fournisseur/commande/commande.web.class.php
index 1a883273864..85f05ce0868 100644
--- a/htdocs/telephonie/fournisseur/commande/commande.web.class.php
+++ b/htdocs/telephonie/fournisseur/commande/commande.web.class.php
@@ -92,7 +92,7 @@ class CommandeMethodeWeb extends CommandeMethode
 
 	$this->ligneids = array();
 	
-	$sqlall = "SELECT s.nom, s.idp as socid, l.ligne, l.statut, l.rowid";
+	$sqlall = "SELECT s.nom, s.rowid as socid, l.ligne, l.statut, l.rowid";
 	$sqlall .= " , comm.name, comm.firstname";
 	
 	$sqlall .= " FROM ".MAIN_DB_PREFIX."societe as s";
@@ -100,7 +100,7 @@ class CommandeMethodeWeb extends CommandeMethode
 	$sqlall .= " , ".MAIN_DB_PREFIX."user as comm";
 	$sqlall .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
 
-	$sqlall .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
+	$sqlall .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
 
 	$sqlall .= " AND l.fk_commercial = comm.rowid ";
 	$sqlall .= " AND f.rowid =".$this->fourn->id;
diff --git a/htdocs/telephonie/index.php b/htdocs/telephonie/index.php
index 12153a1fb68..d8ccee9fbfd 100644
--- a/htdocs/telephonie/index.php
+++ b/htdocs/telephonie/index.php
@@ -142,7 +142,7 @@ if ($user->rights->telephonie->fournisseur->lire)
   $sql .= " ,".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
   $sql .= " ,".MAIN_DB_PREFIX."telephonie_fournisseur as f";
   $sql .= " ,".MAIN_DB_PREFIX."societe_perms as sp";
-  $sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
+  $sql .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
   $sql .= " AND l.fk_client_comm = sp.fk_soc";
   $sql .= " AND sp.fk_user = ".$user->id." AND sp.pread = 1";
   $sql .= " GROUP BY f.nom";
diff --git a/htdocs/telephonie/ligne/commande/commandetableur.class.php b/htdocs/telephonie/ligne/commande/commandetableur.class.php
index 1d4260b171e..92dda7bf2e5 100644
--- a/htdocs/telephonie/ligne/commande/commandetableur.class.php
+++ b/htdocs/telephonie/ligne/commande/commandetableur.class.php
@@ -176,15 +176,15 @@ class CommandeTableur
 
     $ligneids = array();
     
-    $sqlall = "SELECT s.nom, s.idp as socid, l.ligne, f.nom as fournisseur, l.statut, l.rowid";
+    $sqlall = "SELECT s.nom, s.rowid as socid, l.ligne, f.nom as fournisseur, l.statut, l.rowid";
     $sqlall .= " , comm.name, comm.firstname, l.remise";
     $sqlall .= " FROM ".MAIN_DB_PREFIX."societe as s";
     $sqlall .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
     $sqlall .= " , ".MAIN_DB_PREFIX."societe as r";
     $sqlall .= " , ".MAIN_DB_PREFIX."user as comm";
     $sqlall .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-    $sqlall .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
-    $sqlall .= " AND l.fk_soc_facture = r.idp ";
+    $sqlall .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
+    $sqlall .= " AND l.fk_soc_facture = r.rowid ";
     $sqlall .= " AND l.fk_commercial = comm.rowid ";
     /*
      *
diff --git a/htdocs/telephonie/ligne/commande/fiche.php b/htdocs/telephonie/ligne/commande/fiche.php
index 38f682020ba..78768b986a2 100644
--- a/htdocs/telephonie/ligne/commande/fiche.php
+++ b/htdocs/telephonie/ligne/commande/fiche.php
@@ -68,9 +68,9 @@ $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= ",".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= ",".MAIN_DB_PREFIX."telephonie_fournisseur as f";
 $sql .= ",".MAIN_DB_PREFIX."societe as sf";
-$sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid ";
+$sql .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid ";
 $sql .= " AND l.statut IN (1,4,8) ";
-$sql .= " AND l.fk_soc_facture = sf.idp";
+$sql .= " AND l.fk_soc_facture = sf.rowid";
 $sql .= " GROUP BY f.rowid, f.nom ASC";
 
 $result = $db->query($sql);
@@ -128,14 +128,14 @@ else
  *
  */
 
-$sql = "SELECT sf.idp as sfidp, sf.nom as sfnom, s.idp as socid, s.nom, l.ligne, f.nom as fournisseur, l.statut, l.rowid";
+$sql = "SELECT sf.rowid as sfidp, sf.nom as sfnom, s.rowid as socid, s.nom, l.ligne, f.nom as fournisseur, l.statut, l.rowid";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
 $sql .= " , ".MAIN_DB_PREFIX."societe as sf";
-$sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
+$sql .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
 $sql .= " AND l.statut IN (1,4,8) ";
-$sql .= " AND l.fk_soc_facture = sf.idp";
+$sql .= " AND l.fk_soc_facture = sf.rowid";
 $sql .= " ORDER BY s.nom ASC ";
 
 if ($db->query($sql))
diff --git a/htdocs/telephonie/ligne/commande/historique.php b/htdocs/telephonie/ligne/commande/historique.php
index 364a2de38b8..97254d776de 100644
--- a/htdocs/telephonie/ligne/commande/historique.php
+++ b/htdocs/telephonie/ligne/commande/historique.php
@@ -61,13 +61,13 @@ $pagenext = $page + 1;
  *
  */
 
-$sql = "SELECT s.idp as socid, s.nom, l.ligne, f.nom as fournisseur, l.statut, l.rowid, l.remise";
+$sql = "SELECT s.rowid as socid, s.nom, l.ligne, f.nom as fournisseur, l.statut, l.rowid, l.remise";
 $sql .= " , ".$db->pdate("ls.tms")."  as dc";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= " ,".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne_statut as ls";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-$sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
+$sql .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
 $sql .= " AND ls.fk_ligne = l.rowid";
 $sql .= " AND ls.statut = 2";
 
diff --git a/htdocs/telephonie/ligne/commande/liste.php b/htdocs/telephonie/ligne/commande/liste.php
index 315cb59d49e..f7420b4c1da 100644
--- a/htdocs/telephonie/ligne/commande/liste.php
+++ b/htdocs/telephonie/ligne/commande/liste.php
@@ -78,16 +78,16 @@ $pagenext = $page + 1;
  *
  */
 
-$sql = "SELECT sf.idp as sfidp, sf.nom as sfnom, s.idp as socid, s.nom, l.ligne, f.nom as fournisseur, l.statut, l.rowid, f.rowid as fournid, l.mode_paiement";
+$sql = "SELECT sf.rowid as sfidp, sf.nom as sfnom, s.rowid as socid, s.nom, l.ligne, f.nom as fournisseur, l.statut, l.rowid, f.rowid as fournid, l.mode_paiement";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= ",".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= ",".MAIN_DB_PREFIX."telephonie_fournisseur as f";
 $sql .= ",".MAIN_DB_PREFIX."societe as sf";
-$sql .= " WHERE l.fk_soc = s.idp ";
+$sql .= " WHERE l.fk_soc = s.rowid ";
 $sql .= " AND l.fk_fournisseur = f.rowid ";
 $sql .= " AND l.statut IN (-1,1,4) ";
 $sql .= " AND l.techno = 'presel'";
-$sql .= " AND l.fk_soc_facture = sf.idp";
+$sql .= " AND l.fk_soc_facture = sf.rowid";
 $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset);
 
 $result = $db->query($sql);
diff --git a/htdocs/telephonie/ligne/factures.php b/htdocs/telephonie/ligne/factures.php
index 933a51dde04..3d40fe8582e 100644
--- a/htdocs/telephonie/ligne/factures.php
+++ b/htdocs/telephonie/ligne/factures.php
@@ -93,11 +93,11 @@ if ($_GET["id"] or $_GET["numero"])
 
 
       $sql = "SELECT f.fk_facture";
-      $sql .= " ,s.nom, s.idp";
+      $sql .= " ,s.nom, s.rowid as socid";
       $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture as f";
       $sql .= " , ".MAIN_DB_PREFIX."societe as s";
       $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
-      $sql .= " WHERE s.idp = l.fk_soc_facture AND l.rowid = f.fk_ligne";  
+      $sql .= " WHERE s.rowid = l.fk_soc_facture AND l.rowid = f.fk_ligne";  
       $sql .= " AND f.ligne ='".$ligne->numero."'";  
       $sql .= " ORDER BY f.fk_facture DESC";
       
diff --git a/htdocs/telephonie/ligne/fiche.php b/htdocs/telephonie/ligne/fiche.php
index 0492dd55582..e8070cae952 100644
--- a/htdocs/telephonie/ligne/fiche.php
+++ b/htdocs/telephonie/ligne/fiche.php
@@ -295,7 +295,7 @@ if ($_GET["action"] == 'create1')
 
   print '<tr><td width="20%">Client</td><td >';
   $ff = array();
-  $sql = "SELECT idp, nom, ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1 ORDER BY nom ";
+  $sql = "SELECT rowid, nom, ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1 ORDER BY nom ";
   if ( $db->query( $sql) )
     {
       $num = $db->num_rows();
@@ -790,10 +790,10 @@ else
 
 	      /* Contacts */
 	     
-	      $sql = "SELECT c.idp, c.name, c.firstname, c.email ";
+	      $sql = "SELECT c.rowid, c.name, c.firstname, c.email ";
 	      $sql .= "FROM ".MAIN_DB_PREFIX."socpeople as c";
 	      $sql .= ",".MAIN_DB_PREFIX."telephonie_contact_facture as cf";
-	      $sql .= " WHERE c.idp = cf.fk_contact AND cf.fk_ligne = ".$ligne->id." ORDER BY name ";
+	      $sql .= " WHERE c.rowid = cf.fk_contact AND cf.fk_ligne = ".$ligne->id." ORDER BY name ";
 	      if ( $db->query( $sql) )
 		{
 		  $num = $db->num_rows();
@@ -1103,10 +1103,10 @@ else
 	      print '<table class="border" width="100%" cellspacing="0" cellpadding="4">';
 
 
-	      $sql = "SELECT c.idp, c.name, c.firstname, c.email ";
+	      $sql = "SELECT c.rowid, c.name, c.firstname, c.email ";
 	      $sql .= "FROM ".MAIN_DB_PREFIX."socpeople as c";
 	      $sql .= ",".MAIN_DB_PREFIX."telephonie_contact_facture as cf";
-	      $sql .= " WHERE c.idp = cf.fk_contact AND cf.fk_ligne = ".$ligne->id." ORDER BY name ";
+	      $sql .= " WHERE c.rowid = cf.fk_contact AND cf.fk_ligne = ".$ligne->id." ORDER BY name ";
 	      if ( $db->query( $sql) )
 		{
 		  $num = $db->num_rows();
@@ -1137,7 +1137,7 @@ else
 
 	      print '<tr><td valign="top" width="20%">Contact</td><td valign="top" colspan="2">';
 	  	 
-	      $sql = "SELECT idp, name, firstname, email FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$ligne->client_facture_id." ORDER BY name ";
+	      $sql = "SELECT rowid, name, firstname, email FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$ligne->client_facture_id." ORDER BY name ";
 	      if ( $db->query( $sql) )
 		{
 		  print '<select name="contact_id">';
diff --git a/htdocs/telephonie/ligne/groupe.php b/htdocs/telephonie/ligne/groupe.php
index 9a04beb8aeb..91bede74969 100644
--- a/htdocs/telephonie/ligne/groupe.php
+++ b/htdocs/telephonie/ligne/groupe.php
@@ -61,7 +61,7 @@ $pagenext = $page + 1;
  *
  */
 
-$sql = "SELECT g.nom as gnom, s.idp as socid, sf.idp as sfidp, sf.nom as nom_facture,s.nom, l.ligne, l.statut, l.rowid, l.remise";
+$sql = "SELECT g.nom as gnom, s.rowid as socid, sf.rowid as sfidp, sf.nom as nom_facture,s.nom, l.ligne, l.statut, l.rowid, l.remise";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= " ,  ".MAIN_DB_PREFIX."societe as sf";
 
@@ -70,13 +70,13 @@ $sql .= " , ".MAIN_DB_PREFIX."telephonie_groupeligne as g";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_groupe_ligne as gl";
 
 
-$sql .= " WHERE l.fk_soc = s.idp ";
+$sql .= " WHERE l.fk_soc = s.rowid ";
 
 $sql .= " AND g.rowid = gl.fk_groupe";
 $sql .= " AND gl.fk_ligne = l.rowid";
 
 
-$sql .= " AND l.fk_soc_facture = sf.idp";
+$sql .= " AND l.fk_soc_facture = sf.rowid";
 
 if ($_GET["search_ligne"])
 {
diff --git a/htdocs/telephonie/ligne/index.php b/htdocs/telephonie/ligne/index.php
index 8438e96a36a..cc97b02fdb2 100644
--- a/htdocs/telephonie/ligne/index.php
+++ b/htdocs/telephonie/ligne/index.php
@@ -112,7 +112,7 @@ if ($user->rights->telephonie->fournisseur->lire)
   $sql = "SELECT distinct f.nom as fournisseur, f.rowid, count(*) as cc";
   $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
   $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-  $sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
+  $sql .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
   if ($user->rights->telephonie->ligne->lire_restreint)
     {
       $sql .= " AND l.fk_commercial_suiv = ".$user->id;
@@ -152,7 +152,7 @@ if ($user->rights->telephonie->fournisseur->lire)
 
 print '</td><td valign="top" width="70%">';
 
-$sql = "SELECT s.idp as socid, sf.idp as sfidp, sf.nom as nom_facture,s.nom, l.ligne, f.nom as fournisseur, l.statut, l.rowid, l.remise";
+$sql = "SELECT s.rowid as socid, sf.rowid as sfidp, sf.nom as nom_facture,s.nom, l.ligne, f.nom as fournisseur, l.statut, l.rowid, l.remise";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= ",".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= " , ".MAIN_DB_PREFIX."societe as sf";
@@ -160,12 +160,12 @@ $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
 
 $sql .= ",".MAIN_DB_PREFIX."societe_perms as sp";
 
-$sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
+$sql .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
 
-$sql .= " AND s.idp = sp.fk_soc";
+$sql .= " AND s.rowid = sp.fk_soc";
 $sql .= " AND sp.fk_user = ".$user->id." AND sp.pread = 1";
 
-$sql .= " AND l.fk_soc_facture = sf.idp";
+$sql .= " AND l.fk_soc_facture = sf.rowid";
 
 $sql .= " ORDER BY rowid DESC LIMIT 10";
 
diff --git a/htdocs/telephonie/ligne/liste.php b/htdocs/telephonie/ligne/liste.php
index f9d3831468b..22c27b03f9a 100644
--- a/htdocs/telephonie/ligne/liste.php
+++ b/htdocs/telephonie/ligne/liste.php
@@ -63,14 +63,14 @@ $pagenext = $page + 1;
  *
  */
 
-$sql = "SELECT s.idp as socid, sf.idp as sfidp, sf.nom as nom_facture,s.nom, l.ligne, f.nom as fournisseur, l.statut, l.rowid, l.remise";
+$sql = "SELECT s.rowid as socid, sf.rowid as sfidp, sf.nom as nom_facture,s.nom, l.ligne, f.nom as fournisseur, l.statut, l.rowid, l.remise";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= ",".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= ",".MAIN_DB_PREFIX."societe as sf";
 $sql .= ",".MAIN_DB_PREFIX."telephonie_fournisseur as f";
 $sql .= ",".MAIN_DB_PREFIX."societe_perms as sp";
-$sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
-$sql .= " AND l.fk_soc_facture = sf.idp";
+$sql .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
+$sql .= " AND l.fk_soc_facture = sf.rowid";
 $sql .= " AND l.fk_client_comm = sp.fk_soc";
 $sql .= " AND sp.fk_user = ".$user->id." AND sp.pread = 1";
 
diff --git a/htdocs/telephonie/ligne/listecommande.php b/htdocs/telephonie/ligne/listecommande.php
index d1b8653b68e..80060856704 100644
--- a/htdocs/telephonie/ligne/listecommande.php
+++ b/htdocs/telephonie/ligne/listecommande.php
@@ -69,11 +69,11 @@ $pagenext = $page + 1;
  *
  */
 
-$sql = "SELECT s.idp as socid, l.date_commande_last, s.nom, l.ligne, f.nom as fournisseur, l.statut, l.rowid, l.remise";
+$sql = "SELECT s.rowid as socid, l.date_commande_last, s.nom, l.ligne, f.nom as fournisseur, l.statut, l.rowid, l.remise";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= " ,".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-$sql .= " WHERE l.statut = 2 AND l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
+$sql .= " WHERE l.statut = 2 AND l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
 
 if ($_GET["search_ligne"])
 {
diff --git a/htdocs/telephonie/lignetel.class.php b/htdocs/telephonie/lignetel.class.php
index 5b943f3284f..657f4615f6b 100644
--- a/htdocs/telephonie/lignetel.class.php
+++ b/htdocs/telephonie/lignetel.class.php
@@ -667,10 +667,10 @@ class LigneTel {
    */
   function log_clients()
   {
-    $sql = "SELECT distinct s.idp ";
+    $sql = "SELECT distinct s.rowid ";
     $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
     $sql .= " , ".MAIN_DB_PREFIX."societe as s";
-    $sql .= " WHERE l.statut = 3 AND s.idp = l.fk_soc ";
+    $sql .= " WHERE l.statut = 3 AND s.rowid = l.fk_soc ";
 
     if ($this->db->query($sql))
       {
@@ -829,10 +829,10 @@ class LigneTel {
     $resid = array();
 
 
-    $sql = "SELECT c.idp, c.name, c.firstname, c.email ";
+    $sql = "SELECT c.rowid, c.name, c.firstname, c.email ";
     $sql .= "FROM ".MAIN_DB_PREFIX."socpeople as c";
     $sql .= ",".MAIN_DB_PREFIX."telephonie_contact_facture as cf";
-    $sql .= " WHERE c.idp = cf.fk_contact AND cf.fk_ligne = ".$this->id." ORDER BY name ";
+    $sql .= " WHERE c.rowid = cf.fk_contact AND cf.fk_ligne = ".$this->id." ORDER BY name ";
 
     if ( $this->db->query( $sql) )
       {
diff --git a/htdocs/telephonie/script/api/presel-activation-manuelle.php b/htdocs/telephonie/script/api/presel-activation-manuelle.php
index fa9c6db8b2d..d746f46ec72 100644
--- a/htdocs/telephonie/script/api/presel-activation-manuelle.php
+++ b/htdocs/telephonie/script/api/presel-activation-manuelle.php
@@ -39,17 +39,17 @@ $user_passwd   = CMD_PRESEL_WEB_PASS;
 $user_contract = CMD_PRESEL_WEB_CONTRACT;
 
 /*
- * Lecture des lignes a r�silier
+ * Lecture des lignes a r販lier
  *
  */
-$sql = "SELECT s.nom, s.idp as socid, s.address, s.cp, s.ville";
+$sql = "SELECT s.nom, s.rowid as socid, s.address, s.cp, s.ville";
 $sql .= ", l.ligne, l.statut, l.rowid";
 
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-$sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
-$sql .= " AND f.rowid = 4 AND l.ligne = ".$ligne." ORDER BY s.idp ASC";
+$sql .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
+$sql .= " AND f.rowid = 4 AND l.ligne = ".$ligne." ORDER BY s.rowid ASC";
 
 $resql = $db->query($sql);
 $result = 1;
@@ -132,12 +132,12 @@ function ActivationPreselection($host, $user_login, $user_passwd, $ligne, $id_pe
   
   if (substr($result,0,2) == "OK")
     {
-      dolibarr_syslog("Activation r�ussie ligne ".$ligne." id client ".$id_person." $result\n");
+      dolibarr_syslog("Activation r贳sie ligne ".$ligne." id client ".$id_person." $result\n");
       return 0;
     }
   else
     {
-      dolibarr_syslog("Activation �chou�e ligne ".$ligne." id client ".$id_person." $result\n");
+      dolibarr_syslog("Activation 袨ou裠ligne ".$ligne." id client ".$id_person." $result\n");
 
       return -1;
     }
diff --git a/htdocs/telephonie/script/api/presel-resiliation-manuelle.php b/htdocs/telephonie/script/api/presel-resiliation-manuelle.php
index 0f8abc69201..996ca694a68 100644
--- a/htdocs/telephonie/script/api/presel-resiliation-manuelle.php
+++ b/htdocs/telephonie/script/api/presel-resiliation-manuelle.php
@@ -39,17 +39,17 @@ $user_passwd   = CMD_PRESEL_WEB_PASS;
 $user_contract = CMD_PRESEL_WEB_CONTRACT;
 
 /*
- * Lecture des lignes a r�silier
+ * Lecture des lignes a r販lier
  *
  */
-$sql = "SELECT s.nom, s.idp as socid, s.address, s.cp, s.ville";
+$sql = "SELECT s.nom, s.rowid as socid, s.address, s.cp, s.ville";
 $sql .= ", l.ligne, l.statut, l.rowid";
 
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-$sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
-$sql .= " AND f.rowid = 4 AND l.ligne = ".$ligne." ORDER BY s.idp ASC";
+$sql .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
+$sql .= " AND f.rowid = 4 AND l.ligne = ".$ligne." ORDER BY s.rowid ASC";
 
 $resql = $db->query($sql);
 $result = 1;
@@ -132,12 +132,12 @@ function ActivationPreselection($host, $user_login, $user_passwd, $ligne, $id_pe
   
   if (substr($result,0,2) == "OK")
     {
-      dolibarr_syslog("Resiliation r�ussie ligne ".$ligne." id client ".$id_person." $result\n");
+      dolibarr_syslog("Resiliation r贳sie ligne ".$ligne." id client ".$id_person." $result\n");
       return 0;
     }
   else
     {
-      dolibarr_syslog("Resiliation �chou�e ligne ".$ligne." id client ".$id_person." $result\n");
+      dolibarr_syslog("Resiliation 袨ou裠ligne ".$ligne." id client ".$id_person." $result\n");
 
       return -1;
     }
diff --git a/htdocs/telephonie/script/api/presel-resiliation.php b/htdocs/telephonie/script/api/presel-resiliation.php
index 00bdc561182..6ace132c09f 100644
--- a/htdocs/telephonie/script/api/presel-resiliation.php
+++ b/htdocs/telephonie/script/api/presel-resiliation.php
@@ -53,17 +53,17 @@ $user_passwd   = CMD_PRESEL_WEB_PASS;
 $user_contract = CMD_PRESEL_WEB_CONTRACT;
 
 /*
- * Lecture des lignes a r�silier
+ * Lecture des lignes a r販lier
  *
  */
-$sql = "SELECT s.nom, s.idp as socid, s.address, s.cp, s.ville";
+$sql = "SELECT s.nom, s.rowid as socid, s.address, s.cp, s.ville";
 $sql .= ", l.ligne, l.statut, l.rowid";
 
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-$sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
-$sql .= " AND f.rowid = 4 AND l.statut = 4 ORDER BY s.idp ASC";
+$sql .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
+$sql .= " AND f.rowid = 4 AND l.statut = 4 ORDER BY s.rowid ASC";
 
 $resql = $db->query($sql);
 $result = 1;
@@ -167,12 +167,12 @@ function ResiliationPreselection($host, $user_login, $user_passwd, $ligne, $id_p
 
   if (substr($result,0,2) == "OK")
     {
-      dolibarr_syslog("Resiliation r�ussie ligne ".$ligne." id client ".$id_person." $result\n");
+      dolibarr_syslog("Resiliation r贳sie ligne ".$ligne." id client ".$id_person." $result\n");
       return 0;
     }
   else
     {
-      dolibarr_syslog("Resiliation �chou�e ligne ".$ligne." id client ".$id_person." $result\n");
+      dolibarr_syslog("Resiliation 袨ou裠ligne ".$ligne." id client ".$id_person." $result\n");
 
       $fp = fopen("/tmp/$ligne.delete","w");
       if ($fp)
diff --git a/htdocs/telephonie/script/commande_presel.php b/htdocs/telephonie/script/commande_presel.php
index 0b98db38efc..2958910151b 100644
--- a/htdocs/telephonie/script/commande_presel.php
+++ b/htdocs/telephonie/script/commande_presel.php
@@ -61,13 +61,13 @@ $user_contract = CMD_PRESEL_WEB_CONTRACT;
  * Lecture des lignes a commander
  *
  */
-$sql = "SELECT s.nom, s.idp as socid, s.address, s.cp, s.ville";
+$sql = "SELECT s.nom, s.rowid as socid, s.address, s.cp, s.ville";
 $sql .= ", l.ligne, l.statut, l.rowid";
 
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-$sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
+$sql .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
 $sql .= " AND f.rowid = 4 AND l.statut = 9";
 if ($ligne > 0)
 {
@@ -358,7 +358,7 @@ function CreateAbonne($host, $user_login, $user_passwd, $user_contract, $societe
   if ($result == "OK")
     {
       if ($verbose > 1)
-	dolibarr_syslog("Commande r�ussie id client ".$client_id);
+	dolibarr_syslog("Commande r贳sie id client ".$client_id);
       return $client_id;
     }
   else
diff --git a/htdocs/telephonie/script/cron/presel-resiliation.php b/htdocs/telephonie/script/cron/presel-resiliation.php
index 345505b44c9..b2ba8b3a4b6 100644
--- a/htdocs/telephonie/script/cron/presel-resiliation.php
+++ b/htdocs/telephonie/script/cron/presel-resiliation.php
@@ -53,17 +53,17 @@ $user_passwd   = CMD_PRESEL_WEB_PASS;
 $user_contract = CMD_PRESEL_WEB_CONTRACT;
 
 /*
- * Lecture des lignes a r�silier
+ * Lecture des lignes a r販lier
  *
  */
-$sql = "SELECT s.nom, s.idp as socid, s.address, s.cp, s.ville";
+$sql = "SELECT s.nom, s.rowid as socid, s.address, s.cp, s.ville";
 $sql .= ", l.ligne, l.statut, l.rowid";
 
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-$sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
-$sql .= " AND f.rowid = 4 AND l.statut = 4 ORDER BY s.idp ASC";
+$sql .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
+$sql .= " AND f.rowid = 4 AND l.statut = 4 ORDER BY s.rowid ASC";
 
 $resql = $db->query($sql);
 $result = 1;
@@ -168,7 +168,7 @@ function ResiliationPreselection($db, $user, $host, $user_login, $user_passwd, $
   if (substr($result,0,2) == "OK")
     {
       if ($verbose)
-	dolibarr_syslog("Resiliation r�ussie ligne ".$ligne_num." id client ".$id_person." $result\n");
+	dolibarr_syslog("Resiliation r贳sie ligne ".$ligne_num." id client ".$id_person." $result\n");
 
       $ligne = new LigneTel($db);
       $ligne->fetch($ligne_num);
@@ -178,7 +178,7 @@ function ResiliationPreselection($db, $user, $host, $user_login, $user_passwd, $
     }
   else
     {
-      dolibarr_syslog("Resiliation �chou�e ligne ".$ligne_num." id client ".$id_person." $result\n");
+      dolibarr_syslog("Resiliation 袨ou裠ligne ".$ligne_num." id client ".$id_person." $result\n");
 
       $fp = fopen("/tmp/$ligne.delete","w");
       if ($fp)
diff --git a/htdocs/telephonie/script/delete_presel.php b/htdocs/telephonie/script/delete_presel.php
index 83e1be11ba9..709d2ebd8b0 100644
--- a/htdocs/telephonie/script/delete_presel.php
+++ b/htdocs/telephonie/script/delete_presel.php
@@ -53,17 +53,17 @@ $user_passwd   = CMD_PRESEL_WEB_PASS;
 $user_contract = CMD_PRESEL_WEB_CONTRACT;
 
 /*
- * Lecture des lignes a r�silier
+ * Lecture des lignes a r販lier
  *
  */
-$sql = "SELECT s.nom, s.idp as socid, s.address, s.cp, s.ville";
+$sql = "SELECT s.nom, s.rowid as socid, s.address, s.cp, s.ville";
 $sql .= ", l.ligne, l.statut, l.rowid";
 
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-$sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
-$sql .= " AND f.rowid = 4 AND l.statut = 4 ORDER BY s.idp ASC";
+$sql .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
+$sql .= " AND f.rowid = 4 AND l.statut = 4 ORDER BY s.rowid ASC";
 
 $resql = $db->query($sql);
 $result = 1;
@@ -165,12 +165,12 @@ function DeletePreselection($host, $user_login, $user_passwd, $ligne, $id_person
 
   if (substr($result,0,2) == "OK")
     {
-      dolibarr_syslog("Delete r�ussi ligne ".$ligne." id client ".$id_person." $result\n");
+      dolibarr_syslog("Delete r贳si ligne ".$ligne." id client ".$id_person." $result\n");
       return 0;
     }
   else
     {
-      dolibarr_syslog("Delete �chou� ligne ".$ligne." id client ".$id_person." $result\n");
+      dolibarr_syslog("Delete 袨ou矬igne ".$ligne." id client ".$id_person." $result\n");
 
       $fp = fopen("/tmp/$ligne.delete","w");
       if ($fp)
diff --git a/htdocs/telephonie/script/envoi-emails-speciaux.php b/htdocs/telephonie/script/envoi-emails-speciaux.php
index 0d7fff92aae..61458476279 100644
--- a/htdocs/telephonie/script/envoi-emails-speciaux.php
+++ b/htdocs/telephonie/script/envoi-emails-speciaux.php
@@ -55,7 +55,7 @@ $factures_lignes = array();
  */
 $sql = "SELECT sc.email FROM ";     
 $sql .= MAIN_DB_PREFIX."socpeople as sc";
-$sql .= " WHERE sc.idp = ".$contactid;
+$sql .= " WHERE sc.rowid = ".$contactid;
 
 $resql = $db->query($sql);
 
@@ -81,10 +81,10 @@ $sql .= MAIN_DB_PREFIX."telephonie_facture as f";
 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 
-$sql .= " WHERE s.idp = l.fk_client_comm";
+$sql .= " WHERE s.rowid = l.fk_client_comm";
 $sql .= " AND f.fk_facture IS NOT NULL";
 $sql .= " AND l.rowid = f.fk_ligne";
-$sql .= " AND s.idp = ".$clientid;
+$sql .= " AND s.rowid = ".$clientid;
 $sql .= " AND date_format(date,'%Y%m') = ".$year.$month;
 $sql .= " ORDER BY f.fk_facture ASC";
 
@@ -120,10 +120,10 @@ $sql .= MAIN_DB_PREFIX."telephonie_facture as f";
 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 
-$sql .= " WHERE s.idp = l.fk_client_comm";
+$sql .= " WHERE s.rowid = l.fk_client_comm";
 $sql .= " AND f.fk_facture IS NOT NULL";
 $sql .= " AND l.rowid = f.fk_ligne";
-$sql .= " AND s.idp = ".$clientid;
+$sql .= " AND s.rowid = ".$clientid;
 $sql .= " AND date_format(date,'%Y%m') = ".$year.$month;
 $sql .= " ORDER BY f.fk_facture ASC";
 
diff --git a/htdocs/telephonie/script/facturation-alerte.php b/htdocs/telephonie/script/facturation-alerte.php
index f7e67edd7f0..12b7718f714 100644
--- a/htdocs/telephonie/script/facturation-alerte.php
+++ b/htdocs/telephonie/script/facturation-alerte.php
@@ -131,9 +131,9 @@ if (!$error)
   $sql .= " AND f.isfacturable = 'oui'"; 
   $sql .= " AND f.fk_ligne = l.rowid ";
   $sql .= " AND l.fk_contrat = c.rowid";  
-  $sql .= " AND c.fk_client_comm = s.idp";
+  $sql .= " AND c.fk_client_comm = s.rowid";
   $sql .= " AND f.fourn_montant > f.cout_vente";
-  $sql .= " ORDER BY s.idp ASC, c.rowid ASC";
+  $sql .= " ORDER BY s.rowid ASC, c.rowid ASC";
     
   $resql = $db->query($sql) ;
 
@@ -194,7 +194,7 @@ if (!$error)
 
 if (!$error)
 {
-  $sql = "SELECT distinct(s.idp), s.nom";
+  $sql = "SELECT distinct(s.rowid), s.nom";
   $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture as f";
   $sql .= " ,    ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
   $sql .= " ,    ".MAIN_DB_PREFIX."telephonie_contrat as c";
@@ -205,7 +205,7 @@ if (!$error)
   $sql .= " AND f.isfacturable = 'oui'"; 
   $sql .= " AND f.fk_ligne = l.rowid ";
   $sql .= " AND l.fk_contrat = c.rowid";  
-  $sql .= " AND c.fk_client_comm = s.idp";
+  $sql .= " AND c.fk_client_comm = s.rowid";
   $sql .= " AND f.fourn_montant > f.cout_vente";
   $sql .= " GROUP BY s.nom ASC";
 
@@ -259,11 +259,11 @@ if (!$error)
 	  $sql .= " ,    ".MAIN_DB_PREFIX."societe as s";
 	  
 	  $sql .= " WHERE f.fk_facture IS NOT NULL";
-	  $sql .= " AND s.idp = ".$row[0];
+	  $sql .= " AND s.rowid = ".$row[0];
 	  $sql .= " AND f.isfacturable = 'oui'"; 
 	  $sql .= " AND f.fk_ligne = l.rowid ";
 	  $sql .= " AND l.fk_contrat = c.rowid";  
-	  $sql .= " AND c.fk_client_comm = s.idp";
+	  $sql .= " AND c.fk_client_comm = s.rowid";
 	  $sql .= " ORDER BY f.date DESC";
 	  
 	  $re2sql = $db->query($sql) ;
diff --git a/htdocs/telephonie/script/facturation-consolidation.php b/htdocs/telephonie/script/facturation-consolidation.php
index 3d06bb69a62..2f782dcbe82 100644
--- a/htdocs/telephonie/script/facturation-consolidation.php
+++ b/htdocs/telephonie/script/facturation-consolidation.php
@@ -108,8 +108,8 @@ $sql .= " , ".MAIN_DB_PREFIX."societe as groupe";
 $sql .= " , ".MAIN_DB_PREFIX."societe as agence";
 $sql .= " , ".MAIN_DB_PREFIX."user as u";
 $sql .= " WHERE l.fk_contrat = c.rowid";
-$sql .= " AND c.fk_client_comm = groupe.idp";
-$sql .= " AND c.fk_soc = agence.idp";
+$sql .= " AND c.fk_client_comm = groupe.rowid";
+$sql .= " AND c.fk_soc = agence.rowid";
 $sql .= " AND c.fk_commercial_sign = u.rowid";
 //$sql .= " LIMIT 20";
 $resql = $db->query($sql);
diff --git a/htdocs/telephonie/script/facturation-emission.php b/htdocs/telephonie/script/facturation-emission.php
index 5eefab070ca..2c2b4cea97a 100644
--- a/htdocs/telephonie/script/facturation-emission.php
+++ b/htdocs/telephonie/script/facturation-emission.php
@@ -178,8 +178,8 @@ if (!$error)
       /* Lecture des factures t�l�phoniques du contrat */
       dolibarr_syslog($xcli."/".$xclis." Contrat � facturer id=".$contrat." (".memory_get_usage() .")");
 
-      $sql = "SELECT f.rowid, s.idp FROM ";     
-      $sql .=     MAIN_DB_PREFIX."telephonie_facture as f";
+      $sql = "SELECT f.rowid, s.rowid as socid";    
+      $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture as f";
       $sql .= ",".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
       $sql .= " ,    ".MAIN_DB_PREFIX."telephonie_contrat as c";
       $sql .= ",".MAIN_DB_PREFIX."societe as s";
@@ -188,7 +188,7 @@ if (!$error)
       $sql .= " AND c.rowid = ".$contrat;
       $sql .= " AND l.fk_contrat = c.rowid";
       $sql .= " AND l.rowid = f.fk_ligne";
-      $sql .= " AND s.idp = c.fk_soc_facture ";
+      $sql .= " AND s.rowid = c.fk_soc_facture ";
       $sql .= " AND f.fk_facture IS NULL";
       $sql .= " AND f.isfacturable = 'oui'";  
 
diff --git a/htdocs/telephonie/script/graph-statistiques-clients.php b/htdocs/telephonie/script/graph-statistiques-clients.php
index 975c812989c..5fd959cd434 100644
--- a/htdocs/telephonie/script/graph-statistiques-clients.php
+++ b/htdocs/telephonie/script/graph-statistiques-clients.php
@@ -37,7 +37,7 @@ if ($db->query($sql))
 
 }
 
-$sql = "SELECT max(s.idp)";
+$sql = "SELECT max(s.rowid)";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 
 if ($db->query($sql))
diff --git a/htdocs/telephonie/script/graph-statistiques-makedir.php b/htdocs/telephonie/script/graph-statistiques-makedir.php
index 448f68acb66..09a4eb566a5 100644
--- a/htdocs/telephonie/script/graph-statistiques-makedir.php
+++ b/htdocs/telephonie/script/graph-statistiques-makedir.php
@@ -149,7 +149,7 @@ for ($j = 0 ; $j < 10 ; $j++)
  *
  */
 
-$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe";
+$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe";
 
 if ($db->query($sql))
 {
diff --git a/htdocs/telephonie/script/plan-facturation.php b/htdocs/telephonie/script/plan-facturation.php
index 8af333bef39..aaf37d13a1a 100644
--- a/htdocs/telephonie/script/plan-facturation.php
+++ b/htdocs/telephonie/script/plan-facturation.php
@@ -47,7 +47,7 @@ $sql .=" , ".MAIN_DB_PREFIX."societe as s";
 $sql .= " WHERE sl.fk_contrat  = c.rowid";
 $sql .= " AND c.fk_client_comm = 52";
 $sql .= " AND sl.statut <> 7";
-$sql .= " AND c.fk_soc_facture = s.idp";
+$sql .= " AND c.fk_soc_facture = s.rowid";
 $sql .= " ORDER BY c.rowid ASC, sl.code_analytique ASC";
 
 $resql = $db->query($sql);
diff --git a/htdocs/telephonie/script/recap-commande-week.php b/htdocs/telephonie/script/recap-commande-week.php
index d4c67a1b03a..91d46d2f369 100644
--- a/htdocs/telephonie/script/recap-commande-week.php
+++ b/htdocs/telephonie/script/recap-commande-week.php
@@ -153,7 +153,7 @@ function Generate($date_gen, $db, $date_now, $email)
 
   $ligneids = array();
 
-  $sqlall = "SELECT s.code_client, s.nom, s.idp as socid, l.ligne, f.nom as fournisseur, l.statut, l.rowid";
+  $sqlall = "SELECT s.code_client, s.nom, s.rowid as socid, l.ligne, f.nom as fournisseur, l.statut, l.rowid";
   $sqlall .= " , comm.name, comm.firstname, l.remise";
   $sqlall .= " , ".$db->pdate("l.date_commande")." as date_commande";
   $sqlall .= " FROM ".MAIN_DB_PREFIX."societe as s";
@@ -161,8 +161,8 @@ function Generate($date_gen, $db, $date_now, $email)
   $sqlall .= " , ".MAIN_DB_PREFIX."societe as r";
   $sqlall .= " , ".MAIN_DB_PREFIX."user as comm";
   $sqlall .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-  $sqlall .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
-  $sqlall .= " AND l.fk_soc_facture = r.idp ";
+  $sqlall .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
+  $sqlall .= " AND l.fk_soc_facture = r.rowid ";
   $sqlall .= " AND l.fk_commercial = comm.rowid ";
   $sqlall .= " AND date_format(l.date_commande,'%Y%v') = '".strftime("%Y%V", $date_gen)."'";
   /*
diff --git a/htdocs/telephonie/script/recap-commande.php b/htdocs/telephonie/script/recap-commande.php
index 15af4bbe71b..92b7898af2d 100644
--- a/htdocs/telephonie/script/recap-commande.php
+++ b/htdocs/telephonie/script/recap-commande.php
@@ -157,7 +157,7 @@ function Generate($date_gen, $db, $date_now, $email)
 
   $ligneids = array();
 
-  $sqlall = "SELECT s.code_client, s.nom, s.idp as socid, l.ligne, f.nom as fournisseur, l.statut, l.rowid";
+  $sqlall = "SELECT s.code_client, s.nom, s.rowid as socid, l.ligne, f.nom as fournisseur, l.statut, l.rowid";
   $sqlall .= " , comm.name, comm.firstname, l.remise";
   $sqlall .= " , ".$db->pdate("l.date_commande")." as date_commande";
   $sqlall .= " FROM ".MAIN_DB_PREFIX."societe as s";
@@ -165,8 +165,8 @@ function Generate($date_gen, $db, $date_now, $email)
   $sqlall .= " , ".MAIN_DB_PREFIX."societe as r";
   $sqlall .= " , ".MAIN_DB_PREFIX."user as comm";
   $sqlall .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-  $sqlall .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
-  $sqlall .= " AND l.fk_soc_facture = r.idp ";
+  $sqlall .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
+  $sqlall .= " AND l.fk_soc_facture = r.rowid ";
   $sqlall .= " AND l.fk_commercial = comm.rowid ";
   $sqlall .= " AND date_format(l.date_commande,'%Y%m') = '".strftime("%Y%m", $date_gen)."'";
   /*
diff --git a/htdocs/telephonie/script/tools/export-adsl-actives.php b/htdocs/telephonie/script/tools/export-adsl-actives.php
index 26730412f33..73114b25a19 100644
--- a/htdocs/telephonie/script/tools/export-adsl-actives.php
+++ b/htdocs/telephonie/script/tools/export-adsl-actives.php
@@ -33,7 +33,7 @@ $sql = "SELECT la.numero_ligne, s.nom as nom,  la.prix, t.intitule";
 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_adsl_ligne as la";
 $sql .= " ,  ".MAIN_DB_PREFIX."societe as s";
 $sql .= " ,  ".MAIN_DB_PREFIX."telephonie_adsl_type as t";
-$sql .= " WHERE la.fk_client_facture = s.idp";
+$sql .= " WHERE la.fk_client_facture = s.rowid";
 $sql .= " AND t.rowid = la.fk_type";
 
 
diff --git a/htdocs/telephonie/script/tools/export-comms-client52.php b/htdocs/telephonie/script/tools/export-comms-client52.php
index f708097ace1..38ff0267ee5 100644
--- a/htdocs/telephonie/script/tools/export-comms-client52.php
+++ b/htdocs/telephonie/script/tools/export-comms-client52.php
@@ -38,7 +38,7 @@ $sql .= " WHERE date_format(f.date,'%Y') = '2006'";
 $sql .= " AND l.fk_contrat = c.rowid";
 $sql .= " AND c.fk_client_comm = 52";
 $sql .= " AND f.ligne = l.ligne";
-$sql .= " AND l.fk_soc_facture =s.idp";
+$sql .= " AND l.fk_soc_facture =s.rowid";
 $sql .= " AND fc.rowid = f.fk_facture";
 $sql .= " ORDER BY f.date ASC, f.fk_ligne ASC";
 
diff --git a/htdocs/telephonie/script/tools/export-recap-client52.php b/htdocs/telephonie/script/tools/export-recap-client52.php
index 09c7c1c42b1..e64b2649fca 100644
--- a/htdocs/telephonie/script/tools/export-recap-client52.php
+++ b/htdocs/telephonie/script/tools/export-recap-client52.php
@@ -38,7 +38,7 @@ $sql .= " WHERE date_format(f.date,'%Y') = '2005'";
 $sql .= " AND l.fk_contrat = c.rowid";
 $sql .= " AND c.fk_client_comm = 52";
 $sql .= " AND f.ligne = l.ligne";
-$sql .= " AND l.fk_soc_facture =s.idp";
+$sql .= " AND l.fk_soc_facture =s.rowid";
 $sql .= " AND fc.rowid = f.fk_facture";
 $sql .= " ORDER BY f.date ASC, f.fk_ligne ASC";
 
diff --git a/htdocs/telephonie/script/tools/permissions.php b/htdocs/telephonie/script/tools/permissions.php
index d637464d5fb..b4e9187a170 100644
--- a/htdocs/telephonie/script/tools/permissions.php
+++ b/htdocs/telephonie/script/tools/permissions.php
@@ -28,7 +28,7 @@
  ****************************************************************/
 require ("../../../master.inc.php");
 
-$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe";
+$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe";
 $resql = $db->query($sql);
   
 if ( $resql )
diff --git a/htdocs/telephonie/script/update_presel.php b/htdocs/telephonie/script/update_presel.php
index 6538738329e..bdbcdce3cd4 100644
--- a/htdocs/telephonie/script/update_presel.php
+++ b/htdocs/telephonie/script/update_presel.php
@@ -56,13 +56,13 @@ $user_contract = CMD_PRESEL_WEB_CONTRACT;
  * Lecture des lignes a commander
  *
  */
-$sql = "SELECT s.nom, s.idp as socid, s.address, s.cp, s.ville";
+$sql = "SELECT s.nom, s.rowid as socid, s.address, s.cp, s.ville";
 $sql .= ", l.ligne, l.statut, l.rowid";
 
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-$sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
+$sql .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
 $sql .= " AND f.rowid = 4";
 $sql .= " AND l.ligne='".$argv[1]."'";
 $sql .= " ORDER BY l.rowid DESC";
diff --git a/htdocs/telephonie/service/contrats.php b/htdocs/telephonie/service/contrats.php
index 76e14daabad..9940ece79a5 100644
--- a/htdocs/telephonie/service/contrats.php
+++ b/htdocs/telephonie/service/contrats.php
@@ -86,14 +86,14 @@ if ($_GET["id"])
       dolibarr_fiche_head($head, $hselected, 'Service : '.$service->id);
       
       
-      $sql = "SELECT s.idp as socid, s.nom as nom_facture";
+      $sql = "SELECT s.rowid as socid, s.nom as nom_facture";
       $sql .= " , c.ref, cs.montant, c.rowid as crowid";
       $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
       $sql .= " , ".MAIN_DB_PREFIX."telephonie_contrat as c";
       $sql .= " , ".MAIN_DB_PREFIX."telephonie_contrat_service as cs";
       $sql .= " WHERE cs.fk_service = ".$_GET["id"];
       $sql .= " AND cs.fk_contrat = c.rowid";
-      $sql .= " AND s.idp = c.fk_soc_facture";
+      $sql .= " AND s.rowid = c.fk_soc_facture";
       
       if ($_GET["search_client"])
 	{
@@ -148,7 +148,7 @@ if ($_GET["id"])
 	      
 	      print '<a href="'.DOL_URL_ROOT.'/telephonie/contrat/fiche.php?id='.$obj->crowid.'">'.$obj->ref."</a></td>\n";
 	      
-	      print '<td><a href="'.DOL_URL_ROOT.'/soc.php?socid='.$obj->sfidp.'">'.stripslashes($obj->nom_facture).'</a></td>';
+	      print '<td><a href="'.DOL_URL_ROOT.'/soc.php?socid='.$obj->socid.'">'.stripslashes($obj->nom_facture).'</a></td>';
 	      
 	      print '<td align="right">'.price($obj->montant)."</td>\n";
 	      print "</tr>\n";
diff --git a/htdocs/telephonie/service/vendus.php b/htdocs/telephonie/service/vendus.php
index 8043532f666..f0c9b747212 100644
--- a/htdocs/telephonie/service/vendus.php
+++ b/htdocs/telephonie/service/vendus.php
@@ -64,12 +64,12 @@ $pagenext = $page + 1;
  *
  */
 
-$sql = "SELECT s.rowid, idp as socid, sf.idp as sfidp, sf.nom as nom_facture,s.nom, l.ligne, f.nom as fournisseur, l.statut, l.rowid, l.remise";
+$sql = "SELECT s.rowid as socid, sf.rowid as sfidp, sf.nom as nom_facture,s.nom, l.ligne, f.nom as fournisseur, l.statut, l.rowid, l.remise";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 $sql .= " ,  ".MAIN_DB_PREFIX."societe as sf";
 $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-$sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
-$sql .= " AND l.fk_soc_facture = sf.idp";
+$sql .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
+$sql .= " AND l.fk_soc_facture = sf.rowid";
 
 if ($_GET["search_ligne"])
 {
diff --git a/htdocs/telephonie/sql/llx_telephonie_adsl_fournisseur.key.sql b/htdocs/telephonie/sql/llx_telephonie_adsl_fournisseur.key.sql
index 7d10d1fd489..0a8e8d8d331 100644
--- a/htdocs/telephonie/sql/llx_telephonie_adsl_fournisseur.key.sql
+++ b/htdocs/telephonie/sql/llx_telephonie_adsl_fournisseur.key.sql
@@ -26,5 +26,5 @@
 ALTER TABLE llx_telephonie_adsl_fournisseur ADD INDEX (fk_soc);
 --
 --
-ALTER TABLE llx_telephonie_adsl_fournisseur ADD FOREIGN KEY (fk_soc) REFERENCES llx_societe (idp);
+ALTER TABLE llx_telephonie_adsl_fournisseur ADD FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
 
diff --git a/htdocs/telephonie/sql/llx_telephonie_client_stats.key.sql b/htdocs/telephonie/sql/llx_telephonie_client_stats.key.sql
index 28fa5c9a1f2..de2ba21057a 100644
--- a/htdocs/telephonie/sql/llx_telephonie_client_stats.key.sql
+++ b/htdocs/telephonie/sql/llx_telephonie_client_stats.key.sql
@@ -23,4 +23,4 @@
 --
 
 
-ALTER TABLE llx_telephonie_client_stats ADD FOREIGN KEY (fk_client_comm) REFERENCES llx_societe(idp);
+ALTER TABLE llx_telephonie_client_stats ADD FOREIGN KEY (fk_client_comm) REFERENCES llx_societe(rowid);
diff --git a/htdocs/telephonie/sql/llx_telephonie_contact_facture.key.sql b/htdocs/telephonie/sql/llx_telephonie_contact_facture.key.sql
index 4bd32437742..b2eea1647b7 100644
--- a/htdocs/telephonie/sql/llx_telephonie_contact_facture.key.sql
+++ b/htdocs/telephonie/sql/llx_telephonie_contact_facture.key.sql
@@ -6,5 +6,5 @@
 ALTER TABLE llx_telephonie_contact_facture ADD INDEX (fk_contact);
 ALTER TABLE llx_telephonie_contact_facture ADD INDEX (fk_ligne);
 
-ALTER TABLE llx_telephonie_contact_facture ADD FOREIGN KEY (fk_contact) REFERENCES llx_socpeople (idp);
+ALTER TABLE llx_telephonie_contact_facture ADD FOREIGN KEY (fk_contact) REFERENCES llx_socpeople (rowid);
 ALTER TABLE llx_telephonie_contact_facture ADD FOREIGN KEY (fk_ligne) REFERENCES llx_telephonie_societe_ligne (rowid);
diff --git a/htdocs/telephonie/sql/llx_telephonie_societe_ligne.key.sql b/htdocs/telephonie/sql/llx_telephonie_societe_ligne.key.sql
index c368d601fea..08238d2a8ed 100644
--- a/htdocs/telephonie/sql/llx_telephonie_societe_ligne.key.sql
+++ b/htdocs/telephonie/sql/llx_telephonie_societe_ligne.key.sql
@@ -38,9 +38,9 @@ ALTER TABLE llx_telephonie_societe_ligne ADD INDEX (fk_commercial);
 ALTER TABLE llx_telephonie_societe_ligne ADD INDEX (fk_concurrent);
 
 ALTER TABLE llx_telephonie_societe_ligne ADD FOREIGN KEY (fk_fournisseur)   REFERENCES llx_telephonie_fournisseur (rowid);
-ALTER TABLE llx_telephonie_societe_ligne ADD FOREIGN KEY (fk_client_comm)   REFERENCES llx_societe(idp);
-ALTER TABLE llx_telephonie_societe_ligne ADD FOREIGN KEY (fk_soc)           REFERENCES llx_societe(idp);
-ALTER TABLE llx_telephonie_societe_ligne ADD FOREIGN KEY (fk_soc_facture)   REFERENCES llx_societe(idp);
+ALTER TABLE llx_telephonie_societe_ligne ADD FOREIGN KEY (fk_client_comm)   REFERENCES llx_societe(rowid);
+ALTER TABLE llx_telephonie_societe_ligne ADD FOREIGN KEY (fk_soc)           REFERENCES llx_societe(rowid);
+ALTER TABLE llx_telephonie_societe_ligne ADD FOREIGN KEY (fk_soc_facture)   REFERENCES llx_societe(rowid);
 ALTER TABLE llx_telephonie_societe_ligne ADD FOREIGN KEY (fk_user_creat)    REFERENCES llx_user(rowid);
 ALTER TABLE llx_telephonie_societe_ligne ADD FOREIGN KEY (fk_user_commande) REFERENCES llx_user(rowid);
 ALTER TABLE llx_telephonie_societe_ligne ADD FOREIGN KEY (fk_commercial) REFERENCES llx_user(rowid);
diff --git a/htdocs/telephonie/sql/llx_telephonie_tarif_client.key.sql b/htdocs/telephonie/sql/llx_telephonie_tarif_client.key.sql
index 1b932ad994e..9d2e1479915 100644
--- a/htdocs/telephonie/sql/llx_telephonie_tarif_client.key.sql
+++ b/htdocs/telephonie/sql/llx_telephonie_tarif_client.key.sql
@@ -27,5 +27,5 @@ ALTER TABLE llx_telephonie_tarif_client ADD INDEX (fk_client);
 ALTER TABLE llx_telephonie_tarif_client ADD INDEX (fk_user);
 
 ALTER TABLE llx_telephonie_tarif_client ADD FOREIGN KEY (fk_tarif) REFERENCES llx_telephonie_tarif (rowid);
-ALTER TABLE llx_telephonie_tarif_client ADD FOREIGN KEY (fk_client) REFERENCES llx_societe (idp);
+ALTER TABLE llx_telephonie_tarif_client ADD FOREIGN KEY (fk_client) REFERENCES llx_societe (rowid);
 ALTER TABLE llx_telephonie_tarif_client ADD FOREIGN KEY (fk_user) REFERENCES llx_user (rowid);
diff --git a/htdocs/telephonie/stats/ProcessGraphClients.class.php b/htdocs/telephonie/stats/ProcessGraphClients.class.php
index e826a026708..79c9bbdcc3d 100644
--- a/htdocs/telephonie/stats/ProcessGraphClients.class.php
+++ b/htdocs/telephonie/stats/ProcessGraphClients.class.php
@@ -71,21 +71,21 @@ class ProcessGraphClients
      * Lecture des clients
      *
      */
-    $sql = "SELECT s.idp as socid, s.nom, count(l.ligne) as ligne";
+    $sql = "SELECT s.rowid as socid, s.nom, count(l.ligne) as ligne";
     $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
     $sql .= ",".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
-    $sql .= " WHERE l.fk_client_comm = s.idp ";
+    $sql .= " WHERE l.fk_client_comm = s.rowid ";
     if ($id == 0)
       {
-	$sql .= " AND s.idp >= ".$min;
-	$sql .= " AND s.idp < ".$max;
+	$sql .= " AND s.rowid >= ".$min;
+	$sql .= " AND s.rowid < ".$max;
       }
     else
       {
 	$sql .= " AND l.fk_client_comm = ".$id;
       }
 
-    $sql .= " GROUP BY s.idp";
+    $sql .= " GROUP BY s.rowid";
 
     $resql = $this->db->query($sql);
     
diff --git a/htdocs/telephonie/stats/clients/alerte.php b/htdocs/telephonie/stats/clients/alerte.php
index 43279ee6f85..f3764e7f760 100644
--- a/htdocs/telephonie/stats/clients/alerte.php
+++ b/htdocs/telephonie/stats/clients/alerte.php
@@ -63,12 +63,12 @@ print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
 
 print '<tr><td width="70%" valign="top">';
 
-$sql = "SELECT nom, ca, gain, cout, marge, idp";
-$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_client_stats";
-$sql .= " , " .MAIN_DB_PREFIX."societe";
-$sql .= " WHERE idp = fk_client_comm";
-$sql .= " AND marge < ". $marge;
-$sql .= " GROUP BY marge DESC";
+$sql = "SELECT s.nom, tcs.ca, tcs.gain, tcs.cout, tcs.marge, s.rowid";
+$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_client_stats as tcs";
+$sql .= " , " .MAIN_DB_PREFIX."societe as s";
+$sql .= " WHERE s.rowid = tcs.fk_client_comm";
+$sql .= " AND tcs.marge < ". $marge;
+$sql .= " GROUP BY tcs.marge DESC";
 
 if ($db->query($sql))
 {
diff --git a/htdocs/telephonie/stats/clients/gain.php b/htdocs/telephonie/stats/clients/gain.php
index 0100e4c67b0..b63d9304ccf 100644
--- a/htdocs/telephonie/stats/clients/gain.php
+++ b/htdocs/telephonie/stats/clients/gain.php
@@ -52,10 +52,10 @@ $sortorder = $_GET["sortorder"];
 if ($sortorder == "") $sortorder="DESC";
 if ($sortfield == "") $sortfield="marge";
 
-$sql = "SELECT nom, ca, gain, cout, marge, idp";
-$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_client_stats";
-$sql .= " , " .MAIN_DB_PREFIX."societe";
-$sql .= " WHERE idp = fk_client_comm";
+$sql = "SELECT s.nom, tcs.ca, tcs.gain, tcs.cout, tcs.marge, s.rowid";
+$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_client_stats as tcs";
+$sql .= " , " .MAIN_DB_PREFIX."societe as s";
+$sql .= " WHERE s.rowid = tcs.fk_client_comm";
 $sql .= " ORDER BY $sortfield $sortorder ";// . $db->plimit($conf->liste_limit+1, $offset);
 
 if ($db->query($sql))
@@ -65,11 +65,11 @@ if ($db->query($sql))
 
   print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
   print '<tr class="liste_titre">';
-  print_liste_field_titre("Client","gain.php","nom");
-  print_liste_field_titre("Marge","gain.php","marge",'','','align="right"');
-  print_liste_field_titre("Gain Total","gain.php","gain",'','','align="right"');
-  print_liste_field_titre("Vente","gain.php","ca",'','','align="right"');
-  print_liste_field_titre("Achat","gain.php","cout",'','','align="right"');
+  print_liste_field_titre("Client","gain.php","s.nom");
+  print_liste_field_titre("Marge","gain.php","tcs.marge",'','','align="right"');
+  print_liste_field_titre("Gain Total","gain.php","tcs.gain",'','','align="right"');
+  print_liste_field_titre("Vente","gain.php","tcs.ca",'','','align="right"');
+  print_liste_field_titre("Achat","gain.php","tcs.cout",'','','align="right"');
   print "</tr>\n";
   $var=True;
 
diff --git a/htdocs/telephonie/stats/commerciaux/commercialpo.php b/htdocs/telephonie/stats/commerciaux/commercialpo.php
index 5fa2b51aa6b..ac064911f26 100644
--- a/htdocs/telephonie/stats/commerciaux/commercialpo.php
+++ b/htdocs/telephonie/stats/commerciaux/commercialpo.php
@@ -80,7 +80,7 @@ if ($_GET["commid"])
    *
    */
   
-  $sql = "SELECT s.idp, s.nom, p.fk_contrat, p.montant, p.avance_duree, p.avance_pourcent";
+  $sql = "SELECT s.rowid as socid, s.nom, p.fk_contrat, p.montant, p.avance_duree, p.avance_pourcent";
   $sql .= ", p.rem_pour_prev, p.rem_pour_autr, p.mode_paiement";
   $sql .= " , ".$db->pdate("p.datepo") . " as datepo";
   $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_contrat_priseordre as p";
@@ -88,7 +88,7 @@ if ($_GET["commid"])
   $sql .= " , ".MAIN_DB_PREFIX."societe as s";
   
   $sql .= " WHERE p.fk_commercial =".$_GET["commid"];
-  $sql .= " AND c.fk_soc = s.idp";
+  $sql .= " AND c.fk_soc = s.rowid";
   $sql .= " AND p.fk_contrat = c.rowid";
   $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset);
   
@@ -119,11 +119,11 @@ if ($_GET["commid"])
 	  
 	  print "<tr $bc[$var]>";
 	  
-	  print '<td><a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->idp.'">';
+	  print '<td><a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">';
 	  print img_file();
 	  print '</a>&nbsp;';
       
-	  print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->idp.'">'.$obj->nom."</a></td>\n";
+	  print '<a href="'.DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$obj->socid.'">'.$obj->nom."</a></td>\n";
 	  print '<td><a href="'.DOL_URL_ROOT.'/telephonie/contrat/fiche.php?id='.$obj->fk_contrat.'">'.$obj->fk_contrat."</a></td>\n";
 	  print '<td align="center">'.strftime("%e %b %Y",$obj->datepo)."</td>\n";
 
diff --git a/htdocs/telephonie/tarifs/config/index.php b/htdocs/telephonie/tarifs/config/index.php
index 184972797cf..61258f75ca8 100644
--- a/htdocs/telephonie/tarifs/config/index.php
+++ b/htdocs/telephonie/tarifs/config/index.php
@@ -41,14 +41,14 @@ if ($user->societe_id > 0)
  */
 if ($mode == 'search') {
   if ($mode-search == 'soc') {
-    $sql = "SELECT s.idp FROM ".MAIN_DB_PREFIX."societe as s ";
+    $sql = "SELECT s.rowid as socid FROM ".MAIN_DB_PREFIX."societe as s ";
     $sql .= " WHERE lower(s.nom) like '%".strtolower($socname)."%'";
   }
       
   if ( $db->query($sql) ) {
     if ( $db->num_rows() == 1) {
       $obj = $db->fetch_object(0);
-      $socid = $obj->idp;
+      $socid = $obj->socid;
     }
     $db->free();
   }
diff --git a/htdocs/telephonie/tarifs/config/prefixs.php b/htdocs/telephonie/tarifs/config/prefixs.php
index a30dc3ecc46..af4a84a818c 100644
--- a/htdocs/telephonie/tarifs/config/prefixs.php
+++ b/htdocs/telephonie/tarifs/config/prefixs.php
@@ -41,14 +41,14 @@ if ($user->societe_id > 0)
  */
 if ($mode == 'search') {
   if ($mode-search == 'soc') {
-    $sql = "SELECT s.idp FROM ".MAIN_DB_PREFIX."societe as s ";
+    $sql = "SELECT s.rowid as socid FROM ".MAIN_DB_PREFIX."societe as s ";
     $sql .= " WHERE lower(s.nom) like '%".strtolower($socname)."%'";
   }
       
   if ( $db->query($sql) ) {
     if ( $db->num_rows() == 1) {
       $obj = $db->fetch_object(0);
-      $socid = $obj->idp;
+      $socid = $obj->socid;
     }
     $db->free();
   }
diff --git a/htdocs/telephonie/tarifs/fiche.php b/htdocs/telephonie/tarifs/fiche.php
index 7ff56333277..b4a49f10306 100644
--- a/htdocs/telephonie/tarifs/fiche.php
+++ b/htdocs/telephonie/tarifs/fiche.php
@@ -77,11 +77,11 @@ if ($_GET["id"])
 	  
 	  /* Lignes */
 	     
-	  $sql = "SELECT s.idp as socid, s.nom, l.ligne, f.nom as fournisseur, l.statut, l.rowid, l.remise";
+	  $sql = "SELECT s.rowid as socid, s.nom, l.ligne, f.nom as fournisseur, l.statut, l.rowid, l.remise";
 	  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 	  $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
-	  $sql .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
-	  $sql .= " AND s.idp = ".$soc->id;
+	  $sql .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
+	  $sql .= " AND s.rowid = ".$soc->id;
 	  
 	  if ( $db->query( $sql) )
 	    {
diff --git a/htdocs/telephonie/tarifs/index.php b/htdocs/telephonie/tarifs/index.php
index 00e25caf28c..228de107a06 100644
--- a/htdocs/telephonie/tarifs/index.php
+++ b/htdocs/telephonie/tarifs/index.php
@@ -41,14 +41,14 @@ if ($user->societe_id > 0)
  */
 if ($mode == 'search') {
   if ($mode-search == 'soc') {
-    $sql = "SELECT s.idp FROM ".MAIN_DB_PREFIX."societe as s ";
+    $sql = "SELECT s.rowid as socid FROM ".MAIN_DB_PREFIX."societe as s ";
     $sql .= " WHERE lower(s.nom) like '%".strtolower($socname)."%'";
   }
       
   if ( $db->query($sql) ) {
     if ( $db->num_rows() == 1) {
       $obj = $db->fetch_object(0);
-      $socid = $obj->idp;
+      $socid = $obj->socid;
     }
     $db->free();
   }
diff --git a/htdocs/telephonie/telephonie.contrat.class.php b/htdocs/telephonie/telephonie.contrat.class.php
index b22006ac2a2..e46182edb1d 100644
--- a/htdocs/telephonie/telephonie.contrat.class.php
+++ b/htdocs/telephonie/telephonie.contrat.class.php
@@ -431,10 +431,10 @@ class TelephonieContrat {
     $res   = array();
     $resid = array();
 
-    $sql = "SELECT c.idp, c.name, c.firstname, c.email ";
+    $sql = "SELECT c.rowid, c.name, c.firstname, c.email ";
     $sql .= "FROM ".MAIN_DB_PREFIX."socpeople as c";
     $sql .= ",".MAIN_DB_PREFIX."telephonie_contrat_contact_facture as cf";
-    $sql .= " WHERE c.idp = cf.fk_contact ";
+    $sql .= " WHERE c.rowid = cf.fk_contact ";
     $sql .= " AND cf.fk_contrat = ".$this->id." ORDER BY name ";
 
     $resql = $this->db->query($sql);
diff --git a/htdocs/user.class.php b/htdocs/user.class.php
index e123c413e6d..6148f7dff42 100644
--- a/htdocs/user.class.php
+++ b/htdocs/user.class.php
@@ -614,7 +614,7 @@ class User
     // Si contact, supprime lien
     if ($this->contact_id)
     {
-    	$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET fk_user_creat = null WHERE idp = $this->contact_id";
+    	$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET fk_user_creat = null WHERE rowid = ".$this->contact_id;
 	    if ($this->db->query($sql))
 	    {
 	    
@@ -1453,7 +1453,7 @@ class User
 
 		// Charge tableau des id de soci�t� socids
 		$socids = array();
-		$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10";
+		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10";
 		$resql = $this->db->query($sql);
 		if ($resql)
 		{
diff --git a/htdocs/user/home.php b/htdocs/user/home.php
index 8e1fdab3c9b..eab2e951999 100644
--- a/htdocs/user/home.php
+++ b/htdocs/user/home.php
@@ -83,7 +83,7 @@ $max=10;
 $sql = "SELECT u.rowid, u.name, u.firstname, u.admin, u.login, u.fk_societe, ".$db->pdate("u.datec")." as datec,";
 $sql.= " u.ldap_sid, s.nom";
 $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_societe=s.idp";
+$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_societe = s.rowid";
 $sql.= " ORDER BY u.datec";
 $sql.= " DESC limit $max";
 
diff --git a/htdocs/user/index.php b/htdocs/user/index.php
index e9a30283e50..309a4b39705 100644
--- a/htdocs/user/index.php
+++ b/htdocs/user/index.php
@@ -60,7 +60,7 @@ $sql = "SELECT u.rowid, u.name, u.firstname, u.admin, u.fk_societe, u.login, ".$
 $sql.= " u.ldap_sid, u.statut,";
 $sql.= " s.nom";
 $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_societe = s.idp";
+$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_societe = s.rowid";
 $sql.= " WHERE 1=1";
 if ($_POST["search_user"])
 {
diff --git a/mysql/data/data_dev.sql b/mysql/data/data_dev.sql
index d6d6cebd011..81ec29e3606 100644
--- a/mysql/data/data_dev.sql
+++ b/mysql/data/data_dev.sql
@@ -68,49 +68,49 @@ insert into llx_tva (datep, datev, amount) values ('2001-04-11','2001-01-01', 20
 --
 
 
-insert into llx_societe (idp,nom,address,datec,cp,ville,tel,fax, client, prefix_comm)
+insert into llx_societe (rowid,nom,address,datec,cp,ville,tel,fax, client, prefix_comm)
 values (1,'Cumulo','3 place de la R�publique',now(),'56610','Arradon','01 40 15 03 18','01 40 15 06 18',1,'CU');
 
-insert into llx_societe (idp,nom,address,datec,cp,ville,tel,fax, client, prefix_comm, fournisseur, url, fk_forme_juridique)
+insert into llx_societe (rowid,nom,address,datec,cp,ville,tel,fax, client, prefix_comm, fournisseur, url, fk_forme_juridique)
 values (2,'Bolix SA','13 rue Pierre Mend�s France',now(),'56350','Allaire','01 40 15 03 18','01 40 15 06 18',1,'LO',1,'www.dolibarr.com',54);
 
-insert into llx_societe (idp,nom,address,cp,ville,tel,fax,client, prefix_comm)
+insert into llx_societe (rowid,nom,address,cp,ville,tel,fax,client, prefix_comm)
 values (10,'Doli INC.','Rue du Port','29300','Arzano','01 55 55 03 18','01 55 55 55 55',1,'DO');
 
-insert into llx_societe (idp,nom,address,cp,ville,tel,fax,client, prefix_comm,url, fournisseur)
+insert into llx_societe (rowid,nom,address,cp,ville,tel,fax,client, prefix_comm,url, fournisseur)
 values (3,'Foo SARL','3bis Avenue de la Libert�','22300','Ploubezre','01 55 55 03 18','01 55 55 55 55',1,'FOO','www.gnu.org', 1);
 
-insert into llx_societe (idp,nom,address,datec,cp,ville,tel,fax, client, prefix_comm)
+insert into llx_societe (rowid,nom,address,datec,cp,ville,tel,fax, client, prefix_comm)
 values (4,'Talphinfo','Place Dolores Ibarruri',now(),'29400','Bodilis','01 40 15 03 18','01 40 15 06 18',1,'AP');
 
-insert into llx_societe (idp,nom,cp,ville,tel,fax,fournisseur,prefix_comm)
+insert into llx_societe (rowid,nom,cp,ville,tel,fax,fournisseur,prefix_comm)
 values (20,'Bouleau','22800','Le Foeil','01 55 55 03 18','01 55 55 55 55',1,'BTP');
 
 insert into llx_societe (nom,datec,cp,ville,tel,fax, client, prefix_comm)
 values ('Valphanix',now(),'29820','Bohars','01 40 15 03 18','01 40 15 06 18',2,'AL');
 
-insert into llx_societe (idp,nom,cp,ville,tel,fax,fournisseur,prefix_comm)
+insert into llx_societe (rowid,nom,cp,ville,tel,fax,fournisseur,prefix_comm)
 values (101,'Cerisier','22290','Goudelin','01 55 55 03 18','01 55 55 55 55',1,'CER');
 
 insert into llx_societe (nom,cp,ville,tel,fax,client,url)
 values ('Turin','29890','Brignogan-Plage','01 55 55 03 18','01 55 55 55 55',1,'http://www.ot-brignogan-plage.fr/');
 
-insert into llx_societe (idp,nom,cp,ville,tel,fax,fournisseur,prefix_comm)
+insert into llx_societe (rowid,nom,cp,ville,tel,fax,fournisseur,prefix_comm)
 values (100,'Ch�ne','22330','Le Gouray','01 55 55 03 18','01 55 55 55 55',1,'DEL');
 
-insert into llx_societe (idp,nom,cp,ville,tel,fax,client)
+insert into llx_societe (rowid,nom,cp,ville,tel,fax,client)
 values (5,'Yratin SA','29660','Carantec','01 55 55 03 18','01 55 55 55 55',1);
 
-insert into llx_societe (idp,nom,cp,ville,tel,fax,client)
+insert into llx_societe (rowid,nom,cp,ville,tel,fax,client)
 values (6,'Raggos SARL','29233','Cl�der','01 55 55 03 18','01 55 55 55 55',1);
 
-insert into llx_societe (idp,nom,cp,ville,tel,fax,client)
+insert into llx_societe (rowid,nom,cp,ville,tel,fax,client)
 values (7,'Pruitosa','29870','Coat-M�al','01 55 55 03 18','01 55 55 55 55',2);
 
-insert into llx_societe (idp,nom,cp,ville,tel,fax,client)
+insert into llx_societe (rowid,nom,cp,ville,tel,fax,client)
 values (8,'Stratus','29120','Combrit','01 55 55 03 18','01 55 55 55 55',2);
 
-insert into llx_societe (idp,nom,cp,ville,tel,fax,client,address)
+insert into llx_societe (rowid,nom,cp,ville,tel,fax,client,address)
 values (9,'Nimbus','29490','Guipavas','01 55 55 03 18','01 55 55 55 55',2,'15 rue des petites �curies');
 
 insert into llx_societe (nom,cp,ville,tel,fax,client)
@@ -334,39 +334,39 @@ INSERT INTO `llx_boxes` VALUES (25, 21, 0, 2);
 -- Contact
 --
 
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email,poste)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email,poste)
 values (10,1,'Mar�chal','Ferdinand','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net','Administrateur syst�me');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (11,5,'Pejat','Jean-Marie','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
 
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email,poste)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email,poste)
 values (12,1,'Poulossi�re','Paul','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net','Directeur technique');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (13,6,'Myriam','Isabelle','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
 
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (20,2,'Corin','Arnaud','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (30,3,'Philippine','Sagan','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (31,3,'Marie','Jeanne','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (41,4,'Alix','Hopper','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (14,7,'Victoire','Renoir','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (15,7,'Baudelaire','Matthias','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (16,8,'Hugo','Benjamin','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (17,9,'Rembrandt','St�phanie','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (18,10,'Picasso','Myriam','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (19,1,'Beethoven','John','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (22,6,'Dumas','Elisabeth','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (21,10,'','Jos�phine','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
 --
 --
diff --git a/mysql/migration/2.1.0-2.2.0.sql b/mysql/migration/2.1.0-2.2.0.sql
index 12537808816..f7a21cb97c6 100644
--- a/mysql/migration/2.1.0-2.2.0.sql
+++ b/mysql/migration/2.1.0-2.2.0.sql
@@ -47,8 +47,9 @@ create table `llx_categorie_societe` (
 ) type=innodb;
 
 -- 
+alter table `llx_categorie_societe` drop foreign key fk_societe;
 alter table `llx_categorie_societe`
-  add constraint `llx_categorie_societe_ibfk_1` foreign key(`fk_societe`) REFERENCES `llx_societe` (`idp`) ON DELETE CASCADE ON UPDATE CASCADE,
+  add constraint `llx_categorie_societe_ibfk_1` foreign key(`fk_societe`) REFERENCES `llx_societe` (`rowid`) ON DELETE CASCADE ON UPDATE CASCADE,
   add constraint `llx_categorie_societe_ibfk_2` foreign key(`fk_categorie`) REFERENCES `llx_categorie` (`rowid`) ON DELETE CASCADE ON UPDATE CASCADE;
 
 drop table if exists `llx_categorie_product`;
@@ -560,11 +561,70 @@ drop table if exists llx_ventes;
 drop table if exists llx_pointmort;
 drop table if exists llx_birthday_alert;
 
--- Pas de limite sur nb decimal dans base car definie en option 
+-- Pas de limite sur nb decimal dans base car definie en option
 ALTER TABLE llx_product_price ADD COLUMN price_ttc float DEFAULT 0 AFTER price;
 ALTER TABLE llx_product ADD COLUMN price_ttc float DEFAULT 0 AFTER price_base_type;
 ALTER TABLE llx_product_price MODIFY price_ttc float DEFAULT 0;
 ALTER TABLE llx_product ADD COLUMN price_ttc float DEFAULT 0;
 
- 
-
+-- Changement de idp en rowid
+-- V4 ALTER TABLE llx_socpeople DROP FOREIGN KEY fk_socpeople_fk_soc;
+-- V4 ALTER TABLE llx_commande DROP FOREIGN KEY fk_commande_societe;
+-- V4 ALTER TABLE llx_commande_fournisseur DROP FOREIGN KEY fk_commande_fournisseur_societe;
+-- V4 ALTER TABLE llx_contrat DROP FOREIGN KEY fk_contrat_societe;
+-- V4 ALTER TABLE llx_facture DROP FOREIGN KEY fk_facture_fk_soc;
+-- V4 ALTER TABLE llx_facture_fourn DROP FOREIGN KEY fk_facture_fourn_fk_soc;
+-- V4 ALTER TABLE llx_fichinter DROP FOREIGN KEY fk_fichinter_fk_soc;
+-- V4 ALTER TABLE llx_osc_customer DROP FOREIGN KEY llx_osc_customer_fk_soc;
+-- V4 ALTER TABLE llx_propal DROP FOREIGN KEY fk_propal_fk_soc;
+-- V4 ALTER TABLE llx_societe_remise_except DROP FOREIGN KEY fk_societe_remise_fk_soc;
+-- V4 ALTER TABLE llx_product_fournisseur_price DROP FOREIGN KEY fk_product_fournisseur_price_fk_soc;
+-- V4 ALTER TABLE llx_categorie_societe DROP FOREIGN KEY fk_categorie_societe_societe_rowid;
+
+ALTER TABLE `llx_societe` CHANGE `idp` `rowid` integer AUTO_INCREMENT;
+ALTER TABLE `llx_socpeople` CHANGE `idp` `rowid` integer AUTO_INCREMENT;
+
+-- V4 ALTER TABLE llx_socpeople ADD CONSTRAINT fk_socpeople_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
+-- V4 ALTER TABLE llx_commande ADD CONSTRAINT fk_commande_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
+-- V4 ALTER TABLE llx_commande_fournisseur ADD CONSTRAINT fk_commande_fournisseur_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
+-- V4 ALTER TABLE llx_contrat ADD CONSTRAINT fk_contrat_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
+-- V4 ALTER TABLE llx_facture ADD CONSTRAINT fk_facture_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
+-- V4 ALTER TABLE llx_facture_fourn ADD CONSTRAINT fk_facture_fourn_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
+-- V4 ALTER TABLE llx_fichinter ADD CONSTRAINT fk_fichinter_fk_soc	FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
+-- V4 ALTER TABLE llx_product_fournisseur_price ADD CONSTRAINT fk_product_fournisseur_price_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
+-- V4 ALTER TABLE llx_propal ADD CONSTRAINT fk_propal_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
+-- V4 ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
+-- V4 ALTER TABLE llx_categorie_societe ADD CONSTRAINT fk_categorie_societe_fk_soc   FOREIGN KEY (fk_societe) REFERENCES llx_societe (rowid);
+
+ALTER TABLE `llx_osc_customer` CHANGE `osc_custid` `rowid` integer NOT NULL default 0;
+ALTER TABLE `llx_osc_customer` CHANGE `osc_lastmodif` `datem` datetime default NULL;
+ALTER TABLE `llx_osc_customer` CHANGE `doli_socidp` `fk_soc` integer NOT NULL default '0';
+ALTER TABLE `llx_osc_customer` ADD PRIMARY KEY (rowid);
+ALTER TABLE `llx_osc_customer` ADD UNIQUE KEY `fk_soc` (`fk_soc`);
+-- V4 ALTER TABLE llx_osc_customer ADD CONSTRAINT fk_osc_customer_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
+ALTER TABLE `llx_osc_order` CHANGE `osc_orderid` `rowid` integer NOT NULL default 0;
+ALTER TABLE `llx_osc_order` CHANGE `osc_lastmodif` `datem` datetime default NULL;
+ALTER TABLE `llx_osc_order` CHANGE `doli_orderidp` `fk_commande` integer NOT NULL default 0;
+ALTER TABLE `llx_osc_order` ADD PRIMARY KEY (rowid);
+ALTER TABLE `llx_osc_order` ADD UNIQUE KEY `fk_commande` (`fk_commande`);
+ALTER TABLE `llx_osc_product` CHANGE `osc_prodid` `rowid` integer NOT NULL default 0;
+ALTER TABLE `llx_osc_product` CHANGE `osc_lastmodif` `datem` datetime default NULL;
+ALTER TABLE `llx_osc_product` CHANGE `doli_prodidp` `fk_product` integer NOT NULL default 0;
+ALTER TABLE `llx_osc_product` ADD PRIMARY KEY (rowid);
+ALTER TABLE `llx_osc_product` ADD UNIQUE KEY `fk_product` (`fk_product`);
+
+-- V4 ALTER TABLE llx_telephonie_adsl_fournisseur DROP FOREIGN KEY fk_soc;
+-- V4 ALTER TABLE llx_telephonie_adsl_fournisseur ADD FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
+-- V4 ALTER TABLE llx_telephonie_client_stats DROP FOREIGN KEY fk_client_comm;
+-- V4 ALTER TABLE llx_telephonie_client_stats ADD FOREIGN KEY (fk_client_comm) REFERENCES llx_societe(rowid);
+-- V4 ALTER TABLE llx_telephonie_contact_facture DROP FOREIGN KEY fk_contact;
+-- V4 ALTER TABLE llx_telephonie_contact_facture ADD FOREIGN KEY (fk_contact) REFERENCES llx_socpeople (rowid);
+-- V4 ALTER TABLE llx_telephonie_societe_ligne DROP FOREIGN KEY fk_client_comm;
+-- V4 ALTER TABLE llx_telephonie_societe_ligne ADD FOREIGN KEY (fk_client_comm) REFERENCES llx_societe(rowid);
+-- V4 ALTER TABLE llx_telephonie_societe_ligne DROP FOREIGN KEY fk_soc;
+-- V4 ALTER TABLE llx_telephonie_societe_ligne ADD FOREIGN KEY (fk_soc) REFERENCES llx_societe(rowid);
+-- V4 ALTER TABLE llx_telephonie_societe_ligne DROP FOREIGN KEY fk_soc_facture;
+-- V4 ALTER TABLE llx_telephonie_societe_ligne ADD FOREIGN KEY (fk_soc_facture) REFERENCES llx_societe(rowid);
+-- V4 ALTER TABLE llx_telephonie_tarif_client DROP FOREIGN KEY fk_client;
+-- V4 ALTER TABLE llx_telephonie_tarif_client ADD FOREIGN KEY (fk_client) REFERENCES llx_societe (rowid);
+-- fin du changement idp en rowid
\ No newline at end of file
diff --git a/mysql/tables/llx_categorie_societe.key.sql b/mysql/tables/llx_categorie_societe.key.sql
index 824e4ac2dd3..36f9c3e290d 100644
--- a/mysql/tables/llx_categorie_societe.key.sql
+++ b/mysql/tables/llx_categorie_societe.key.sql
@@ -22,4 +22,4 @@ ALTER TABLE llx_categorie_societe ADD INDEX idx_categorie_societe_fk_categorie (
 ALTER TABLE llx_categorie_societe ADD INDEX idx_categorie_societe_fk_societe (fk_societe);
 
 ALTER TABLE llx_categorie_societe ADD CONSTRAINT fk_categorie_societe_categorie_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid);
-ALTER TABLE llx_categorie_societe ADD CONSTRAINT fk_categorie_societe_societe_rowid   FOREIGN KEY (fk_societe) REFERENCES llx_societe (rowid);
+ALTER TABLE llx_categorie_societe ADD CONSTRAINT fk_categorie_societe_fk_soc   FOREIGN KEY (fk_societe) REFERENCES llx_societe (rowid);
diff --git a/mysql/tables/llx_commande.key.sql b/mysql/tables/llx_commande.key.sql
index 088ca768907..03e6d1e0142 100644
--- a/mysql/tables/llx_commande.key.sql
+++ b/mysql/tables/llx_commande.key.sql
@@ -22,7 +22,7 @@
 
 
 -- Supprimme orphelins pour permettre mont�e de la cl�
--- V4 DELETE llx_commande FROM llx_commande LEFT JOIN llx_societe ON llx_commande.fk_soc = llx_societe.idp WHERE llx_societe.idp IS NULL; 
+-- V4 DELETE llx_commande FROM llx_commande LEFT JOIN llx_societe ON llx_commande.fk_soc = llx_societe.rowid WHERE llx_societe.rowid IS NULL; 
 
 ALTER TABLE llx_commande ADD INDEX idx_commande_fk_soc (fk_soc);
-ALTER TABLE llx_commande ADD CONSTRAINT fk_commande_societe FOREIGN KEY (fk_soc) REFERENCES llx_societe (idp);
+ALTER TABLE llx_commande ADD CONSTRAINT fk_commande_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
diff --git a/mysql/tables/llx_commande_fournisseur.key.sql b/mysql/tables/llx_commande_fournisseur.key.sql
index ca614c9bfb0..399304b857d 100644
--- a/mysql/tables/llx_commande_fournisseur.key.sql
+++ b/mysql/tables/llx_commande_fournisseur.key.sql
@@ -22,7 +22,7 @@
 
 
 -- Supprimme orphelins pour permettre mont�e de la cl�
--- V4 DELETE llx_commande_fournisseur FROM llx_commande_fournisseur LEFT JOIN llx_societe ON llx_commande_fournisseur.fk_soc = llx_societe.idp WHERE llx_societe.idp IS NULL; 
+-- V4 DELETE llx_commande_fournisseur FROM llx_commande_fournisseur LEFT JOIN llx_societe ON llx_commande_fournisseur.fk_soc = llx_societe.rowid WHERE llx_societe.rowid IS NULL; 
 
 ALTER TABLE llx_commande_fournisseur ADD INDEX idx_commande_fournisseur_fk_soc (fk_soc);
-ALTER TABLE llx_commande_fournisseur ADD CONSTRAINT fk_commande_fournisseur_societe FOREIGN KEY (fk_soc) REFERENCES llx_societe (idp);
+ALTER TABLE llx_commande_fournisseur ADD CONSTRAINT fk_commande_fournisseur_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
diff --git a/mysql/tables/llx_contrat.key.sql b/mysql/tables/llx_contrat.key.sql
index 697d930d917..676588c5a14 100644
--- a/mysql/tables/llx_contrat.key.sql
+++ b/mysql/tables/llx_contrat.key.sql
@@ -23,12 +23,12 @@
 
 
 -- Supprimme orhpelins pour permettre mont�e de la cl�
--- V4 DELETE llx_contratdet FROM llx_contratdet, llx_contrat LEFT JOIN llx_societe ON llx_contrat.fk_soc = llx_societe.idp WHERE llx_contratdet.fk_contrat = llx_contrat.rowid AND llx_societe.idp IS NULL; 
--- V4 DELETE llx_contrat FROM llx_contrat LEFT JOIN llx_societe ON llx_contrat.fk_soc = llx_societe.idp WHERE llx_societe.idp IS NULL;
+-- V4 DELETE llx_contratdet FROM llx_contratdet, llx_contrat LEFT JOIN llx_societe ON llx_contrat.fk_soc = llx_societe.rowid WHERE llx_contratdet.fk_contrat = llx_contrat.rowid AND llx_societe.rowid IS NULL; 
+-- V4 DELETE llx_contrat FROM llx_contrat LEFT JOIN llx_societe ON llx_contrat.fk_soc = llx_societe.rowid WHERE llx_societe.rowid IS NULL;
 -- V4 DELETE llx_contrat FROM llx_contrat LEFT JOIN llx_user ON llx_contrat.fk_user_author = llx_user.rowid WHERE llx_user.rowid IS NULL;
 
 ALTER TABLE llx_contrat ADD INDEX idx_contrat_fk_soc (fk_soc);
 ALTER TABLE llx_contrat ADD INDEX idx_contrat_fk_user_author (fk_user_author);
 
-ALTER TABLE llx_contrat ADD CONSTRAINT fk_contrat_societe FOREIGN KEY (fk_soc) REFERENCES llx_societe (idp);
+ALTER TABLE llx_contrat ADD CONSTRAINT fk_contrat_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
 ALTER TABLE llx_contrat ADD CONSTRAINT fk_contrat_user_author FOREIGN KEY (fk_user_author) REFERENCES llx_user (rowid);
\ No newline at end of file
diff --git a/mysql/tables/llx_facture.key.sql b/mysql/tables/llx_facture.key.sql
index 2337c01618a..64dd91e3ae3 100644
--- a/mysql/tables/llx_facture.key.sql
+++ b/mysql/tables/llx_facture.key.sql
@@ -28,7 +28,7 @@ ALTER TABLE llx_facture ADD INDEX idx_facture_fk_user_valid (fk_user_valid);
 ALTER TABLE llx_facture ADD INDEX idx_facture_fk_facture_source (fk_facture_source);
 ALTER TABLE llx_facture ADD INDEX idx_facture_fk_projet (fk_projet);
 
-ALTER TABLE llx_facture ADD CONSTRAINT fk_facture_fk_soc            FOREIGN KEY (fk_soc) REFERENCES llx_societe (idp);
+ALTER TABLE llx_facture ADD CONSTRAINT fk_facture_fk_soc            FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
 ALTER TABLE llx_facture ADD CONSTRAINT fk_facture_fk_user_author    FOREIGN KEY (fk_user_author) REFERENCES llx_user (rowid);
 ALTER TABLE llx_facture ADD CONSTRAINT fk_facture_fk_user_valid     FOREIGN KEY (fk_user_valid)  REFERENCES llx_user (rowid);
 ALTER TABLE llx_facture ADD CONSTRAINT fk_facture_fk_facture_source FOREIGN KEY (fk_facture_source) REFERENCES llx_facture (rowid);
diff --git a/mysql/tables/llx_facture_fourn.key.sql b/mysql/tables/llx_facture_fourn.key.sql
index 08367d90977..ac338a57464 100644
--- a/mysql/tables/llx_facture_fourn.key.sql
+++ b/mysql/tables/llx_facture_fourn.key.sql
@@ -30,7 +30,7 @@ ALTER TABLE llx_facture_fourn ADD INDEX idx_facture_fourn_fk_user_author (fk_use
 ALTER TABLE llx_facture_fourn ADD INDEX idx_facture_fourn_fk_user_valid (fk_user_valid);
 ALTER TABLE llx_facture_fourn ADD INDEX idx_facture_fourn_fk_projet (fk_projet);
 
-ALTER TABLE llx_facture_fourn ADD CONSTRAINT fk_facture_fourn_fk_soc            FOREIGN KEY (fk_soc) REFERENCES llx_societe (idp);
+ALTER TABLE llx_facture_fourn ADD CONSTRAINT fk_facture_fourn_fk_soc            FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
 ALTER TABLE llx_facture_fourn ADD CONSTRAINT fk_facture_fourn_fk_user_author    FOREIGN KEY (fk_user_author) REFERENCES llx_user (rowid);
 ALTER TABLE llx_facture_fourn ADD CONSTRAINT fk_facture_fourn_fk_user_valid     FOREIGN KEY (fk_user_valid) REFERENCES llx_user (rowid);
 ALTER TABLE llx_facture_fourn ADD CONSTRAINT fk_facture_fourn_fk_projet         FOREIGN KEY (fk_projet) REFERENCES llx_projet (rowid);
diff --git a/mysql/tables/llx_fichinter.key.sql b/mysql/tables/llx_fichinter.key.sql
index e160d8dd91e..26ba1623dfa 100644
--- a/mysql/tables/llx_fichinter.key.sql
+++ b/mysql/tables/llx_fichinter.key.sql
@@ -22,4 +22,4 @@
 
 
 ALTER TABLE llx_fichinter ADD INDEX idx_fichinter_fk_soc (fk_soc);
-ALTER TABLE llx_fichinter ADD CONSTRAINT fk_fichinter_fk_soc	FOREIGN KEY (fk_soc)     REFERENCES llx_societe (idp);
+ALTER TABLE llx_fichinter ADD CONSTRAINT fk_fichinter_fk_soc	FOREIGN KEY (fk_soc)     REFERENCES llx_societe (rowid);
diff --git a/mysql/tables/llx_osc_customer.key.sql b/mysql/tables/llx_osc_customer.key.sql
index c1539ba1a91..5f6f4308e2c 100644
--- a/mysql/tables/llx_osc_customer.key.sql
+++ b/mysql/tables/llx_osc_customer.key.sql
@@ -1,13 +1,24 @@
--- phpMyAdmin SQL Dump
--- version 2.6.2-Debian-3sarge1
--- http://www.phpmyadmin.net
--- 
--- Serveur: localhost
--- G�n�r� le : Samedi 05 Ao�t 2006 � 17:25
--- Version du serveur: 4.0.24
--- Version de PHP: 4.3.10-16
--- 
-
-
-ALTER TABLE `llx_osc_customer`
-  ADD CONSTRAINT `llx_osc_customer_societe_idp` FOREIGN KEY (`doli_socidp`) REFERENCES `llx_societe` (`idp`);
+-- ===================================================================
+-- Copyright (C) 2005 Laurent Destailleur  <eldy@users.sourceforge.net>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 2 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program; if not, write to the Free Software
+-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+--
+-- $Id$
+-- $Source$
+--
+-- ===================================================================
+
+
+ALTER TABLE llx_osc_customer ADD CONSTRAINT fk_osc_customer_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
diff --git a/mysql/tables/llx_osc_customer.sql b/mysql/tables/llx_osc_customer.sql
index c438f7e907f..491b7d0f8b6 100644
--- a/mysql/tables/llx_osc_customer.sql
+++ b/mysql/tables/llx_osc_customer.sql
@@ -1,17 +1,29 @@
--- phpMyAdmin SQL Dump
--- version 2.6.2-Debian-3sarge1
--- http://www.phpmyadmin.net
--- 
--- Serveur: localhost
--- G�n�r� le : Samedi 05 Ao�t 2006 � 17:25
--- Version du serveur: 4.0.24
--- Version de PHP: 4.3.10-16
--- 
-
-CREATE TABLE IF NOT EXISTS `llx_osc_customer` (
-  `osc_custid` int(11) NOT NULL default '0',
-  `osc_lastmodif` datetime default NULL,
-  `doli_socidp` int(11) NOT NULL default '0',
-  PRIMARY KEY  (`osc_custid`),
-  UNIQUE KEY `doli_socidp` (`doli_socidp`)
-) TYPE=InnoDB COMMENT='Table transition client OSC - societe Dolibarr';
+-- ===================================================================
+-- Copyright (C) 2005 Laurent Destailleur  <eldy@users.sourceforge.net>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 2 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program; if not, write to the Free Software
+-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+--
+-- $Id$
+-- $Source$
+--
+-- ===================================================================
+
+CREATE TABLE IF NOT EXISTS `llx_osc_customer` (
+  `rowid` int(11) NOT NULL default '0',
+  `datem` datetime default NULL,
+  `fk_soc` int(11) NOT NULL default '0',
+  PRIMARY KEY  (`rowid`),
+  UNIQUE KEY `fk_soc` (`fk_soc`)
+) TYPE=InnoDB COMMENT='Table transition client OSC - societe Dolibarr';
diff --git a/mysql/tables/llx_osc_order.sql b/mysql/tables/llx_osc_order.sql
index b892e280747..14c6a872bc2 100644
--- a/mysql/tables/llx_osc_order.sql
+++ b/mysql/tables/llx_osc_order.sql
@@ -1,25 +1,29 @@
--- phpMyAdmin SQL Dump
--- version 2.6.2-Debian-3sarge1
--- http://www.phpmyadmin.net
--- 
--- Serveur: localhost
--- G�n�r� le : Samedi 05 Ao�t 2006 � 17:25
--- Version du serveur: 4.0.24
--- Version de PHP: 4.3.10-16
--- 
--- Base de donn�es: `dolidev`
--- 
-
--- --------------------------------------------------------
-
--- 
--- Structure de la table `llx_osc_order`
--- 
+-- ===================================================================
+-- Copyright (C) 2005 Laurent Destailleur  <eldy@users.sourceforge.net>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 2 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program; if not, write to the Free Software
+-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+--
+-- $Id$
+-- $Source$
+--
+-- ===================================================================
 
 CREATE TABLE IF NOT EXISTS `llx_osc_order` (
-  `osc_orderid` int(11) NOT NULL default '0',
-  `osc_lastmodif` datetime default NULL,
-  `doli_orderidp` int(11) NOT NULL default '0',
-  PRIMARY KEY  (`osc_orderid`),
-  UNIQUE KEY `doli_orderidp` (`doli_orderidp`)
+  `rowid` int(11) NOT NULL default '0',
+  `datem` datetime default NULL,
+  `fk_commande` int(11) NOT NULL default '0',
+  PRIMARY KEY  (`rowid`),
+  UNIQUE KEY `fk_commande` (`fk_commande`)
 ) TYPE=InnoDB COMMENT='Table transition commande OSC - commande Dolibarr';
diff --git a/mysql/tables/llx_osc_product.sql b/mysql/tables/llx_osc_product.sql
index 7b2fbbb9990..ff10752e515 100644
--- a/mysql/tables/llx_osc_product.sql
+++ b/mysql/tables/llx_osc_product.sql
@@ -1,27 +1,31 @@
--- phpMyAdmin SQL Dump
--- version 2.6.2-Debian-3sarge1
--- http://www.phpmyadmin.net
--- 
--- Serveur: localhost
--- G�n�r� le : Samedi 05 Ao�t 2006 � 17:25
--- Version du serveur: 4.0.24
--- Version de PHP: 4.3.10-16
--- 
--- Base de donn�es: `dolidev`
--- 
-
--- --------------------------------------------------------
-
--- 
--- Structure de la table `llx_osc_product`
--- 
+-- ===================================================================
+-- Copyright (C) 2005 Laurent Destailleur  <eldy@users.sourceforge.net>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 2 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program; if not, write to the Free Software
+-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+--
+-- $Id$
+-- $Source$
+--
+-- ===================================================================
 
 CREATE TABLE IF NOT EXISTS `llx_osc_product` (
-  `osc_prodid` int(11) NOT NULL default '0',
-  `osc_lastmodif` datetime default NULL,
-  `doli_prodidp` int(11) NOT NULL default '0',
-  PRIMARY KEY  (`osc_prodid`),
-  UNIQUE KEY `doli_prodidp` (`doli_prodidp`)
+  `rowid` int(11) NOT NULL default '0',
+  `datem` datetime default NULL,
+  `fk_product` int(11) NOT NULL default '0',
+  PRIMARY KEY  (`rowid`),
+  UNIQUE KEY `fk_product` (`fk_product`)
 ) TYPE=InnoDB COMMENT='Table transition produit OSC - produit Dolibarr';
 
 
diff --git a/mysql/tables/llx_product_fournisseur_price.key.sql b/mysql/tables/llx_product_fournisseur_price.key.sql
index b73df53e63c..64ffd17a721 100644
--- a/mysql/tables/llx_product_fournisseur_price.key.sql
+++ b/mysql/tables/llx_product_fournisseur_price.key.sql
@@ -27,7 +27,7 @@ ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_fournisseur_pric
 ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_fournisseur_price_fk_product (fk_product);
 
 ALTER TABLE llx_product_fournisseur_price ADD CONSTRAINT fk_product_fournisseur_price_fk_user    FOREIGN KEY (fk_user)    REFERENCES llx_user (rowid);
-ALTER TABLE llx_product_fournisseur_price ADD CONSTRAINT fk_product_fournisseur_price_fk_soc     FOREIGN KEY (fk_soc)     REFERENCES llx_societe (idp);
+ALTER TABLE llx_product_fournisseur_price ADD CONSTRAINT fk_product_fournisseur_price_fk_soc     FOREIGN KEY (fk_soc)     REFERENCES llx_societe (rowid);
 ALTER TABLE llx_product_fournisseur_price ADD CONSTRAINT fk_product_fournisseur_price_fk_product FOREIGN KEY (fk_product) REFERENCES llx_product (rowid);
 
 
diff --git a/mysql/tables/llx_propal.key.sql b/mysql/tables/llx_propal.key.sql
index 9391b8c70d2..323c72b3d33 100644
--- a/mysql/tables/llx_propal.key.sql
+++ b/mysql/tables/llx_propal.key.sql
@@ -25,5 +25,4 @@
 ALTER TABLE llx_propal ADD INDEX idx_propal_fk_soc (fk_soc);
 
 
-ALTER TABLE llx_propal ADD CONSTRAINT fk_propal_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (idp);
-
+ALTER TABLE llx_propal ADD CONSTRAINT fk_propal_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
\ No newline at end of file
diff --git a/mysql/tables/llx_societe.sql b/mysql/tables/llx_societe.sql
index 27fe41e9810..139112dc5c9 100644
--- a/mysql/tables/llx_societe.sql
+++ b/mysql/tables/llx_societe.sql
@@ -22,7 +22,7 @@
 
 create table llx_societe
 (
-  idp                integer AUTO_INCREMENT PRIMARY KEY,
+  rowid              integer AUTO_INCREMENT PRIMARY KEY,
   statut             tinyint        DEFAULT 0,            -- statut
   parent             integer,
   tms                timestamp,
diff --git a/mysql/tables/llx_societe_remise_except.key.sql b/mysql/tables/llx_societe_remise_except.key.sql
index af5a311d8fe..c6b6107bebd 100644
--- a/mysql/tables/llx_societe_remise_except.key.sql
+++ b/mysql/tables/llx_societe_remise_except.key.sql
@@ -31,7 +31,7 @@ ALTER TABLE llx_societe_remise_except ADD INDEX idx_societe_remise_except_fk_fac
 
 
 ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_user    FOREIGN KEY (fk_user)    REFERENCES llx_user (rowid);
-ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_soc     FOREIGN KEY (fk_soc)     REFERENCES llx_societe (idp);
+ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_soc     FOREIGN KEY (fk_soc)     REFERENCES llx_societe (rowid);
 ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_facture FOREIGN KEY (fk_facture) REFERENCES llx_facturedet (rowid);
 ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_facture_source FOREIGN KEY (fk_facture_source) REFERENCES llx_facture (rowid);
 
diff --git a/mysql/tables/llx_socpeople.key.sql b/mysql/tables/llx_socpeople.key.sql
index bdfc53e9cf2..083f35528b5 100644
--- a/mysql/tables/llx_socpeople.key.sql
+++ b/mysql/tables/llx_socpeople.key.sql
@@ -24,5 +24,5 @@
 ALTER TABLE llx_socpeople ADD INDEX idx_socpeople_fk_soc (fk_soc);
 ALTER TABLE llx_socpeople ADD INDEX idx_socpeople_fk_user_creat (fk_user_creat);
 
-ALTER TABLE llx_socpeople ADD CONSTRAINT fk_socpeople_fk_soc    FOREIGN KEY (fk_soc)     REFERENCES llx_societe (idp);
+ALTER TABLE llx_socpeople ADD CONSTRAINT fk_socpeople_fk_soc    FOREIGN KEY (fk_soc)     REFERENCES llx_societe (rowid);
 ALTER TABLE llx_socpeople ADD CONSTRAINT fk_socpeople_user_creat_user_rowid FOREIGN KEY (fk_user_creat) REFERENCES llx_user (rowid);
diff --git a/mysql/tables/llx_socpeople.sql b/mysql/tables/llx_socpeople.sql
index 41db956f22f..2c271a9801c 100644
--- a/mysql/tables/llx_socpeople.sql
+++ b/mysql/tables/llx_socpeople.sql
@@ -22,7 +22,7 @@
 
 create table llx_socpeople
 (
-  idp            integer AUTO_INCREMENT PRIMARY KEY,
+  rowid          integer AUTO_INCREMENT PRIMARY KEY,
   datec          datetime,
   tms            timestamp,
   fk_soc         integer,           -- lien vers la societe
diff --git a/pgsql/data/data_dev.sql b/pgsql/data/data_dev.sql
index e9bb4f5a70d..a31c790b7ca 100644
--- a/pgsql/data/data_dev.sql
+++ b/pgsql/data/data_dev.sql
@@ -129,19 +129,19 @@ values ('Foo SARL','22300','Ploubezre','01 55 55 03 18','01 55 55 55 55',1,'FOO'
 insert into llx_societe (nom,datec,cp,ville,tel,fax, client, prefix_comm)
 values ('Talphinfo',now(),'29400','Bodilis','01 40 15 03 18','01 40 15 06 18',1,'AP');
 
-insert into llx_societe (idp,nom,cp,ville,tel,fax,fournisseur,prefix_comm)
+insert into llx_societe (rowid,nom,cp,ville,tel,fax,fournisseur,prefix_comm)
 values (20,'Bouleau','22800','Le Foeil','01 55 55 03 18','01 55 55 55 55',1,'BTP');
 
 insert into llx_societe (nom,datec,cp,ville,tel,fax, client, prefix_comm)
 values ('Valphanix',now(),'29820','Bohars','01 40 15 03 18','01 40 15 06 18',1,'AL');
 
-insert into llx_societe (idp,nom,cp,ville,tel,fax,fournisseur,prefix_comm)
+insert into llx_societe (rowid,nom,cp,ville,tel,fax,fournisseur,prefix_comm)
 values (101,'Cerisier','22290','Goudelin','01 55 55 03 18','01 55 55 55 55',1,'CER');
 
 insert into llx_societe (nom,cp,ville,tel,fax,client,url)
 values ('Turin','29890','Brignogan-Plage','01 55 55 03 18','01 55 55 55 55',1,'http://www.ot-brignogan-plage.fr/');
 
-insert into llx_societe (idp,nom,cp,ville,tel,fax,fournisseur,prefix_comm)
+insert into llx_societe (rowid,nom,cp,ville,tel,fax,fournisseur,prefix_comm)
 values (100,'Ch�ne','22330','Le Gouray','01 55 55 03 18','01 55 55 55 55',1,'DEL');
 
 insert into llx_societe (nom,cp,ville,tel,fax,client)
@@ -165,39 +165,39 @@ values ('Iono','22110','Rostrenen','01 55 55 03 18','01 55 55 55 55',1);
 -- Contact
 --
 delete from llx_socpeople;
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email,poste)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email,poste)
 values (10,1,'Mar�chal','Ferdinand','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net','Administrateur syst�me');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (11,5,'Pejat','Jean-Marie','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
 
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email,poste)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email,poste)
 values (12,1,'Poulossi�re','Paul','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net','Directeur technique');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (13,6,'Myriam','Isabelle','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
 
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (20,2,'Corin','Arnaud','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (30,3,'Philippine','Sagan','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (31,3,'Marie','Jeanne','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (41,4,'Alix','Hopper','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (14,7,'Victoire','Renoir','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (15,7,'Baudelaire','Matthias','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (16,8,'Hugo','Benjamin','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (17,9,'Rembrandt','St�phanie','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (18,10,'Picasso','Myriam','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (19,11,'Beethoven','John','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (22,11,'Dumas','Elisabeth','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
-insert into llx_socpeople (idp,fk_soc, name, firstname, phone,fax,email)
+insert into llx_socpeople (rowid,fk_soc, name, firstname, phone,fax,email)
 values (21,10,'','Jos�phine','01 40 15 03 18','01 40 15 06 18','dev@lafrere.net');
 --
 --
diff --git a/scripts/addons/editeur/droits-nouveautes.php b/scripts/addons/editeur/droits-nouveautes.php
index 1b524c40fea..373429efe31 100644
--- a/scripts/addons/editeur/droits-nouveautes.php
+++ b/scripts/addons/editeur/droits-nouveautes.php
@@ -102,7 +102,7 @@ $sql .= ", ".MAIN_DB_PREFIX."product_fournisseur as pf";
 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
 
 $sql .= " WHERE p.rowid = pl.rowid";
-$sql .= " AND pf.fk_product = p.rowid AND s.idp=pf.fk_soc";
+$sql .= " AND pf.fk_product = p.rowid AND s.rowid = pf.fk_soc";
 $sql .= " AND p.rowid = c.fk_cnv_livre";
 $sql .= " AND p.canvas = 'livre'";
 $sql .= " ORDER BY p.rowid ASC";
diff --git a/scripts/company/export-csv-example.php b/scripts/company/export-csv-example.php
index 93d274d69ed..70a74a7969a 100644
--- a/scripts/company/export-csv-example.php
+++ b/scripts/company/export-csv-example.php
@@ -40,7 +40,7 @@ $page->set_column(0,4,18); // A
 $sql = "SELECT distinct(c.email),c.name, c.firstname, s.nom ";
 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
-$sql .= " WHERE s.idp = c.fk_soc";
+$sql .= " WHERE s.rowid = c.fk_soc";
 $sql .= " AND s.client = 1";
 $sql .= " AND c.email IS NOT NULL";
 $sql .= " ORDER BY c.email ASC";
diff --git a/scripts/company/import-csv.pl b/scripts/company/import-csv.pl
index 4019b0705e3..e14fbcd5f6e 100644
--- a/scripts/company/import-csv.pl
+++ b/scripts/company/import-csv.pl
@@ -86,7 +86,7 @@ while (<FH>)
 	$stha = $dbh->prepare($sql);
 	$stha->execute;
 	
-	$sql = "SELECT MAX(idp) as co FROM llx_societe";
+	$sql = "SELECT MAX(rowid) as co FROM llx_societe";
 	$sth = $dbh->prepare("$sql") || die $dbh->errstr ;
 	if ( $sth->execute ) {
 	    if ( $sth->rows ) {
diff --git a/scripts/company/sync_contacts_dolibarr2ldap.php b/scripts/company/sync_contacts_dolibarr2ldap.php
index 86e64ce71a2..3a5ce40b35e 100644
--- a/scripts/company/sync_contacts_dolibarr2ldap.php
+++ b/scripts/company/sync_contacts_dolibarr2ldap.php
@@ -63,7 +63,7 @@ if (! $conf->global->LDAP_CONTACT_ACTIVE)
 }
 */
 
-$sql = "SELECT idp as rowid";
+$sql = "SELECT rowid";
 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople";
 
 $resql = $db->query($sql);
diff --git a/scripts/courrier/droits-editeurs.php b/scripts/courrier/droits-editeurs.php
index f831f718ea6..dd43b0b0517 100644
--- a/scripts/courrier/droits-editeurs.php
+++ b/scripts/courrier/droits-editeurs.php
@@ -35,7 +35,7 @@ $error = 0;
 $year = strftime("%Y", time());
 
 // 
-$sql = "SELECT s.idp,s.nom";
+$sql = "SELECT s.rowid as socid, s.nom";
 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
 //$sql .= " , ".MAIN_DB_PREFIX."categorie_fournisseur as cf";
 $sql .= " WHERE s.fournisseur = 1 ";
@@ -47,7 +47,7 @@ if ($resql)
 {
   while ($obj = $db->fetch_object($resql) )
     {
-      $id       = $obj->idp;
+      $id       = $obj->socid;
       
       dolibarr_syslog("droits-editeurs.php id:$id", LOG_DEBUG );
       
@@ -120,7 +120,7 @@ class pdf_courrier_editeur
 	$year_data = $year - 1;
 
 	// On r�cup�re donn�es du mail
-	$sql = "SELECT p.rowid,p.label, pc.taux, pc.quantite";
+	$sql = "SELECT p.rowid, p.label, pc.taux, pc.quantite";
 	$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
 	$sql .= " , ".MAIN_DB_PREFIX."facturedet as fd";
 	$sql .= " , ".MAIN_DB_PREFIX."product as p";
@@ -141,7 +141,7 @@ class pdf_courrier_editeur
 	    $i = 0;
 	    while ($obj = $this->db->fetch_object($resql) )
 	      {
-		$id       = $obj->idp;
+		$id       = $obj->socid;
 		$books[$i]['title'] = $obj->label;
 		$books[$i]['id'] = $obj->rowid;
 		$books[$i]['taux'] = $obj->taux;
diff --git a/scripts/invoices/factures-impayees-commerciaux.php b/scripts/invoices/factures-impayees-commerciaux.php
index d3a5b1533a3..075d70e4153 100644
--- a/scripts/invoices/factures-impayees-commerciaux.php
+++ b/scripts/invoices/factures-impayees-commerciaux.php
@@ -50,10 +50,10 @@ $sql .= " , ".MAIN_DB_PREFIX."societe as s";
 $sql .= " , ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 $sql .= " , ".MAIN_DB_PREFIX."user as u";
 $sql .= " WHERE f.paye = 0";
-$sql .= " AND f.fk_soc = s.idp";
-$sql .= " AND sc.fk_soc = s.idp";
+$sql .= " AND f.fk_soc = s.rowid";
+$sql .= " AND sc.fk_soc = s.rowid";
 $sql .= " AND sc.fk_user = u.rowid";
-$sql .= " ORDER BY u.email ASC, s.idp ASC";
+$sql .= " ORDER BY u.email ASC, s.rowid ASC";
 
 if ( $db->query($sql) )
 {
diff --git a/scripts/prelevement/prelevement.php b/scripts/prelevement/prelevement.php
index 9d6fce6e86f..3c1480a0c0f 100644
--- a/scripts/prelevement/prelevement.php
+++ b/scripts/prelevement/prelevement.php
@@ -69,7 +69,7 @@ if (!$error)
   $sql .= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
 
   $sql .= " WHERE f.rowid = pfd.fk_facture";
-  $sql .= " AND s.idp = f.fk_soc";
+  $sql .= " AND s.rowid = f.fk_soc";
   $sql .= " AND f.fk_statut = 1";
   $sql .= " AND f.paye = 0";
   $sql .= " AND pfd.traite = 0";
-- 
GitLab