From 57d121664fc53ba2204ab9e094b8d91eed210a98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 21 Nov 2024 19:11:32 +0100 Subject: [PATCH] set object entity at create (#32019) * set object entity at create * set object entity at create * set object entity at create * set object entity at create * set object entity at create * set object entity at create * do not break multicompany thing * do not break multicompany thing * missing translation * fix phpstan * doc * fix entity * fix set entity --- htdocs/adherents/class/adherent.class.php | 5 ++++- htdocs/comm/propal/class/propal.class.php | 4 +++- htdocs/commande/class/commande.class.php | 3 ++- htdocs/compta/facture/class/facture.class.php | 3 ++- htdocs/contact/class/contact.class.php | 3 ++- htdocs/contrat/class/contrat.class.php | 3 ++- htdocs/expedition/class/expedition.class.php | 3 ++- htdocs/fichinter/class/fichinter.class.php | 3 ++- htdocs/fourn/class/fournisseur.commande.class.php | 11 ++++++++--- htdocs/fourn/class/fournisseur.facture.class.php | 3 ++- htdocs/societe/class/societe.class.php | 2 +- 11 files changed, 30 insertions(+), 13 deletions(-) diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index fb48539e46735..452bd835d11ce 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -646,6 +646,9 @@ public function create($user, $notrigger = 0) } } + // setEntity will set entity with the right value if empty or change it for the right value if multicompany module is active + $this->entity = setEntity($this); + $this->db->begin(); // Insert member @@ -658,7 +661,7 @@ public function create($user, $notrigger = 0) $sql .= ", ".($user->id > 0 ? $user->id : "null"); // Can be null because member can be created by a guest or a script $sql .= ", null, null, '".$this->db->escape($this->morphy)."'"; $sql .= ", ".((int) $this->typeid); - $sql .= ", ".$conf->entity; + $sql .= ", ".((int) $this->entity); $sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null"); $sql .= ", ".(!empty($this->ip) ? "'".$this->db->escape($this->ip)."'" : "null"); $sql .= ")"; diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index c42b5b22c93a6..daa19da672d57 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1135,6 +1135,8 @@ public function create($user, $notrigger = 0) $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; } + // setEntity will set entity with the right value if empty or change it for the right value if multicompany module is active + $this->entity = setEntity($this); // Set tmp vars $delivery_date = $this->delivery_date; @@ -1229,7 +1231,7 @@ public function create($user, $notrigger = 0) $sql .= ", ".($this->fk_project ? $this->fk_project : "null"); $sql .= ", ".(int) $this->fk_incoterms; $sql .= ", '".$this->db->escape($this->location_incoterms)."'"; - $sql .= ", ".setEntity($this); + $sql .= ", ".(int) $this->entity; $sql .= ", ".(int) $this->fk_multicurrency; $sql .= ", '".$this->db->escape($this->multicurrency_code)."'"; $sql .= ", ".(float) $this->multicurrency_tx; diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 3e97bd8037262..976b37d28dece 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -947,6 +947,7 @@ public function create($user, $notrigger = 0) $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; } + $this->entity = setEntity($this); dol_syslog(get_class($this)."::create user=".$user->id); @@ -1010,7 +1011,7 @@ public function create($user, $notrigger = 0) $sql .= ", ".(!empty($this->warehouse_id) && $this->warehouse_id > 0 ? ((int) $this->warehouse_id) : 'NULL'); $sql .= ", ".(int) $this->fk_incoterms; $sql .= ", '".$this->db->escape($this->location_incoterms)."'"; - $sql .= ", ".setEntity($this); + $sql .= ", ".(int) $this->entity; $sql .= ", ".($this->module_source ? "'".$this->db->escape($this->module_source)."'" : "null"); $sql .= ", ".($this->pos_source != '' ? "'".$this->db->escape($this->pos_source)."'" : "null"); $sql .= ", ".(int) $this->fk_multicurrency; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 06eb0d45c293b..ed4d1e522a1ff 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -523,6 +523,7 @@ public function create(User $user, $notrigger = 0, $forceduedate = 0) $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; } + $this->entity = setEntity($this); dol_syslog(get_class($this)."::create user=".$user->id." date=".$this->date); @@ -718,7 +719,7 @@ public function create(User $user, $notrigger = 0, $forceduedate = 0) $sql .= ")"; $sql .= " VALUES ("; $sql .= "'(PROV)'"; - $sql .= ", ".setEntity($this); + $sql .= ", ".(int) $this->entity; $sql .= ", ".($this->ref_ext ? "'".$this->db->escape($this->ref_ext)."'" : "null"); $sql .= ", '".$this->db->escape($this->type)."'"; $sql .= ", ".($this->subtype ? "'".$this->db->escape($this->subtype)."'" : "null"); diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 08041134de3e4..9af01fe74ced5 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -508,7 +508,8 @@ public function create($user, $notrigger = 0) $this->statut = 0; // This is to convert '' into '0' to avoid bad sql request } - $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity); + // setEntity will set entity with the right value if empty or change it for the right value if multicompany module is active + $this->entity = setEntity($this); $sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople ("; $sql .= " datec"; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 81371d0556e95..2fefa846bce2c 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -1024,6 +1024,7 @@ public function create($user) $this->error .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("SalesRepresentativeFollowUp")); $paramsok = 0; } + $this->entity = setEntity($this); if (!$paramsok) { return -1; } @@ -1043,7 +1044,7 @@ public function create($user) $sql .= ",".($this->commercial_suivi_id > 0 ? ((int) $this->commercial_suivi_id) : "NULL"); $sql .= ",".($this->fk_project > 0 ? ((int) $this->fk_project) : "NULL"); $sql .= ", ".(dol_strlen($this->ref) <= 0 ? "null" : "'".$this->db->escape($this->ref)."'"); - $sql .= ", ".((int) $conf->entity); + $sql .= ", ".((int) $this->entity); $sql .= ", ".((int) $this->signed_status); $sql .= ", ".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL"); $sql .= ", ".(!empty($this->note_public) ? ("'".$this->db->escape($this->note_public)."'") : "NULL"); diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 5193c3cde90d7..54df830cd0676 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -430,6 +430,7 @@ public function create($user, $notrigger = 0) if (empty($this->date_shipping) && !empty($this->date_expedition)) { $this->date_shipping = $this->date_expedition; } + $this->entity = setEntity($this); $this->user = $user; @@ -462,7 +463,7 @@ public function create($user, $notrigger = 0) $sql .= ", signed_status"; $sql .= ") VALUES ("; $sql .= "'(PROV)'"; - $sql .= ", ".((int) $conf->entity); + $sql .= ", ".((int) $this->entity); $sql .= ", ".($this->ref_customer ? "'".$this->db->escape($this->ref_customer)."'" : "null"); $sql .= ", ".($this->ref_ext ? "'".$this->db->escape($this->ref_ext)."'" : "null"); $sql .= ", '".$this->db->idate($now)."'"; diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 33d4eda38055d..1a9340923e697 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -295,6 +295,7 @@ public function create($user, $notrigger = 0) dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); return -1; } + $this->entity = setEntity($this); $soc = new Societe($this->db); $result = $soc->fetch($this->socid); @@ -325,7 +326,7 @@ public function create($user, $notrigger = 0) $sql .= ", '".$this->db->idate($now)."'"; $sql .= ", '".$this->db->escape($this->ref)."'"; $sql .= ", ".($this->ref_client ? "'".$this->db->escape($this->ref_client)."'" : "null"); - $sql .= ", ".((int) $conf->entity); + $sql .= ", ".((int) $this->entity); $sql .= ", ".((int) $user->id); $sql .= ", ".((int) $user->id); $sql .= ", ".($this->description ? "'".$this->db->escape($this->description)."'" : "null"); diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 3fef90726d4fd..9064fe9bbc4fa 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -116,6 +116,8 @@ class CommandeFournisseur extends CommonOrder /** * @var ?int<0,9> + * @deprecated see $status + * @see $status */ public $statut; // 0=Draft -> 1=Validated -> 2=Approved -> 3=Ordered/Process running -> 4=Received partially -> 5=Received totally -> (reopen) 4=Received partially // -> 7=Canceled/Never received -> (reopen) 3=Process running @@ -892,7 +894,7 @@ public function valid($user, $idwarehouse = 0, $notrigger = 0) */ public function getLibStatut($mode = 0) { - return $this->LibStatut($this->statut, $mode, $this->billed); + return $this->LibStatut($this->status, $mode, $this->billed); } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -992,7 +994,7 @@ public function getTooltipContentArray($params) if ($user->hasRight("fournisseur", "commande", "read")) { $datas['picto'] = ''.$langs->trans("SupplierOrder").''; - if ($this->statut) { + if ($this->status) { $datas['picto'] .= ' '.$this->getLibStatut(5); } if (!empty($this->ref)) { @@ -1156,6 +1158,7 @@ public function getNextNumRef($soc) $obj = new $classname(); '@phan-var-force ModeleNumRefSuppliersOrders $obj'; + /** @var ModeleNumRefSuppliersOrders $obj */ $numref = $obj->getNextValue($soc, $this); if ($numref != "") { @@ -1169,6 +1172,7 @@ public function getNextNumRef($soc) return -2; } } + /** * Class invoiced the supplier order * @@ -1598,6 +1602,7 @@ public function create($user, $notrigger = 0) $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; } + $this->entity = setEntity($this); // We set order into draft status $this->statut = self::STATUS_DRAFT; // deprecated @@ -1630,7 +1635,7 @@ public function create($user, $notrigger = 0) $sql .= ", ".(isset($this->ref_supplier) ? "'".$this->db->escape($this->ref_supplier)."'" : "NULL"); $sql .= ", '".$this->db->escape($this->note_private)."'"; $sql .= ", '".$this->db->escape($this->note_public)."'"; - $sql .= ", ".setEntity($this); + $sql .= ", ".((int) $this->entity); $sql .= ", ".((int) $this->socid); $sql .= ", ".($this->fk_project > 0 ? ((int) $this->fk_project) : "null"); $sql .= ", '".$this->db->idate($date)."'"; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index c0514cead7eb4..be62ce3770b74 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -423,6 +423,7 @@ public function create($user) $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; } + $this->entity = setEntity($this); $this->db->begin(); @@ -577,7 +578,7 @@ public function create($user) $sql .= "'(PROV)'"; $sql .= ", '".$this->db->escape($this->ref_supplier)."'"; $sql .= ", '".$this->db->escape($this->ref_ext)."'"; - $sql .= ", ".((int) $conf->entity); + $sql .= ", ".((int) $this->entity); $sql .= ", '".$this->db->escape($this->type)."'"; $sql .= ", ".((int) $this->subtype); $sql .= ", '".$this->db->escape(isset($this->label) ? $this->label : (isset($this->libelle) ? $this->libelle : ''))."'"; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 7f35e25cef72b..35b5d930548c4 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1038,7 +1038,7 @@ public function create(User $user, $notrigger = 0) $result = $this->verify(); if ($result >= 0) { - $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity); + $this->entity = setEntity($this); $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe ("; $sql .= "nom";