mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-24 10:49:00 +02:00
Show expired lot sum in parts table in parenthesis
This commit is contained in:
parent
1f6f39172f
commit
bd12185b44
2 changed files with 32 additions and 1 deletions
|
@ -210,8 +210,19 @@ final class PartsDataTable implements DataTableTypeInterface
|
|||
'label' => $this->translator->trans('part.table.amount'),
|
||||
'render' => function ($value, Part $context) {
|
||||
$amount = $context->getAmountSum();
|
||||
$expiredAmount = $context->getExpiredAmountSum();
|
||||
|
||||
return $this->amountFormatter->format($amount, $context->getPartUnit());
|
||||
$ret = $this->amountFormatter->format($amount, $context->getPartUnit());
|
||||
|
||||
//If we have expired lots, we show them in parentheses behind
|
||||
if ($expiredAmount > 0) {
|
||||
$ret .= sprintf(' <span title="%s" class="text-muted">(+%s)</span>',
|
||||
$this->translator->trans('part_lots.is_expired'),
|
||||
$this->amountFormatter->format($expiredAmount, $context->getPartUnit()));
|
||||
}
|
||||
|
||||
|
||||
return $ret;
|
||||
},
|
||||
'orderField' => 'amountSum'
|
||||
])
|
||||
|
|
|
@ -193,6 +193,26 @@ trait InstockTrait
|
|||
return round($sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the summed amount of all part lots that are expired. If no part lots are expired 0 is returned.
|
||||
* @return float
|
||||
*/
|
||||
public function getExpiredAmountSum(): float
|
||||
{
|
||||
$sum = 0.0;
|
||||
foreach ($this->getPartLots() as $lot) {
|
||||
if ($lot->isExpired() && !$lot->isInstockUnknown()) {
|
||||
$sum += $lot->getAmount();
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->useFloatAmount()) {
|
||||
return $sum;
|
||||
}
|
||||
|
||||
return round($sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum amount of parts that have to be instock.
|
||||
* See getPartUnit() for the associated unit.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue