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

TraitCompanies::getAccountingCustomerParty()   A

Complexity

Conditions 6
Paths 32

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 19
c 0
b 0
f 0
nc 32
nop 1
dl 0
loc 28
rs 9.0111
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 TraitCompanies
32
{
33
34
    private function getAccountingCustomerParty($child2): array {
35
        $arrayMainOutput = [
36
            'PostalAddress'    => $this->getPostalAddress($child2->children('cac', true)->PostalAddress),
37
            'PartyLegalEntity' => $this->getPartyLegalEntity($child2->children('cac', true)->PartyLegalEntity),
38
        ];
39
        // optional components =========================================================================================
40
        if (isset($child2->children('cac', true)->PartyName)) {
41
            $arrayMainOutput['PartyName'] = $this->getPartyName($child2->children('cac', true)->PartyName);
42
        }
43
        if (isset($child2->children('cac', true)->PartyTaxScheme)) {
44
            $arrayMainOutput['PartyTaxScheme'] = $this->getPartyTaxScheme($child2
45
                    ->children('cac', true)->PartyTaxScheme);
46
        }
47
        if (isset($child2->children('cac', true)->PartyIdentification)) {
48
            $arrayMainOutput['PartyIdentification'] = $this->getPartyIdentification($child2
49
                    ->children('cac', true)->PartyIdentification);
50
        }
51
        if (isset($child2->children('cbc', true)->EndpointID)) {
52
            $arrayMainOutput['EndpointID'] = [
53
                'schemeID' => $child2->children('cbc', true)->EndpointID->attributes()->schemeID->__toString(),
54
                'value'    => $child2->children('cbc', true)->EndpointID->__toString(),
55
            ];
56
        }
57
        $arrayContact = $this->getContact($child2->children('cac', true)->Contact);
58
        if ($arrayContact != []) {
59
            $arrayMainOutput['Contact'] = $arrayContact;
60
        }
61
        return ['Party' => $arrayMainOutput];
62
    }
63
64
    private function getAccountingSupplierParty($child2): array {
65
        $arrayMainOutput = [
66
            'PostalAddress'    => $this->getPostalAddress($child2->children('cac', true)->PostalAddress),
67
            'PartyTaxScheme'   => $this->getPartyTaxScheme($child2->children('cac', true)->PartyTaxScheme),
68
            'PartyLegalEntity' => $this->getPartyLegalEntity($child2->children('cac', true)->PartyLegalEntity),
69
        ];
70
        if (isset($child2->children('cac', true)->PartyName)) {
71
            $arrayMainOutput['PartyName'] = $this->getPartyName($child2->children('cac', true)->PartyName);
72
        }
73
        // optional components =========================================================================================
74
        $arrayContact = $this->getContact($child2->children('cac', true)->Contact);
75
        if ($arrayContact != []) {
76
            $arrayMainOutput['Contact'] = $arrayContact;
77
        }
78
        if (isset($child2->children('cbc', true)->EndpointID)) {
79
            $arrayMainOutput['EndpointID'] = [
80
                'schemeID' => $child2->children('cbc', true)->EndpointID->attributes()->schemeID->__toString(),
81
                'value'    => $child2->children('cbc', true)->EndpointID->__toString(),
82
            ];
83
        }
84
        return ['Party' => $arrayMainOutput];
85
    }
86
87
    private function getContact($child3): array {
88
        // optional components =========================================================================================
89
        $arrayOutput = [];
90
        if (isset($child3->children('cbc', true)->Name)) {
91
            $arrayOutput['Name'] = $child3->children('cbc', true)->Name->__toString();
92
        }
93
        if (isset($child3->children('cbc', true)->Telephone)) {
94
            $arrayOutput['Telephone'] = $child3->children('cbc', true)->Telephone->__toString();
95
        }
96
        if (isset($child3->children('cbc', true)->ElectronicMail)) {
97
            $arrayOutput['ElectronicMail'] = $child3->children('cbc', true)->ElectronicMail->__toString();
98
        }
99
        return $arrayOutput;
100
    }
101
102
    private function getPartyIdentification($child3): array {
103
        $arrayOutput = [
104
            'ID' => $child3->children('cbc', true)->ID->__toString(),
105
        ];
106
        return $arrayOutput;
107
    }
108
109
    private function getPartyLegalEntity($child3): array {
110
        $arrayOutput = [
111
            'RegistrationName' => $child3->children('cbc', true)->RegistrationName->__toString(),
112
        ];
113
        // optional components =========================================================================================
114
        if (isset($child3->children('cbc', true)->CompanyID)) {
115
            $arrayOutput['CompanyID'] = $child3->children('cbc', true)->CompanyID->__toString();
116
        }
117
        if (isset($child3->children('cbc', true)->CompanyLegalForm)) {
118
            $arrayOutput['CompanyLegalForm'] = $child3->children('cbc', true)->CompanyLegalForm->__toString();
119
        }
120
        return $arrayOutput;
121
    }
122
123
    private function getPartyName($child3): array {
124
        $arrayOutput         = [];
125
        $arrayOutput['Name'] = $child3->children('cbc', true)->Name->__toString();
126
        return $arrayOutput;
127
    }
128
129
    private function getPartyTaxScheme($child3): array {
130
        return [
131
            'CompanyID' => $child3->children('cbc', true)->CompanyID->__toString(),
132
            'TaxScheme' => [
133
                'ID' => $child3->children('cac', true)->TaxScheme->children('cbc', true)->ID->__toString(),
134
            ]
135
        ];
136
    }
137
138
    private function getPaymentMeans($child2): array {
139
        $arrayOutput                                = [
140
            'PaymentMeansCode' => $child2->children('cbc', true)->PaymentMeansCode->__toString(),
141
        ];
142
        $childPayeeFinancialAccount                 = $child2->children('cac', true)->PayeeFinancialAccount;
143
        $arrayOutput['PayeeFinancialAccount']['ID'] = $childPayeeFinancialAccount
144
                ->children('cbc', true)->ID->__toString();
145
        // optional components =========================================================================================
146
        if (isset($child2->children('cbc', true)->PaymentID)) {
147
            $arrayOutput['PaymentID'] = $child2->children('cbc', true)->PaymentID->__toString();
148
        }
149
        if (isset($childPayeeFinancialAccount->children('cbc', true)->Name)) {
150
            $arrayOutput['PayeeFinancialAccount']['Name'] = $childPayeeFinancialAccount
151
                    ->children('cbc', true)->Name->__toString();
152
        }
153
        if (isset($childPayeeFinancialAccount->children('cac', true)->FinancialInstitutionBranch)) {
154
            $arrayOutput['PayeeFinancialAccount']['FinancialInstitutionBranch']['ID'] = $childPayeeFinancialAccount
155
                    ->children('cac', true)->FinancialInstitutionBranch->children('cbc', true)->ID->__toString();
156
        }
157
        return $arrayOutput;
158
    }
159
160
    private function getPostalAddress($child3): array {
161
        $arrayOutput = [
162
            'CityName'         => $child3->children('cbc', true)->CityName->__toString(),
163
            'Country'          => [
164
                'IdentificationCode' => $child3->children('cac', true)->Country
165
                    ->children('cbc', true)->IdentificationCode->__toString(),
166
            ],
167
            'CountrySubentity' => $child3->children('cbc', true)->CountrySubentity->__toString(),
168
            'StreetName'       => $child3->children('cbc', true)->StreetName->__toString(),
169
        ];
170
        // optional component ==========================================================================================
171
        if (isset($child3->children('cbc', true)->PostalZone)) {
172
            $arrayOutput['PostalZone'] = $child3->children('cbc', true)->PostalZone->__toString();
173
        }
174
        return $arrayOutput;
175
    }
176
}
177