Passed
Push — main ( a8d720...b18f8c )
by Daniel
02:10
created

TraitTax   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
c 0
b 0
f 0
dl 0
loc 39
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTaxSubTotal() 0 7 1
A getTaxTotal() 0 10 3
A getTaxCategory() 0 13 2
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 TraitTax
32
{
33
34
    use TraitBasic;
35
36
    private function getTaxCategory($child3): array {
37
        $arrayOutput = [
38
            'ID'        => $child3->children('cbc', true)->ID->__toString(),
39
            'Percent'   => (float) $child3->children('cbc', true)->Percent->__toString(),
40
            'TaxScheme' => [
41
                'ID' => $child3->children('cac', true)->TaxScheme->children('cbc', true)->ID->__toString(),
42
            ],
43
        ];
44
        // optional components =========================================================================================
45
        if (isset($child3->children('cbc', true)->TaxExemptionReason)) {
46
            $arrayOutput['TaxExemptionReason'] = $child3->children('cbc', true)->TaxExemptionReason->__toString();
47
        }
48
        return $arrayOutput;
49
    }
50
51
    private function getTaxSubTotal($child3): array {
52
        $arrayOutput = [
53
            'TaxAmount'     => $this->getTagWithCurrencyParameter($child3->children('cbc', true)->TaxAmount),
54
            'TaxableAmount' => $this->getTagWithCurrencyParameter($child3->children('cbc', true)->TaxableAmount),
55
            'TaxCategory'   => $this->getTaxCategory($child3->children('cac', true)->TaxCategory),
56
        ];
57
        return $arrayOutput;
58
    }
59
60
    private function getTaxTotal($child2): array {
61
        $arrayOutput = [
62
            'TaxAmount' => $this->getTagWithCurrencyParameter($child2->children('cbc', true)->TaxAmount)
63
        ];
64
        $intLineNo   = 0;
65
        foreach ($child2->children('cac', true)->TaxSubtotal as $child3) {
66
            $intLineNo++;
67
            $arrayOutput['TaxSubtotal'][($intLineNo < 10 ? '0' : '') . $intLineNo] = $this->getTaxSubTotal($child3);
68
        }
69
        return $arrayOutput;
70
    }
71
}
72