diff --git a/htdocs/core/modules/societe/mod_codeclient_elephant.php b/htdocs/core/modules/societe/mod_codeclient_elephant.php index d6a6da23a94..993bb2ed2b3 100644 --- a/htdocs/core/modules/societe/mod_codeclient_elephant.php +++ b/htdocs/core/modules/societe/mod_codeclient_elephant.php @@ -297,12 +297,14 @@ class mod_codeclient_elephant extends ModeleThirdPartyCode * @param DoliDB $db Handler acces base * @param string $code Code a verifier * @param Societe $soc Objet societe + * @param int $type 0 = customer/prospect , 1 = supplier * @return int 0 if available, <0 if KO */ - function verif_dispo($db, $code, $soc) + function verif_dispo($db, $code, $soc, $type=0) { - $sql = "SELECT code_client FROM ".MAIN_DB_PREFIX."societe"; - $sql.= " WHERE code_client = '".$code."'"; + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; + if ($type == 1) $sql.= " WHERE code_fournisseur = '".$code."'"; + else $sql.= " WHERE code_client = '".$code."'"; if ($soc->id > 0) $sql.= " AND rowid <> ".$soc->id; $resql=$db->query($sql); diff --git a/htdocs/core/modules/societe/mod_codeclient_monkey.php b/htdocs/core/modules/societe/mod_codeclient_monkey.php index e942e747794..f4d9e5b4b33 100644 --- a/htdocs/core/modules/societe/mod_codeclient_monkey.php +++ b/htdocs/core/modules/societe/mod_codeclient_monkey.php @@ -182,7 +182,7 @@ class mod_codeclient_monkey extends ModeleThirdPartyCode { if ($this->verif_syntax($code) >= 0) { - $is_dispo = $this->verif_dispo($db, $code, $soc); + $is_dispo = $this->verif_dispo($db, $code, $soc, $type); if ($is_dispo <> 0) { $result=-3; @@ -205,7 +205,7 @@ class mod_codeclient_monkey extends ModeleThirdPartyCode } } - dol_syslog(get_class($this)."::verif type=".$type." result=".$result); + dol_syslog(get_class($this)."::verif code=".$code." type=".$type." result=".$result); return $result; } @@ -216,14 +216,16 @@ class mod_codeclient_monkey extends ModeleThirdPartyCode * @param DoliDB $db Handler acces base * @param string $code Code a verifier * @param Societe $soc Objet societe + * @param int $type 0 = customer/prospect , 1 = supplier * @return int 0 if available, <0 if KO */ - function verif_dispo($db, $code, $soc) + function verif_dispo($db, $code, $soc, $type=0) { global $conf, $mc; - $sql = "SELECT code_client FROM ".MAIN_DB_PREFIX."societe"; - $sql.= " WHERE code_client = '".$code."'"; + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; + if ($type == 1) $sql.= " WHERE code_fournisseur = '".$code."'"; + else $sql.= " WHERE code_client = '".$code."'"; $sql.= " AND entity IN (".getEntity('societe').")"; if ($soc->id > 0) $sql.= " AND rowid <> ".$soc->id; @@ -244,7 +246,6 @@ class mod_codeclient_monkey extends ModeleThirdPartyCode { return -2; } - } diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 34724c844d5..cfa07c4f7c4 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -462,8 +462,8 @@ class Societe extends CommonObject $this->db->begin(); // For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts) - if ($this->code_client == -1) $this->get_codeclient($this,0); - if ($this->code_fournisseur == -1) $this->get_codefournisseur($this,1); + if ($this->code_client == -1 || $this->code_client === 'auto') $this->get_codeclient($this,0); + if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1); // Check more parameters (including mandatory setup // If error, this->errors[] is filled @@ -812,8 +812,8 @@ class Societe extends CommonObject $this->barcode=trim($this->barcode); // For automatic creation - if ($this->code_client == -1) $this->get_codeclient($this,0); - if ($this->code_fournisseur == -1) $this->get_codefournisseur($this,1); + if ($this->code_client == -1 || $this->code_client === 'auto') $this->get_codeclient($this,0); + if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1); $this->code_compta=trim($this->code_compta); $this->code_compta_fournisseur=trim($this->code_compta_fournisseur);