Show formatted amount values on part info page.

This commit is contained in:
Jan Böhmer 2019-08-26 15:09:05 +02:00
parent f5ebce2a77
commit 5cc08af7b6
5 changed files with 147 additions and 6 deletions

View file

@ -31,6 +31,8 @@ namespace App\Twig;
use App\Entity\Attachments\Attachment;
use App\Entity\Base\DBElement;
use App\Entity\Parts\MeasurementUnit;
use App\Services\AmountFormatter;
use App\Services\EntityURLGenerator;
use App\Services\MoneyFormatter;
use App\Services\SIFormatter;
@ -51,11 +53,12 @@ class AppExtension extends AbstractExtension
protected $treeBuilder;
protected $moneyFormatter;
protected $siformatter;
protected $amountFormatter;
public function __construct(EntityURLGenerator $entityURLGenerator, AdapterInterface $cache,
SerializerInterface $serializer, TreeBuilder $treeBuilder,
MoneyFormatter $moneyFormatter,
SIFormatter $SIFormatter)
SIFormatter $SIFormatter, AmountFormatter $amountFormatter)
{
$this->entityURLGenerator = $entityURLGenerator;
$this->cache = $cache;
@ -63,6 +66,7 @@ class AppExtension extends AbstractExtension
$this->treeBuilder = $treeBuilder;
$this->moneyFormatter = $moneyFormatter;
$this->siformatter = $SIFormatter;
$this->amountFormatter = $amountFormatter;
}
public function getFilters()
@ -72,6 +76,7 @@ class AppExtension extends AbstractExtension
new TwigFilter('bbCode', [$this, 'parseBBCode'], ['pre_escape' => 'html', 'is_safe' => ['html']]),
new TwigFilter('moneyFormat', [$this, 'formatCurrency']),
new TwigFilter('siFormat', [$this, 'siFormat']),
new TwigFilter('amountFormat', [$this, 'amountFormat'])
];
}
@ -127,4 +132,9 @@ class AppExtension extends AbstractExtension
{
return $this->siformatter->format($value, $unit, $decimals);
}
public function amountFormat($value, ?MeasurementUnit $unit, array $options = [])
{
return $this->amountFormatter->format($value, $unit, $options);
}
}