diff --git a/src/DataTables/PartsDataTable.php b/src/DataTables/PartsDataTable.php index 9e6e2415..8dc94ba0 100644 --- a/src/DataTables/PartsDataTable.php +++ b/src/DataTables/PartsDataTable.php @@ -178,7 +178,22 @@ final class PartsDataTable implements DataTableTypeInterface $amount = $context->getAmountSum(); $expiredAmount = $context->getExpiredAmountSum(); - $ret = htmlspecialchars($this->amountFormatter->format($amount, $context->getPartUnit())); + $ret = ''; + + if ($context->isAmountUnknown()) { + //When all amounts are unknown, we show a question mark + if ($amount === 0.0) { + $ret .= sprintf('?', + $this->translator->trans('part_lots.instock_unknown')); + } else { //Otherwise mark it with greater equal and the (known) amount + $ret .= sprintf('', + $this->translator->trans('part_lots.instock_unknown') + ); + $ret .= htmlspecialchars($this->amountFormatter->format($amount, $context->getPartUnit())); + } + } else { + $ret .= htmlspecialchars($this->amountFormatter->format($amount, $context->getPartUnit())); + } //If we have expired lots, we show them in parentheses behind if ($expiredAmount > 0) { diff --git a/src/Entity/Parts/PartTraits/InstockTrait.php b/src/Entity/Parts/PartTraits/InstockTrait.php index 29d04c89..8ab300b5 100644 --- a/src/Entity/Parts/PartTraits/InstockTrait.php +++ b/src/Entity/Parts/PartTraits/InstockTrait.php @@ -160,9 +160,25 @@ trait InstockTrait return $this->getAmountSum() < $this->getMinAmount(); } + /** + * Returns true, if at least one of the part lots has an unknown amount. + * It is possible that other part lots have a known amount, then getAmountSum() will return sum of all known amounts. + * @return bool True if at least one part lot has an unknown amount. + */ + public function isAmountUnknown(): bool + { + foreach ($this->getPartLots() as $lot) { + if ($lot->isInstockUnknown()) { + return true; + } + } + + return false; + } + /** * Returns the summed amount of this part (over all part lots) - * Part Lots that have unknown value or are expired, are not used for this value. + * Part Lots that have unknown value or are expired, are not used for this value (counted as 0). * * @return float The amount of parts given in partUnit */ diff --git a/templates/parts/info/_main_infos.html.twig b/templates/parts/info/_main_infos.html.twig index e8ecd95c..99c20126 100644 --- a/templates/parts/info/_main_infos.html.twig +++ b/templates/parts/info/_main_infos.html.twig @@ -41,8 +41,17 @@ {{ helper.structural_entity_link(part.category) }}
- - {{ part.amountSum | format_amount(part.partUnit) }} + + {% if not part.amountUnknown %} + {# For known instock we can just show the label as normal #} + {{ part.amountSum | format_amount(part.partUnit) }} + {% else %} + {% if part.amountSum == 0.0 %} + ? + {% else %} + ≥{{ part.amountSum | format_amount(part.partUnit) }} + {% endif %} + {% endif %} {% if part.expiredAmountSum > 0 %} (+{{ part.expiredAmountSum }}) {% endif %}