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\AbstractHeader; |
16
|
|
|
|
17
|
|
|
class Header extends AbstractHeader |
18
|
|
|
{ |
19
|
|
|
/** @var string[] */ |
20
|
|
|
protected array $refElements = ['extId', 'number', 'paymentType', 'priceLevel', 'centre', 'activity', 'contract', 'regVATinEU', 'MOSS', 'evidentiaryResourcesMOSS', 'carrier']; |
21
|
|
|
|
22
|
|
|
/** @var string[] */ |
23
|
|
|
protected array $elements = ['extId', 'orderType', 'number', 'numberOrder', 'date', 'dateDelivery', 'dateFrom', 'dateTo', 'text', 'partnerIdentity', 'myIdentity', 'paymentType', 'priceLevel', 'isExecuted', 'isReserved', 'centre', 'activity', 'contract', 'regVATinEU', 'MOSS', 'evidentiaryResourcesMOSS', 'accountingPeriodMOSS', 'note', 'carrier', 'intNote', 'markRecord', 'histRate']; |
24
|
|
|
|
25
|
|
|
/** @var string[] */ |
26
|
|
|
protected array $additionalElements = ['id', 'isDelivered', 'permanentDocument']; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
11 |
|
public function getXML(): \SimpleXMLElement |
32
|
|
|
{ |
33
|
11 |
|
if (is_null($this->namespace)) { |
34
|
1 |
|
throw new \LogicException('Namespace not set.'); |
35
|
|
|
} |
36
|
|
|
|
37
|
10 |
|
if (is_null($this->nodePrefix)) { |
38
|
1 |
|
throw new \LogicException('Node name prefix not set.'); |
39
|
|
|
} |
40
|
|
|
|
41
|
9 |
|
$xml = $this->createXML()->addChild($this->namespace . ':' . $this->nodePrefix . 'Header', '', $this->namespace($this->namespace)); |
42
|
|
|
|
43
|
9 |
|
$this->addElements($xml, \array_merge($this->elements, ($this->useOneDirectionalVariables ? $this->additionalElements : []), ['parameters']), $this->namespace); |
44
|
|
|
|
45
|
9 |
|
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->setDefault('orderType', 'receivedOrder'); |
57
|
2 |
|
$resolver->setAllowedValues('orderType', ['receivedOrder', 'issuedOrder']); |
58
|
2 |
|
$resolver->setNormalizer('numberOrder', $this->normalizerFactory->getClosure('string32')); |
59
|
2 |
|
$resolver->setNormalizer('date', $this->normalizerFactory->getClosure('date')); |
60
|
2 |
|
$resolver->setNormalizer('dateDelivery', $this->normalizerFactory->getClosure('date')); |
61
|
2 |
|
$resolver->setNormalizer('dateFrom', $this->normalizerFactory->getClosure('date')); |
62
|
2 |
|
$resolver->setNormalizer('dateTo', $this->normalizerFactory->getClosure('date')); |
63
|
2 |
|
$resolver->setNormalizer('text', $this->normalizerFactory->getClosure('string240')); |
64
|
2 |
|
$resolver->setNormalizer('isExecuted', $this->normalizerFactory->getClosure('bool')); |
65
|
2 |
|
$resolver->setNormalizer('isReserved', $this->normalizerFactory->getClosure('bool')); |
66
|
2 |
|
$resolver->setNormalizer('markRecord', $this->normalizerFactory->getClosure('bool')); |
67
|
2 |
|
$resolver->setNormalizer('histRate', $this->normalizerFactory->getClosure('bool')); |
68
|
|
|
|
69
|
2 |
|
if ($this->useOneDirectionalVariables) { |
70
|
1 |
|
$resolver->setNormalizer('id', $this->normalizerFactory->getClosure('int')); |
71
|
1 |
|
$resolver->setNormalizer('isDelivered', $this->normalizerFactory->getClosure('bool')); |
72
|
1 |
|
$resolver->setNormalizer('permanentDocument', $this->normalizerFactory->getClosure('bool')); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|