diff --git a/src/Invoice/InvoiceCommentEntity.php b/src/Invoice/InvoiceCommentEntity.php new file mode 100644 index 0000000..642262f --- /dev/null +++ b/src/Invoice/InvoiceCommentEntity.php @@ -0,0 +1,43 @@ + 'date', + 'COMMENT' => 'comment', + 'COMMENT_PUBLIC' => 'commentPublic' + ]; + + public function __construct(\SimpleXMLElement $data = null) + { + if ($data) { + $this->setData($data); + } + } + + /** + * @param \SimpleXMLElement $data + * @return InvoiceCommentEntity + */ + public function setData(\SimpleXMLElement $data): self + { + foreach ($data as $key => $value) { + if (!isset(self::FIELD_MAPPING[$key])) { + trigger_error('the provided xml key ' . $key . ' is not mapped at the moment in ' . self::class); + continue; + } + + $this->{self::FIELD_MAPPING[$key]} = (string) $value; + } + + return $this; + } +} diff --git a/src/Invoice/InvoiceEntity.php b/src/Invoice/InvoiceEntity.php index 3fe244a..14c9738 100644 --- a/src/Invoice/InvoiceEntity.php +++ b/src/Invoice/InvoiceEntity.php @@ -37,6 +37,8 @@ class InvoiceEntity public $comment; + public $comments; + public $paymentType; public $daysForPayment; @@ -129,6 +131,7 @@ class InvoiceEntity 'ZIPCODE' => 'zipcode', 'CITY' => 'city', 'COMMENT_' => 'comment', + 'COMMENTS' => 'comments', 'PAYMENT_TYPE' => 'paymentType', 'DAYS_FOR_PAYMENT' => 'daysForPayment', 'BANK_NAME' => 'bankName', @@ -182,6 +185,7 @@ class InvoiceEntity 'zipcode' => 'ZIPCODE', 'city' => 'CITY', 'comment' => 'COMMENT_', + 'comments' => 'COMMENTS', 'paymentType' => 'PAYMENT_TYPE', 'daysForPayment' => 'DAYS_FOR_PAYMENT', 'bankName' => 'BANK_NAME', @@ -239,6 +243,14 @@ public function setData(\SimpleXMLElement $data): self } switch ($key) { + case 'COMMENTS': + $comments = []; + foreach ($value as $comment) { + $comments[] = new InvoiceCommentEntity($comment); + } + + $this->{self::FIELD_MAPPING[$key]} = $comments; + break; case 'ITEMS': $items = []; foreach ($value as $item) {