From 38da2a61e4a7f2f10ce9577bc4274ff106f2ad91 Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Sun, 19 Jan 2025 17:38:34 +0100 Subject: [PATCH] Clean code --- htdocs/commande/class/commande.class.php | 124 ++--------------------- 1 file changed, 8 insertions(+), 116 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 392382ce3d4..474c50a7ff7 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -534,7 +534,7 @@ class Commande extends CommonOrder $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; $sql .= " SET ref = '".$this->db->escape($num)."',"; $sql .= " fk_statut = ".self::STATUS_VALIDATED.","; - $sql .= " date_valid='".$this->db->idate($now)."',"; + $sql .= " date_valid = '".$this->db->idate($now)."',"; $sql .= " fk_user_valid = ".($user->id > 0 ? (int) $user->id : "null").","; $sql .= " fk_user_modif = ".((int) $user->id); $sql .= " WHERE rowid = ".((int) $this->id); @@ -655,7 +655,7 @@ class Commande extends CommonOrder public function setDraft($user, $idwarehouse = -1) { //phpcs:enable - global $conf, $langs; + global $langs; $error = 0; @@ -1234,7 +1234,7 @@ class Commande extends CommonOrder */ public function createFromClone(User $user, $socid = 0) { - global $conf, $user, $hookmanager; + global $user, $hookmanager; $error = 0; @@ -1537,7 +1537,7 @@ class Commande extends CommonOrder */ public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $fk_product = 0, $remise_percent = 0, $info_bits = 0, $fk_remise_except = 0, $price_base_type = 'HT', $pu_ttc = 0, $date_start = '', $date_end = '', $type = 0, $rang = -1, $special_code = 0, $fk_parent_line = 0, $fk_fournprice = null, $pa_ht = 0, $label = '', $array_options = array(), $fk_unit = null, $origin = '', $origin_id = 0, $pu_ht_devise = 0, $ref_ext = '', $noupdateafterinsertline = 0) { - global $mysoc, $conf, $langs, $user; + global $mysoc, $langs, $user; $logtext = "::addline commandeid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_percent=$remise_percent"; $logtext .= ", info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, date_start=$date_start"; @@ -1910,16 +1910,16 @@ class Commande extends CommonOrder $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON c.fk_incoterms = i.rowid'; if ($id) { - $sql .= " WHERE c.rowid=".((int) $id); + $sql .= " WHERE c.rowid = ".((int) $id); } else { $sql .= " WHERE c.entity IN (".getEntity('commande').")"; // Don't use entity if you use rowid } if ($ref) { - $sql .= " AND c.ref='".$this->db->escape($ref)."'"; + $sql .= " AND c.ref = '".$this->db->escape($ref)."'"; } if ($ref_ext) { - $sql .= " AND c.ref_ext='".$this->db->escape($ref_ext)."'"; + $sql .= " AND c.ref_ext = '".$this->db->escape($ref_ext)."'"; } dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -2372,45 +2372,6 @@ class Commande extends CommonOrder return 0; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Return a array with the pending stock by product - * - * @param int $filtre_statut Filtre sur statut - * @return int 0 si OK, <0 si KO - * - * TODO FONCTION NON FINIE A FINIR - */ - /*public function stock_array($filtre_statut = self::STATUS_CANCELED) - { - // phpcs:enable - $this->stocks = array(); - - // Tableau des id de produit de la commande - $array_of_product = array(); - - // Recherche total en stock pour chaque produit - // TODO $array_of_product est défini vide juste au dessus !! - if (count($array_of_product)) { - $sql = "SELECT fk_product, sum(ps.reel) as total"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps"; - $sql .= " WHERE ps.fk_product IN (".$this->db->sanitize(join(',', $array_of_product)).")"; - $sql .= ' GROUP BY fk_product'; - $resql = $this->db->query($sql); - if ($resql) { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) { - $obj = $this->db->fetch_object($resql); - $this->stocks[$obj->fk_product] = $obj->total; - $i++; - } - $this->db->free($resql); - } - } - return 0; - }*/ - /** * Delete an order line * @@ -2544,73 +2505,6 @@ class Commande extends CommonOrder } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Set a fixed amount discount - * - * @param User $user User qui positionne la remise - * @param float $remise Discount - * @param int $notrigger 1=Does not execute triggers, 0= execute triggers - * @return int Return integer <0 if KO, >0 if OK - */ - /* - public function set_remise_absolue($user, $remise, $notrigger = 0) - { - // phpcs:enable - if (empty($remise)) { - $remise = 0; - } - - $remise = price2num($remise); - - if ($user->hasRight('commande', 'creer')) { - $error = 0; - - $this->db->begin(); - - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql .= ' SET remise_absolue = '.((float) $remise); - $sql .= ' WHERE rowid = '.((int) $this->id).' AND fk_statut = '.self::STATUS_DRAFT; - - dol_syslog(__METHOD__, LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { - $this->errors[] = $this->db->error(); - $error++; - } - - if (!$error) { - $this->oldcopy = clone $this; - $this->remise_absolue = $remise; - $this->update_price(1); - } - - if (!$notrigger && empty($error)) { - // Call trigger - $result = $this->call_trigger('ORDER_MODIFY', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } - - if (!$error) { - $this->db->commit(); - return 1; - } else { - foreach ($this->errors as $errmsg) { - dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); - $this->error .= ($this->error ? ', '.$errmsg : $errmsg); - } - $this->db->rollback(); - return -1 * $error; - } - } - - return 0; - } - */ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set the order date @@ -3138,7 +3032,7 @@ class Commande extends CommonOrder */ public function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $price_base_type = 'HT', $info_bits = 0, $date_start = '', $date_end = '', $type = 0, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = null, $pa_ht = 0, $label = '', $special_code = 0, $array_options = array(), $fk_unit = null, $pu_ht_devise = 0, $notrigger = 0, $ref_ext = '', $rang = 0) { - global $conf, $mysoc, $langs, $user; + global $mysoc, $langs, $user; dol_syslog(get_class($this)."::updateline id=$rowid, desc=$desc, pu=$pu, qty=$qty, remise_percent=$remise_percent, txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, price_base_type=$price_base_type, info_bits=$info_bits, date_start=$date_start, date_end=$date_end, type=$type, fk_parent_line=$fk_parent_line, pa_ht=$pa_ht, special_code=$special_code, ref_ext=$ref_ext"); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; @@ -3350,8 +3244,6 @@ class Commande extends CommonOrder */ public function update(User $user, $notrigger = 0) { - global $conf; - $error = 0; // Clean parameters