2020-01-11 06:30:25 +00:00
|
|
|
|
<?php
|
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
|
|
|
|
|
*/
|
|
|
|
|
|
2021-11-18 04:24:30 +00:00
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
namespace AtolOnline\Entities;
|
|
|
|
|
|
2021-11-18 04:24:30 +00:00
|
|
|
|
use AtolOnline\{
|
|
|
|
|
Constants\Constraints,
|
2021-12-01 12:11:08 +00:00
|
|
|
|
Enums\PaymentMethods,
|
|
|
|
|
Enums\PaymentObjects,
|
|
|
|
|
Enums\VatTypes,
|
|
|
|
|
Exceptions\EmptyItemNameException,
|
|
|
|
|
Exceptions\InvalidDeclarationNumberException,
|
|
|
|
|
Exceptions\InvalidEnumValueException,
|
|
|
|
|
Exceptions\InvalidOKSMCodeException,
|
|
|
|
|
Exceptions\NegativeItemPriceException,
|
|
|
|
|
Exceptions\NegativeItemQuantityException,
|
|
|
|
|
Exceptions\TooHighItemQuantityException,
|
2021-11-18 04:24:30 +00:00
|
|
|
|
Exceptions\TooHighPriceException,
|
2021-12-01 12:11:08 +00:00
|
|
|
|
Exceptions\TooHighSumException,
|
2021-11-22 06:51:10 +00:00
|
|
|
|
Exceptions\TooLongItemNameException,
|
2021-12-01 12:11:08 +00:00
|
|
|
|
Exceptions\TooLongMeasurementUnitException,
|
2021-11-22 06:51:10 +00:00
|
|
|
|
Exceptions\TooLongUserdataException,
|
|
|
|
|
Exceptions\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
|
|
|
|
*/
|
2020-04-17 12:10:50 +00:00
|
|
|
|
class Item extends Entity
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
|
|
|
|
/**
|
2021-11-27 16:57:07 +00:00
|
|
|
|
* @var string Наименование (1030)
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-11-18 04:24:30 +00:00
|
|
|
|
protected string $name;
|
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 float Цена в рублях (с учётом скидок и наценок) (1079)
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
protected float $price;
|
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 float Количество/вес (1023)
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
protected float $quantity;
|
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 Единица измерения (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
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @var string|null Признак способа расчёта (1214)
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
protected ?string $payment_method = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string|null Признак предмета расчёта (1212)
|
|
|
|
|
*/
|
|
|
|
|
protected ?string $payment_object = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string|null Номер таможенной декларации (1321)
|
|
|
|
|
*/
|
|
|
|
|
protected ?string $declaration_number = 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
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
protected ?AgentInfo $agent_info = 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
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
protected ?string $user_data = null;
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @var string|null Цифровой код страны происхождения товара (1230)
|
|
|
|
|
*/
|
|
|
|
|
protected ?string $country_code = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Конструктор
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @param string|null $name Наименование
|
|
|
|
|
* @param float|null $price Цена за одну единицу
|
|
|
|
|
* @param float|null $quantity Количество
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @throws TooLongItemNameException
|
|
|
|
|
* @throws TooHighPriceException
|
|
|
|
|
* @throws TooManyException
|
|
|
|
|
* @throws NegativeItemPriceException
|
|
|
|
|
* @throws EmptyItemNameException
|
|
|
|
|
* @throws NegativeItemQuantityException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
|
|
|
|
public function __construct(
|
2021-12-01 12:11:08 +00:00
|
|
|
|
string $name = null,
|
|
|
|
|
float $price = null,
|
|
|
|
|
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-11-22 06:51:10 +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
|
|
|
|
{
|
|
|
|
|
$name = trim($name);
|
2021-11-18 04:24:30 +00:00
|
|
|
|
if (mb_strlen($name) > Constraints::MAX_LENGTH_ITEM_NAME) {
|
2021-12-01 12:11:08 +00:00
|
|
|
|
throw new TooLongItemNameException($name);
|
|
|
|
|
}
|
|
|
|
|
if (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-01 12:11:08 +00:00
|
|
|
|
* @param float $rubles
|
2020-01-11 06:30:25 +00:00
|
|
|
|
* @return $this
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @throws NegativeItemPriceException
|
|
|
|
|
* @throws TooHighPriceException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
public function setPrice(float $rubles): self
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2021-12-01 12:11:08 +00:00
|
|
|
|
if ($rubles > Constraints::MAX_COUNT_ITEM_PRICE) {
|
|
|
|
|
throw new TooHighPriceException($this->getName(), $rubles);
|
|
|
|
|
}
|
|
|
|
|
if ($rubles < 0) {
|
|
|
|
|
throw new NegativeItemPriceException($this->getName(), $rubles);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-12-01 12:11:08 +00:00
|
|
|
|
$this->price = $rubles;
|
|
|
|
|
//$this->calcSum();
|
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
|
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
|
|
|
|
}
|
2021-12-01 12:11:08 +00:00
|
|
|
|
if ($quantity < 0) {
|
|
|
|
|
throw new NegativeItemQuantityException($this->getName(), $quantity);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-12-01 12:11:08 +00:00
|
|
|
|
$this->quantity = $quantity;
|
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
|
|
|
|
*
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @return float
|
|
|
|
|
* @throws TooHighSumException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
public function getSum(): float
|
|
|
|
|
{
|
|
|
|
|
$sum = $this->price * $this->quantity;
|
|
|
|
|
if ($sum > Constraints::MAX_COUNT_ITEM_PRICE) {
|
|
|
|
|
throw new TooHighSumException($this->getName(), $sum);
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
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
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
public function getPaymentMethod(): ?string
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
|
|
|
|
return $this->payment_method;
|
|
|
|
|
}
|
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
|
|
|
|
*
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @param string|null $payment_method Признак способа оплаты
|
2020-01-11 06:30:25 +00:00
|
|
|
|
* @return $this
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @throws InvalidEnumValueException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
public function setPaymentMethod(?string $payment_method): self
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2021-12-01 12:11:08 +00:00
|
|
|
|
$payment_method = trim((string)$payment_method);
|
|
|
|
|
PaymentMethods::isValid($payment_method);
|
|
|
|
|
$this->payment_method = $payment_method ?: null;
|
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
|
|
|
|
*
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @return string|null
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
public function getPaymentObject(): ?string
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
|
|
|
|
return $this->payment_object;
|
|
|
|
|
}
|
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
|
|
|
|
*
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @param string|null $payment_object Признак предмета расчёта
|
2020-01-11 06:30:25 +00:00
|
|
|
|
* @return $this
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @throws InvalidEnumValueException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
public function setPaymentObject(?string $payment_object): self
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2021-12-01 12:11:08 +00:00
|
|
|
|
$payment_object = trim((string)$payment_object);
|
|
|
|
|
PaymentObjects::isValid($payment_object);
|
|
|
|
|
$this->payment_object = $payment_object ?: null;
|
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
|
|
|
|
/**
|
|
|
|
|
* Устанавливает ставку НДС
|
|
|
|
|
*
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @param Vat|string|null $vat Объект ставки, одно из значений VatTypes или null для удаления ставки
|
2020-01-11 06:30:25 +00:00
|
|
|
|
* @return $this
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @throws TooHighSumException
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
public function setVat(Vat|string|null $vat): self
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2021-12-01 12:11:08 +00:00
|
|
|
|
if (is_string($vat)) {
|
|
|
|
|
$vat = trim($vat);
|
|
|
|
|
VatTypes::isValid($vat) && $vat = new Vat($vat, $this->getSum());
|
|
|
|
|
} elseif ($vat instanceof Vat) {
|
|
|
|
|
$vat->setSum($this->getSum());
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-12-01 12:11:08 +00:00
|
|
|
|
$this->vat = $vat ?: null;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Возвращает установленный объект атрибутов агента
|
|
|
|
|
*
|
|
|
|
|
* @return AgentInfo|null
|
|
|
|
|
*/
|
|
|
|
|
public function getAgentInfo(): ?AgentInfo
|
|
|
|
|
{
|
|
|
|
|
return $this->agent_info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Устанавливает атрибуты агента
|
|
|
|
|
*
|
|
|
|
|
* @param AgentInfo|null $agent_info
|
|
|
|
|
* @return Item
|
|
|
|
|
*/
|
|
|
|
|
public function setAgentInfo(?AgentInfo $agent_info): self
|
|
|
|
|
{
|
|
|
|
|
$this->agent_info = $agent_info;
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
return $this->user_data;
|
|
|
|
|
}
|
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 $user_data Дополнительный реквизит
|
2020-01-11 06:30:25 +00:00
|
|
|
|
* @return $this
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @throws TooLongUserdataException Слишком длинный дополнительный реквизит
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
public function setUserData(?string $user_data): self
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2021-12-01 12:11:08 +00:00
|
|
|
|
$user_data = trim((string)$user_data);
|
2021-11-18 04:24:30 +00:00
|
|
|
|
if (mb_strlen($user_data) > Constraints::MAX_LENGTH_USER_DATA) {
|
2021-12-01 12:11:08 +00:00
|
|
|
|
throw new TooLongUserdataException($user_data);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-12-01 12:11:08 +00:00
|
|
|
|
$this->user_data = $user_data ?: null;
|
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
|
|
|
|
*
|
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
|
|
|
|
{
|
2021-12-01 12:11:08 +00:00
|
|
|
|
return $this->country_code;
|
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-01 12:11:08 +00:00
|
|
|
|
* @param string|null $country_code
|
|
|
|
|
* @return Item
|
|
|
|
|
* @throws InvalidOKSMCodeException
|
|
|
|
|
* @see https://classifikators.ru/oksm
|
|
|
|
|
* @see https://ru.wikipedia.org/wiki/Общероссийский_классификатор_стран_мира
|
2020-01-11 06:30:25 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
public function setCountryCode(?string $country_code): self
|
2020-01-11 06:30:25 +00:00
|
|
|
|
{
|
2021-12-01 12:11:08 +00:00
|
|
|
|
$country_code = trim((string)$country_code);
|
|
|
|
|
if (preg_match(Constraints::PATTERN_OKSM_CODE, $country_code) != 1) {
|
|
|
|
|
throw new InvalidOKSMCodeException($country_code);
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-12-01 12:11:08 +00:00
|
|
|
|
$this->country_code = $country_code ?: null;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Возвращает установленный код таможенной декларации
|
|
|
|
|
*
|
|
|
|
|
* @return string|null
|
|
|
|
|
*/
|
|
|
|
|
public function getDeclarationNumber(): ?string
|
|
|
|
|
{
|
|
|
|
|
return $this->declaration_number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Устанавливает код таможенной декларации
|
|
|
|
|
*
|
|
|
|
|
* @param string|null $declaration_number
|
|
|
|
|
* @return Item
|
|
|
|
|
* @throws InvalidDeclarationNumberException
|
|
|
|
|
*/
|
|
|
|
|
public function setDeclarationNumber(?string $declaration_number): self
|
|
|
|
|
{
|
|
|
|
|
if (is_string($declaration_number)) {
|
|
|
|
|
$declaration_number = trim($declaration_number);
|
|
|
|
|
if (
|
|
|
|
|
mb_strlen($declaration_number) < Constraints::MIN_LENGTH_DECLARATION_NUMBER ||
|
|
|
|
|
mb_strlen($declaration_number) > Constraints::MAX_LENGTH_DECLARATION_NUMBER
|
|
|
|
|
) {
|
|
|
|
|
throw new InvalidDeclarationNumberException($declaration_number);
|
|
|
|
|
}
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-12-01 12:11:08 +00:00
|
|
|
|
$this->declaration_number = $declaration_number;
|
|
|
|
|
return $this;
|
2020-01-11 06:30:25 +00:00
|
|
|
|
}
|
2021-11-22 06:51:10 +00:00
|
|
|
|
|
2021-12-01 12:11:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* Расчитывает стоимость и размер НДС на неё
|
|
|
|
|
*
|
|
|
|
|
* @return float
|
|
|
|
|
* @throws TooHighPriceException Слишком большая сумма
|
|
|
|
|
*/
|
|
|
|
|
//public function calcSum(): float
|
|
|
|
|
//{
|
|
|
|
|
// $sum = $this->quantity * $this->price;
|
|
|
|
|
// if (rubles($sum) > 42949672.95) {
|
|
|
|
|
// throw new TooHighPriceException($sum, 42949672.95);
|
|
|
|
|
// }
|
|
|
|
|
// $this->sum = $sum;
|
|
|
|
|
// if ($this->vat) {
|
|
|
|
|
// $this->vat->setSum(rubles($sum));
|
|
|
|
|
// }
|
|
|
|
|
// return $this->getSum();
|
|
|
|
|
//}
|
|
|
|
|
|
2020-01-11 06:30:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @throws TooHighSumException
|
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 12:11:08 +00:00
|
|
|
|
$this->getMeasurementUnit() && $json['measurement_unit'] = $this->getMeasurementUnit();
|
|
|
|
|
$this->getPaymentMethod() && $json['payment_method'] = $this->getPaymentMethod();
|
|
|
|
|
$this->getPaymentObject() && $json['payment_object'] = $this->getPaymentObject();
|
|
|
|
|
$this->getDeclarationNumber() && $json['declaration_number'] = $this->getDeclarationNumber();
|
|
|
|
|
$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();
|
|
|
|
|
$this->getUserData() && $json['user_data'] = $this->getUserData();
|
|
|
|
|
//TODO excise
|
|
|
|
|
$this->getCountryCode() && $json['country_code'] = $this->getCountryCode();
|
|
|
|
|
//TODO nomenclature_code
|
2020-01-11 06:30:25 +00:00
|
|
|
|
return $json;
|
|
|
|
|
}
|
|
|
|
|
}
|