1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NFePHP\eFinanc\Factories; |
4
|
|
|
|
5
|
|
|
use NFePHP\eFinanc\Common\Factory; |
6
|
|
|
use NFePHP\eFinanc\Common\FactoryInterface; |
7
|
|
|
use NFePHP\eFinanc\Common\FactoryId; |
8
|
|
|
use NFePHP\Common\Certificate; |
9
|
|
|
use stdClass; |
10
|
|
|
|
11
|
|
|
class EvtCadDeclarante extends Factory implements FactoryInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Constructor |
15
|
|
|
* @param string $config |
16
|
|
|
* @param stdClass $std |
17
|
|
|
* @param Certificate $certificate |
18
|
|
|
* @param string $data |
19
|
|
|
*/ |
20
|
|
|
public function __construct( |
21
|
|
|
$config, |
22
|
|
|
stdClass $std, |
23
|
|
|
Certificate $certificate = null, |
24
|
|
|
$data = '' |
25
|
|
|
) { |
26
|
|
|
$params = new \stdClass(); |
27
|
|
|
$params->evtName = 'evtCadDeclarante'; |
28
|
|
|
$params->evtTag = 'evtCadDeclarante'; |
29
|
|
|
$params->evtAlias = 'F-2000'; |
30
|
|
|
parent::__construct($config, $std, $params, $certificate, $data); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function toNode() |
34
|
|
|
{ |
35
|
|
|
$ideDeclarante = $this->node->getElementsByTagName('ideDeclarante')->item(0); |
36
|
|
|
//o idEvento pode variar de evento para evento |
37
|
|
|
//então cada factory individualmente terá de construir o seu |
38
|
|
|
$ideEvento = $this->dom->createElement("ideEvento"); |
39
|
|
|
$this->dom->addChild( |
40
|
|
|
$ideEvento, |
41
|
|
|
"indRetificacao", |
42
|
|
|
$this->std->indretificacao, |
43
|
|
|
true |
44
|
|
|
); |
45
|
|
|
$this->dom->addChild( |
46
|
|
|
$ideEvento, |
47
|
|
|
"nrRecibo", |
48
|
|
|
isset($this->std->nrrecibo) ? $this->std->nrrecibo : null, |
49
|
|
|
false |
50
|
|
|
); |
51
|
|
|
$this->dom->addChild( |
52
|
|
|
$ideEvento, |
53
|
|
|
"tpAmb", |
54
|
|
|
(string) $this->tpAmb, |
55
|
|
|
true |
56
|
|
|
); |
57
|
|
|
$this->dom->addChild( |
58
|
|
|
$ideEvento, |
59
|
|
|
"aplicEmi", |
60
|
|
|
'1', |
61
|
|
|
true |
62
|
|
|
); |
63
|
|
|
$this->dom->addChild( |
64
|
|
|
$ideEvento, |
65
|
|
|
"verAplic", |
66
|
|
|
$this->verAplic, |
67
|
|
|
true |
68
|
|
|
); |
69
|
|
|
$this->node->insertBefore($ideEvento, $ideDeclarante); |
70
|
|
|
|
71
|
|
|
$infoCadastro = $this->dom->createElement("infoCadastro"); |
72
|
|
|
$info = $this->std->infocadastro; |
73
|
|
|
$this->dom->addChild( |
74
|
|
|
$infoCadastro, |
75
|
|
|
"GIIN", |
76
|
|
|
isset($info->giin) ? $info->giin : null, |
77
|
|
|
false |
78
|
|
|
); |
79
|
|
|
$this->dom->addChild( |
80
|
|
|
$infoCadastro, |
81
|
|
|
"CategoriaDeclarante", |
82
|
|
|
isset($info->categoriadeclarante) ? $info->categoriadeclarante : null, |
83
|
|
|
false |
84
|
|
|
); |
85
|
|
View Code Duplication |
if (!empty($info->nif)) { |
|
|
|
|
86
|
|
|
foreach ($info->nif as $n) { |
87
|
|
|
$NIF = $this->dom->createElement("NIF"); |
88
|
|
|
$this->dom->addChild( |
89
|
|
|
$NIF, |
90
|
|
|
"NumeroNIF", |
91
|
|
|
$n->numeronif, |
92
|
|
|
true |
93
|
|
|
); |
94
|
|
|
$this->dom->addChild( |
95
|
|
|
$NIF, |
96
|
|
|
"PaisEmissao", |
97
|
|
|
$n->paisemissao, |
98
|
|
|
true |
99
|
|
|
); |
100
|
|
|
$this->dom->addChild( |
101
|
|
|
$NIF, |
102
|
|
|
"tpNIF", |
103
|
|
|
isset($n->tpnif) ? $n->tpnif : null, |
104
|
|
|
false |
105
|
|
|
); |
106
|
|
|
$infoCadastro->appendChild($NIF); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
$this->dom->addChild( |
110
|
|
|
$infoCadastro, |
111
|
|
|
"nome", |
112
|
|
|
$info->nome, |
113
|
|
|
true |
114
|
|
|
); |
115
|
|
|
$this->dom->addChild( |
116
|
|
|
$infoCadastro, |
117
|
|
|
"tpNome", |
118
|
|
|
isset($info->tpnome) ? $info->tpnome : null, |
119
|
|
|
false |
120
|
|
|
); |
121
|
|
|
$this->dom->addChild( |
122
|
|
|
$infoCadastro, |
123
|
|
|
"enderecoLivre", |
124
|
|
|
$info->enderecolivre, |
125
|
|
|
true |
126
|
|
|
); |
127
|
|
|
$this->dom->addChild( |
128
|
|
|
$infoCadastro, |
129
|
|
|
"tpEndereco", |
130
|
|
|
isset($info->tpendereco) ? $info->tpendereco : null, |
131
|
|
|
false |
132
|
|
|
); |
133
|
|
|
$this->dom->addChild( |
134
|
|
|
$infoCadastro, |
135
|
|
|
"municipio", |
136
|
|
|
$info->municipio, |
137
|
|
|
true |
138
|
|
|
); |
139
|
|
|
$this->dom->addChild( |
140
|
|
|
$infoCadastro, |
141
|
|
|
"UF", |
142
|
|
|
$info->uf, |
143
|
|
|
true |
144
|
|
|
); |
145
|
|
|
$this->dom->addChild( |
146
|
|
|
$infoCadastro, |
147
|
|
|
"CEP", |
148
|
|
|
$info->cep, |
149
|
|
|
true |
150
|
|
|
); |
151
|
|
|
$this->dom->addChild( |
152
|
|
|
$infoCadastro, |
153
|
|
|
"Pais", |
154
|
|
|
$info->pais, |
155
|
|
|
true |
156
|
|
|
); |
157
|
|
|
foreach ($info->paisresid as $p) { |
158
|
|
|
$paisResid = $this->dom->createElement("paisResid"); |
159
|
|
|
$this->dom->addChild( |
160
|
|
|
$paisResid, |
161
|
|
|
"Pais", |
162
|
|
|
$p->pais, |
163
|
|
|
true |
164
|
|
|
); |
165
|
|
|
$infoCadastro->appendChild($paisResid); |
166
|
|
|
} |
167
|
|
|
if (!empty($info->enderecooutros)) { |
168
|
|
|
foreach ($info->enderecooutros as $out) { |
169
|
|
|
$EnderecoOutros = $this->dom->createElement("EnderecoOutros"); |
170
|
|
|
$this->dom->addChild( |
171
|
|
|
$EnderecoOutros, |
172
|
|
|
"tpEndereco", |
173
|
|
|
isset($out->tpendereco) ? $out->tpendereco : null, |
174
|
|
|
false |
175
|
|
|
); |
176
|
|
|
$this->dom->addChild( |
177
|
|
|
$EnderecoOutros, |
178
|
|
|
"EnderecoLivre", |
179
|
|
|
isset($out->enderecolivre) ? $out->enderecolivre : null, |
180
|
|
|
false |
181
|
|
|
); |
182
|
|
View Code Duplication |
if (!empty($out->enderecoestrutura) && empty($out->enderecolivre)) { |
|
|
|
|
183
|
|
|
$ee = $out->enderecoestrutura; |
184
|
|
|
$EnderecoEstrutura = $this->dom->createElement("EnderecoEstrutura"); |
185
|
|
|
$this->dom->addChild( |
186
|
|
|
$EnderecoEstrutura, |
187
|
|
|
"EnderecoLivre", |
188
|
|
|
isset($ee->enderecolivre) ? $ee->enderecolivre : null, |
189
|
|
|
false |
190
|
|
|
); |
191
|
|
|
if (!empty($ee->endereco)) { |
192
|
|
|
$end = $ee->endereco; |
193
|
|
|
$Endereco = $this->dom->createElement("Endereco"); |
194
|
|
|
$this->dom->addChild( |
195
|
|
|
$Endereco, |
196
|
|
|
"Logradouro", |
197
|
|
|
isset($end->logradouro) ? $end->logradouro : null, |
198
|
|
|
false |
199
|
|
|
); |
200
|
|
|
$this->dom->addChild( |
201
|
|
|
$Endereco, |
202
|
|
|
"Numero", |
203
|
|
|
isset($end->numero) ? $end->numero : null, |
204
|
|
|
false |
205
|
|
|
); |
206
|
|
|
$this->dom->addChild( |
207
|
|
|
$Endereco, |
208
|
|
|
"Complemento", |
209
|
|
|
isset($end->complemento) ? $end->complemento : null, |
210
|
|
|
false |
211
|
|
|
); |
212
|
|
|
$this->dom->addChild( |
213
|
|
|
$Endereco, |
214
|
|
|
"Andar", |
215
|
|
|
isset($end->andar) ? $end->andar : null, |
216
|
|
|
false |
217
|
|
|
); |
218
|
|
|
$this->dom->addChild( |
219
|
|
|
$Endereco, |
220
|
|
|
"Bairro", |
221
|
|
|
isset($end->bairro) ? $end->bairro : null, |
222
|
|
|
false |
223
|
|
|
); |
224
|
|
|
$this->dom->addChild( |
225
|
|
|
$Endereco, |
226
|
|
|
"CaixaPostal", |
227
|
|
|
isset($end->caixapostal) ? $end->caixapostal : null, |
228
|
|
|
false |
229
|
|
|
); |
230
|
|
|
$EnderecoEstrutura->appendChild($Endereco); |
231
|
|
|
} |
232
|
|
|
$this->dom->addChild( |
233
|
|
|
$EnderecoEstrutura, |
234
|
|
|
"CEP", |
235
|
|
|
$ee->cep, |
236
|
|
|
true |
237
|
|
|
); |
238
|
|
|
$this->dom->addChild( |
239
|
|
|
$EnderecoEstrutura, |
240
|
|
|
"Municipio", |
241
|
|
|
$ee->municipio, |
242
|
|
|
true |
243
|
|
|
); |
244
|
|
|
$this->dom->addChild( |
245
|
|
|
$EnderecoEstrutura, |
246
|
|
|
"UF", |
247
|
|
|
$ee->uf, |
248
|
|
|
true |
249
|
|
|
); |
250
|
|
|
$EnderecoOutros->appendChild($EnderecoEstrutura); |
251
|
|
|
} |
252
|
|
|
$this->dom->addChild( |
253
|
|
|
$EnderecoOutros, |
254
|
|
|
"Pais", |
255
|
|
|
$out->pais, |
256
|
|
|
true |
257
|
|
|
); |
258
|
|
|
$infoCadastro->appendChild($EnderecoOutros); |
259
|
|
|
} |
260
|
|
|
} |
261
|
|
|
$this->node->appendChild($infoCadastro); |
262
|
|
|
//finalização do xml |
263
|
|
|
$this->eFinanceira->appendChild($this->node); |
264
|
|
|
//$this->xml = $this->dom->saveXML($this->eFinanceira); |
265
|
|
|
$this->sign($this->evtTag); |
266
|
|
|
} |
267
|
|
|
} |
268
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.