Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Put vat description in separate property
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas De Keukelaere committed Sep 22, 2021
1 parent 583195e commit b2a5a10
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
8 changes: 7 additions & 1 deletion Factr.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace SumoCoders\Factr;

use InvalidArgumentException;
use SumoCoders\Factr\Exception;
use SumoCoders\Factr\Client\Client;
use SumoCoders\Factr\Invoice\Invoice;
Expand Down Expand Up @@ -568,7 +569,7 @@ public function invoices(array $filters = null)
$filters,
function($filter) use ($allowedFilters) {
if (!in_array($filter, $allowedFilters)) {
throw new \InvalidArgumentException('Invalid filter');
throw new InvalidArgumentException('Invalid filter');
}
}
);
Expand Down Expand Up @@ -641,6 +642,11 @@ public function invoicesGetByIid($iid)
*/
public function invoicesCreate(Invoice $invoice)
{
if (($invoice->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');

Expand Down
28 changes: 23 additions & 5 deletions Invoice/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace SumoCoders\Factr\Invoice;

use SumoCoders\Factr\Client\Client;
use SumoCoders\Factr\Factr;

/**
* Class Invoice
Expand Down Expand Up @@ -59,7 +58,7 @@ class Invoice
/**
* @var string
*/
protected $discountDescription, $vatException;
protected $discountDescription, $vatException, $vatDescription;

/**
* @var bool
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit b2a5a10

Please sign in to comment.