Passed
Push — master ( 5a5376...939b2a )
by Roberto
02:35 queued 10s
created

Make::taginfMDFeTransp()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 44
ccs 0
cts 44
cp 0
rs 8.9048
c 0
b 0
f 0
cc 5
nc 4
nop 1
crap 30
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    Cleiton Perin <cperin20 at gmail dot com>
19
 * @author    Vanderlei Cavassin <cavassin.vanderlei at gmail dot com>
20
 */
21
22
use DOMElement;
23
use NFePHP\Common\DOMImproved as Dom;
24
use NFePHP\Common\Keys;
25
use NFePHP\Common\Strings;
26
use RuntimeException;
27
use stdClass;
28
29
class Make
30
{
31
    /**
32
     * @var array
33
     */
34
    public $errors = [];
35
    /**
36
     * versao
37
     * numero da versão do xml da MDFe
38
     *
39
     * @var string
40
     */
41
    public $versao = '3.00';
42
    /**
43
     * mod
44
     * modelo da MDFe 58
45
     *
46
     * @var integer
47
     */
48
    public $mod = '58';
49
    /**
50
     * chave da MDFe
51
     *
52
     * @var string
53
     */
54
    public $chMDFe = '';
55
56
    //propriedades privadas utilizadas internamente pela classe
57
    /**
58
     * @type string|\DOMNode
59
     */
60
    private $MDFe = '';
61
    /**
62
     * @type string|\DOMNode
63
     */
64
    private $infMDFe = '';
65
    /**
66
     * @type string|\DOMNode
67
     */
68
    private $ide = '';
69
    /**
70
     * @type string|\DOMNode
71
     */
72
    private $emit = '';
73
    /**
74
     * @type string|\DOMNode
75
     */
76
    private $infANTT = '';
77
    /**
78
     * @type string|\DOMNode
79
     */
80
    private $enderEmit = '';
81
    /**
82
     * @type string|\DOMNode
83
     */
84
    private $infModal = '';
85
    /**
86
     * @type string|\DOMNode
87
     */
88
    private $tot = '';
89
    /**
90
     * @type string|\DOMNode
91
     */
92
    private $seg = [];
93
    /**
94
     * @type string|\DOMNode
95
     */
96
    private $prodPred = null;
97
    /**
98
     * @type string|\DOMNode
99
     */
100
    private $infMunDescarga = [];
101
    /**
102
     * @type string|\DOMNode
103
     */
104
    private $veicReboque = [];
105
    /**
106
     * @type string|\DOMNode
107
     */
108
    private $infNFe = [];
109
    /**
110
     * @type string|\DOMNode
111
     */
112
    private $infCTe = [];
113
    /**
114
     * @type string|\DOMNode
115
     */
116
    private $infMDFeTransp = [];
117
    /**
118
     * @type string|\DOMNode
119
     */
120
    private $infContratante = [];
121
    /**
122
     * @type string|\DOMNode
123
     */
124
    private $infPag = [];
125
    /**
126
     * @type string|\DOMNode
127
     */
128
    private $infLotacao = null;
129
    /**
130
     * @type string|\DOMNode
131
     */
132
    private $autXML = [];
133
    /**
134
     * @type string|\DOMNode
135
     */
136
    private $infCIOT = [];
137
    /**
138
     * @type string|\DOMNode
139
     */
140
    private $disp = [];
141
    /**
142
     * @type string|\DOMNode
143
     */
144
    private $infMunCarrega = [];
145
    /**
146
     * @type string|\DOMNode
147
     */
148
    private $infPercurso = [];
149
    /**
150
     * @type string|\DOMNode
151
     */
152
    private $lacRodo = [];
153
    /**
154
     * @type string|\DOMNode
155
     */
156
    private $vag = [];
157
    /**
158
     * @type string|\DOMNode
159
     */
160
    private $infAdic = '';
161
    /**
162
     * @type string|\DOMNode
163
     */
164
    private $rodo = '';
165
    /**
166
     * @type string|\DOMNode
167
     */
168
    private $ferrov = '';
169
    /**
170
     * @type string|\DOMNode
171
     */
172
    private $infDoc = '';
173
    /**
174
     * @type string|\DOMNode
175
     */
176
    private $valePed = '';
177
    /**
178
     * @type string|\DOMNode
179
     */
180
    private $veicTracao = '';
181
    /**
182
     * @type string|\DOMNode
183
     */
184
    private $infUnidTransp = '';
185
    /**
186
     * @type string|\DOMNode
187
     */
188
    private $aereo = '';
189
    /**
190
     * @type string|\DOMNode
191
     */
192
    private $trem = '';
193
    /**
194
     * @type string|\DOMNode
195
     */
196
    private $aquav = '';
197
    /**
198
     * @type array
199
     */
200
    private $infTermCarreg = [];
201
    /**
202
     * @type array
203
     */
204
    private $infTermDescarreg = [];
205
    /**
206
     * @type array
207
     */
208
    private $infEmbComb = [];
209
    /**
210
     * @type array
211
     */
212
    private $infUnidCargaVazia = [];
213
    /**
214
     * @type array
215
     */
216
    private $infUnidTranspVazia = [];
217
    /**
218
     * @var boolean
219
     */
220
    protected $replaceAccentedChars = false;
221
222
    /**
223
     * Função construtora cria um objeto DOMDocument
224
     * que será carregado com o documento fiscal
225
     */
226
    public function __construct()
227
    {
228
        $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...
229
        $this->dom->preserveWhiteSpace = false;
230
        $this->dom->formatOutput = false;
231
    }
232
233
    /**
234
     * Retorns the xml
235
     *
236
     * @return xml
237
     */
238
    public function getXML()
239
    {
240
        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...
241
            $this->montaMDFe();
242
        }
243
        return $this->xml;
244
    }
245
246
    /**
247
     * Retorns the key number of NFe (44 digits)
248
     *
249
     * @return string
250
     */
251
    public function getChave()
252
    {
253
        return $this->chMDFe;
254
    }
255
256
    /**
257
     * Returns the model of MDFe
258
     *
259
     * @return int
260
     */
261
    public function getModelo()
262
    {
263
        return $this->mod;
264
    }
265
266
    /**
267
     * Set character convertion to ASCII only ou not
268
     * @param bool $option
269
     */
270
    public function setOnlyAscii($option = false)
271
    {
272
        $this->replaceAccentedChars = $option;
273
    }
274
275
    /**
276
     * Call method of xml assembly. For compatibility only.
277
     *
278
     * @return boolean
279
     */
280
    public function montaMDFe()
281
    {
282
        return $this->monta();
283
    }
284
285
    /**
286
     * @param $indDoc
287
     * @return int|void
288
     */
289
    private function contaDoc($indDoc)
290
    {
291
        $total = 0;
292
        foreach ($indDoc as $doc) {
293
            $total += count($doc);
294
        }
295
        return $total;
296
    }
297
298
    /**
299
     * MDFe xml mount method
300
     * this function returns TRUE on success or FALSE on error
301
     * The xml of the MDFe must be retrieved by the getXML() function or
302
     * directly by the public property $xml
303
     *
304
     * @return boolean
305
     */
306
    public function monta()
307
    {
308
        $this->errors = $this->dom->errors;
309
        //cria a tag raiz da MDFe
310
        $this->buildMDFe();
311
        $this->buildInfModal();
312
        $this->infMDFe = $this->dom->createElement("infMDFe");
313
        $this->buildIde();
314
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "enderEmit"');
315
        $this->dom->appChild($this->infMDFe, $this->emit, 'Falta tag "emit"');
316
        if ($this->rodo) {
317
            $tpEmit = $this->ide->getElementsByTagName('tpEmit')->item(0)->nodeValue;
318
            if (($tpEmit == 1 || $tpEmit == 3) && empty($this->prodPred)) {
319
                $this->errors[] = "Tag prodPred é obrigatória para modal rodoviário!";
320
            }
321
            if (($tpEmit == 1 || $tpEmit == 3) && empty($this->infLotacao)
322
                && ($this->contaDoc($this->infCTe)
323
                    + $this->contaDoc($this->infNFe)
324
                    + $this->contaDoc($this->infMDFeTransp)) == 1
325
            ) {
326
                $this->errors[] = "Tag infLotacao é obrigatória quando só "
327
                    . "existir um Documento informado!";
328
            }
329
            if ($this->infANTT) {
330
                if ($this->infCIOT) {
331
                    $this->dom->addArrayChild(
332
                        $this->infANTT,
333
                        $this->infCIOT,
334
                        'Falta tag "infCIOT"'
335
                    );
336
                }
337
                if ($this->valePed) {
338
                    $this->dom->appChild($this->infANTT, $this->valePed, 'Falta tag "valePed"');
339
                    if ($this->disp) {
340
                        $this->dom->addArrayChild($this->valePed, $this->disp, 'Falta tag "disp"');
341
                    }
342
                }
343
                if ($this->infContratante) {
344
                    $this->dom->addArrayChild(
345
                        $this->infANTT,
346
                        $this->infContratante,
347
                        'Falta tag "infContratante"'
348
                    );
349
                }
350
                if ($this->infPag) {
351
                    $this->dom->addArrayChild($this->infANTT, $this->infPag, 'Falta tag "infpag"');
352
                }
353
                $this->dom->appChild($this->rodo, $this->infANTT, 'Falta tag "infANTT"');
354
            }
355
            if ($this->veicTracao) {
356
                $this->dom->appChild($this->rodo, $this->veicTracao, 'Falta tag "rodo"');
357
            }
358
            if ($this->veicReboque) {
359
                $this->dom->addArrayChild($this->rodo, $this->veicReboque, 'Falta tag "veicReboque"');
360
            }
361
            if ($this->lacRodo) {
362
                $this->dom->addArrayChild($this->rodo, $this->lacRodo, 'Falta tag "lacRodo"');
363
            }
364
            $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "infModal"');
365
        }
366
        if ($this->aereo) {
367
            $this->dom->appChild($this->infModal, $this->aereo, 'Falta tag "aereo"');
368
        }
369
        if ($this->ferrov) {
370
            if ($this->trem) {
371
                $this->dom->appChild($this->ferrov, $this->trem, 'Falta tag "ferrov"');
372
            }
373
            if ($this->vag) {
374
                $this->dom->addArrayChild($this->ferrov, $this->vag, 'Falta tag "vag"');
375
            }
376
            $this->dom->appChild($this->infModal, $this->ferrov, 'Falta tag "ferrov"');
377
        }
378
        if ($this->aquav) {
379
            foreach ($this->infTermCarreg as $termCarreg) {
380
                $this->dom->appChild($this->aquav, $termCarreg, 'Falta tag "aquav"');
381
            }
382
            foreach ($this->infTermDescarreg as $termDescarreg) {
383
                $this->dom->appChild($this->aquav, $termDescarreg, 'Falta tag "aquav"');
384
            }
385
            foreach ($this->infEmbComb as $embComb) {
386
                $this->dom->appChild($this->aquav, $embComb, 'Falta tag "aquav"');
387
            }
388
            foreach ($this->infUnidCargaVazia as $unidCargaVazia) {
389
                $this->dom->appChild($this->aquav, $unidCargaVazia, 'Falta tag "aquav"');
390
            }
391
            foreach ($this->infUnidTranspVazia as $unidTranspVazia) {
392
                $this->dom->appChild($this->aquav, $unidTranspVazia, 'Falta tag "aquav"');
393
            }
394
            $this->dom->appChild($this->infModal, $this->aquav, 'Falta tag "aquav"');
395
        }
396
        $this->dom->appChild($this->infMDFe, $this->infModal, 'Falta tag "infModal"');
397
        if ($this->infDoc) {
398
            $this->dom->appChild($this->infMDFe, $this->infDoc, 'Falta tag "infDoc"');
399
            if ($this->infMunDescarga) {
400
                foreach ($this->infMunDescarga as $key => $value) {
0 ignored issues
show
Bug introduced by
The expression $this->infMunDescarga 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...
401
                    $this->dom->appChild($this->infDoc, $value, 'Falta tag "infMunDescarga"');
402
                    if (isset($this->infCTe[$key])) {
403
                        $this->dom->addArrayChild($value, $this->infCTe[$key], 'Falta tag "infCTe"');
404
                    }
405
                    if (isset($this->infNFe[$key])) {
406
                        $this->dom->addArrayChild(
407
                            $value,
408
                            $this->infNFe[$key],
409
                            'Falta tag "infNFe"'
410
                        );
411
                    }
412
                    if (isset($this->infMDFeTransp[$key])) {
413
                        $this->dom->addArrayChild(
414
                            $value,
415
                            $this->infMDFeTransp[$key],
416
                            'Falta tag "infMDFeTransp"'
417
                        );
418
                    }
419
                }
420
            }
421
        }
422
        if (!empty($this->seg)) {
423
            $this->dom->addArrayChild($this->infMDFe, $this->seg, 'Falta tag "seg"');
424
        }
425
        if (!empty($this->prodPred)) {
426
            $this->dom->appChild($this->infMDFe, $this->prodPred, 'Falta tag "prodPred"');
427
        }
428
        $this->dom->appChild($this->infMDFe, $this->tot, 'Falta tag "tot"');
429
        if (!empty($this->lacres)) {
430
            foreach ($this->lacres as $lacres) {
0 ignored issues
show
Bug introduced by
The property lacres 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...
431
                $this->dom->appChild($this->infMDFe, $lacres, 'Falta tag "lacres"');
432
            }
433
        }
434
        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...
435
            $this->dom->appChild($this->infMDFe, $autXML, 'Falta tag "infMDFe"');
436
        }
437
        if (!empty($this->infAdic)) {
438
            $this->dom->appChild($this->infMDFe, $this->infAdic, 'Falta tag "infAdic"');
439
        }
440
        $this->dom->appChild($this->MDFe, $this->infMDFe, 'Falta tag "infMDFe"');
441
        $this->dom->appendChild($this->MDFe);
442
        // testa da chave
443
        $this->checkMDFKey($this->dom);
444
        $this->xml = $this->dom->saveXML();
445
        if (count($this->errors) > 0) {
446
            throw new RuntimeException('Existem erros nas tags. Obtenha os erros com getErrors().');
447
        }
448
        return true;
449
    }
450
451
    /**
452
     * Informações de identificação da MDFe
453
     * tag MDFe/infMDFe/ide
454
     *
455
     * @param  stdClass $std
456
     * @return DOMElement
457
     */
458
    public function tagide(stdClass $std)
459
    {
460
        $possible = [
461
            'cUF',
462
            'tpAmb',
463
            'tpEmit',
464
            'tpTransp',
465
            'mod',
466
            'serie',
467
            'nMDF',
468
            'cMDF',
469
            'cDV',
470
            'modal',
471
            'dhEmi',
472
            'tpEmis',
473
            'procEmi',
474
            'verProc',
475
            'UFIni',
476
            'UFFim',
477
            'dhIniViagem',
478
            'indCanalVerde',
479
            'indCarregaPosterior'
480
        ];
481
        $std = $this->equilizeParameters($std, $possible);
482
        $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...
483
        $identificador = '[4] <ide> - ';
484
        $ide = $this->dom->createElement("ide");
485
        $this->dom->addChild(
486
            $ide,
487
            "cUF",
488
            $std->cUF,
489
            true,
490
            $identificador . "Código da UF do emitente do Documento Fiscal"
491
        );
492
        $this->dom->addChild(
493
            $ide,
494
            "tpAmb",
495
            $std->tpAmb,
496
            true,
497
            $identificador . "Identificação do Ambiente"
498
        );
499
        $this->dom->addChild(
500
            $ide,
501
            "tpEmit",
502
            $std->tpEmit,
503
            true,
504
            $identificador . "Indicador da tipo de emitente"
505
        );
506
        $this->dom->addChild(
507
            $ide,
508
            "tpTransp",
509
            $std->tpTransp,
510
            false,
511
            $identificador . "Tipo do Transportador"
512
        );
513
        $this->dom->addChild(
514
            $ide,
515
            "mod",
516
            $std->mod,
517
            true,
518
            $identificador . "Código do Modelo do Documento Fiscal"
519
        );
520
        $this->dom->addChild(
521
            $ide,
522
            "serie",
523
            $std->serie,
524
            true,
525
            $identificador . "Série do Documento Fiscal"
526
        );
527
        $this->dom->addChild(
528
            $ide,
529
            "nMDF",
530
            $std->nMDF,
531
            true,
532
            $identificador . "Número do Documento Fiscal"
533
        );
534
        $this->dom->addChild(
535
            $ide,
536
            "cMDF",
537
            str_pad($std->cMDF, 8, '0', STR_PAD_LEFT),
538
            true,
539
            $identificador . "Código do numérico do MDF"
540
        );
541
        $this->dom->addChild(
542
            $ide,
543
            "cDV",
544
            $std->cDV,
545
            true,
546
            $identificador . "Dígito Verificador da Chave de Acesso da NF-e"
547
        );
548
        $this->dom->addChild(
549
            $ide,
550
            "modal",
551
            $std->modal,
552
            true,
553
            $identificador . "Modalidade de transporte"
554
        );
555
        $this->dom->addChild(
556
            $ide,
557
            "dhEmi",
558
            $std->dhEmi,
559
            true,
560
            $identificador . "Data e hora de emissão do Documento Fiscal"
561
        );
562
        $this->dom->addChild(
563
            $ide,
564
            "tpEmis",
565
            $std->tpEmis,
566
            true,
567
            $identificador . "Tipo de Emissão do Documento Fiscal"
568
        );
569
        $this->dom->addChild(
570
            $ide,
571
            "procEmi",
572
            $std->procEmi,
573
            true,
574
            $identificador . "Processo de emissão"
575
        );
576
        $this->dom->addChild(
577
            $ide,
578
            "verProc",
579
            $std->verProc,
580
            true,
581
            $identificador . "Versão do Processo de emissão"
582
        );
583
        $this->dom->addChild(
584
            $ide,
585
            "UFIni",
586
            $std->UFIni,
587
            true,
588
            $identificador . "Sigla da UF do Carregamento"
589
        );
590
        $this->dom->addChild(
591
            $ide,
592
            "UFFim",
593
            $std->UFFim,
594
            true,
595
            $identificador . "Sigla da UF do Descarregamento"
596
        );
597
        $this->dom->addChild(
598
            $ide,
599
            "dhIniViagem",
600
            $std->dhIniViagem,
601
            false,
602
            $identificador . "Data e hora previstos de início da viagem"
603
        );
604
        $this->dom->addChild(
605
            $ide,
606
            "indCanalVerde",
607
            $std->indCanalVerde,
608
            false,
609
            $identificador . "Indicador de participação do Canal Verde"
610
        );
611
        $this->dom->addChild(
612
            $ide,
613
            "indCarregaPosterior",
614
            $std->indCarregaPosterior,
615
            false,
616
            $identificador . "Indicador de MDF-e com inclusão da Carga posterior"
617
            . " a emissão por evento de inclusão de DF-e"
618
        );
619
620
        $this->mod = $std->mod;
621
        $this->ide = $ide;
622
        return $ide;
623
    }
624
625
    /**
626
     * taginfMunCarrega
627
     *
628
     * tag MDFe/infMDFe/ide/infMunCarrega
629
     *
630
     * @param  stdClass $std
631
     * @return DOMElement
632
     */
633
    public function taginfMunCarrega(stdClass $std)
634
    {
635
        $possible = [
636
            'cMunCarrega',
637
            'xMunCarrega'
638
        ];
639
        $std = $this->equilizeParameters($std, $possible);
640
        $infMunCarrega = $this->dom->createElement("infMunCarrega");
641
        $this->dom->addChild(
642
            $infMunCarrega,
643
            "cMunCarrega",
644
            $std->cMunCarrega,
645
            true,
646
            "Código do Município de Carregamento"
647
        );
648
        $this->dom->addChild(
649
            $infMunCarrega,
650
            "xMunCarrega",
651
            $std->xMunCarrega,
652
            true,
653
            "Nome do Município de Carregamento"
654
        );
655
        $this->infMunCarrega[] = $infMunCarrega;
656
        return $infMunCarrega;
657
    }
658
659
    /**
660
     * tagInfPercurso
661
     *
662
     * tag MDFe/infMDFe/ide/infPercurso
663
     *
664
     * @param  stdClass $std
665
     * @return DOMElement
666
     */
667
    public function taginfPercurso(stdClass $std)
668
    {
669
        $possible = [
670
            'UFPer'
671
        ];
672
        $std = $this->equilizeParameters($std, $possible);
673
        $infPercurso = $this->dom->createElement("infPercurso");
674
        $this->dom->addChild(
675
            $infPercurso,
676
            "UFPer",
677
            $std->UFPer,
678
            true,
679
            "Sigla das Unidades da Federação do percurso"
680
        );
681
        $this->infPercurso[] = $infPercurso;
682
        return $infPercurso;
683
    }
684
685
    /**
686
     * tagemit
687
     * Identificação do emitente da MDFe
688
     * tag MDFe/infMDFe/emit
689
     *
690
     * @param  stdClass $std
691
     * @return DOMElement
692
     */
693
    public function tagemit(stdClass $std)
694
    {
695
        $possible = [
696
            'CNPJ',
697
            'CPF',
698
            'IE',
699
            'xNome',
700
            'xFant'
701
        ];
702
        $std = $this->equilizeParameters($std, $possible);
703
        $identificador = '[25] <emit> - ';
704
        $this->emit = $this->dom->createElement("emit");
705
        if ($std->CPF) {
706
            $this->dom->addChild(
707
                $this->emit,
708
                "CPF",
709
                $std->CPF,
710
                true,
711
                $identificador . "CPF do emitente"
712
            );
713
        } else {
714
            $this->dom->addChild(
715
                $this->emit,
716
                "CNPJ",
717
                $std->CNPJ,
718
                true,
719
                $identificador . "CNPJ do emitente"
720
            );
721
        }
722
        $this->dom->addChild(
723
            $this->emit,
724
            "IE",
725
            $std->IE,
726
            false,
727
            $identificador . "Inscrição Estadual do emitente"
728
        );
729
        $this->dom->addChild(
730
            $this->emit,
731
            "xNome",
732
            $std->xNome,
733
            true,
734
            $identificador . "Razão Social ou Nome do emitente"
735
        );
736
        $this->dom->addChild(
737
            $this->emit,
738
            "xFant",
739
            $std->xFant,
740
            false,
741
            $identificador . "Nome fantasia do emitente"
742
        );
743
        return $this->emit;
744
    }
745
746
    /**
747
     * tagenderEmit
748
     * Endereço do emitente [30] pai [25]
749
     * tag MDFe/infMDFe/emit/endEmit
750
     *
751
     * @param  stdClass $std
752
     * @return DOMElement
753
     */
754
    public function tagenderEmit(stdClass $std)
755
    {
756
        $possible = [
757
            'xLgr',
758
            'nro',
759
            'xCpl',
760
            'xBairro',
761
            'cMun',
762
            'xMun',
763
            'CEP',
764
            'UF',
765
            'fone',
766
            'email'
767
        ];
768
        $std = $this->equilizeParameters($std, $possible);
769
        $identificador = '[30] <enderEmit> - ';
770
        $this->enderEmit = $this->dom->createElement("enderEmit");
771
        $this->dom->addChild(
772
            $this->enderEmit,
773
            "xLgr",
774
            $std->xLgr,
775
            true,
776
            $identificador . "Logradouro do Endereço do emitente"
777
        );
778
        $this->dom->addChild(
779
            $this->enderEmit,
780
            "nro",
781
            $std->nro,
782
            true,
783
            $identificador . "Número do Endereço do emitente"
784
        );
785
        $this->dom->addChild(
786
            $this->enderEmit,
787
            "xCpl",
788
            $std->xCpl,
789
            false,
790
            $identificador . "Complemento do Endereço do emitente"
791
        );
792
        $this->dom->addChild(
793
            $this->enderEmit,
794
            "xBairro",
795
            $std->xBairro,
796
            true,
797
            $identificador . "Bairro do Endereço do emitente"
798
        );
799
        $this->dom->addChild(
800
            $this->enderEmit,
801
            "cMun",
802
            $std->cMun,
803
            true,
804
            $identificador . "Código do município do Endereço do emitente"
805
        );
806
        $this->dom->addChild(
807
            $this->enderEmit,
808
            "xMun",
809
            $std->xMun,
810
            true,
811
            $identificador . "Nome do município do Endereço do emitente"
812
        );
813
        $this->dom->addChild(
814
            $this->enderEmit,
815
            "CEP",
816
            $std->CEP,
817
            true,
818
            $identificador . "Código do CEP do Endereço do emitente"
819
        );
820
        $this->dom->addChild(
821
            $this->enderEmit,
822
            "UF",
823
            $std->UF,
824
            true,
825
            $identificador . "Sigla da UF do Endereço do emitente"
826
        );
827
        $this->dom->addChild(
828
            $this->enderEmit,
829
            "fone",
830
            $std->fone,
831
            false,
832
            $identificador . "Número de telefone do emitente"
833
        );
834
        $this->dom->addChild(
835
            $this->enderEmit,
836
            "email",
837
            $std->email,
838
            false,
839
            $identificador . "Endereço de email do emitente"
840
        );
841
        return $this->enderEmit;
842
    }
843
844
    /**
845
     * tagrodo
846
     * tag MDFe/infMDFe/infModal/rodo
847
     *
848
     * @return DOMElement
849
     */
850
    private function tagrodo()
851
    {
852
        $this->rodo = $this->dom->createElement("rodo");
853
        return $this->rodo;
854
    }
855
856
    /**
857
     * tagferrov
858
     * tag MDFe/infMDFe/infModal/ferrov
859
     *
860
     * @return DOMElement
861
     */
862
    private function tagferrov()
863
    {
864
        if (empty($this->ferrov)) {
865
            $this->ferrov = $this->dom->createElement("ferrov");
866
        }
867
        return $this->ferrov;
868
    }
869
870
    /**
871
     * tagrodo
872
     * tag MDFe/infMDFe/infModal/rodo
873
     *
874
     * @return DOMElement
875
     */
876
    private function taginfDoc()
877
    {
878
        if (empty($this->infDoc)) {
879
            $this->infDoc = $this->dom->createElement("infDoc");
880
        }
881
        return $this->infDoc;
882
    }
883
884
    /**
885
     * valePed
886
     * tag MDFe/infMDFe/infModal/rodo/infANTT/valePed
887
     *
888
     * @return DOMElement
889
     */
890
    private function tagvalePed()
891
    {
892
        if (empty($this->valePed)) {
893
            $this->valePed = $this->dom->createElement("valePed");
894
        }
895
        return $this->valePed;
896
    }
897
898
    /**
899
     * infANTT
900
     * tag MDFe/infMDFe/infModal/rodo/infANTT
901
     *
902
     * @return DOMElement
903
     */
904
    public function taginfANTT(stdClass $std)
905
    {
906
        $possible = [
907
            'RNTRC'
908
        ];
909
        $std = $this->equilizeParameters($std, $possible);
910
        $identificador = '[2] <infANTT> - ';
911
        $infANTT = $this->dom->createElement("infANTT");
912
        $this->dom->addChild(
913
            $infANTT,
914
            "RNTRC",
915
            $std->RNTRC,
916
            false,
917
            $identificador . "Registro Nacional de Transportadores Rodoviários"
918
            . " de Carga"
919
        );
920
        $this->infANTT = $infANTT;
921
        return $infANTT;
922
    }
923
924
    /**
925
     * disp
926
     * tag MDFe/infMDFe/infModal/rodo/infANTT/disp
927
     *
928
     * @return DOMElement
929
     */
930
    public function tagdisp(stdClass $std)
931
    {
932
        $possible = [
933
            'CNPJForn',
934
            'CNPJPg',
935
            'CPFPg',
936
            'nCompra',
937
            'vValePed'
938
        ];
939
        $this->tagvalePed();
940
        $std = $this->equilizeParameters($std, $possible);
941
        $identificador = '[4] <disp> - ';
942
        $disp = $this->dom->createElement("disp");
943
        $this->dom->addChild(
944
            $disp,
945
            "CNPJForn",
946
            $std->CNPJForn,
947
            false,
948
            $identificador . "CNPJ da empresa fornecedora do ValePedágio"
949
        );
950
        $this->dom->addChild(
951
            $disp,
952
            "CNPJPg",
953
            $std->CNPJPg,
954
            false,
955
            $identificador . "CNPJ do responsável pelo pagamento do Vale-Pedágio"
956
        );
957
        $this->dom->addChild(
958
            $disp,
959
            "CPFPg",
960
            $std->CPFPg,
961
            false,
962
            $identificador . "CPF do responsável pelo pagamento do Vale-Pedágio"
963
        );
964
        $this->dom->addChild(
965
            $disp,
966
            "nCompra",
967
            $std->nCompra,
968
            false,
969
            $identificador . "Número do comprovante de compra"
970
        );
971
        $this->dom->addChild(
972
            $disp,
973
            "vValePed",
974
            $this->conditionalNumberFormatting($std->vValePed),
975
            false,
976
            $identificador . "Valor do Vale-Pedagio"
977
        );
978
        $this->disp[] = $disp;
979
        return $disp;
980
    }
981
982
    /**
983
     * infContratante
984
     * tag MDFe/infMDFe/infModal/rodo/infANTT/infContratante
985
     *
986
     * @return DOMElement
987
     */
988
    public function taginfContratante(stdClass $std)
989
    {
990
        $possible = [
991
            'xNome',
992
            'CPF',
993
            'CPF',
994
            'idEstrangeiro'
995
        ];
996
        $std = $this->equilizeParameters($std, $possible);
997
        $identificador = '[4] <infContratante> - ';
998
        $infContratante = $this->dom->createElement("infContratante");
999
1000
        $this->dom->addChild(
1001
            $infContratante,
1002
            "xNome",
1003
            $std->xNome,
1004
            false,
1005
            $identificador . "Nome do contratante do serviço"
1006
        );
1007
        if ($std->CPF) {
1008
            $this->dom->addChild(
1009
                $infContratante,
1010
                "CPF",
1011
                $std->CPF,
1012
                true,
1013
                $identificador . "Número do CPF do contratante do serviço"
1014
            );
1015
        } elseif ($std->CNPJ) {
1016
            $this->dom->addChild(
1017
                $infContratante,
1018
                "CNPJ",
1019
                $std->CNPJ,
1020
                true,
1021
                $identificador . "Número do CNPJ do contratante do serviço"
1022
            );
1023
        } else {
1024
            $this->dom->addChild(
1025
                $infContratante,
1026
                "idEstrangeiro",
1027
                $std->idEstrangeiro,
1028
                true,
1029
                $identificador . "Identificador do contratante do serviço em "
1030
                . "caso de ser estrangeiro"
1031
            );
1032
        }
1033
        $this->infContratante[] = $infContratante;
1034
        return $infContratante;
1035
    }
1036
1037
    /**
1038
     * infANTT
1039
     * tag MDFe/infMDFe/infModal/rodo/infANTT/infCIOT
1040
     *
1041
     * @return DOMElement
1042
     */
1043
    public function taginfCIOT(stdClass $std)
1044
    {
1045
        $possible = [
1046
            'CIOT',
1047
            'CPF',
1048
            'CNPJ'
1049
        ];
1050
        $std = $this->equilizeParameters($std, $possible);
1051
        $identificador = '[4] <infCIOT> - ';
1052
        $infCIOT = $this->dom->createElement("infCIOT");
1053
        $this->dom->addChild(
1054
            $infCIOT,
1055
            "CIOT",
1056
            $std->CIOT,
1057
            true,
1058
            $identificador . "Código Identificador da Operação de Transporte"
1059
        );
1060
        if ($std->CPF) {
1061
            $this->dom->addChild(
1062
                $infCIOT,
1063
                "CPF",
1064
                $std->CPF,
1065
                true,
1066
                $identificador . "Número do CPF responsável pela geração do CIOT"
1067
            );
1068
        } else {
1069
            $this->dom->addChild(
1070
                $infCIOT,
1071
                "CNPJ",
1072
                $std->CNPJ,
1073
                true,
1074
                $identificador . "Número do CNPJ responsável pela geração do CIOT"
1075
            );
1076
        }
1077
        $this->infCIOT[] = $infCIOT;
1078
        return $infCIOT;
1079
    }
1080
1081
    /**
1082
     * tagInfMunDescarga
1083
     * tag MDFe/infMDFe/infDoc/infMunDescarga
1084
     *
1085
     * @param  stdClass $std
1086
     * @return DOMElement
1087
     */
1088
    public function taginfMunDescarga(stdClass $std)
1089
    {
1090
        $possible = [
1091
            'cMunDescarga',
1092
            'xMunDescarga',
1093
            'nItem'
1094
        ];
1095
        $this->taginfDoc();
1096
        $std = $this->equilizeParameters($std, $possible);
1097
        $identificador = '[4] <infMunDescarga> - ';
1098
        $infMunDescarga = $this->dom->createElement("infMunDescarga");
1099
        $this->dom->addChild(
1100
            $infMunDescarga,
1101
            "cMunDescarga",
1102
            $std->cMunDescarga,
1103
            true,
1104
            $identificador . "Código do Município de Descarga"
1105
        );
1106
        $this->dom->addChild(
1107
            $infMunDescarga,
1108
            "xMunDescarga",
1109
            $std->xMunDescarga,
1110
            true,
1111
            $identificador . "Nome do Município de Descarga"
1112
        );
1113
        $this->infMunDescarga[$std->nItem] = $infMunDescarga;
1114
        return $infMunDescarga;
1115
    }
1116
1117
    /**
1118
     * taginfCTe
1119
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infCTe
1120
     *
1121
     * @param  stdClass $std
1122
     * @return DOMElement
1123
     */
1124
    public function taginfCTe(stdClass $std)
1125
    {
1126
        $possible = [
1127
            'chCTe',
1128
            'SegCodBarra',
1129
            'indReentrega',
1130
            'infEntregaParcial',
1131
            'infUnidTransp',
1132
            'peri',
1133
            'nItem'
1134
        ];
1135
        $std = $this->equilizeParameters($std, $possible);
1136
        $infCTe = $this->dom->createElement("infCTe");
1137
        $identificador = '[4] <infCTe> - ';
1138
        $this->dom->addChild(
1139
            $infCTe,
1140
            "chCTe",
1141
            $std->chCTe,
1142
            true,
1143
            $identificador . "Chave de Acesso CTe"
1144
        );
1145
        $this->dom->addChild(
1146
            $infCTe,
1147
            "SegCodBarra",
1148
            $std->SegCodBarra,
1149
            false,
1150
            $identificador . "Segundo código de barras do CTe"
1151
        );
1152
        $this->dom->addChild(
1153
            $infCTe,
1154
            "indReentrega",
1155
            $std->indReentrega,
1156
            false,
1157
            $identificador . "Indicador de Reentrega"
1158
        );
1159
        if ($std->infUnidTransp) {
1160
            foreach ($std->infUnidTransp as $value) {
1161
                $this->dom->appChild(
1162
                    $infCTe,
1163
                    $this->taginfUnidTransp($value),
1164
                    'Falta tag "infUnidTransp"'
1165
                );
1166
            }
1167
        }
1168
        if ($std->peri) {
1169
            foreach ($std->peri as $value) {
1170
                $this->dom->appChild(
1171
                    $infCTe,
1172
                    $this->tagperi($value),
1173
                    'Falta tag "peri"'
1174
                );
1175
            }
1176
        }
1177
        if ($std->infEntregaParcial != null) {
1178
            $possible = [
1179
                'qtdTotal',
1180
                'qtdParcial'
1181
            ];
1182
            $stdinfEntregaParcial = $this->equilizeParameters(
1183
                $std->infEntregaParcial,
1184
                $possible
1185
            );
1186
            $identificadorparcial = '[4] <infEntregaParcial> - ';
1187
            $infEntregaParcial = $this->dom->createElement("infEntregaParcial");
1188
            $this->dom->addChild(
1189
                $infEntregaParcial,
1190
                "qtdTotal",
1191
                $this->conditionalNumberFormatting($stdinfEntregaParcial->qtdTotal, 4),
1192
                true,
1193
                $identificadorparcial . "Quantidade total de volumes"
1194
            );
1195
            $this->dom->addChild(
1196
                $infEntregaParcial,
1197
                "qtdParcial",
1198
                $this->conditionalNumberFormatting($stdinfEntregaParcial->qtdParcial, 4),
1199
                true,
1200
                $identificadorparcial . "Quantidade de volumes enviados no MDF-e"
1201
            );
1202
            $this->dom->appChild($infCTe, $infEntregaParcial, 'Falta tag "infCTe"');
1203
        }
1204
        $this->infCTe[$std->nItem][] = $infCTe;
1205
        return $infCTe;
1206
    }
1207
1208
    /**
1209
     * tagperi
1210
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/peri
1211
     *
1212
     * @param  stdClass $std
1213
     * @return DOMElement
1214
     */
1215
    private function tagperi(stdClass $std)
1216
    {
1217
        $possible = [
1218
            'nONU',
1219
            'xNomeAE',
1220
            'xClaRisco',
1221
            'grEmb',
1222
            'qTotProd',
1223
            'qVolTipo'
1224
        ];
1225
        $std = $this->equilizeParameters($std, $possible);
1226
        $peri = $this->dom->createElement("peri");
1227
        $this->dom->addChild(
1228
            $peri,
1229
            "nONU",
1230
            $std->nONU,
1231
            true,
1232
            "Número ONU/UN"
1233
        );
1234
        $this->dom->addChild(
1235
            $peri,
1236
            "xNomeAE",
1237
            $std->xNomeAE,
1238
            true,
1239
            "Nome apropriado para embarque do produto"
1240
        );
1241
        $this->dom->addChild(
1242
            $peri,
1243
            "xClaRisco",
1244
            $std->xClaRisco,
1245
            true,
1246
            "Classe ou subclasse/divisão, e risco subsidiário/risco secundário"
1247
        );
1248
        $this->dom->addChild(
1249
            $peri,
1250
            "grEmb",
1251
            $std->grEmb,
1252
            true,
1253
            "Grupo de Embalagem"
1254
        );
1255
        $this->dom->addChild(
1256
            $peri,
1257
            "qTotProd",
1258
            $std->qTotProd,
1259
            true,
1260
            "Quantidade total por produto"
1261
        );
1262
        $this->dom->addChild(
1263
            $peri,
1264
            "qVolTipo",
1265
            $std->qVolTipo,
1266
            true,
1267
            "Quantidade e Tipo de volumes"
1268
        );
1269
        return $peri;
1270
    }
1271
1272
    /**
1273
     * taginfNFe
1274
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infNFe
1275
     *
1276
     * @param  stdClass $std
1277
     * @return DOMElement
1278
     */
1279
    public function taginfNFe(stdClass $std)
1280
    {
1281
        $possible = [
1282
            'chNFe',
1283
            'SegCodBarra',
1284
            'indReentrega',
1285
            'infUnidTransp',
1286
            'peri',
1287
            'nItem'
1288
        ];
1289
        $std = $this->equilizeParameters($std, $possible);
1290
        $infNFe = $this->dom->createElement("infNFe");
1291
        $this->dom->addChild(
1292
            $infNFe,
1293
            "chNFe",
1294
            $std->chNFe,
1295
            true,
1296
            "Chave de Acesso NFe"
1297
        );
1298
        $this->dom->addChild(
1299
            $infNFe,
1300
            "SegCodBarra",
1301
            $std->SegCodBarra,
1302
            false,
1303
            "Segundo código de barras do NFe"
1304
        );
1305
        $this->dom->addChild(
1306
            $infNFe,
1307
            "indReentrega",
1308
            $std->indReentrega,
1309
            false,
1310
            "Indicador de Reentrega"
1311
        );
1312
        if ($std->infUnidTransp) {
1313
            foreach ($std->infUnidTransp as $value) {
1314
                $this->dom->appChild(
1315
                    $infNFe,
1316
                    $this->taginfUnidTransp($value),
1317
                    'Falta tag "infUnidTransp"'
1318
                );
1319
            }
1320
        }
1321
        if ($std->peri) {
1322
            foreach ($std->peri as $value) {
1323
                $this->dom->appChild($infNFe, $this->tagperi($value), 'Falta tag "peri"');
1324
            }
1325
        }
1326
        $this->infNFe[$std->nItem][] = $infNFe;
1327
        return $infNFe;
1328
    }
1329
1330
    /**
1331
     * taginfMDFeTransp
1332
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infMDFeTransp
1333
     *
1334
     * @param  stdClass $std
1335
     * @return DOMElement
1336
     */
1337
    public function taginfMDFeTransp(stdClass $std)
1338
    {
1339
        $possible = [
1340
            'chMDFe',
1341
            'indReentrega',
1342
            'nItem'
1343
        ];
1344
        $std = $this->equilizeParameters($std, $possible);
1345
        $infMDFeTransp = $this->dom->createElement("infMDFeTransp");
1346
        $this->dom->addChild(
1347
            $infMDFeTransp,
1348
            "chMDFe",
1349
            $std->chMDFe,
1350
            true,
1351
            "Chave de Acesso NFe"
1352
        );
1353
        $this->dom->addChild(
1354
            $infMDFeTransp,
1355
            "indReentrega",
1356
            $std->indReentrega,
1357
            false,
1358
            "Indicador de Reentrega"
1359
        );
1360
        if ($std->infUnidTransp) {
1361
            foreach ($std->infUnidTransp as $value) {
1362
                $this->dom->appChild(
1363
                    $infMDFeTransp,
1364
                    $this->taginfUnidTransp($value),
1365
                    'Falta tag "infUnidTransp"'
1366
                );
1367
            }
1368
        }
1369
        if ($std->peri) {
1370
            foreach ($std->peri as $value) {
1371
                $this->dom->appChild(
1372
                    $infMDFeTransp,
1373
                    $this->tagperi($value),
1374
                    'Falta tag "peri"'
1375
                );
1376
            }
1377
        }
1378
        $this->infMDFeTransp[$std->nItem][] = $infMDFeTransp;
1379
        return $infMDFeTransp;
1380
    }
1381
1382
    /**
1383
     * taginfUnidTransp
1384
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/infUnidTransp
1385
     *
1386
     * @param  stdClass $std
1387
     * @return DOMElement
1388
     */
1389
    private function taginfUnidTransp(stdClass $std)
1390
    {
1391
        $possible = [
1392
            'tpUnidTransp',
1393
            'idUnidTransp',
1394
            'qtdRat',
1395
            'lacUnidTransp',
1396
            'infUnidCarga'
1397
        ];
1398
        $std = $this->equilizeParameters($std, $possible);
1399
        $infUnidTransp = $this->dom->createElement("infUnidTransp");
1400
        $this->dom->addChild(
1401
            $infUnidTransp,
1402
            "tpUnidTransp",
1403
            $std->tpUnidTransp,
1404
            true,
1405
            "Tipo da Unidade de Transporte"
1406
        );
1407
        $this->dom->addChild(
1408
            $infUnidTransp,
1409
            "idUnidTransp",
1410
            $std->idUnidTransp,
1411
            false,
1412
            "Identificação da Unidade de Transporte"
1413
        );
1414
        if ($std->lacUnidTransp != null) {
1415
            $possible = [
1416
                'nLacre'
1417
            ];
1418
            $stdlacUnidTransp = $this->equilizeParameters($std->lacUnidTransp, $possible);
1419
            foreach ($stdlacUnidTransp->nLacre as $nLacre) {
1420
                $lacUnidTransp = $this->dom->createElement("lacUnidTransp");
1421
                $this->dom->addChild(
1422
                    $lacUnidTransp,
1423
                    "nLacre",
1424
                    $nLacre,
1425
                    true,
1426
                    "Número do lacre"
1427
                );
1428
                $this->dom->appChild(
1429
                    $infUnidTransp,
1430
                    $lacUnidTransp,
1431
                    'Falta tag "infUnidTransp"'
1432
                );
1433
            }
1434
        }
1435
        if ($std->infUnidCarga) {
1436
            foreach ($std->infUnidCarga as $value) {
1437
                $this->dom->appChild(
1438
                    $infUnidTransp,
1439
                    $this->taginfUnidCarga($value),
1440
                    'Falta tag "infUnidCarga"'
1441
                );
1442
            }
1443
        }
1444
        $this->dom->addChild(
1445
            $infUnidTransp,
1446
            "qtdRat",
1447
            $this->conditionalNumberFormatting($std->qtdRat),
1448
            false,
1449
            "Quantidade rateada (Peso,Volume) "
1450
        );
1451
        return $infUnidTransp;
1452
    }
1453
1454
    /**
1455
     * taginfUnidCarga
1456
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/infUnidCarga
1457
     *
1458
     * @param  stdClass $std
1459
     * @return DOMElement
1460
     */
1461
    private function taginfUnidCarga(stdClass $std)
1462
    {
1463
        $possible = [
1464
            'tpUnidCarga',
1465
            'idUnidCarga',
1466
            'lacUnidCarga',
1467
            'qtdRat'
1468
        ];
1469
        $std = $this->equilizeParameters($std, $possible);
1470
        $infUnidCarga = $this->dom->createElement("infUnidCarga");
1471
        $this->dom->addChild(
1472
            $infUnidCarga,
1473
            "tpUnidCarga",
1474
            $std->tpUnidCarga,
1475
            false,
1476
            "Tipo da Unidade de Carga"
1477
        );
1478
        $this->dom->addChild(
1479
            $infUnidCarga,
1480
            "idUnidCarga",
1481
            $std->idUnidCarga,
1482
            false,
1483
            "Identificação da Unidade de Carga "
1484
        );
1485
        if ($std->lacUnidCarga != null) {
1486
            $possible = [
1487
                'nLacre'
1488
            ];
1489
            $stdlacUnidCarga = $this->equilizeParameters($std->lacUnidCarga, $possible);
1490
            foreach ($stdlacUnidCarga->nLacre as $nLacre) {
1491
                $lacUnidCarga = $this->dom->createElement("lacUnidCarga");
1492
                $this->dom->addChild(
1493
                    $lacUnidCarga,
1494
                    "nLacre",
1495
                    $nLacre,
1496
                    true,
1497
                    "Número do lacre"
1498
                );
1499
                $this->dom->appChild(
1500
                    $infUnidCarga,
1501
                    $lacUnidCarga,
1502
                    'Falta tag "infUnidCarga"'
1503
                );
1504
            }
1505
        }
1506
        $this->dom->addChild(
1507
            $infUnidCarga,
1508
            "qtdRat",
1509
            $this->conditionalNumberFormatting($std->qtdRat),
1510
            false,
1511
            "Quantidade rateada (Peso,Volume) "
1512
        );
1513
        return $infUnidCarga;
1514
    }
1515
1516
    /**
1517
     * tagseg
1518
     * tag MDFe/infMDFe/seg
1519
     *
1520
     * @param  stdClass $std
1521
     * @return DOMElement
1522
     */
1523
    public function tagseg(stdClass $std)
1524
    {
1525
        $possible = [
1526
            'respSeg',
1527
            'CNPJ',
1528
            'CPF',
1529
            'infSeg',
1530
            'nApol',
1531
            'nAver'
1532
        ];
1533
        $std = $this->equilizeParameters($std, $possible);
1534
        $seg = $this->dom->createElement("seg");
1535
        $infResp = $this->dom->createElement("infResp");
1536
        $this->dom->addChild(
1537
            $infResp,
1538
            "respSeg",
1539
            $std->respSeg,
1540
            true,
1541
            "Responsável pelo seguro"
1542
        );
1543
        $this->dom->addChild(
1544
            $infResp,
1545
            "CNPJ",
1546
            $std->CNPJ,
1547
            false,
1548
            "Número do CNPJ do responsável pelo seguro"
1549
        );
1550
        $this->dom->addChild(
1551
            $infResp,
1552
            "CPF",
1553
            $std->CPF,
1554
            false,
1555
            "Número do CPF do responsável pelo seguro"
1556
        );
1557
        $this->dom->appChild($seg, $infResp, 'Falta tag "seg"');
1558
        if ($std->infSeg != null) {
1559
            $possible = [
1560
                'xSeg',
1561
                'CNPJ'
1562
            ];
1563
            $stdinfSeg = $this->equilizeParameters($std->infSeg, $possible);
1564
            $infSeg = $this->dom->createElement("infSeg");
1565
            $this->dom->addChild(
1566
                $infSeg,
1567
                "xSeg",
1568
                $stdinfSeg->xSeg,
1569
                true,
1570
                "Nome da Seguradora"
1571
            );
1572
            $this->dom->addChild(
1573
                $infSeg,
1574
                "CNPJ",
1575
                $stdinfSeg->CNPJ,
1576
                false,
1577
                "Número do CNPJ da seguradora"
1578
            );
1579
            $this->dom->appChild($seg, $infSeg, 'Falta tag "seg"');
1580
        }
1581
        $this->dom->addChild(
1582
            $seg,
1583
            "nApol",
1584
            $std->nApol,
1585
            false,
1586
            "Número da Apólice"
1587
        );
1588
        if ($std->nAver != null) {
1589
            foreach ($std->nAver as $nAver) {
1590
                $this->dom->addChild(
1591
                    $seg,
1592
                    "nAver",
1593
                    $nAver,
1594
                    true,
1595
                    "Número da Averbação"
1596
                );
1597
            }
1598
        }
1599
        $this->seg[] = $seg;
1600
        return $seg;
1601
    }
1602
1603
    /**
1604
     * tagprodPred
1605
     * tag MDFe/infMDFe/prodPred
1606
     *
1607
     * @param  stdClass $std
1608
     * @return DOMElement
1609
     */
1610
    public function tagprodPred($std)
1611
    {
1612
        $possible = [
1613
            'tpCarga',
1614
            'xProd',
1615
            'cEAN',
1616
            'NCM',
1617
            'infLotacao'
1618
        ];
1619
        $std = $this->equilizeParameters($std, $possible);
1620
        $this->prodPred = $this->dom->createElement("prodPred");
1621
        $this->dom->addChild(
1622
            $this->prodPred,
1623
            "tpCarga",
1624
            $std->tpCarga,
1625
            true,
1626
            "Tipo da Carga. 01-Granel sólido; 02-Granel líquido; "
1627
            . "03-Frigorificada; 04-Conteinerizada; 05-Carga Geral; "
1628
            . "06-Neogranel; 07-Perigosa (granel sólido); 08-Perigosa (granel "
1629
            . "líquido); 09-Perigosa (carga frigorificada); 10-Perigosa "
1630
            . "(conteinerizada); 11-Perigosa (carga geral)."
1631
        );
1632
        $this->dom->addChild(
1633
            $this->prodPred,
1634
            "xProd",
1635
            $std->xProd,
1636
            true,
1637
            "Descrição do produto predominante"
1638
        );
1639
        $this->dom->addChild(
1640
            $this->prodPred,
1641
            "cEAN",
1642
            $std->cEAN,
1643
            false,
1644
            "GTIN (Global Trade Item Number) do produto, antigo código EAN "
1645
            . "ou código de barras"
1646
        );
1647
        $this->dom->addChild(
1648
            $this->prodPred,
1649
            "NCM",
1650
            $std->NCM,
1651
            false,
1652
            "Código NCM"
1653
        );
1654
        if (!empty($std->infLotacao)) {
1655
            $this->dom->appChild(
1656
                $this->prodPred,
1657
                $this->taginfLotacao($std->infLotacao),
1658
                'Falta tag "infLotacao"'
1659
            );
1660
        }
1661
        return $this->prodPred;
1662
    }
1663
1664
    /**
1665
     *
1666
     */
1667
    private function taginfLotacao(stdClass $std)
1668
    {
1669
        $possible = [
1670
            'infLocalCarrega',
1671
            'infLocalDescarrega'
1672
        ];
1673
        $std = $this->equilizeParameters($std, $possible);
1674
        $this->infLotacao = $this->dom->createElement("infLotacao");
1675
        if (!empty($std->infLocalCarrega)) {
1676
            $this->dom->appChild(
1677
                $this->infLotacao,
1678
                $this->tagLocalCarrega($std->infLocalCarrega),
1679
                'Falta tag "infLocalCarrega"'
1680
            );
1681
        }
1682
        if (!empty($std->infLocalDescarrega)) {
1683
            $this->dom->appChild(
1684
                $this->infLotacao,
1685
                $this->tagLocalDescarrega($std->infLocalDescarrega),
1686
                'Falta tag "infLocalDescarrega"'
1687
            );
1688
        }
1689
        return $this->infLotacao;
1690
    }
1691
1692
    /**
1693
     * Informações da localização do carregamento do MDF-e de carga lotação
1694
     *
1695
     */
1696
    private function tagLocalCarrega(stdClass $std)
1697
    {
1698
        $possible = [
1699
            'CEP',
1700
            'latitude',
1701
            'longitude'
1702
        ];
1703
        $std = $this->equilizeParameters($std, $possible);
1704
        $tagLocalCarrega = $this->dom->createElement("infLocalCarrega");
1705
        if (!empty($std->CEP)) {
1706
            $this->dom->addChild(
1707
                $tagLocalCarrega,
1708
                "CEP",
1709
                $std->CEP,
1710
                true,
1711
                "CEP onde foi carregado o MDF-e"
1712
            );
1713
        } else {
1714
            $this->dom->addChild(
1715
                $tagLocalCarrega,
1716
                "latitude",
1717
                $std->latitude,
1718
                true,
1719
                "Latitude do ponto geográfico onde foi carregado o MDF-e"
1720
            );
1721
            $this->dom->addChild(
1722
                $tagLocalCarrega,
1723
                "longitude",
1724
                $std->longitude,
1725
                true,
1726
                "Longitude do ponto geográfico onde foi carregado o MDF-e"
1727
            );
1728
        }
1729
        return $tagLocalCarrega;
1730
    }
1731
1732
    /**
1733
     * Informações da localização do descarregamento do MDF-e de carga lotação
1734
     */
1735
    private function tagLocalDescarrega(stdClass $std)
1736
    {
1737
        $possible = [
1738
            'CEP',
1739
            'latitude',
1740
            'longitude'
1741
        ];
1742
        $std = $this->equilizeParameters($std, $possible);
1743
        $tagLocalDescarrega = $this->dom->createElement("infLocalDescarrega");
1744
        if (!empty($std->CEP)) {
1745
            $this->dom->addChild(
1746
                $tagLocalDescarrega,
1747
                "CEP",
1748
                $std->CEP,
1749
                true,
1750
                "CEP onde foi descarregado o MDF-e"
1751
            );
1752
        } else {
1753
            $this->dom->addChild(
1754
                $tagLocalDescarrega,
1755
                "latitude",
1756
                $std->latitude,
1757
                true,
1758
                "Latitude do ponto geográfico onde foi descarregado o MDF-e"
1759
            );
1760
            $this->dom->addChild(
1761
                $tagLocalDescarrega,
1762
                "longitude",
1763
                $std->longitude,
1764
                true,
1765
                "Longitude do ponto geográfico onde foi descarregado o MDF-e"
1766
            );
1767
        }
1768
        return $tagLocalDescarrega;
1769
    }
1770
1771
    /**
1772
     * tagTot
1773
     * tag MDFe/infMDFe/tot
1774
     *
1775
     * @param  stdClass $std
1776
     * @return DOMElement
1777
     */
1778
    public function tagtot(stdClass $std)
1779
    {
1780
        $possible = [
1781
            'qCTe',
1782
            'qNFe',
1783
            'qMDFe',
1784
            'vCarga',
1785
            'cUnid',
1786
            'qCarga'
1787
        ];
1788
        $std = $this->equilizeParameters($std, $possible);
1789
        if (!isset($std->qCTe)) {
1790
            $std->qCTe = 0;
1791
            foreach ($this->infCTe as $infCTe) {
0 ignored issues
show
Bug introduced by
The expression $this->infCTe 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...
1792
                $std->qCTe += count($infCTe);
1793
            }
1794
            if ($std->qCTe == 0) {
1795
                $std->qCTe = '';
1796
            }
1797
        }
1798
        if (!isset($std->qNFe)) {
1799
            $std->qNFe = 0;
1800
            foreach ($this->infNFe as $infNFe) {
0 ignored issues
show
Bug introduced by
The expression $this->infNFe 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...
1801
                $std->qNFe += count($infNFe);
1802
            }
1803
            if ($std->qNFe == 0) {
1804
                $std->qNFe = '';
1805
            }
1806
        }
1807
        if (!isset($std->qMDFe)) {
1808
            $std->qMDFe = 0;
1809
            foreach ($this->infMDFeTransp as $infMDFeTransp) {
0 ignored issues
show
Bug introduced by
The expression $this->infMDFeTransp 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...
1810
                $std->qMDFe += count($infMDFeTransp);
1811
            }
1812
            if ($std->qMDFe == 0) {
1813
                $std->qMDFe = '';
1814
            }
1815
        }
1816
        $tot = $this->dom->createElement("tot");
1817
        $this->dom->addChild(
1818
            $tot,
1819
            "qCTe",
1820
            $std->qCTe,
1821
            false,
1822
            "Quantidade total de CT-e relacionados no Manifesto"
1823
        );
1824
        $this->dom->addChild(
1825
            $tot,
1826
            "qNFe",
1827
            $std->qNFe,
1828
            false,
1829
            "Quantidade total de NF-e relacionados no Manifesto"
1830
        );
1831
        $this->dom->addChild(
1832
            $tot,
1833
            "qMDFe",
1834
            $std->qMDFe,
1835
            false,
1836
            "Quantidade total de MDF-e relacionados no Manifesto"
1837
        );
1838
        $this->dom->addChild(
1839
            $tot,
1840
            "vCarga",
1841
            $this->conditionalNumberFormatting($std->vCarga),
1842
            true,
1843
            "Valor total da mercadoria/carga transportada"
1844
        );
1845
        $this->dom->addChild(
1846
            $tot,
1847
            "cUnid",
1848
            $std->cUnid,
1849
            true,
1850
            "Código da unidade de medida do Peso Bruto da Carga / Mercadoria Transportada"
1851
        );
1852
        $this->dom->addChild(
1853
            $tot,
1854
            "qCarga",
1855
            $this->conditionalNumberFormatting($std->qCarga, 4),
1856
            true,
1857
            "Peso Bruto Total da Carga / Mercadoria Transportada"
1858
        );
1859
        $this->tot = $tot;
1860
        return $tot;
1861
    }
1862
1863
    /**
1864
     * tagLacres
1865
     * tag MDFe/infMDFe/lacres
1866
     *
1867
     * @param  stdClass $std
1868
     * @return DOMElement
1869
     */
1870
    public function taglacres(stdClass $std)
1871
    {
1872
        $possible = [
1873
            'nLacre'
1874
        ];
1875
        $std = $this->equilizeParameters($std, $possible);
1876
        $lacres = $this->dom->createElement("lacres");
1877
        $this->dom->addChild(
1878
            $lacres,
1879
            "nLacre",
1880
            $std->nLacre,
1881
            false,
1882
            "Número do lacre"
1883
        );
1884
        $this->lacres[] = $lacres; //array de DOMNode
1885
        return $this->lacres;
1886
    }
1887
1888
    /**
1889
     * taginfAdic
1890
     * Grupo de Informações Adicionais Z01 pai A01
1891
     * tag MDFe/infMDFe/infAdic (opcional)
1892
     *
1893
     * @param  stdClass $std
1894
     * @return DOMElement
1895
     */
1896
    public function taginfAdic(stdClass $std)
1897
    {
1898
        $possible = [
1899
            'infAdFisco',
1900
            'infCpl'
1901
        ];
1902
        $std = $this->equilizeParameters($std, $possible);
1903
        $infAdic = $this->dom->createElement("infAdic");
1904
        $this->dom->addChild(
1905
            $infAdic,
1906
            "infAdFisco",
1907
            $std->infAdFisco,
1908
            false,
1909
            "Informações Adicionais de Interesse do Fisco"
1910
        );
1911
        $this->dom->addChild(
1912
            $infAdic,
1913
            "infCpl",
1914
            $std->infCpl,
1915
            false,
1916
            "Informações Complementares de interesse do Contribuinte"
1917
        );
1918
        $this->infAdic = $infAdic;
1919
        return $infAdic;
1920
    }
1921
1922
    /**
1923
     * tagautXML
1924
     * tag MDFe/infMDFe/autXML
1925
     *
1926
     * Autorizados para download do XML do MDF-e
1927
     *
1928
     * @param  stdClass $std
1929
     * @return DOMElement
1930
     */
1931
    public function tagautXML(stdClass $std)
1932
    {
1933
        $possible = [
1934
            'CNPJ',
1935
            'CPF'
1936
        ];
1937
        $std = $this->equilizeParameters($std, $possible);
1938
        $autXML = $this->dom->createElement("autXML");
1939
        $this->dom->addChild(
1940
            $autXML,
1941
            "CNPJ",
1942
            $std->CNPJ,
1943
            false,
1944
            "CNPJ do autorizado"
1945
        );
1946
        $this->dom->addChild(
1947
            $autXML,
1948
            "CPF",
1949
            $std->CPF,
1950
            false,
1951
            "CPF do autorizado"
1952
        );
1953
        $this->autXML[] = $autXML;
1954
        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 1954 which is incompatible with the return type documented by NFePHP\MDFe\Make::tagautXML of type DOMElement.
Loading history...
1955
    }
1956
1957
    /**
1958
     * buildInfModal
1959
     * tag MDFe/infMDFe/infModal
1960
     *
1961
     * @return DOMElement
1962
     */
1963
    private function buildInfModal()
1964
    {
1965
        $infModal = $this->dom->createElement("infModal");
1966
        $infModal->setAttribute("versaoModal", $this->versao);
1967
        $this->infModal = $infModal;
1968
        $modal = $this->ide->getElementsByTagName('modal')->item(0)->nodeValue;
1969
        /*
1970
         1 - Rodoviário;
1971
         2 - Aéreo;
1972
         3 - Aquaviário;
1973
         4 - Ferroviário;
1974
         */
1975
        if ($modal == '1') {
1976
            $this->tagrodo();
1977
        } elseif ($modal == '4') {
1978
            $this->tagferrov();
1979
        }
1980
        return $infModal;
1981
    }
1982
1983
    private function buildIde()
1984
    {
1985
        $this->dom->appChild($this->infMDFe, $this->ide, 'Falta tag "ide"');
1986
        foreach ($this->infPercurso as $percurso) {
0 ignored issues
show
Bug introduced by
The expression $this->infPercurso 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...
1987
            $node = $this->ide->getElementsByTagName('infPercurso')->item(0);
1988
            if (empty($node)) {
1989
                $node = $this->ide->getElementsByTagName('UFFim')->item(0);
1990
            } else {
1991
                if ($this->ide->getElementsByTagName('infPercurso')->length > 1) {
1992
                    $node = $this->ide->getElementsByTagName('infPercurso')
1993
                        ->item($this->ide->getElementsByTagName('infPercurso')
1994
                        ->length - 1);
1995
                }
1996
            }
1997
            $this->dom->insertAfter($percurso, $node);
1998
        }
1999
        $UFFim = $this->ide->getElementsByTagName('UFFim')->item(0);
2000
        foreach ($this->infMunCarrega as $munCarrega) {
0 ignored issues
show
Bug introduced by
The expression $this->infMunCarrega 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...
2001
            $this->dom->insertAfter($munCarrega, $UFFim);
2002
        }
2003
    }
2004
2005
    /**
2006
     * tagAereo
2007
     * tag MDFe/infMDFe/infModal/aereo
2008
     *
2009
     * @return DOMElement
2010
     */
2011
2012
    public function tagaereo(stdClass $std)
2013
    {
2014
        $possible = [
2015
            'nac',
2016
            'matr',
2017
            'nVoo',
2018
            'cAerEmb',
2019
            'cAerDes',
2020
            'dVoo'
2021
        ];
2022
        $std = $this->equilizeParameters($std, $possible);
2023
        $aereo = $this->dom->createElement("aereo");
2024
        $identificador = '[1] <aereo> - ';
2025
        $this->dom->addChild(
2026
            $aereo,
2027
            "nac",
2028
            $std->nac,
2029
            true,
2030
            $identificador . "Marca da Nacionalidade da aeronave"
2031
        );
2032
        $this->dom->addChild(
2033
            $aereo,
2034
            "matr",
2035
            $std->matr,
2036
            true,
2037
            $identificador . "Marca de Matrícula da aeronave"
2038
        );
2039
        $this->dom->addChild(
2040
            $aereo,
2041
            "nVoo",
2042
            $std->nVoo,
2043
            true,
2044
            $identificador . "Número do Vôo"
2045
        );
2046
        $this->dom->addChild(
2047
            $aereo,
2048
            "cAerEmb",
2049
            $std->cAerEmb,
2050
            true,
2051
            $identificador . "Aeródromo de Embarque - Código IATA"
2052
        );
2053
        $this->dom->addChild(
2054
            $aereo,
2055
            "cAerDes",
2056
            $std->cAerDes,
2057
            true,
2058
            $identificador . "Aeródromo de Destino - Código IATA"
2059
        );
2060
        $this->dom->addChild(
2061
            $aereo,
2062
            "dVoo",
2063
            $std->dVoo,
2064
            true,
2065
            $identificador . "Data do Vôo"
2066
        );
2067
        $this->aereo = $aereo;
2068
        return $aereo;
2069
    }
2070
2071
2072
    /**
2073
     * tagtrem
2074
     * tag MDFe/infMDFe/infModal/ferrov/trem
2075
     *
2076
     * @return DOMElement
2077
     */
2078
2079
    public function tagtrem(stdClass $std)
2080
    {
2081
        $possible = [
2082
            'xPref',
2083
            'dhTrem',
2084
            'xOri',
2085
            'xDest',
2086
            'qVag'
2087
        ];
2088
        $std = $this->equilizeParameters($std, $possible);
2089
        $trem = $this->dom->createElement("trem");
2090
        $identificador = '[1] <trem> - ';
2091
        $this->dom->addChild(
2092
            $trem,
2093
            "xPref",
2094
            $std->xPref,
2095
            true,
2096
            $identificador . "Prefixo do Trem"
2097
        );
2098
        $this->dom->addChild(
2099
            $trem,
2100
            "dhTrem",
2101
            $std->dhTrem,
2102
            false,
2103
            $identificador . "Data e hora de liberação do trem na origem"
2104
        );
2105
        $this->dom->addChild(
2106
            $trem,
2107
            "xOri",
2108
            $std->xOri,
2109
            true,
2110
            $identificador . "Origem do Trem"
2111
        );
2112
        $this->dom->addChild(
2113
            $trem,
2114
            "xDest",
2115
            $std->xDest,
2116
            true,
2117
            $identificador . "Destino do Trem"
2118
        );
2119
        $this->dom->addChild(
2120
            $trem,
2121
            "qVag",
2122
            $std->qVag,
2123
            true,
2124
            $identificador . "Quantidade de vagões carregados"
2125
        );
2126
        $this->trem = $trem;
2127
        return $trem;
2128
    }
2129
2130
    /**
2131
     * tagVag
2132
     * tag MDFe/infMDFe/infModal/ferrov/trem/vag
2133
     *
2134
     * @param string $serie
2135
     * @param string $nVag
0 ignored issues
show
Bug introduced by
There is no parameter named $serie. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2136
     * @param string $nSeq
0 ignored issues
show
Bug introduced by
There is no parameter named $nVag. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2137
     * @param string $tonUtil
0 ignored issues
show
Bug introduced by
There is no parameter named $nSeq. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2138
     *
0 ignored issues
show
Bug introduced by
There is no parameter named $tonUtil. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2139
     * @return DOMElement
2140
     */
2141
2142
    public function tagVag(stdClass $std)
2143
    {
2144
        $possible = [
2145
            'pesoBC',
2146
            'pesoR',
2147
            'tpVag',
2148
            'serie',
2149
            'nVag',
2150
            'nSeq',
2151
            'TU'
2152
        ];
2153
        $identificador = '[1] <vag> - ';
2154
        $std = $this->equilizeParameters($std, $possible);
2155
        $vag = $this->dom->createElement("vag");
2156
        $this->dom->addChild(
2157
            $vag,
2158
            "pesoBC",
2159
            $std->pesoBC,
2160
            true,
2161
            $identificador . "Peso Base de Cálculo de Frete em Toneladas"
2162
        );
2163
        $this->dom->addChild(
2164
            $vag,
2165
            "pesoR",
2166
            $std->pesoR,
2167
            true,
2168
            $identificador . "Peso Real em Toneladas"
2169
        );
2170
        $this->dom->addChild(
2171
            $vag,
2172
            "tpVag",
2173
            $std->tpVag,
2174
            false,
2175
            $identificador . "Tipo de Vagão"
2176
        );
2177
        $this->dom->addChild(
2178
            $vag,
2179
            "serie",
2180
            $std->serie,
2181
            true,
2182
            $identificador . "Serie de Identificação do vagão"
2183
        );
2184
        $this->dom->addChild(
2185
            $vag,
2186
            "nVag",
2187
            $std->nVag,
2188
            true,
2189
            $identificador . "Número de Identificação do vagão"
2190
        );
2191
        $this->dom->addChild(
2192
            $vag,
2193
            "nSeq",
2194
            $std->nSeq,
2195
            false,
2196
            $identificador . "Sequência do vagão na composição"
2197
        );
2198
        $this->dom->addChild(
2199
            $vag,
2200
            "TU",
2201
            $std->TU,
2202
            true,
2203
            $identificador . "Tonelada Útil"
2204
        );
2205
        $this->vag[] = $vag;
2206
        return $vag;
2207
    }
2208
2209
    /**
2210
     * tagaquav
2211
     * tag MDFe/infMDFe/infModal/aquav
2212
     *
2213
     * @param stdClass $std
2214
     * @return DOMElement
2215
     */
2216
2217
    public function tagaquav(stdClass $std)
2218
    {
2219
        $possible = [
2220
            'irin',
2221
            'tpEmb',
2222
            'cEmbar',
2223
            'xEmbar',
2224
            'nViag',
2225
            'cPrtEmb',
2226
            'cPrtDest',
2227
            'prtTrans',
2228
            'tpNav',
2229
            'infTermCarreg',
2230
            'infTermDescarreg',
2231
            'infEmbComb',
2232
            'infUnidCargaVazia',
2233
            'infUnidTranspVazia'
2234
        ];
2235
        $identificador = '[1] <aquav> - ';
2236
        $std = $this->equilizeParameters($std, $possible);
2237
        $aquav = $this->dom->createElement("aquav");
2238
        $this->dom->addChild(
2239
            $aquav,
2240
            "irin",
2241
            $std->irin,
2242
            true,
2243
            $identificador . "Irin do navio sempre deverá ser informado"
2244
        );
2245
        $this->dom->addChild(
2246
            $aquav,
2247
            "tpEmb",
2248
            $std->tpEmb,
2249
            true,
2250
            $identificador . "Código do tipo de embarcação"
2251
        );
2252
        $this->dom->addChild(
2253
            $aquav,
2254
            "cEmbar",
2255
            $std->cEmbar,
2256
            true,
2257
            $identificador . "Código da embarcação"
2258
        );
2259
        $this->dom->addChild(
2260
            $aquav,
2261
            "xEmbar",
2262
            $std->xEmbar,
2263
            true,
2264
            $identificador . "Nome da embarcação"
2265
        );
2266
        $this->dom->addChild(
2267
            $aquav,
2268
            "nViag",
2269
            $std->nViag,
2270
            true,
2271
            $identificador . "Número da Viagem"
2272
        );
2273
        $this->dom->addChild(
2274
            $aquav,
2275
            "cPrtEmb",
2276
            $std->cPrtEmb,
2277
            true,
2278
            $identificador . "Código do Porto de Embarque"
2279
        );
2280
        $this->dom->addChild(
2281
            $aquav,
2282
            "cPrtDest",
2283
            $std->cPrtDest,
2284
            true,
2285
            $identificador . "Código do Porto de Destino"
2286
        );
2287
        $this->dom->addChild(
2288
            $aquav,
2289
            "prtTrans",
2290
            $std->prtTrans,
2291
            false,
2292
            $identificador . "Porto de Transbordo"
2293
        );
2294
        $this->dom->addChild(
2295
            $aquav,
2296
            "tpNav",
2297
            $std->tpNav,
2298
            false,
2299
            $identificador . "Tipo de Navegação"
2300
        );
2301
        if ($std->infTermCarreg) {
2302
            foreach ($std->infTermCarreg as $value) {
2303
                $this->dom->appChild(
2304
                    $aquav,
2305
                    $this->taginfTermCarreg($value),
2306
                    'Falta tag "infTermCarreg"'
2307
                );
2308
            }
2309
        }
2310
        if ($std->infTermDescarreg) {
2311
            foreach ($std->infTermDescarreg as $value) {
2312
                $this->dom->appChild(
2313
                    $aquav,
2314
                    $this->taginfTermDescarreg($value),
2315
                    'Falta tag "infTermDescarreg"'
2316
                );
2317
            }
2318
        }
2319
        if ($std->infEmbComb) {
2320
            foreach ($std->infEmbComb as $value) {
2321
                $this->dom->appChild(
2322
                    $aquav,
2323
                    $this->taginfEmbComb($value),
2324
                    'Falta tag "infEmbComb"'
2325
                );
2326
            }
2327
        }
2328
        if ($std->infUnidCargaVazia) {
2329
            foreach ($std->infUnidCargaVazia as $value) {
2330
                $this->dom->appChild(
2331
                    $aquav,
2332
                    $this->taginfUnidCargaVazia($value),
2333
                    'Falta tag "infUnidCargaVazia"'
2334
                );
2335
            }
2336
        }
2337
        if ($std->infUnidTranspVazia) {
2338
            foreach ($std->infUnidTranspVazia as $value) {
2339
                $this->dom->appChild(
2340
                    $aquav,
2341
                    $this->taginfUnidTranspVazia($value),
2342
                    'Falta tag "infUnidTranspVazia"'
2343
                );
2344
            }
2345
        }
2346
        $this->aquav = $aquav;
2347
        return $aquav;
2348
    }
2349
2350
    /**
2351
     * infUnidTranspVazia
2352
     * tag MDFe/infMDFe/infModal/Aqua/infUnidTranspVazia
2353
     *
2354
     * @return DOMElement
2355
     */
2356
    public function taginfUnidTranspVazia(stdClass $std)
2357
    {
2358
        $possible = [
2359
            'idUnidTranspVazia',
2360
            'tpUnidTranspVazia'
2361
        ];
2362
        $identificador = '[1] <infUnidTranspVazia> - ';
2363
        $std = $this->equilizeParameters($std, $possible);
2364
        $infUnidTranspVazia = $this->dom->createElement("infUnidTranspVazia");
2365
        $this->dom->addChild(
2366
            $infUnidTranspVazia,
2367
            "idUnidTranspVazia",
2368
            $std->idUnidTranspVazia,
2369
            true,
2370
            $identificador . "dentificação da unidades de transporte vazia"
2371
        );
2372
        $this->dom->addChild(
2373
            $infUnidTranspVazia,
2374
            "tpUnidTranspVazia",
2375
            $std->tpUnidTranspVazia,
2376
            true,
2377
            $identificador . "Tipo da unidade de transporte vazia"
2378
        );
2379
        return $infUnidTranspVazia;
2380
    }
2381
2382
    /**
2383
     * infUnidCargaVazia
2384
     * tag MDFe/infMDFe/infModal/Aqua/infUnidCargaVazia
2385
     *
2386
     * @return DOMElement
2387
     */
2388
    public function taginfUnidCargaVazia(stdClass $std)
2389
    {
2390
        $possible = [
2391
            'idUnidCargaVazia',
2392
            'tpUnidCargaVazia'
2393
        ];
2394
        $identificador = '[1] <infUnidCargaVazia> - ';
2395
        $std = $this->equilizeParameters($std, $possible);
2396
        $infUnidCargaVazia = $this->dom->createElement("infUnidCargaVazia");
2397
        $this->dom->addChild(
2398
            $infUnidCargaVazia,
2399
            "idUnidCargaVazia",
2400
            $std->idUnidCargaVazia,
2401
            true,
2402
            $identificador . "Identificação da unidades de carga vazia"
2403
        );
2404
        $this->dom->addChild(
2405
            $infUnidCargaVazia,
2406
            "tpUnidCargaVazia",
2407
            $std->tpUnidCargaVazia,
2408
            true,
2409
            $identificador . "Tipo da unidade de carga vazia"
2410
        );
2411
        return $infUnidCargaVazia;
2412
    }
2413
2414
    /**
2415
     * taginfTermDescarreg
2416
     * tag MDFe/infMDFe/infModal/Aqua/infTermDescarreg
2417
     *
2418
     * @return DOMElement
2419
     */
2420
    public function taginfTermDescarreg(stdClass $std)
2421
    {
2422
        $possible = [
2423
            'cTermDescarreg',
2424
            'xTermDescarreg'
2425
        ];
2426
        $identificador = '[1] <infTermDescarreg> - ';
2427
        $std = $this->equilizeParameters($std, $possible);
2428
        $infTermDescarreg = $this->dom->createElement("infTermDescarreg");
2429
        $this->dom->addChild(
2430
            $infTermDescarreg,
2431
            "cTermDescarreg",
2432
            $std->cTermDescarreg,
2433
            true,
2434
            $identificador . "Código do Terminal de Descarregamento"
2435
        );
2436
        $this->dom->addChild(
2437
            $infTermDescarreg,
2438
            "xTermDescarreg",
2439
            $std->xTermDescarreg,
2440
            true,
2441
            $identificador . "Nome do Terminal de Descarregamento"
2442
        );
2443
        return $infTermDescarreg;
2444
    }
2445
2446
    /**
2447
     * tagInfTermCarreg
2448
     * tag MDFe/infMDFe/infModal/aquav/infTermCarreg
2449
     *
2450
     * @return DOMElement
2451
     */
2452
    public function taginfTermCarreg(stdClass $std)
2453
    {
2454
        $possible = [
2455
            'cTermCarreg',
2456
            'xTermCarreg'
2457
        ];
2458
        $identificador = '[1] <infTermCarreg> - ';
2459
        $std = $this->equilizeParameters($std, $possible);
2460
        $infTermCarreg = $this->dom->createElement("infTermCarreg");
2461
2462
        $this->dom->addChild(
2463
            $infTermCarreg,
2464
            "cTermCarreg",
2465
            $std->cTermCarreg,
2466
            true,
2467
            $identificador . "Código do Terminal de Carregamento"
2468
        );
2469
        $this->dom->addChild(
2470
            $infTermCarreg,
2471
            "xTermCarreg",
2472
            $std->xTermCarreg,
2473
            true,
2474
            $identificador . "Nome do Terminal de Carregamento"
2475
        );
2476
        return $infTermCarreg;
2477
    }
2478
2479
    /**
2480
     * tagInfTermCarreg
2481
     * tag MDFe/infMDFe/infModal/aquav/infEmbComb
2482
     *
2483
     * @param stdClass $std
2484
     * @return DOMElement
2485
     */
2486
    public function taginfEmbComb(stdClass $std)
2487
    {
2488
        $possible = [
2489
            'cEmbComb',
2490
            'xBalsa'
2491
        ];
2492
        $identificador = '[1] <infEmbComb> - ';
2493
        $std = $this->equilizeParameters($std, $possible);
2494
        $infEmbComb = $this->dom->createElement("infEmbComb");
2495
2496
        $this->dom->addChild(
2497
            $infEmbComb,
2498
            "cEmbComb",
2499
            $std->cEmbComb,
2500
            true,
2501
            $identificador . "Código da embarcação do comboio"
2502
        );
2503
        $this->dom->addChild(
2504
            $infEmbComb,
2505
            "xBalsa",
2506
            $std->xBalsa,
2507
            true,
2508
            $identificador . "Identificador da Balsa"
2509
        );
2510
        return $infEmbComb;
2511
    }
2512
2513
    /**
2514
     * condutor
2515
     * tag MDFe/infMDFe/infModal/rodo/veicTracao/condutor
2516
     *
2517
     * @param  string $cEmbComb
0 ignored issues
show
Bug introduced by
There is no parameter named $cEmbComb. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2518
     *
2519
     * @return DOMElement
2520
     */
2521
    private function tagcondutor(stdClass $std)
2522
    {
2523
        $possible = [
2524
            'xNome',
2525
            'CPF'
2526
        ];
2527
        $std = $this->equilizeParameters($std, $possible);
2528
        $condutor = $this->dom->createElement("condutor");
2529
        $identificador = '[4] <condutor> - ';
2530
        $this->dom->addChild(
2531
            $condutor,
2532
            "xNome",
2533
            $std->xNome,
2534
            true,
2535
            $identificador . "Nome do Condutor "
2536
        );
2537
        $this->dom->addChild(
2538
            $condutor,
2539
            "CPF",
2540
            $std->CPF,
2541
            true,
2542
            $identificador . "CPF do Condutor "
2543
        );
2544
        return $condutor;
2545
    }
2546
2547
    /**
2548
     * tagVeicTracao
2549
     * tag MDFe/infMDFe/infModal/rodo/veicTracao
2550
     *
2551
     * @param  stdClass $std
2552
     * @return DOMElement
2553
     */
2554
    public function tagveicTracao(stdClass $std)
2555
    {
2556
        $possible = [
2557
            'cInt',
2558
            'placa',
2559
            'RENAVAM',
2560
            'tara',
2561
            'capKG',
2562
            'capM3',
2563
            'prop',
2564
            'tpRod',
2565
            'tpCar',
2566
            'UF',
2567
            'condutor'
2568
        ];
2569
        $std = $this->equilizeParameters($std, $possible);
2570
        $veicTracao = $this->dom->createElement("veicTracao");
2571
        $identificador = '[4] <disp> - ';
2572
        $this->dom->addChild(
2573
            $veicTracao,
2574
            "cInt",
2575
            $std->cInt,
2576
            false,
2577
            $identificador . "Código interno do veículo"
2578
        );
2579
        $this->dom->addChild(
2580
            $veicTracao,
2581
            "placa",
2582
            $std->placa,
2583
            true,
2584
            $identificador . "Placa do veículo"
2585
        );
2586
        $this->dom->addChild(
2587
            $veicTracao,
2588
            "RENAVAM",
2589
            $std->RENAVAM,
2590
            false,
2591
            $identificador . "RENAVAM"
2592
        );
2593
        $this->dom->addChild(
2594
            $veicTracao,
2595
            "tara",
2596
            $std->tara,
2597
            true,
2598
            $identificador . "Tara em KG"
2599
        );
2600
        $this->dom->addChild(
2601
            $veicTracao,
2602
            "capKG",
2603
            $std->capKG,
2604
            false,
2605
            $identificador . "Capacidade em KG"
2606
        );
2607
        $this->dom->addChild(
2608
            $veicTracao,
2609
            "capM3",
2610
            $std->capM3,
2611
            false,
2612
            $identificador . "Capacidade em M3"
2613
        );
2614
        if ($std->prop != null) {
2615
            $possible = [
2616
                'CPF',
2617
                'CNPJ',
2618
                'RNTRC',
2619
                'xNome',
2620
                'IE',
2621
                'UF',
2622
                'tpProp'
2623
            ];
2624
            $identificadorProp = '[4] <prop> - ';
2625
            $stdprop = $this->equilizeParameters($std->prop, $possible);
2626
            $prop = $this->dom->createElement("prop");
2627
            if ($stdprop->CPF) {
2628
                $this->dom->addChild(
2629
                    $prop,
2630
                    "CPF",
2631
                    $stdprop->CPF,
2632
                    true,
2633
                    $identificadorProp . "Número do CPF"
2634
                );
2635
            } else {
2636
                $this->dom->addChild(
2637
                    $prop,
2638
                    "CNPJ",
2639
                    $stdprop->CNPJ,
2640
                    true,
2641
                    $identificadorProp . "Número do CNPJ"
2642
                );
2643
            }
2644
            $this->dom->addChild(
2645
                $prop,
2646
                "RNTRC",
2647
                $stdprop->RNTRC,
2648
                true,
2649
                $identificadorProp . "RNTRC"
2650
            );
2651
            $this->dom->addChild(
2652
                $prop,
2653
                "xNome",
2654
                $stdprop->xNome,
2655
                true,
2656
                $identificadorProp . "Razão Social"
2657
            );
2658
            $this->dom->addChild(
2659
                $prop,
2660
                "IE",
2661
                $stdprop->IE,
2662
                true,
2663
                $identificadorProp . "Inscrição Estadual",
2664
                true
2665
            );
2666
            $this->dom->addChild(
2667
                $prop,
2668
                "UF",
2669
                $stdprop->UF,
2670
                true,
2671
                $identificadorProp . "Unidade da Federação"
2672
            );
2673
            $this->dom->addChild(
2674
                $prop,
2675
                "tpProp",
2676
                $stdprop->tpProp,
2677
                true,
2678
                $identificadorProp . "Tipo Proprietário"
2679
            );
2680
            $this->dom->appChild($veicTracao, $prop, 'Falta tag "veicTracao"');
2681
        }
2682
        if ($std->condutor) {
2683
            foreach ($std->condutor as $value) {
2684
                $this->dom->appChild(
2685
                    $veicTracao,
2686
                    $this->tagcondutor($value),
2687
                    'Falta tag "condutor"'
2688
                );
2689
            }
2690
        }
2691
        $this->dom->addChild(
2692
            $veicTracao,
2693
            "tpRod",
2694
            $std->tpRod,
2695
            true,
2696
            $identificador . "Tipo de rodado"
2697
        );
2698
        $this->dom->addChild(
2699
            $veicTracao,
2700
            "tpCar",
2701
            $std->tpCar,
2702
            true,
2703
            $identificador . "Tipo de carroceria"
2704
        );
2705
        $this->dom->addChild(
2706
            $veicTracao,
2707
            "UF",
2708
            $std->UF,
2709
            true,
2710
            $identificador . "UF de licenciamento do veículo"
2711
        );
2712
        $this->veicTracao = $veicTracao;
2713
        return $veicTracao;
2714
    }
2715
2716
    /**
2717
     * tagVeicReboque
2718
     * tag MDFe/infMDFe/infModal/rodo/VeicReboque
2719
     *
2720
     * @param  stdClass $std
2721
     * @return DOMElement
2722
     */
2723
    public function tagveicReboque(stdClass $std)
2724
    {
2725
        $possible = [
2726
            'cInt',
2727
            'placa',
2728
            'RENAVAM',
2729
            'tara',
2730
            'capKG',
2731
            'capM3',
2732
            'prop',
2733
            'tpCar',
2734
            'UF'
2735
        ];
2736
        $std = $this->equilizeParameters($std, $possible);
2737
        $veicReboque = $this->dom->createElement("veicReboque");
2738
        $identificador = '[4] <veicReboque> - ';
2739
        $this->dom->addChild(
2740
            $veicReboque,
2741
            "cInt",
2742
            $std->cInt,
2743
            false,
2744
            $identificador . "Código interno do veículo"
2745
        );
2746
        $this->dom->addChild(
2747
            $veicReboque,
2748
            "placa",
2749
            $std->placa,
2750
            true,
2751
            $identificador . "Placa do veículo"
2752
        );
2753
        $this->dom->addChild(
2754
            $veicReboque,
2755
            "RENAVAM",
2756
            $std->RENAVAM,
2757
            false,
2758
            $identificador . "RENAVAM"
2759
        );
2760
        $this->dom->addChild(
2761
            $veicReboque,
2762
            "tara",
2763
            $std->tara,
2764
            true,
2765
            $identificador . "Tara em KG"
2766
        );
2767
        $this->dom->addChild(
2768
            $veicReboque,
2769
            "capKG",
2770
            $std->capKG,
2771
            false,
2772
            $identificador . "Capacidade em KG"
2773
        );
2774
        $this->dom->addChild(
2775
            $veicReboque,
2776
            "capM3",
2777
            $std->capM3,
2778
            false,
2779
            $identificador . "Capacidade em M3"
2780
        );
2781
        if ($std->prop != null) {
2782
            $identificadorprop = '[4] <prop> - ';
2783
            $possible = [
2784
                'CPF',
2785
                'CNPJ',
2786
                'RNTRC',
2787
                'xNome',
2788
                'IE',
2789
                'UF',
2790
                'tpProp'
2791
            ];
2792
            $stdprop = $this->equilizeParameters($std->prop, $possible);
2793
            $prop = $this->dom->createElement("prop");
2794
            if ($stdprop->CPF) {
2795
                $this->dom->addChild(
2796
                    $prop,
2797
                    "CPF",
2798
                    $stdprop->CPF,
2799
                    true,
2800
                    $identificadorprop . "Número do CPF"
2801
                );
2802
            } else {
2803
                $this->dom->addChild(
2804
                    $prop,
2805
                    "CNPJ",
2806
                    $stdprop->CNPJ,
2807
                    true,
2808
                    $identificadorprop . "Número do CNPJ"
2809
                );
2810
            }
2811
            $this->dom->addChild(
2812
                $prop,
2813
                "RNTRC",
2814
                $stdprop->RNTRC,
2815
                true,
2816
                $identificadorprop . "RNTRC"
2817
            );
2818
            $this->dom->addChild(
2819
                $prop,
2820
                "xNome",
2821
                $stdprop->xNome,
2822
                true,
2823
                $identificadorprop . "Razão Social"
2824
            );
2825
            $this->dom->addChild(
2826
                $prop,
2827
                "IE",
2828
                $stdprop->IE,
2829
                true,
2830
                $identificadorprop . "Inscrição Estadual"
2831
            );
2832
            $this->dom->addChild(
2833
                $prop,
2834
                "UF",
2835
                $stdprop->UF,
2836
                true,
2837
                $identificadorprop . "Unidade da Federação"
2838
            );
2839
            $this->dom->addChild(
2840
                $prop,
2841
                "tpProp",
2842
                $stdprop->tpProp,
2843
                true,
2844
                $identificadorprop . "Tipo Proprietário"
2845
            );
2846
            $this->dom->appChild($veicReboque, $prop, 'Falta tag "veicReboque"');
2847
        }
2848
        $this->dom->addChild(
2849
            $veicReboque,
2850
            "tpCar",
2851
            $std->tpCar,
2852
            true,
2853
            $identificador . "Tipo de carroceria"
2854
        );
2855
        $this->dom->addChild(
2856
            $veicReboque,
2857
            "UF",
2858
            $std->UF,
2859
            true,
2860
            $identificador . "UF de licenciamento do veículo"
2861
        );
2862
        $this->veicReboque[] = $veicReboque;
2863
        return $veicReboque;
2864
    }
2865
2866
    /**
2867
     * tagcodAgPorto
2868
     * tag MDFe/infMDFe/infModal/rodo/codAgPorto
2869
     *
2870
     * @param  stdClass $std
2871
     * @return DOMElement
2872
     */
2873
    public function tagcodAgPorto(stdClass $std)
2874
    {
2875
        $possible = [
2876
            'codAgPorto'
2877
        ];
2878
        $std = $this->equilizeParameters($std, $possible);
2879
        $this->dom->addChild(
2880
            $this->rodo,
2881
            "codAgPorto",
2882
            $std->codAgPorto,
2883
            false,
2884
            "Código de Agendamento no porto"
2885
        );
2886
        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 2886 which is incompatible with the return type documented by NFePHP\MDFe\Make::tagcodAgPorto of type DOMElement.
Loading history...
2887
    }
2888
2889
    /**
2890
     * taglacRodo
2891
     * tag MDFe/infMDFe/infModal/rodo/lacRodo
2892
     *
2893
     * @param  stdClass $std
2894
     * @return DOMElement
2895
     */
2896
    public function taglacRodo(stdClass $std)
2897
    {
2898
        $possible = [
2899
            'nLacre'
2900
        ];
2901
        $std = $this->equilizeParameters($std, $possible);
2902
        $lacRodo = $this->dom->createElement("lacRodo");
2903
        $this->dom->addChild(
2904
            $lacRodo,
2905
            "nLacre",
2906
            $std->nLacre,
2907
            true,
2908
            "Número do Lacre"
2909
        );
2910
        $this->lacRodo[] = $lacRodo;
2911
        return $lacRodo;
2912
    }
2913
2914
    /**
2915
     * Informações do Responsável técnico ZD01 pai A01
2916
     * tag NFe/infNFe/infRespTec (opcional)
2917
     * @param stdClass $std
2918
     * @return DOMElement
2919
     * @throws RuntimeException
2920
     */
2921
    public function taginfRespTec(stdClass $std)
2922
    {
2923
        $possible = [
2924
            'CNPJ',
2925
            'xContato',
2926
            'email',
2927
            'fone',
2928
            'CSRT',
2929
            'idCSRT'
2930
        ];
2931
        $std = $this->equilizeParameters($std, $possible);
2932
        $infRespTec = $this->dom->createElement("infRespTec");
2933
        $this->dom->addChild(
2934
            $infRespTec,
2935
            "CNPJ",
2936
            $std->CNPJ,
2937
            true,
2938
            "Informar o CNPJ da pessoa jurídica responsável pelo sistema "
2939
            . "utilizado na emissão do documento fiscal eletrônico"
2940
        );
2941
        $this->dom->addChild(
2942
            $infRespTec,
2943
            "xContato",
2944
            $std->xContato,
2945
            true,
2946
            "Informar o nome da pessoa a ser contatada na empresa desenvolvedora "
2947
            . "do sistema utilizado na emissão do documento fiscal eletrônico"
2948
        );
2949
        $this->dom->addChild(
2950
            $infRespTec,
2951
            "email",
2952
            $std->email,
2953
            true,
2954
            "Informar o e-mail da pessoa a ser contatada na empresa "
2955
            . "desenvolvedora do sistema."
2956
        );
2957
        $this->dom->addChild(
2958
            $infRespTec,
2959
            "fone",
2960
            $std->fone,
2961
            true,
2962
            "Informar o telefone da pessoa a ser contatada na empresa "
2963
            . "desenvolvedora do sistema."
2964
        );
2965
        if (!empty($std->CSRT) && !empty($std->idCSRT)) {
2966
            $this->csrt = $std->CSRT;
0 ignored issues
show
Bug introduced by
The property csrt 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...
2967
            $this->dom->addChild(
2968
                $infRespTec,
2969
                "idCSRT",
2970
                $std->idCSRT,
2971
                true,
2972
                "Identificador do CSRT utilizado para montar o hash do CSRT"
2973
            );
2974
            $this->dom->addChild(
2975
                $infRespTec,
2976
                "hashCSRT",
2977
                $std->CSRT,
2978
                true,
2979
                "hash do CSRT"
2980
            );
2981
        }
2982
        $this->infRespTec = $infRespTec;
0 ignored issues
show
Bug introduced by
The property infRespTec 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...
2983
        return $infRespTec;
2984
    }
2985
2986
    /**
2987
     * Metodo responsavel para montagem da tag ingPag - Informações do Pagamento do Frete
2988
     *
2989
     * @param stdClass $std
2990
     * @return DOMElement
2991
     * @throws RuntimeException
2992
     */
2993
    public function taginfPag(stdClass $std)
2994
    {
2995
        $possible = [
2996
            'xNome',
2997
            'CPF',
2998
            'CNPJ',
2999
            'idEstrangeiro',
3000
            'Comp',
3001
            'vContrato',
3002
            'indPag',
3003
            'infPrazo',
3004
            'infBanc'
3005
        ];
3006
        $std = $this->equilizeParameters($std, $possible);
3007
        $infPag = $this->dom->createElement("infPag");
3008
        $identificador = '[4] <infPag> - ';
3009
        $this->dom->addChild(
3010
            $infPag,
3011
            "xNome",
3012
            $std->xNome,
3013
            true,
3014
            $identificador . "Nome do responsável pelo pgto"
3015
        );
3016
        if (!empty($std->CPF)) {
3017
            $this->dom->addChild(
3018
                $infPag,
3019
                "CPF",
3020
                $std->CPF,
3021
                true,
3022
                $identificador . "Número do CPF do responsável pelo pgto"
3023
            );
3024
        } elseif (!empty($std->CNPJ)) {
3025
            $this->dom->addChild(
3026
                $infPag,
3027
                "CNPJ",
3028
                $std->CNPJ,
3029
                true,
3030
                $identificador . "Número do CNPJ do responsável pelo pgto"
3031
            );
3032
        } else {
3033
            $this->dom->addChild(
3034
                $infPag,
3035
                "idEstrangeiro",
3036
                $std->idEstrangeiro,
3037
                true,
3038
                $identificador . "Identificador do responsável pelo pgto em "
3039
                . "caso de ser estrangeiro"
3040
            );
3041
        }
3042
        foreach ($std->Comp as $value) {
3043
            $this->dom->appChild($infPag, $this->compPag($value), 'Falta tag "Comp"');
3044
        }
3045
        $this->dom->addChild(
3046
            $infPag,
3047
            "vContrato",
3048
            $std->vContrato,
3049
            true,
3050
            $identificador . "Valor total do contrato"
3051
        );
3052
        $this->dom->addChild(
3053
            $infPag,
3054
            "indPag",
3055
            $std->indPag,
3056
            true,
3057
            $identificador . "Indicador da Forma de Pagamento"
3058
        );
3059
        if ($std->indPag == 1) {
3060
            foreach ($std->infPrazo as $value) {
3061
                $this->dom->appChild($infPag, $this->infPrazo($value), 'Falta tag "infPrazo"');
3062
            }
3063
        }
3064
        $this->dom->appChild($infPag, $this->infBanc($std->infBanc), 'Falta tag "infBanc"');
3065
        $this->infPag[] = $infPag;
3066
        return $infPag;
3067
    }
3068
3069
    /**
3070
     * Componentes do Pagamento do Frete
3071
     * @param stdClass
3072
     *
3073
     */
3074
    private function compPag(stdClass $std)
3075
    {
3076
        $possible = [
3077
            'tpComp',
3078
            'vComp',
3079
            'xComp'
3080
        ];
3081
        $stdComp = $this->equilizeParameters($std, $possible);
3082
        $comp = $this->dom->createElement("Comp");
3083
        $identificador = '[4] <Comp> - ';
3084
        $this->dom->addChild(
3085
            $comp,
3086
            "tpComp",
3087
            $stdComp->tpComp,
3088
            true,
3089
            $identificador . "Tipo do Componente"
3090
        );
3091
        $this->dom->addChild(
3092
            $comp,
3093
            "vComp",
3094
            $stdComp->vComp,
3095
            true,
3096
            $identificador . "Valor do Componente"
3097
        );
3098
        $this->dom->addChild(
3099
            $comp,
3100
            "xComp",
3101
            $stdComp->xComp,
3102
            false,
3103
            $identificador . "Descrição do componente do tipo Outros"
3104
        );
3105
        return $comp;
3106
    }
3107
3108
    /***
3109
     * Informações do pagamento a prazo. Obs: Informar somente se indPag for à Prazo.
3110
     *
3111
     */
3112
    private function infPrazo(stdClass $std)
3113
    {
3114
        $possible = [
3115
            'nParcela',
3116
            'dVenc',
3117
            'vParcela'
3118
        ];
3119
        $stdPraz = $this->equilizeParameters($std, $possible);
3120
        $prazo = $this->dom->createElement("infPrazo");
3121
        $identificador = '[4] <infPrazo> - ';
3122
        $this->dom->addChild(
3123
            $prazo,
3124
            "nParcela",
3125
            $stdPraz->nParcela,
3126
            false,
3127
            $identificador . "Número da parcela"
3128
        );
3129
        $this->dom->addChild(
3130
            $prazo,
3131
            "dVenc",
3132
            $stdPraz->dVenc,
3133
            false,
3134
            $identificador . "Data de vencimento da Parcela (AAAA-MMDD)"
3135
        );
3136
        $this->dom->addChild(
3137
            $prazo,
3138
            "vParcela",
3139
            $this->conditionalNumberFormatting($stdPraz->vParcela),
3140
            true,
3141
            $identificador . "Valor da Parcela"
3142
        );
3143
        return $prazo;
3144
    }
3145
3146
    /**
3147
     * Informações bancárias.
3148
     *
3149
     */
3150
    private function infBanc(stdClass $std)
3151
    {
3152
        $possible = [
3153
            'codBanco',
3154
            'codAgencia',
3155
            'CNPJIPEF'
3156
        ];
3157
        $stdBanco = $this->equilizeParameters($std, $possible);
3158
        $banco = $this->dom->createElement("infBanc");
3159
        $identificador = '[4] <infBanc> - ';
3160
        if (!empty($stdBanco->codBanco)) {
3161
            $this->dom->addChild(
3162
                $banco,
3163
                "codBanco",
3164
                $stdBanco->codBanco,
3165
                true,
3166
                $identificador . "Número do banco"
3167
            );
3168
            $this->dom->addChild(
3169
                $banco,
3170
                "codAgencia",
3171
                $stdBanco->codAgencia,
3172
                true,
3173
                $identificador . "Número da Agência"
3174
            );
3175
        } else {
3176
            $this->dom->addChild(
3177
                $banco,
3178
                "CNPJIPEF",
3179
                $stdBanco->CNPJIPEF,
3180
                true,
3181
                $identificador . "Número do CNPJ da Instituição de pagamento Eletrônico do Frete"
3182
            );
3183
        }
3184
        return $banco;
3185
    }
3186
3187
    /**
3188
     * buildMDFe
3189
     * Tag raiz da MDFe
3190
     * tag MDFe DOMNode
3191
     * Função chamada pelo método [ monta ]
3192
     *
3193
     * @return DOMElement
3194
     */
3195
    protected function buildMDFe()
3196
    {
3197
        if (empty($this->MDFe)) {
3198
            $this->MDFe = $this->dom->createElement("MDFe");
3199
            $this->MDFe->setAttribute("xmlns", "http://www.portalfiscal.inf.br/mdfe");
3200
        }
3201
        return $this->MDFe;
3202
    }
3203
3204
    /**
3205
     * checkMDFKey
3206
     * Remonta a chave do MDFe de 44 digitos com base em seus dados
3207
     * Isso é útil no caso da chave informada estar errada
3208
     * se a chave estiver errada a mesma é substituida
3209
     *
3210
     * @param object $dom
3211
     */
3212
    private function checkMDFKey($dom)
3213
    {
3214
        $infMDFe = $dom->getElementsByTagName("infMDFe")->item(0);
3215
        $ide = $dom->getElementsByTagName("ide")->item(0);
3216
        $emit = $dom->getElementsByTagName("emit")->item(0);
3217
        $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue;
3218
        $dhEmi = $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue;
3219
        if (!empty($emit->getElementsByTagName('CNPJ')->item(0)->nodeValue)) {
3220
            $doc = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3221
        } else {
3222
            $doc = $emit->getElementsByTagName('CPF')->item(0)->nodeValue;
3223
        }
3224
        $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue;
3225
        $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
3226
        $nMDF = $ide->getElementsByTagName('nMDF')->item(0)->nodeValue;
3227
        $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue;
3228
        $cNF = $ide->getElementsByTagName('cMDF')->item(0)->nodeValue;
3229
        $chave = str_replace('MDFe', '', $infMDFe->getAttribute("Id"));
3230
        $dt = new \DateTime($dhEmi);
3231
        $chaveMontada = Keys::build(
3232
            $cUF,
3233
            $dt->format('y'),
3234
            $dt->format('m'),
3235
            $doc,
3236
            $mod,
3237
            $serie,
3238
            $nMDF,
3239
            $tpEmis,
3240
            $cNF
3241
        );
3242
        //caso a chave contida na NFe esteja errada
3243
        //substituir a chave
3244
        if ($chaveMontada != $chave) {
3245
            $ide->getElementsByTagName('cDV')->item(0)->nodeValue = substr($chaveMontada, -1);
3246
            $infMDFe = $dom->getElementsByTagName("infMDFe")->item(0);
3247
            $infMDFe->setAttribute("Id", "MDFe" . $chaveMontada);
3248
            $infMDFe->setAttribute("versao", $this->versao);
3249
            $this->chMDFe = $chaveMontada;
3250
        }
3251
    }
3252
3253
    /**
3254
     * Retorna os erros detectados
3255
     * @return array
3256
     */
3257
    public function getErrors()
3258
    {
3259
        return $this->errors;
3260
    }
3261
3262
    /**
3263
     * Includes missing or unsupported properties in stdClass
3264
     * Replace all unsuported chars
3265
     *
3266
     * @param  stdClass $std
3267
     * @param  array $possible
3268
     * @return stdClass
3269
     */
3270
    private function equilizeParameters(stdClass $std, $possible)
3271
    {
3272
        return Strings::equilizeParameters($std, $possible, $this->replaceAccentedChars);
3273
    }
3274
    
3275
        /**
3276
     * Formatação numerica condicional
3277
     * @param string|float|int|null $value
3278
     * @param int $decimal
3279
     * @return string
3280
     */
3281
    protected function conditionalNumberFormatting($value = null, $decimal = 2)
3282
    {
3283
        if (is_numeric($value)) {
3284
            return number_format($value, $decimal, '.', '');
3285
        }
3286
        return null;
3287
    }
3288
3289
    /*
3290
    protected function conditionalNumberFormatting($value = null, array $decimal): string
3291
    {
3292
        if (!is_numeric($value)) {
3293
            return null;
3294
        }
3295
        $num = (float) $value;
3296
        $l = explode('.', $num);
3297
        $declen = 0;
3298
        if (!empty($l[1])) {
3299
            $declen = strlen($l[1]);
3300
        }
3301
        if ($declen < $decimal[0]) {
3302
            return number_format($num, $decimal[0], '.', '');
3303
        } elseif ($declen > $decimal[1]) {
3304
            return number_format($num, $decimal[1], '.', '');
3305
        }
3306
        return $num;
3307
    }*/
3308
}
3309