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

Commit

Permalink
Merge pull request #24 from jonasdekeukelaere/vat-reverse-charge
Browse files Browse the repository at this point in the history
Add vat exception to invoice
  • Loading branch information
jonasdekeukelaere authored Sep 23, 2021
2 parents ae19f61 + b2a5a10 commit 8b12bd5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 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
47 changes: 45 additions & 2 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;
protected $discountDescription, $vatException, $vatDescription;

/**
* @var bool
Expand Down Expand Up @@ -404,6 +403,44 @@ public function prepareForSending()
$this->prepareForSending = true;
}

/**
* @return string
*/
public function getVatException()
{
return $this->vatException;
}

/**
* @param string $vatException
* @return $this
*/
public function setVatException($vatException)
{
$this->vatException = $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 @@ -470,6 +507,12 @@ public function toArray($forApi = false)
$data['percentage'] = $this->isDiscountAPercentage();
$data['discount_description'] = $this->getDiscountDescription();
}
if ($this->getVatException()) {
$data['vat_exception'] = $this->getVatException();
}
if ($this->getVatDescription()) {
$data['vat_description'] = $this->getVatDescription();
}

$data['items'] = array();
foreach ($this->getItems() as $item) {
Expand Down

0 comments on commit 8b12bd5

Please sign in to comment.