Update societe.class.php
This commit is contained in:
parent
0c4884bb2c
commit
8a9c21c642
@ -3112,20 +3112,55 @@ class Societe extends CommonObject
|
|||||||
{
|
{
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
if ($this->id) {
|
if ($this->id) {
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
|
// InfraS change (to avoid infinite loop)
|
||||||
$sql .= " SET parent = ".($id > 0 ? $id : "null");
|
$sameparent = $this->get_parents($id, $this->id);
|
||||||
$sql .= " WHERE rowid = ".$this->id;
|
if ($sameparent < 0) return -1;
|
||||||
|
elseif ($sameparent == 1)
|
||||||
|
{
|
||||||
|
setEventMessages('la maison mère choisie est déjà filiale de ce tiers', null, 'warnings');
|
||||||
|
return -1;
|
||||||
|
} // elseif ($sameparent == 1)
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$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;
|
||||||
} else {
|
} // if ($resql)
|
||||||
return -1;
|
else return -1;
|
||||||
}
|
} // else // elseif ($sameparent == 1)
|
||||||
} else {
|
} // if ($this->id)
|
||||||
return -1;
|
else return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||||
|
/**
|
||||||
|
* Search parent commany of current company
|
||||||
|
*
|
||||||
|
* @param int $idparent Id of thirdparty to check
|
||||||
|
* @param int $idchild Id of thirdparty to compare to
|
||||||
|
* @return int <0 if KO, 0 if OK or 1 if at some level a parent company was the child to compare to
|
||||||
|
*/
|
||||||
|
public function get_parents($idparent, $idchild)
|
||||||
|
{
|
||||||
|
// phpcs:enable
|
||||||
|
$sql = 'SELECT s.parent';
|
||||||
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
|
||||||
|
$sql .= ' WHERE rowid = '.$idparent;
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
|
||||||
|
if ($obj->parent == '') return 0;
|
||||||
|
elseif ($obj->parent == $idchild) return 1;
|
||||||
|
else $sameparent = $this->get_parents($obj->parent, $idchild);
|
||||||
|
return $sameparent;
|
||||||
|
} // if ($resql)
|
||||||
|
else return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user