File: D:/HostingSpaces/SBogers10/shop.komma.nl/app/Vat/Resources/VatCalculationResource.php
<?php
namespace App\Vat\Resources;
use Illuminate\Contracts\Support\Arrayable;
use Komma\KMS\Globalization\RegionInfoInterface;
class VatCalculationResource implements Arrayable, \JsonSerializable
{
/** @var int $priceExVat */
private $priceExVat = 0;
/** @var string $priceExVatFormatted */
private $priceExVatFormatted = '';
/** @var int $priceExVatForNumberInput */
private $priceExVatForNumberInput = 0;
/** @var int $priceIncVat */
private $priceIncVat = 0;
/** @var string $priceIncVatFormatted */
private $priceIncVatFormatted = '';
/** @var int $priceIncVatForNumberInput */
private $priceIncVatForNumberInput = 0;
/** @var int $vatAmount */
private $vatAmount = 0;
/** @var string $vatAmountFormatted */
private $vatAmountFormatted = '';
/** @var int $vatAmountForNumberInput */
private $vatAmountForNumberInput = 0;
/** @var */
private $vatPercentage = 0;
/** @var RegionInfoInterface */
private $regionInfo;
public function __construct()
{
$this->regionInfo = app(RegionInfoInterface::class);
}
private function updateFormattedValues()
{
$currencySymbol = $this->regionInfo->getCurrencySymbol();
$this->priceExVatFormatted = $currencySymbol.' '.$this->regionInfo->getNumberFormat()->centsToCurrency($this->priceExVat, true, true);
$this->priceExVatForNumberInput = $this->regionInfo->getNumberFormat()->centsToCurrency($this->priceExVat, true, true);
$this->priceExVatForNumberInput = str_replace($this->regionInfo->getNumberFormat()->getCurrencyGroupSeparator(), '', $this->priceExVatForNumberInput);
$this->priceExVatForNumberInput = str_replace($this->regionInfo->getNumberFormat()->getCurrencyDecimalSeparator(), '.', $this->priceExVatForNumberInput);
$this->priceIncVatFormatted = $currencySymbol.' '.$this->regionInfo->getNumberFormat()->centsToCurrency($this->priceIncVat, true, true);
$this->priceIncVatForNumberInput = $this->regionInfo->getNumberFormat()->centsToCurrency($this->priceIncVat, true, true);
$this->priceIncVatForNumberInput = str_replace($this->regionInfo->getNumberFormat()->getCurrencyGroupSeparator(), '', $this->priceIncVatForNumberInput);
$this->priceIncVatForNumberInput = str_replace($this->regionInfo->getNumberFormat()->getCurrencyDecimalSeparator(), '.', $this->priceIncVatForNumberInput);
$this->vatAmountFormatted = $currencySymbol.' '.$this->regionInfo->getNumberFormat()->centsToCurrency($this->vatAmount, true, true);
$this->vatAmountForNumberInput = $this->regionInfo->getNumberFormat()->centsToCurrency($this->vatAmount, true, true);
$this->vatAmountForNumberInput = str_replace($this->regionInfo->getNumberFormat()->getCurrencyGroupSeparator(), '', $this->vatAmountForNumberInput);
$this->vatAmountForNumberInput = str_replace($this->regionInfo->getNumberFormat()->getCurrencyDecimalSeparator(), '.', $this->vatAmountForNumberInput);
}
/**
* Get the instance as an array.
*
* @return array
*/
public function toArray()
{
return [
'priceExVat' => $this->priceExVat,
'priceExVatFormatted' => $this->priceExVatFormatted,
'priceExVatForNumberInput' => $this->priceExVatForNumberInput,
'vatPercentage' => $this->vatPercentage,
'priceIncVat' => $this->priceIncVat,
'priceIncVatFormatted' => $this->priceIncVatFormatted,
'priceIncVatForNumberInput' => $this->priceIncVatForNumberInput,
'vatAmount' => $this->vatAmount,
'vatAmountFormatted' => $this->vatAmountFormatted,
'vatAmountForNumberInput' => $this->vatAmountForNumberInput,
'regionDisplayName' => $this->regionInfo->getNeutralRegionInfo()->getDisplayName(),
];
}
/**
* Specify data which should be serialized to JSON
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize()
{
return $this->toArray();
}
/**
* @return int
*/
public function getPriceExVat(): int
{
return $this->priceExVat;
}
/**
* @param int $priceExVat
* @return VatCalculationResource
*/
public function setPriceExVat(int $priceExVat): VatCalculationResource
{
$this->priceExVat = $priceExVat;
$this->updateFormattedValues();
return $this;
}
/**
* @return string
*/
public function getPriceExVatFormatted(): string
{
return $this->priceExVatFormatted;
}
/**
* @return int
*/
public function getPriceExVatForNumberInput(): int
{
return $this->priceExVatForNumberInput;
}
/**
* @return int
*/
public function getPriceIncVat(): int
{
return $this->priceIncVat;
}
/**
* @param int $priceIncVat
* @return VatCalculationResource
*/
public function setPriceIncVat(int $priceIncVat): VatCalculationResource
{
$this->priceIncVat = $priceIncVat;
$this->updateFormattedValues();
return $this;
}
/**
* @return string
*/
public function getPriceIncVatFormatted(): string
{
return $this->priceIncVatFormatted;
}
/**
* @return int
*/
public function getPriceIncVatForNumberInput(): int
{
return $this->priceIncVatForNumberInput;
}
/**
* @return int
*/
public function getVatAmount(): int
{
return $this->vatAmount;
}
/**
* @param int $vatAmount
* @return VatCalculationResource
*/
public function setVatAmount(int $vatAmount): VatCalculationResource
{
$this->vatAmount = $vatAmount;
$this->updateFormattedValues();
return $this;
}
/**
* @return string
*/
public function getVatAmountFormatted(): string
{
return $this->vatAmountFormatted;
}
/**
* @return int
*/
public function getVatAmountForNumberInput(): int
{
return $this->vatAmountForNumberInput;
}
/**
* @return mixed
*/
public function getVatPercentage()
{
return $this->vatPercentage;
}
/**
* @param mixed $vatPercentage
* @return VatCalculationResource
*/
public function setVatPercentage($vatPercentage)
{
$this->vatPercentage = $vatPercentage;
return $this;
}
/**
* @return RegionInfoInterface
*/
public function getRegionInfo(): RegionInfoInterface
{
return $this->regionInfo;
}
/**
* @param RegionInfoInterface $regionInfo
* @return VatCalculationResource
*/
public function setRegionInfo(RegionInfoInterface $regionInfo): VatCalculationResource
{
$this->regionInfo = $regionInfo;
return $this;
}
}