Skip to content

Commit

Permalink
Support exporting invoices with liquidation data (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brezak authored Sep 27, 2024
1 parent c3db0a1 commit 6035d9c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/Pohoda/ListRequestSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,16 @@ public function it_creates_correct_xml_for_stock_with_complex_filter()

$this->addFilter(['storage' => ['ids' => 'MAIN'], 'lastChanges' => '2018-04-29 14:30'])->getXML()->asXML()->shouldReturn('<lStk:listStockRequest version="2.0" stockVersion="2.0"><lStk:requestStock><ftr:filter><ftr:storage><typ:ids>MAIN</typ:ids></ftr:storage><ftr:lastChanges>2018-04-29T14:30:00</ftr:lastChanges></ftr:filter></lStk:requestStock></lStk:listStockRequest>');
}

public function it_creates_proper_restriction_data()
{
$this->beConstructedWith(
['type' => 'Invoice'],
'123'
);

$this->addRestrictionData(['liquidation' => true]);

$this->getXml()->asXML()->shouldReturn('<lst:listInvoiceRequest version="2.0" invoiceVersion="2.0" invoiceType="issuedInvoice"><lst:requestInvoice/><lst:restrictionData><lst:liquidation>true</lst:liquidation></lst:restrictionData></lst:listInvoiceRequest>');
}
}
19 changes: 19 additions & 0 deletions src/Pohoda/ListRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Riesenia\Pohoda\Common\OptionsResolver;
use Riesenia\Pohoda\ListRequest\Filter;
use Riesenia\Pohoda\ListRequest\RestrictionData;
use Riesenia\Pohoda\ListRequest\UserFilterName;
use Symfony\Component\OptionsResolver\Options;

Expand All @@ -31,6 +32,20 @@ public function addFilter(array $data): self
return $this;
}

/**
* Add restriction data.
*
* @param array<string,mixed> $data
*
* @return $this
*/
public function addRestrictionData(array $data): self
{
$this->_data['restrictionData'] = new RestrictionData($data, $this->_ico);

return $this;
}

/**
* Add user filter name.
*
Expand Down Expand Up @@ -70,6 +85,10 @@ public function getXML(): \SimpleXMLElement

$request = $xml->addChild($this->_data['namespace'] . ':request' . $this->_data['type']);

if (isset($this->_data['restrictionData'])) {
$this->_addElements($xml, ['restrictionData'], 'lst');
}

$this->_addElements($request, ['filter', 'userFilterName'], 'ftr');
}

Expand Down
44 changes: 44 additions & 0 deletions src/Pohoda/ListRequest/RestrictionData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* This file is part of riesenia/pohoda package.
*
* Licensed under the MIT License
* (c) RIESENIA.com
*/

declare(strict_types=1);

namespace Riesenia\Pohoda\ListRequest;

use Riesenia\Pohoda\Agenda;
use Riesenia\Pohoda\Common\OptionsResolver;

class RestrictionData extends Agenda
{
/** @var string[] */
protected $_elements = ['liquidation'];

/**
* {@inheritdoc}
*/
public function getXML(): \SimpleXMLElement
{
$xml = $this->_createXML()->addChild('lst:restrictionData', '', $this->_namespace('lst'));

$this->_addElements($xml, $this->_elements, 'lst');

return $xml;
}

/**
* {@inheritdoc}
*/
protected function _configureOptions(OptionsResolver $resolver)
{
// available options
$resolver->setDefined($this->_elements);

// validate / format options
$resolver->setNormalizer('liquidation', $resolver->getNormalizer('bool'));
}
}

0 comments on commit 6035d9c

Please sign in to comment.