Passed
Push — master ( 303ee9...d335b7 )
by
unknown
56s queued 11s
created

Make::taginfUnidCargaVazia()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 0
cts 25
cp 0
rs 9.456
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace NFePHP\MDFe;
4
5
/**
6
 * Classe a construção do xml do Manifesto Eletrônico de Documentos Fiscais (MDF-e)
7
 * NOTA: Esta classe foi construida conforme estabelecido no
8
 * Manual de Orientação do Contribuinte
9
 * Padrões Técnicos de Comunicação do Manifesto Eletrônico de Documentos Fiscais
10
 * versão 3.00a
11
 *
12
 * @category  Library
13
 * @package   nfephp-org/sped-mdfe
14
 * @name      Make.php
15
 * @copyright 2009-2019 NFePHP
16
 * @license   http://www.gnu.org/licenses/lesser.html LGPL v3
17
 * @link      http://github.com/nfephp-org/sped-mdfe for the canonical source repository
18
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
19
 */
20
21
use NFePHP\Common\Keys;
22
use NFePHP\Common\DOMImproved as Dom;
23
use NFePHP\Common\Strings;
24
use stdClass;
25
use RuntimeException;
26
use InvalidArgumentException;
27
use DOMElement;
28
use DateTime;
29
use Exception;
30
31
class Make
32
{
33
    /**
34
     * @var array
35
     */
36
    public $errors = [];
37
    /**
38
     * versao
39
     * numero da versão do xml da MDFe
40
     *
41
     * @var string
42
     */
43
    public $versao = '3.00';
44
    /**
45
     * mod
46
     * modelo da MDFe 58
47
     *
48
     * @var integer
49
     */
50
    public $mod = '58';
51
    /**
52
     * chave da MDFe
53
     *
54
     * @var string
55
     */
56
    public $chMDFe = '';
57
58
    //propriedades privadas utilizadas internamente pela classe
59
    /**
60
     * @type string|\DOMNode
61
     */
62
    private $MDFe = '';
63
    /**
64
     * @type string|\DOMNode
65
     */
66
    private $infMDFe = '';
67
    /**
68
     * @type string|\DOMNode
69
     */
70
    private $ide = '';
71
    /**
72
     * @type string|\DOMNode
73
     */
74
    private $emit = '';
75
    /**
76
     * @type string|\DOMNode
77
     */
78
    private $enderEmit = '';
79
    /**
80
     * @type string|\DOMNode
81
     */
82
    private $infModal = '';
83
    /**
84
     * @type string|\DOMNode
85
     */
86
    private $tot = '';
87
    /**
88
     * @type string|\DOMNode
89
     */
90
    private $seg = '';
91
    /**
92
     * @type string|\DOMNode
93
     */
94
    private $aLacres = [];
95
    /**
96
     * @type string|\DOMNode
97
     */
98
    private $autXML = [];
99
    /**
100
     * @type string|\DOMNode
101
     */
102
    private $infAdic = '';
103
    /**
104
     * @type string|\DOMNode
105
     */
106
    private $rodo = '';
107
    /**
108
     * @type string|\DOMNode
109
     */
110
    private $infDoc = '';
111
    /**
112
     * @type string|\DOMNode
113
     */
114
    private $infUnidTransp = '';
115
    /**
116
     * @type array|\DOMNode
117
     */
118
    private $aInfMunDescarga = [];
119
    /**
120
     * @type array|\DOMNode
121
     */
122
    private $aInfMunCarrega = [];
123
    /**
124
     * @type array|\DOMNode
125
     */
126
    private $aInfPercurso = [];
127
    /**
128
     * @type string|\DOMNode
129
     */
130
    private $veicTracao = '';
131
    /**
132
     * @type string|\DOMNode
133
     */
134
    private $aereo = '';
135
    /**
136
     * @type string|\DOMNode
137
     */
138
    private $trem = '';
139
    /**
140
     * @type string|\DOMNode
141
     */
142
    private $aquav = '';
143
    /**
144
     * @type array
145
     */
146
    private $infTermCarreg = [];
147
    /**
148
     * @type array
149
     */
150
    private $infTermDescarreg = [];
151
    /**
152
     * @type array
153
     */
154
    private $infEmbComb = [];
155
    /**
156
     * @type array
157
     */
158
    private $infUnidCargaVazia = [];
159
    /**
160
     * @type array
161
     */
162
    private $infUnidTranspVazia = [];
163
    /**
164
     * @var boolean
165
     */
166
    protected $replaceAccentedChars = false;
167
168
    /**
169
     * Função construtora cria um objeto DOMDocument
170
     * que será carregado com o documento fiscal
171
     */
172
    public function __construct()
173
    {
174
        $this->dom = new Dom('1.0', 'UTF-8');
0 ignored issues
show
Bug introduced by
The property dom does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
175
        $this->dom->preserveWhiteSpace = false;
176
        $this->dom->formatOutput = false;
177
    }
178
179
    /**
180
     * Retorns the xml
181
     *
182
     * @return xml
183
     */
184
    public function getXML()
185
    {
186
        if (empty($this->xml)) {
0 ignored issues
show
Bug introduced by
The property xml does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
187
            $this->montaMDFe();
188
        }
189
        return $this->xml;
190
    }
191
192
    /**
193
     * Retorns the key number of NFe (44 digits)
194
     *
195
     * @return string
196
     */
197
    public function getChave()
198
    {
199
        return $this->chMDFe;
200
    }
201
202
    /**
203
     * Returns the model of MDFe
204
     *
205
     * @return int
206
     */
207
    public function getModelo()
208
    {
209
        return $this->mod;
210
    }
211
212
    /**
213
     * Call method of xml assembly. For compatibility only.
214
     *
215
     * @return boolean
216
     */
217
    public function montaMDFe()
218
    {
219
        return $this->monta();
220
    }
221
222
    /**
223
     * MDFe xml mount method
224
     * this function returns TRUE on success or FALSE on error
225
     * The xml of the MDFe must be retrieved by the getXML() function or
226
     * directly by the public property $xml
227
     *
228
     * @return boolean
229
     */
230
    public function monta()
231
    {
232
        $this->errors = $this->dom->errors;
233
        if (count($this->errors) > 0) {
234
            return false;
235
        }
236
        //cria a tag raiz da MDFe
237
        $this->buildMDFe();
238
        $this->buildInfModal();
239
        
240
        $this->infMDFe = $this->dom->createElement("infMDFe");
241
242
        $this->dom->appChild($this->infMDFe, $this->ide, 'Falta tag "infMDFe"');
243
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "emit"');
244
        $this->dom->appChild($this->infMDFe, $this->emit, 'Falta tag "infMDFe"');
245
        if (! empty($this->rodo)) {
246
            $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "infModal"');
247
        }
248
        if (!empty($this->aquav)) {
249
            $this->dom->appChild($this->infModal, $this->aquav, 'Falta tag "infModal"');
250
            foreach ($this->infTermCarreg as $termCarreg) {
251
                $this->dom->appChild($this->aquav, $termCarreg, 'Falta tag "aquav"');
252
            }
253
            foreach ($this->infTermDescarreg as $termDescarreg) {
254
                $this->dom->appChild($this->aquav, $termDescarreg, 'Falta tag "aquav"');
255
            }
256
            foreach ($this->infEmbComb as $embComb) {
257
                $this->dom->appChild($this->aquav, $embComb, 'Falta tag "aquav"');
258
            }
259
            foreach ($this->infUnidCargaVazia as $unidCargaVazia) {
260
                $this->dom->appChild($this->aquav, $unidCargaVazia, 'Falta tag "aquav"');
261
            }
262
            foreach ($this->infUnidTranspVazia as $unidTranspVazia) {
263
                $this->dom->appChild($this->aquav, $unidTranspVazia, 'Falta tag "aquav"');
264
            }
265
        }
266
        $this->dom->appChild($this->infMDFe, $this->infModal, 'Falta tag "infMDFe"');
267
        $this->dom->appChild($this->infMDFe, $this->infDoc, 'Falta tag "infMDFe"');
268
        if (! empty($this->seg)) {
269
            $this->dom->appChild($this->infMDFe, $this->seg, 'Falta tag "infMDFe"');
270
        }
271
        $this->dom->appChild($this->infMDFe, $this->tot, 'Falta tag "infMDFe"');
272
        foreach ($this->aLacres as $lacre) {
0 ignored issues
show
Bug introduced by
The expression $this->aLacres of type string|object<DOMNode> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
273
            $this->dom->appChild($this->infMDFe, $lacre, 'Falta tag "infMDFe"');
274
        }
275
        foreach ($this->autXML as $autXML) {
0 ignored issues
show
Bug introduced by
The expression $this->autXML of type string|object<DOMNode> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
276
            $this->dom->appChild($this->infMDFe, $autXML, 'Falta tag "infMDFe"');
277
        }
278
        if (! empty($this->infAdic)) {
279
            $this->dom->appChild($this->infMDFe, $this->infAdic, 'Falta tag "infMDFe"');
280
        }
281
        $this->dom->appChild($this->MDFe, $this->infMDFe, 'Falta tag "MDFe"');
282
        
283
        $this->dom->appendChild($this->MDFe);
284
        // testa da chave
285
        $this->checkMDFKey($this->dom);
286
        $this->xml = $this->dom->saveXML();
287
        
288
        return true;
289
    }
290
291
    /**
292
     * Informações de identificação da MDFe
293
     * tag MDFe/infMDFe/ide
294
     *
295
     * @param  stdClass $std
296
     * @return DOMElement
297
     */
298
    public function tagide(stdClass $std)
299
    {
300
301
        $possible = [
302
            'cUF',
303
            'tpAmb',
304
            'tpEmit',
305
            'tpTransp',
306
            'mod',
307
            'serie',
308
            'nMDF',
309
            'cMDF',
310
            'cDV',
311
            'modal',
312
            'dhEmi',
313
            'tpEmis',
314
            'procEmi',
315
            'verProc',
316
            'ufIni',
317
            'ufFim'
318
        ];
319
320
        $std = $this->equilizeParameters($std, $possible);
321
        
322
        $this->tpAmb = $std->tpAmb;
0 ignored issues
show
Bug introduced by
The property tpAmb does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
323
        $identificador = '[4] <ide> - ';
324
        $ide = $this->dom->createElement("ide");
325
        $this->dom->addChild(
326
            $ide,
327
            "cUF",
328
            $std->cUF,
329
            true,
330
            $identificador . "Código da UF do emitente do Documento Fiscal"
331
        );
332
        $this->dom->addChild(
333
            $ide,
334
            "tpAmb",
335
            $std->tpAmb,
336
            true,
337
            $identificador . "Identificação do Ambiente"
338
        );
339
        $this->dom->addChild(
340
            $ide,
341
            "tpEmit",
342
            $std->tpEmit,
343
            true,
344
            $identificador . "Indicador da tipo de emitente"
345
        );
346
        $this->dom->addChild(
347
            $ide,
348
            "tpTransp",
349
            $std->tpTransp,
350
            false,
351
            $identificador . "Tipo do Transportador"
352
        );
353
        $this->dom->addChild(
354
            $ide,
355
            "mod",
356
            $std->mod,
357
            true,
358
            $identificador . "Código do Modelo do Documento Fiscal"
359
        );
360
        $this->dom->addChild(
361
            $ide,
362
            "serie",
363
            $std->serie,
364
            true,
365
            $identificador . "Série do Documento Fiscal"
366
        );
367
        $this->dom->addChild(
368
            $ide,
369
            "nMDF",
370
            $std->nMDF,
371
            true,
372
            $identificador . "Número do Documento Fiscal"
373
        );
374
        $this->dom->addChild(
375
            $ide,
376
            "cMDF",
377
            $std->cMDF,
378
            true,
379
            $identificador . "Código do numérico do MDF"
380
        );
381
        $this->dom->addChild(
382
            $ide,
383
            "cDV",
384
            $std->cDV,
385
            true,
386
            $identificador . "Dígito Verificador da Chave de Acesso da NF-e"
387
        );
388
        $this->dom->addChild(
389
            $ide,
390
            "modal",
391
            $std->modal,
392
            true,
393
            $identificador . "Modalidade de transporte"
394
        );
395
        $this->dom->addChild(
396
            $ide,
397
            "dhEmi",
398
            $std->dhEmi,
399
            true,
400
            $identificador . "Data e hora de emissão do Documento Fiscal"
401
        );
402
        $this->dom->addChild(
403
            $ide,
404
            "tpEmis",
405
            $std->tpEmis,
406
            true,
407
            $identificador . "Tipo de Emissão do Documento Fiscal"
408
        );
409
        $this->dom->addChild(
410
            $ide,
411
            "procEmi",
412
            $std->procEmi,
413
            true,
414
            $identificador . "Processo de emissão"
415
        );
416
        $this->dom->addChild(
417
            $ide,
418
            "verProc",
419
            $std->verProc,
420
            true,
421
            $identificador . "Versão do Processo de emissão"
422
        );
423
        $this->dom->addChild(
424
            $ide,
425
            "UFIni",
426
            $std->UFIni,
427
            true,
428
            $identificador . "Sigla da UF do Carregamento"
429
        );
430
        $this->dom->addChild(
431
            $ide,
432
            "UFFim",
433
            $std->UFFim,
434
            true,
435
            $identificador . "Sigla da UF do Descarregamento"
436
        );
437
        
438
        $this->mod = $std->mod;
439
        $this->ide = $ide;
440
        $this->buildTagIde();
441
        return $ide;
442
    }
443
444
    /**
445
     * taginfMunCarrega
446
     *
447
     * tag MDFe/infMDFe/ide/infMunCarrega
448
     *
449
     * @param  stdClass $std
450
     * @return DOMElement
451
     */
452
    public function taginfMunCarrega(stdClass $std)
453
    {
454
        $possible = [
455
            'cMunCarrega',
456
            'xMunCarrega'
457
        ];
458
459
        $std = $this->equilizeParameters($std, $possible);
460
        $infMunCarrega = $this->dom->createElement("infMunCarrega");
461
        $this->dom->addChild(
462
            $infMunCarrega,
463
            "cMunCarrega",
464
            $std->cMunCarrega,
465
            true,
466
            "Código do Município de Carregamento"
467
        );
468
        $this->dom->addChild(
469
            $infMunCarrega,
470
            "xMunCarrega",
471
            $std->xMunCarrega,
472
            true,
473
            "Nome do Município de Carregamento"
474
        );
475
        $this->aInfMunCarrega[] = $infMunCarrega;
476
        return $infMunCarrega;
477
    }
478
479
    /**
480
     * tagInfPercurso
481
     *
482
     * tag MDFe/infMDFe/ide/infPercurso
483
     *
484
     * @param  stdClass $std
485
     * @return DOMElement
486
     */
487
    public function taginfPercurso(stdClass $std)
488
    {
489
        $possible = [
490
            'UFPer'
491
        ];
492
493
        $std = $this->equilizeParameters($std, $possible);
494
        foreach ($std->UFPer as $UFPer) {
495
            $infPercurso = $this->dom->createElement("infPercurso");
496
            $this->dom->addChild(
497
                $infPercurso,
498
                "UFPer",
499
                $UFPer,
500
                true,
501
                "Sigla das Unidades da Federação do percurso"
502
            );
503
            $this->aInfPercurso[] = $infPercurso;
504
        }
505
        return $this->aInfPercurso;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->aInfPercurso; of type array|DOMNode adds the type array to the return on line 505 which is incompatible with the return type documented by NFePHP\MDFe\Make::taginfPercurso of type DOMElement.
Loading history...
506
    }
507
508
    /**
509
     * tagemit
510
     * Identificação do emitente da MDFe
511
     * tag MDFe/infMDFe/emit
512
     *
513
     * @param  stdClass $std
514
     * @return DOMElement
515
     */
516
    public function tagemit(stdClass $std)
517
    {
518
        $possible = [
519
            'CNPJ',
520
            'CPF',
521
            'IE',
522
            'xNome',
523
            'xFant'
524
        ];
525
        $std = $this->equilizeParameters($std, $possible);
526
        
527
        $identificador = '[25] <emit> - ';
528
        $this->emit = $this->dom->createElement("emit");
529
        $this->dom->addChild(
530
            $this->emit,
531
            "CNPJ",
532
            $std->CNPJ,
533
            false,
534
            $identificador . "CNPJ do emitente"
535
        );
536
        $this->dom->addChild(
537
            $this->emit,
538
            "CPF",
539
            $std->CPF,
540
            false,
541
            $identificador . "CPF do emitente"
542
        );
543
        $this->dom->addChild(
544
            $this->emit,
545
            "IE",
546
            $std->IE,
547
            false,
548
            $identificador . "Inscrição Estadual do emitente"
549
        );
550
        $this->dom->addChild(
551
            $this->emit,
552
            "xNome",
553
            $std->xNome,
554
            true,
555
            $identificador . "Razão Social ou Nome do emitente"
556
        );
557
        $this->dom->addChild(
558
            $this->emit,
559
            "xFant",
560
            $std->xFant,
561
            false,
562
            $identificador . "Nome fantasia do emitente"
563
        );
564
        return $this->emit;
565
    }
566
567
    /**
568
     * tagenderEmit
569
     * Endereço do emitente [30] pai [25]
570
     * tag MDFe/infMDFe/emit/endEmit
571
     *
572
     * @param  stdClass $std
573
     * @return DOMElement
574
     */
575
    public function tagenderEmit(stdClass $std)
576
    {
577
        $possible = [
578
            'xLgr',
579
            'nro',
580
            'xCpl',
581
            'xBairro',
582
            'cMun',
583
            'xMun',
584
            'CEP',
585
            'UF',
586
            'fone',
587
            'email'
588
        ];
589
        $std = $this->equilizeParameters($std, $possible);
590
591
        $identificador = '[30] <enderEmit> - ';
592
        $this->enderEmit = $this->dom->createElement("enderEmit");
593
        
594
        $this->dom->addChild(
595
            $this->enderEmit,
596
            "xLgr",
597
            $std->xLgr,
598
            true,
599
            $identificador . "Logradouro do Endereço do emitente"
600
        );
601
        $this->dom->addChild(
602
            $this->enderEmit,
603
            "nro",
604
            $std->nro,
605
            true,
606
            $identificador . "Número do Endereço do emitente"
607
        );
608
        $this->dom->addChild(
609
            $this->enderEmit,
610
            "xCpl",
611
            $std->xCpl,
612
            false,
613
            $identificador . "Complemento do Endereço do emitente"
614
        );
615
        $this->dom->addChild(
616
            $this->enderEmit,
617
            "xBairro",
618
            $std->xBairro,
619
            true,
620
            $identificador . "Bairro do Endereço do emitente"
621
        );
622
        $this->dom->addChild(
623
            $this->enderEmit,
624
            "cMun",
625
            $std->cMun,
626
            true,
627
            $identificador . "Código do município do Endereço do emitente"
628
        );
629
        $this->dom->addChild(
630
            $this->enderEmit,
631
            "xMun",
632
            $std->xMun,
633
            true,
634
            $identificador . "Nome do município do Endereço do emitente"
635
        );
636
        $this->dom->addChild(
637
            $this->enderEmit,
638
            "CEP",
639
            $std->CEP,
640
            true,
641
            $identificador . "Código do CEP do Endereço do emitente"
642
        );
643
        $this->dom->addChild(
644
            $this->enderEmit,
645
            "UF",
646
            $std->UF,
647
            true,
648
            $identificador . "Sigla da UF do Endereço do emitente"
649
        );
650
        $this->dom->addChild(
651
            $this->enderEmit,
652
            "fone",
653
            $std->fone,
654
            false,
655
            $identificador . "Número de telefone do emitente"
656
        );
657
        $this->dom->addChild(
658
            $this->enderEmit,
659
            "email",
660
            $std->email,
661
            false,
662
            $identificador . "Endereço de email do emitente"
663
        );
664
        return $this->enderEmit;
665
    }
666
667
    /**
668
     * tagInfMunDescarga
669
     * tag MDFe/infMDFe/infDoc/infMunDescarga
670
     *
671
     * @param  stdClass $std
672
     * @return DOMElement
673
     */
674
    public function taginfMunDescarga(stdClass $std)
675
    {
676
        $possible = [
677
            'cMunDescarga',
678
            'xMunDescarga'
679
        ];
680
        $std = $this->equilizeParameters($std, $possible);
681
682
        if (empty($this->infDoc)) {
683
            $infDoc = $this->dom->createElement("infDoc");
684
        } else {
685
            $infDoc = $this->infDoc;
686
        }
687
        $infMunDescarga = $this->dom->createElement("infMunDescarga");
688
        $this->dom->addChild(
689
            $infMunDescarga,
690
            "cMunDescarga",
691
            $std->cMunDescarga,
692
            true,
693
            "Código do Município de Descarga"
694
        );
695
        $this->dom->addChild(
696
            $infMunDescarga,
697
            "xMunDescarga",
698
            $std->xMunDescarga,
699
            true,
700
            "Nome do Município de Descarga"
701
        );
702
        $this->dom->appChild($infDoc, $infMunDescarga, 'Falta tag "infDoc"');
703
        $this->infDoc = $infDoc;
704
        $this->aInfMunDescarga = $infMunDescarga;
705
        return $infMunDescarga;
706
    }
707
708
    /**
709
     * taginfANTT
710
     * tag MDFe/infMDFe/rodo/taginfANTT
711
     *
712
     * @param  stdClass $std
713
     * @return DOMElement
714
     */
715
    public function taginfANTT(stdClass $std)
716
    {
717
        $possible = [
718
            'RNTRC',
719
            'infCIOT',
720
            'valePed',
721
            'infContratante'
722
        ];
723
        $std = $this->equilizeParameters($std, $possible);
724
        $rodo = $this->dom->createElement("rodo");
725
        $infANTT = $this->dom->createElement("infANTT");
726
        $this->dom->addChild(
727
            $infANTT,
728
            "RNTRC",
729
            $std->RNTRC,
730
            false,
731
            "RNTRC"
732
        );
733
734
        if ($std->infCIOT != null) {
735
            $possible = [
736
                'CIOT',
737
                'CPF',
738
                'CNPJ'
739
            ];
740
            foreach ($std->infCIOT as $infCIOT) {
741
                $stdinfCIOT = $this->equilizeParameters($infCIOT, $possible);
742
                $infCIOT = $this->dom->createElement("infCIOT");
743
                $this->dom->addChild(
744
                    $infCIOT,
745
                    "CIOT",
746
                    $stdinfCIOT->CIOT,
747
                    true,
748
                    "CIOT"
749
                );
750
                
751
                $this->dom->addChild(
752
                    $infCIOT,
753
                    "CPF",
754
                    $stdinfCIOT->CPF,
755
                    false,
756
                    "CPF"
757
                );
758
                $this->dom->addChild(
759
                    $infCIOT,
760
                    "CNPJ",
761
                    $stdinfCIOT->CNPJ,
762
                    false,
763
                    "CNPJ"
764
                );
765
                $this->dom->appChild($infANTT, $infCIOT, 'Falta tag "$infANTT"');
766
            }
767
        }
768
        if ($std->valePed != null) {
769
            $possible = [
770
                'CNPJForn',
771
                'CNPJPg',
772
                'CPFPg',
773
                'nCompra',
774
                'vValePed'
775
            ];
776
            foreach ($std->valePed as $valePed) {
777
                $stdvalePed = $this->equilizeParameters($valePed, $possible);
778
                $valePed = $this->dom->createElement("valePed");
779
                $disp = $this->dom->createElement("disp");
780
                $this->dom->addChild(
781
                    $disp,
782
                    "CNPJForn",
783
                    $stdvalePed->CNPJForn,
784
                    false,
785
                    "CNPJForn"
786
                );
787
                $this->dom->addChild(
788
                    $disp,
789
                    "CNPJPg",
790
                    $stdvalePed->CNPJPg,
791
                    false,
792
                    "CNPJPg"
793
                );
794
                $this->dom->addChild(
795
                    $disp,
796
                    "CPFPg",
797
                    $stdvalePed->CPFPg,
798
                    false,
799
                    "CPFPg"
800
                );
801
                $this->dom->addChild(
802
                    $disp,
803
                    "nCompra",
804
                    $stdvalePed->nCompra,
805
                    false,
806
                    "nCompra"
807
                );
808
                $this->dom->addChild(
809
                    $disp,
810
                    "vValePed",
811
                    $stdvalePed->vValePed,
812
                    false,
813
                    "vValePed"
814
                );
815
                $this->dom->appChild($valePed, $disp, 'Falta tag "valePed"');
816
                $this->dom->appChild($infANTT, $valePed, 'Falta tag "infANTT"');
817
            }
818
        }
819
        if ($std->infContratante != null) {
820
            $possible = [
821
                'CPF',
822
                'CNPJ'
823
            ];
824
            foreach ($std->infContratante as $infContratante) {
825
                $stdinfContratante = $this->equilizeParameters($infContratante, $possible);
826
                $infContratante = $this->dom->createElement("infContratante");
827
                $this->dom->addChild(
828
                    $infContratante,
829
                    "CPF",
830
                    $stdinfContratante->CPF,
831
                    false,
832
                    "CPF"
833
                );
834
                $this->dom->addChild(
835
                    $infContratante,
836
                    "CNPJ",
837
                    $stdinfContratante->CNPJ,
838
                    false,
839
                    "CNPJ"
840
                );
841
                $this->dom->appChild($infANTT, $infContratante, 'Falta tag "infANTT"');
842
            }
843
        }
844
        
845
        $this->dom->appChild($rodo, $infANTT, 'Falta tag "rodo"');
846
        $this->rodo = $rodo;
847
        return $this->rodo;
848
    }
849
    
850
    /**
851
     * taginfCTe
852
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infCTe
853
     *
854
     * @param  stdClass $std
855
     * @return DOMElement
856
     */
857
    public function taginfCTe(stdClass $std)
858
    {
859
        $possible = [
860
            'chCTe',
861
            'SegCodBarra',
862
            'indReentrega',
863
            'infUnidTransp',
864
            'peri',
865
            'infEntregaParcial'
866
        ];
867
        $std = $this->equilizeParameters($std, $possible);
868
        $infCTe = $this->dom->createElement("infCTe");
869
        $this->dom->addChild(
870
            $infCTe,
871
            "chCTe",
872
            $std->chCTe,
873
            true,
874
            "Chave de Acesso CTe"
875
        );
876
        $this->dom->addChild(
877
            $infCTe,
878
            "SegCodBarra",
879
            $std->SegCodBarra,
880
            false,
881
            "Segundo código de barras do CTe"
882
        );
883
        $this->dom->addChild(
884
            $infCTe,
885
            "indReentrega",
886
            $std->indReentrega,
887
            false,
888
            "Indicador de Reentrega"
889
        );
890
        if ($std->infUnidTransp != null) {
891
            $infUnidTransp = $this->taginfUnidTransp($std->infUnidTransp);
892
            $this->dom->appChild($infCTe, $infUnidTransp, 'Falta tag "infCTe"');
893
        }
894
        if ($std->peri != null) {
895
            $peri = $this->tagperi($std->peri);
896
            $this->dom->appChild($infCTe, $peri, 'Falta tag "infCTe"');
897
        }
898
        if ($std->infEntregaParcial != null) {
899
            $possible = [
900
                'qtdTotal',
901
                'qtdParcial'
902
            ];
903
            $stdinfEntregaParcial = $this->equilizeParameters($std->infEntregaParcial, $possible);
904
            $infEntregaParcial = $this->dom->createElement("infEntregaParcial");
905
            $this->dom->addChild(
906
                $infEntregaParcial,
907
                "qtdTotal",
908
                $stdinfEntregaParcial->qtdTotal,
909
                true,
910
                "Quantidade total de volumes"
911
            );
912
            $this->dom->addChild(
913
                $infEntregaParcial,
914
                "qtdParcial",
915
                $stdinfEntregaParcial->qtdParcial,
916
                true,
917
                "Quantidade de volumes enviados no MDF-e"
918
            );
919
            $this->dom->appChild($infCTe, $infEntregaParcial, 'Falta tag "infCTe"');
920
        }
921
        $this->dom->appChild($this->aInfMunDescarga, $infCTe, 'Falta tag "infMunDescarga"');
922
        return $infCTe;
923
    }
924
925
    /**
926
     * tagperi
927
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/peri
928
     *
929
     * @param  stdClass $std
930
     * @return DOMElement
931
     */
932
    public function tagperi(stdClass $std)
933
    {
934
        $possible = [
935
            'nONU',
936
            'xNomeAE',
937
            'xClaRisco',
938
            'grEmb',
939
            'qTotProd',
940
            'qVolTipo'
941
        ];
942
        $std = $this->equilizeParameters($std, $possible);
943
        $peri = $this->dom->createElement("peri");
944
        $this->dom->addChild(
945
            $peri,
946
            "nONU",
947
            $std->nONU,
948
            true,
949
            "Número ONU/UN"
950
        );
951
        $this->dom->addChild(
952
            $peri,
953
            "xNomeAE",
954
            $std->xNomeAE,
955
            true,
956
            "Nome apropriado para embarque do produto"
957
        );
958
        $this->dom->addChild(
959
            $peri,
960
            "xClaRisco",
961
            $std->xClaRisco,
962
            true,
963
            "Classe ou subclasse/divisão, e risco subsidiário/risco secundário"
964
        );
965
        $this->dom->addChild(
966
            $peri,
967
            "grEmb",
968
            $std->grEmb,
969
            true,
970
            "Grupo de Embalagem"
971
        );
972
        $this->dom->addChild(
973
            $peri,
974
            "qTotProd",
975
            $std->qTotProd,
976
            true,
977
            "Quantidade total por produto"
978
        );
979
        $this->dom->addChild(
980
            $peri,
981
            "qVolTipo",
982
            $std->qVolTipo,
983
            true,
984
            "Quantidade e Tipo de volumes"
985
        );
986
        return $peri;
987
    }
988
    
989
    /**
990
     * taginfNFe
991
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infNFe
992
     *
993
     * @param  stdClass $std
994
     * @return DOMElement
995
     */
996
    public function taginfNFe(stdClass $std)
997
    {
998
        $possible = [
999
            'chNFe',
1000
            'SegCodBarra',
1001
            'indReentrega',
1002
            'infUnidTransp',
1003
            'peri'
1004
        ];
1005
        $std = $this->equilizeParameters($std, $possible);
1006
        $infNFe = $this->dom->createElement("infNFe");
1007
        $this->dom->addChild(
1008
            $infNFe,
1009
            "chNFe",
1010
            $std->chNFe,
1011
            true,
1012
            "Chave de Acesso NFe"
1013
        );
1014
        $this->dom->addChild(
1015
            $infNFe,
1016
            "SegCodBarra",
1017
            $std->SegCodBarra,
1018
            false,
1019
            "Segundo código de barras do NFe"
1020
        );
1021
        $this->dom->addChild(
1022
            $infNFe,
1023
            "indReentrega",
1024
            $std->indReentrega,
1025
            false,
1026
            "Indicador de Reentrega"
1027
        );
1028
        if ($std->infUnidTransp != null) {
1029
            $infUnidTransp = $this->taginfUnidTransp($std->infUnidTransp);
1030
            $this->dom->appChild($infNFe, $infUnidTransp, 'Falta tag "infNFe"');
1031
        }
1032
        if ($std->peri != null) {
1033
            $peri = $this->tagperi($std->peri);
1034
            $this->dom->appChild($infNFe, $peri, 'Falta tag "infNFe"');
1035
        }
1036
        $this->dom->appChild($this->aInfMunDescarga, $infNFe, 'Falta tag "infMunDescarga"');
1037
        return $infNFe;
1038
    }
1039
1040
    /**
1041
     * taginfMDFeTransp
1042
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infMDFeTransp
1043
     *
1044
     * @param  stdClass $std
1045
     * @return DOMElement
1046
     */
1047
    public function taginfMDFeTransp(stdClass $std)
1048
    {
1049
        $possible = [
1050
            'chMDFe',
1051
            'indReentrega',
1052
            'infUnidTransp',
1053
            'peri'
1054
        ];
1055
        $std = $this->equilizeParameters($std, $possible);
1056
        $infMDFeTransp = $this->dom->createElement("infMDFeTransp");
1057
        $this->dom->addChild(
1058
            $infMDFeTransp,
1059
            "chMDFe",
1060
            $std->chMDFe,
1061
            true,
1062
            "Chave de Acesso NFe"
1063
        );
1064
        $this->dom->addChild(
1065
            $infMDFeTransp,
1066
            "indReentrega",
1067
            $std->indReentrega,
1068
            false,
1069
            "Indicador de Reentrega"
1070
        );
1071
        if ($std->infUnidTransp != null) {
1072
            $infUnidTransp = $this->taginfUnidTransp($std->infUnidTransp);
1073
            $this->dom->appChild($infMDFeTransp, $infUnidTransp, 'Falta tag "infMDFeTransp"');
1074
        }
1075
        if ($std->peri != null) {
1076
            $peri = $this->tagperi($std->peri);
1077
            $this->dom->appChild($infMDFeTransp, $peri, 'Falta tag "infMDFeTransp"');
1078
        }
1079
        $this->dom->appChild($this->aInfMunDescarga, $infMDFeTransp, 'Falta tag "infMunDescarga"');
1080
        return $infMDFeTransp;
1081
    }
1082
1083
    /**
1084
     * taginfUnidTransp
1085
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/infUnidTransp
1086
     *
1087
     * @param  stdClass $std
1088
     * @return DOMElement
1089
     */
1090
    public function taginfUnidTransp(stdClass $std)
1091
    {
1092
        $possible = [
1093
            'tpUnidTransp',
1094
            'idUnidTransp',
1095
            'qtdRat',
1096
            'lacUnidTransp',
1097
            'infUnidCarga'
1098
        ];
1099
        $std = $this->equilizeParameters($std, $possible);
1100
        $infUnidTransp = $this->dom->createElement("infUnidTransp");
1101
        $this->dom->addChild(
1102
            $infUnidTransp,
1103
            "tpUnidTransp",
1104
            $std->tpUnidTransp,
1105
            true,
1106
            "Tipo da Unidade de Transporte"
1107
        );
1108
        $this->dom->addChild(
1109
            $infUnidTransp,
1110
            "idUnidTransp",
1111
            $std->idUnidTransp,
1112
            false,
1113
            "Identificação da Unidade de Transporte"
1114
        );
1115
        if ($std->lacUnidTransp != null) {
1116
            $possible = [
1117
                'nLacre'
1118
            ];
1119
            $stdlacUnidTransp = $this->equilizeParameters($std->lacUnidTransp, $possible);
1120
            foreach ($stdlacUnidTransp->nLacre as $nLacre) {
1121
                $lacUnidTransp = $this->dom->createElement("lacUnidTransp");
1122
                $this->dom->addChild(
1123
                    $lacUnidTransp,
1124
                    "nLacre",
1125
                    $nLacre,
1126
                    true,
1127
                    "Número do lacre"
1128
                );
1129
                $this->dom->appChild($infUnidTransp, $lacUnidTransp, 'Falta tag "infUnidTransp"');
1130
            }
1131
        }
1132
        if ($std->infUnidCarga != null) {
1133
            $infUnidCarga = $this->taginfUnidCarga($std->infUnidCarga);
1134
            $this->dom->appChild($infUnidTransp, $infUnidCarga, 'Falta tag "infUnidTransp"');
1135
        }
1136
        $this->dom->addChild(
1137
            $infUnidTransp,
1138
            "qtdRat",
1139
            $std->qtdRat,
1140
            false,
1141
            "Quantidade rateada (Peso,Volume) "
1142
        );
1143
        return $infUnidTransp;
1144
    }
1145
1146
    /**
1147
     * taginfUnidCarga
1148
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/infUnidCarga
1149
     *
1150
     * @param  stdClass $std
1151
     * @return DOMElement
1152
     */
1153
    public function taginfUnidCarga(stdClass $std)
1154
    {
1155
        $possible = [
1156
            'tpUnidCarga',
1157
            'idUnidCarga',
1158
            'lacUnidCarga',
1159
            'qtdRat'
1160
        ];
1161
        $std = $this->equilizeParameters($std, $possible);
1162
        $infUnidCarga = $this->dom->createElement("infUnidCarga");
1163
        $this->dom->addChild(
1164
            $infUnidCarga,
1165
            "tpUnidCarga",
1166
            $std->tpUnidCarga,
1167
            false,
1168
            "Tipo da Unidade de Carga"
1169
        );
1170
        $this->dom->addChild(
1171
            $infUnidCarga,
1172
            "idUnidCarga",
1173
            $std->idUnidCarga,
1174
            false,
1175
            "Identificação da Unidade de Carga "
1176
        );
1177
        if ($std->lacUnidCarga != null) {
1178
            $possible = [
1179
                'nLacre'
1180
            ];
1181
            $stdlacUnidCarga = $this->equilizeParameters($std->lacUnidCarga, $possible);
1182
            foreach ($stdlacUnidCarga->nLacre as $nLacre) {
1183
                $lacUnidCarga = $this->dom->createElement("lacUnidCarga");
1184
                $this->dom->addChild(
1185
                    $lacUnidCarga,
1186
                    "nLacre",
1187
                    $nLacre,
1188
                    true,
1189
                    "Número do lacre"
1190
                );
1191
                $this->dom->appChild($infUnidCarga, $lacUnidCarga, 'Falta tag "infUnidCarga"');
1192
            }
1193
        }
1194
        $this->dom->addChild(
1195
            $infUnidCarga,
1196
            "qtdRat",
1197
            $std->qtdRat,
1198
            false,
1199
            "Quantidade rateada (Peso,Volume) "
1200
        );
1201
        
1202
        return $infUnidCarga ;
1203
    }
1204
    
1205
    /**
1206
     * tagseg
1207
     * tag MDFe/infMDFe/seg
1208
     *
1209
     * @param  stdClass $std
1210
     * @return DOMElement
1211
     */
1212
    public function tagseg(stdClass $std)
1213
    {
1214
        $possible = [
1215
            'respSeg',
1216
            'CNPJ',
1217
            'CPF',
1218
            'infSeg',
1219
            'nApol',
1220
            'nAver'
1221
        ];
1222
        $std = $this->equilizeParameters($std, $possible);
1223
        $seg = $this->dom->createElement("seg");
1224
        $infResp = $this->dom->createElement("infResp");
1225
        $this->dom->addChild(
1226
            $infResp,
1227
            "respSeg",
1228
            $std->respSeg,
1229
            true,
1230
            "Responsável pelo seguro"
1231
        );
1232
        $this->dom->addChild(
1233
            $infResp,
1234
            "CNPJ",
1235
            $std->CNPJ,
1236
            false,
1237
            "Número do CNPJ do responsável pelo seguro"
1238
        );
1239
        $this->dom->addChild(
1240
            $infResp,
1241
            "CPF",
1242
            $std->CPF,
1243
            false,
1244
            "Número do CPF do responsável pelo seguro"
1245
        );
1246
        $this->dom->appChild($seg, $infResp, 'Falta tag "seg"');
1247
        if ($std->infSeg != null) {
1248
            $possible = [
1249
                'xSeg',
1250
                'CNPJ'
1251
            ];
1252
            $stdinfSeg = $this->equilizeParameters($std->infSeg, $possible);
1253
            $infSeg = $this->dom->createElement("infSeg");
1254
            $this->dom->addChild(
1255
                $infSeg,
1256
                "xSeg",
1257
                $stdinfSeg->xSeg,
1258
                true,
1259
                "Nome da Seguradora"
1260
            );
1261
            $this->dom->addChild(
1262
                $infSeg,
1263
                "CNPJ",
1264
                $stdinfSeg->CNPJ,
1265
                false,
1266
                "Número do CNPJ da seguradora"
1267
            );
1268
            $this->dom->appChild($seg, $infSeg, 'Falta tag "seg"');
1269
        }
1270
        $this->dom->addChild(
1271
            $seg,
1272
            "nApol",
1273
            $std->nApol,
1274
            false,
1275
            "Número da Apólice"
1276
        );
1277
        if ($std->nAver != null) {
1278
            foreach ($std->nAver as $nAver) {
1279
                $this->dom->addChild(
1280
                    $seg,
1281
                    "nAver",
1282
                    $nAver,
1283
                    true,
1284
                    "Número da Averbação"
1285
                );
1286
            }
1287
        }
1288
        $this->seg = $seg;
1289
        return $seg;
1290
    }
1291
1292
    /**
1293
     * tagTot
1294
     * tag MDFe/infMDFe/tot
1295
     *
1296
     * @param  stdClass $std
1297
     * @return DOMElement
1298
     */
1299
    public function tagtot(stdClass $std)
1300
    {
1301
        $possible = [
1302
            'qCTe',
1303
            'qNFe',
1304
            'qMDFe',
1305
            'vCarga',
1306
            'cUnid',
1307
            'qCarga'
1308
        ];
1309
        $std = $this->equilizeParameters($std, $possible);
1310
        $tot = $this->dom->createElement("tot");
1311
        $this->dom->addChild(
1312
            $tot,
1313
            "qCTe",
1314
            $std->qCTe,
1315
            false,
1316
            "Quantidade total de CT-e relacionados no Manifesto"
1317
        );
1318
        $this->dom->addChild(
1319
            $tot,
1320
            "qNFe",
1321
            $std->qNFe,
1322
            false,
1323
            "Quantidade total de NF-e relacionados no Manifesto"
1324
        );
1325
        $this->dom->addChild(
1326
            $tot,
1327
            "qMDFe",
1328
            $std->qMDFe,
1329
            false,
1330
            "Quantidade total de MDF-e relacionados no Manifesto"
1331
        );
1332
        $this->dom->addChild(
1333
            $tot,
1334
            "vCarga",
1335
            $std->vCarga,
1336
            true,
1337
            "Valor total da mercadoria/carga transportada"
1338
        );
1339
        $this->dom->addChild(
1340
            $tot,
1341
            "cUnid",
1342
            $std->cUnid,
1343
            true,
1344
            "Código da unidade de medida do Peso Bruto da Carga / Mercadoria Transportada"
1345
        );
1346
        $this->dom->addChild(
1347
            $tot,
1348
            "qCarga",
1349
            $std->qCarga,
1350
            true,
1351
            "Peso Bruto Total da Carga / Mercadoria Transportada"
1352
        );
1353
        $this->tot = $tot;
1354
        return $tot;
1355
    }
1356
1357
    /**
1358
     * tagLacres
1359
     * tag MDFe/infMDFe/lacres
1360
     *
1361
     * @param  stdClass $std
1362
     * @return DOMElement
1363
     */
1364
    public function taglacres(stdClass $std)
1365
    {
1366
        $possible = [
1367
            'nLacre'
1368
        ];
1369
        $std = $this->equilizeParameters($std, $possible);
1370
        foreach ($std->nLacre as $nLacre) {
1371
            $lacres = $this->dom->createElement("lacres");
1372
            $this->dom->addChild(
1373
                $lacres,
1374
                "nLacre",
1375
                $nLacre,
1376
                false,
1377
                "Número do lacre"
1378
            );
1379
            $this->aLacres[] = $lacres; //array de DOMNode
1380
        }
1381
        return $this->aLacres;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->aLacres; of type string|DOMNode adds the type string to the return on line 1381 which is incompatible with the return type documented by NFePHP\MDFe\Make::taglacres of type DOMElement.
Loading history...
1382
    }
1383
1384
    /**
1385
     * taginfAdic
1386
     * Grupo de Informações Adicionais Z01 pai A01
1387
     * tag MDFe/infMDFe/infAdic (opcional)
1388
     *
1389
     * @param  stdClass $std
1390
     * @return DOMElement
1391
     */
1392
    public function taginfAdic(stdClass $std)
1393
    {
1394
        $possible = [
1395
            'infAdFisco',
1396
            'infCpl'
1397
        ];
1398
        $std = $this->equilizeParameters($std, $possible);
1399
        $infAdic = $this->dom->createElement("infAdic");
1400
        $this->dom->addChild(
1401
            $infAdic,
1402
            "infAdFisco",
1403
            $std->infAdFisco,
1404
            false,
1405
            "Informações Adicionais de Interesse do Fisco"
1406
        );
1407
        $this->dom->addChild(
1408
            $infAdic,
1409
            "infCpl",
1410
            $std->infCpl,
1411
            false,
1412
            "Informações Complementares de interesse do Contribuinte"
1413
        );
1414
        $this->infAdic = $infAdic;
1415
        return $infAdic;
1416
    }
1417
1418
    /**
1419
     * tagautXML
1420
     * tag MDFe/infMDFe/autXML
1421
     *
1422
     * Autorizados para download do XML do MDF-e
1423
     *
1424
     * @param  stdClass $std
1425
     * @return DOMElement
1426
     */
1427
    public function tagautXML(stdClass $std)
1428
    {
1429
        $possible = [
1430
            'CNPJ',
1431
            'CPF'
1432
        ];
1433
        $std = $this->equilizeParameters($std, $possible);
1434
        $autXML = $this->dom->createElement("autXML");
1435
        $this->dom->addChild(
1436
            $autXML,
1437
            "CNPJ",
1438
            $std->CNPJ,
1439
            false,
1440
            "CNPJ do autorizado"
1441
        );
1442
        $this->dom->addChild(
1443
            $autXML,
1444
            "CPF",
1445
            $std->CPF,
1446
            false,
1447
            "CPF do autorizado"
1448
        );
1449
        $this->autXML[] = $autXML;
1450
        return $this->autXML;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->autXML; of type string|DOMNode adds the type string to the return on line 1450 which is incompatible with the return type documented by NFePHP\MDFe\Make::tagautXML of type DOMElement.
Loading history...
1451
    }
1452
1453
    /**
1454
     * buildInfModal
1455
     * tag MDFe/infMDFe/infModal
1456
     *
1457
     * @return DOMElement
1458
     */
1459
    public function buildInfModal()
1460
    {
1461
        $infModal = $this->dom->createElement("infModal");
1462
        $infModal->setAttribute("versaoModal", $this->versao);
1463
        $this->infModal = $infModal;
1464
        return $infModal;
1465
    }
1466
1467
    /**
1468
     * tagAereo
1469
     * tag MDFe/infMDFe/infModal/aereo
1470
     *
1471
     * @param string $nac
1472
     * @param string $matr
1473
     * @param string $nVoo
1474
     * @param string $cAerEmb
1475
     * @param string $cAerDes
1476
     * @param string $dVoo
1477
     *
1478
     * @return DOMElement
1479
     */
1480
   
1481
    public function tagAereo(
1482
        $nac = '',
1483
        $matr = '',
1484
        $nVoo = '',
1485
        $cAerEmb = '',
1486
        $cAerDes = '',
1487
        $dVoo = ''
1488
    ) {
1489
        $aereo = $this->dom->createElement("aereo");
1490
        $this->dom->addChild(
1491
            $aereo,
1492
            "nac",
1493
            $nac,
1494
            true,
1495
            "Marca da Nacionalidade da aeronave"
1496
        );
1497
        $this->dom->addChild(
1498
            $aereo,
1499
            "matr",
1500
            $matr,
1501
            true,
1502
            "Marca de Matrícula da aeronave"
1503
        );
1504
        $this->dom->addChild(
1505
            $aereo,
1506
            "nVoo",
1507
            $nVoo,
1508
            true,
1509
            "Número do Vôo"
1510
        );
1511
        $this->dom->addChild(
1512
            $aereo,
1513
            "cAerEmb",
1514
            $cAerEmb,
1515
            true,
1516
            "Aeródromo de Embarque - Código IATA"
1517
        );
1518
        $this->dom->addChild(
1519
            $aereo,
1520
            "cAerDes",
1521
            $cAerDes,
1522
            true,
1523
            "Aeródromo de Destino - Código IATA"
1524
        );
1525
        $this->dom->addChild(
1526
            $aereo,
1527
            "dVoo",
1528
            $dVoo,
1529
            true,
1530
            "Data do Vôo"
1531
        );
1532
        $this->aereo = $aereo;
1533
        return $aereo;
1534
    }
1535
    
1536
    /**
1537
     * tagTrem
1538
     * tag MDFe/infMDFe/infModal/ferrov/trem
1539
     *
1540
     * @param string $xPref
1541
     * @param string $dhTrem
1542
     * @param string $xOri
1543
     * @param string $xDest
1544
     * @param string $qVag
1545
     *
1546
     * @return DOMElement
1547
     */
1548
    
1549
    public function tagTrem(
1550
        $xPref = '',
1551
        $dhTrem = '',
1552
        $xOri = '',
1553
        $xDest = '',
1554
        $qVag = ''
1555
    ) {
1556
        $trem = $this->dom->createElement("trem");
1557
        $this->dom->addChild(
1558
            $trem,
1559
            "xPref",
1560
            $xPref,
1561
            true,
1562
            "Prefixo do Trem"
1563
        );
1564
        $this->dom->addChild(
1565
            $trem,
1566
            "dhTrem",
1567
            $dhTrem,
1568
            false,
1569
            "Data e hora de liberação do trem na origem"
1570
        );
1571
        $this->dom->addChild(
1572
            $trem,
1573
            "xOri",
1574
            $xOri,
1575
            true,
1576
            "Origem do Trem"
1577
        );
1578
        $this->dom->addChild(
1579
            $trem,
1580
            "xDest",
1581
            $xDest,
1582
            true,
1583
            "Destino do Trem"
1584
        );
1585
        $this->dom->addChild(
1586
            $trem,
1587
            "qVag",
1588
            $qVag,
1589
            true,
1590
            "Quantidade de vagões"
1591
        );
1592
        $this->trem = $trem;
1593
        return $trem;
1594
    }
1595
    
1596
    /**
1597
     * tagVag
1598
     * tag MDFe/infMDFe/infModal/ferrov/trem/vag
1599
     *
1600
     * @param string $serie
1601
     * @param string $nVag
1602
     * @param string $nSeq
1603
     * @param string $tonUtil
1604
     *
1605
     * @return DOMElement
1606
     */
1607
    
1608
    public function tagVag(
1609
        $serie = '',
1610
        $nVag = '',
1611
        $nSeq = '',
1612
        $tonUtil = ''
1613
    ) {
1614
        $vag = $this->dom->createElement("vag");
1615
        $this->dom->addChild(
1616
            $vag,
1617
            "serie",
1618
            $serie,
1619
            true,
1620
            "Série de Identificação do vagão"
1621
        );
1622
        $this->dom->addChild(
1623
            $vag,
1624
            "nVag",
1625
            $nVag,
1626
            true,
1627
            "Número de Identificação do vagão"
1628
        );
1629
        $this->dom->addChild(
1630
            $vag,
1631
            "nSeq",
1632
            $nSeq,
1633
            false,
1634
            "Sequência do vagão na composição"
1635
        );
1636
        $this->dom->addChild(
1637
            $vag,
1638
            "TU",
1639
            $tonUtil,
1640
            true,
1641
            "Tonelada Útil"
1642
        );
1643
        $this->aVag[] = $vag;
0 ignored issues
show
Bug introduced by
The property aVag does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1644
        return $vag;
1645
    }
1646
1647
    /**
1648
     * tagaquav
1649
     * tag MDFe/infMDFe/infModal/aquav
1650
     *
1651
     * @param stdClass $std
1652
     * @return DOMElement
1653
     */
1654
    public function tagaquav(stdClass $std)
1655
    {
1656
        $possible = [
1657
            "irin",
1658
            "tpEmb",
1659
            "cEmbar",
1660
            "xEmbar",
1661
            "nViag",
1662
            "cPrtEmb",
1663
            "cPrtDest",
1664
            "prtTrans",
1665
            "tpNav",
1666
        ];
1667
        $std = $this->equilizeParameters($std, $possible);
1668
        $aquav = $this->dom->createElement("aquav");
1669
1670
        $this->dom->addChild(
1671
            $aquav,
1672
            "irin",
1673
            $std->irin,
1674
            true,
1675
            "Irin do navio"
1676
        );
1677
        $this->dom->addChild(
1678
            $aquav,
1679
            "tpEmb",
1680
            $std->tpEmb,
1681
            true,
1682
            "Código do tipo de embarcação"
1683
        );
1684
        $this->dom->addChild(
1685
            $aquav,
1686
            "cEmbar",
1687
            $std->cEmbar,
1688
            true,
1689
            "Código da Embarcação"
1690
        );
1691
        $this->dom->addChild(
1692
            $aquav,
1693
            "xEmbar",
1694
            $std->xEmbar,
1695
            true,
1696
            "Nome da embarcação"
1697
        );
1698
        $this->dom->addChild(
1699
            $aquav,
1700
            "nViag",
1701
            $std->nViag,
1702
            true,
1703
            "Número da Viagem"
1704
        );
1705
        $this->dom->addChild(
1706
            $aquav,
1707
            "cPrtEmb",
1708
            $std->cPrtEmb,
1709
            true,
1710
            "Código do Porto de Embarque"
1711
        );
1712
        $this->dom->addChild(
1713
            $aquav,
1714
            "cPrtDest",
1715
            $std->cPrtDest,
1716
            true,
1717
            "Código do Porto de Destino"
1718
        );
1719
        $this->dom->addChild(
1720
            $aquav,
1721
            "prtTrans",
1722
            $std->prtTrans,
1723
            false,
1724
            "Porto de Transbordo"
1725
        );
1726
        $this->dom->addChild(
1727
            $aquav,
1728
            "tpNav",
1729
            $std->tpNav,
1730
            false,
1731
            "Tipo de Navegação"
1732
        );
1733
1734
        $this->aquav = $aquav;
1735
1736
        return $this->aquav;
1737
    }
1738
1739
    /**
1740
     * tagInfTermCarreg
1741
     * tag MDFe/infMDFe/infModal/aquav/infTermCarreg
1742
     *
1743
     * @param stdClass $std
1744
     * @return DOMElement
1745
     */
1746
    public function taginfTermCarreg(stdClass $std)
1747
    {
1748
        $possible = [
1749
            "cTermCarreg",
1750
            "xTermCarreg"
1751
        ];
1752
        $std = $this->equilizeParameters($std, $possible);
1753
        $infTermCarreg = $this->dom->createElement("infTermCarreg");
1754
1755
        $this->dom->addChild(
1756
            $infTermCarreg,
1757
            "cTermCarreg",
1758
            $std->cTermCarreg,
1759
            true,
1760
            "Código do Terminal de Carregamento"
1761
        );
1762
1763
        $this->dom->addChild(
1764
            $infTermCarreg,
1765
            "xTermCarreg",
1766
            $std->xTermCarreg,
1767
            true,
1768
            "Nome do Terminal de Carregamento"
1769
        );
1770
1771
        $this->infTermCarreg[] = $infTermCarreg;
1772
1773
        return $infTermCarreg;
1774
    }
1775
1776
    /**
1777
     * tagInfTermCarreg
1778
     * tag MDFe/infMDFe/infModal/aquav/infTermDescarreg
1779
     *
1780
     * @param stdClass $std
1781
     * @return DOMElement
1782
     */
1783
    public function taginfTermDescarreg(stdClass $std)
1784
    {
1785
        $possible = [
1786
            "cTermDescarreg",
1787
            "xTermDescarreg"
1788
        ];
1789
        $std = $this->equilizeParameters($std, $possible);
1790
        $infTermDescarreg = $this->dom->createElement("infTermDescarreg");
1791
1792
        $this->dom->addChild(
1793
            $infTermDescarreg,
1794
            "cTermDescarreg",
1795
            $std->cTermDescarreg,
1796
            true,
1797
            "Código do Terminal de Carregamento"
1798
        );
1799
1800
        $this->dom->addChild(
1801
            $infTermDescarreg,
1802
            "xTermDescarreg",
1803
            $std->xTermDescarreg,
1804
            true,
1805
            "Nome do Terminal de Carregamento"
1806
        );
1807
1808
        $this->infTermDescarreg[] = $infTermDescarreg;
1809
1810
        return $infTermDescarreg;
1811
    }
1812
1813
    /**
1814
     * tagInfTermCarreg
1815
     * tag MDFe/infMDFe/infModal/aquav/infEmbComb
1816
     *
1817
     * @param stdClass $std
1818
     * @return DOMElement
1819
     */
1820
    public function taginfEmbComb(stdClass $std)
1821
    {
1822
        $possible = [
1823
            "cEmbComb",
1824
            "xBalsa"
1825
        ];
1826
        $std = $this->equilizeParameters($std, $possible);
1827
        $infEmbComb = $this->dom->createElement("infEmbComb");
1828
1829
        $this->dom->addChild(
1830
            $infEmbComb,
1831
            "cEmbComb",
1832
            $std->cEmbComb,
1833
            true,
1834
            "Código da embarcação do comboio"
1835
        );
1836
1837
        $this->dom->addChild(
1838
            $infEmbComb,
1839
            "xBalsa",
1840
            $std->xBalsa,
1841
            true,
1842
            "Identificador da Balsa"
1843
        );
1844
1845
        $this->infEmbComb[] = $infEmbComb;
1846
1847
        return $infEmbComb;
1848
    }
1849
1850
    /**
1851
     * tagInfTermCarreg
1852
     * tag MDFe/infMDFe/infModal/aquav/infUnidCargaVazia
1853
     *
1854
     * @param stdClass $std
1855
     * @return DOMElement
1856
     */
1857
    public function taginfUnidCargaVazia(stdClass $std)
1858
    {
1859
        $possible = [
1860
            "idUnidCargaVazia",
1861
            "tpUnidCargaVazia"
1862
        ];
1863
        $std = $this->equilizeParameters($std, $possible);
1864
        $infUnidCargaVazia = $this->dom->createElement("infUnidCargaVazia");
1865
1866
        $this->dom->addChild(
1867
            $infUnidCargaVazia,
1868
            "idUnidCargaVazia",
1869
            $std->idUnidCargaVazia,
1870
            true,
1871
            "Identificação da unidades de carga vazia"
1872
        );
1873
1874
        $this->dom->addChild(
1875
            $infUnidCargaVazia,
1876
            "tpUnidCargaVazia",
1877
            $std->tpUnidCargaVazia,
1878
            true,
1879
            "Tipo da unidade de carga vazia"
1880
        );
1881
1882
        $this->infUnidCargaVazia[] = $infUnidCargaVazia;
1883
1884
        return $infUnidCargaVazia;
1885
    }
1886
1887
    /**
1888
     * tagInfTermCarreg
1889
     * tag MDFe/infMDFe/infModal/aquav/infUnidTranspVazia
1890
     *
1891
     * @param stdClass $std
1892
     * @return DOMElement
1893
     */
1894
    public function taginfUnidTranspVazia(stdClass $std)
1895
    {
1896
        $possible = [
1897
            "idUnidTranspVazia",
1898
            "tpUnidTranspVazia"
1899
        ];
1900
        $std = $this->equilizeParameters($std, $possible);
1901
        $infUnidTranspVazia = $this->dom->createElement("infUnidTranspVazia");
1902
1903
        $this->dom->addChild(
1904
            $infUnidTranspVazia,
1905
            "idUnidTranspVazia",
1906
            $std->idUnidTranspVazia,
1907
            true,
1908
            "Identificação da unidades de transporte vazia"
1909
        );
1910
1911
        $this->dom->addChild(
1912
            $infUnidTranspVazia,
1913
            "tpUnidTranspVazia",
1914
            $std->tpUnidTranspVazia,
1915
            true,
1916
            "Tipo da unidade de transporte vazia"
1917
        );
1918
1919
        $this->infUnidTranspVazia[] = $infUnidTranspVazia;
1920
1921
        return $infUnidTranspVazia;
1922
    }
1923
    
1924
    /**
1925
     * tagVeicTracao
1926
     * tag MDFe/infMDFe/infModal/rodo/veicTracao
1927
     *
1928
     * @param  stdClass $std
1929
     * @return DOMElement
1930
     */
1931
    public function tagveicTracao(stdClass $std)
1932
    {
1933
        $possible = [
1934
            'cInt',
1935
            'placa',
1936
            'RENAVAM',
1937
            'tara',
1938
            'capKG',
1939
            'capM3',
1940
            'prop',
1941
            'condutor',
1942
            'tpRod',
1943
            'tpCar',
1944
            'UF'
1945
        ];
1946
        $std = $this->equilizeParameters($std, $possible);
1947
        $veicTracao = $this->dom->createElement("veicTracao");
1948
        $this->dom->addChild(
1949
            $veicTracao,
1950
            "cInt",
1951
            $std->cInt,
1952
            false,
1953
            "Código interno do veículo"
1954
        );
1955
        $this->dom->addChild(
1956
            $veicTracao,
1957
            "placa",
1958
            $std->placa,
1959
            true,
1960
            "Placa do veículo"
1961
        );
1962
        $this->dom->addChild(
1963
            $veicTracao,
1964
            "RENAVAM",
1965
            $std->RENAVAM,
1966
            false,
1967
            "RENAVAM"
1968
        );
1969
        $this->dom->addChild(
1970
            $veicTracao,
1971
            "tara",
1972
            $std->tara,
1973
            true,
1974
            "Tara em KG"
1975
        );
1976
        $this->dom->addChild(
1977
            $veicTracao,
1978
            "capKG",
1979
            $std->capKG,
1980
            false,
1981
            "Capacidade em KG"
1982
        );
1983
        $this->dom->addChild(
1984
            $veicTracao,
1985
            "capM3",
1986
            $std->capM3,
1987
            false,
1988
            "Capacidade em M3"
1989
        );
1990
        if ($std->prop != null) {
1991
            $possible = [
1992
                'CPF',
1993
                'CNPJ',
1994
                'RNTRC',
1995
                'xNome',
1996
                'IE',
1997
                'UF',
1998
                'tpProp'
1999
            ];
2000
            $stdprop = $this->equilizeParameters($std->prop, $possible);
2001
            $prop = $this->dom->createElement("prop");
2002
            $this->dom->addChild(
2003
                $prop,
2004
                "CPF",
2005
                $stdprop->CPF,
2006
                false,
2007
                "Número do CPF"
2008
            );
2009
            $this->dom->addChild(
2010
                $prop,
2011
                "CNPJ",
2012
                $stdprop->CNPJ,
2013
                false,
2014
                "Número do CNPJ"
2015
            );
2016
            $this->dom->addChild(
2017
                $prop,
2018
                "RNTRC",
2019
                $stdprop->RNTRC,
2020
                true,
2021
                "RNTRC"
2022
            );
2023
            $this->dom->addChild(
2024
                $prop,
2025
                "xNome",
2026
                $stdprop->xNome,
2027
                true,
2028
                "Razão Social"
2029
            );
2030
            $this->dom->addChild(
2031
                $prop,
2032
                "IE",
2033
                $stdprop->IE,
2034
                true,
2035
                "Inscrição Estadual"
2036
            );
2037
            $this->dom->addChild(
2038
                $prop,
2039
                "UF",
2040
                $stdprop->UF,
2041
                true,
2042
                "Unidade da Federação"
2043
            );
2044
            $this->dom->addChild(
2045
                $prop,
2046
                "tpProp",
2047
                $stdprop->tpProp,
2048
                true,
2049
                "Tipo Proprietário"
2050
            );
2051
            $this->dom->appChild($veicTracao, $prop, 'Falta tag "veicTracao"');
2052
        }
2053
        
2054
        if ($std->condutor != null) {
2055
            $possible = [
2056
                'xNome',
2057
                'CPF'
2058
            ];
2059
            foreach ($std->condutor as $condutor) {
2060
                $stdcondutor = $this->equilizeParameters($condutor, $possible);
2061
                $tagcondutor = $this->dom->createElement("condutor");
2062
                $this->dom->addChild(
2063
                    $tagcondutor,
2064
                    "xNome",
2065
                    $stdcondutor->xNome,
2066
                    true,
2067
                    "Nome do Condutor "
2068
                );
2069
                $this->dom->addChild(
2070
                    $tagcondutor,
2071
                    "CPF",
2072
                    $stdcondutor->CPF,
2073
                    true,
2074
                    "CPF do Condutor "
2075
                );
2076
                $this->dom->appChild($veicTracao, $tagcondutor, 'Falta tag "veicTracao"');
2077
            }
2078
        }
2079
        $this->dom->addChild(
2080
            $veicTracao,
2081
            "tpRod",
2082
            $std->tpRod,
2083
            true,
2084
            "Tipo de rodado"
2085
        );
2086
        $this->dom->addChild(
2087
            $veicTracao,
2088
            "tpCar",
2089
            $std->tpCar,
2090
            true,
2091
            "Tipo de carroceria"
2092
        );
2093
        $this->dom->addChild(
2094
            $veicTracao,
2095
            "UF",
2096
            $std->UF,
2097
            true,
2098
            "UF de licenciamento do veículo"
2099
        );
2100
2101
        $this->dom->appChild($this->rodo, $veicTracao, 'Falta tag "rodo"');
2102
        return $this->rodo;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->rodo; of type string|DOMNode adds the type string to the return on line 2102 which is incompatible with the return type documented by NFePHP\MDFe\Make::tagveicTracao of type DOMElement.
Loading history...
2103
    }
2104
2105
    /**
2106
     * tagVeicReboque
2107
     * tag MDFe/infMDFe/infModal/rodo/VeicReboque
2108
     *
2109
     * @param  stdClass $std
2110
     * @return DOMElement
2111
     */
2112
    public function tagveicReboque(stdClass $std)
2113
    {
2114
        $possible = [
2115
            'cInt',
2116
            'placa',
2117
            'RENAVAM',
2118
            'tara',
2119
            'capKG',
2120
            'capM3',
2121
            'prop',
2122
            'tpCar',
2123
            'UF'
2124
        ];
2125
        $std = $this->equilizeParameters($std, $possible);
2126
        $veicReboque = $this->dom->createElement("veicReboque");
2127
        $this->dom->addChild(
2128
            $veicReboque,
2129
            "cInt",
2130
            $std->cInt,
2131
            false,
2132
            "Código interno do veículo"
2133
        );
2134
        $this->dom->addChild(
2135
            $veicReboque,
2136
            "placa",
2137
            $std->placa,
2138
            true,
2139
            "Placa do veículo"
2140
        );
2141
        $this->dom->addChild(
2142
            $veicReboque,
2143
            "RENAVAM",
2144
            $std->RENAVAM,
2145
            false,
2146
            "RENAVAM"
2147
        );
2148
        $this->dom->addChild(
2149
            $veicReboque,
2150
            "tara",
2151
            $std->tara,
2152
            true,
2153
            "Tara em KG"
2154
        );
2155
        $this->dom->addChild(
2156
            $veicReboque,
2157
            "capKG",
2158
            $std->capKG,
2159
            false,
2160
            "Capacidade em KG"
2161
        );
2162
        $this->dom->addChild(
2163
            $veicReboque,
2164
            "capM3",
2165
            $std->capM3,
2166
            false,
2167
            "Capacidade em M3"
2168
        );
2169
        if ($std->prop != null) {
2170
            $possible = [
2171
                'CPF',
2172
                'CNPJ',
2173
                'RNTRC',
2174
                'xNome',
2175
                'IE',
2176
                'UF',
2177
                'tpProp'
2178
            ];
2179
            $stdprop = $this->equilizeParameters($std->prop, $possible);
2180
            $prop = $this->dom->createElement("prop");
2181
            $this->dom->addChild(
2182
                $prop,
2183
                "CPF",
2184
                $stdprop->CPF,
2185
                false,
2186
                "Número do CPF"
2187
            );
2188
            $this->dom->addChild(
2189
                $prop,
2190
                "CNPJ",
2191
                $stdprop->CNPJ,
2192
                false,
2193
                "Número do CNPJ"
2194
            );
2195
            $this->dom->addChild(
2196
                $prop,
2197
                "RNTRC",
2198
                $stdprop->RNTRC,
2199
                true,
2200
                "RNTRC"
2201
            );
2202
            $this->dom->addChild(
2203
                $prop,
2204
                "xNome",
2205
                $stdprop->xNome,
2206
                true,
2207
                "Razão Social"
2208
            );
2209
            $this->dom->addChild(
2210
                $prop,
2211
                "IE",
2212
                $stdprop->IE,
2213
                true,
2214
                "Inscrição Estadual"
2215
            );
2216
            $this->dom->addChild(
2217
                $prop,
2218
                "UF",
2219
                $stdprop->UF,
2220
                true,
2221
                "Unidade da Federação"
2222
            );
2223
            $this->dom->addChild(
2224
                $prop,
2225
                "tpProp",
2226
                $stdprop->tpProp,
2227
                true,
2228
                "Tipo Proprietário"
2229
            );
2230
            $this->dom->appChild($veicReboque, $prop, 'Falta tag "veicReboque"');
2231
        }
2232
        $this->dom->addChild(
2233
            $veicReboque,
2234
            "tpCar",
2235
            $std->tpCar,
2236
            true,
2237
            "Tipo de carroceria"
2238
        );
2239
        $this->dom->addChild(
2240
            $veicReboque,
2241
            "UF",
2242
            $std->UF,
2243
            true,
2244
            "UF de licenciamento do veículo"
2245
        );
2246
2247
        $this->dom->appChild($this->rodo, $veicReboque, 'Falta tag "rodo"');
2248
        return $this->rodo;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->rodo; of type string|DOMNode adds the type string to the return on line 2248 which is incompatible with the return type documented by NFePHP\MDFe\Make::tagveicReboque of type DOMElement.
Loading history...
2249
    }
2250
2251
    /**
2252
     * tagcodAgPorto
2253
     * tag MDFe/infMDFe/infModal/rodo/codAgPorto
2254
     *
2255
     * @param  stdClass $std
2256
     * @return DOMElement
2257
     */
2258
    public function tagcodAgPorto(stdClass $std)
2259
    {
2260
        $possible = [
2261
            'codAgPorto'
2262
        ];
2263
        $std = $this->equilizeParameters($std, $possible);
2264
        $this->dom->addChild(
2265
            $this->rodo,
2266
            "codAgPorto",
2267
            $std->codAgPorto,
2268
            false,
2269
            "Código de Agendamento no porto"
2270
        );
2271
        return $this->rodo;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->rodo; of type string|DOMNode adds the type string to the return on line 2271 which is incompatible with the return type documented by NFePHP\MDFe\Make::tagcodAgPorto of type DOMElement.
Loading history...
2272
    }
2273
2274
    /**
2275
     * taglacRodo
2276
     * tag MDFe/infMDFe/infModal/rodo/lacRodo
2277
     *
2278
     * @param  stdClass $std
2279
     * @return DOMElement
2280
     */
2281
    public function taglacRodo(stdClass $std)
2282
    {
2283
        $possible = [
2284
            'nLacre'
2285
        ];
2286
        $std = $this->equilizeParameters($std, $possible);
2287
        $lacRodo = $this->dom->createElement("lacRodo");
2288
        $this->dom->addChild(
2289
            $lacRodo,
2290
            "nLacre",
2291
            $std->nLacre,
2292
            false,
2293
            "Número do Lacre"
2294
        );
2295
        $this->dom->appChild($this->rodo, $lacRodo, 'Falta tag "rodo"');
2296
        return $this->rodo;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->rodo; of type string|DOMNode adds the type string to the return on line 2296 which is incompatible with the return type documented by NFePHP\MDFe\Make::taglacRodo of type DOMElement.
Loading history...
2297
    }
2298
2299
    /**
2300
     * buildMDFe
2301
     * Tag raiz da MDFe
2302
     * tag MDFe DOMNode
2303
     * Função chamada pelo método [ monta ]
2304
     *
2305
     * @return DOMElement
2306
     */
2307
    protected function buildMDFe()
2308
    {
2309
        if (empty($this->MDFe)) {
2310
            $this->MDFe = $this->dom->createElement("MDFe");
2311
            $this->MDFe->setAttribute("xmlns", "http://www.portalfiscal.inf.br/mdfe");
2312
        }
2313
        return $this->MDFe;
2314
    }
2315
2316
    /**
2317
     * buildTagIde
2318
     * Adiciona as tags
2319
     * infMunCarrega e infPercurso
2320
     * a tag ide
2321
     */
2322
    
2323
    protected function buildTagIde()
2324
    {
2325
        if (! empty($this->aInfMunCarrega)) {
2326
            $this->dom->addArrayChild($this->ide, $this->aInfMunCarrega);
2327
        }
2328
        if (! empty($this->aInfPercurso)) {
2329
            $this->dom->addArrayChild($this->ide, $this->aInfPercurso);
2330
        }
2331
    }
2332
    
2333
    /**
2334
     * checkMDFKey
2335
     * Remonta a chave do MDFe de 44 digitos com base em seus dados
2336
     * Isso é útil no caso da chave informada estar errada
2337
     * se a chave estiver errada a mesma é substituida
2338
     *
2339
     * @param object $dom
2340
     */
2341
    private function checkMDFKey($dom)
2342
    {
2343
        $infMDFe = $dom->getElementsByTagName("infMDFe")->item(0);
2344
        $ide = $dom->getElementsByTagName("ide")->item(0);
2345
        $emit = $dom->getElementsByTagName("emit")->item(0);
2346
        $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue;
2347
        $dhEmi = $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue;
2348
        if (!empty($emit->getElementsByTagName('CNPJ')->item(0)->nodeValue)) {
2349
            $doc = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
2350
        } else {
2351
            $doc = $emit->getElementsByTagName('CPF')->item(0)->nodeValue;
2352
        }
2353
        $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue;
2354
        $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
2355
        $nMDF = $ide->getElementsByTagName('nMDF')->item(0)->nodeValue;
2356
        $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue;
2357
        $cNF = $ide->getElementsByTagName('cMDF')->item(0)->nodeValue;
2358
        $chave = str_replace('MDFe', '', $infMDFe->getAttribute("Id"));
2359
        $dt = new DateTime($dhEmi);
2360
        $chaveMontada = Keys::build(
2361
            $cUF,
2362
            $dt->format('y'),
2363
            $dt->format('m'),
2364
            $doc,
2365
            $mod,
2366
            $serie,
2367
            $nMDF,
2368
            $tpEmis,
2369
            $cNF
2370
        );
2371
        //caso a chave contida na NFe esteja errada
2372
        //substituir a chave
2373
        if ($chaveMontada != $chave) {
2374
            $ide->getElementsByTagName('cDV')->item(0)->nodeValue = substr($chaveMontada, -1);
2375
            $infMDFe = $dom->getElementsByTagName("infMDFe")->item(0);
2376
            $infMDFe->setAttribute("Id", "MDFe" . $chaveMontada);
2377
            $infMDFe->setAttribute("versao", $this->versao);
2378
            $this->chMDFe = $chaveMontada;
2379
        }
2380
    }
2381
2382
    /**
2383
     * Includes missing or unsupported properties in stdClass
2384
     * Replace all unsuported chars
2385
     *
2386
     * @param  stdClass $std
2387
     * @param  array    $possible
2388
     * @return stdClass
2389
     */
2390
    protected function equilizeParameters(stdClass $std, $possible)
2391
    {
2392
        $arr = get_object_vars($std);
2393
        foreach ($possible as $key) {
2394
            if (!array_key_exists($key, $arr)) {
2395
                $std->$key = null;
2396
            } else {
2397
                if (is_string($std->$key)) {
2398
                    $std->$key = trim(Strings::replaceUnacceptableCharacters($std->$key));
2399
                    if ($this->replaceAccentedChars) {
2400
                        $std->$key = Strings::toASCII($std->$key);
2401
                    }
2402
                }
2403
            }
2404
        }
2405
        return $std;
2406
    }
2407
}
2408