diff --git a/htdocs/langs/ca_ES/errors.lang b/htdocs/langs/ca_ES/errors.lang
index 53b481a318e..9175059a8f1 100644
--- a/htdocs/langs/ca_ES/errors.lang
+++ b/htdocs/langs/ca_ES/errors.lang
@@ -83,4 +83,5 @@ ErrorBadMaskFailedToLocatePosOfSequence=Error, sense número de seqüència en l
ErrorBadMaskBadRazMonth=Error, valor de tornada a 0 incorrecte
ErrorSelectAtLeastOne=Error. Seleccioneu com a mínim una entrada.
ErrorProductWithRefNotExist=La referència de producte '%s' no existeix
-ErrorDeleteNotPossibleLineIsConsolidated=Eliminació impossible ja que el registre està enllaçat a una transacció bancària conciliada
\ No newline at end of file
+ErrorDeleteNotPossibleLineIsConsolidated=Eliminació impossible ja que el registre està enllaçat a una transacció bancària conciliada
+ErrorProdIdAlreadyExist=%s es troba assignat a altre tercer
\ No newline at end of file
diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang
index b75f10c59d5..2eb610db51b 100644
--- a/htdocs/langs/en_US/errors.lang
+++ b/htdocs/langs/en_US/errors.lang
@@ -82,4 +82,5 @@ ErrorBadMaskFailedToLocatePosOfSequence=Error, mask without sequence number
ErrorBadMaskBadRazMonth=Error, bad reset value
ErrorSelectAtLeastOne=Error. Select at least one entry.
ErrorProductWithRefNotExist=Product with reference '%s' don't exist
-ErrorDeleteNotPossibleLineIsConsolidated=Delete not possible because record is linked to a bank transation that is conciliated
\ No newline at end of file
+ErrorDeleteNotPossibleLineIsConsolidated=Delete not possible because record is linked to a bank transation that is conciliated
+ErrorProdIdAlreadyExist=%s is assigned to another third
\ No newline at end of file
diff --git a/htdocs/langs/es_ES/errors.lang b/htdocs/langs/es_ES/errors.lang
index c7af8f2646e..6f5ea5a7453 100644
--- a/htdocs/langs/es_ES/errors.lang
+++ b/htdocs/langs/es_ES/errors.lang
@@ -83,4 +83,5 @@ ErrorBadMaskFailedToLocatePosOfSequence=Error, sin número de secuencia en la m
ErrorBadMaskBadRazMonth=Error, valor de vuelta a 0 incorrecto
ErrorSelectAtLeastOne=Error. Seleccione al menos una entrada.
ErrorProductWithRefNotExist=La referencia de producto '%s' no existe
-ErrorDeleteNotPossibleLineIsConsolidated=Eliminación imposible ya que el registro está enlazado a una transacción bancaria conciliada
\ No newline at end of file
+ErrorDeleteNotPossibleLineIsConsolidated=Eliminación imposible ya que el registro está enlazado a una transacción bancaria conciliada
+ErrorProdIdAlreadyExist=%s se encuentra asignado a otro tercero
\ No newline at end of file
diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang
index 116dfd9af5f..334a237aeec 100644
--- a/htdocs/langs/fr_FR/errors.lang
+++ b/htdocs/langs/fr_FR/errors.lang
@@ -83,4 +83,5 @@ ErrorBadMaskFailedToLocatePosOfSequence=Erreur, masque sans numéro de séquence
ErrorBadMaskBadRazMonth=Erreur, mauvais valeur de remise à zéro
ErrorSelectAtLeastOne=Erreur. Sélectionnez au moins une entrée.
ErrorProductWithRefNotExist=La référence produit '%s' n'existe pas
-ErrorDeleteNotPossibleLineIsConsolidated=Suppression impossible car l'enregistrement porte sur au moins une transaction bancaire rapprochée
\ No newline at end of file
+ErrorDeleteNotPossibleLineIsConsolidated=Suppression impossible car l'enregistrement porte sur au moins une transaction bancaire rapprochée
+ErrorProdIdAlreadyExist=%s est attribué à un autre tiers
\ No newline at end of file
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index 6edf7b9d6c6..696ba4e921b 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -6,7 +6,7 @@
* Copyright (C) 2006 Andre Cianfarani
* Copyright (C) 2005-2009 Regis Houssin
* Copyright (C) 2008 Patrick Raguin
- * Copyright (C) 2010 Juanjo Menent
+ * Copyright (C) 2010-2011 Juanjo Menent
*
* 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
@@ -26,7 +26,7 @@
* \file htdocs/societe/class/societe.class.php
* \ingroup societe
* \brief File for third party class
- * \version $Id: societe.class.php,v 1.96 2011/08/10 22:47:35 eldy Exp $
+ * \version $Id: societe.class.php,v 1.97 2011/08/11 16:53:43 simnandez Exp $
*/
require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
@@ -1958,12 +1958,88 @@ class Societe extends CommonObject
}
}
}
+
+ /**
+ * Returns if a profid sould be verified
+ * @param idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm)
+ * @return boolean true , false
+ */
+ function id_prof_verifiable($idprof)
+ {
+ global $conf;
+
+ switch($idprof)
+ {
+ case 1:
+ $ret=(!$conf->global->SOCIETE_IDPROF1_UNIQUE?false:true);
+ break;
+ case 2:
+ $ret=(!$conf->global->SOCIETE_IDPROF2_UNIQUE?false:true);
+ break;
+ case 3:
+ $ret=(!$conf->global->SOCIETE_IDPROF3_UNIQUE?false:true);
+ break;
+ case 4:
+ $ret=(!$conf->global->SOCIETE_IDPROF4_UNIQUE?false:true);
+ break;
+ default:
+ $ret=false;
+ }
+
+ return $ret;
+ }
+
+ /**
+ * Verify if a profid exists into database for others thirds
+ * @param idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm)
+ * @param value value of profid
+ * @param socid id of society if update
+ * @return boolean true if exists, false if not
+ */
+ function id_prof_exists($idprof,$value,$socid=0)
+ {
+ switch($idprof)
+ {
+ case 1:
+ $field="siren";
+ break;
+ case 2:
+ $field="siret";
+ break;
+ case 3:
+ $field="ape";
+ break;
+ case 4:
+ $field="idprof4";
+ break;
+ }
+
+ //Verify duplicate entries
+ $sql = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."'";
+ if($socid) $sql .= " AND rowid <> ".$socid;
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $nump = $this->db->num_rows($resql);
+ $obj = $this->db->fetch_object($resql);
+ $count = $obj->idprof;
+ }
+ else
+ {
+ $count = 0;
+ print $this->db->error();
+ }
+ $this->db->free($resql);
+
+ if ($count > 0) return true;
+ else return false;
+ }
/**
* Verifie la validite d'un identifiant professionnel en fonction du pays de la societe (siren, siret, ...)
* @param idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm)
* @param soc Objet societe
- * @return int <=0 if KO, >0 if OK
+ * @return int <=0 if KO, >0 if OK, -10=idprofx already exist into database
* TODO not in business class
*/
function id_prof_check($idprof,$soc)
@@ -1973,7 +2049,7 @@ class Societe extends CommonObject
$ok=1;
if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1;
-
+
// Verifie SIREN si pays FR
if ($idprof == 1 && $soc->pays_code == 'FR')
{
diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php
index d054983f8a3..567c079d66f 100644
--- a/htdocs/societe/soc.php
+++ b/htdocs/societe/soc.php
@@ -25,7 +25,7 @@
* \file htdocs/societe/soc.php
* \ingroup societe
* \brief Third party card page
- * \version $Id: soc.php,v 1.132 2011/08/10 22:47:35 eldy Exp $
+ * \version $Id: soc.php,v 1.133 2011/08/11 16:53:43 simnandez Exp $
*/
require("../main.inc.php");
@@ -133,7 +133,7 @@ if (empty($reshook))
$object->fetch($socid);
}
else if ($canvas) $object->canvas=$canvas;
-
+
if (GETPOST("private") == 1)
{
$object->particulier = GETPOST("private");
@@ -230,8 +230,24 @@ if (empty($reshook))
$error++; $errors[] = $langs->trans("ErrorSupplierModuleNotEnabled");
$action = ($action=='add'?'create':'edit');
}
- }
+ if($action == 'add') $mode=0;
+ else $mode=1;
+
+ for ($i = 1; $i < 3; $i++)
+ {
+ $slabel="idprof".$i;
+ if (($_POST[$slabel] && $object->id_prof_verifiable($i)))
+ {
+ if($object->id_prof_exists($i,$_POST["$slabel"],$object->id))
+ {
+ $langs->load("errors");
+ $error++; $errors[] = $langs->transcountry('ProfId'.$i ,$object->pays_code)." ".$langs->trans("ErrorProdIdAlreadyExist",$_POST["$slabel"]);
+ $action = ($action=='add'?'create':'edit');
+ }
+ }
+ }
+ }
if (! $error)
{
if ($action == 'add')
@@ -1959,5 +1975,5 @@ else
$db->close();
-llxFooter('$Date: 2011/08/10 22:47:35 $ - $Revision: 1.132 $');
+llxFooter('$Date: 2011/08/11 16:53:43 $ - $Revision: 1.133 $');
?>
\ No newline at end of file