From 0f658d38a9f1cf13cba21274b1e326d9d1aff605 Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Fri, 29 May 2020 22:05:35 +0800 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BE=D1=88=D0=B8?= =?UTF-8?q?=D0=B1=D0=BE=D0=BA=20=D0=BF=D1=80=D0=B8=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=B4=D0=BE=D0=BA?= =?UTF-8?q?=D1=83=D0=BC=D0=BD=D0=B5=D1=82=D0=B0=20=D0=BA=20json-=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AtolOnline/Entities/Document.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/AtolOnline/Entities/Document.php b/src/AtolOnline/Entities/Document.php index 541a550..0c48b6e 100644 --- a/src/AtolOnline/Entities/Document.php +++ b/src/AtolOnline/Entities/Document.php @@ -199,9 +199,9 @@ class Document extends Entity /** * Возвращает заданного клиента (покупателя) * - * @return Client + * @return Client|null */ - public function getClient(): Client + public function getClient(): ?Client { return $this->client; } @@ -221,9 +221,9 @@ class Document extends Entity /** * Возвращает заданную компанию (продавца) * - * @return Company + * @return Company|null */ - public function getCompany(): Company + public function getCompany(): ?Company { return $this->company; } @@ -388,7 +388,7 @@ class Document extends Entity $doc->payments->add($payment); } } - if ($array['total'] != $doc->calcTotal()) { + if (isset($array['total']) && $array['total'] != $doc->calcTotal()) { throw new AtolException('Real total sum not equals to provided in JSON one'); } return $doc; @@ -401,16 +401,24 @@ class Document extends Entity */ public function jsonSerialize() { - $json['company'] = $this->getCompany()->jsonSerialize();// обязательно - $json['payments'] = $this->payments->jsonSerialize(); // обязательно + if ($this->getCompany()) { + $json['company'] = $this->getCompany()->jsonSerialize(); // обязательно + } + if ($this->getPayments()) { + $json['payments'] = $this->getPayments()->jsonSerialize(); // обязательно + } if ($this->getCashier()) { $json['cashier'] = $this->getCashier(); } if ($this->getCorrectionInfo()) { $json['correction_info'] = $this->getCorrectionInfo()->jsonSerialize(); // обязательно для коррекционных } else { - $json['client'] = $this->getClient()->jsonSerialize(); // обязательно для некоррекционных - $json['items'] = $this->items->jsonSerialize(); // обязательно для некоррекционных + if ($this->getClient()) { + $json['client'] = $this->getClient()->jsonSerialize(); // обязательно для некоррекционных + } + if ($this->getItems()) { + $json['items'] = $this->getItems()->jsonSerialize(); // обязательно для некоррекционных + } $json['total'] = $this->calcTotal(); // обязательно для некоррекционных } if ($this->getVats()) { @@ -418,4 +426,4 @@ class Document extends Entity } return $json; } -} \ No newline at end of file +}