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($objFile, string $strTag): array |
38
|
|
|
{ |
39
|
|
|
$arrayLines = []; |
40
|
|
|
$intLineNo = 0; |
41
|
|
|
foreach ($objFile->children('cac', true) as $strNodeName => $child) { |
42
|
|
|
if ($strNodeName === ($strTag . 'Line')) { |
43
|
|
|
$intLineNo++; |
44
|
|
|
$intLineStr = ($intLineNo < 10 ? '0' : '') . $intLineNo; |
45
|
|
|
$arrayLines[$intLineStr] = $this->getLine($strTag, $child); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
return $arrayLines; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
private function getLine(string $strType, $child): array |
52
|
|
|
{ |
53
|
|
|
$arrayOutput = [ |
54
|
|
|
'ID' => $child->children('cbc', true)->ID->__toString(), |
55
|
|
|
'LineExtensionAmount' => $this->getElementSingle($child->children('cbc', true) |
56
|
|
|
->LineExtensionAmount), |
57
|
|
|
]; |
58
|
|
|
// optional components ========================================================================================= |
59
|
|
|
if (isset($child->children('cac', true)->OrderLineReference)) { |
60
|
|
|
$arrayOutput['OrderLineReference']['LineID'] = $child->children('cac', true)->OrderLineReference |
61
|
|
|
->children('cbc', true)->LineID->__toString(); |
62
|
|
|
} |
63
|
|
|
if (isset($child->children('cac', true)->DocumentReference)) { |
64
|
|
|
$arrayOutput['DocumentReference']['ID'] = $child->children('cac', true)->DocumentReference |
65
|
|
|
->children('cbc', true)->ID->__toString(); |
66
|
|
|
} |
67
|
|
|
foreach (['AccountingCost', 'InvoicePeriod', 'Note'] as $strElement) { |
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
|
|
|
} |
75
|
|
|
switch ($strType) { |
76
|
|
|
case 'CreditNote': |
77
|
|
|
$arrayOutput['CreditedQuantity'] = $this->getElementSingle($child->children('cbc', true) |
78
|
|
|
->CreditedQuantity); |
79
|
|
|
break; |
80
|
|
|
case 'Invoice': |
81
|
|
|
$arrayOutput['InvoicedQuantity'] = $this->getElementSingle($child->children('cbc', true) |
82
|
|
|
->InvoicedQuantity); |
83
|
|
|
break; |
84
|
|
|
} |
85
|
|
|
$arrayOutput['Item'] = $this->getLineItem($child->children('cac', true)->Item); |
86
|
|
|
$arrayOutput['Price'] = $this->getElements($child->children('cac', true)->Price); |
87
|
|
|
return $arrayOutput; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
private function getLineItem($child3): array |
91
|
|
|
{ |
92
|
|
|
$arrayOutput = []; |
93
|
|
|
foreach ($this->arraySettings['CustomOrder']['Lines_Item'] as $value) { |
94
|
|
|
switch ($value) { |
95
|
|
|
case 'AdditionalItemProperty': |
96
|
|
|
$intLineNo = 0; |
97
|
|
|
foreach ($child3->children('cac', true)->$value as $value2) { |
98
|
|
|
$intLineNo++; |
99
|
|
|
$intLineStr = ($intLineNo < 10 ? '0' : '') . $intLineNo; |
100
|
|
|
$arrayOutput[$value][$intLineStr] = [ |
101
|
|
|
'Name' => $value2->children('cbc', true)->Name->__toString(), |
102
|
|
|
'Value' => $value2->children('cbc', true)->Value->__toString(), |
103
|
|
|
]; |
104
|
|
|
} |
105
|
|
|
break; |
106
|
|
|
case 'ClassifiedTaxCategory': |
107
|
|
|
$arrayOutput[$value] = $this->getTaxCategory($child3->children('cac', true)->$value); |
108
|
|
|
break; |
109
|
|
|
case 'CommodityClassification': |
110
|
|
|
// intentionally left open |
111
|
|
|
case 'StandardItemIdentification': |
112
|
|
|
$intLineNo = 0; |
113
|
|
|
foreach ($child3->children('cac', true)->$value as $value2) { |
114
|
|
|
$intLineNo++; |
115
|
|
|
$intLineStr = ($intLineNo < 10 ? '0' : '') . $intLineNo; |
116
|
|
|
$arrayOutput[$value][$intLineStr] = $this->getElements($value2); |
117
|
|
|
} |
118
|
|
|
break; |
119
|
|
|
case 'OriginCountry': |
120
|
|
|
// intentionally left open |
121
|
|
|
case 'SellersItemIdentification': |
122
|
|
|
if (count($child3->children('cac', true)->$value) !== 0) { |
123
|
|
|
$arrayOutput[$value] = $this->getElements($child3->children('cac', true)->$value); |
124
|
|
|
} |
125
|
|
|
break; |
126
|
|
|
default: |
127
|
|
|
if (count($child3->children('cbc', true)->$value) !== 0) { |
128
|
|
|
$arrayOutput[$value] = $child3->children('cbc', true)->$value->__toString(); |
129
|
|
|
} |
130
|
|
|
break; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
return $arrayOutput; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|