Skip to content

Commit

Permalink
suppliers
Browse files Browse the repository at this point in the history
  • Loading branch information
segy committed Nov 23, 2023
1 parent 304afce commit 24b7c4f
Show file tree
Hide file tree
Showing 5 changed files with 253 additions and 0 deletions.
80 changes: 80 additions & 0 deletions spec/Pohoda/SupplierSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* This file is part of riesenia/pohoda package.
*
* Licensed under the MIT License
* (c) RIESENIA.com
*/

declare(strict_types=1);

namespace spec\Riesenia\Pohoda;

use PhpSpec\ObjectBehavior;

class SupplierSpec extends ObjectBehavior
{
public function let()
{
$this->beConstructedWith([
'stockItem' => [
'stockItem' => [
'ids' => 'B04'
]
],
'suppliers' => [
[
'supplierItem' => [
'default' => true,
'refAd' => [
'id' => 2
],
'orderCode' => 'A1',
'orderName' => 'A-zasoba',
'purchasingPrice' => 1968,
'rate' => 0,
'payVAT' => false,
'ean' => '11112228',
'printEAN' => true,
'unitEAN' => 'ks',
'unitCoefEAN' => 1,
'deliveryTime' => 12,
'minQuantity' => 2,
'note' => 'fdf'
]
],
[
'supplierItem' => [
'default' => false,
'refAd' => [
'ids' => 'INTEAK spol. s r. o.'
],
'orderCode' => 'I1',
'orderName' => 'I-zasoba',
'purchasingPrice' => 500,
'rate' => 0,
'payVAT' => false,
'ean' => '212121212',
'printEAN' => true,
'unitEAN' => 'ks',
'unitCoefEAN' => 1,
'deliveryTime' => 12,
'minQuantity' => 2,
'note' => 'aasn'
]
]
]
], '123');
}

public function it_is_initializable_and_extends_agenda()
{
$this->shouldHaveType('Riesenia\Pohoda\Supplier');
$this->shouldHaveType('Riesenia\Pohoda\Agenda');
}

public function it_creates_correct_xml()
{
$this->getXML()->asXML()->shouldReturn('<sup:supplier version="2.0"><sup:stockItem><typ:stockItem><typ:ids>B04</typ:ids></typ:stockItem></sup:stockItem><sup:suppliers><sup:supplierItem default="true"><sup:refAd><typ:id>2</typ:id></sup:refAd><sup:orderCode>A1</sup:orderCode><sup:orderName>A-zasoba</sup:orderName><sup:purchasingPrice>1968</sup:purchasingPrice><sup:rate>0</sup:rate><sup:payVAT>false</sup:payVAT><sup:ean>11112228</sup:ean><sup:printEAN>true</sup:printEAN><sup:unitEAN>ks</sup:unitEAN><sup:unitCoefEAN>1</sup:unitCoefEAN><sup:deliveryTime>12</sup:deliveryTime><sup:minQuantity>2</sup:minQuantity><sup:note>fdf</sup:note></sup:supplierItem><sup:supplierItem default="false"><sup:refAd><typ:ids>INTEAK spol. s r. o.</typ:ids></sup:refAd><sup:orderCode>I1</sup:orderCode><sup:orderName>I-zasoba</sup:orderName><sup:purchasingPrice>500</sup:purchasingPrice><sup:rate>0</sup:rate><sup:payVAT>false</sup:payVAT><sup:ean>212121212</sup:ean><sup:printEAN>true</sup:printEAN><sup:unitEAN>ks</sup:unitEAN><sup:unitCoefEAN>1</sup:unitCoefEAN><sup:deliveryTime>12</sup:deliveryTime><sup:minQuantity>2</sup:minQuantity><sup:note>aasn</sup:note></sup:supplierItem></sup:suppliers></sup:supplier>');
}
}
2 changes: 2 additions & 0 deletions src/Pohoda.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @method \Riesenia\Pohoda\Stock createStock(array $data = [])
* @method \Riesenia\Pohoda\StockTransfer createStockTransfer(array $data = [])
* @method \Riesenia\Pohoda\Storage createStorage(array $data = [])
* @method \Riesenia\Pohoda\Supplier createSupplier(array $data = [])
* @method \Riesenia\Pohoda\UserList createUserList(array $data = [])
*/
class Pohoda
Expand All @@ -58,6 +59,7 @@ class Pohoda
'pro' => 'http://www.stormware.cz/schema/version_2/prodejka.xsd',
'str' => 'http://www.stormware.cz/schema/version_2/storage.xsd',
'stk' => 'http://www.stormware.cz/schema/version_2/stock.xsd',
'sup' => 'http://www.stormware.cz/schema/version_2/supplier.xsd',
'typ' => 'http://www.stormware.cz/schema/version_2/type.xsd',
'vyd' => 'http://www.stormware.cz/schema/version_2/vydejka.xsd'
];
Expand Down
63 changes: 63 additions & 0 deletions src/Pohoda/Supplier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* This file is part of riesenia/pohoda package.
*
* Licensed under the MIT License
* (c) RIESENIA.com
*/

declare(strict_types=1);

namespace Riesenia\Pohoda;

use Riesenia\Pohoda\Common\OptionsResolver;
use Riesenia\Pohoda\Supplier\StockItem;
use Riesenia\Pohoda\Supplier\SupplierItem;

class Supplier extends Agenda
{
/** @var string */
public static $importRoot = 'lst:supplier';

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

// process suppliers
if (isset($data['suppliers'])) {
$data['suppliers'] = \array_map(function ($supplier) use ($ico, $resolveOptions) {
return new SupplierItem($supplier['supplierItem'], $ico, $resolveOptions);
}, $data['suppliers']);
}

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

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

$this->_addElements($xml, ['stockItem', 'suppliers'], 'sup');

return $xml;
}

/**
* {@inheritdoc}
*/
protected function _configureOptions(OptionsResolver $resolver)
{
// available options
$resolver->setDefined(['stockItem', 'suppliers']);
}
}
44 changes: 44 additions & 0 deletions src/Pohoda/Supplier/StockItem.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\Supplier;

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

class StockItem extends Agenda
{
/** @var string[] */
protected $_refElements = ['stockItem'];

/** @var string[] */
protected $_elements = ['stockItem'];

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

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

return $xml;
}

/**
* {@inheritdoc}
*/
protected function _configureOptions(OptionsResolver $resolver)
{
// available options
$resolver->setDefined($this->_elements);
}
}
64 changes: 64 additions & 0 deletions src/Pohoda/Supplier/SupplierItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* This file is part of riesenia/pohoda package.
*
* Licensed under the MIT License
* (c) RIESENIA.com
*/

declare(strict_types=1);

namespace Riesenia\Pohoda\Supplier;

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

class SupplierItem extends Agenda
{
/** @var string[] */
protected $_refElements = ['refAd', 'currency', 'deliveryPeriod'];

/** @var string[] */
protected $_elements = ['default', 'refAd', 'orderCode', 'orderName', 'purchasingPrice', 'currency', 'rate', 'payVAT', 'ean', 'printEAN', 'unitEAN', 'unitCoefEAN', 'deliveryTime', 'deliveryPeriod', 'minQuantity', 'unit', 'note'];

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

// handle default
if ($this->_data['default']) {
$xml->addAttribute('default', $this->_data['default']);
unset($this->_data['default']);
}

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

return $xml;
}

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

$resolver->setNormalizer('default', $resolver->getNormalizer('bool'));
$resolver->setNormalizer('orderCode', $resolver->getNormalizer('string64'));
$resolver->setNormalizer('orderName', $resolver->getNormalizer('string90'));
$resolver->setNormalizer('purchasingPrice', $resolver->getNormalizer('number'));
$resolver->setNormalizer('rate', $resolver->getNormalizer('float'));
$resolver->setNormalizer('payVAT', $resolver->getNormalizer('bool'));
$resolver->setNormalizer('ean', $resolver->getNormalizer('string20'));
$resolver->setNormalizer('printEAN', $resolver->getNormalizer('bool'));
$resolver->setNormalizer('unitEAN', $resolver->getNormalizer('string10'));
$resolver->setNormalizer('unitCoefEAN', $resolver->getNormalizer('float'));
$resolver->setNormalizer('deliveryTime', $resolver->getNormalizer('int'));
$resolver->setNormalizer('minQuantity', $resolver->getNormalizer('float'));
$resolver->setNormalizer('unit', $resolver->getNormalizer('string10'));
}
}

0 comments on commit 24b7c4f

Please sign in to comment.