|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of riesenia/pohoda package. |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the MIT License |
|
7
|
|
|
* (c) RIESENIA.com |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Riesenia\Pohoda\Order; |
|
13
|
|
|
|
|
14
|
|
|
use Riesenia\Pohoda\Common\OptionsResolver; |
|
15
|
|
|
use Riesenia\Pohoda\Document\AbstractItem; |
|
16
|
|
|
|
|
17
|
|
|
class Item extends AbstractItem |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var string[] */ |
|
20
|
|
|
protected array $refElements = ['typeServiceMOSS', 'centre', 'activity', 'contract']; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string[] */ |
|
23
|
|
|
protected array $elements = ['text', 'quantity', 'delivered', 'unit', 'coefficient', 'payVAT', 'rateVAT', 'percentVAT', 'discountPercentage', 'homeCurrency', 'foreignCurrency', 'typeServiceMOSS', 'note', 'code', 'stockItem', 'centre', 'activity', 'contract', 'PDP']; |
|
24
|
|
|
|
|
25
|
|
|
/** @var string[] */ |
|
26
|
|
|
protected array $additionalElements = ['id']; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
2 |
|
public function getXML(): \SimpleXMLElement |
|
32
|
|
|
{ |
|
33
|
2 |
|
if (is_null($this->namespace)) { |
|
34
|
|
|
throw new \LogicException('Namespace not set.'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
2 |
|
if (is_null($this->nodePrefix)) { |
|
38
|
|
|
throw new \LogicException('Node name prefix not set.'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
2 |
|
$xml = $this->createXML()->addChild($this->namespace . ':' . $this->nodePrefix . 'Item', '', $this->namespace($this->namespace)); |
|
42
|
|
|
|
|
43
|
2 |
|
$this->addElements($xml, \array_merge($this->elements, ($this->useOneDirectionalVariables ? $this->additionalElements : []), ['parameters']), $this->namespace); |
|
44
|
|
|
|
|
45
|
2 |
|
return $xml; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
2 |
|
protected function configureOptions(OptionsResolver $resolver): void |
|
52
|
|
|
{ |
|
53
|
2 |
|
$resolver->setDefined(array_merge($this->elements, ($this->useOneDirectionalVariables ? $this->additionalElements : []))); |
|
54
|
|
|
|
|
55
|
|
|
// validate / format options |
|
56
|
2 |
|
$resolver->setNormalizer('text', $this->normalizerFactory->getClosure('string90')); |
|
57
|
2 |
|
$resolver->setNormalizer('quantity', $this->normalizerFactory->getClosure('float')); |
|
58
|
2 |
|
$resolver->setNormalizer('delivered', $this->normalizerFactory->getClosure('float')); |
|
59
|
2 |
|
$resolver->setNormalizer('unit', $this->normalizerFactory->getClosure('string10')); |
|
60
|
2 |
|
$resolver->setNormalizer('coefficient', $this->normalizerFactory->getClosure('float')); |
|
61
|
2 |
|
$resolver->setNormalizer('payVAT', $this->normalizerFactory->getClosure('bool')); |
|
62
|
2 |
|
$resolver->setAllowedValues('rateVAT', ['none', 'high', 'low', 'third', 'historyHigh', 'historyLow', 'historyThird']); |
|
63
|
2 |
|
$resolver->setNormalizer('percentVAT', $this->normalizerFactory->getClosure('float')); |
|
64
|
2 |
|
$resolver->setNormalizer('discountPercentage', $this->normalizerFactory->getClosure('float')); |
|
65
|
2 |
|
$resolver->setNormalizer('note', $this->normalizerFactory->getClosure('string90')); |
|
66
|
2 |
|
$resolver->setNormalizer('code', $this->normalizerFactory->getClosure('string64')); |
|
67
|
2 |
|
$resolver->setNormalizer('PDP', $this->normalizerFactory->getClosure('bool')); |
|
68
|
|
|
|
|
69
|
2 |
|
if ($this->useOneDirectionalVariables) { |
|
70
|
1 |
|
$resolver->setNormalizer('id', $this->normalizerFactory->getClosure('int')); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|