mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-23 18:28:49 +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\PartLot;
|
||||||
use App\Entity\Parts\Storelocation;
|
use App\Entity\Parts\Storelocation;
|
||||||
use App\Entity\Parts\Supplier;
|
use App\Entity\Parts\Supplier;
|
||||||
|
use App\Services\AmountFormatter;
|
||||||
use App\Services\EntityURLGenerator;
|
use App\Services\EntityURLGenerator;
|
||||||
use App\Services\ToolsTreeBuilder;
|
use App\Services\ToolsTreeBuilder;
|
||||||
use App\Services\TreeBuilder;
|
use App\Services\TreeBuilder;
|
||||||
|
@ -60,12 +61,15 @@ class PartsDataTable implements DataTableTypeInterface
|
||||||
protected $urlGenerator;
|
protected $urlGenerator;
|
||||||
protected $translator;
|
protected $translator;
|
||||||
protected $treeBuilder;
|
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->urlGenerator = $urlGenerator;
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
$this->treeBuilder = $treeBuilder;
|
$this->treeBuilder = $treeBuilder;
|
||||||
|
$this->amountFormatter = $amountFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getQuery(QueryBuilder $builder)
|
protected function getQuery(QueryBuilder $builder)
|
||||||
|
@ -195,11 +199,17 @@ class PartsDataTable implements DataTableTypeInterface
|
||||||
])
|
])
|
||||||
->add('amount', TextColumn::class, [
|
->add('amount', TextColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.amount'),
|
'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, [
|
->add('minamount', TextColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.minamount'),
|
'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, [
|
->add('partUnit', TextColumn::class, [
|
||||||
'field' => 'partUnit.name',
|
'field' => 'partUnit.name',
|
||||||
|
|
|
@ -105,7 +105,6 @@ class AmountFormatter
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
throw new \InvalidArgumentException('$value must be an numeric value!');
|
throw new \InvalidArgumentException('$value must be an numeric value!');
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = (float) $value;
|
$value = (float) $value;
|
||||||
|
|
||||||
//Find out what options to use
|
//Find out what options to use
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue