mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Format amounts in part tables using the partUnit
This commit is contained in:
parent
718e472e04
commit
a6f16315ee
2 changed files with 13 additions and 4 deletions
|
@ -38,6 +38,7 @@ use App\Entity\Parts\Part;
|
|||
use App\Entity\Parts\PartLot;
|
||||
use App\Entity\Parts\Storelocation;
|
||||
use App\Entity\Parts\Supplier;
|
||||
use App\Services\AmountFormatter;
|
||||
use App\Services\EntityURLGenerator;
|
||||
use App\Services\ToolsTreeBuilder;
|
||||
use App\Services\TreeBuilder;
|
||||
|
@ -60,12 +61,15 @@ class PartsDataTable implements DataTableTypeInterface
|
|||
protected $urlGenerator;
|
||||
protected $translator;
|
||||
protected $treeBuilder;
|
||||
protected $amountFormatter;
|
||||
|
||||
public function __construct(EntityURLGenerator $urlGenerator, TranslatorInterface $translator, TreeBuilder $treeBuilder)
|
||||
public function __construct(EntityURLGenerator $urlGenerator, TranslatorInterface $translator,
|
||||
TreeBuilder $treeBuilder, AmountFormatter $amountFormatter)
|
||||
{
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->translator = $translator;
|
||||
$this->treeBuilder = $treeBuilder;
|
||||
$this->amountFormatter = $amountFormatter;
|
||||
}
|
||||
|
||||
protected function getQuery(QueryBuilder $builder)
|
||||
|
@ -195,11 +199,17 @@ class PartsDataTable implements DataTableTypeInterface
|
|||
])
|
||||
->add('amount', TextColumn::class, [
|
||||
'label' => $this->translator->trans('part.table.amount'),
|
||||
'propertyPath' => 'amountSum'
|
||||
'render' => function ($value, Part $context) {
|
||||
$amount = $context->getAmountSum();
|
||||
return $this->amountFormatter->format($amount, $context->getPartUnit());
|
||||
}
|
||||
])
|
||||
->add('minamount', TextColumn::class, [
|
||||
'label' => $this->translator->trans('part.table.minamount'),
|
||||
'visible' => false
|
||||
'visible' => false,
|
||||
'render' => function ($value, Part $context) {
|
||||
return $this->amountFormatter->format($value, $context->getPartUnit());
|
||||
}
|
||||
])
|
||||
->add('partUnit', TextColumn::class, [
|
||||
'field' => 'partUnit.name',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue