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) { |
37
|
|
|
$arrayLines = []; |
38
|
|
|
$intLineNo = 0; |
39
|
|
|
foreach ($objFile->children('cac', true) as $strNodeName => $child) { |
40
|
|
|
if ($strNodeName === ($strTag . 'Line')) { |
41
|
|
|
$intLineNo++; |
42
|
|
|
$intLineStr = ($intLineNo < 10 ? '0' : '') . $intLineNo; |
43
|
|
|
$arrayLines[$intLineStr] = $this->getLine($strTag, $child); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
return $arrayLines; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
private function getLine(string $strType, $child): array { |
50
|
|
|
$arrayOutput = [ |
51
|
|
|
'ID' => $child->children('cbc', true)->ID->__toString(), |
52
|
|
|
'LineExtensionAmount' => $this->getTagWithCurrencyParameter($child->children('cbc', true) |
53
|
|
|
->LineExtensionAmount), |
54
|
|
|
]; |
55
|
|
|
// optional components ========================================================================================= |
56
|
|
|
if (isset($child->children('cbc', true)->Note)) { |
57
|
|
|
$arrayOutput['Note'] = $child->children('cbc', true)->Note->__toString(); |
58
|
|
|
} |
59
|
|
|
switch ($strType) { |
60
|
|
|
case 'CreditNote': |
61
|
|
|
$arrayOutput['CreditedQuantity'] = $this->getTagWithUnitCodeParameter($child->children('cbc', true) |
62
|
|
|
->CreditedQuantity); |
63
|
|
|
break; |
64
|
|
|
case 'Invoice': |
65
|
|
|
$arrayOutput['InvoicedQuantity'] = $this->getTagWithUnitCodeParameter($child->children('cbc', true) |
66
|
|
|
->InvoicedQuantity); |
67
|
|
|
break; |
68
|
|
|
} |
69
|
|
|
$arrayOutput['Item'] = $this->getLineItem($child->children('cac', true)->Item); |
70
|
|
|
$arrayOutput['Price'] = $this->getLinePrice($child->children('cac', true)->Price); |
71
|
|
|
return $arrayOutput; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
private function getLineItem($child3): array { |
75
|
|
|
$arrayOutput = [ |
76
|
|
|
'Name' => $child3->children('cbc', true)->Name->__toString(), |
77
|
|
|
]; |
78
|
|
|
// optional components ========================================================================================= |
79
|
|
|
if (isset($child3->children('cbc', true)->Description)) { |
80
|
|
|
$arrayOutput['Description'] = $child3->children('cac', true)->Description->__toString(); |
81
|
|
|
} |
82
|
|
|
if (isset($child3->children('cac', true)->AllowanceCharge)) { |
83
|
|
|
$intLineNo = 0; |
84
|
|
|
foreach ($child3->children('cac', true)->AllowanceCharge as $child4) { |
85
|
|
|
$intLineNo++; |
86
|
|
|
$intLineStr = ($intLineNo < 10 ? '0' : '') . $intLineNo; |
87
|
|
|
$arrayOutput['AllowanceCharge'][$intLineStr] = $this->getLineItemAllowanceCharge($child4); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
if (isset($child3->children('cac', true)->CommodityClassification)) { |
91
|
|
|
$child4 = $child3->children('cac', true) |
92
|
|
|
->CommodityClassification->children('cbc', true)->ItemClassificationCode; |
93
|
|
|
$arrayOutput['CommodityClassification']['ItemClassificationCode'] = [ |
94
|
|
|
'listID' => $child4->attributes()->listID->__toString(), |
95
|
|
|
'value' => $child4->__toString(), |
96
|
|
|
]; |
97
|
|
|
} |
98
|
|
|
if (isset($child3->children('cac', true)->SellersItemIdentification)) { |
99
|
|
|
$arrayOutput['SellersItemIdentification']['ID'] = $child3 |
100
|
|
|
->children('cac', true)->SellersItemIdentification->children('cbc', true)->ID->__toString(); |
101
|
|
|
} |
102
|
|
|
$arrayOutput['ClassifiedTaxCategory'] = $this->getTaxCategory($child3 |
103
|
|
|
->children('cac', true)->ClassifiedTaxCategory); |
104
|
|
|
return $arrayOutput; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
private function getLineItemAllowanceCharge($child2): array { |
108
|
|
|
$arrayOutput = [ |
109
|
|
|
'Amount' => $this->getTagWithCurrencyParameter($child2->Amount), |
110
|
|
|
'AllowanceChargeReason' => $child2->children('cbc', true)->AllowanceChargeReason->__toString(), |
111
|
|
|
'AllowanceChargeReasonCode' => $child2->children('cbc', true)->AllowanceChargeReasonCode->__toString(), |
112
|
|
|
'ChargeIndicator' => $child2->children('cbc', true)->ChargeIndicator->__toString(), |
113
|
|
|
]; |
114
|
|
|
// optional components ========================================================================================= |
115
|
|
|
if (isset($child2->children('cbc', true)->BaseAmount)) { |
116
|
|
|
$arrayOutput['BaseAmount'] = $this->getTagWithCurrencyParameter($child2->children('cbc', true) |
117
|
|
|
->BaseAmount); |
118
|
|
|
} |
119
|
|
|
return $arrayOutput; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
private function getLinePrice($child2): array { |
123
|
|
|
$arrayOutput = [ |
124
|
|
|
'PriceAmount' => $this->getTagWithCurrencyParameter($child2->children('cbc', true)->PriceAmount), |
125
|
|
|
]; |
126
|
|
|
// optional components ========================================================================================= |
127
|
|
|
if (isset($child2->children('cbc', true)->BaseQuantity)) { |
128
|
|
|
$arrayOutput['BaseQuantity'] = $this->getTagWithUnitCodeParameter($child2->children('cbc', true) |
129
|
|
|
->BaseQuantity); |
130
|
|
|
} |
131
|
|
|
return $arrayOutput; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|