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 TraitLines |
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
use TraitBasic, |
35
|
|
|
TraitTax; |
36
|
|
|
|
37
|
|
|
private function getDocumentLines(\SimpleXMLElement $arrayDataIn, string $strTag): array |
38
|
|
|
{ |
39
|
|
|
$arrayLines = []; |
40
|
|
|
$intLineNo = 0; |
41
|
|
|
foreach ($arrayDataIn->children('cac', true) as $strNodeName => $child) { |
42
|
|
|
if ($strNodeName === ($strTag . 'Line')) { |
43
|
|
|
$intLineNo++; |
44
|
|
|
$intLineStr = ($intLineNo < 10 ? '0' : '') . $intLineNo; |
45
|
|
|
$arrayLines[$intLineStr] = $this->getLine($child); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
return $arrayLines; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
private function getLine(\SimpleXMLElement $child): array |
52
|
|
|
{ |
53
|
|
|
$arrayOutput = []; |
54
|
|
|
foreach ($this->arraySettings['CustomOrder']['Lines@Read'] as $strElement => $strType) { |
55
|
|
|
switch ($strType) { |
56
|
|
|
case 'Item': |
57
|
|
|
$arrayOutput['Item'] = $this->getLineItem($child->children('cac', true)->Item); |
58
|
|
|
break; |
59
|
|
|
case 'Multiple': |
60
|
|
|
$intLineNo = 0; |
61
|
|
|
foreach ($child->children('cac', true)->$strElement as $value2) { |
62
|
|
|
$intLineNo++; |
63
|
|
|
$intLineStr = ($intLineNo < 10 ? '0' : '') . $intLineNo; |
64
|
|
|
$arrayOutput[$strElement][$intLineStr] = $this->getElements($value2); |
65
|
|
|
} |
66
|
|
|
break; |
67
|
|
|
case 'Single': |
68
|
|
|
if (count($child->children('cbc', true)->$strElement) !== 0) { |
69
|
|
|
$arrayOutput[$strElement] = $child->children('cbc', true)->$strElement->__toString(); |
70
|
|
|
} |
71
|
|
|
if (count($child->children('cac', true)->$strElement) !== 0) { |
72
|
|
|
$arrayOutput[$strElement] = $this->getElements($child->children('cac', true)->$strElement); |
73
|
|
|
} |
74
|
|
|
break; |
75
|
|
|
case 'SingleTag': |
76
|
|
|
if (count($child->children('cbc', true)->$strElement) !== 0) { |
77
|
|
|
$arrayOutput[$strElement] = $this->getElementSingle($child->children('cbc', true)->$strElement); |
78
|
|
|
} |
79
|
|
|
break; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
return $arrayOutput; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
private function getLineItem(\SimpleXMLElement $child3): array |
86
|
|
|
{ |
87
|
|
|
$arrayOutput = []; |
88
|
|
|
foreach ($this->arraySettings['CustomOrder']['Lines_Item@Read'] as $key => $value) { |
89
|
|
|
switch ($value) { |
90
|
|
|
case 'MultipleAggregate': |
91
|
|
|
$intLineNo = 0; |
92
|
|
|
foreach ($child3->children('cac', true)->$key as $value2) { |
93
|
|
|
$intLineNo++; |
94
|
|
|
$intLineStr = ($intLineNo < 10 ? '0' : '') . $intLineNo; |
95
|
|
|
$arrayOutput[$key][$intLineStr] = $this->getElements($value2); |
96
|
|
|
} |
97
|
|
|
break; |
98
|
|
|
case 'SingleAggregate': |
99
|
|
|
if (count($child3->children('cac', true)->$key) !== 0) { |
100
|
|
|
$arrayOutput[$key] = $this->getElements($child3->children('cac', true)->$key); |
101
|
|
|
} |
102
|
|
|
break; |
103
|
|
|
case 'SingleBasic': |
104
|
|
|
if (count($child3->children('cbc', true)->$key) !== 0) { |
105
|
|
|
$arrayOutput[$key] = $child3->children('cbc', true)->$key->__toString(); |
106
|
|
|
} |
107
|
|
|
break; |
108
|
|
|
case 'TaxCategory': |
109
|
|
|
$arrayOutput[$key] = $this->getTaxCategory($child3->children('cac', true)->$key); |
110
|
|
|
break; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
return $arrayOutput; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|