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 <eldy@destailleur.fr>
This commit is contained in:
Frédéric FRANCE 2025-09-21 12:12:09 +02:00 committed by GitHub
parent 5c2344cca8
commit e7ddb684e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 112 additions and 229 deletions

View file

@ -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\<int\<0, 11\>, array\<int, float\|int\>\> but returns non\-empty\-array\<int\<0, 11\>, 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\<string, array\<int, array\<int, float\|int\|string\>\>\>\) 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

View file

@ -735,7 +735,7 @@ class AccountingAccount extends CommonObject
* @param FactureLigne|SupplierInvoiceLine $factureDet Facture Det
* @param array<string,int> $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';
}
}

View file

@ -806,7 +806,7 @@ abstract class CommonObject
public $labelStatusShort = array();
/**
* @var array<string,int|string> Array to store lists of tpl
* @var array<string,int|float|string|null> Array to store lists of tpl
*/
public $tpl;

View file

@ -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;
}
}
/**

View file

@ -1,8 +1,8 @@
<?php
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2017 Charlie Benke <charlie@patas-monkey.com>
* Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2017 Charlie Benke <charlie@patas-monkey.com>
* Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
*
* 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 '<td class="linecolqty right">'.$this->tpl['qty'].'</td>';
if (getDolGlobalString('PRODUCT_USE_UNITS')) {
print '<td class="linecoluseunit left">'.$langs->trans($this->tpl['unit']).'</td>';
print '<td class="linecoluseunit left">'.$langs->trans((string) $this->tpl['unit']).'</td>';
}
print '<td class="linecoldiscount right">'.$this->tpl['remise_percent'].'</td>';

View file

@ -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';
}
/**

View file

@ -151,7 +151,7 @@ class MoLine extends CommonObjectLine
public $qty;
/**
* @var float Quantity frozen
* @var int<0,1> Is quantity frozen
*/
public $qty_frozen;
/**

View file

@ -1,8 +1,8 @@
<?php
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2017 Charlie Benke <charlie@patas-monkey.com>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2017 Charlie Benke <charlie@patas-monkey.com>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
*
* 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 '</td>';
// Qty
print '<td class="right">'.$this->tpl['qty'].(($this->tpl['efficiency'] > 0 && $this->tpl['efficiency'] < 1) ? ' / '.$form->textwithpicto($this->tpl['efficiency'], $langs->trans("ValueOfMeansLoss")).' = '.$qtytoconsumeforline : '').'</td>';
print '<td class="right">'.$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) : '').'</td>';
// Unit
print '<td class="right">'.measuringUnitString($this->tpl['fk_unit'], '', null, 1).'</td>';
// Stock
print '<td class="center">';
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 '</td>';
print '<td class="center">';
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']));
}
}

View file

@ -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<string,array<int,array{0:int,1:float,2:int,3:string,4:int,5:string}>>
* @var null|array<string,array<int,array{0:int,1:float,2:int,3:string,4:int,5:string}>>
*/
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<int<0,11>,array<int,int|float>>|int<-1,-1> Return integer <0 if KO, result[month]=array(valuex,valuey) where month is 0 to 11
* @return array<int<0,11>,array<int,int|float|string>>|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.'<br>';
// print $idx.'-'.$year.'-'.$month.'<br>';
$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 ? " - " : "")."<b>".$langs->trans("Length").'</b>: '.$this->length.' '.measuringUnitString(0, 'size', $this->length_units);
$labelsize .= "<b>".$langs->trans("Length").'</b>: '.$this->length.' '.measuringUnitString(0, 'size', $this->length_units);
}
if ($this->width) {
$labelsize .= ($labelsize ? " - " : "")."<b>".$langs->trans("Width").'</b>: '.$this->width.' '.measuringUnitString(0, 'size', $this->width_units);
@ -5792,7 +5794,7 @@ class Product extends CommonObject
$labelsurfacevolume = "";
if ($this->surface) {
$labelsurfacevolume .= ($labelsurfacevolume ? " - " : "")."<b>".$langs->trans("Surface").'</b>: '.$this->surface.' '.measuringUnitString(0, 'surface', $this->surface_units);
$labelsurfacevolume .= "<b>".$langs->trans("Surface").'</b>: '.$this->surface.' '.measuringUnitString(0, 'surface', $this->surface_units);
}
if ($this->volume) {
$labelsurfacevolume .= ($labelsurfacevolume ? " - " : "")."<b>".$langs->trans("Volume").'</b>: '.$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]) ? "&nbsp;".$langs->trans($dur[$this->duration_unit]) : '');
}
if (empty($user->socid)) {
if (!empty($this->pmp) && $this->pmp) {
if (isset($this->pmp) && $this->pmp) {
$datas['pmp'] = "<br><b>".$langs->trans("PMPValue").'</b>: '.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 .= '</div>';
$return .= '<div class="info-box-content">';
$return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
$return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl() . '</span>';
if ($selected >= 0) {
$return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
}
if (property_exists($this, 'label')) {
$return .= '<br><span class="info-box-label opacitymedium inline-block tdoverflowmax150 valignmiddle" title="'.dol_escape_htmltag($this->label).'">'.dol_escape_htmltag($this->label).'</span>';
}
if (property_exists($this, 'price') && property_exists($this, 'price_ttc')) {
if ($this->price_base_type == 'TTC') {
$return .= '<br><span class="info-box-status amount">'.price($this->price_ttc).' '.$langs->trans("TTC").'</span>';
} else {
if ($this->status) {
$return .= '<br><span class="info-box-status amount">'.price($this->price).' '.$langs->trans("HT").'</span>';
}
$return .= '<br><span class="info-box-label opacitymedium inline-block tdoverflowmax150 valignmiddle" title="'.dol_escape_htmltag($this->label).'">'.dol_escape_htmltag($this->label).'</span>';
if ($this->price_base_type == 'TTC') {
$return .= '<br><span class="info-box-status amount">'.price($this->price_ttc).' '.$langs->trans("TTC").'</span>';
} else {
if ($this->status) {
$return .= '<br><span class="info-box-status amount">'.price($this->price).' '.$langs->trans("HT").'</span>';
}
}
$br = 1;
if (property_exists($this, 'stock_reel') && $this->isProduct()) {
if ($this->isProduct()) {
$return .= '<br><div class="info-box-status opacitymedium inline-block valignmiddle">'.img_picto($langs->trans('PhysicalStock'), 'stock').'</div><div class="inline-block valignmiddle paddingleft" title="'.$langs->trans('PhysicalStock').'">'.$this->stock_reel.'</div>';
$br = 0;
}
if (method_exists($this, 'getLibStatut')) {
if ($br) {
$return .= '<br><div class="info-box-status inline-block valignmiddle">'.$this->getLibStatut(3, 1).' '.$this->getLibStatut(3, 0).'</div>';
} else {
$return .= '<div class="info-box-status inline-block valignmiddle marginleftonly paddingleft">'.$this->getLibStatut(3, 1).' '.$this->getLibStatut(3, 0).'</div>';
}
if ($br) {
$return .= '<br>';
$return .= '<div class="info-box-status inline-block valignmiddle">'.$this->getLibStatut(3, 1).' '.$this->getLibStatut(3, 0).'</div>';
} else {
$return .= '<div class="info-box-status inline-block valignmiddle marginleftonly paddingleft">'.$this->getLibStatut(3, 1).' '.$this->getLibStatut(3, 0).'</div>';
}
$return .= '</div>';
$return .= '</div>';

View file

@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2015 Ion Agorria <ion@agorria.com>
/* Copyright (C) 2015 Ion Agorria <ion@agorria.com>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
*
* 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<string,mixed> $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<string,mixed> $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<string,mixed> $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<string,mixed> $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())
{