diff --git a/dev/build/phpstan/phpstan-baseline.neon b/dev/build/phpstan/phpstan-baseline.neon index bd4416e2bd5..eece2d10dd4 100644 --- a/dev/build/phpstan/phpstan-baseline.neon +++ b/dev/build/phpstan/phpstan-baseline.neon @@ -10806,126 +10806,12 @@ parameters: count: 1 path: ../../../htdocs/expedition/card.php - - - message: '#^Call to function method_exists\(\) with \$this\(Expedition\) and ''getLibStatut'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Call to function method_exists\(\) with \$this\(Expedition\) and ''getNomUrl'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Call to function property_exists\(\) with \$this\(Expedition\) and ''thirdparty'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Call to function property_exists\(\) with \$this\(Expedition\) and ''total_ht'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/expedition/class/expedition.class.php - - message: '#^Left side of && is always true\.$#' identifier: booleanAnd.leftAlwaysTrue count: 1 path: ../../../htdocs/expedition/class/expedition.class.php - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 5 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Property CommonObject\:\:\$fk_delivery_address \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Property CommonObject\:\:\$shipping_method_id \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Property Expedition\:\:\$fk_user_author \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Property Expedition\:\:\$ref_customer \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Property Expedition\:\:\$size_units \(int\|string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Property Expedition\:\:\$socid \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Property Expedition\:\:\$tracking_number \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Property Expedition\:\:\$trueDepth \(int\|string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Property Expedition\:\:\$trueHeight \(int\|string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Property Expedition\:\:\$trueWeight \(int\|string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Property Expedition\:\:\$trueWidth \(int\|string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Property Expedition\:\:\$weight_units \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Property ExpeditionLigne\:\:\$detail_batch \(array\\|stdClass\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/expedition/class/expedition.class.php - - - - message: '#^Ternary operator condition is always true\.$#' - identifier: ternary.alwaysTrue - count: 1 - path: ../../../htdocs/expedition/class/expedition.class.php - - message: '#^Negated boolean expression is always true\.$#' identifier: booleanNot.alwaysTrue diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 899ff0c0bbb..5170ed21996 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -3151,7 +3151,7 @@ class Adherent extends CommonObject $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); - $nb = $obj->nb; + $nb = (int) $obj->nb; $this->db->free($resql); return $nb; diff --git a/htdocs/admin/system/perf.php b/htdocs/admin/system/perf.php index 61a91db6d66..fa31433680e 100644 --- a/htdocs/admin/system/perf.php +++ b/htdocs/admin/system/perf.php @@ -538,7 +538,7 @@ if ($resql) { $limitforoptim = 5000; $num = $db->num_rows($resql); $obj = $db->fetch_object($resql); - $nb = $obj->nb; + $nb = (int) $obj->nb; if ($nb > $limitforoptim) { if (!getDolGlobalString('PRODUIT_USE_SEARCH_TO_SELECT')) { print img_picto('', 'warning.png', 'class="pictofixedwidth"').' '.$langs->trans("YouHaveXObjectUseComboOptim", $nb, $langs->transnoentitiesnoconv("ProductsOrServices"), 'PRODUIT_USE_SEARCH_TO_SELECT'); @@ -559,7 +559,7 @@ if ($resql) { $limitforoptim = 5000; $num = $db->num_rows($resql); $obj = $db->fetch_object($resql); - $nb = $obj->nb; + $nb = (int) $obj->nb; if ($nb > $limitforoptim) { if (!getDolGlobalString('COMPANY_USE_SEARCH_TO_SELECT')) { print img_picto('', 'warning.png', 'class="pictofixedwidth"').' '.$langs->trans("YouHaveXObjectUseComboOptim", $nb, $langs->transnoentitiesnoconv("ThirdParties"), 'COMPANY_USE_SEARCH_TO_SELECT'); @@ -580,7 +580,7 @@ if ($resql) { $limitforoptim = 5000; $num = $db->num_rows($resql); $obj = $db->fetch_object($resql); - $nb = $obj->nb; + $nb = (int) $obj->nb; if ($nb > $limitforoptim) { if (!getDolGlobalString('CONTACT_USE_SEARCH_TO_SELECT')) { print img_picto('', 'warning.png', 'class="pictofixedwidth"').' '.$langs->trans("YouHaveXObjectUseComboOptim", $nb, $langs->transnoentitiesnoconv("Contacts"), 'CONTACT_USE_SEARCH_TO_SELECT'); @@ -601,7 +601,7 @@ if ($resql) { $limitforoptim = 5000; $num = $db->num_rows($resql); $obj = $db->fetch_object($resql); - $nb = $obj->nb; + $nb = (int) $obj->nb; if ($nb > $limitforoptim) { if (!getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) { print img_picto('', 'warning.png', 'class="pictofixedwidth"').' '.$langs->trans("YouHaveXObjectUseComboOptim", $nb, $langs->transnoentitiesnoconv("Projects"), 'PROJECT_USE_SEARCH_TO_SELECT'); @@ -630,7 +630,7 @@ if ($resql) { $limitforoptim = 100000; $num = $db->num_rows($resql); $obj = $db->fetch_object($resql); - $nb = $obj->nb; + $nb = (int) $obj->nb; if ($nb > $limitforoptim) { if (!getDolGlobalString('PRODUCT_DONOTSEARCH_ANYWHERE')) { print img_picto('', 'warning.png', 'class="pictofixedwidth"').' '.$langs->trans("YouHaveXObjectUseSearchOptim", $nb, $langs->transnoentitiesnoconv("ProductsOrServices"), 'PRODUCT_DONOTSEARCH_ANYWHERE'); @@ -653,7 +653,7 @@ if ($resql) { $limitforoptim = 100000; $num = $db->num_rows($resql); $obj = $db->fetch_object($resql); - $nb = $obj->nb; + $nb = (int) $obj->nb; if ($nb > $limitforoptim) { if (!getDolGlobalString('COMPANY_DONOTSEARCH_ANYWHERE')) { print img_picto('', 'warning.png', 'class="pictofixedwidth"').' '.$langs->trans("YouHaveXObjectUseSearchOptim", $nb, $langs->transnoentitiesnoconv("ThirdParties"), 'COMPANY_DONOTSEARCH_ANYWHERE'); diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index fc0137ef334..eada42b6c6e 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -119,7 +119,7 @@ class Propal extends CommonObject /** * Ref from thirdparty - * @var string + * @var ?string */ public $ref_customer; diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index f5b4c19e901..698fdcda7bc 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2375,7 +2375,7 @@ class Commande extends CommonOrder if ($resql) { $obj = $this->db->fetch_object($resql); if ($obj) { - $nb = $obj->nb; + $nb = (int) $obj->nb; } $this->db->free($resql); diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 6374637fcb1..eaf1c0e3501 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -1500,7 +1500,7 @@ class Account extends CommonObject $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); - $nb = $obj->nb; + $nb = (int) $obj->nb; } else { dol_print_error($this->db); } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index ef855d7845e..b6f466a72d5 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -143,7 +143,7 @@ class Facture extends CommonInvoice public $ref_client; /** - * @var string customer ref + * @var ?string customer ref */ public $ref_customer; @@ -467,8 +467,8 @@ class Facture extends CommonInvoice $this->type = self::TYPE_STANDARD; } - $this->ref_client = trim($this->ref_client); // deprecated - $this->ref_customer = trim($this->ref_customer); + $this->ref_client = trim((string) $this->ref_client); // deprecated + $this->ref_customer = trim((string) $this->ref_customer); $this->note_private = (isset($this->note_private) ? trim($this->note_private) : ''); $this->note = (isset($this->note) ? trim($this->note) : $this->note_private); // deprecated diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 01209331438..7e5f14166aa 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -1471,7 +1471,7 @@ class Contact extends CommonObject $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); - $nb = $obj->nb; + $nb = (int) $obj->nb; $this->db->free($resql); return $nb; diff --git a/htdocs/core/boxes/box_produits_alerte_stock.php b/htdocs/core/boxes/box_produits_alerte_stock.php index fc5448fed47..9bf1d094f92 100644 --- a/htdocs/core/boxes/box_produits_alerte_stock.php +++ b/htdocs/core/boxes/box_produits_alerte_stock.php @@ -1,11 +1,11 @@ - * Copyright (C) 2004-2011 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2005-2012 Maxime Kohlhaas - * Copyright (C) 2015-2021 Frédéric France - * Copyright (C) 2015 Juanjo Menent - * Copyright (C) 2024-2025 MDW +/* Copyright (C) 2003 Rodolphe Quiedeville + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2005-2012 Maxime Kohlhaas + * Copyright (C) 2015-2025 Frédéric France + * Copyright (C) 2015 Juanjo Menent + * Copyright (C) 2024-2025 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 26fab7f5286..bca33a09703 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -483,20 +483,20 @@ abstract class CommonObject protected $depr_cond_reglement; // Internal value for deprecation /** - * @var int Delivery address ID + * @var ?int Delivery address ID * @see setDeliveryAddress() * @deprecated */ public $fk_delivery_address; /** - * @var int Shipping method ID + * @var ?int Shipping method ID * @see setShippingMethod() */ public $shipping_method_id; /** - * @var string Shipping method label + * @var ?string Shipping method label * @see setShippingMethod() */ public $shipping_method; diff --git a/htdocs/core/lib/import.lib.php b/htdocs/core/lib/import.lib.php index ed84858103a..469484d8292 100644 --- a/htdocs/core/lib/import.lib.php +++ b/htdocs/core/lib/import.lib.php @@ -3,7 +3,7 @@ * Copyright (C) 2007 Rodolphe Quiedeville * Copyright (C) 2010 Regis Houssin * Copyright (C) 2010 Juanjo Menent - * Copyright (C) 2018-2021 Frédéric France + * Copyright (C) 2018-2025 Frédéric France * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify @@ -23,7 +23,7 @@ /** * \file htdocs/core/lib/import.lib.php - * \brief Ensemble de functions de base pour le module import + * \brief basic set of functions for the import module * \ingroup import */ diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index f32d38767fa..311cc8cca59 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -1,6 +1,6 @@ - * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024-2025 Frédéric France * Copyright (C) 2024-2025 MDW * * This program is free software; you can redistribute it and/or modify @@ -1066,7 +1066,7 @@ function getNbOfImagePublicURLOfObject($object) if ($resql) { $obj = $db->fetch_object($resql); if ($obj) { - $nb = $obj->nb; + $nb = (int) $obj->nb; } } diff --git a/htdocs/core/modules/mailings/modules_mailings.php b/htdocs/core/modules/mailings/modules_mailings.php index 5b789aead0e..c6316114463 100644 --- a/htdocs/core/modules/mailings/modules_mailings.php +++ b/htdocs/core/modules/mailings/modules_mailings.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2024-2025 MDW + * Copyright (C) 2025 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -174,7 +175,7 @@ class MailingTargets // This can't be abstract as it is used for some method $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); - $nb = $obj->nb; + $nb = (int) $obj->nb; $sql = "UPDATE ".$this->db->prefix()."mailing"; $sql .= " SET nbemail = ".((int) $nb)." WHERE rowid = ".((int) $mailing_id); diff --git a/htdocs/delivery/class/delivery.class.php b/htdocs/delivery/class/delivery.class.php index e82ac5bed33..f658f1d1a1e 100644 --- a/htdocs/delivery/class/delivery.class.php +++ b/htdocs/delivery/class/delivery.class.php @@ -85,12 +85,12 @@ class Delivery extends CommonObject public $draft; /** - * @var int thirdparty id + * @var ?int thirdparty id */ public $socid; /** - * @var string ref customer + * @var ?string ref customer */ public $ref_customer; @@ -162,8 +162,8 @@ class Delivery extends CommonObject } $error = 0; - $now = dol_now(); + $this->ref_customer = trim((string) $this->ref_customer); /* Delivery note as draft On positionne en mode draft le bon de livraison */ $this->draft = 1; @@ -411,6 +411,11 @@ class Delivery extends CommonObject dol_syslog(get_class($this)."::valid begin"); + if (!isset($this->socid)) { + dol_syslog(get_class($this)."::can't valid socid not set", LOG_WARNING); + return 0; + } + $this->db->begin(); $error = 0; @@ -429,6 +434,7 @@ class Delivery extends CommonObject // Retrieving the new reference $objMod = new $modName($this->db); '@phan-var-force ModeleNumRefDeliveryOrder $objMod'; + /** @var ModeleNumRefDeliveryOrder $objMod */ $soc = new Societe($this->db); $soc->fetch($this->socid); diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 05b24463507..8551275d894 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -13,7 +13,7 @@ * Copyright (C) 2018 Nicolas ZABOURI * Copyright (C) 2018-2025 Frédéric France * Copyright (C) 2020 Lenin Rivas - * Copyright (C) 2024-2025 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 William Mead * * This program is free software; you can redistribute it and/or modify @@ -93,16 +93,18 @@ class Expedition extends CommonObject /** * @var int ID of user author + * @deprecated use $user_creation_id */ public $user_author_id; /** - * @var int ID of user author + * @var ?int ID of user author + * @deprecated use $user_creation_id */ public $fk_user_author; /** - * @var int + * @var ?int */ public $socid; @@ -114,7 +116,7 @@ class Expedition extends CommonObject public $ref_client; /** - * @var string Customer ref + * @var ?string Customer ref */ public $ref_customer; @@ -124,12 +126,12 @@ class Expedition extends CommonObject public $entrepot_id; /** - * @var string Tracking number + * @var ?string Tracking number */ public $tracking_number; /** - * @var string Tracking url + * @var ?string Tracking url */ public $tracking_url; /** @@ -138,39 +140,39 @@ class Expedition extends CommonObject public $billed; /** - * @var int|string + * @var null|int|string */ public $trueWeight; /** - * @var int + * @var ?int */ public $weight_units; /** - * @var int|string + * @var null|int|string */ public $trueWidth; /** - * @var int + * @var ?int */ public $width_units; /** - * @var int|string + * @var null|int|string */ public $trueHeight; /** - * @var int + * @var ?int */ public $height_units; /** - * @var int|string + * @var null|int|string */ public $trueDepth; /** - * @var int + * @var ?int */ public $depth_units; /** - * @var string A denormalized value + * @var null|string A denormalized value */ public $trueSize; @@ -185,12 +187,12 @@ class Expedition extends CommonObject public $multicurrency_subprice; /** - * @var int|string + * @var null|int|string */ public $size_units; /** - * @var int|string + * @var null|int|string */ public $sizeH; @@ -244,7 +246,7 @@ class Expedition extends CommonObject */ public $meths; /** - * @var array> + * @var array */ public $listmeths; // List of carriers @@ -387,6 +389,7 @@ class Expedition extends CommonObject $obj = new $classname(); '@phan-var-force ModelNumRefExpedition $obj'; + /** @var ModelNumRefExpedition $obj */ $numref = $obj->getNextValue($soc, $this); if ($numref != "") { @@ -416,7 +419,7 @@ class Expedition extends CommonObject $error = 0; // Clean parameters - $this->tracking_number = dol_sanitizeFileName($this->tracking_number); + $this->tracking_number = dol_sanitizeFileName((string) $this->tracking_number); if (empty($this->fk_project)) { $this->fk_project = 0; } @@ -856,17 +859,18 @@ class Expedition extends CommonObject if ($this->db->num_rows($result)) { $obj = $this->db->fetch_object($result); - $this->id = $obj->rowid; - $this->entity = $obj->entity; - $this->ref = $obj->ref; - $this->socid = $obj->socid; + $this->id = (int) $obj->rowid; + $this->entity = $obj->entity; + $this->ref = $obj->ref; + $this->socid = $obj->socid; $this->ref_customer = $obj->ref_customer; - $this->ref_ext = $obj->ref_ext; + $this->ref_ext = $obj->ref_ext; $this->status = $obj->fk_statut; $this->statut = $this->status; // Deprecated $this->signed_status = $obj->signed_status; $this->user_author_id = $obj->fk_user_author; $this->fk_user_author = $obj->fk_user_author; + $this->user_creation_id = $obj->fk_user_author; $this->date_creation = $this->db->jdate($obj->date_creation); $this->date_valid = $this->db->jdate($obj->date_valid); $this->date = $this->db->jdate($obj->date_expedition); // TODO deprecated @@ -968,6 +972,11 @@ class Expedition extends CommonObject return 0; } + if (!isset($this->socid)) { + dol_syslog(get_class($this)."::can't valid socid not set", LOG_WARNING); + return 0; + } + if (!((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'creer')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'shipping_advance', 'validate')))) { $this->error = 'Permission denied'; @@ -987,7 +996,7 @@ class Expedition extends CommonObject $result = $soc->setAsCustomer(); // Define new ref - if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life + if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life $numref = $this->getNextNumRef($soc); } elseif (!empty($this->ref)) { $numref = (string) $this->ref; @@ -1112,22 +1121,18 @@ class Expedition extends CommonObject if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) { if ($this->status == self::STATUS_VALIDATED || $this->status == self::STATUS_CLOSED) { - // Expedition validee + // Expedition validated include_once DOL_DOCUMENT_ROOT.'/delivery/class/delivery.class.php'; $delivery = new Delivery($this->db); $result = $delivery->create_from_sending($user, $this->id); - if ($result > 0) { - return $result; - } else { - $this->error = $delivery->error; - return $result; + if ($result <= 0) { + $this->setErrorsFromObject($delivery); } - } else { - return 0; + return $result; } - } else { - return 0; } + + return 0; } /** @@ -1217,7 +1222,12 @@ class Expedition extends CommonObject if ($product_type == 0 || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { $isavirtualproduct = ($productChildrenNb > 0); // The product is qualified for a check of quantity (must be enough in stock to be added into shipment). - if (!$isavirtualproduct || !getDolGlobalString('PRODUIT_SOUSPRODUITS') || ($isavirtualproduct && !getDolGlobalString('STOCK_EXCLUDE_VIRTUAL_PRODUCTS'))) { // If STOCK_EXCLUDE_VIRTUAL_PRODUCTS is set, we do not manage stock for kits/virtual products. + if ( + !$isavirtualproduct + || !getDolGlobalInt('PRODUIT_SOUSPRODUITS') + || ($isavirtualproduct && !getDolGlobalInt('STOCK_EXCLUDE_VIRTUAL_PRODUCTS')) + ) { + // If STOCK_EXCLUDE_VIRTUAL_PRODUCTS is set, we do not manage stock for kits/virtual products. if ($product->stockable_product == Product::ENABLED_STOCK && $product_stock < $qty) { $langs->load("errors"); $this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref); @@ -1254,7 +1264,7 @@ class Expedition extends CommonObject * * @param array{detail:array,qty:int|float,ix_l:int} $dbatch Array of value (key 'detail' -> Array, key 'qty' total quantity for line, key ix_l : original line index) * @param array $array_options extrafields array - * @param Object $origin_line Origin line (only from OrderLine at this moment) + * @param CommonObjectLine $origin_line Origin line (only from OrderLine at this moment) * @return int Return integer <0 if KO, >0 if OK */ public function addline_batch($dbatch, $array_options = [], $origin_line = null) @@ -1298,8 +1308,6 @@ class Expedition extends CommonObject return -1; } } - - //var_dump($linebatch); } } if (is_object($linebatch)) { @@ -1634,42 +1642,37 @@ class Expedition extends CommonObject $this->fetch_origin(); $origin_object = $this->origin_object; '@phan-var-force Facture|Commande $origin_object'; + /** @var Commande $origin_object */ if ($origin_object->status == Commande::STATUS_SHIPMENTONPROCESS) { // If order source of shipment is "shipment in progress" // Check if there is no more shipment. If not, we can move back status of order to "validated" instead of "shipment in progress" $origin_object->loadExpeditions(); - //var_dump($this->$origin->expeditions);exit; if (count($origin_object->expeditions) <= 0) { $origin_object->setStatut(Commande::STATUS_VALIDATED); } } } - if (!$error) { - $this->db->commit(); + $this->db->commit(); - // We delete PDFs - $ref = dol_sanitizeFileName($this->ref); - if (!empty($conf->expedition->dir_output)) { - $dir = $conf->expedition->dir_output.'/sending/'.$ref; - $file = $dir.'/'.$ref.'.pdf'; - if (file_exists($file)) { - if (!dol_delete_file($file)) { - return 0; - } - } - if (file_exists($dir)) { - if (!dol_delete_dir_recursive($dir)) { - $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir); - return 0; - } + // We delete PDFs + $ref = dol_sanitizeFileName($this->ref); + if (!empty($conf->expedition->dir_output)) { + $dir = $conf->expedition->dir_output.'/sending/'.$ref; + $file = $dir.'/'.$ref.'.pdf'; + if (file_exists($file)) { + if (!dol_delete_file($file)) { + return 0; + } + } + if (file_exists($dir)) { + if (!dol_delete_dir_recursive($dir)) { + $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir); + return 0; } } - - return 1; - } else { - $this->db->rollback(); - return -1; } + + return 1; } else { $this->error = $this->db->lasterror()." - sql=$sql"; $this->db->rollback(); @@ -1855,43 +1858,37 @@ class Expedition extends CommonObject if ($origin_object->status == Commande::STATUS_SHIPMENTONPROCESS) { // If order source of shipment is "shipment in progress" // Check if there is no more shipment. If not, we can move back status of order to "validated" instead of "shipment in progress" $origin_object->loadExpeditions(); - //var_dump($this->$origin->expeditions);exit; if (count($origin_object->expeditions) <= 0) { $origin_object->setStatut(Commande::STATUS_VALIDATED); } } } - if (!$error) { - $this->db->commit(); + $this->db->commit(); - // Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive - $this->deleteEcmFiles(0); // Deleting files physically is done later with the dol_delete_dir_recursive - $this->deleteEcmFiles(1); // Deleting files physically is done later with the dol_delete_dir_recursive + // Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive + $this->deleteEcmFiles(0); // Deleting files physically is done later with the dol_delete_dir_recursive + $this->deleteEcmFiles(1); // Deleting files physically is done later with the dol_delete_dir_recursive - // We delete PDFs - $ref = dol_sanitizeFileName($this->ref); - if (!empty($conf->expedition->dir_output)) { - $dir = $conf->expedition->dir_output . '/sending/' . $ref; - $file = $dir . '/' . $ref . '.pdf'; - if (file_exists($file)) { - if (!dol_delete_file($file)) { - return 0; - } - } - if (file_exists($dir)) { - if (!dol_delete_dir_recursive($dir)) { - $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir); - return 0; - } + // We delete PDFs + $ref = dol_sanitizeFileName($this->ref); + if (!empty($conf->expedition->dir_output)) { + $dir = $conf->expedition->dir_output . '/sending/' . $ref; + $file = $dir . '/' . $ref . '.pdf'; + if (file_exists($file)) { + if (!dol_delete_file($file)) { + return 0; + } + } + if (file_exists($dir)) { + if (!dol_delete_dir_recursive($dir)) { + $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir); + return 0; } } - - return 1; - } else { - $this->db->rollback(); - return -1; } + + return 1; } else { $this->error = $this->db->lasterror()." - sql=$sql"; $this->db->rollback(); @@ -2130,10 +2127,10 @@ class Expedition extends CommonObject $lineindex++; } else { $line->total_ht += $tabprice[0]; - $line->total_localtax1 += $tabprice[9]; - $line->total_localtax2 += $tabprice[10]; - $line->total_ttc += $tabprice[2]; - $line->total_tva += $tabprice[1]; + $line->total_localtax1 += $tabprice[9]; + $line->total_localtax2 += $tabprice[10]; + $line->total_ttc += $tabprice[2]; + $line->total_tva += $tabprice[1]; } $i++; @@ -2361,19 +2358,13 @@ class Expedition extends CommonObject $return .= img_picto('', 'order'); $return .= ''; $return .= '
'; - $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).''; + $return .= '' . $this->getNomUrl() . ''; if ($selected >= 0) { $return .= ''; } - if (property_exists($this, 'thirdparty') && is_object($this->thirdparty)) { - $return .= '
'.$this->thirdparty->getNomUrl(1).'
'; - } - if (property_exists($this, 'total_ht')) { - $return .= '
'.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency).' '.$langs->trans('HT').'
'; - } - if (method_exists($this, 'getLibStatut')) { - $return .= '
'.$this->getLibStatut(3).'
'; - } + $return .= '
'.$this->thirdparty->getNomUrl(1).'
'; + $return .= '
'.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency).' '.$langs->trans('HT').'
'; + $return .= '
'.$this->getLibStatut(3).'
'; $return .= '
'; $return .= ''; $return .= ''; @@ -2404,7 +2395,7 @@ class Expedition extends CommonObject $this->ref = 'SPECIMEN'; $this->specimen = 1; $this->status = self::STATUS_VALIDATED; - $this->livraison_id = 0; + $this->livraison_id = 0; $this->date = $now; $this->date_creation = $now; $this->date_valid = $now; @@ -2529,7 +2520,7 @@ class Expedition extends CommonObject { // phpcs:enable global $langs; - $this->meths = array(); + $this->meths = []; $sql = "SELECT em.rowid, em.code, em.libelle as label"; $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em"; @@ -2540,7 +2531,7 @@ class Expedition extends CommonObject if ($resql) { while ($obj = $this->db->fetch_object($resql)) { $label = $langs->trans('SendingMethod'.$obj->code); - $this->meths[$obj->rowid] = ($label != 'SendingMethod'.$obj->code ? $label : $obj->label); + $this->meths[(int) $obj->rowid] = ($label != 'SendingMethod'.$obj->code ? $label : $obj->label); } } } @@ -2557,7 +2548,7 @@ class Expedition extends CommonObject // phpcs:enable global $langs; - $this->listmeths = array(); + $this->listmeths = []; $i = 0; $sql = "SELECT em.rowid, em.code, em.libelle as label, em.description, em.tracking, em.active"; @@ -2569,13 +2560,15 @@ class Expedition extends CommonObject $resql = $this->db->query($sql); if ($resql) { while ($obj = $this->db->fetch_object($resql)) { - $this->listmeths[$i]['rowid'] = $obj->rowid; - $this->listmeths[$i]['code'] = $obj->code; $label = $langs->trans('SendingMethod'.$obj->code); - $this->listmeths[$i]['libelle'] = ($label != 'SendingMethod'.$obj->code ? $label : $obj->label); - $this->listmeths[$i]['description'] = $obj->description; - $this->listmeths[$i]['tracking'] = $obj->tracking; - $this->listmeths[$i]['active'] = $obj->active; + $this->listmeths[$i]= [ + 'rowid' => (int) $obj->rowid, + 'code' => $obj->code, + 'libelle' => ($label != 'SendingMethod'.$obj->code ? $label : $obj->label), + 'description' => $obj->description, + 'tracking' => $obj->tracking, + 'active' => (int) $obj->active, + ]; $i++; } } @@ -2589,6 +2582,7 @@ class Expedition extends CommonObject */ public function getUrlTrackingStatus($value = '') { + $tracking = ''; if (!empty($this->shipping_method_id)) { $sql = "SELECT em.code, em.tracking"; $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em"; @@ -2597,14 +2591,14 @@ class Expedition extends CommonObject $resql = $this->db->query($sql); if ($resql) { if ($obj = $this->db->fetch_object($resql)) { - $tracking = $obj->tracking; + $tracking = (string) $obj->tracking; } } } if (!empty($tracking) && !empty($value)) { $url = str_replace('{TRACKID}', $value, $tracking); - $this->tracking_url = sprintf('%s', $url, ($value ? $value : 'url')); + $this->tracking_url = sprintf('%s', $url, $value); } else { $this->tracking_url = $value; } @@ -2665,7 +2659,7 @@ class Expedition extends CommonObject $this->status = self::STATUS_CLOSED; // Will be revert to STATUS_VALIDATED at end if there is a rollback // If stock increment is done on closing - if (!$error && isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) { + if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) { $result = $this->manageStockMvtOnEvt($user); if ($result < 0) { $error++; @@ -2754,8 +2748,7 @@ class Expedition extends CommonObject // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans($labelmovement, $obj->ref)); if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; + $this->setErrorsFromObject($mouvS); $error++; break; } @@ -2765,8 +2758,7 @@ class Expedition extends CommonObject // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans($labelmovement, $obj->ref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock); if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; + $this->setErrorsFromObject($mouvS); $error++; break; } @@ -2877,7 +2869,7 @@ class Expedition extends CommonObject $this->billed = 0; // If stock increment is done on closing - if (!$error && isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) { + if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; $langs->load("agenda"); @@ -2920,8 +2912,7 @@ class Expedition extends CommonObject // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr", $this->ref)); if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; + $this->setErrorsFromObject($mouvS); $error++; break; } @@ -2931,8 +2922,7 @@ class Expedition extends CommonObject // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr", $this->ref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock); if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; + $this->setErrorsFromObject($mouvS); $error++; break; } diff --git a/htdocs/expedition/class/expeditionligne.class.php b/htdocs/expedition/class/expeditionligne.class.php index 4515ec51c9e..9473da3f50e 100644 --- a/htdocs/expedition/class/expeditionligne.class.php +++ b/htdocs/expedition/class/expeditionligne.class.php @@ -138,7 +138,7 @@ class ExpeditionLigne extends CommonObjectLine /** * Detail of lot and qty = array(id in llx_expeditiondet_batch, fk_expeditiondet, batch, qty, fk_origin_stock) * We can use this to know warehouse planned to be used for each lot. - * @var stdClass|ExpeditionLineBatch[] + * @var null|stdClass|ExpeditionLineBatch[] */ public $detail_batch; diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index ba70f69fbad..24e5228c90a 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1796,7 +1796,7 @@ if ($dirins && ($action == 'droptable' || $action == 'droptableextrafields') && if ($resql) { $obj = $db->fetch_object($resql); if ($obj) { - $nb = $obj->nb; + $nb = (int) $obj->nb; } } else { if ($db->lasterrno() == 'DB_ERROR_NOSUCHTABLE') { diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index f142db94b15..ada2a2015e2 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5510,7 +5510,7 @@ class Product extends CommonObject if ($resql) { $obj = $this->db->fetch_object($resql); if ($obj) { - $nb = $obj->nb; + $nb = (int) $obj->nb; } } else { return -1; @@ -5534,7 +5534,7 @@ class Product extends CommonObject if ($resql) { $obj = $this->db->fetch_object($resql); if ($obj) { - $nb = $obj->nb; + $nb = (int) $obj->nb; } } @@ -6161,8 +6161,7 @@ class Product extends CommonObject $this->db->commit(); return 1; } else { - $this->error = $movementstock->error; - $this->errors = $movementstock->errors; + $this->setErrorsFromObject($movementstock); $this->db->rollback(); return -1; diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index e4ea806ac00..87bf62f66dc 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -912,7 +912,7 @@ class MouvementStock extends CommonObject if ($resql) { $obj = $this->db->fetch_object($resql); if ($obj) { - $nb = $obj->nb; + $nb = (int) $obj->nb; } return (empty($nb) ? 0 : $nb); } else { diff --git a/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php b/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php index 522d34976bf..997f5749134 100644 --- a/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php +++ b/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php @@ -72,7 +72,7 @@ class StockTransfer extends CommonObject public $ref_client; /** - * @var string Customer ref + * @var ?string Customer ref */ public $ref_customer; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index c2227c9afdf..7dfb682704f 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -4535,7 +4535,7 @@ class Societe extends CommonObject $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); - $nb = $obj->nb; + $nb = (int) $obj->nb; $this->db->free($resql); return $nb; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 9f1b0759685..eb97b2f8199 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -3700,7 +3700,7 @@ class User extends CommonObject $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); - $nb = $obj->nb; + $nb = (int) $obj->nb; $this->db->free($resql); return $nb; diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index 25226a0746c..3765b20ef82 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -360,7 +360,7 @@ class ProductCombination if ($resql) { $obj = $this->db->fetch_object($resql); if ($obj) { - $nb = $obj->nb; + $nb = (int) $obj->nb; } }