From b2a5a10261ea70d06dded5fa70d1a5361d06aa7c Mon Sep 17 00:00:00 2001 From: Jonas De Keukelaere Date: Wed, 22 Sep 2021 14:48:26 +0100 Subject: [PATCH] Put vat description in separate property --- Factr.php | 8 +++++++- Invoice/Invoice.php | 28 +++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Factr.php b/Factr.php index e0a80dd..4f08e36 100644 --- a/Factr.php +++ b/Factr.php @@ -1,6 +1,7 @@ getVatException() && !$invoice->getVatDescription()) + || (!$invoice->getVatException() && $invoice->getVatDescription())) { + throw new InvalidArgumentException('Vat exception and vat description are required if one of them is filled'); + } + $parameters['invoice'] = $invoice->toArray(true); $rawData = $this->doCall('invoices.json', $parameters, 'POST'); diff --git a/Invoice/Invoice.php b/Invoice/Invoice.php index fcdc263..9f5832a 100644 --- a/Invoice/Invoice.php +++ b/Invoice/Invoice.php @@ -2,7 +2,6 @@ namespace SumoCoders\Factr\Invoice; use SumoCoders\Factr\Client\Client; -use SumoCoders\Factr\Factr; /** * Class Invoice @@ -59,7 +58,7 @@ class Invoice /** * @var string */ - protected $discountDescription, $vatException; + protected $discountDescription, $vatException, $vatDescription; /** * @var bool @@ -423,6 +422,25 @@ public function setVatException($vatException) return $this; } + /** + * @return string + */ + public function getVatDescription() + { + return $this->vatDescription; + } + + /** + * @param string $vatDescription + * @return $this + */ + public function setVatDescription($vatDescription) + { + $this->vatDescription = $vatDescription; + + return $this; + } + /** * Initialize the object with raw data * @@ -491,9 +509,9 @@ public function toArray($forApi = false) } if ($this->getVatException()) { $data['vat_exception'] = $this->getVatException(); - if ($this->getVatException() === 'cash_discount') { - $data['vat_description'] = 'btw verlegd'; - } + } + if ($this->getVatDescription()) { + $data['vat_description'] = $this->getVatDescription(); } $data['items'] = array();