Highlight amount sum in part tables and part info page, when amount is less than minAmount

This commit is contained in:
Jan Böhmer 2023-04-03 23:15:29 +02:00
parent 69fdc85c99
commit 5330476dbe
4 changed files with 29 additions and 5 deletions

View file

@ -202,6 +202,12 @@ final class PartsDataTable implements DataTableTypeInterface
htmlspecialchars($this->amountFormatter->format($expiredAmount, $context->getPartUnit())));
}
//When the amount is below the minimum amount, we highlight the number red
if ($context->isNotEnoughInstock()) {
$ret = sprintf('<b class="text-danger" title="%s">%s</b>',
$this->translator->trans('part.info.amount.less_than_desired'),
$ret);
}
return $ret;
},

View file

@ -151,6 +151,15 @@ trait InstockTrait
return false;
}
/**
* Returns true, if the total instock amount of this part is less than the minimum amount.
* @return bool
*/
public function isNotEnoughInstock(): bool
{
return $this->getAmountSum() < $this->getMinAmount();
}
/**
* 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.

View file

@ -41,11 +41,14 @@
<span class="text-muted">{{ helper.structural_entity_link(part.category) }}</span>
</h6>
<h6><i class="fas fa-shapes fa-fw"></i>
<span class="text-muted">
<span title="{% trans %}instock.label{% endtrans %}">{{ part.amountSum | format_amount(part.partUnit) }}</span>
/
<span title="{% trans %}mininstock.label{% endtrans %}">{{ part.minAmount | format_amount(part.partUnit) }}</span>
</span>
<span class="{% if part.notEnoughInstock %}text-danger font-weight-bold{% else %}text-muted{% endif %}">
<span title="{% trans %}instock.label{% endtrans %}">{{ part.amountSum | format_amount(part.partUnit) }}</span>
/
<span title="{% trans %}mininstock.label{% endtrans %}">{{ part.minAmount | format_amount(part.partUnit) }}</span>
</span>
{% if part.notEnoughInstock %}
<span class="badge badge-warning bg-warning rounded-pill"><i class="fa-solid fa-less-than-equal"></i>&nbsp;{% trans %}part.info.amount.less_than_desired{% endtrans %}</span>
{% endif %}
</h6>
<h6 class="">
<i class="fas fa-microchip fa-fw" title="{% trans %}footprint.label{% endtrans %}"></i>

View file

@ -11253,5 +11253,11 @@ Element 3</target>
<target>Not allowed to do the desired action. Please check your permissions and the owner of the part lots.</target>
</segment>
</unit>
<unit id="Dwo4KWP" name="part.info.amount.less_than_desired">
<segment>
<source>part.info.amount.less_than_desired</source>
<target>Less than desired</target>
</segment>
</unit>
</file>
</xliff>