From ebbaeb512908c76018558a091163df4e5177fd80 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 23 Jan 2026 22:34:17 +0100 Subject: [PATCH] Clean code --- htdocs/expedition/card.php | 51 +++++++++++--------- htdocs/expedition/class/expedition.class.php | 3 +- htdocs/expedition/shipment.php | 2 +- htdocs/product/class/product.class.php | 7 ++- htdocs/product/price.php | 10 ++++ 5 files changed, 47 insertions(+), 26 deletions(-) diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index e5d31de915d..4366e35e0ab 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -1532,22 +1532,22 @@ if ($action == 'create' && $usercancreate) { print $langs->trans("Weight"); print ''; print img_picto('', 'fa-balance-scale', 'class="pictofixedwidth"'); - print ' '; - $text = $formproduct->selectMeasuringUnits("weight_units", "weight", (string) GETPOSTINT('weight_units'), 0, 2); + print ' '; // Do not use GETPOSTINT here, we must accept '' also. + $text = $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOST('weight_units'), 0, 2); $htmltext = $langs->trans("KeepEmptyForAutoCalculation"); print $form->textwithpicto($text, $htmltext); print ''; - // Dim + // Dim width x height x depth print ''; print $langs->trans("Width") . ' x ' . $langs->trans("Height") . ' x ' . $langs->trans("Depth"); print ' '; print img_picto('', 'fa-ruler', 'class="pictofixedwidth"'); - print ''; - print ' x '; - print ' x '; + print ''; + print ' x '; + print ' x '; print ' '; - $text = $formproduct->selectMeasuringUnits("size_units", "size", (string) GETPOSTINT('size_units'), 0, 2); + $text = $formproduct->selectMeasuringUnits("size_units", "size", GETPOST('size_units'), 0, 2); $htmltext = $langs->trans("KeepEmptyForAutoCalculation"); print $form->textwithpicto($text, $htmltext); print ''; @@ -1756,22 +1756,22 @@ if ($action == 'create' && $usercancreate) { print $langs->trans("Weight"); print ''; print img_picto('', 'fa-balance-scale', 'class="pictofixedwidth"'); - print ' '; - $text = $formproduct->selectMeasuringUnits("weight_units", "weight", (string) GETPOSTINT('weight_units'), 0, 2); + print ' '; // Do not use GETPOSTINT here, we must accept '' also. + $text = $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOST('weight_units'), 0, 2); $htmltext = $langs->trans("KeepEmptyForAutoCalculation"); print $form->textwithpicto($text, $htmltext); print ''; - // Dim + // Dim Width x Height x Depth print ''; print $langs->trans("Width") . ' x ' . $langs->trans("Height") . ' x ' . $langs->trans("Depth"); print ' '; print img_picto('', 'fa-ruler', 'class="pictofixedwidth"'); - print ''; - print ' x '; - print ' x '; + print ''; + print ' x '; + print ' x '; print ' '; - $text = $formproduct->selectMeasuringUnits("size_units", "size", (string) GETPOSTINT('size_units'), 0, 2); + $text = $formproduct->selectMeasuringUnits("size_units", "size", GETPOST('size_units'), 0, 2); $htmltext = $langs->trans("KeepEmptyForAutoCalculation"); print $form->textwithpicto($text, $htmltext); print ''; @@ -2026,14 +2026,18 @@ if ($action == 'create' && $usercancreate) { // Qty print '' . $line->qty; print ''; - print '' . $unit_order . ''; + if ($line->qty) { + print ' ' . $unit_order . ''; + } // Qty already shipped print ''; $quantityDelivered = isset($object->expeditions[$line->id]) ? $object->expeditions[$line->id] : ''; print $quantityDelivered; print ''; - print '' . $unit_order . ''; + if ($quantityDelivered) { + print ' ' . $unit_order . ''; + } // Qty to ship $quantityAsked = $line->qty; @@ -2512,17 +2516,19 @@ if ($action == 'create' && $usercancreate) { if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { $disabled = ''; + $alt = ''; if (isModEnabled('productbatch') && $product->hasbatch()) { $disabled = 'disabled="disabled"'; + $alt = 'Product need serial or batch number'; } if ($warehouse_selected_id <= 0) { // We did not force a given warehouse, so we won't have no warehouse to change qty. $disabled = 'disabled="disabled"'; } // finally we overwrite the input with the product status stockable_product if it's disabled - if ($product->stockable_product == Product::DISABLED_STOCK) { + if ($product->stockable_product == Product::ENABLED_STOCK) { $disabled = ''; } - print ' '; + print ' '; if (empty($disabled) && (!getDolGlobalInt('STOCK_DISALLOW_NEGATIVE_TRANSFER') || $product->stockable_product == Product::DISABLED_STOCK)) { print ''; } @@ -2545,16 +2551,17 @@ if ($action == 'create' && $usercancreate) { print ''; if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { - if ($warehouse_selected_id > 0 && $product->stockable_product == Product::ENABLED_STOCK) { + // product may use stock management + if (($warehouse_selected_id > 0 && $product->stockable_product == Product::ENABLED_STOCK)) { $warehouseObject = new Entrepot($db); $warehouseObject->fetch($warehouse_selected_id); print img_warning() . ' ' . $langs->trans("NoProductToShipFoundIntoStock", $warehouseObject->label); } else { if ($line->fk_product) { - if ($product->stockable_product == Product::ENABLED_STOCK) { - print img_warning() . ' ' . $langs->trans('StockTooLow'); - } else { + if ($product->stockable_product != Product::ENABLED_STOCK) { print img_warning() . ' ' . $langs->trans('StockDisabled'); + } else { + print img_warning() . ' ' . $langs->trans('StockTooLow'); } } else { print ''; diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 6d04fcdd71a..65d03fdd33f 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -2891,7 +2891,7 @@ class Expedition extends CommonObject $resql = $this->db->query($sql); if ($resql) { // Set order billed if 100% of order is shipped (qty in shipment lines match qty in order lines) - if ($this->origin == 'commande' && $this->origin_id > 0) { + if ($this->origin_type == 'commande' && $this->origin_id > 0) { $order = new Commande($this->db); $order->fetch($this->origin_id); @@ -2921,6 +2921,7 @@ class Expedition extends CommonObject // If stock increment is done on closing if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) { $result = $this->manageStockMvtOnEvt($user); + if ($result < 0) { $error++; } diff --git a/htdocs/expedition/shipment.php b/htdocs/expedition/shipment.php index cad0e5b28a3..65adf304ce8 100644 --- a/htdocs/expedition/shipment.php +++ b/htdocs/expedition/shipment.php @@ -919,7 +919,7 @@ if ($order_id > 0 || !empty($ref)) { if ($toBeShippedTotal <= 0) { print ' '.img_warning($langs->trans("WarningNoQtyLeftToSend")); } - print '

'; + print ''; print "\n"; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 701cd0b2409..37020628afe 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5787,13 +5787,16 @@ class Product extends CommonObject $datas['ref'] = '
'.$langs->trans('ProductRef').': '.$this->ref; } if (!empty($this->label)) { - $datas['label'] = '
'.$langs->trans('ProductLabel').': '.$this->label; + $datas['label'] = '
'.$langs->trans('ProductLabel').': '.$this->label.'
'; } if ($permissiontoreadproduct) { - if (!empty($this->description)) { + if (!empty($this->description) && getDolGlobalString('PRODUCT_SHOW_DESCRIPTION_IN_TOOLTIP')) { $datas['description'] = '
'.$langs->trans('ProductDescription').': '.dolGetFirstLineOfText($this->description, 5); } + + $datas['stockmanaged'] = "
".$langs->trans("StockableProduct").': '.yn($this->isStockManaged()); + if ($this->isStockManaged()) { if (isModEnabled('productbatch')) { $langs->load("productbatch"); diff --git a/htdocs/product/price.php b/htdocs/product/price.php index e15b0795d3c..0c5e206e709 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -1382,6 +1382,16 @@ if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUS } } } else { + // Type + if (isModEnabled("product") && isModEnabled("service")) { + $typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service"); + print ''; + print (!getDolGlobalString('PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey("Type", 'fk_product_type', (string) $object->type, $object, 0, $typeformat) : $langs->trans('Type'); + print ''; + print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, 0, $typeformat); + print ''; + } + // TVA print ''.$langs->trans("DefaultTaxRate").'';