Округление цены и количества в сетьерах Item до 2 и 3 зн после запятой соответственно

Также переименованы исключения о слишком высоких цене и сумме предмета расчёта, чтобы избежать конфликтов с другими
This commit is contained in:
2021-12-03 23:52:41 +08:00
parent d533164d1b
commit 65ec639014
4 changed files with 61 additions and 60 deletions

View File

@@ -25,9 +25,9 @@ use AtolOnline\Exceptions\{
NegativeItemExciseException,
NegativeItemPriceException,
NegativeItemQuantityException,
TooHighItemPriceException,
TooHighItemQuantityException,
TooHighPriceException,
TooHighSumException,
TooHighItemSumException,
TooLongItemCodeException,
TooLongItemNameException,
TooLongMeasurementUnitException,
@@ -124,7 +124,7 @@ final class Item extends Entity
* @param float|null $price Цена за одну единицу
* @param float|null $quantity Количество
* @throws TooLongItemNameException
* @throws TooHighPriceException
* @throws TooHighItemPriceException
* @throws TooManyException
* @throws NegativeItemPriceException
* @throws EmptyItemNameException
@@ -184,21 +184,22 @@ final class Item extends Entity
/**
* Устанавливает цену в рублях
*
* @param float $rubles
* @param float $price
* @return $this
* @throws NegativeItemPriceException
* @throws TooHighPriceException
* @throws TooHighSumException
* @throws TooHighItemPriceException
* @throws TooHighItemSumException
*/
public function setPrice(float $rubles): self
public function setPrice(float $price): self
{
if ($rubles > Constraints::MAX_COUNT_ITEM_PRICE) {
throw new TooHighPriceException($this->getName(), $rubles);
$price = round($price, 2);
if ($price > Constraints::MAX_COUNT_ITEM_PRICE) {
throw new TooHighItemPriceException($this->getName(), $price);
}
if ($rubles < 0) {
throw new NegativeItemPriceException($this->getName(), $rubles);
if ($price < 0) {
throw new NegativeItemPriceException($this->getName(), $price);
}
$this->price = $rubles;
$this->price = $price;
$this->getVat()?->setSum($this->getSum());
return $this;
}
@@ -220,7 +221,7 @@ final class Item extends Entity
* @return $this
* @throws TooHighItemQuantityException
* @throws NegativeItemQuantityException
* @throws TooHighSumException
* @throws TooHighItemSumException
*/
public function setQuantity(float $quantity): self
{
@@ -240,13 +241,13 @@ final class Item extends Entity
* Возвращает стоимость (цена * количество + акциз)
*
* @return float
* @throws TooHighSumException
* @throws TooHighItemSumException
*/
public function getSum(): float
{
$sum = $this->getPrice() * $this->getQuantity() + (float)$this->getExcise();
if ($sum > Constraints::MAX_COUNT_ITEM_SUM) {
throw new TooHighSumException($this->getName(), $sum);
throw new TooHighItemSumException($this->getName(), $sum);
}
return $sum;
}
@@ -386,7 +387,7 @@ final class Item extends Entity
*
* @param Vat|string|null $vat Объект ставки, одно из значений VatTypes или null для удаления ставки
* @return $this
* @throws TooHighSumException
* @throws TooHighItemSumException
* @throws InvalidEnumValueException
*/
public function setVat(Vat|string|null $vat): self
@@ -490,7 +491,7 @@ final class Item extends Entity
* @param float|null $excise
* @return Item
* @throws NegativeItemExciseException
* @throws TooHighSumException
* @throws TooHighItemSumException
*/
public function setExcise(?float $excise): self
{
@@ -567,7 +568,7 @@ final class Item extends Entity
/**
* @inheritDoc
* @throws TooHighSumException
* @throws TooHighItemSumException
*/
public function jsonSerialize(): array
{

View File

@@ -15,9 +15,9 @@ use AtolOnline\Constants\Constraints;
use AtolOnline\Constants\Ffd105Tags;
/**
* Исключение, возникающее при попытке указать слишком высокую цену (сумму)
* Исключение, возникающее при попытке указать слишком высокую цену (сумму) предмета расчёта
*/
class TooHighPriceException extends TooManyException
class TooHighItemPriceException extends TooManyException
{
protected array $ffd_tags = [Ffd105Tags::ITEM_PRICE];
protected float $max = Constraints::MAX_COUNT_ITEM_PRICE;

View File

@@ -15,12 +15,12 @@ use AtolOnline\Constants\Constraints;
use AtolOnline\Constants\Ffd105Tags;
/**
* Исключение, возникающее при попытке получеиня слишком высокой стоимости
* Исключение, возникающее при попытке получеиня слишком высокой стоимости предмета расчёта
*/
class TooHighSumException extends TooManyException
class TooHighItemSumException extends TooManyException
{
protected array $ffd_tags = [Ffd105Tags::ITEM_SUM];
protected float $max = Constraints::MAX_COUNT_ITEM_PRICE;
protected float $max = Constraints::MAX_COUNT_ITEM_SUM;
/**
* Конструктор