2021-11-24 09:57:24 +00:00
|
|
|
<?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;
|
|
|
|
|
2021-12-03 10:23:00 +00:00
|
|
|
use AtolOnline\Exceptions\{
|
|
|
|
InvalidInnLengthException,
|
|
|
|
InvalidPhoneException
|
|
|
|
};
|
|
|
|
use AtolOnline\Traits\{
|
|
|
|
HasInn,
|
|
|
|
HasPhones
|
|
|
|
};
|
2021-11-24 09:57:24 +00:00
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Класс, описывающий поставшика
|
|
|
|
*
|
2021-11-26 01:16:46 +00:00
|
|
|
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 29
|
2021-11-24 09:57:24 +00:00
|
|
|
*/
|
|
|
|
class Supplier extends Entity
|
|
|
|
{
|
2021-12-03 10:23:00 +00:00
|
|
|
use HasPhones, HasInn;
|
|
|
|
|
2021-11-24 09:57:24 +00:00
|
|
|
/**
|
2021-11-24 10:54:48 +00:00
|
|
|
* @var string|null Наименование (1225)
|
|
|
|
*/
|
|
|
|
protected ?string $name = null;
|
|
|
|
|
2021-11-24 09:57:24 +00:00
|
|
|
/**
|
|
|
|
* Конструктор
|
|
|
|
*
|
2021-11-24 10:54:48 +00:00
|
|
|
* @param string|null $name Наименование поставщика (1225)
|
|
|
|
* @param string|null $inn ИНН (1226)
|
|
|
|
* @param array|Collection|null $phones Телефоны поставщика (1171)
|
|
|
|
* @throws InvalidInnLengthException
|
2021-11-24 09:57:24 +00:00
|
|
|
* @throws InvalidPhoneException
|
|
|
|
*/
|
|
|
|
public function __construct(
|
2021-11-24 10:54:48 +00:00
|
|
|
?string $name = null,
|
|
|
|
?string $inn = null,
|
2021-11-24 09:57:24 +00:00
|
|
|
array|Collection|null $phones = null,
|
|
|
|
) {
|
2021-11-24 10:54:48 +00:00
|
|
|
!is_null($name) && $this->setName($name);
|
|
|
|
!is_null($inn) && $this->setInn($inn);
|
2021-11-24 09:57:24 +00:00
|
|
|
$this->setPhones($phones);
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:54:48 +00:00
|
|
|
/**
|
|
|
|
* Возвращает установленное наименование поставщика
|
|
|
|
*
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function getName(): ?string
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Устанавливает наименование поставщика
|
|
|
|
*
|
|
|
|
* @param string|null $name
|
|
|
|
* @return Supplier
|
|
|
|
*/
|
|
|
|
public function setName(?string $name): self
|
|
|
|
{
|
|
|
|
// критерии к длине строки не описаны ни в схеме, ни в документации
|
|
|
|
$this->name = trim($name) ?: null;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2021-11-24 09:57:24 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function jsonSerialize(): array
|
|
|
|
{
|
|
|
|
$json = [];
|
2021-11-24 10:54:48 +00:00
|
|
|
$this->getName() && $json['name'] = $this->getName();
|
|
|
|
$this->getInn() && $json['inn'] = $this->getInn();
|
2021-11-24 09:57:24 +00:00
|
|
|
!$this->getPhones()->isEmpty() && $json['phones'] = $this->getPhones()->toArray();
|
|
|
|
return $json;
|
|
|
|
}
|
|
|
|
}
|