mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-23 10:18:56 +02:00
Added optional "stocked amount" and storage locations columns for the BOM list
This fixes issue #429
This commit is contained in:
parent
958d59a0ff
commit
83ad99215f
4 changed files with 103 additions and 59 deletions
|
@ -20,14 +20,17 @@ declare(strict_types=1);
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace App\DataTables\Helpers;
|
namespace App\DataTables\Helpers;
|
||||||
|
|
||||||
|
use App\Entity\Parts\StorageLocation;
|
||||||
use App\Entity\ProjectSystem\Project;
|
use App\Entity\ProjectSystem\Project;
|
||||||
use App\Entity\Attachments\Attachment;
|
use App\Entity\Attachments\Attachment;
|
||||||
use App\Entity\Parts\Part;
|
use App\Entity\Parts\Part;
|
||||||
use App\Services\Attachments\AttachmentURLGenerator;
|
use App\Services\Attachments\AttachmentURLGenerator;
|
||||||
use App\Services\Attachments\PartPreviewGenerator;
|
use App\Services\Attachments\PartPreviewGenerator;
|
||||||
use App\Services\EntityURLGenerator;
|
use App\Services\EntityURLGenerator;
|
||||||
|
use App\Services\Formatters\AmountFormatter;
|
||||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,8 +38,13 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
*/
|
*/
|
||||||
class PartDataTableHelper
|
class PartDataTableHelper
|
||||||
{
|
{
|
||||||
public function __construct(private readonly PartPreviewGenerator $previewGenerator, private readonly AttachmentURLGenerator $attachmentURLGenerator, private readonly EntityURLGenerator $entityURLGenerator, private readonly TranslatorInterface $translator)
|
public function __construct(
|
||||||
{
|
private readonly PartPreviewGenerator $previewGenerator,
|
||||||
|
private readonly AttachmentURLGenerator $attachmentURLGenerator,
|
||||||
|
private readonly EntityURLGenerator $entityURLGenerator,
|
||||||
|
private readonly TranslatorInterface $translator,
|
||||||
|
private readonly AmountFormatter $amountFormatter,
|
||||||
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderName(Part $context): string
|
public function renderName(Part $context): string
|
||||||
|
@ -45,14 +53,16 @@ class PartDataTableHelper
|
||||||
|
|
||||||
//Depending on the part status we show a different icon (the later conditions have higher priority)
|
//Depending on the part status we show a different icon (the later conditions have higher priority)
|
||||||
if ($context->isFavorite()) {
|
if ($context->isFavorite()) {
|
||||||
$icon = sprintf('<i class="fa-solid fa-star fa-fw me-1" title="%s"></i>', $this->translator->trans('part.favorite.badge'));
|
$icon = sprintf('<i class="fa-solid fa-star fa-fw me-1" title="%s"></i>',
|
||||||
|
$this->translator->trans('part.favorite.badge'));
|
||||||
}
|
}
|
||||||
if ($context->isNeedsReview()) {
|
if ($context->isNeedsReview()) {
|
||||||
$icon = sprintf('<i class="fa-solid fa-ambulance fa-fw me-1" title="%s"></i>', $this->translator->trans('part.needs_review.badge'));
|
$icon = sprintf('<i class="fa-solid fa-ambulance fa-fw me-1" title="%s"></i>',
|
||||||
|
$this->translator->trans('part.needs_review.badge'));
|
||||||
}
|
}
|
||||||
if ($context->getBuiltProject() instanceof Project) {
|
if ($context->getBuiltProject() instanceof Project) {
|
||||||
$icon = sprintf('<i class="fa-solid fa-box-archive fa-fw me-1" title="%s"></i>',
|
$icon = sprintf('<i class="fa-solid fa-box-archive fa-fw me-1" title="%s"></i>',
|
||||||
$this->translator->trans('part.info.projectBuildPart.hint') . ': ' . $context->getBuiltProject()->getName());
|
$this->translator->trans('part.info.projectBuildPart.hint').': '.$context->getBuiltProject()->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,4 +95,62 @@ class PartDataTableHelper
|
||||||
$title
|
$title
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function renderStorageLocations(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->entityURLGenerator->listPartsURL($lot->getStorageLocation()),
|
||||||
|
htmlspecialchars($lot->getStorageLocation()->getFullPath()),
|
||||||
|
htmlspecialchars($lot->getStorageLocation()->getName())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode('<br>', $tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderAmount(Part $context): string
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,63 +139,11 @@ final class PartsDataTable implements DataTableTypeInterface
|
||||||
->add('storelocation', TextColumn::class, [
|
->add('storelocation', TextColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.storeLocations'),
|
'label' => $this->translator->trans('part.table.storeLocations'),
|
||||||
'orderField' => 'storelocations.name',
|
'orderField' => 'storelocations.name',
|
||||||
'render' => function ($value, Part $context): string {
|
'render' => fn ($value, Part $context) => $this->partDataTableHelper->renderStorageLocations($context),
|
||||||
$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);
|
|
||||||
},
|
|
||||||
], alias: 'storage_location')
|
], alias: 'storage_location')
|
||||||
->add('amount', TextColumn::class, [
|
->add('amount', TextColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.amount'),
|
'label' => $this->translator->trans('part.table.amount'),
|
||||||
'render' => function ($value, Part $context) {
|
'render' => fn ($value, Part $context) => $this->partDataTableHelper->renderAmount($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;
|
|
||||||
},
|
|
||||||
'orderField' => 'amountSum'
|
'orderField' => 'amountSum'
|
||||||
])
|
])
|
||||||
->add('minamount', TextColumn::class, [
|
->add('minamount', TextColumn::class, [
|
||||||
|
|
|
@ -151,6 +151,28 @@ class ProjectBomEntriesDataTable implements DataTableTypeInterface
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
|
->add('instockAmount', TextColumn::class, [
|
||||||
|
'label' => 'project.bom.instockAmount',
|
||||||
|
'visible' => false,
|
||||||
|
'render' => function ($value, ProjectBOMEntry $context) {
|
||||||
|
if ($context->getPart()) {
|
||||||
|
return $this->partDataTableHelper->renderAmount($context->getPart());
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
])
|
||||||
|
->add('storageLocations', TextColumn::class, [
|
||||||
|
'label' => 'part.table.storeLocations',
|
||||||
|
'visible' => false,
|
||||||
|
'render' => function ($value, ProjectBOMEntry $context) {
|
||||||
|
if ($context->getPart()) {
|
||||||
|
return $this->partDataTableHelper->renderStorageLocations($context->getPart());
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
->add('addedDate', LocaleDateTimeColumn::class, [
|
->add('addedDate', LocaleDateTimeColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.addedDate'),
|
'label' => $this->translator->trans('part.table.addedDate'),
|
||||||
|
|
|
@ -11951,5 +11951,11 @@ Please note, that you can not impersonate a disabled user. If you try you will g
|
||||||
<target>Vendor barcode (configured in part lot)</target>
|
<target>Vendor barcode (configured in part lot)</target>
|
||||||
</segment>
|
</segment>
|
||||||
</unit>
|
</unit>
|
||||||
|
<unit id="ilCTQni" name="project.bom.instockAmount">
|
||||||
|
<segment>
|
||||||
|
<source>project.bom.instockAmount</source>
|
||||||
|
<target>Stocked amount</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue