|
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; |
|
15
|
|
|
use Riesenia\Pohoda\Document\AbstractItem; |
|
16
|
|
|
use Riesenia\Pohoda\ValueTransformer\SanitizeEncoding; |
|
17
|
|
|
|
|
18
|
|
|
class Item extends AbstractItem |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var string[] */ |
|
21
|
|
|
protected array $refElements = ['typeServiceMOSS', 'centre', 'activity', 'contract']; |
|
22
|
|
|
|
|
23
|
|
|
/** @var string[] */ |
|
24
|
|
|
protected array $elements = ['text', 'quantity', 'delivered', 'unit', 'coefficient', 'payVAT', 'rateVAT', 'rateVatValue', 'percentVAT', 'discountPercentage', 'homeCurrency', 'foreignCurrency', 'typeServiceMOSS', 'note', 'code', 'stockItem', 'centre', 'activity', 'contract', 'PDP']; |
|
25
|
|
|
|
|
26
|
|
|
/** @var string[] */ |
|
27
|
|
|
protected array $additionalElements = ['id']; |
|
28
|
|
|
|
|
29
|
4 |
|
public function __construct( |
|
30
|
|
|
Common\NamespacesPaths $namespacesPaths, |
|
31
|
|
|
SanitizeEncoding $sanitizeEncoding, |
|
32
|
|
|
string $companyRegistrationNumber, |
|
33
|
|
|
bool $resolveOptions = true, |
|
34
|
|
|
Common\OptionsResolver\Normalizers\NormalizerFactory $normalizerFactory = new Common\OptionsResolver\Normalizers\NormalizerFactory(), |
|
35
|
|
|
) { |
|
36
|
|
|
// init attributes |
|
37
|
4 |
|
$this->elementsAttributesMapper = [ |
|
38
|
4 |
|
'rateVatValue' => new Common\ElementAttributes('rateVAT', 'value'), |
|
39
|
4 |
|
]; |
|
40
|
|
|
|
|
41
|
4 |
|
parent::__construct($namespacesPaths, $sanitizeEncoding, $companyRegistrationNumber, $resolveOptions, $normalizerFactory); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
*/ |
|
47
|
4 |
|
public function getXML(): \SimpleXMLElement |
|
48
|
|
|
{ |
|
49
|
4 |
|
if (is_null($this->namespace)) { |
|
50
|
1 |
|
throw new \LogicException('Namespace not set.'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
3 |
|
if (is_null($this->nodePrefix)) { |
|
54
|
1 |
|
throw new \LogicException('Node name prefix not set.'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
2 |
|
$xml = $this->createXML()->addChild($this->namespace . ':' . $this->nodePrefix . 'Item', '', $this->namespace($this->namespace)); |
|
58
|
|
|
|
|
59
|
2 |
|
$this->addElements($xml, \array_merge($this->elements, ($this->useOneDirectionalVariables ? $this->additionalElements : []), ['parameters']), $this->namespace); |
|
60
|
|
|
|
|
61
|
2 |
|
return $xml; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* {@inheritdoc} |
|
66
|
|
|
*/ |
|
67
|
2 |
|
protected function configureOptions(Common\OptionsResolver $resolver): void |
|
68
|
|
|
{ |
|
69
|
2 |
|
$resolver->setDefined(array_merge($this->elements, ($this->useOneDirectionalVariables ? $this->additionalElements : []))); |
|
70
|
|
|
|
|
71
|
|
|
// validate / format options |
|
72
|
2 |
|
$resolver->setNormalizer('text', $this->normalizerFactory->getClosure('string90')); |
|
73
|
2 |
|
$resolver->setNormalizer('quantity', $this->normalizerFactory->getClosure('float')); |
|
74
|
2 |
|
$resolver->setNormalizer('delivered', $this->normalizerFactory->getClosure('float')); |
|
75
|
2 |
|
$resolver->setNormalizer('unit', $this->normalizerFactory->getClosure('string10')); |
|
76
|
2 |
|
$resolver->setNormalizer('coefficient', $this->normalizerFactory->getClosure('float')); |
|
77
|
2 |
|
$resolver->setNormalizer('payVAT', $this->normalizerFactory->getClosure('bool')); |
|
78
|
2 |
|
$resolver->setAllowedValues('rateVAT', ['none', 'high', 'low', 'third', 'historyHigh', 'historyLow', 'historyThird']); |
|
79
|
2 |
|
$resolver->setNormalizer('rateVatValue', $this->normalizerFactory->getClosure('float')); |
|
80
|
2 |
|
$resolver->setNormalizer('percentVAT', $this->normalizerFactory->getClosure('float')); |
|
81
|
2 |
|
$resolver->setNormalizer('discountPercentage', $this->normalizerFactory->getClosure('float')); |
|
82
|
2 |
|
$resolver->setNormalizer('note', $this->normalizerFactory->getClosure('string90')); |
|
83
|
2 |
|
$resolver->setNormalizer('code', $this->normalizerFactory->getClosure('string64')); |
|
84
|
2 |
|
$resolver->setNormalizer('PDP', $this->normalizerFactory->getClosure('bool')); |
|
85
|
|
|
|
|
86
|
2 |
|
if ($this->useOneDirectionalVariables) { |
|
87
|
1 |
|
$resolver->setNormalizer('id', $this->normalizerFactory->getClosure('int')); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|