Skip to content

Commit

Permalink
set object entity at create (#32019)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
frederic34 authored Nov 21, 2024
1 parent 687e71d commit 57d1216
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 13 deletions.
5 changes: 4 additions & 1 deletion htdocs/adherents/class/adherent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 .= ")";
Expand Down
4 changes: 3 additions & 1 deletion htdocs/comm/propal/class/propal.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion htdocs/commande/class/commande.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion htdocs/compta/facture/class/facture.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion htdocs/contact/class/contact.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion htdocs/contrat/class/contrat.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion htdocs/expedition/class/expedition.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)."'";
Expand Down
3 changes: 2 additions & 1 deletion htdocs/fichinter/class/fichinter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
11 changes: 8 additions & 3 deletions htdocs/fourn/class/fournisseur.commande.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -992,7 +994,7 @@ public function getTooltipContentArray($params)

if ($user->hasRight("fournisseur", "commande", "read")) {
$datas['picto'] = '<u class="paddingrightonly">'.$langs->trans("SupplierOrder").'</u>';
if ($this->statut) {
if ($this->status) {
$datas['picto'] .= ' '.$this->getLibStatut(5);
}
if (!empty($this->ref)) {
Expand Down Expand Up @@ -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 != "") {
Expand All @@ -1169,6 +1172,7 @@ public function getNextNumRef($soc)
return -2;
}
}

/**
* Class invoiced the supplier order
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)."'";
Expand Down
3 changes: 2 additions & 1 deletion htdocs/fourn/class/fournisseur.facture.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ public function create($user)
$this->fk_multicurrency = 0;
$this->multicurrency_tx = 1;
}
$this->entity = setEntity($this);

$this->db->begin();

Expand Down Expand Up @@ -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 : ''))."'";
Expand Down
2 changes: 1 addition & 1 deletion htdocs/societe/class/societe.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 57d1216

Please sign in to comment.