Skip to content

Commit

Permalink
introducing Document
Browse files Browse the repository at this point in the history
  • Loading branch information
segy committed May 3, 2022
1 parent a94995d commit d8535f7
Show file tree
Hide file tree
Showing 33 changed files with 487 additions and 1,173 deletions.
67 changes: 5 additions & 62 deletions src/Pohoda/CashSlip.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,81 +10,24 @@

namespace Riesenia\Pohoda;

use Riesenia\Pohoda\CashSlip\Header;
use Riesenia\Pohoda\CashSlip\Item;
use Riesenia\Pohoda\CashSlip\Summary;
use Riesenia\Pohoda\Common\AddParameterToHeaderTrait;
use Riesenia\Pohoda\Common\OptionsResolver;

class CashSlip extends Agenda
class CashSlip extends Document
{
use AddParameterToHeaderTrait;

/** @var string */
public static $importRoot = 'lst:prodejka';

/**
* {@inheritdoc}
*/
public function __construct(array $data, string $ico, bool $resolveOptions = true)
{
// pass to header
$data = ['header' => new Header($data, $ico, $resolveOptions)];

parent::__construct($data, $ico, $resolveOptions);
}

/**
* Add item.
*
* @param array<string,mixed> $data
*
* @return $this
*/
public function addItem(array $data): self
{
if (!isset($this->_data['prodejkaDetail'])) {
$this->_data['prodejkaDetail'] = [];
}

$this->_data['prodejkaDetail'][] = new Item($data, $this->_ico);

return $this;
}

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

return $this;
}

/**
* {@inheritdoc}
*/
public function getXML(): \SimpleXMLElement
protected function _getDocumentNamespace(): string
{
$xml = $this->_createXML()->addChild('pro:prodejka', '', $this->_namespace('pro'));
$xml->addAttribute('version', '2.0');

$this->_addElements($xml, ['header', 'prodejkaDetail', 'summary'], 'pro');

return $xml;
return 'pro';
}

/**
* {@inheritdoc}
*/
protected function _configureOptions(OptionsResolver $resolver)
protected function _getDocumentName(): string
{
// available options
$resolver->setDefined(['header']);
return 'prodejka';
}
}
36 changes: 3 additions & 33 deletions src/Pohoda/CashSlip/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,23 @@

namespace Riesenia\Pohoda\CashSlip;

use Riesenia\Pohoda\Agenda;
use Riesenia\Pohoda\Common\AddParameterTrait;
use Riesenia\Pohoda\Common\OptionsResolver;
use Riesenia\Pohoda\Type\Address;
use Riesenia\Pohoda\Document\Header as DocumentHeader;

class Header extends Agenda
class Header extends DocumentHeader
{
use AddParameterTrait;

/** @var string[] */
protected $_refElements = ['number', 'accounting', 'paymentType', 'priceLevel', 'centre', 'activity', 'contract', 'kasa'];

/** @var string[] */
protected $_elements = ['prodejkaType', 'number', 'date', 'accounting', 'text', 'partnerIdentity', 'paymentType', 'priceLevel', 'centre', 'activity', 'contract', 'kasa', 'note', 'intNote'];

/**
* {@inheritdoc}
*/
public function __construct(array $data, string $ico, bool $resolveOptions = true)
{
// process partner identity
if (isset($data['partnerIdentity'])) {
$data['partnerIdentity'] = new Address($data['partnerIdentity'], $ico, $resolveOptions);
}

parent::__construct($data, $ico, $resolveOptions);
}

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

$this->_addElements($xml, \array_merge($this->_elements, ['parameters']), 'pro');

return $xml;
}

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

// validate / format options
$resolver->setDefault('prodejkaType', 'saleVoucher');
Expand Down
45 changes: 3 additions & 42 deletions src/Pohoda/CashSlip/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,23 @@

namespace Riesenia\Pohoda\CashSlip;

use Riesenia\Pohoda\Agenda;
use Riesenia\Pohoda\Common\AddParameterTrait;
use Riesenia\Pohoda\Common\OptionsResolver;
use Riesenia\Pohoda\Type\CurrencyItem;
use Riesenia\Pohoda\Type\StockItem;
use Riesenia\Pohoda\Document\Item as DocumentItem;

class Item extends Agenda
class Item extends DocumentItem
{
use AddParameterTrait;

/** @var string[] */
protected $_refElements = ['centre', 'activity', 'contract'];

/** @var string[] */
protected $_elements = ['text', 'quantity', 'unit', 'coefficient', 'payVAT', 'rateVAT', 'discountPercentage', 'homeCurrency', 'foreignCurrency', 'note', 'code', 'stockItem', 'centre', 'activity', 'contract'];

/**
* {@inheritdoc}
*/
public function __construct(array $data, string $ico, bool $resolveOptions = true)
{
// process home currency
if (isset($data['homeCurrency'])) {
$data['homeCurrency'] = new CurrencyItem($data['homeCurrency'], $ico, $resolveOptions);
}
// process foreign currency
if (isset($data['foreignCurrency'])) {
$data['foreignCurrency'] = new CurrencyItem($data['foreignCurrency'], $ico, $resolveOptions);
}
// process stock item
if (isset($data['stockItem'])) {
$data['stockItem'] = new StockItem($data['stockItem'], $ico, $resolveOptions);
}

parent::__construct($data, $ico, $resolveOptions);
}

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

$this->_addElements($xml, \array_merge($this->_elements, ['parameters']), 'pro');

return $xml;
}

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

// validate / format options
$resolver->setNormalizer('text', $resolver->getNormalizer('string255'));
Expand Down
33 changes: 3 additions & 30 deletions src/Pohoda/CashSlip/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,20 @@

namespace Riesenia\Pohoda\CashSlip;

use Riesenia\Pohoda\Agenda;
use Riesenia\Pohoda\Common\OptionsResolver;
use Riesenia\Pohoda\Type\CurrencyHome;
use Riesenia\Pohoda\Document\Summary as DocumentSummary;

class Summary extends Agenda
class Summary extends DocumentSummary
{
/** @var string[] */
protected $_elements = ['roundingDocument', 'roundingVAT', 'calculateVAT', 'homeCurrency'];

/**
* {@inheritdoc}
*/
public function __construct(array $data, string $ico, bool $resolveOptions = true)
{
// process home currency
if (isset($data['homeCurrency'])) {
$data['homeCurrency'] = new CurrencyHome($data['homeCurrency'], $ico, $resolveOptions);
}

parent::__construct($data, $ico, $resolveOptions);
}

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

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

return $xml;
}

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

// validate / format options
$resolver->setAllowedValues('roundingDocument', ['none', 'math2one', 'math2half', 'math2tenth', 'up2one', 'up2half', 'up2tenth', 'down2one', 'down2half', 'down2tenth']);
Expand Down
Loading

0 comments on commit d8535f7

Please sign in to comment.