NEW : adds visual indicators on the Sales Order card (commande/card.php) (#37460)

* This PR adds visual indicators on the Sales Order card (commande/card.php) to quickly identify if an order or its lines are shippable based on current stock levels. This feature mirrors the existing functionality found in the Orders List, bringing valuable logistics information directly into the Order Card context.

Key Features:
Global Shippable Status: Adds a "shippable" icon (Truck) next to the "Planned delivery date" field.

Logic: Checks if all products in the order are in stock.

Condition: Visible only if Stock and Shipment modules are enabled, a delivery date is set, and the order is validated.

Visual: Green icon if fully shippable, Red/Warning if stock is insufficient. Includes a detailed tooltip.

Per-Line Shippable Status: Adds a new "Shippable" column in the product lines table.

Logic: Compares real stock vs. remaining quantity to ship for each line.

Visual: Displays a green/red status bullet (standard Dolibarr status icons) directly in the line.

Implementation: Done by updating objectline_title.tpl.php and objectline_view.tpl.php with specific checks for the commande element.

New Configuration Option: Added a hidden option ORDER_DISABLE_SHIPPABLE_ICON_ON_CARD to disable this feature if needed (configurable in Home > Setup > Other Setup or via module settings).

Backend Optimization: Added a new method getShippableInfos() in commande.class.php to centralize the stock check logic (optimized with stock caching to avoid N+1 query issues).

Technical Details:
Modified Files:

commande/card.php: Integration of the global icon next to the date.

commande/class/commande.class.php: Added getShippableInfos() method.

core/tpl/objectline_title.tpl.php: Added "Shippable" column header (conditional for Orders).

core/tpl/objectline_view.tpl.php: Added "Shippable" column cell content (conditional for Orders).

Performance: Logic uses static caching for product stock to minimize database impact when rendering large orders.

* missed element

* img_picto

* phan add

* load_stock and global $i

* phan

* ci retour

* change icon
change phan directive

* phan

* Fight against optionflation

Signed-off-by: Laurent Destailleur <eldy@destailleur.fr>

* Change condition for displaying shippable icon

Signed-off-by: Laurent Destailleur <eldy@destailleur.fr>

* Change condition for displaying shippable status icon

Signed-off-by: Laurent Destailleur <eldy@destailleur.fr>

* Update card.php

Signed-off-by: Laurent Destailleur <eldy@destailleur.fr>

* Update shippable status condition in template

Signed-off-by: Laurent Destailleur <eldy@destailleur.fr>

* Update shippable status condition logic

Signed-off-by: Laurent Destailleur <eldy@destailleur.fr>

---------

Signed-off-by: Laurent Destailleur <eldy@destailleur.fr>
Co-authored-by: jpb <jean-pascal.boudet@atm-consulting>
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
boudet jean pascal
2026-03-12 14:42:31 +01:00
committed by GitHub
parent b02f1a4ebf
commit a4b8cb7008
8 changed files with 240 additions and 103 deletions

View File

@@ -4320,4 +4320,164 @@ class Commande extends CommonOrder
{
return $this->setSignedStatusCommon($user, $status, $notrigger, $triggercode);
}
/**
* Compute shippable status and tooltip/icon for the order.
*
* @param array<mixed> $options Extra options (reserved for future use)
* @return array<string,mixed> Array with keys: has_product, shippable, texticon, textinfo, warning
* /
*/
public function getShippableInfos(array $options = array()) : array
{
global $conf, $langs;
$langs->loadLangs(array('orders', 'sendings', 'stocks', 'products'));
$result = array(
'has_product' => false,
'shippable' => false,
'texticon' => '',
'textinfo' => '',
'warning' => false,
);
// Requested naming for statuses
if ($this->status == self::STATUS_DRAFT || $this->status == self::STATUS_CLOSED) {
return $result;
}
$genericCommande = $this;
$genericProduct = new Product($this->db);
$productstatcache = array();
$productstatcachevirtual = array();
$genericCommande->getLinesArray(); // Load array ->lines
$genericCommande->loadExpeditions(); // Load array ->expeditions
$notshippable = 0;
$has_reliquat = 0;
$warning = 0;
$textinfo = '';
$textwarning = '';
$nbprod = 0;
$genericProduct = new Product($this->db);
$numlines = count($genericCommande->lines);
for ($lig = 0; $lig < $numlines; $lig++) {
$orderLine = $genericCommande->lines[$lig]; // @phan-var-force OrderLine $orderLine
if (isset($genericCommande->expeditions[$orderLine->id])) {
$reliquat = $orderLine->qty - $genericCommande->expeditions[$orderLine->id];
} else {
$reliquat = $orderLine->qty;
}
if ($orderLine->product_type == 0 && $orderLine->fk_product > 0) { // product, not service
$nbprod = 1;
if (empty($productstatcache[$orderLine->fk_product])) {
$genericProduct->fetch($orderLine->fk_product);
$genericProduct->load_stock('nobatch,warehouseopen'); // loadvirtualstock included
$productstatcache[$orderLine->fk_product]['stockreel'] = $genericProduct->stock_reel;
$productstatcachevirtual[$orderLine->fk_product]['stockreel'] = $genericProduct->stock_theorique;
}
$genericProduct->stock_reel = $productstatcache[$orderLine->fk_product]['stockreel'];
$genericProduct->stock_theorique = $productstatcachevirtual[$orderLine->fk_product]['stockreel'];
if ($reliquat > 0) {
$has_reliquat = 1;
if (!getDolGlobalString('SHIPPABLE_ORDER_ICON_IN_LIST')) {
$textinfo .= $reliquat . ' x ' . $orderLine->product_ref . '&nbsp;' . dol_trunc($orderLine->product_label, 20);
$textinfo .= ' - ' . $langs->trans("Stock") . ': <span class="' . ($genericProduct->stock_reel >= $reliquat ? 'ok' : 'error') . '">' . $genericProduct->stock_reel . '</span>';
$textinfo .= ' - ' . $langs->trans("VirtualStock") . ': <span class="' . ($genericProduct->stock_theorique >= $reliquat ? 'ok' : 'error') . '">' . $genericProduct->stock_theorique . '</span>';
if ($reliquat != $orderLine->qty) {
$textinfo .= ' <span class="opacitymedium">' . $langs->trans("QtyInOtherShipments") . ' ' . ($orderLine->qty - $reliquat) . '</span>';
}
$textinfo .= '<br>';
} else {
// BUGGED CODE (kept for backward compatibility and hidden conf)
$stockorder = 0;
$stockordersupplier = 0;
if (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT') || getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {
if (isModEnabled('order')) {
if (empty($productstatcache[$orderLine->fk_product]['statsordercustomer'])) {
$genericProduct->fetch($orderLine->fk_product);
$genericProduct->load_stats_commande(0, '1,2');
$productstatcache[$orderLine->fk_product]['statsordercustomer'] = $genericProduct->stats_commande['qty'];
}
$genericProduct->stats_commande['qty'] = $productstatcache[$orderLine->fk_product]['statsordercustomer'];
$stockorder = $genericProduct->stats_commande['qty'];
if (isModEnabled('supplier_order')) {
if (empty($productstatcache[$orderLine->fk_product]['statsordersupplier'])) {
$genericProduct->load_stats_commande_fournisseur(0, '3');
$productstatcache[$orderLine->fk_product]['statsordersupplier'] = $genericProduct->stats_commande_fournisseur['qty'];
}
$genericProduct->stats_commande_fournisseur['qty'] = $productstatcache[$orderLine->fk_product]['statsordersupplier'];
$stockordersupplier = $genericProduct->stats_commande_fournisseur['qty'];
}
}
}
$textinfo .= $reliquat . ' x ' . $orderLine->ref . '&nbsp;' . dol_trunc($orderLine->product_label, 20);
$textinfo .= ' ' . $langs->trans("Available") . '&nbsp;&nbsp;' . $genericProduct->stock_reel . '..' . $stockorder;
if ($stockorder && $genericProduct->stock_reel < ($genericProduct->stock_reel - $stockorder + $reliquat)) {
$warning++;
$textwarning .= '<span class="warning">' . $langs->trans("Available") . '&nbsp;&nbsp;' . $genericProduct->stock_reel . '..' . $stockorder . '</span>';
} else {
if ($reliquat > $genericProduct->stock_reel) {
$textinfo .= ' <span class="warning">' . $langs->trans("Available") . '&nbsp;&nbsp;' . $genericProduct->stock_reel . '</span>';
} else {
$textinfo .= ' <span class="ok">' . $langs->trans("Available") . '&nbsp;&nbsp;' . $genericProduct->stock_reel . '</span>';
}
}
if (isModEnabled('supplier_order')) {
$textinfo .= '&nbsp;' . $langs->trans("SupplierOrder") . '&nbsp;&nbsp;' . $stockordersupplier;
}
if ($reliquat != $orderLine->qty) {
$textinfo .= ' <span class="opacitymedium">' . $langs->trans("QtyInOtherShipments") . ' ' . ($orderLine->qty - $reliquat) . '</span>';
}
$textinfo .= '<br>';
}
if ($reliquat > $genericProduct->stock_reel) {
$notshippable++;
}
}
}
}
if ($nbprod) {
if (!$has_reliquat) {
$texticon = img_picto('', 'statut5', '', 0, 0, 0, '', 'paddingleft');
$textinfo = $texticon . ' ' . $langs->trans("Shipped");
$result['shippable'] = true;
} elseif ($notshippable) {
$texticon = img_picto('', 'dolly', '', 0, 0, 0, '', 'error paddingleft');
$textinfo = $texticon . ' ' . $langs->trans("NonShippable") . '<br>' . $textinfo;
$result['shippable'] = false;
} else {
$texticon = img_picto('', 'dolly', '', 0, 0, 0, '', 'green paddingleft');
$textinfo = $texticon . ' ' . $langs->trans("Shippable") . '<br>' . $textinfo;
$result['shippable'] = true;
}
$result['has_product'] = true;
$result['texticon'] = $texticon;
$result['textinfo'] = $textinfo;
$result['warning'] = !empty($warning);
}
return $result;
}
}