diff --git a/src/Constants/Constraints.php b/src/Constants/Constraints.php index 49dfec6..8c9dd34 100644 --- a/src/Constants/Constraints.php +++ b/src/Constants/Constraints.php @@ -128,6 +128,11 @@ final class Constraints */ const MAX_COUNT_DOC_VATS = 6; + /** + * Максимальная сумма одной оплаты + */ + const MAX_COUNT_PAYMENT_SUM = 99999.999; + /** * Максимальная длина имени кассира (1021) * @@ -142,16 +147,25 @@ final class Constraints */ const MAX_LENGTH_ITEM_CODE = 32; + /** + * Максимальная длина наименования дополнительного реквизита (1085) + * + * @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 32 + */ + const MAX_LENGTH_ADD_USER_PROP_NAME = 64; + + /** + * Максимальная длина значения дополнительного реквизита (1086) + * + * @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 32 + */ + const MAX_LENGTH_ADD_USER_PROP_VALUE = 256; + /** * Формат даты документа коррекции */ const CORRECTION_DATE_FORMAT = 'd.m.Y'; - /** - * Максимальная сумма одной оплаты - */ - const MAX_COUNT_PAYMENT_SUM = 99999.999; - /** * Регулярное выражение для валидации строки ИНН * diff --git a/src/Constants/Ffd105Tags.php b/src/Constants/Ffd105Tags.php index 32a015a..ed6cc5f 100644 --- a/src/Constants/Ffd105Tags.php +++ b/src/Constants/Ffd105Tags.php @@ -226,4 +226,19 @@ final class Ffd105Tags * Сумма НДС чека по расч. ставке 20/120 */ const DOC_VAT_TYPE_VAT120 = 1106; + + /** + * Дополнительный реквизит пользователя + */ + const DOC_ADD_USER_PROP = 1084; + + /** + * Наименование дополнительного реквизита пользователя + */ + const DOC_ADD_USER_PROP_NAME = 1085; + + /** + * Значение дополнительного реквизита пользователя + */ + const DOC_ADD_USER_PROP_VALUE = 1086; } diff --git a/src/Entities/AdditionalUserProps.php b/src/Entities/AdditionalUserProps.php new file mode 100644 index 0000000..0d1739b --- /dev/null +++ b/src/Entities/AdditionalUserProps.php @@ -0,0 +1,127 @@ +setName($name)->setValue($value); + } + + /** + * Возвращает наименование реквизита + * + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * Устанавливает наименование реквизита + * + * @param string $name + * @return $this + * @throws TooLongAddUserPropNameException + * @throws EmptyAddUserPropNameException + */ + public function setName(string $name): self + { + $name = trim($name); + if (mb_strlen($name) > Constraints::MAX_LENGTH_ADD_USER_PROP_NAME) { + throw new TooLongAddUserPropNameException($name); + } + if (empty($name)) { + throw new EmptyAddUserPropNameException($name); + } + $this->name = $name; + return $this; + } + + /** + * Возвращает установленный телефон + * + * @return string|null + */ + public function getValue(): ?string + { + return $this->value; + } + + /** + * Устанавливает значение реквизита + * + * @param string $value + * @return $this + * @throws TooLongAddUserPropValueException + * @throws EmptyAddUserPropValueException + */ + public function setValue(string $value): self + { + $value = trim($value); + if (mb_strlen($value) > Constraints::MAX_LENGTH_CLIENT_NAME) { + throw new TooLongAddUserPropValueException($value); + } + if (empty($value)) { + throw new EmptyAddUserPropValueException($value); + } + $this->value = $value; + return $this; + } + + /** + * @inheritDoc + */ + #[Pure] + public function jsonSerialize(): array + { + return [ + 'name' => $this->getName(), + 'value' => $this->getValue(), + ]; + } +} diff --git a/src/Exceptions/EmptyAddUserPropNameException.php b/src/Exceptions/EmptyAddUserPropNameException.php new file mode 100644 index 0000000..567d18b --- /dev/null +++ b/src/Exceptions/EmptyAddUserPropNameException.php @@ -0,0 +1,25 @@ +assertAtolable( + new AdditionalUserProps('name', 'value'), + [ + 'name' => 'name', + 'value' => 'value', + ] + ); + } + + /** + * Тестирует выброс исключения при слишком длинном наименовании + * + * @covers \AtolOnline\Entities\AdditionalUserProps::setName + * @covers \AtolOnline\Exceptions\TooLongAddUserPropNameException + * @throws EmptyAddUserPropNameException + * @throws EmptyAddUserPropValueException + * @throws TooLongAddUserPropValueException + */ + public function testTooLongAddCheckPropNameException(): void + { + $this->expectException(TooLongAddUserPropNameException::class); + new AdditionalUserProps(Helpers::randomStr(Constraints::MAX_LENGTH_ADD_USER_PROP_NAME + 1), 'value'); + } + + /** + * Тестирует выброс исключения при пустом наименовании + * + * @covers \AtolOnline\Entities\AdditionalUserProps::setName + * @covers \AtolOnline\Exceptions\EmptyAddUserPropNameException + */ + public function testEmptyAddCheckPropNameException(): void + { + $this->expectException(EmptyAddUserPropNameException::class); + new AdditionalUserProps('', 'value'); + } + + /** + * Тестирует выброс исключения при слишком длинном значении + * + * @covers \AtolOnline\Entities\AdditionalUserProps::setValue + * @covers \AtolOnline\Exceptions\TooLongAddUserPropValueException + * @throws EmptyAddUserPropNameException + * @throws EmptyAddUserPropValueException + * @throws TooLongAddUserPropValueException + * @throws TooLongAddUserPropNameException + */ + public function testTooLongAddCheckPropValueException(): void + { + $this->expectException(TooLongAddUserPropValueException::class); + new AdditionalUserProps('name', Helpers::randomStr(Constraints::MAX_LENGTH_ADD_USER_PROP_VALUE + 1)); + } + + /** + * Тестирует выброс исключения при пустом значении + * + * @covers \AtolOnline\Entities\AdditionalUserProps::setValue + * @covers \AtolOnline\Exceptions\EmptyAddUserPropValueException + */ + public function testEmptyAddCheckPropValueException(): void + { + $this->expectException(EmptyAddUserPropValueException::class); + new AdditionalUserProps('name', ''); + } +}