diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php
index 758a4e21c8de4..99a7e6d888afa 100644
--- a/htdocs/product/composition/card.php
+++ b/htdocs/product/composition/card.php
@@ -613,6 +613,7 @@
$totalsell = 0;
$total = 0;
+ $potential_kit_stock = 0;
if (count($prods_arbo)) {
foreach ($prods_arbo as $value) {
$productstatic->fetch($value['id']);
@@ -681,7 +682,20 @@
if (isModEnabled('stock')) {
print '
'.$value['stock'].' | '; // Real stock
}
-
+ // Check if the component has a required quantity and stock.
+ if ($value['nb'] > 0 && is_numeric($value['stock'])) {
+ // Calculate how many full kits this component can support.
+ $possible_with_this = floor($value['stock'] / $value['nb']);
+ // Keep the smallest value across all components (the limiting factor).
+ if ($potential_kit_stock === 0 || $possible_with_this < $potential_kit_stock) {
+ $potential_kit_stock = $possible_with_this;
+ }
+ } else {
+ // If a component has no required quantity or its stock is not available, no kit can be made.
+ $potential_kit_stock = 0;
+ // Optionally, break the loop early for efficiency.
+ break;
+ }
// Hook fields
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $productstatic); // Note that $action and $object may have been modified by hook
@@ -795,6 +809,15 @@
// Stock
if (isModEnabled('stock')) {
+ // Add a new row for the potential kits stock.
+ $colspan_counter = 4;
+ print '';
+ print ' | | | ';
+ print '' . $langs->trans("PotentialKitsFromStock") . ' | ';
+ // Calculate the value to display. If $potential_kit_stock is null or 0, show 0.
+ $stock_to_display = $potential_kit_stock;
+ print '' . price($stock_to_display) . ' | ';
+ print '
';
print ' | ';
}