Fix check of customer/supplier code

This commit is contained in:
Laurent Destailleur 2018-01-10 18:19:54 +01:00
parent 43d560830c
commit f2b8c3c97d
3 changed files with 16 additions and 13 deletions

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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);