2020-01-11 06:30:25 +00:00
|
|
|
|
<?php
|
2022-12-14 16:19:55 +00:00
|
|
|
|
|
2021-11-18 04:24:30 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
|
|
|
|
* This code is licensed under MIT.
|
|
|
|
|
* Этот код распространяется по лицензии MIT.
|
|
|
|
|
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
|
|
|
|
*/
|
|
|
|
|
|
2022-12-14 16:19:55 +00:00
|
|
|
|
declare(strict_types=1);
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
namespace AtolOnline\Entities;
|
|
|
|
|
|
2022-12-14 16:19:55 +00:00
|
|
|
|
use AtolOnline\Constraints;
|
2021-12-03 10:23:00 +00:00
|
|
|
|
use AtolOnline\Enums\{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
PaymentMethod,
|
|
|
|
|
PaymentObject,
|
|
|
|
|
VatType};
|
2021-12-03 10:23:00 +00:00
|
|
|
|
use AtolOnline\Exceptions\{
|
|
|
|
|
EmptyItemNameException,
|
|
|
|
|
InvalidDeclarationNumberException,
|
|
|
|
|
InvalidOKSMCodeException,
|
|
|
|
|
NegativeItemExciseException,
|
|
|
|
|
NegativeItemPriceException,
|
|
|
|
|
NegativeItemQuantityException,
|
2021-12-03 15:52:41 +00:00
|
|
|
|
TooHighItemPriceException,
|
2021-12-03 10:23:00 +00:00
|
|
|
|
TooHighItemQuantityException,
|
2021-12-03 15:52:41 +00:00
|
|
|
|
TooHighItemSumException,
|
2021-12-03 10:23:00 +00:00
|
|
|
|
TooLongItemCodeException,
|
|
|
|
|
TooLongItemNameException,
|
|
|
|
|
TooLongMeasurementUnitException,
|
|
|
|
|
TooLongUserdataException,
|
2022-12-14 16:19:55 +00:00
|
|
|
|
TooManyException};
|
2020-01-11 06:30:25 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Предмет расчёта (товар, услуга)
|
|
|
|
|
*
|
2021-11-27 16:57:07 +00:00
|
|
|
|
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 21-30
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-03 10:24:21 +00:00
|
|
|
|
final class Item extends Entity
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @var string|null Единица измерения (1197)
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
protected ?string $measurement_unit = null;
|
2021-11-22 06:51:10 +00:00
|
|
|
|
|
2021-12-03 03:52:40 +00:00
|
|
|
|
/**
|
|
|
|
|
* @var string|null Код товара (1162)
|
|
|
|
|
*/
|
|
|
|
|
protected ?string $code = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string|null Код товара (1162) в форматированной шестнадцатиричной форме
|
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
protected ?string $codeHex = null;
|
2021-12-03 03:52:40 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2022-12-14 16:19:55 +00:00
|
|
|
|
* @var PaymentMethod|null Признак способа расчёта (1214)
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
protected ?PaymentMethod $paymentMethod = null;
|
2021-12-01 12:11:08 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2022-12-14 16:19:55 +00:00
|
|
|
|
* @var PaymentObject|null Признак предмета расчёта (1212)
|
2021-12-01 12:11:08 +00:00
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
protected ?PaymentObject $paymentObject = null;
|
2021-12-01 12:11:08 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string|null Номер таможенной декларации (1321)
|
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
protected ?string $declarationNumber = null;
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @var Vat|null Ставка НДС
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
protected ?Vat $vat = null;
|
2021-11-22 06:51:10 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @var AgentInfo|null Атрибуты агента
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
protected ?AgentInfo $agentInfo = null;
|
2021-11-22 06:51:10 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @var Supplier|null Атрибуты поставшика
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
protected ?Supplier $supplier = null;
|
2021-11-22 06:51:10 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @var string|null Дополнительный реквизит (1191)
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
protected ?string $userData = null;
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2021-12-01 16:23:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* @var float|null Сумма акциза, включенная в стоимость (1229)
|
|
|
|
|
*/
|
|
|
|
|
protected ?float $excise = null;
|
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @var string|null Цифровой код страны происхождения товара (1230)
|
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
protected ?string $countryCode = null;
|
2021-12-01 12:11:08 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Конструктор
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
2022-12-14 16:19:55 +00:00
|
|
|
|
* @param string|null $name Наименование (1030)
|
|
|
|
|
* @param float|null $price Цена в рублях (с учётом скидок и наценок) (1079)
|
|
|
|
|
* @param float|null $quantity Количество/вес (1023)
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @throws TooLongItemNameException
|
2021-12-03 15:52:41 +00:00
|
|
|
|
* @throws TooHighItemPriceException
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @throws TooManyException
|
|
|
|
|
* @throws NegativeItemPriceException
|
|
|
|
|
* @throws EmptyItemNameException
|
|
|
|
|
* @throws NegativeItemQuantityException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
public function __construct(
|
2022-12-14 16:19:55 +00:00
|
|
|
|
protected ?string $name = null,
|
|
|
|
|
protected ?float $price = null,
|
|
|
|
|
protected ?float $quantity = null,
|
2020-01-11 06:30:25 +00:00
|
|
|
|
) {
|
2021-12-01 12:11:08 +00:00
|
|
|
|
!is_null($name) && $this->setName($name);
|
|
|
|
|
!is_null($price) && $this->setPrice($price);
|
|
|
|
|
!is_null($quantity) && $this->setQuantity($quantity);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-11-22 06:51:10 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* Возвращает наименование
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2021-11-18 04:24:30 +00:00
|
|
|
|
public function getName(): string
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
|
|
|
|
return $this->name;
|
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* Устаналивает наименование
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
|
|
|
|
* @param string $name Наименование
|
|
|
|
|
* @return $this
|
2021-12-03 10:23:00 +00:00
|
|
|
|
* @throws TooLongItemNameException
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @throws EmptyItemNameException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-11-18 04:24:30 +00:00
|
|
|
|
public function setName(string $name): self
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
if (mb_strlen($name = trim($name)) > Constraints::MAX_LENGTH_ITEM_NAME) {
|
2021-12-01 12:11:08 +00:00
|
|
|
|
throw new TooLongItemNameException($name);
|
|
|
|
|
}
|
2022-12-14 16:19:55 +00:00
|
|
|
|
empty($name) && throw new EmptyItemNameException();
|
2020-01-11 06:30:25 +00:00
|
|
|
|
$this->name = $name;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
2021-11-22 06:51:10 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* Возвращает цену в рублях
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
|
|
|
|
* @return float
|
|
|
|
|
*/
|
2021-11-18 04:24:30 +00:00
|
|
|
|
public function getPrice(): float
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2021-12-01 12:11:08 +00:00
|
|
|
|
return $this->price;
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* Устанавливает цену в рублях
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
2021-12-03 15:52:41 +00:00
|
|
|
|
* @param float $price
|
2020-01-11 06:30:25 +00:00
|
|
|
|
* @return $this
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @throws NegativeItemPriceException
|
2021-12-03 15:52:41 +00:00
|
|
|
|
* @throws TooHighItemPriceException
|
|
|
|
|
* @throws TooHighItemSumException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-03 15:52:41 +00:00
|
|
|
|
public function setPrice(float $price): self
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2021-12-03 15:52:41 +00:00
|
|
|
|
$price = round($price, 2);
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$price > Constraints::MAX_COUNT_ITEM_PRICE && throw new TooHighItemPriceException($this->getName(), $price);
|
|
|
|
|
$price < 0 && throw new NegativeItemPriceException($this->getName(), $price);
|
2021-12-03 15:52:41 +00:00
|
|
|
|
$this->price = $price;
|
2021-12-03 10:24:00 +00:00
|
|
|
|
$this->getVat()?->setSum($this->getSum());
|
2020-01-11 06:30:25 +00:00
|
|
|
|
return $this;
|
|
|
|
|
}
|
2021-11-22 06:51:10 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* Возвращает количество
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
|
|
|
|
* @return float
|
|
|
|
|
*/
|
|
|
|
|
public function getQuantity(): float
|
|
|
|
|
{
|
|
|
|
|
return $this->quantity;
|
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* Устанавливает количество
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @param float $quantity Количество
|
2020-01-11 06:30:25 +00:00
|
|
|
|
* @return $this
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @throws TooHighItemQuantityException
|
|
|
|
|
* @throws NegativeItemQuantityException
|
2021-12-03 15:52:41 +00:00
|
|
|
|
* @throws TooHighItemSumException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
public function setQuantity(float $quantity): self
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
|
|
|
|
$quantity = round($quantity, 3);
|
2021-12-01 12:11:08 +00:00
|
|
|
|
if ($quantity > Constraints::MAX_COUNT_ITEM_QUANTITY) {
|
|
|
|
|
throw new TooHighItemQuantityException($this->getName(), $quantity);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$quantity < 0 && throw new NegativeItemQuantityException($this->getName(), $quantity);
|
2021-12-01 12:11:08 +00:00
|
|
|
|
$this->quantity = $quantity;
|
2021-12-03 10:24:00 +00:00
|
|
|
|
$this->getVat()?->setSum($this->getSum());
|
2020-01-11 06:30:25 +00:00
|
|
|
|
return $this;
|
|
|
|
|
}
|
2021-11-22 06:51:10 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 16:23:37 +00:00
|
|
|
|
* Возвращает стоимость (цена * количество + акциз)
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @return float
|
2021-12-03 15:52:41 +00:00
|
|
|
|
* @throws TooHighItemSumException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
public function getSum(): float
|
|
|
|
|
{
|
2021-12-01 16:23:37 +00:00
|
|
|
|
$sum = $this->getPrice() * $this->getQuantity() + (float)$this->getExcise();
|
2021-12-03 03:52:40 +00:00
|
|
|
|
if ($sum > Constraints::MAX_COUNT_ITEM_SUM) {
|
2021-12-03 15:52:41 +00:00
|
|
|
|
throw new TooHighItemSumException($this->getName(), $sum);
|
2021-12-01 12:11:08 +00:00
|
|
|
|
}
|
|
|
|
|
return $sum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Возвращает заданную единицу измерения количества
|
|
|
|
|
*
|
|
|
|
|
* @return string|null
|
|
|
|
|
*/
|
|
|
|
|
public function getMeasurementUnit(): ?string
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
|
|
|
|
return $this->measurement_unit;
|
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* Устанавливает единицу измерения количества
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @param string|null $measurement_unit
|
2020-01-11 06:30:25 +00:00
|
|
|
|
* @return $this
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @throws TooLongMeasurementUnitException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
public function setMeasurementUnit(?string $measurement_unit): self
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2021-12-01 12:11:08 +00:00
|
|
|
|
$measurement_unit = trim((string)$measurement_unit);
|
2021-11-18 04:24:30 +00:00
|
|
|
|
if (mb_strlen($measurement_unit) > Constraints::MAX_LENGTH_MEASUREMENT_UNIT) {
|
2021-12-01 12:11:08 +00:00
|
|
|
|
throw new TooLongMeasurementUnitException($measurement_unit);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-12-01 12:11:08 +00:00
|
|
|
|
$this->measurement_unit = $measurement_unit ?: null;
|
2020-01-11 06:30:25 +00:00
|
|
|
|
return $this;
|
|
|
|
|
}
|
2021-11-22 06:51:10 +00:00
|
|
|
|
|
2021-12-03 03:52:40 +00:00
|
|
|
|
/**
|
|
|
|
|
* Возвращает установленный код товара
|
|
|
|
|
*
|
|
|
|
|
* @return string|null
|
|
|
|
|
*/
|
|
|
|
|
public function getCode(): ?string
|
|
|
|
|
{
|
|
|
|
|
return $this->code;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Возвращает шестнадцатиричное представление кода товара
|
|
|
|
|
*
|
|
|
|
|
* @return string|null
|
|
|
|
|
*/
|
|
|
|
|
public function getCodeHex(): ?string
|
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
return $this->codeHex;
|
2021-12-03 03:52:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Устанавливает код товара
|
|
|
|
|
*
|
|
|
|
|
* @param string|null $code
|
|
|
|
|
* @return Item
|
|
|
|
|
* @throws TooLongItemCodeException
|
|
|
|
|
*/
|
|
|
|
|
public function setCode(?string $code): self
|
|
|
|
|
{
|
|
|
|
|
$hex_string = null;
|
|
|
|
|
$code = trim((string)$code);
|
|
|
|
|
if (mb_strlen($code) > Constraints::MAX_LENGTH_ITEM_CODE) {
|
|
|
|
|
throw new TooLongItemCodeException($this->getName(), $code);
|
|
|
|
|
}
|
|
|
|
|
if (!empty($code)) {
|
|
|
|
|
$hex = bin2hex($code);
|
|
|
|
|
$hex_string = trim(preg_replace('/([\dA-Fa-f]{2})/', '$1 ', $hex));
|
|
|
|
|
}
|
|
|
|
|
$this->code = $code ?: null;
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->codeHex = $hex_string ?: null;
|
2021-12-03 03:52:40 +00:00
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* Возвращает признак способа оплаты
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
2022-12-14 16:19:55 +00:00
|
|
|
|
* @return PaymentMethod|null
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
public function getPaymentMethod(): ?PaymentMethod
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
return $this->paymentMethod;
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-11-22 06:51:10 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* Устанавливает признак способа оплаты
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
2022-12-14 16:19:55 +00:00
|
|
|
|
* @param PaymentMethod|null $paymentMethod Признак способа оплаты
|
2020-01-11 06:30:25 +00:00
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
public function setPaymentMethod(?PaymentMethod $paymentMethod): self
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->paymentMethod = $paymentMethod;
|
2020-01-11 06:30:25 +00:00
|
|
|
|
return $this;
|
|
|
|
|
}
|
2021-11-22 06:51:10 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* Возвращает признак предмета расчёта
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
2022-12-14 16:19:55 +00:00
|
|
|
|
* @return PaymentObject|null
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
public function getPaymentObject(): ?PaymentObject
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
return $this->paymentObject;
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-11-22 06:51:10 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* Устанавливает признак предмета расчёта
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
2022-12-14 16:19:55 +00:00
|
|
|
|
* @param PaymentObject|null $paymentObject Признак предмета расчёта
|
2020-01-11 06:30:25 +00:00
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
public function setPaymentObject(?PaymentObject $paymentObject): self
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->paymentObject = $paymentObject;
|
2020-01-11 06:30:25 +00:00
|
|
|
|
return $this;
|
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Возвращает ставку НДС
|
|
|
|
|
*
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @return Vat|null
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
public function getVat(): ?Vat
|
|
|
|
|
{
|
|
|
|
|
return $this->vat;
|
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Устанавливает ставку НДС
|
|
|
|
|
*
|
2022-12-14 16:19:55 +00:00
|
|
|
|
* @param Vat | VatType | null $vat Объект ставки, одно из значений VatTypes или null для удаления ставки
|
2020-01-11 06:30:25 +00:00
|
|
|
|
* @return $this
|
2021-12-03 15:52:41 +00:00
|
|
|
|
* @throws TooHighItemSumException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
public function setVat(Vat | VatType | null $vat): self
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
if (is_null($vat)) {
|
|
|
|
|
$this->vat = null;
|
2021-12-01 12:11:08 +00:00
|
|
|
|
} elseif ($vat instanceof Vat) {
|
|
|
|
|
$vat->setSum($this->getSum());
|
2021-12-01 16:23:37 +00:00
|
|
|
|
$this->vat = $vat;
|
2022-12-14 16:19:55 +00:00
|
|
|
|
} else {
|
|
|
|
|
$this->vat = new Vat($vat, $this->getSum());
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-12-01 12:11:08 +00:00
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Возвращает установленный объект атрибутов агента
|
|
|
|
|
*
|
|
|
|
|
* @return AgentInfo|null
|
|
|
|
|
*/
|
|
|
|
|
public function getAgentInfo(): ?AgentInfo
|
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
return $this->agentInfo;
|
2021-12-01 12:11:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Устанавливает атрибуты агента
|
|
|
|
|
*
|
2022-12-14 16:19:55 +00:00
|
|
|
|
* @param AgentInfo|null $agentInfo
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @return Item
|
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
public function setAgentInfo(?AgentInfo $agentInfo): self
|
2021-12-01 12:11:08 +00:00
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->agentInfo = $agentInfo;
|
2021-12-01 12:11:08 +00:00
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Возвращает установленного поставщика
|
|
|
|
|
*
|
|
|
|
|
* @return Supplier|null
|
|
|
|
|
*/
|
|
|
|
|
public function getSupplier(): ?Supplier
|
|
|
|
|
{
|
|
|
|
|
return $this->supplier;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Устанавливает поставщика
|
|
|
|
|
*
|
|
|
|
|
* @param Supplier|null $supplier
|
|
|
|
|
* @return Item
|
|
|
|
|
*/
|
|
|
|
|
public function setSupplier(?Supplier $supplier): self
|
|
|
|
|
{
|
|
|
|
|
$this->supplier = $supplier;
|
2020-01-11 06:30:25 +00:00
|
|
|
|
return $this;
|
|
|
|
|
}
|
2021-11-22 06:51:10 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* Возвращает дополнительный реквизит
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
|
|
|
|
* @return string|null
|
|
|
|
|
*/
|
|
|
|
|
public function getUserData(): ?string
|
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
return $this->userData;
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* Устанавливает дополнительный реквизит
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
2022-12-14 16:19:55 +00:00
|
|
|
|
* @param string|null $userData Дополнительный реквизит
|
2020-01-11 06:30:25 +00:00
|
|
|
|
* @return $this
|
2021-12-03 10:23:00 +00:00
|
|
|
|
* @throws TooLongUserdataException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
public function setUserData(?string $userData): self
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$userData = trim((string)$userData);
|
|
|
|
|
if (mb_strlen($userData) > Constraints::MAX_LENGTH_USER_DATA) {
|
|
|
|
|
throw new TooLongUserdataException($userData);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->userData = $userData ?: null;
|
2020-01-11 06:30:25 +00:00
|
|
|
|
return $this;
|
|
|
|
|
}
|
2021-11-22 06:51:10 +00:00
|
|
|
|
|
2021-12-01 16:23:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* Возвращает установленную сумму акциза
|
|
|
|
|
*
|
|
|
|
|
* @return float|null
|
|
|
|
|
*/
|
|
|
|
|
public function getExcise(): ?float
|
|
|
|
|
{
|
|
|
|
|
return $this->excise;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Устанавливает сумму акциза
|
|
|
|
|
*
|
|
|
|
|
* @param float|null $excise
|
|
|
|
|
* @return Item
|
|
|
|
|
* @throws NegativeItemExciseException
|
2021-12-03 15:52:41 +00:00
|
|
|
|
* @throws TooHighItemSumException
|
2021-12-01 16:23:37 +00:00
|
|
|
|
*/
|
2021-12-03 10:23:00 +00:00
|
|
|
|
public function setExcise(?float $excise): self
|
2021-12-01 16:23:37 +00:00
|
|
|
|
{
|
|
|
|
|
if ($excise < 0) {
|
|
|
|
|
throw new NegativeItemExciseException($this->getName(), $excise);
|
|
|
|
|
}
|
|
|
|
|
$this->excise = $excise;
|
2021-12-03 10:24:00 +00:00
|
|
|
|
$this->getVat()?->setSum($this->getSum());
|
2021-12-01 16:23:37 +00:00
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* Возвращает установленный код страны происхождения товара
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @return string|null
|
|
|
|
|
* @see https://ru.wikipedia.org/wiki/Общероссийский_классификатор_стран_мира
|
|
|
|
|
* @see https://classifikators.ru/oksm
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
public function getCountryCode(): ?string
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
return $this->countryCode;
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* Устанавливает код страны происхождения товара
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
2022-12-14 16:19:55 +00:00
|
|
|
|
* @param string|null $countryCode
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @return Item
|
|
|
|
|
* @throws InvalidOKSMCodeException
|
|
|
|
|
* @see https://classifikators.ru/oksm
|
|
|
|
|
* @see https://ru.wikipedia.org/wiki/Общероссийский_классификатор_стран_мира
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
public function setCountryCode(?string $countryCode): self
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$countryCode = trim((string)$countryCode);
|
|
|
|
|
if (preg_match(Constraints::PATTERN_OKSM_CODE, $countryCode) != 1) {
|
|
|
|
|
throw new InvalidOKSMCodeException($countryCode);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->countryCode = $countryCode ?: null;
|
2021-12-01 12:11:08 +00:00
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Возвращает установленный код таможенной декларации
|
|
|
|
|
*
|
|
|
|
|
* @return string|null
|
|
|
|
|
*/
|
|
|
|
|
public function getDeclarationNumber(): ?string
|
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
return $this->declarationNumber;
|
2021-12-01 12:11:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Устанавливает код таможенной декларации
|
|
|
|
|
*
|
2022-12-14 16:19:55 +00:00
|
|
|
|
* @param string|null $declarationNumber
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @return Item
|
|
|
|
|
* @throws InvalidDeclarationNumberException
|
|
|
|
|
*/
|
2022-12-14 16:19:55 +00:00
|
|
|
|
public function setDeclarationNumber(?string $declarationNumber): self
|
2021-12-01 12:11:08 +00:00
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
if (is_string($declarationNumber)) {
|
|
|
|
|
$declarationNumber = trim($declarationNumber);
|
|
|
|
|
$is_short = mb_strlen($declarationNumber) < Constraints::MIN_LENGTH_DECLARATION_NUMBER;
|
|
|
|
|
$is_long = mb_strlen($declarationNumber) > Constraints::MAX_LENGTH_DECLARATION_NUMBER;
|
|
|
|
|
if ($is_short || $is_long) {
|
|
|
|
|
throw new InvalidDeclarationNumberException($declarationNumber);
|
2021-12-01 12:11:08 +00:00
|
|
|
|
}
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->declarationNumber = $declarationNumber;
|
2021-12-01 12:11:08 +00:00
|
|
|
|
return $this;
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-11-22 06:51:10 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2021-12-03 15:52:41 +00:00
|
|
|
|
* @throws TooHighItemSumException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
public function jsonSerialize(): array
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
|
|
|
|
$json = [
|
2021-12-01 12:11:08 +00:00
|
|
|
|
'name' => $this->getName(),
|
|
|
|
|
'price' => $this->getPrice(),
|
|
|
|
|
'quantity' => $this->getQuantity(),
|
|
|
|
|
'sum' => $this->getSum(),
|
2020-01-11 06:30:25 +00:00
|
|
|
|
];
|
2021-12-01 16:23:37 +00:00
|
|
|
|
!is_null($this->getMeasurementUnit()) && $json['measurement_unit'] = $this->getMeasurementUnit();
|
2021-12-03 03:52:40 +00:00
|
|
|
|
!is_null($this->getCodeHex()) && $json['nomenclature_code'] = $this->getCodeHex();
|
2021-12-01 16:23:37 +00:00
|
|
|
|
!is_null($this->getPaymentMethod()) && $json['payment_method'] = $this->getPaymentMethod();
|
|
|
|
|
!is_null($this->getPaymentObject()) && $json['payment_object'] = $this->getPaymentObject();
|
|
|
|
|
!is_null($this->getDeclarationNumber()) && $json['declaration_number'] = $this->getDeclarationNumber();
|
2021-12-01 12:11:08 +00:00
|
|
|
|
$this->getVat()?->jsonSerialize() && $json['vat'] = $this->getVat()->jsonSerialize();
|
|
|
|
|
$this->getAgentInfo()?->jsonSerialize() && $json['agent_info'] = $this->getAgentInfo()->jsonSerialize();
|
|
|
|
|
$this->getSupplier()?->jsonSerialize() && $json['supplier_info'] = $this->getSupplier()->jsonSerialize();
|
2021-12-01 16:23:37 +00:00
|
|
|
|
!is_null($this->getUserData()) && $json['user_data'] = $this->getUserData();
|
|
|
|
|
!is_null($this->getExcise()) && $json['excise'] = $this->getExcise();
|
|
|
|
|
!is_null($this->getCountryCode()) && $json['country_code'] = $this->getCountryCode();
|
2020-01-11 06:30:25 +00:00
|
|
|
|
return $json;
|
|
|
|
|
}
|
|
|
|
|
}
|