-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Calculate potential kits stock from components #38012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 4 commits
e686526
201e143
b2fedbb
d0218f0
8702696
2c43834
885e3af
66a96e3
d8cda78
df8d2c1
1e365a5
dc21773
a2ae972
0791ec6
1002129
828bfeb
6686d2d
11b2e76
d21fe9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -613,6 +613,7 @@ | |
|
|
||
| $totalsell = 0; | ||
| $total = 0; | ||
| $potential_kit_stock = null; | ||
| if (count($prods_arbo)) { | ||
| foreach ($prods_arbo as $value) { | ||
| $productstatic->fetch($value['id']); | ||
|
|
@@ -681,7 +682,20 @@ | |
| if (isModEnabled('stock')) { | ||
| print '<td class="right">'.$value['stock'].'</td>'; // 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 === null || $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 = 0; | ||
| print '<tr class="total-row right">'; | ||
| print '<td></td><td></td><td></td>'; | ||
| print '<td colspan="' . ($colspan_counter + 4) . '" class="titlefield">' . $langs->trans("PotentialKitsFromStock") . '</td>'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: there are several methods to potentially fix the phan error You could use The PHP ternary operator to make a 1 liner, and I would make that line just before using the variable `colspan_counter`` Something like But it may just be much more interesting to figure out why $colspan_counter was null to begin with.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $colspan_counter in null only about my ignorance. Should i assign a value = 0 (integer) am i right ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @edupulpillo I am not sure what the colspan_counter is for, but if you want to do addition, then starting with 0 is a good bet, but if you only do the addition once - why even have a variable?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are right, better to use a constant So now your review is not needed anymore. Kindly accept the latest version, it pased already allt he tests of code. Please complete your review is not possible to cancel a request review accidentally requested |
||
| // Calculate the value to display. If $potential_kit_stock is null or 0, show 0. | ||
| $stock_to_display = ($potential_kit_stock !== null && $potential_kit_stock > 0) ? $potential_kit_stock : 0; | ||
| print '<td class="total-value">' . price($stock_to_display) . '</td>'; | ||
| print '</tr>'; | ||
| print '<td class="liste_total right"> </td>'; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.