|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace kalanis\Pohoda\Document; |
|
6
|
|
|
|
|
7
|
|
|
use kalanis\Pohoda\Common; |
|
8
|
|
|
use kalanis\Pohoda\Type; |
|
9
|
|
|
use kalanis\PohodaException; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @property Common\Dtos\AbstractItemDto $data |
|
13
|
|
|
*/ |
|
14
|
|
|
abstract class AbstractItem extends AbstractPart |
|
15
|
|
|
{ |
|
16
|
|
|
use Common\AddParameterTrait; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritdoc} |
|
20
|
|
|
*/ |
|
21
|
16 |
|
public function setData(Common\Dtos\AbstractDto $data): parent |
|
22
|
|
|
{ |
|
23
|
|
|
// process home currency |
|
24
|
16 |
|
if (isset($data->homeCurrency)) { |
|
25
|
12 |
|
$homeCurrency = new Type\CurrencyItem($this->dependenciesFactory); |
|
26
|
12 |
|
$homeCurrency |
|
27
|
12 |
|
->setDirectionalVariable($this->useOneDirectionalVariables) |
|
28
|
12 |
|
->setResolveOptions($this->resolveOptions) |
|
29
|
12 |
|
->setData($data->homeCurrency); |
|
30
|
12 |
|
$data->homeCurrency = $homeCurrency; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
// process foreign currency |
|
34
|
16 |
|
if (isset($data->foreignCurrency)) { |
|
35
|
1 |
|
$foreignCurrency = new Type\CurrencyItem($this->dependenciesFactory); |
|
36
|
1 |
|
$foreignCurrency |
|
37
|
1 |
|
->setDirectionalVariable($this->useOneDirectionalVariables) |
|
38
|
1 |
|
->setResolveOptions($this->resolveOptions) |
|
39
|
1 |
|
->setData($data->foreignCurrency); |
|
40
|
1 |
|
$data->foreignCurrency = $foreignCurrency; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
// process stock item |
|
44
|
16 |
|
if (isset($data->stockItem)) { |
|
45
|
7 |
|
$stockItem = new Type\StockItem($this->dependenciesFactory); |
|
46
|
7 |
|
$stockItem |
|
47
|
7 |
|
->setDirectionalVariable($this->useOneDirectionalVariables) |
|
48
|
7 |
|
->setResolveOptions($this->resolveOptions) |
|
49
|
7 |
|
->setData($data->stockItem); |
|
50
|
7 |
|
$data->stockItem = $stockItem; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
16 |
|
return parent::setData($data); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
14 |
|
public function getXML(): \SimpleXMLElement |
|
60
|
|
|
{ |
|
61
|
14 |
|
if (is_null($this->namespace)) { |
|
62
|
1 |
|
throw new PohodaException('Namespace not set.'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
13 |
|
if (is_null($this->nodePrefix)) { |
|
66
|
1 |
|
throw new PohodaException('Node name prefix not set.'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
12 |
|
$xml = $this->createXML()->addChild($this->namespace . ':' . $this->nodePrefix . 'Item', '', $this->namespace($this->namespace)); |
|
70
|
|
|
|
|
71
|
12 |
|
$this->addElements($xml, $this->getDataElements(), $this->namespace); |
|
72
|
|
|
|
|
73
|
12 |
|
return $xml; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|