Update societe.class.php

This commit is contained in:
Laurent Destailleur 2021-05-20 14:38:24 +02:00 committed by GitHub
parent 70c85cfd72
commit 890d0f8040
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3114,25 +3114,25 @@ class Societe extends CommonObject
if ($this->id) { if ($this->id) {
// InfraS change (to avoid infinite loop) // InfraS change (to avoid infinite loop)
$sameparent = $this->get_parents($id, $this->id); $sameparent = $this->get_parents($id, $this->id);
if ($sameparent < 0) return -1; if ($sameparent < 0) {
elseif ($sameparent == 1)
{
setEventMessages('la maison mère choisie est déjà filiale de ce tiers', null, 'warnings');
return -1; return -1;
} // elseif ($sameparent == 1) } elseif ($sameparent == 1) {
else { setEventMessages('ParentCompanyIsAlreadyAChild', null, 'warnings');
return -1;
} else {
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe SET parent = '.($id > 0 ? $id : 'null').' WHERE rowid = '.$this->id; $sql = 'UPDATE '.MAIN_DB_PREFIX.'societe SET parent = '.($id > 0 ? $id : 'null').' WHERE rowid = '.$this->id;
dol_syslog(get_class($this).'::set_parent', LOG_DEBUG); dol_syslog(get_class($this).'::set_parent', LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql) {
{
$this->parent = $id; $this->parent = $id;
return 1; return 1;
} // if ($resql) } else {
else return -1; return -1;
} // else // elseif ($sameparent == 1) }
} // if ($this->id) }
else return -1; } else {
return -1;
}
} }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
@ -3150,16 +3150,20 @@ class Societe extends CommonObject
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s'; $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
$sql .= ' WHERE rowid = '.$idparent; $sql .= ' WHERE rowid = '.$idparent;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql) {
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
if ($obj->parent == '') return 0; if ($obj->parent == '') {
elseif ($obj->parent == $idchild) return 1; return 0;
else $sameparent = $this->get_parents($obj->parent, $idchild); } elseif ($obj->parent == $idchild) {
return 1;
} else {
$sameparent = $this->get_parents($obj->parent, $idchild);
}
return $sameparent; return $sameparent;
} // if ($resql) } else {
else return -1; return -1;
}
} }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps