|
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 TraitTax; |
|
35
|
|
|
|
|
36
|
|
|
private function getDocumentLines($objFile, string $strTag): array |
|
37
|
|
|
{ |
|
38
|
|
|
$arrayLines = []; |
|
39
|
|
|
$intLineNo = 0; |
|
40
|
|
|
foreach ($objFile->children('cac', true) as $strNodeName => $child) { |
|
41
|
|
|
if ($strNodeName === ($strTag . 'Line')) { |
|
42
|
|
|
$intLineNo++; |
|
43
|
|
|
$intLineStr = ($intLineNo < 10 ? '0' : '') . $intLineNo; |
|
44
|
|
|
$arrayLines[$intLineStr] = $this->getLine($strTag, $child); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
return $arrayLines; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
private function getLine(string $strType, $child): array |
|
51
|
|
|
{ |
|
52
|
|
|
$arrayOutput = [ |
|
53
|
|
|
'ID' => $child->children('cbc', true)->ID->__toString(), |
|
54
|
|
|
'LineExtensionAmount' => $this->getTagWithCurrencyParameter($child->children('cbc', true) |
|
55
|
|
|
->LineExtensionAmount), |
|
56
|
|
|
]; |
|
57
|
|
|
// optional components ========================================================================================= |
|
58
|
|
|
if (isset($child->children('cac', true)->OrderLineReference)) { |
|
59
|
|
|
$arrayOutput['OrderLineReference']['LineID'] = $child->children('cac', true)->OrderLineReference |
|
60
|
|
|
->children('cbc', true)->LineID->__toString(); |
|
61
|
|
|
} |
|
62
|
|
|
if (isset($child->children('cac', true)->DocumentReference)) { |
|
63
|
|
|
$arrayOutput['DocumentReference']['ID'] = $child->children('cac', true)->DocumentReference |
|
64
|
|
|
->children('cbc', true)->ID->__toString(); |
|
65
|
|
|
} |
|
66
|
|
|
if (isset($child->children('cbc', true)->AccountingCost)) { |
|
67
|
|
|
$arrayOutput['AccountingCost'] = $child->children('cbc', true)->AccountingCost->__toString(); |
|
68
|
|
|
} |
|
69
|
|
|
if (isset($child->children('cbc', true)->Note)) { |
|
70
|
|
|
$arrayOutput['Note'] = $child->children('cbc', true)->Note->__toString(); |
|
71
|
|
|
} |
|
72
|
|
|
switch ($strType) { |
|
73
|
|
|
case 'CreditNote': |
|
74
|
|
|
$arrayOutput['CreditedQuantity'] = $this->getTagWithUnitCodeParameter($child->children('cbc', true) |
|
75
|
|
|
->CreditedQuantity); |
|
76
|
|
|
break; |
|
77
|
|
|
case 'Invoice': |
|
78
|
|
|
$arrayOutput['InvoicedQuantity'] = $this->getTagWithUnitCodeParameter($child->children('cbc', true) |
|
79
|
|
|
->InvoicedQuantity); |
|
80
|
|
|
break; |
|
81
|
|
|
} |
|
82
|
|
|
if (isset($child->children('cac', true)->AllowanceCharge)) { |
|
83
|
|
|
$arrayOutput['AllowanceCharge'] = $this->getLineItemAllowanceCharge($child |
|
84
|
|
|
->children('cac', true)->AllowanceCharge); |
|
85
|
|
|
} |
|
86
|
|
|
$arrayOutput['Item'] = $this->getLineItem($child->children('cac', true)->Item); |
|
87
|
|
|
$arrayOutput['Price'] = $this->getElements($child->children('cac', true)->Price); |
|
88
|
|
|
return $arrayOutput; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
private function getLineItem($child3): array |
|
92
|
|
|
{ |
|
93
|
|
|
$arrayOutput = []; |
|
94
|
|
|
foreach ($this->arraySettings['CustomOrder']['Lines_Item'] as $value) { |
|
95
|
|
|
switch ($value) { |
|
96
|
|
|
case 'AdditionalItemProperty': |
|
97
|
|
|
$intLineNo = 0; |
|
98
|
|
|
foreach ($child3->children('cac', true)->$value as $value2) { |
|
99
|
|
|
$intLineNo++; |
|
100
|
|
|
$intLineStr = ($intLineNo < 10 ? '0' : '') . $intLineNo; |
|
101
|
|
|
$arrayOutput[$value][$intLineStr] = [ |
|
102
|
|
|
'Name' => $value2->children('cbc', true)->Name->__toString(), |
|
103
|
|
|
'Value' => $value2->children('cbc', true)->Value->__toString(), |
|
104
|
|
|
]; |
|
105
|
|
|
} |
|
106
|
|
|
break; |
|
107
|
|
|
case 'ClassifiedTaxCategory': |
|
108
|
|
|
$arrayOutput[$value] = $this->getTaxCategory($child3->children('cac', true)->$value); |
|
109
|
|
|
break; |
|
110
|
|
|
case 'CommodityClassification': |
|
111
|
|
|
// intentionally left open |
|
112
|
|
|
case 'StandardItemIdentification': |
|
113
|
|
|
$intLineNo = 0; |
|
114
|
|
|
foreach ($child3->children('cac', true)->$value as $value2) { |
|
115
|
|
|
$intLineNo++; |
|
116
|
|
|
$intLineStr = ($intLineNo < 10 ? '0' : '') . $intLineNo; |
|
117
|
|
|
$arrayOutput[$value][$intLineStr] = $this->getElements($value2); |
|
118
|
|
|
} |
|
119
|
|
|
break; |
|
120
|
|
|
case 'OriginCountry': |
|
121
|
|
|
// intentionally left open |
|
122
|
|
|
case 'SellersItemIdentification': |
|
123
|
|
|
if (count($child3->children('cac', true)->$value) !== 0) { |
|
124
|
|
|
$arrayOutput[$value] = $this->getElements($child3->children('cac', true)->$value); |
|
125
|
|
|
} |
|
126
|
|
|
break; |
|
127
|
|
|
default: |
|
128
|
|
|
if (count($child3->children('cbc', true)->$value) !== 0) { |
|
129
|
|
|
$arrayOutput[$value] = $child3->children('cbc', true)->$value->__toString(); |
|
130
|
|
|
} |
|
131
|
|
|
break; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
return $arrayOutput; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
private function getLineItemAllowanceCharge($child3): array |
|
138
|
|
|
{ |
|
139
|
|
|
$arrayOutput = []; |
|
140
|
|
|
$intLineNo = 0; |
|
141
|
|
|
foreach ($child3 as $child4) { |
|
142
|
|
|
$intLineNo++; |
|
143
|
|
|
$intLineStr = ($intLineNo < 10 ? '0' : '') . $intLineNo; |
|
144
|
|
|
$arrayOutput[$intLineStr] = [ |
|
145
|
|
|
'Amount' => $this->getTagWithCurrencyParameter($child4 |
|
146
|
|
|
->children('cbc', true)->Amount), |
|
147
|
|
|
'AllowanceChargeReasonCode' => $child4->children('cbc', true)->AllowanceChargeReasonCode->__toString(), |
|
148
|
|
|
'ChargeIndicator' => $child4->children('cbc', true)->ChargeIndicator->__toString(), |
|
149
|
|
|
]; |
|
150
|
|
|
if (isset($child4->children('cbc', true)->AllowanceChargeReason)) { |
|
151
|
|
|
$arrayOutput[$intLineStr]['AllowanceChargeReason'] = $child4 |
|
152
|
|
|
->children('cbc', true)->AllowanceChargeReason->__toString(); |
|
153
|
|
|
} |
|
154
|
|
|
if (isset($child4->children('cbc', true)->BaseAmount)) { |
|
155
|
|
|
$arrayOutput[$intLineStr]['BaseAmount'] = $this->getTagWithCurrencyParameter($child4 |
|
156
|
|
|
->children('cbc', true)->BaseAmount); |
|
157
|
|
|
} |
|
158
|
|
|
if (isset($child4->children('cbc', true)->MultiplierFactorNumeric)) { |
|
159
|
|
|
$arrayOutput[$intLineStr]['MultiplierFactorNumeric'] = $child4 |
|
160
|
|
|
->children('cbc', true)->MultiplierFactorNumeric->__toString(); |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
return $arrayOutput; |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
|