From e7ddb684e0c1b2299bae70e1bbbc65dec0d85257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 21 Sep 2025 12:12:09 +0200 Subject: [PATCH] clean code (#35387) * clean code * clean code * clean code * clean code * clean code * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix --------- Co-authored-by: Laurent Destailleur --- dev/build/phpstan/phpstan-baseline.neon | 132 ------------------ .../class/accountingaccount.class.php | 6 +- htdocs/core/class/commonobject.class.php | 2 +- htdocs/core/class/html.form.class.php | 39 ++++-- htdocs/core/tpl/originproductline.tpl.php | 10 +- htdocs/mrp/class/mo.class.php | 4 +- htdocs/mrp/class/moline.class.php | 2 +- htdocs/mrp/tpl/originproductline.tpl.php | 26 ++-- htdocs/product/class/product.class.php | 109 +++++++-------- .../class/price_parser.class.php | 11 +- 10 files changed, 112 insertions(+), 229 deletions(-) diff --git a/dev/build/phpstan/phpstan-baseline.neon b/dev/build/phpstan/phpstan-baseline.neon index 2681da54435..975e4c02cb3 100644 --- a/dev/build/phpstan/phpstan-baseline.neon +++ b/dev/build/phpstan/phpstan-baseline.neon @@ -13872,138 +13872,6 @@ parameters: count: 1 path: ../../../htdocs/product/class/html.formproduct.class.php - - - message: '#^Call to function method_exists\(\) with \$this\(Product\) and ''getLibStatut'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Call to function method_exists\(\) with \$this\(Product\) and ''getNomUrl'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Call to function property_exists\(\) with \$this\(Product\) and ''label'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Call to function property_exists\(\) with \$this\(Product\) and ''price'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Call to function property_exists\(\) with \$this\(Product\) and ''price_ttc'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Call to function property_exists\(\) with \$this\(Product\) and ''stock_reel'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Comparison operation "\>\=" between 0 and 0 is always true\.$#' - identifier: greaterOrEqual.alwaysTrue - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Loose comparison using \=\= between 1 and 1 will always evaluate to true\.$#' - identifier: equal.alwaysTrue - count: 2 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Method Product\:\:_get_stats\(\) should return \-1\|array\, array\\> but returns non\-empty\-array\, array\{string, \(float\|int\)\}\>\.$#' - identifier: return.type - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Negated boolean expression is always false\.$#' - identifier: booleanNot.alwaysFalse - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Property Product\:\:\$accountancy_code_buy \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Property Product\:\:\$accountancy_code_sell \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Property Product\:\:\$desiredstock \(float\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Property Product\:\:\$fk_default_bom \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Property Product\:\:\$seuil_stock_alerte \(float\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Property Product\:\:\$sousprods \(array\\>\>\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Property Product\:\:\$status \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Property Product\:\:\$status_buy \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Result of && is always true\.$#' - identifier: booleanAnd.alwaysTrue - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Right side of && is always true\.$#' - identifier: booleanAnd.rightAlwaysTrue - count: 1 - path: ../../../htdocs/product/class/product.class.php - - - - message: '#^Ternary operator condition is always false\.$#' - identifier: ternary.alwaysFalse - count: 2 - path: ../../../htdocs/product/class/product.class.php - - message: '#^Negated boolean expression is always true\.$#' identifier: booleanNot.alwaysTrue diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index 6f519987532..90c20ecb4e3 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -735,7 +735,7 @@ class AccountingAccount extends CommonObject * @param FactureLigne|SupplierInvoiceLine $factureDet Facture Det * @param array $accountingAccount Array of Accounting account * @param string $type Customer / Supplier - * @return array{suggestedaccountingaccountbydefaultfor:string,suggestedaccountingaccountfor:string,suggestedid:?int,code_l:string,code_p:string,code_t:string}|int<-1,-1> Array of accounting accounts suggested or < 0 if technical error. + * @return array{suggestedaccountingaccountbydefaultfor:''|'eec'|'eecwithoutvatnumber'|'eecwithvat'|'export',suggestedaccountingaccountfor:'deposit'|'eec'|'eecwithoutvatnumber'|'eecwithvat'|'export'|'prodserv'|'thirdparty',suggestedid:?int,code_l:string,code_p:?string,code_t:string}|int<-1,-1> Array of accounting accounts suggested or < 0 if technical error. * 'suggestedaccountingaccountbydefaultfor'=>Will be used for the label to show on tooltip for account by default on any product * 'suggestedaccountingaccountfor'=>Is the account suggested for this product */ @@ -890,7 +890,7 @@ class AccountingAccount extends CommonObject $code_l = (string) $accountdeposittoventilated->ref; $code_p = ''; $code_t = ''; - $suggestedid = $accountdeposittoventilated->rowid; + $suggestedid = (int) $accountdeposittoventilated->rowid; $suggestedaccountingaccountfor = 'deposit'; } @@ -909,7 +909,7 @@ class AccountingAccount extends CommonObject $code_l = (string) $accountdeposittoventilated->ref; $code_p = ''; $code_t = ''; - $suggestedid = $accountdeposittoventilated->rowid; + $suggestedid = (int) $accountdeposittoventilated->rowid; $suggestedaccountingaccountfor = 'deposit'; } } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 956818e15a9..c069efdf8f6 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -806,7 +806,7 @@ abstract class CommonObject public $labelStatusShort = array(); /** - * @var array Array to store lists of tpl + * @var array Array to store lists of tpl */ public $tpl; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index c0405821f13..bb0034064ec 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -105,19 +105,38 @@ class Form * Return an array of Duration Types * * @param Translate $langs Translation to be used + * @param bool $plurial return plurial or singular + * @param bool $reverse change order of duration types * @return array{y:string,m:string,w:string,d:string,h:string,i:string,s:string} Types of durations */ - public function getDurationTypes(Translate $langs) + public function getDurationTypes(Translate $langs, $plurial = true, $reverse = false) { - return [ - 'y' => $langs->trans('Years'), - 'm' => $langs->trans('Month'), - 'w' => $langs->trans('Weeks'), - 'd' => $langs->trans('Days'), - 'h' => $langs->trans('Hours'), - 'i' => $langs->trans('Minutes'), - 's' => $langs->trans('Seconds'), - ]; + if ($plurial) { + $arrayoftypes = [ + 'y' => $langs->trans('Years'), + 'm' => $langs->trans('Month'), + 'w' => $langs->trans('Weeks'), + 'd' => $langs->trans('Days'), + 'h' => $langs->trans('Hours'), + 'i' => $langs->trans('Minutes'), + 's' => $langs->trans('Seconds'), + ]; + } else { + $arrayoftypes = [ + "y" => $langs->trans("Year"), + "m" => $langs->trans("Month"), + "w" => $langs->trans("Week"), + "d" => $langs->trans("Day"), + "h" => $langs->trans("Hour"), + "i" => $langs->trans("Minute"), + 's' => $langs->trans('Second'), + ]; + } + if ($reverse) { + return array_reverse($arrayoftypes); + } else { + return $arrayoftypes; + } } /** diff --git a/htdocs/core/tpl/originproductline.tpl.php b/htdocs/core/tpl/originproductline.tpl.php index ac06df48160..f49d79d4593 100644 --- a/htdocs/core/tpl/originproductline.tpl.php +++ b/htdocs/core/tpl/originproductline.tpl.php @@ -1,8 +1,8 @@ - * Copyright (C) 2017 Charlie Benke - * Copyright (C) 2022 Gauthier VERDOL - * Copyright (C) 2024 Frédéric France +/* Copyright (C) 2010-2012 Regis Houssin + * Copyright (C) 2017 Charlie Benke + * Copyright (C) 2022 Gauthier VERDOL + * Copyright (C) 2024-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 @@ -63,7 +63,7 @@ if (isModEnabled("multicurrency")) { print ''.$this->tpl['qty'].''; if (getDolGlobalString('PRODUCT_USE_UNITS')) { - print ''.$langs->trans($this->tpl['unit']).''; + print ''.$langs->trans((string) $this->tpl['unit']).''; } print ''.$this->tpl['remise_percent'].''; diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index 4e2e91c2454..e42fdf61f25 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -264,7 +264,7 @@ class Mo extends CommonObject public $fk_parent_line; /** - * @ var array{id:int,label:string,qty_bom:int|float,stock:float,seuil_stock_alerte:float,virtual_stock:float,qty:float,fk_unit:int,qty_frozen:float,disable_stock_change:int<0,1>,efficiency:float} tpl + * @var array{}|array{id:int,label:string,qty_bom:int|float,stock:float,seuil_stock_alerte:null|float,virtual_stock:float,qty:float,fk_unit:int,qty_frozen:int<0,1>,disable_stock_change:int<0,1>,efficiency:float} tpl */ public $tpl = array(); @@ -1836,7 +1836,7 @@ class Mo extends CommonObject global $conf; // used into template - $res = include DOL_DOCUMENT_ROOT.'/mrp/tpl/originproductline.tpl.php'; + include DOL_DOCUMENT_ROOT.'/mrp/tpl/originproductline.tpl.php'; } /** diff --git a/htdocs/mrp/class/moline.class.php b/htdocs/mrp/class/moline.class.php index be6d209312e..8a8bb8b40d0 100644 --- a/htdocs/mrp/class/moline.class.php +++ b/htdocs/mrp/class/moline.class.php @@ -151,7 +151,7 @@ class MoLine extends CommonObjectLine public $qty; /** - * @var float Quantity frozen + * @var int<0,1> Is quantity frozen */ public $qty_frozen; /** diff --git a/htdocs/mrp/tpl/originproductline.tpl.php b/htdocs/mrp/tpl/originproductline.tpl.php index 1fae83d4fe1..4352dc77cfc 100644 --- a/htdocs/mrp/tpl/originproductline.tpl.php +++ b/htdocs/mrp/tpl/originproductline.tpl.php @@ -1,8 +1,8 @@ - * Copyright (C) 2017 Charlie Benke - * Copyright (C) 2024-2025 MDW - * Copyright (C) 2024 Frédéric France +/* Copyright (C) 2010-2012 Regis Houssin + * Copyright (C) 2017 Charlie Benke + * Copyright (C) 2024-2025 MDW + * Copyright (C) 2024-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 @@ -19,15 +19,17 @@ */ /** - * @var CommonObject $this + * @var DoliDB $db + * @var Mo $this * @var Conf $conf * @var Form $form - * @var BOMLine $line + * @var MoLine $line * @var Translate $langs */ ' -@phan-var-force BOMLine $line +@phan-var-force MoLine $line +@phan-var-force Mo $this '; // Protection to avoid direct call of template @@ -36,12 +38,8 @@ if (empty($conf) || !is_object($conf)) { exit(1); } -'@phan-var-force CommonObject $this'; - global $db, $langs; -/** @var DoliDB $db */ - if (empty($form) || !is_object($form)) { $form = new Form($db); } @@ -83,14 +81,14 @@ if ($res) { } print ''; // Qty -print ''.$this->tpl['qty'].(($this->tpl['efficiency'] > 0 && $this->tpl['efficiency'] < 1) ? ' / '.$form->textwithpicto($this->tpl['efficiency'], $langs->trans("ValueOfMeansLoss")).' = '.$qtytoconsumeforline : '').''; +print ''.$this->tpl['qty'].((isset($this->tpl['efficiency']) && $this->tpl['efficiency'] > 0 && $this->tpl['efficiency'] < 1) ? (' / '.$form->textwithpicto((string) $this->tpl['efficiency'], $langs->trans("ValueOfMeansLoss")).' = '.$qtytoconsumeforline) : '').''; // Unit print ''.measuringUnitString($this->tpl['fk_unit'], '', null, 1).''; // Stock print ''; if ($tmpproduct->isStockManaged()) { print(empty($this->tpl['stock']) ? 0 : price2num($this->tpl['stock'], 'MS')); - if ($this->tpl['seuil_stock_alerte'] != '' && ($this->tpl['stock'] < $this->tpl['seuil_stock_alerte'])) { + if (isset($this->tpl['seuil_stock_alerte']) && $this->tpl['seuil_stock_alerte'] != '' && ($this->tpl['stock'] < $this->tpl['seuil_stock_alerte'])) { print ' '.img_warning($langs->trans("StockLowerThanLimit", $this->tpl['seuil_stock_alerte'])); } } @@ -98,7 +96,7 @@ print ''; print ''; if ($tmpproduct->isStockManaged()) { print((empty($this->tpl['virtual_stock']) ? 0 : price2num($this->tpl['virtual_stock'], 'MS'))); - if ($this->tpl['seuil_stock_alerte'] != '' && ($this->tpl['virtual_stock'] < $this->tpl['seuil_stock_alerte'])) { + if (isset($this->tpl['seuil_stock_alerte']) && $this->tpl['seuil_stock_alerte'] != '' && ($this->tpl['virtual_stock'] < $this->tpl['seuil_stock_alerte'])) { print ' '.img_warning($langs->trans("StockLowerThanLimit", $this->tpl['seuil_stock_alerte'])); } } diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 7a58f5f7a87..c7fb45d999d 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -383,12 +383,12 @@ class Product extends CommonObject /** * Stock alert * - * @var float + * @var ?float */ public $seuil_stock_alerte = 0; /** - * @var float Ask for replenishment when `$desiredstock` < `$stock_reel` + * @var ?float Ask for replenishment when `$desiredstock` < `$stock_reel` */ public $desiredstock = 0; @@ -413,13 +413,13 @@ class Product extends CommonObject /** * Status indicates whether the product is on sale '1' or not '0' * - * @var int + * @var ?int */ public $status = 0; /** * Status indicates whether the product is on sale '1' or not '0' - * @var int + * @var ?int * @deprecated Use $status instead * @see $status */ @@ -428,13 +428,13 @@ class Product extends CommonObject /** * Status indicate whether the product is available for purchase '1' or not '0' * - * @var int + * @var ?int */ public $status_buy = 0; /** * Status indicate whether the product is available for purchase '1' or not '0' - * @var int + * @var ?int * @deprecated Use $status_buy instead * @see $status_buy */ @@ -450,7 +450,7 @@ class Product extends CommonObject /** * fk_default_bom indicates the default bom * - * @var int + * @var ?int */ public $fk_default_bom; @@ -572,27 +572,27 @@ class Product extends CommonObject public $net_measure_units; // scale -3, 0, 3, 6 /** - * @var string + * @var ?string */ public $accountancy_code_sell; /** - * @var string + * @var ?string */ public $accountancy_code_sell_intra; /** - * @var string + * @var ?string */ public $accountancy_code_sell_export; /** - * @var string + * @var ?string */ public $accountancy_code_buy; /** - * @var string + * @var ?string */ public $accountancy_code_buy_intra; /** - * @var string + * @var ?string */ public $accountancy_code_buy_export; @@ -787,7 +787,7 @@ class Product extends CommonObject /** * Array with list of sub-products for Kits * - * @var array> + * @var null|array> */ public $sousprods = array(); @@ -1047,12 +1047,12 @@ class Product extends CommonObject $price_min_ttc = price2num($this->price_min * (1 + ($this->tva_tx / 100)), 'MU'); } - $this->accountancy_code_buy = trim($this->accountancy_code_buy); - $this->accountancy_code_buy_intra = trim($this->accountancy_code_buy_intra); - $this->accountancy_code_buy_export = trim($this->accountancy_code_buy_export); - $this->accountancy_code_sell = trim($this->accountancy_code_sell); - $this->accountancy_code_sell_intra = trim($this->accountancy_code_sell_intra); - $this->accountancy_code_sell_export = trim($this->accountancy_code_sell_export); + $this->accountancy_code_buy = trim((string) $this->accountancy_code_buy); + $this->accountancy_code_buy_intra = trim((string) $this->accountancy_code_buy_intra); + $this->accountancy_code_buy_export = trim((string) $this->accountancy_code_buy_export); + $this->accountancy_code_sell = trim((string) $this->accountancy_code_sell); + $this->accountancy_code_sell_intra = trim((string) $this->accountancy_code_sell_intra); + $this->accountancy_code_sell_export = trim((string) $this->accountancy_code_sell_export); // Barcode value $this->barcode = trim($this->barcode); @@ -1834,7 +1834,7 @@ class Product extends CommonObject if (empty($objectisused)) { $this->db->begin(); - if (!$error && empty($notrigger)) { + if (empty($notrigger)) { // Call trigger $result = $this->call_trigger('PRODUCT_DELETE', $user); if ($result < 0) { @@ -2655,7 +2655,7 @@ class Product extends CommonObject include_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; $priceparser = new PriceParser($this->db); $price_result = $priceparser->parseProductSupplier($prod_supplier); - if ($result >= 0) { + if ($price_result >= 0) { $obj->price = $price_result; } } @@ -3028,9 +3028,10 @@ class Product extends CommonObject $sql .= " p.datec, p.tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.sell_or_eat_by_mandatory, p.batch_mask, p.fk_unit,"; $sql .= " p.fk_price_expression, p.price_autogen, p.stockable_product, p.model_pdf,"; $sql .= " p.price_label"; - if (!$separatedStock) { - $sql .= ", p.stock"; - } + // can't be false TODO fix + // if (!$separatedStock) { + // $sql .= ", p.stock"; + // } } $resql = $this->db->query($sql); @@ -4380,7 +4381,7 @@ class Product extends CommonObject * @param string $sql Request to execute * @param string $mode 'byunit'=number of unit, 'bynumber'=nb of entities * @param int $year Year (0=current year, -1=all years) - * @return array,array>|int<-1,-1> Return integer <0 if KO, result[month]=array(valuex,valuey) where month is 0 to 11 + * @return array,array>|int<-1,-1> Return integer <0 if KO, result[month]=array(valuex,valuey) where month is 0 to 11 */ private function _get_stats($sql, $mode, $year = 0) { @@ -4430,12 +4431,12 @@ class Product extends CommonObject $result = array(); for ($j = 0; $j < 12; $j++) { - // $ids is 'D', 'N', 'O', 'S', ... (First letter of month in user language) + // $idx is 'D', 'N', 'O', 'S', ... (First letter of month in user language) $idx = ucfirst(dol_trunc(dol_print_date(dol_mktime(12, 0, 0, $month, 1, 1970), "%b"), 1, 'right', 'UTF-8', 1)); - //print $idx.'-'.$year.'-'.$month.'
'; + // print $idx.'-'.$year.'-'.$month.'
'; $result[$j] = array($idx, isset($tab[$year.$month]) ? $tab[$year.$month] : 0); - // $result[$j] = array($monthnum,isset($tab[$year.$month])?$tab[$year.$month]:0); + // $result[$j] = array($monthnum,isset($tab[$year.$month])?$tab[$year.$month]:0); $month = "0".($month - 1); if (dol_strlen($month) == 3) { @@ -4884,9 +4885,9 @@ class Product extends CommonObject */ public function add_sousproduit($id_pere, $id_fils, $qty, $incdec = 1, $notrigger = 0) { + // phpcs:enable global $user; - // phpcs:enable // Clean parameters if (!is_numeric($id_pere)) { $id_pere = 0; @@ -4957,9 +4958,9 @@ class Product extends CommonObject */ public function update_sousproduit($id_pere, $id_fils, $qty, $incdec = 1, $notrigger = 0) { + // phpcs:enable global $user; - // phpcs:enable // Clean parameters if (!is_numeric($id_pere)) { $id_pere = 0; @@ -5009,9 +5010,9 @@ class Product extends CommonObject */ public function del_sousproduit($fk_parent, $fk_child, $notrigger = 0) { + // phpcs:enable global $user; - // phpcs:enable if (!is_numeric($fk_parent)) { $fk_parent = 0; } @@ -5242,6 +5243,7 @@ class Product extends CommonObject */ public function clone_price($fromId, $toId) { + // phpcs:enable global $user; $now = dol_now(); @@ -5778,7 +5780,7 @@ class Product extends CommonObject } $labelsize = ""; if ($this->length) { - $labelsize .= ($labelsize ? " - " : "")."".$langs->trans("Length").': '.$this->length.' '.measuringUnitString(0, 'size', $this->length_units); + $labelsize .= "".$langs->trans("Length").': '.$this->length.' '.measuringUnitString(0, 'size', $this->length_units); } if ($this->width) { $labelsize .= ($labelsize ? " - " : "")."".$langs->trans("Width").': '.$this->width.' '.measuringUnitString(0, 'size', $this->width_units); @@ -5792,7 +5794,7 @@ class Product extends CommonObject $labelsurfacevolume = ""; if ($this->surface) { - $labelsurfacevolume .= ($labelsurfacevolume ? " - " : "")."".$langs->trans("Surface").': '.$this->surface.' '.measuringUnitString(0, 'surface', $this->surface_units); + $labelsurfacevolume .= "".$langs->trans("Surface").': '.$this->surface.' '.measuringUnitString(0, 'surface', $this->surface_units); } if ($this->volume) { $labelsurfacevolume .= ($labelsurfacevolume ? " - " : "")."".$langs->trans("Volume").': '.$this->volume.' '.measuringUnitString(0, 'volume', $this->volume_units); @@ -5812,7 +5814,7 @@ class Product extends CommonObject $datas['duration'] .= (!empty($this->duration_unit) && isset($dur[$this->duration_unit]) ? " ".$langs->trans($dur[$this->duration_unit]) : ''); } if (empty($user->socid)) { - if (!empty($this->pmp) && $this->pmp) { + if (isset($this->pmp) && $this->pmp) { $datas['pmp'] = "
".$langs->trans("PMPValue").': '.price($this->pmp, 0, '', 1, -1, -1, $conf->currency); } @@ -6009,7 +6011,7 @@ class Product extends CommonObject /** * Return label of a given status * - * @param int $status Statut + * @param int $status Status * @param int<0,6> $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto * @param int<0,2> $type 0=Status "to sell", 1=Status "to buy", 2=Status "to Batch" * @return string Label of status @@ -6070,8 +6072,8 @@ class Product extends CommonObject $labelStatus = $langs->transnoentitiesnoconv('ProductStatusOnBuyShort'); $labelStatusShort = $langs->transnoentitiesnoconv('ProductStatusOnBuy'); } elseif ($type == 2) { - $labelStatus = ($status == 1 ? $langs->transnoentitiesnoconv('ProductStatusOnBatch') : $langs->transnoentitiesnoconv('ProductStatusOnSerial')); - $labelStatusShort = ($status == 1 ? $langs->transnoentitiesnoconv('ProductStatusOnBatchShort') : $langs->transnoentitiesnoconv('ProductStatusOnSerialShort')); + $labelStatus = $langs->transnoentitiesnoconv('ProductStatusOnBatch'); + $labelStatusShort = $langs->transnoentitiesnoconv('ProductStatusOnBatchShort'); } } elseif ($type == 2 && $status == 2) { $labelStatus = $langs->transnoentitiesnoconv('ProductStatusOnSerial'); @@ -7250,33 +7252,28 @@ class Product extends CommonObject } $return .= ''; $return .= '
'; - $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).''; + $return .= '' . $this->getNomUrl() . ''; if ($selected >= 0) { $return .= ''; } - if (property_exists($this, 'label')) { - $return .= '
'.dol_escape_htmltag($this->label).''; - } - if (property_exists($this, 'price') && property_exists($this, 'price_ttc')) { - if ($this->price_base_type == 'TTC') { - $return .= '
'.price($this->price_ttc).' '.$langs->trans("TTC").''; - } else { - if ($this->status) { - $return .= '
'.price($this->price).' '.$langs->trans("HT").''; - } + $return .= '
'.dol_escape_htmltag($this->label).''; + if ($this->price_base_type == 'TTC') { + $return .= '
'.price($this->price_ttc).' '.$langs->trans("TTC").''; + } else { + if ($this->status) { + $return .= '
'.price($this->price).' '.$langs->trans("HT").''; } } $br = 1; - if (property_exists($this, 'stock_reel') && $this->isProduct()) { + if ($this->isProduct()) { $return .= '
'.img_picto($langs->trans('PhysicalStock'), 'stock').'
'.$this->stock_reel.'
'; $br = 0; } - if (method_exists($this, 'getLibStatut')) { - if ($br) { - $return .= '
'.$this->getLibStatut(3, 1).' '.$this->getLibStatut(3, 0).'
'; - } else { - $return .= '
'.$this->getLibStatut(3, 1).' '.$this->getLibStatut(3, 0).'
'; - } + if ($br) { + $return .= '
'; + $return .= '
'.$this->getLibStatut(3, 1).' '.$this->getLibStatut(3, 0).'
'; + } else { + $return .= '
'.$this->getLibStatut(3, 1).' '.$this->getLibStatut(3, 0).'
'; } $return .= '
'; $return .= ''; diff --git a/htdocs/product/dynamic_price/class/price_parser.class.php b/htdocs/product/dynamic_price/class/price_parser.class.php index 9aa6a91d7c0..d5e714439f4 100644 --- a/htdocs/product/dynamic_price/class/price_parser.class.php +++ b/htdocs/product/dynamic_price/class/price_parser.class.php @@ -1,6 +1,7 @@ +/* Copyright (C) 2015 Ion Agorria * 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 @@ -133,7 +134,7 @@ class PriceParser * @param Product $product The Product object to get information * @param string $expression The expression to parse * @param array $values Strings to replace - * @return int > 0 if OK, < 1 if KO + * @return int Return > 0 if OK, < 1 if KO */ public function parseExpression($product, $expression, $values) { @@ -261,7 +262,7 @@ class PriceParser * * @param Product $product The Product object to get information * @param array $extra_values Any additional values for expression - * @return int > 0 if OK, < 1 if KO + * @return int Return > 0 if OK, < 1 if KO */ public function parseProduct($product, $extra_values = array()) { @@ -308,7 +309,7 @@ class PriceParser * * @param ProductFournisseur $product_supplier The Product supplier object to get information * @param array $extra_values Any additional values for expression - * @return int > 0 if OK, < 1 if KO + * @return int Return > 0 if OK, < 1 if KO */ public function parseProductSupplier($product_supplier, $extra_values = array()) { @@ -339,7 +340,7 @@ class PriceParser * @param int $product_id The Product id to get information * @param string $expression The expression to parse * @param array $extra_values Any additional values for expression - * @return int > 0 if OK, < 1 if KO + * @return int Return > 0 if OK, < 1 if KO */ public function testExpression($product_id, $expression, $extra_values = array()) {