-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
} | ||
} |