Added optional "stocked amount" and storage locations columns for the BOM list

This fixes issue #429
This commit is contained in:
Jan Böhmer 2023-11-19 22:13:25 +01:00
parent 958d59a0ff
commit 83ad99215f
4 changed files with 103 additions and 59 deletions

View file

@ -139,63 +139,11 @@ final class PartsDataTable implements DataTableTypeInterface
->add('storelocation', TextColumn::class, [
'label' => $this->translator->trans('part.table.storeLocations'),
'orderField' => 'storelocations.name',
'render' => function ($value, Part $context): string {
$tmp = [];
foreach ($context->getPartLots() as $lot) {
//Ignore lots without storelocation
if (!$lot->getStorageLocation() instanceof StorageLocation) {
continue;
}
$tmp[] = sprintf(
'<a href="%s" title="%s">%s</a>',
$this->urlGenerator->listPartsURL($lot->getStorageLocation()),
htmlspecialchars($lot->getStorageLocation()->getFullPath()),
htmlspecialchars($lot->getStorageLocation()->getName())
);
}
return implode('<br>', $tmp);
},
'render' => fn ($value, Part $context) => $this->partDataTableHelper->renderStorageLocations($context),
], alias: 'storage_location')
->add('amount', TextColumn::class, [
'label' => $this->translator->trans('part.table.amount'),
'render' => function ($value, Part $context) {
$amount = $context->getAmountSum();
$expiredAmount = $context->getExpiredAmountSum();
$ret = '';
if ($context->isAmountUnknown()) {
//When all amounts are unknown, we show a question mark
if ($amount === 0.0) {
$ret .= sprintf('<b class="text-primary" title="%s">?</b>',
$this->translator->trans('part_lots.instock_unknown'));
} else { //Otherwise mark it with greater equal and the (known) amount
$ret .= sprintf('<b class="text-primary" title="%s">≥</b>',
$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) {
$ret .= sprintf(' <span title="%s" class="text-muted">(+%s)</span>',
$this->translator->trans('part_lots.is_expired'),
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;
},
'render' => fn ($value, Part $context) => $this->partDataTableHelper->renderAmount($context),
'orderField' => 'amountSum'
])
->add('minamount', TextColumn::class, [