1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Copyright (c) 2024 - 2025 Daniel Popiniuc. |
5
|
|
|
* All rights reserved. This program and the accompanying materials |
6
|
|
|
* are made available under the terms of the Eclipse Public License v1.0 |
7
|
|
|
* which accompanies this distribution, and is available at |
8
|
|
|
* http://www.eclipse.org/legal/epl-v10.html |
9
|
|
|
* |
10
|
|
|
* Contributors: |
11
|
|
|
* Daniel Popiniuc |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace danielgp\efactura; |
15
|
|
|
|
16
|
|
|
trait TraitTax |
17
|
|
|
{ |
18
|
|
|
use TraitBasic; |
19
|
|
|
|
20
|
13 |
|
private function getTax(\SimpleXMLElement $child): array |
21
|
|
|
{ |
22
|
13 |
|
$arrayOut = []; |
23
|
13 |
|
$intLineNo = 0; |
24
|
13 |
|
foreach ($child as $child2) { |
25
|
13 |
|
if (!is_null($child2)) { |
26
|
13 |
|
$intLineNo++; |
27
|
13 |
|
$intLineStr = $this->getLineStringFromNumber($intLineNo); |
28
|
13 |
|
$arrayOut[$intLineStr] = $this->getTaxTotal($child2); |
29
|
|
|
} |
30
|
|
|
} |
31
|
13 |
|
return $arrayOut; |
32
|
|
|
} |
33
|
|
|
|
34
|
13 |
|
private function getTaxCategory(\SimpleXMLElement $child3, string $strElementName): array |
35
|
|
|
{ |
36
|
13 |
|
$arrayOut = []; |
37
|
13 |
|
foreach ($this->arrayProcessing[$strElementName] as $strElement => $strType) { |
38
|
|
|
switch($strType) { |
39
|
13 |
|
case 'Elements': |
40
|
13 |
|
if (isset($child3->children($this->arrayProcessing['mapping']['cac'], true)->$strElement)) { |
41
|
13 |
|
$arrayOut[$strElement] = $this->getElements($child3->children($this |
42
|
13 |
|
->arrayProcessing['mapping']['cac'], true)->$strElement); |
43
|
|
|
} |
44
|
13 |
|
break; |
45
|
13 |
|
case 'Single': |
46
|
13 |
|
if (isset($child3->children($this->arrayProcessing['mapping']['cbc'], true)->$strElement)) { |
47
|
13 |
|
$arrayOut[$strElement] = $this->getElementSingle($child3->children($this |
48
|
13 |
|
->arrayProcessing['mapping']['cbc'], true)->$strElement); |
49
|
|
|
} |
50
|
13 |
|
break; |
51
|
|
|
} |
52
|
|
|
} |
53
|
13 |
|
return $arrayOut; |
54
|
|
|
} |
55
|
|
|
|
56
|
13 |
|
private function getTaxSubTotal(\SimpleXMLElement $child) |
57
|
|
|
{ |
58
|
13 |
|
$arrayOut = []; |
59
|
13 |
|
foreach ($this->arrayProcessing['TaxSubtotal'] as $strElementChild => $strTypeChild) { |
60
|
|
|
switch($strTypeChild) { |
61
|
13 |
|
case 'Single': |
62
|
13 |
|
if (isset($child->children($this->arrayProcessing['mapping']['cbc'], true)->$strElementChild)) { |
63
|
13 |
|
$arrayOut[$strElementChild] = $this->getElementSingle($child |
64
|
13 |
|
->children($this->arrayProcessing['mapping']['cbc'], true)->$strElementChild); |
65
|
|
|
} |
66
|
13 |
|
break; |
67
|
13 |
|
case 'Multiple': |
68
|
13 |
|
if (isset($child->children($this->arrayProcessing['mapping']['cac'], true)->$strElementChild)) { |
69
|
13 |
|
$arrayOut[$strElementChild] = $this->getTaxCategory($child |
70
|
13 |
|
->children($this->arrayProcessing['mapping']['cac'], true) |
71
|
13 |
|
->$strElementChild, $strElementChild); |
72
|
|
|
} |
73
|
13 |
|
break; |
74
|
|
|
} |
75
|
|
|
} |
76
|
13 |
|
return $arrayOut; |
77
|
|
|
} |
78
|
|
|
|
79
|
13 |
|
private function getTaxTotal(\SimpleXMLElement $child): array |
80
|
|
|
{ |
81
|
13 |
|
$arrayOut = []; |
82
|
13 |
|
foreach ($this->arrayProcessing['TaxTotal'] as $strElement => $strType) { |
83
|
|
|
switch($strType) { |
84
|
13 |
|
case 'Single': |
85
|
13 |
|
if (isset($child->children($this->arrayProcessing['mapping']['cbc'], true)->$strElement)) { |
86
|
13 |
|
$arrayOut[$strElement] = $this->getElementSingle($child->children($this |
87
|
13 |
|
->arrayProcessing['mapping']['cbc'], true)->$strElement); |
88
|
|
|
} |
89
|
13 |
|
break; |
90
|
13 |
|
case 'Multiple': |
91
|
13 |
|
$intLineNo = 0; |
92
|
13 |
|
foreach ($child->children($this->arrayProcessing['mapping']['cac'], true)->$strElement as $child3) { |
93
|
13 |
|
$intLineNo++; |
94
|
13 |
|
$intLineStr = $this->getLineStringFromNumber($intLineNo); |
95
|
13 |
|
$arrayOut[$strElement][$intLineStr] = $this->getTaxSubTotal($child3); |
96
|
|
|
} |
97
|
13 |
|
break; |
98
|
|
|
} |
99
|
|
|
} |
100
|
13 |
|
return $arrayOut; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|