Skip to content

Commit

Permalink
fix invoice comments
Browse files Browse the repository at this point in the history
  • Loading branch information
teiling88 committed Dec 10, 2018
1 parent e5cd3ba commit b2cb509
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/Invoice/InvoiceCommentEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php declare(strict_types=1);

namespace FastBillSdk\Invoice;

class InvoiceCommentEntity
{
public $date;

public $comment;

public $commentPublic;

const FIELD_MAPPING = [
'DATE' => '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;
}
}
12 changes: 12 additions & 0 deletions src/Invoice/InvoiceEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class InvoiceEntity

public $comment;

public $comments;

public $paymentType;

public $daysForPayment;
Expand Down Expand Up @@ -129,6 +131,7 @@ class InvoiceEntity
'ZIPCODE' => 'zipcode',
'CITY' => 'city',
'COMMENT_' => 'comment',
'COMMENTS' => 'comments',
'PAYMENT_TYPE' => 'paymentType',
'DAYS_FOR_PAYMENT' => 'daysForPayment',
'BANK_NAME' => 'bankName',
Expand Down Expand Up @@ -182,6 +185,7 @@ class InvoiceEntity
'zipcode' => 'ZIPCODE',
'city' => 'CITY',
'comment' => 'COMMENT_',
'comments' => 'COMMENTS',
'paymentType' => 'PAYMENT_TYPE',
'daysForPayment' => 'DAYS_FOR_PAYMENT',
'bankName' => 'BANK_NAME',
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b2cb509

Please sign in to comment.