Поддержка correction_info

This commit is contained in:
2021-12-03 20:09:14 +08:00
parent 05fd25e810
commit d533164d1b
9 changed files with 332 additions and 142 deletions

View File

@@ -66,10 +66,7 @@ final class Company extends Entity
string $inn,
string $payment_address,
) {
$this->setEmail($email);
$this->setSno($sno);
$this->setInn($inn);
$this->setPaymentAddress($payment_address);
$this->setEmail($email)->setSno($sno)->setInn($inn)->setPaymentAddress($payment_address);
}
/**
@@ -92,8 +89,7 @@ final class Company extends Entity
public function setSno(string $sno): self
{
$sno = trim($sno);
SnoTypes::isValid($sno);
$this->sno = $sno;
SnoTypes::isValid($sno) && $this->sno = $sno;
return $this;
}

View File

@@ -0,0 +1,157 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
* This code is licensed under MIT.
* Этот код распространяется по лицензии MIT.
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
*/
declare(strict_types = 1);
namespace AtolOnline\Entities;
use AtolOnline\Constants\Constraints;
use AtolOnline\Enums\CorrectionTypes;
use AtolOnline\Exceptions\{
EmptyCorrectionNumberException,
InvalidCorrectionDateException,
InvalidEnumValueException
};
use DateTime;
use Exception;
use JetBrains\PhpStorm\{
ArrayShape,
Pure
};
/**
* Класс, описывающий данные коррекции
*
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 35
*/
class CorrectionInfo extends Entity
{
/**
* @var string|null Тип коррекции (1173)
*/
protected ?string $type = null;
/**
* @var string|null Дата документа основания для коррекции (1178)
*/
protected ?string $date = null;
/**
* @var string|null Номер документа основания для коррекции (1179)
*/
protected ?string $number = null;
/**
* Конструктор
*
* @param string $type Тип коррекции
* @param string $date Дата документа
* @param string $number Номер документа
* @throws InvalidEnumValueException
* @throws InvalidCorrectionDateException
* @throws EmptyCorrectionNumberException
*/
public function __construct(string $type, string $date, string $number)
{
$this->setType($type)->setDate($date)->setNumber($number);
}
/**
* Возвращает тип коррекции
*
* @return string|null
*/
public function getType(): ?string
{
return $this->type;
}
/**
* Устанавливает тип коррекции
*
* @param string $type
* @return $this
* @throws InvalidEnumValueException
*/
public function setType(string $type): self
{
$type = trim($type);
CorrectionTypes::isValid($type) && $this->type = $type;
return $this;
}
/**
* Возвращает дату документа основания для коррекции
*
* @return string|null
*/
public function getDate(): ?string
{
return $this->date;
}
/**
* Устанавливает дату документа основания для коррекции
*
* @param DateTime|string $date Строковая дата в формате d.m.Y либо объект DateTime с датой
* @return $this
* @throws InvalidCorrectionDateException
*/
public function setDate(DateTime|string $date): self
{
try {
if (is_string($date)) {
$date = new DateTime(trim($date));
}
$this->date = $date->format(Constraints::CORRECTION_DATE_FORMAT);
} catch (Exception $e) {
throw new InvalidCorrectionDateException($date, $e->getMessage());
}
return $this;
}
/**
* Возвращает установленный номер документа основания для коррекции
*
* @return string|null
*/
public function getNumber(): ?string
{
return $this->number;
}
/**
* Устанавливает номер документа основания для коррекции
*
* @param string $number
* @return $this
* @throws EmptyCorrectionNumberException
*/
public function setNumber(string $number): self
{
$number = trim($number);
empty($number) && throw new EmptyCorrectionNumberException();
$this->number = $number;
return $this;
}
/**
* @inheritDoc
*/
#[Pure]
#[ArrayShape(['type' => 'string', 'base_date' => 'string', 'base_number' => 'string'])]
public function jsonSerialize(): array
{
return [
'type' => $this->getType(),
'base_date' => $this->getDate(),
'base_number' => $this->getNumber(),
];
}
}

View File

@@ -1,134 +0,0 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
* This code is licensed under MIT.
* Этот код распространяется по лицензии MIT.
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
*/
declare(strict_types = 1);
namespace AtolOnline\Entities;
/**
* Класс todoCorrectionInfo, описывающий данные чек коррекции
*/
class todoCorrectionInfo extends Entity
{
/**
* @var string Тип коррекции. Тег ФФД - 1173.
*/
protected string $type;
/**
* @var string Дата документа основания для коррекции. Тег ФФД - 1178.
*/
protected string $base_date;
/**
* @var string Номер документа основания для коррекции. Тег ФФД - 1179.
*/
protected string $base_number;
/**
* todoCorrectionInfo constructor.
*
* @param string|null $type Тип коррекции
* @param string|null $base_date Дата документа
* @param string|null $base_number Номер документа
*/
public function __construct(
?string $type = null,
?string $base_date = null,
?string $base_number = null
) {
$type && $this->setType($type);
$base_date && $this->setDate($base_date);
$base_number && $this->setNumber($base_number);
}
/**
* Возвращает номер документа основания для коррекции.
* Тег ФФД - 1179.
*
* @return string|null
*/
public function getNumber(): ?string
{
return $this->base_number;
}
/**
* Устанавливает номер документа основания для коррекции.
* Тег ФФД - 1179.
*
* @param string $number
* @return $this
*/
public function setNumber(string $number): todoCorrectionInfo
{
$this->base_number = trim($number);
return $this;
}
/**
* Возвращает дату документа основания для коррекции.
* Тег ФФД - 1178.
*
* @return string|null
*/
public function getDate(): ?string
{
return $this->base_date;
}
/**
* Устанавливает дату документа основания для коррекции.
* Тег ФФД - 1178.
*
* @param string $date Строка в формате d.m.Y
* @return $this
*/
public function setDate(string $date): todoCorrectionInfo
{
$this->base_date = $date;
return $this;
}
/**
* Возвращает тип коррекции.
* Тег ФФД - 1173.
*
* @return string|null
*/
public function getType(): ?string
{
return $this->type;
}
/**
* Устанавливает тип коррекции.
* Тег ФФД - 1173.
*
* @param string $type
* @return $this
*/
public function setType(string $type): todoCorrectionInfo
{
$this->type = $type;
return $this;
}
/**
* @inheritDoc
*/
public function jsonSerialize(): array
{
return [
'type' => $this->getType() ?? '',
'base_date' => $this->getDate() ?? '',
'base_number' => $this->getNumber() ?? '',
];
}
}