|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
* The MIT License (MIT) |
|
6
|
|
|
* |
|
7
|
|
|
* Copyright (c) 2024 Daniel Popiniuc |
|
8
|
|
|
* |
|
9
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
10
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
11
|
|
|
* in the Software without restriction, including without limitation the rights |
|
12
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
13
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
14
|
|
|
* furnished to do so, subject to the following conditions: |
|
15
|
|
|
* |
|
16
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
17
|
|
|
* copies or substantial portions of the Software. |
|
18
|
|
|
* |
|
19
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
20
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
21
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
22
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
23
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
24
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
25
|
|
|
* SOFTWARE. |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
namespace danielgp\efactura; |
|
30
|
|
|
|
|
31
|
|
|
trait TraitBasic |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
protected array $arraySettings = []; |
|
35
|
|
|
|
|
36
|
|
|
private function getCommentsFromFileAsArray(): array |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->getJsonFromFile('ElectronicInvoiceComments.json'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
private function getElements(\SimpleXMLElement $arrayIn): array |
|
42
|
|
|
{ |
|
43
|
|
|
$arrayToReturn = []; |
|
44
|
|
|
foreach ($arrayIn->children('cbc', true) as $key => $value) { |
|
45
|
|
|
if (count($value->attributes()) === 0) { |
|
46
|
|
|
$arrayToReturn[$key] = $value->__toString(); |
|
47
|
|
|
} else { |
|
48
|
|
|
foreach ($value->attributes() as $keyA => $valueA) { |
|
49
|
|
|
$arrayToReturn[$key] = [ |
|
50
|
|
|
$keyA => $valueA->__toString(), |
|
51
|
|
|
'value' => $value->__toString(), |
|
52
|
|
|
]; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
return $arrayToReturn; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
private function getJsonFromFile(string $strFileName): array |
|
60
|
|
|
{ |
|
61
|
|
|
$strFileName = __DIR__ . DIRECTORY_SEPARATOR . $strFileName; |
|
62
|
|
|
if (!file_exists($strFileName)) { |
|
63
|
|
|
throw new \RuntimeException(sprintf('File %s does not exists!', $strFileName)); |
|
64
|
|
|
} |
|
65
|
|
|
$fileHandle = fopen($strFileName, 'r'); |
|
66
|
|
|
if ($fileHandle === false) { |
|
67
|
|
|
throw new \RuntimeException(sprintf('Unable to open file %s for read purpose!', $strFileName)); |
|
68
|
|
|
} |
|
69
|
|
|
$fileContent = fread($fileHandle, ((int) filesize($strFileName))); |
|
70
|
|
|
fclose($fileHandle); |
|
71
|
|
|
$arrayToReturn = json_decode($fileContent, true); |
|
72
|
|
|
if (json_last_error() != JSON_ERROR_NONE) { |
|
73
|
|
|
throw new \RuntimeException(sprintf('Unable to interpret JSON from %s file...', $strFileName)); |
|
74
|
|
|
} |
|
75
|
|
|
return $arrayToReturn; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
private function getHierarchyTagOrder(): void |
|
79
|
|
|
{ |
|
80
|
|
|
$this->arraySettings['CustomOrder'] = $this->getJsonFromFile('ElectronicInvoiceHierarchyTagOrder.json'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
private function getMultipleElements(array|\SimpleXMLElement $arrayIn): array |
|
84
|
|
|
{ |
|
85
|
|
|
$arrayToReturn = []; |
|
86
|
|
|
$intLineNo = 0; |
|
87
|
|
|
foreach ($arrayIn as $child) { |
|
88
|
|
|
$intLineNo++; |
|
89
|
|
|
$intLineStr = ($intLineNo < 10 ? '0' : '') . $intLineNo; |
|
90
|
|
|
$arrayToReturn[$intLineStr] = $this->getPaymentMeans($child); |
|
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
return $arrayToReturn; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
private function getMultipleElementsStandard(array|\SimpleXMLElement $arrayIn): array |
|
96
|
|
|
{ |
|
97
|
|
|
$arrayToReturn = []; |
|
98
|
|
|
$intLineNo = 0; |
|
99
|
|
|
foreach ($arrayIn as $child) { |
|
100
|
|
|
$intLineNo++; |
|
101
|
|
|
$intLineStr = ($intLineNo < 10 ? '0' : '') . $intLineNo; |
|
102
|
|
|
foreach ($child->children('cbc', true) as $key2 => $value2) { |
|
103
|
|
|
if (count($value2->attributes()) === 0) { |
|
104
|
|
|
$arrayToReturn[$intLineStr][$key2] = $value2->__toString(); |
|
105
|
|
|
} else { |
|
106
|
|
|
foreach ($value2->attributes() as $keyA => $valueA) { |
|
107
|
|
|
$arrayToReturn[$intLineStr][$key2] = [ |
|
108
|
|
|
$keyA => $valueA->__toString(), |
|
109
|
|
|
'value' => $value2->__toString(), |
|
110
|
|
|
]; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
foreach ($child->children('cac', true) as $key2 => $value2) { |
|
115
|
|
|
foreach ($value2->children('cbc', true) as $key3 => $value3) { |
|
116
|
|
|
$arrayToReturn[$intLineStr][$key2][$key3] = $value3->__toString(); |
|
117
|
|
|
} |
|
118
|
|
|
foreach ($value2->children('cac', true) as $key3 => $value3) { |
|
119
|
|
|
foreach ($value3->children('cbc', true) as $key4 => $value4) { |
|
120
|
|
|
$arrayToReturn[$intLineStr][$key2][$key3][$key4] = $value4->__toString(); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
return $arrayToReturn; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
private function getTagWithCurrencyParameter($childLineExtensionAmount): array |
|
129
|
|
|
{ |
|
130
|
|
|
return [ |
|
131
|
|
|
'currencyID' => $childLineExtensionAmount->attributes()->currencyID->__toString(), |
|
132
|
|
|
'value' => (float) $childLineExtensionAmount->__toString(), |
|
133
|
|
|
]; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
private function getTagWithCurrencyParameterAsString($childLineExtensionAmount): array |
|
137
|
|
|
{ |
|
138
|
|
|
return [ |
|
139
|
|
|
'currencyID' => $childLineExtensionAmount->attributes()->currencyID->__toString(), |
|
140
|
|
|
'value' => $childLineExtensionAmount->__toString(), |
|
141
|
|
|
]; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
private function getTagWithUnitCodeParameter($childLineExtensionAmount): array |
|
145
|
|
|
{ |
|
146
|
|
|
return [ |
|
147
|
|
|
'unitCode' => $childLineExtensionAmount->attributes()->unitCode->__toString(), |
|
148
|
|
|
'value' => (float) $childLineExtensionAmount->__toString(), |
|
149
|
|
|
]; |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|