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 TraitLines |
17
|
|
|
{ |
18
|
|
|
use TraitBasic; |
19
|
|
|
use TraitTax; |
20
|
|
|
|
21
|
13 |
|
private function getDocumentLines(\SimpleXMLElement $arrayDataIn, string $strTag): array |
22
|
|
|
{ |
23
|
13 |
|
$arrayLines = []; |
24
|
13 |
|
$intLineNo = 0; |
25
|
13 |
|
foreach ($arrayDataIn->children($this->arrayProcessing['mapping']['cac'], true) as $strNodeName => $child) { |
26
|
13 |
|
if ($strNodeName === ($strTag . 'Line')) { |
27
|
13 |
|
$intLineNo++; |
28
|
13 |
|
$intLineStr = $this->getLineStringFromNumber($intLineNo); |
29
|
13 |
|
if (!is_null($child)) { |
30
|
13 |
|
$arrayLines[$intLineStr] = $this->getLine($child); |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
} |
34
|
13 |
|
return $arrayLines; |
35
|
|
|
} |
36
|
|
|
|
37
|
13 |
|
private function getLine(\SimpleXMLElement $child): array |
38
|
|
|
{ |
39
|
13 |
|
$arrayOutput = []; |
40
|
13 |
|
foreach ($this->arrayProcessing['Lines@Read'] as $strElement => $strType) { |
41
|
|
|
switch($strType) { |
42
|
13 |
|
case 'Item': |
43
|
13 |
|
$arrayOutput[$strElement] = $this->getLineItem($child->children($this->arrayProcessing['mapping']['cac'], true)->$strElement); |
44
|
13 |
|
break; |
45
|
13 |
|
case 'Multiple': |
46
|
13 |
|
if (isset($child->children($this->arrayProcessing['mapping']['cac'], true)->$strElement)) { |
47
|
3 |
|
$arrayOutput[$strElement] = $this->getMultipleElementsByKey($child |
48
|
3 |
|
->children($this->arrayProcessing['mapping']['cac'], true)->$strElement); |
49
|
|
|
} |
50
|
13 |
|
break; |
51
|
13 |
|
case 'Single': |
52
|
13 |
|
if (isset($child->children($this->arrayProcessing['mapping']['cbc'], true)->$strElement)) { |
53
|
13 |
|
$arrayOutput[$strElement] = $this->getElementSingle($child->children($this->arrayProcessing['mapping']['cbc'], true)->$strElement); |
54
|
13 |
|
} elseif (isset($child->children($this->arrayProcessing['mapping']['cac'], true)->$strElement)) { |
55
|
13 |
|
$arrayOutput[$strElement] = $this->getElements($child->children($this->arrayProcessing['mapping']['cac'], true)->$strElement); |
56
|
|
|
} |
57
|
13 |
|
break; |
58
|
|
|
} |
59
|
|
|
} |
60
|
13 |
|
return $arrayOutput; |
61
|
|
|
} |
62
|
|
|
|
63
|
13 |
|
private function getLineItem(\SimpleXMLElement $child3): array |
64
|
|
|
{ |
65
|
13 |
|
$arrayOutput = []; |
66
|
13 |
|
foreach ($this->arrayProcessing['Lines_Item@Read'] as $key => $value) { |
67
|
|
|
switch($value) { |
68
|
13 |
|
case 'Multiple': |
69
|
13 |
|
if (isset($child3->children($this->arrayProcessing['mapping']['cac'], true)->$key)) { |
70
|
7 |
|
$arrayOutput[$key] = $this->getMultipleElementsByKey($child3->children($this->arrayProcessing['mapping']['cac'], true)->$key); |
71
|
|
|
} |
72
|
13 |
|
break; |
73
|
13 |
|
case 'Single': |
74
|
13 |
|
if (isset($child3->children($this->arrayProcessing['mapping']['cbc'], true)->$key)) { |
75
|
13 |
|
$arrayOutput[$key] = $child3->children($this->arrayProcessing['mapping']['cbc'], true)->$key->__toString(); |
76
|
13 |
|
} elseif (isset($child3->children($this->arrayProcessing['mapping']['cac'], true)->$key)) { |
77
|
7 |
|
$arrayOutput[$key] = $this->getElements($child3->children($this->arrayProcessing['mapping']['cac'], true)->$key); |
78
|
|
|
} |
79
|
13 |
|
break; |
80
|
13 |
|
case 'TaxCategory': |
81
|
13 |
|
if (isset($child3->children($this->arrayProcessing['mapping']['cac'], true)->$key)) { |
82
|
13 |
|
$arrayOutput[$key] = $this->getTaxCategory($child3->children($this->arrayProcessing['mapping']['cac'], true)->$key, $key); |
83
|
|
|
} |
84
|
13 |
|
break; |
85
|
|
|
} |
86
|
|
|
} |
87
|
13 |
|
return $arrayOutput; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|