Completed
Pull Request — master (#125)
by
unknown
02:38
created

EvtCdBenPrRP   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 464
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 3
dl 0
loc 464
ccs 0
cts 353
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
D toNode() 0 421 16
1
<?php
2
3
namespace NFePHP\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtCdBenPrRP Event S-2400 constructor
7
 *
8
 * @category  NFePHP
9
 * @package   NFePHPSocial
10
 * @copyright NFePHP Copyright (c) 2017
11
 * @license   http://www.gnu.org/licenses/lgpl.txt LGPLv3+
12
 * @license   https://opensource.org/licenses/MIT MIT
13
 * @license   http://www.gnu.org/licenses/gpl.txt GPLv3+
14
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
15
 * @link      http://github.com/nfephp-org/sped-esocial for the canonical source repository
16
 */
17
18
use NFePHP\Common\Certificate;
19
use NFePHP\eSocial\Common\Factory;
20
use NFePHP\eSocial\Common\FactoryId;
21
use NFePHP\eSocial\Common\FactoryInterface;
22
use stdClass;
23
24
class EvtCdBenPrRP extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
31
    /**
32
     * @var string
33
     */
34
    protected $evtName = 'evtCdBenPrRP';
35
36
    /**
37
     * @var string
38
     */
39
    protected $evtAlias = 'S-2400';
40
41
    /**
42
     * Parameters patterns
43
     *
44
     * @var array
45
     */
46
    protected $parameters = [];
47
48
    /**
49
     * Constructor
50
     *
51
     * @param string $config
52
     * @param stdClass $std
53
     * @param Certificate $certificate
54
     */
55
    public function __construct(
56
        $config,
57
        stdClass $std,
58
        Certificate $certificate
59
    ) {
60
        parent::__construct($config, $std, $certificate);
61
    }
62
63
    /**
64
     * Node constructor
65
     */
66
    protected function toNode()
67
    {
68
        $evtid = FactoryId::build(
69
            $this->tpInsc,
70
            $this->nrInsc,
71
            $this->date,
72
            $this->sequencial
73
        );
74
75
        $evtCdBenPrRP = $this->dom->createElement("evtCdBenPrRP");
76
77
        $att = $this->dom->createAttribute('Id');
78
79
        $att->value = $evtid;
80
81
        $evtCdBenPrRP->appendChild($att);
82
83
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
84
85
        $ideEvento = $this->dom->createElement("ideEvento");
86
        $this->dom->addChild(
87
            $ideEvento,
88
            "indRetif",
89
            $this->std->indretif,
90
            true
91
        );
92
        $this->dom->addChild(
93
            $ideEvento,
94
            "tpAmb",
95
            $this->tpAmb,
96
            true
97
        );
98
        $this->dom->addChild(
99
            $ideEvento,
100
            "procEmi",
101
            $this->procEmi,
102
            true
103
        );
104
        $this->dom->addChild(
105
            $ideEvento,
106
            "verProc",
107
            $this->verProc,
108
            true
109
        );
110
111
        $this->node->insertBefore($ideEvento, $ideEmpregador);
112
113
        $ideBenef = $this->dom->createElement("ideBenef");
114
115
        $this->dom->addChild(
116
            $ideBenef,
117
            "cpfBenef",
118
            $this->std->idebenef->cpfbenef,
119
            true
120
        );
121
122
        $this->dom->addChild(
123
            $ideBenef,
124
            "nmBenefic",
125
            $this->std->idebenef->nmbenefic,
126
            true
127
        );
128
129
        $this->node->appendChild($ideBenef);
130
131
        $dadosBenef = $this->dom->createElement("dadosBenef");
132
133
        $this->dom->addChild(
134
            $dadosBenef,
135
            "cpfBenef",
136
            $this->std->idebenef->dadosbenef->cpfbenef,
137
            true
138
        );
139
140
        $this->dom->addChild(
141
            $dadosBenef,
142
            "nmBenefic",
143
            $this->std->idebenef->dadosbenef->nmbenefic,
144
            true
145
        );
146
147
        $dadosNasc = $this->dom->createElement("dadosNasc");
148
149
        $this->dom->addChild(
150
            $dadosNasc,
151
            "dtNascto",
152
            $this->std->idebenef->dadosbenef->dadosnasc->dtnascto,
153
            true
154
        );
155
156
        $this->dom->addChild(
157
            $dadosNasc,
158
            "codMunic",
159
            !empty($this->std->idebenef->dadosbenef->dadosnasc->codmunic) ?
160
                $this->std->idebenef->dadosbenef->dadosnasc->codmunic : null,
161
            false
162
        );
163
164
        $this->dom->addChild(
165
            $dadosNasc,
166
            "uf",
167
            !empty($this->std->idebenef->dadosbenef->dadosnasc->uf) ?
168
                $this->std->idebenef->dadosbenef->dadosnasc->uf : null,
169
            false
170
        );
171
172
        $this->dom->addChild(
173
            $dadosNasc,
174
            "paisNascto",
175
            $this->std->idebenef->dadosbenef->dadosnasc->paisnascto,
176
            true
177
        );
178
179
        $this->dom->addChild(
180
            $dadosNasc,
181
            "paisNac",
182
            $this->std->idebenef->dadosbenef->dadosnasc->paisnac,
183
            true
184
        );
185
186
        $this->dom->addChild(
187
            $dadosNasc,
188
            "nmMae",
189
            !empty($this->std->idebenef->dadosbenef->dadosnasc->nmmae) ?
190
                $this->std->idebenef->dadosbenef->dadosnasc->nmmae : null,
191
            false
192
        );
193
194
        $this->dom->addChild(
195
            $dadosNasc,
196
            "nmPai",
197
            !empty($this->std->idebenef->dadosbenef->dadosnasc->nmpai) ?
198
                $this->std->idebenef->dadosbenef->dadosnasc->nmpai : null,
199
            false
200
        );
201
202
        $dadosBenef->appendChild($dadosNasc);
203
204
        $endereco = $this->dom->createElement("endereco");
205
206
        if (isset($this->std->idebenef->dadosbenef->endereco->brasil)) {
207
            $brasil = $this->dom->createElement("brasil");
208
209
            $this->dom->addChild(
210
                $brasil,
211
                "tpLograd",
212
                $this->std->idebenef->dadosbenef->endereco->brasil->tplograd,
213
                true
214
            );
215
216
            $this->dom->addChild(
217
                $brasil,
218
                "dscLograd",
219
                $this->std->idebenef->dadosbenef->endereco->brasil->dsclograd,
220
                true
221
            );
222
223
            $this->dom->addChild(
224
                $brasil,
225
                "nrLograd",
226
                $this->std->idebenef->dadosbenef->endereco->brasil->nrlograd,
227
                true
228
            );
229
230
            $this->dom->addChild(
231
                $brasil,
232
                "complemento",
233
                !empty($this->std->idebenef->dadosbenef->endereco->brasil->complemento) ?
234
                    $this->std->idebenef->dadosbenef->endereco->brasil->complemento : null,
235
                false
236
            );
237
238
            $this->dom->addChild(
239
                $brasil,
240
                "bairro",
241
                !empty($this->std->idebenef->dadosbenef->endereco->brasil->bairro) ?
242
                    $this->std->idebenef->dadosbenef->endereco->brasil->bairro : null,
243
                false
244
            );
245
246
            $this->dom->addChild(
247
                $brasil,
248
                "cep",
249
                $this->std->idebenef->dadosbenef->endereco->brasil->cep,
250
                true
251
            );
252
253
            $this->dom->addChild(
254
                $brasil,
255
                "codMunic",
256
                $this->std->idebenef->dadosbenef->endereco->brasil->codmunic,
257
                true
258
            );
259
260
            $this->dom->addChild(
261
                $brasil,
262
                "uf",
263
                $this->std->idebenef->dadosbenef->endereco->brasil->uf,
264
                true
265
            );
266
267
            $endereco->appendChild($brasil);
268
        }
269
270
        if (isset($this->std->idebenef->dadosbenef->endereco->exterior)) {
271
            $exterior = $this->dom->createElement("exterior");
272
273
            $this->dom->addChild(
274
                $exterior,
275
                "paisResid",
276
                $this->std->idebenef->dadosbenef->endereco->exterior->paisresid,
277
                true
278
            );
279
280
            $this->dom->addChild(
281
                $exterior,
282
                "dscLograd",
283
                $this->std->idebenef->dadosbenef->endereco->exterior->dsclograd,
284
                true
285
            );
286
287
            $this->dom->addChild(
288
                $exterior,
289
                "nrLograd",
290
                $this->std->idebenef->dadosbenef->endereco->exterior->nrlograd,
291
                true
292
            );
293
294
            $this->dom->addChild(
295
                $exterior,
296
                "complemento",
297
                !empty($this->std->idebenef->dadosbenef->endereco->exterior->complemento) ?
298
                    $this->std->idebenef->dadosbenef->endereco->exterior->complemento : null,
299
                false
300
            );
301
302
            $this->dom->addChild(
303
                $exterior,
304
                "bairro",
305
                !empty($this->std->idebenef->dadosbenef->endereco->exterior->bairro) ?
306
                    $this->std->idebenef->dadosbenef->endereco->exterior->bairro : null,
307
                false
308
            );
309
310
            $this->dom->addChild(
311
                $exterior,
312
                "nmCid",
313
                $this->std->idebenef->dadosbenef->endereco->exterior->nmcid,
314
                true
315
            );
316
317
            $this->dom->addChild(
318
                $exterior,
319
                "codPostal",
320
                $this->std->idebenef->dadosbenef->endereco->exterior->codpostal,
321
                true
322
            );
323
324
            $endereco->appendChild($exterior);
325
        }
326
327
        $dadosBenef->appendChild($endereco);
328
329
        $ideBenef->appendChild($dadosBenef);
330
331
        $infoBeneficio = $this->dom->createElement("infoBeneficio");
332
333
        $this->dom->addChild(
334
            $infoBeneficio,
335
            "tpPlanRP",
336
            $this->std->infobeneficio->tpplanrp,
337
            true
338
        );
339
340
        $this->node->appendChild($infoBeneficio);
341
342
        if (isset($this->std->infobeneficio->inibeneficio)) {
343
            $iniBeneficio = $this->dom->createElement("iniBeneficio");
344
345
            $this->dom->addChild(
346
                $iniBeneficio,
347
                "tpBenef",
348
                $this->std->infobeneficio->inibeneficio->tpbenef,
349
                true
350
            );
351
352
            $this->dom->addChild(
353
                $iniBeneficio,
354
                "nrBenefic",
355
                $this->std->infobeneficio->inibeneficio->nrbenefic,
356
                true
357
            );
358
359
            $this->dom->addChild(
360
                $iniBeneficio,
361
                "dtIniBenef",
362
                $this->std->infobeneficio->inibeneficio->dtinibenef,
363
                true
364
            );
365
366
            $this->dom->addChild(
367
                $iniBeneficio,
368
                "vrBenef",
369
                $this->std->infobeneficio->inibeneficio->vrbenef,
370
                true
371
            );
372
373
            if (isset($this->std->infobeneficio->inibeneficio->infopenmorte)) {
374
                $infoPenMorte = $this->dom->createElement("infoPenMorte");
375
376
                $this->dom->addChild(
377
                    $infoPenMorte,
378
                    "idQuota",
379
                    $this->std->infobeneficio->inibeneficio->infopenmorte->idquota,
380
                    true
381
                );
382
383
                $this->dom->addChild(
384
                    $infoPenMorte,
385
                    "cpfInst",
386
                    $this->std->infobeneficio->inibeneficio->infopenmorte->cpfinst,
387
                    true
388
                );
389
390
                $iniBeneficio->appendChild($infoPenMorte);
391
            }
392
393
            $infoBeneficio->appendChild($iniBeneficio);
394
        }
395
396
        if (isset($this->std->infobeneficio->altbeneficio)) {
397
            $altBeneficio = $this->dom->createElement("altBeneficio");
398
399
            $this->dom->addChild(
400
                $altBeneficio,
401
                "tpBenef",
402
                $this->std->infobeneficio->altbeneficio->tpbenef,
403
                true
404
            );
405
406
            $this->dom->addChild(
407
                $altBeneficio,
408
                "nrBenefic",
409
                $this->std->infobeneficio->altbeneficio->nrbenefic,
410
                true
411
            );
412
413
            $this->dom->addChild(
414
                $altBeneficio,
415
                "dtIniBenef",
416
                $this->std->infobeneficio->altbeneficio->dtinibenef,
417
                true
418
            );
419
420
            $this->dom->addChild(
421
                $altBeneficio,
422
                "vrBenef",
423
                $this->std->infobeneficio->altbeneficio->vrbenef,
424
                true
425
            );
426
427
            if (isset($this->std->infobeneficio->altbeneficio->infopenmorte)) {
428
                $infoPenMorte = $this->dom->createElement("infoPenMorte");
429
430
                $this->dom->addChild(
431
                    $infoPenMorte,
432
                    "idQuota",
433
                    $this->std->infobeneficio->altbeneficio->infopenmorte->idquota,
434
                    true
435
                );
436
437
                $this->dom->addChild(
438
                    $infoPenMorte,
439
                    "cpfInst",
440
                    $this->std->infobeneficio->altbeneficio->infopenmorte->cpfinst,
441
                    true
442
                );
443
444
                $altBeneficio->appendChild($infoPenMorte);
445
            }
446
447
            $infoBeneficio->appendChild($altBeneficio);
448
        }
449
450
        if (isset($this->std->infobeneficio->fimbeneficio)) {
451
            $fimBeneficio = $this->dom->createElement("fimBeneficio");
452
453
            $this->dom->addChild(
454
                $fimBeneficio,
455
                "tpBenef",
456
                $this->std->infobeneficio->fimbeneficio->tpbenef,
457
                true
458
            );
459
460
            $this->dom->addChild(
461
                $fimBeneficio,
462
                "nrBenefic",
463
                $this->std->infobeneficio->fimbeneficio->nrbenefic,
464
                true
465
            );
466
467
            $this->dom->addChild(
468
                $fimBeneficio,
469
                "dtFimBenef",
470
                $this->std->infobeneficio->fimbeneficio->dtfimbenef,
471
                true
472
            );
473
474
            $this->dom->addChild(
475
                $fimBeneficio,
476
                "mtvFim",
477
                $this->std->infobeneficio->fimbeneficio->mtvfim,
478
                true
479
            );
480
481
            $infoBeneficio->appendChild($fimBeneficio);
482
        }
483
484
        $this->eSocial->appendChild($this->node);
485
        $this->sign();
486
    }
487
}
488