Files
2025-08-02 16:30:27 +02:00

91 lines
1.8 KiB
PHP

<?php
namespace KupShop\KupShopBundle\Util\Price;
use KupShop\I18nBundle\Entity\Currency;
class Price
{
/** @var \Decimal */
protected $value;
/** @var Currency */
protected $currency;
/** @var \Decimal */
protected $vat;
protected $source;
public function getSource()
{
return $this->source;
}
public function setSource($source): self
{
$this->source = $source;
return $this;
}
public function __construct(\Decimal $value, Currency $currency, $vat)
{
$this->value = $value;
$this->currency = $currency;
$this->vat = toDecimal($vat);
}
public function setValue(\Decimal $value): void
{
$this->value = $value;
}
public function getValue(): \Decimal
{
return $this->value;
}
public function getCurrency(): Currency
{
return $this->currency;
}
public function getVat(): \Decimal
{
return $this->vat;
}
public function getPriceWithVat($round = true): \Decimal
{
$price = $this->value->addVat($this->vat);
if ($round) {
return $this->round($price);
}
return $price;
}
public function getPriceWithoutVat($round = true): \Decimal
{
$price = $this->getPriceWithVat($round);
return $price->removeVat($this->vat);
}
protected function round(\Decimal $price): \Decimal
{
return roundPrice($price, null, null, null, $this->currency, source: $this->getSource());
}
public function getVatValue(): \Decimal
{
return $this->getPriceWithVat()->sub($this->getPriceWithoutVat());
}
public function getVatPrice(): Price
{
return new Price($this->getVatValue(), $this->getCurrency(), \DecimalConstants::zero());
}
}