Passed
Pull Request — master (#129)
by
unknown
02:37
created

Make::disp()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 57

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 57
ccs 0
cts 57
cp 0
rs 8.9381
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
                }
340
                if ($this->infContratante) {
341
                    $this->dom->addArrayChild(
342
                        $this->infANTT,
343
                        $this->infContratante,
344
                        'Falta tag "infContratante"'
345
                    );
346
                }
347
                if ($this->infPag) {
348
                    $this->dom->addArrayChild($this->infANTT, $this->infPag, 'Falta tag "infpag"');
349
                }
350
                $this->dom->appChild($this->rodo, $this->infANTT, 'Falta tag "infANTT"');
351
            }
352
            if ($this->veicTracao) {
353
                $this->dom->appChild($this->rodo, $this->veicTracao, 'Falta tag "rodo"');
354
            }
355
            if ($this->veicReboque) {
356
                $this->dom->addArrayChild($this->rodo, $this->veicReboque, 'Falta tag "veicReboque"');
357
            }
358
            if ($this->lacRodo) {
359
                $this->dom->addArrayChild($this->rodo, $this->lacRodo, 'Falta tag "lacRodo"');
360
            }
361
            $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "infModal"');
362
        }
363
        if ($this->aereo) {
364
            $this->dom->appChild($this->infModal, $this->aereo, 'Falta tag "aereo"');
365
        }
366
        if ($this->ferrov) {
367
            if ($this->trem) {
368
                $this->dom->appChild($this->ferrov, $this->trem, 'Falta tag "ferrov"');
369
            }
370
            if ($this->vag) {
371
                $this->dom->addArrayChild($this->ferrov, $this->vag, 'Falta tag "vag"');
372
            }
373
            $this->dom->appChild($this->infModal, $this->ferrov, 'Falta tag "ferrov"');
374
        }
375
        if ($this->aquav) {
376
            foreach ($this->infTermCarreg as $termCarreg) {
377
                $this->dom->appChild($this->aquav, $termCarreg, 'Falta tag "aquav"');
378
            }
379
            foreach ($this->infTermDescarreg as $termDescarreg) {
380
                $this->dom->appChild($this->aquav, $termDescarreg, 'Falta tag "aquav"');
381
            }
382
            foreach ($this->infEmbComb as $embComb) {
383
                $this->dom->appChild($this->aquav, $embComb, 'Falta tag "aquav"');
384
            }
385
            foreach ($this->infUnidCargaVazia as $unidCargaVazia) {
386
                $this->dom->appChild($this->aquav, $unidCargaVazia, 'Falta tag "aquav"');
387
            }
388
            foreach ($this->infUnidTranspVazia as $unidTranspVazia) {
389
                $this->dom->appChild($this->aquav, $unidTranspVazia, 'Falta tag "aquav"');
390
            }
391
            $this->dom->appChild($this->infModal, $this->aquav, 'Falta tag "aquav"');
392
        }
393
        $this->dom->appChild($this->infMDFe, $this->infModal, 'Falta tag "infModal"');
394
        if ($this->infDoc) {
395
            $this->dom->appChild($this->infMDFe, $this->infDoc, 'Falta tag "infDoc"');
396
            if ($this->infMunDescarga) {
397
                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...
398
                    $this->dom->appChild($this->infDoc, $value, 'Falta tag "infMunDescarga"');
399
                    if (isset($this->infCTe[$key])) {
400
                        $this->dom->addArrayChild($value, $this->infCTe[$key], 'Falta tag "infCTe"');
401
                    }
402
                    if (isset($this->infNFe[$key])) {
403
                        $this->dom->addArrayChild(
404
                            $value,
405
                            $this->infNFe[$key],
406
                            'Falta tag "infNFe"'
407
                        );
408
                    }
409
                    if (isset($this->infMDFeTransp[$key])) {
410
                        $this->dom->addArrayChild(
411
                            $value,
412
                            $this->infMDFeTransp[$key],
413
                            'Falta tag "infMDFeTransp"'
414
                        );
415
                    }
416
                }
417
            }
418
        }
419
        if (!empty($this->seg)) {
420
            $this->dom->addArrayChild($this->infMDFe, $this->seg, 'Falta tag "seg"');
421
        }
422
        if (!empty($this->prodPred)) {
423
            $this->dom->appChild($this->infMDFe, $this->prodPred, 'Falta tag "prodPred"');
424
        }
425
        $this->dom->appChild($this->infMDFe, $this->tot, 'Falta tag "tot"');
426
        if (!empty($this->lacres)) {
427
            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...
428
                $this->dom->appChild($this->infMDFe, $lacres, 'Falta tag "lacres"');
429
            }
430
        }
431
        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...
432
            $this->dom->appChild($this->infMDFe, $autXML, 'Falta tag "infMDFe"');
433
        }
434
        if (!empty($this->infAdic)) {
435
            $this->dom->appChild($this->infMDFe, $this->infAdic, 'Falta tag "infAdic"');
436
        }
437
        $this->dom->appChild($this->MDFe, $this->infMDFe, 'Falta tag "infMDFe"');
438
        $this->dom->appendChild($this->MDFe);
439
        // testa da chave
440
        $this->checkMDFKey($this->dom);
441
        $this->xml = $this->dom->saveXML();
442
        if (count($this->errors) > 0) {
443
            throw new RuntimeException('Existem erros nas tags. Obtenha os erros com getErrors().');
444
        }
445
        return true;
446
    }
447
448
    /**
449
     * Informações de identificação da MDFe
450
     * tag MDFe/infMDFe/ide
451
     *
452
     * @param  stdClass $std
453
     * @return DOMElement
454
     */
455
    public function tagide(stdClass $std)
456
    {
457
        $possible = [
458
            'cUF',
459
            'tpAmb',
460
            'tpEmit',
461
            'tpTransp',
462
            'mod',
463
            'serie',
464
            'nMDF',
465
            'cMDF',
466
            'cDV',
467
            'modal',
468
            'dhEmi',
469
            'tpEmis',
470
            'procEmi',
471
            'verProc',
472
            'UFIni',
473
            'UFFim',
474
            'dhIniViagem',
475
            'indCanalVerde',
476
            'indCarregaPosterior'
477
        ];
478
        $std = $this->equilizeParameters($std, $possible);
479
        $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...
480
        $identificador = '[4] <ide> - ';
481
        $ide = $this->dom->createElement("ide");
482
        $this->dom->addChild(
483
            $ide,
484
            "cUF",
485
            $std->cUF,
486
            true,
487
            $identificador . "Código da UF do emitente do Documento Fiscal"
488
        );
489
        $this->dom->addChild(
490
            $ide,
491
            "tpAmb",
492
            $std->tpAmb,
493
            true,
494
            $identificador . "Identificação do Ambiente"
495
        );
496
        $this->dom->addChild(
497
            $ide,
498
            "tpEmit",
499
            $std->tpEmit,
500
            true,
501
            $identificador . "Indicador da tipo de emitente"
502
        );
503
        $this->dom->addChild(
504
            $ide,
505
            "tpTransp",
506
            $std->tpTransp,
507
            false,
508
            $identificador . "Tipo do Transportador"
509
        );
510
        $this->dom->addChild(
511
            $ide,
512
            "mod",
513
            $std->mod,
514
            true,
515
            $identificador . "Código do Modelo do Documento Fiscal"
516
        );
517
        $this->dom->addChild(
518
            $ide,
519
            "serie",
520
            $std->serie,
521
            true,
522
            $identificador . "Série do Documento Fiscal"
523
        );
524
        $this->dom->addChild(
525
            $ide,
526
            "nMDF",
527
            $std->nMDF,
528
            true,
529
            $identificador . "Número do Documento Fiscal"
530
        );
531
        $this->dom->addChild(
532
            $ide,
533
            "cMDF",
534
            str_pad($std->cMDF, 8, '0', STR_PAD_LEFT),
535
            true,
536
            $identificador . "Código do numérico do MDF"
537
        );
538
        $this->dom->addChild(
539
            $ide,
540
            "cDV",
541
            $std->cDV,
542
            true,
543
            $identificador . "Dígito Verificador da Chave de Acesso da NF-e"
544
        );
545
        $this->dom->addChild(
546
            $ide,
547
            "modal",
548
            $std->modal,
549
            true,
550
            $identificador . "Modalidade de transporte"
551
        );
552
        $this->dom->addChild(
553
            $ide,
554
            "dhEmi",
555
            $std->dhEmi,
556
            true,
557
            $identificador . "Data e hora de emissão do Documento Fiscal"
558
        );
559
        $this->dom->addChild(
560
            $ide,
561
            "tpEmis",
562
            $std->tpEmis,
563
            true,
564
            $identificador . "Tipo de Emissão do Documento Fiscal"
565
        );
566
        $this->dom->addChild(
567
            $ide,
568
            "procEmi",
569
            $std->procEmi,
570
            true,
571
            $identificador . "Processo de emissão"
572
        );
573
        $this->dom->addChild(
574
            $ide,
575
            "verProc",
576
            $std->verProc,
577
            true,
578
            $identificador . "Versão do Processo de emissão"
579
        );
580
        $this->dom->addChild(
581
            $ide,
582
            "UFIni",
583
            $std->UFIni,
584
            true,
585
            $identificador . "Sigla da UF do Carregamento"
586
        );
587
        $this->dom->addChild(
588
            $ide,
589
            "UFFim",
590
            $std->UFFim,
591
            true,
592
            $identificador . "Sigla da UF do Descarregamento"
593
        );
594
        $this->dom->addChild(
595
            $ide,
596
            "dhIniViagem",
597
            $std->dhIniViagem,
598
            false,
599
            $identificador . "Data e hora previstos de início da viagem"
600
        );
601
        $this->dom->addChild(
602
            $ide,
603
            "indCanalVerde",
604
            $std->indCanalVerde,
605
            false,
606
            $identificador . "Indicador de participação do Canal Verde"
607
        );
608
        if ($std->indCarregaPosterior && $std->indCarregaPosterior == '1') {
609
            $this->dom->addChild(
610
                $ide,
611
                "indCarregaPosterior",
612
                $std->indCarregaPosterior,
613
                false,
614
                $identificador . "Indicador de MDF-e com inclusão da Carga posterior"
615
                    . " a emissão por evento de inclusão de DF-e"
616
            );
617
        }
618
619
        $this->mod = $std->mod;
620
        $this->ide = $ide;
621
        return $ide;
622
    }
623
624
    /**
625
     * taginfMunCarrega
626
     *
627
     * tag MDFe/infMDFe/ide/infMunCarrega
628
     *
629
     * @param  stdClass $std
630
     * @return DOMElement
631
     */
632
    public function taginfMunCarrega(stdClass $std)
633
    {
634
        $possible = [
635
            'cMunCarrega',
636
            'xMunCarrega'
637
        ];
638
        $std = $this->equilizeParameters($std, $possible);
639
        $infMunCarrega = $this->dom->createElement("infMunCarrega");
640
        $this->dom->addChild(
641
            $infMunCarrega,
642
            "cMunCarrega",
643
            $std->cMunCarrega,
644
            true,
645
            "Código do Município de Carregamento"
646
        );
647
        $this->dom->addChild(
648
            $infMunCarrega,
649
            "xMunCarrega",
650
            $std->xMunCarrega,
651
            true,
652
            "Nome do Município de Carregamento"
653
        );
654
        $this->infMunCarrega[] = $infMunCarrega;
655
        return $infMunCarrega;
656
    }
657
658
    /**
659
     * tagInfPercurso
660
     *
661
     * tag MDFe/infMDFe/ide/infPercurso
662
     *
663
     * @param  stdClass $std
664
     * @return DOMElement
665
     */
666
    public function taginfPercurso(stdClass $std)
667
    {
668
        $possible = [
669
            'UFPer'
670
        ];
671
        $std = $this->equilizeParameters($std, $possible);
672
        $infPercurso = $this->dom->createElement("infPercurso");
673
        $this->dom->addChild(
674
            $infPercurso,
675
            "UFPer",
676
            $std->UFPer,
677
            true,
678
            "Sigla das Unidades da Federação do percurso"
679
        );
680
        $this->infPercurso[] = $infPercurso;
681
        return $infPercurso;
682
    }
683
684
    /**
685
     * tagemit
686
     * Identificação do emitente da MDFe
687
     * tag MDFe/infMDFe/emit
688
     *
689
     * @param  stdClass $std
690
     * @return DOMElement
691
     */
692
    public function tagemit(stdClass $std)
693
    {
694
        $possible = [
695
            'CNPJ',
696
            'CPF',
697
            'IE',
698
            'xNome',
699
            'xFant'
700
        ];
701
        $std = $this->equilizeParameters($std, $possible);
702
        $identificador = '[25] <emit> - ';
703
        $this->emit = $this->dom->createElement("emit");
704
        if ($std->CPF) {
705
            $this->dom->addChild(
706
                $this->emit,
707
                "CPF",
708
                $std->CPF,
709
                true,
710
                $identificador . "CPF do emitente"
711
            );
712
        } else {
713
            $this->dom->addChild(
714
                $this->emit,
715
                "CNPJ",
716
                $std->CNPJ,
717
                true,
718
                $identificador . "CNPJ do emitente"
719
            );
720
        }
721
        $this->dom->addChild(
722
            $this->emit,
723
            "IE",
724
            $std->IE,
725
            false,
726
            $identificador . "Inscrição Estadual do emitente"
727
        );
728
        $this->dom->addChild(
729
            $this->emit,
730
            "xNome",
731
            substr($std->xNome, 0, 60),
732
            true,
733
            $identificador . "Razão Social ou Nome do emitente"
734
        );
735
        $this->dom->addChild(
736
            $this->emit,
737
            "xFant",
738
            substr($std->xFant, 0, 60),
739
            false,
740
            $identificador . "Nome fantasia do emitente"
741
        );
742
        return $this->emit;
743
    }
744
745
    /**
746
     * tagenderEmit
747
     * Endereço do emitente [30] pai [25]
748
     * tag MDFe/infMDFe/emit/endEmit
749
     *
750
     * @param  stdClass $std
751
     * @return DOMElement
752
     */
753
    public function tagenderEmit(stdClass $std)
754
    {
755
        $possible = [
756
            'xLgr',
757
            'nro',
758
            'xCpl',
759
            'xBairro',
760
            'cMun',
761
            'xMun',
762
            'CEP',
763
            'UF',
764
            'fone',
765
            'email'
766
        ];
767
        $std = $this->equilizeParameters($std, $possible);
768
        $identificador = '[30] <enderEmit> - ';
769
        $this->enderEmit = $this->dom->createElement("enderEmit");
770
        $this->dom->addChild(
771
            $this->enderEmit,
772
            "xLgr",
773
            $std->xLgr,
774
            true,
775
            $identificador . "Logradouro do Endereço do emitente"
776
        );
777
        $this->dom->addChild(
778
            $this->enderEmit,
779
            "nro",
780
            $std->nro,
781
            true,
782
            $identificador . "Número do Endereço do emitente"
783
        );
784
        $this->dom->addChild(
785
            $this->enderEmit,
786
            "xCpl",
787
            $std->xCpl,
788
            false,
789
            $identificador . "Complemento do Endereço do emitente"
790
        );
791
        $this->dom->addChild(
792
            $this->enderEmit,
793
            "xBairro",
794
            $std->xBairro,
795
            true,
796
            $identificador . "Bairro do Endereço do emitente"
797
        );
798
        $this->dom->addChild(
799
            $this->enderEmit,
800
            "cMun",
801
            $std->cMun,
802
            true,
803
            $identificador . "Código do município do Endereço do emitente"
804
        );
805
        $this->dom->addChild(
806
            $this->enderEmit,
807
            "xMun",
808
            $std->xMun,
809
            true,
810
            $identificador . "Nome do município do Endereço do emitente"
811
        );
812
        $this->dom->addChild(
813
            $this->enderEmit,
814
            "CEP",
815
            $std->CEP,
816
            true,
817
            $identificador . "Código do CEP do Endereço do emitente"
818
        );
819
        $this->dom->addChild(
820
            $this->enderEmit,
821
            "UF",
822
            $std->UF,
823
            true,
824
            $identificador . "Sigla da UF do Endereço do emitente"
825
        );
826
        $this->dom->addChild(
827
            $this->enderEmit,
828
            "fone",
829
            $std->fone,
830
            false,
831
            $identificador . "Número de telefone do emitente"
832
        );
833
        $this->dom->addChild(
834
            $this->enderEmit,
835
            "email",
836
            $std->email,
837
            false,
838
            $identificador . "Endereço de email do emitente"
839
        );
840
        return $this->enderEmit;
841
    }
842
843
    /**
844
     * tagrodo
845
     * tag MDFe/infMDFe/infModal/rodo
846
     *
847
     * @return DOMElement
848
     */
849
    private function tagrodo()
850
    {
851
        $this->rodo = $this->dom->createElement("rodo");
852
        return $this->rodo;
853
    }
854
855
    /**
856
     * tagferrov
857
     * tag MDFe/infMDFe/infModal/ferrov
858
     *
859
     * @return DOMElement
860
     */
861
    private function tagferrov()
862
    {
863
        if (empty($this->ferrov)) {
864
            $this->ferrov = $this->dom->createElement("ferrov");
865
        }
866
        return $this->ferrov;
867
    }
868
869
    /**
870
     * tagrodo
871
     * tag MDFe/infMDFe/infModal/rodo
872
     *
873
     * @return DOMElement
874
     */
875
    private function taginfDoc()
876
    {
877
        if (empty($this->infDoc)) {
878
            $this->infDoc = $this->dom->createElement("infDoc");
879
        }
880
        return $this->infDoc;
881
    }
882
883
    /**
884
     * valePed
885
     * tag MDFe/infMDFe/infModal/rodo/infANTT/valePed
886
     *
887
     * @param stdClass $std
888
     * @return DOMElement
889
     */
890
    public function tagvalePed(stdClass $std)
891
    {
892
        $possible = [
893
            'disp',
894
            'categCombVeic'
895
        ];
896
        $std = $this->equilizeParameters($std, $possible);
897
        $valePed = $this->dom->createElement("valePed");
898
        $identificador = '[2] <valePed> - ';
899
        foreach ($std->disp as $value) {
900
            $this->dom->appChild($valePed, $this->disp($value), 'Falta tag "disp"');
901
        }
902
        $this->dom->addChild(
903
            $valePed,
904
            "categCombVeic",
905
            $std->categCombVeic,
906
            false,
907
            $identificador . "Categoria de Combinação Veicular"
908
        );
909
        $this->valePed = $valePed;
910
        return $valePed;
911
    }
912
913
    /**
914
     * infANTT
915
     * tag MDFe/infMDFe/infModal/rodo/infANTT
916
     *
917
     * @return DOMElement
918
     */
919
    public function taginfANTT(stdClass $std)
920
    {
921
        $possible = [
922
            'RNTRC'
923
        ];
924
        $std = $this->equilizeParameters($std, $possible);
925
        $identificador = '[2] <infANTT> - ';
926
        $infANTT = $this->dom->createElement("infANTT");
927
        $this->dom->addChild(
928
            $infANTT,
929
            "RNTRC",
930
            $std->RNTRC,
931
            false,
932
            $identificador . "Registro Nacional de Transportadores Rodoviários"
933
                . " de Carga"
934
        );
935
        $this->infANTT = $infANTT;
936
        return $infANTT;
937
    }
938
939
    /**
940
     * disp
941
     * tag MDFe/infMDFe/infModal/rodo/infANTT/valePed/disp
942
     * @param stdClass $std
943
     * @return DOMElement
944
     */
945
    private function disp(stdClass $std)
946
    {
947
        $possible = [
948
            'CNPJForn',
949
            'CNPJPg',
950
            'CPFPg',
951
            'nCompra',
952
            'vValePed',
953
            'tpValePed'
954
        ];
955
        $std = $this->equilizeParameters($std, $possible);
956
        $disp = $this->dom->createElement("disp");
957
        $identificador = '[4] <disp> - ';
958
        $this->dom->addChild(
959
            $disp,
960
            "CNPJForn",
961
            $std->CNPJForn,
962
            false,
963
            $identificador . "CNPJ da empresa fornecedora do ValePedágio"
964
        );
965
        $this->dom->addChild(
966
            $disp,
967
            "CNPJPg",
968
            $std->CNPJPg,
969
            false,
970
            $identificador . "CNPJ do responsável pelo pagamento do Vale-Pedágio"
971
        );
972
        $this->dom->addChild(
973
            $disp,
974
            "CPFPg",
975
            $std->CPFPg,
976
            false,
977
            $identificador . "CPF do responsável pelo pagamento do Vale-Pedágio"
978
        );
979
        $this->dom->addChild(
980
            $disp,
981
            "nCompra",
982
            $std->nCompra,
983
            false,
984
            $identificador . "Número do comprovante de compra"
985
        );
986
        $this->dom->addChild(
987
            $disp,
988
            "vValePed",
989
            $this->conditionalNumberFormatting($std->vValePed),
990
            false,
991
            $identificador . "Valor do Vale-Pedagio"
992
        );
993
        $this->dom->addChild(
994
            $disp,
995
            "tpValePed",
996
            $std->tpValePed,
997
            false,
998
            $identificador . "Tipo do Vale Pedágio"
999
        );
1000
        return $disp;
1001
    }
1002
1003
    /**
1004
     * infContratante
1005
     * tag MDFe/infMDFe/infModal/rodo/infANTT/infContratante
1006
     *
1007
     * @return DOMElement
1008
     */
1009
    public function taginfContratante(stdClass $std)
1010
    {
1011
        $possible = [
1012
            'xNome',
1013
            'CPF',
1014
            'CPF',
1015
            'idEstrangeiro'
1016
        ];
1017
        $std = $this->equilizeParameters($std, $possible);
1018
        $identificador = '[4] <infContratante> - ';
1019
        $infContratante = $this->dom->createElement("infContratante");
1020
1021
        $this->dom->addChild(
1022
            $infContratante,
1023
            "xNome",
1024
            $std->xNome,
1025
            false,
1026
            $identificador . "Nome do contratante do serviço"
1027
        );
1028
        if ($std->CPF) {
1029
            $this->dom->addChild(
1030
                $infContratante,
1031
                "CPF",
1032
                $std->CPF,
1033
                true,
1034
                $identificador . "Número do CPF do contratante do serviço"
1035
            );
1036
        } elseif ($std->CNPJ) {
1037
            $this->dom->addChild(
1038
                $infContratante,
1039
                "CNPJ",
1040
                $std->CNPJ,
1041
                true,
1042
                $identificador . "Número do CNPJ do contratante do serviço"
1043
            );
1044
        } else {
1045
            $this->dom->addChild(
1046
                $infContratante,
1047
                "idEstrangeiro",
1048
                $std->idEstrangeiro,
1049
                true,
1050
                $identificador . "Identificador do contratante do serviço em "
1051
                    . "caso de ser estrangeiro"
1052
            );
1053
        }
1054
        $this->infContratante[] = $infContratante;
1055
        return $infContratante;
1056
    }
1057
1058
    /**
1059
     * infANTT
1060
     * tag MDFe/infMDFe/infModal/rodo/infANTT/infCIOT
1061
     *
1062
     * @return DOMElement
1063
     */
1064
    public function taginfCIOT(stdClass $std)
1065
    {
1066
        $possible = [
1067
            'CIOT',
1068
            'CPF',
1069
            'CNPJ'
1070
        ];
1071
        $std = $this->equilizeParameters($std, $possible);
1072
        $identificador = '[4] <infCIOT> - ';
1073
        $infCIOT = $this->dom->createElement("infCIOT");
1074
        $this->dom->addChild(
1075
            $infCIOT,
1076
            "CIOT",
1077
            $std->CIOT,
1078
            true,
1079
            $identificador . "Código Identificador da Operação de Transporte"
1080
        );
1081
        if ($std->CPF) {
1082
            $this->dom->addChild(
1083
                $infCIOT,
1084
                "CPF",
1085
                $std->CPF,
1086
                true,
1087
                $identificador . "Número do CPF responsável pela geração do CIOT"
1088
            );
1089
        } else {
1090
            $this->dom->addChild(
1091
                $infCIOT,
1092
                "CNPJ",
1093
                $std->CNPJ,
1094
                true,
1095
                $identificador . "Número do CNPJ responsável pela geração do CIOT"
1096
            );
1097
        }
1098
        $this->infCIOT[] = $infCIOT;
1099
        return $infCIOT;
1100
    }
1101
1102
    /**
1103
     * tagInfMunDescarga
1104
     * tag MDFe/infMDFe/infDoc/infMunDescarga
1105
     *
1106
     * @param  stdClass $std
1107
     * @return DOMElement
1108
     */
1109
    public function taginfMunDescarga(stdClass $std)
1110
    {
1111
        $possible = [
1112
            'cMunDescarga',
1113
            'xMunDescarga',
1114
            'nItem'
1115
        ];
1116
        $this->taginfDoc();
1117
        $std = $this->equilizeParameters($std, $possible);
1118
        $identificador = '[4] <infMunDescarga> - ';
1119
        $infMunDescarga = $this->dom->createElement("infMunDescarga");
1120
        $this->dom->addChild(
1121
            $infMunDescarga,
1122
            "cMunDescarga",
1123
            $std->cMunDescarga,
1124
            true,
1125
            $identificador . "Código do Município de Descarga"
1126
        );
1127
        $this->dom->addChild(
1128
            $infMunDescarga,
1129
            "xMunDescarga",
1130
            $std->xMunDescarga,
1131
            true,
1132
            $identificador . "Nome do Município de Descarga"
1133
        );
1134
        $this->infMunDescarga[$std->nItem] = $infMunDescarga;
1135
        return $infMunDescarga;
1136
    }
1137
1138
    /**
1139
     * taginfCTe
1140
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infCTe
1141
     *
1142
     * @param  stdClass $std
1143
     * @return DOMElement
1144
     */
1145
    public function taginfCTe(stdClass $std)
1146
    {
1147
        $possible = [
1148
            'chCTe',
1149
            'SegCodBarra',
1150
            'indReentrega',
1151
            'infEntregaParcial',
1152
            'infUnidTransp',
1153
            'peri',
1154
            'nItem'
1155
        ];
1156
        $std = $this->equilizeParameters($std, $possible);
1157
        $infCTe = $this->dom->createElement("infCTe");
1158
        $identificador = '[4] <infCTe> - ';
1159
        $this->dom->addChild(
1160
            $infCTe,
1161
            "chCTe",
1162
            $std->chCTe,
1163
            true,
1164
            $identificador . "Chave de Acesso CTe"
1165
        );
1166
        $this->dom->addChild(
1167
            $infCTe,
1168
            "SegCodBarra",
1169
            $std->SegCodBarra,
1170
            false,
1171
            $identificador . "Segundo código de barras do CTe"
1172
        );
1173
        $this->dom->addChild(
1174
            $infCTe,
1175
            "indReentrega",
1176
            $std->indReentrega,
1177
            false,
1178
            $identificador . "Indicador de Reentrega"
1179
        );
1180
        if ($std->infUnidTransp) {
1181
            foreach ($std->infUnidTransp as $value) {
1182
                $this->dom->appChild(
1183
                    $infCTe,
1184
                    $this->taginfUnidTransp($value),
1185
                    'Falta tag "infUnidTransp"'
1186
                );
1187
            }
1188
        }
1189
        if ($std->peri) {
1190
            foreach ($std->peri as $value) {
1191
                $this->dom->appChild(
1192
                    $infCTe,
1193
                    $this->tagperi($value),
1194
                    'Falta tag "peri"'
1195
                );
1196
            }
1197
        }
1198
        if ($std->infEntregaParcial != null) {
1199
            $possible = [
1200
                'qtdTotal',
1201
                'qtdParcial'
1202
            ];
1203
            $stdinfEntregaParcial = $this->equilizeParameters(
1204
                $std->infEntregaParcial,
1205
                $possible
1206
            );
1207
            $identificadorparcial = '[4] <infEntregaParcial> - ';
1208
            $infEntregaParcial = $this->dom->createElement("infEntregaParcial");
1209
            $this->dom->addChild(
1210
                $infEntregaParcial,
1211
                "qtdTotal",
1212
                $this->conditionalNumberFormatting($stdinfEntregaParcial->qtdTotal, 4),
1213
                true,
1214
                $identificadorparcial . "Quantidade total de volumes"
1215
            );
1216
            $this->dom->addChild(
1217
                $infEntregaParcial,
1218
                "qtdParcial",
1219
                $this->conditionalNumberFormatting($stdinfEntregaParcial->qtdParcial, 4),
1220
                true,
1221
                $identificadorparcial . "Quantidade de volumes enviados no MDF-e"
1222
            );
1223
            $this->dom->appChild($infCTe, $infEntregaParcial, 'Falta tag "infCTe"');
1224
        }
1225
        $this->infCTe[$std->nItem][] = $infCTe;
1226
        return $infCTe;
1227
    }
1228
1229
    /**
1230
     * tagperi
1231
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/peri
1232
     *
1233
     * @param  stdClass $std
1234
     * @return DOMElement
1235
     */
1236
    private function tagperi(stdClass $std)
1237
    {
1238
        $possible = [
1239
            'nONU',
1240
            'xNomeAE',
1241
            'xClaRisco',
1242
            'grEmb',
1243
            'qTotProd',
1244
            'qVolTipo'
1245
        ];
1246
        $std = $this->equilizeParameters($std, $possible);
1247
        $peri = $this->dom->createElement("peri");
1248
        $this->dom->addChild(
1249
            $peri,
1250
            "nONU",
1251
            $std->nONU,
1252
            true,
1253
            "Número ONU/UN"
1254
        );
1255
        $this->dom->addChild(
1256
            $peri,
1257
            "xNomeAE",
1258
            $std->xNomeAE,
1259
            true,
1260
            "Nome apropriado para embarque do produto"
1261
        );
1262
        $this->dom->addChild(
1263
            $peri,
1264
            "xClaRisco",
1265
            $std->xClaRisco,
1266
            true,
1267
            "Classe ou subclasse/divisão, e risco subsidiário/risco secundário"
1268
        );
1269
        $this->dom->addChild(
1270
            $peri,
1271
            "grEmb",
1272
            $std->grEmb,
1273
            true,
1274
            "Grupo de Embalagem"
1275
        );
1276
        $this->dom->addChild(
1277
            $peri,
1278
            "qTotProd",
1279
            $std->qTotProd,
1280
            true,
1281
            "Quantidade total por produto"
1282
        );
1283
        $this->dom->addChild(
1284
            $peri,
1285
            "qVolTipo",
1286
            $std->qVolTipo,
1287
            true,
1288
            "Quantidade e Tipo de volumes"
1289
        );
1290
        return $peri;
1291
    }
1292
1293
    /**
1294
     * taginfNFe
1295
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infNFe
1296
     *
1297
     * @param  stdClass $std
1298
     * @return DOMElement
1299
     */
1300
    public function taginfNFe(stdClass $std)
1301
    {
1302
        $possible = [
1303
            'chNFe',
1304
            'SegCodBarra',
1305
            'indReentrega',
1306
            'infUnidTransp',
1307
            'peri',
1308
            'nItem'
1309
        ];
1310
        $std = $this->equilizeParameters($std, $possible);
1311
        $infNFe = $this->dom->createElement("infNFe");
1312
        $this->dom->addChild(
1313
            $infNFe,
1314
            "chNFe",
1315
            $std->chNFe,
1316
            true,
1317
            "Chave de Acesso NFe"
1318
        );
1319
        $this->dom->addChild(
1320
            $infNFe,
1321
            "SegCodBarra",
1322
            $std->SegCodBarra,
1323
            false,
1324
            "Segundo código de barras do NFe"
1325
        );
1326
        $this->dom->addChild(
1327
            $infNFe,
1328
            "indReentrega",
1329
            $std->indReentrega,
1330
            false,
1331
            "Indicador de Reentrega"
1332
        );
1333
        if ($std->infUnidTransp) {
1334
            foreach ($std->infUnidTransp as $value) {
1335
                $this->dom->appChild(
1336
                    $infNFe,
1337
                    $this->taginfUnidTransp($value),
1338
                    'Falta tag "infUnidTransp"'
1339
                );
1340
            }
1341
        }
1342
        if ($std->peri) {
1343
            foreach ($std->peri as $value) {
1344
                $this->dom->appChild($infNFe, $this->tagperi($value), 'Falta tag "peri"');
1345
            }
1346
        }
1347
        $this->infNFe[$std->nItem][] = $infNFe;
1348
        return $infNFe;
1349
    }
1350
1351
    /**
1352
     * taginfMDFeTransp
1353
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infMDFeTransp
1354
     *
1355
     * @param  stdClass $std
1356
     * @return DOMElement
1357
     */
1358
    public function taginfMDFeTransp(stdClass $std)
1359
    {
1360
        $possible = [
1361
            'chMDFe',
1362
            'indReentrega',
1363
            'nItem'
1364
        ];
1365
        $std = $this->equilizeParameters($std, $possible);
1366
        $infMDFeTransp = $this->dom->createElement("infMDFeTransp");
1367
        $this->dom->addChild(
1368
            $infMDFeTransp,
1369
            "chMDFe",
1370
            $std->chMDFe,
1371
            true,
1372
            "Chave de Acesso NFe"
1373
        );
1374
        $this->dom->addChild(
1375
            $infMDFeTransp,
1376
            "indReentrega",
1377
            $std->indReentrega,
1378
            false,
1379
            "Indicador de Reentrega"
1380
        );
1381
        if ($std->infUnidTransp) {
1382
            foreach ($std->infUnidTransp as $value) {
1383
                $this->dom->appChild(
1384
                    $infMDFeTransp,
1385
                    $this->taginfUnidTransp($value),
1386
                    'Falta tag "infUnidTransp"'
1387
                );
1388
            }
1389
        }
1390
        if ($std->peri) {
1391
            foreach ($std->peri as $value) {
1392
                $this->dom->appChild(
1393
                    $infMDFeTransp,
1394
                    $this->tagperi($value),
1395
                    'Falta tag "peri"'
1396
                );
1397
            }
1398
        }
1399
        $this->infMDFeTransp[$std->nItem][] = $infMDFeTransp;
1400
        return $infMDFeTransp;
1401
    }
1402
1403
    /**
1404
     * taginfUnidTransp
1405
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/infUnidTransp
1406
     *
1407
     * @param  stdClass $std
1408
     * @return DOMElement
1409
     */
1410
    private function taginfUnidTransp(stdClass $std)
1411
    {
1412
        $possible = [
1413
            'tpUnidTransp',
1414
            'idUnidTransp',
1415
            'qtdRat',
1416
            'lacUnidTransp',
1417
            'infUnidCarga'
1418
        ];
1419
        $std = $this->equilizeParameters($std, $possible);
1420
        $infUnidTransp = $this->dom->createElement("infUnidTransp");
1421
        $this->dom->addChild(
1422
            $infUnidTransp,
1423
            "tpUnidTransp",
1424
            $std->tpUnidTransp,
1425
            true,
1426
            "Tipo da Unidade de Transporte"
1427
        );
1428
        $this->dom->addChild(
1429
            $infUnidTransp,
1430
            "idUnidTransp",
1431
            $std->idUnidTransp,
1432
            false,
1433
            "Identificação da Unidade de Transporte"
1434
        );
1435
        if ($std->lacUnidTransp != null) {
1436
            $possible = [
1437
                'nLacre'
1438
            ];
1439
            $stdlacUnidTransp = $this->equilizeParameters($std->lacUnidTransp, $possible);
1440
            foreach ($stdlacUnidTransp->nLacre as $nLacre) {
1441
                $lacUnidTransp = $this->dom->createElement("lacUnidTransp");
1442
                $this->dom->addChild(
1443
                    $lacUnidTransp,
1444
                    "nLacre",
1445
                    $nLacre,
1446
                    true,
1447
                    "Número do lacre"
1448
                );
1449
                $this->dom->appChild(
1450
                    $infUnidTransp,
1451
                    $lacUnidTransp,
1452
                    'Falta tag "infUnidTransp"'
1453
                );
1454
            }
1455
        }
1456
        if ($std->infUnidCarga) {
1457
            foreach ($std->infUnidCarga as $value) {
1458
                $this->dom->appChild(
1459
                    $infUnidTransp,
1460
                    $this->taginfUnidCarga($value),
1461
                    'Falta tag "infUnidCarga"'
1462
                );
1463
            }
1464
        }
1465
        $this->dom->addChild(
1466
            $infUnidTransp,
1467
            "qtdRat",
1468
            $this->conditionalNumberFormatting($std->qtdRat),
1469
            false,
1470
            "Quantidade rateada (Peso,Volume) "
1471
        );
1472
        return $infUnidTransp;
1473
    }
1474
1475
    /**
1476
     * taginfUnidCarga
1477
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/infUnidCarga
1478
     *
1479
     * @param  stdClass $std
1480
     * @return DOMElement
1481
     */
1482
    private function taginfUnidCarga(stdClass $std)
1483
    {
1484
        $possible = [
1485
            'tpUnidCarga',
1486
            'idUnidCarga',
1487
            'lacUnidCarga',
1488
            'qtdRat'
1489
        ];
1490
        $std = $this->equilizeParameters($std, $possible);
1491
        $infUnidCarga = $this->dom->createElement("infUnidCarga");
1492
        $this->dom->addChild(
1493
            $infUnidCarga,
1494
            "tpUnidCarga",
1495
            $std->tpUnidCarga,
1496
            false,
1497
            "Tipo da Unidade de Carga"
1498
        );
1499
        $this->dom->addChild(
1500
            $infUnidCarga,
1501
            "idUnidCarga",
1502
            $std->idUnidCarga,
1503
            false,
1504
            "Identificação da Unidade de Carga "
1505
        );
1506
        if ($std->lacUnidCarga != null) {
1507
            $possible = [
1508
                'nLacre'
1509
            ];
1510
            $stdlacUnidCarga = $this->equilizeParameters($std->lacUnidCarga, $possible);
1511
            foreach ($stdlacUnidCarga->nLacre as $nLacre) {
1512
                $lacUnidCarga = $this->dom->createElement("lacUnidCarga");
1513
                $this->dom->addChild(
1514
                    $lacUnidCarga,
1515
                    "nLacre",
1516
                    $nLacre,
1517
                    true,
1518
                    "Número do lacre"
1519
                );
1520
                $this->dom->appChild(
1521
                    $infUnidCarga,
1522
                    $lacUnidCarga,
1523
                    'Falta tag "infUnidCarga"'
1524
                );
1525
            }
1526
        }
1527
        $this->dom->addChild(
1528
            $infUnidCarga,
1529
            "qtdRat",
1530
            $this->conditionalNumberFormatting($std->qtdRat),
1531
            false,
1532
            "Quantidade rateada (Peso,Volume) "
1533
        );
1534
        return $infUnidCarga;
1535
    }
1536
1537
    /**
1538
     * tagseg
1539
     * tag MDFe/infMDFe/seg
1540
     *
1541
     * @param  stdClass $std
1542
     * @return DOMElement
1543
     */
1544
    public function tagseg(stdClass $std)
1545
    {
1546
        $possible = [
1547
            'respSeg',
1548
            'CNPJ',
1549
            'CPF',
1550
            'infSeg',
1551
            'nApol',
1552
            'nAver'
1553
        ];
1554
        $std = $this->equilizeParameters($std, $possible);
1555
        $seg = $this->dom->createElement("seg");
1556
        $infResp = $this->dom->createElement("infResp");
1557
        $this->dom->addChild(
1558
            $infResp,
1559
            "respSeg",
1560
            $std->respSeg,
1561
            true,
1562
            "Responsável pelo seguro"
1563
        );
1564
        $this->dom->addChild(
1565
            $infResp,
1566
            "CNPJ",
1567
            $std->CNPJ,
1568
            false,
1569
            "Número do CNPJ do responsável pelo seguro"
1570
        );
1571
        $this->dom->addChild(
1572
            $infResp,
1573
            "CPF",
1574
            $std->CPF,
1575
            false,
1576
            "Número do CPF do responsável pelo seguro"
1577
        );
1578
        $this->dom->appChild($seg, $infResp, 'Falta tag "seg"');
1579
        if ($std->infSeg != null) {
1580
            $possible = [
1581
                'xSeg',
1582
                'CNPJ'
1583
            ];
1584
            $stdinfSeg = $this->equilizeParameters($std->infSeg, $possible);
1585
            $infSeg = $this->dom->createElement("infSeg");
1586
            $this->dom->addChild(
1587
                $infSeg,
1588
                "xSeg",
1589
                $stdinfSeg->xSeg,
1590
                true,
1591
                "Nome da Seguradora"
1592
            );
1593
            $this->dom->addChild(
1594
                $infSeg,
1595
                "CNPJ",
1596
                $stdinfSeg->CNPJ,
1597
                false,
1598
                "Número do CNPJ da seguradora"
1599
            );
1600
            $this->dom->appChild($seg, $infSeg, 'Falta tag "seg"');
1601
        }
1602
        $this->dom->addChild(
1603
            $seg,
1604
            "nApol",
1605
            $std->nApol,
1606
            false,
1607
            "Número da Apólice"
1608
        );
1609
        if ($std->nAver != null) {
1610
            foreach ($std->nAver as $nAver) {
1611
                $this->dom->addChild(
1612
                    $seg,
1613
                    "nAver",
1614
                    $nAver,
1615
                    true,
1616
                    "Número da Averbação"
1617
                );
1618
            }
1619
        }
1620
        $this->seg[] = $seg;
1621
        return $seg;
1622
    }
1623
1624
    /**
1625
     * tagprodPred
1626
     * tag MDFe/infMDFe/prodPred
1627
     *
1628
     * @param  stdClass $std
1629
     * @return DOMElement
1630
     */
1631
    public function tagprodPred($std)
1632
    {
1633
        $possible = [
1634
            'tpCarga',
1635
            'xProd',
1636
            'cEAN',
1637
            'NCM',
1638
            'infLotacao'
1639
        ];
1640
        $std = $this->equilizeParameters($std, $possible);
1641
        $this->prodPred = $this->dom->createElement("prodPred");
1642
        $this->dom->addChild(
1643
            $this->prodPred,
1644
            "tpCarga",
1645
            $std->tpCarga,
1646
            true,
1647
            "Tipo da Carga. 01-Granel sólido; 02-Granel líquido; "
1648
                . "03-Frigorificada; 04-Conteinerizada; 05-Carga Geral; "
1649
                . "06-Neogranel; 07-Perigosa (granel sólido); 08-Perigosa (granel "
1650
                . "líquido); 09-Perigosa (carga frigorificada); 10-Perigosa "
1651
                . "(conteinerizada); 11-Perigosa (carga geral)."
1652
        );
1653
        $this->dom->addChild(
1654
            $this->prodPred,
1655
            "xProd",
1656
            $std->xProd,
1657
            true,
1658
            "Descrição do produto predominante"
1659
        );
1660
        $this->dom->addChild(
1661
            $this->prodPred,
1662
            "cEAN",
1663
            $std->cEAN,
1664
            false,
1665
            "GTIN (Global Trade Item Number) do produto, antigo código EAN "
1666
                . "ou código de barras"
1667
        );
1668
        $this->dom->addChild(
1669
            $this->prodPred,
1670
            "NCM",
1671
            $std->NCM,
1672
            false,
1673
            "Código NCM"
1674
        );
1675
        if (!empty($std->infLotacao)) {
1676
            $this->dom->appChild(
1677
                $this->prodPred,
1678
                $this->taginfLotacao($std->infLotacao),
1679
                'Falta tag "infLotacao"'
1680
            );
1681
        }
1682
        return $this->prodPred;
1683
    }
1684
1685
    /**
1686
     *
1687
     */
1688
    private function taginfLotacao(stdClass $std)
1689
    {
1690
        $possible = [
1691
            'infLocalCarrega',
1692
            'infLocalDescarrega'
1693
        ];
1694
        $std = $this->equilizeParameters($std, $possible);
1695
        $this->infLotacao = $this->dom->createElement("infLotacao");
1696
        if (!empty($std->infLocalCarrega)) {
1697
            $this->dom->appChild(
1698
                $this->infLotacao,
1699
                $this->tagLocalCarrega($std->infLocalCarrega),
1700
                'Falta tag "infLocalCarrega"'
1701
            );
1702
        }
1703
        if (!empty($std->infLocalDescarrega)) {
1704
            $this->dom->appChild(
1705
                $this->infLotacao,
1706
                $this->tagLocalDescarrega($std->infLocalDescarrega),
1707
                'Falta tag "infLocalDescarrega"'
1708
            );
1709
        }
1710
        return $this->infLotacao;
1711
    }
1712
1713
    /**
1714
     * Informações da localização do carregamento do MDF-e de carga lotação
1715
     *
1716
     */
1717
    private function tagLocalCarrega(stdClass $std)
1718
    {
1719
        $possible = [
1720
            'CEP',
1721
            'latitude',
1722
            'longitude'
1723
        ];
1724
        $std = $this->equilizeParameters($std, $possible);
1725
        $tagLocalCarrega = $this->dom->createElement("infLocalCarrega");
1726
        if (!empty($std->CEP)) {
1727
            $this->dom->addChild(
1728
                $tagLocalCarrega,
1729
                "CEP",
1730
                $std->CEP,
1731
                true,
1732
                "CEP onde foi carregado o MDF-e"
1733
            );
1734
        } else {
1735
            $this->dom->addChild(
1736
                $tagLocalCarrega,
1737
                "latitude",
1738
                $std->latitude,
1739
                true,
1740
                "Latitude do ponto geográfico onde foi carregado o MDF-e"
1741
            );
1742
            $this->dom->addChild(
1743
                $tagLocalCarrega,
1744
                "longitude",
1745
                $std->longitude,
1746
                true,
1747
                "Longitude do ponto geográfico onde foi carregado o MDF-e"
1748
            );
1749
        }
1750
        return $tagLocalCarrega;
1751
    }
1752
1753
    /**
1754
     * Informações da localização do descarregamento do MDF-e de carga lotação
1755
     */
1756
    private function tagLocalDescarrega(stdClass $std)
1757
    {
1758
        $possible = [
1759
            'CEP',
1760
            'latitude',
1761
            'longitude'
1762
        ];
1763
        $std = $this->equilizeParameters($std, $possible);
1764
        $tagLocalDescarrega = $this->dom->createElement("infLocalDescarrega");
1765
        if (!empty($std->CEP)) {
1766
            $this->dom->addChild(
1767
                $tagLocalDescarrega,
1768
                "CEP",
1769
                $std->CEP,
1770
                true,
1771
                "CEP onde foi descarregado o MDF-e"
1772
            );
1773
        } else {
1774
            $this->dom->addChild(
1775
                $tagLocalDescarrega,
1776
                "latitude",
1777
                $std->latitude,
1778
                true,
1779
                "Latitude do ponto geográfico onde foi descarregado o MDF-e"
1780
            );
1781
            $this->dom->addChild(
1782
                $tagLocalDescarrega,
1783
                "longitude",
1784
                $std->longitude,
1785
                true,
1786
                "Longitude do ponto geográfico onde foi descarregado o MDF-e"
1787
            );
1788
        }
1789
        return $tagLocalDescarrega;
1790
    }
1791
1792
    /**
1793
     * tagTot
1794
     * tag MDFe/infMDFe/tot
1795
     *
1796
     * @param  stdClass $std
1797
     * @return DOMElement
1798
     */
1799
    public function tagtot(stdClass $std)
1800
    {
1801
        $possible = [
1802
            'qCTe',
1803
            'qNFe',
1804
            'qMDFe',
1805
            'vCarga',
1806
            'cUnid',
1807
            'qCarga'
1808
        ];
1809
        $std = $this->equilizeParameters($std, $possible);
1810
        if (!isset($std->qCTe)) {
1811
            $std->qCTe = 0;
1812
            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...
1813
                $std->qCTe += count($infCTe);
1814
            }
1815
            if ($std->qCTe == 0) {
1816
                $std->qCTe = '';
1817
            }
1818
        }
1819
        if (!isset($std->qNFe)) {
1820
            $std->qNFe = 0;
1821
            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...
1822
                $std->qNFe += count($infNFe);
1823
            }
1824
            if ($std->qNFe == 0) {
1825
                $std->qNFe = '';
1826
            }
1827
        }
1828
        if (!isset($std->qMDFe)) {
1829
            $std->qMDFe = 0;
1830
            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...
1831
                $std->qMDFe += count($infMDFeTransp);
1832
            }
1833
            if ($std->qMDFe == 0) {
1834
                $std->qMDFe = '';
1835
            }
1836
        }
1837
        $tot = $this->dom->createElement("tot");
1838
        $this->dom->addChild(
1839
            $tot,
1840
            "qCTe",
1841
            $std->qCTe,
1842
            false,
1843
            "Quantidade total de CT-e relacionados no Manifesto"
1844
        );
1845
        $this->dom->addChild(
1846
            $tot,
1847
            "qNFe",
1848
            $std->qNFe,
1849
            false,
1850
            "Quantidade total de NF-e relacionados no Manifesto"
1851
        );
1852
        $this->dom->addChild(
1853
            $tot,
1854
            "qMDFe",
1855
            $std->qMDFe,
1856
            false,
1857
            "Quantidade total de MDF-e relacionados no Manifesto"
1858
        );
1859
        $this->dom->addChild(
1860
            $tot,
1861
            "vCarga",
1862
            $this->conditionalNumberFormatting($std->vCarga),
1863
            true,
1864
            "Valor total da mercadoria/carga transportada"
1865
        );
1866
        $this->dom->addChild(
1867
            $tot,
1868
            "cUnid",
1869
            $std->cUnid,
1870
            true,
1871
            "Código da unidade de medida do Peso Bruto da Carga / Mercadoria Transportada"
1872
        );
1873
        $this->dom->addChild(
1874
            $tot,
1875
            "qCarga",
1876
            $this->conditionalNumberFormatting($std->qCarga, 4),
1877
            true,
1878
            "Peso Bruto Total da Carga / Mercadoria Transportada"
1879
        );
1880
        $this->tot = $tot;
1881
        return $tot;
1882
    }
1883
1884
    /**
1885
     * tagLacres
1886
     * tag MDFe/infMDFe/lacres
1887
     *
1888
     * @param  stdClass $std
1889
     * @return DOMElement
1890
     */
1891
    public function taglacres(stdClass $std)
1892
    {
1893
        $possible = [
1894
            'nLacre'
1895
        ];
1896
        $std = $this->equilizeParameters($std, $possible);
1897
        $lacres = $this->dom->createElement("lacres");
1898
        $this->dom->addChild(
1899
            $lacres,
1900
            "nLacre",
1901
            $std->nLacre,
1902
            false,
1903
            "Número do lacre"
1904
        );
1905
        $this->lacres[] = $lacres; //array de DOMNode
1906
        return $this->lacres;
1907
    }
1908
1909
    /**
1910
     * taginfAdic
1911
     * Grupo de Informações Adicionais Z01 pai A01
1912
     * tag MDFe/infMDFe/infAdic (opcional)
1913
     *
1914
     * @param  stdClass $std
1915
     * @return DOMElement
1916
     */
1917
    public function taginfAdic(stdClass $std)
1918
    {
1919
        $possible = [
1920
            'infAdFisco',
1921
            'infCpl'
1922
        ];
1923
        $std = $this->equilizeParameters($std, $possible);
1924
        $infAdic = $this->dom->createElement("infAdic");
1925
        $this->dom->addChild(
1926
            $infAdic,
1927
            "infAdFisco",
1928
            $std->infAdFisco,
1929
            false,
1930
            "Informações Adicionais de Interesse do Fisco"
1931
        );
1932
        $this->dom->addChild(
1933
            $infAdic,
1934
            "infCpl",
1935
            $std->infCpl,
1936
            false,
1937
            "Informações Complementares de interesse do Contribuinte"
1938
        );
1939
        $this->infAdic = $infAdic;
1940
        return $infAdic;
1941
    }
1942
1943
    /**
1944
     * tagautXML
1945
     * tag MDFe/infMDFe/autXML
1946
     *
1947
     * Autorizados para download do XML do MDF-e
1948
     *
1949
     * @param  stdClass $std
1950
     * @return DOMElement
1951
     */
1952
    public function tagautXML(stdClass $std)
1953
    {
1954
        $possible = [
1955
            'CNPJ',
1956
            'CPF'
1957
        ];
1958
        $std = $this->equilizeParameters($std, $possible);
1959
        $autXML = $this->dom->createElement("autXML");
1960
        $this->dom->addChild(
1961
            $autXML,
1962
            "CNPJ",
1963
            $std->CNPJ,
1964
            false,
1965
            "CNPJ do autorizado"
1966
        );
1967
        $this->dom->addChild(
1968
            $autXML,
1969
            "CPF",
1970
            $std->CPF,
1971
            false,
1972
            "CPF do autorizado"
1973
        );
1974
        $this->autXML[] = $autXML;
1975
        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 1975 which is incompatible with the return type documented by NFePHP\MDFe\Make::tagautXML of type DOMElement.
Loading history...
1976
    }
1977
1978
    /**
1979
     * buildInfModal
1980
     * tag MDFe/infMDFe/infModal
1981
     *
1982
     * @return DOMElement
1983
     */
1984
    private function buildInfModal()
1985
    {
1986
        $infModal = $this->dom->createElement("infModal");
1987
        $infModal->setAttribute("versaoModal", $this->versao);
1988
        $this->infModal = $infModal;
1989
        $modal = $this->ide->getElementsByTagName('modal')->item(0)->nodeValue;
1990
        /*
1991
         1 - Rodoviário;
1992
         2 - Aéreo;
1993
         3 - Aquaviário;
1994
         4 - Ferroviário;
1995
         */
1996
        if ($modal == '1') {
1997
            $this->tagrodo();
1998
        } elseif ($modal == '4') {
1999
            $this->tagferrov();
2000
        }
2001
        return $infModal;
2002
    }
2003
2004
    private function buildIde()
2005
    {
2006
        $this->dom->appChild($this->infMDFe, $this->ide, 'Falta tag "ide"');
2007
        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...
2008
            $node = $this->ide->getElementsByTagName('infPercurso')->item(0);
2009
            if (empty($node)) {
2010
                $node = $this->ide->getElementsByTagName('UFFim')->item(0);
2011
            } else {
2012
                if ($this->ide->getElementsByTagName('infPercurso')->length > 1) {
2013
                    $node = $this->ide->getElementsByTagName('infPercurso')
2014
                        ->item($this->ide->getElementsByTagName('infPercurso')
2015
                            ->length - 1);
2016
                }
2017
            }
2018
            $this->dom->insertAfter($percurso, $node);
2019
        }
2020
        $UFFim = $this->ide->getElementsByTagName('UFFim')->item(0);
2021
        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...
2022
            $this->dom->insertAfter($munCarrega, $UFFim);
2023
        }
2024
    }
2025
2026
    /**
2027
     * tagAereo
2028
     * tag MDFe/infMDFe/infModal/aereo
2029
     *
2030
     * @return DOMElement
2031
     */
2032
2033
    public function tagaereo(stdClass $std)
2034
    {
2035
        $possible = [
2036
            'nac',
2037
            'matr',
2038
            'nVoo',
2039
            'cAerEmb',
2040
            'cAerDes',
2041
            'dVoo'
2042
        ];
2043
        $std = $this->equilizeParameters($std, $possible);
2044
        $aereo = $this->dom->createElement("aereo");
2045
        $identificador = '[1] <aereo> - ';
2046
        $this->dom->addChild(
2047
            $aereo,
2048
            "nac",
2049
            $std->nac,
2050
            true,
2051
            $identificador . "Marca da Nacionalidade da aeronave"
2052
        );
2053
        $this->dom->addChild(
2054
            $aereo,
2055
            "matr",
2056
            $std->matr,
2057
            true,
2058
            $identificador . "Marca de Matrícula da aeronave"
2059
        );
2060
        $this->dom->addChild(
2061
            $aereo,
2062
            "nVoo",
2063
            $std->nVoo,
2064
            true,
2065
            $identificador . "Número do Vôo"
2066
        );
2067
        $this->dom->addChild(
2068
            $aereo,
2069
            "cAerEmb",
2070
            $std->cAerEmb,
2071
            true,
2072
            $identificador . "Aeródromo de Embarque - Código IATA"
2073
        );
2074
        $this->dom->addChild(
2075
            $aereo,
2076
            "cAerDes",
2077
            $std->cAerDes,
2078
            true,
2079
            $identificador . "Aeródromo de Destino - Código IATA"
2080
        );
2081
        $this->dom->addChild(
2082
            $aereo,
2083
            "dVoo",
2084
            $std->dVoo,
2085
            true,
2086
            $identificador . "Data do Vôo"
2087
        );
2088
        $this->aereo = $aereo;
2089
        return $aereo;
2090
    }
2091
2092
2093
    /**
2094
     * tagtrem
2095
     * tag MDFe/infMDFe/infModal/ferrov/trem
2096
     *
2097
     * @return DOMElement
2098
     */
2099
2100
    public function tagtrem(stdClass $std)
2101
    {
2102
        $possible = [
2103
            'xPref',
2104
            'dhTrem',
2105
            'xOri',
2106
            'xDest',
2107
            'qVag'
2108
        ];
2109
        $std = $this->equilizeParameters($std, $possible);
2110
        $trem = $this->dom->createElement("trem");
2111
        $identificador = '[1] <trem> - ';
2112
        $this->dom->addChild(
2113
            $trem,
2114
            "xPref",
2115
            $std->xPref,
2116
            true,
2117
            $identificador . "Prefixo do Trem"
2118
        );
2119
        $this->dom->addChild(
2120
            $trem,
2121
            "dhTrem",
2122
            $std->dhTrem,
2123
            false,
2124
            $identificador . "Data e hora de liberação do trem na origem"
2125
        );
2126
        $this->dom->addChild(
2127
            $trem,
2128
            "xOri",
2129
            $std->xOri,
2130
            true,
2131
            $identificador . "Origem do Trem"
2132
        );
2133
        $this->dom->addChild(
2134
            $trem,
2135
            "xDest",
2136
            $std->xDest,
2137
            true,
2138
            $identificador . "Destino do Trem"
2139
        );
2140
        $this->dom->addChild(
2141
            $trem,
2142
            "qVag",
2143
            $std->qVag,
2144
            true,
2145
            $identificador . "Quantidade de vagões carregados"
2146
        );
2147
        $this->trem = $trem;
2148
        return $trem;
2149
    }
2150
2151
    /**
2152
     * tagVag
2153
     * tag MDFe/infMDFe/infModal/ferrov/trem/vag
2154
     *
2155
     * @param string $serie
2156
     * @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...
2157
     * @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...
2158
     * @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...
2159
     *
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...
2160
     * @return DOMElement
2161
     */
2162
2163
    public function tagVag(stdClass $std)
2164
    {
2165
        $possible = [
2166
            'pesoBC',
2167
            'pesoR',
2168
            'tpVag',
2169
            'serie',
2170
            'nVag',
2171
            'nSeq',
2172
            'TU'
2173
        ];
2174
        $identificador = '[1] <vag> - ';
2175
        $std = $this->equilizeParameters($std, $possible);
2176
        $vag = $this->dom->createElement("vag");
2177
        $this->dom->addChild(
2178
            $vag,
2179
            "pesoBC",
2180
            $std->pesoBC,
2181
            true,
2182
            $identificador . "Peso Base de Cálculo de Frete em Toneladas"
2183
        );
2184
        $this->dom->addChild(
2185
            $vag,
2186
            "pesoR",
2187
            $std->pesoR,
2188
            true,
2189
            $identificador . "Peso Real em Toneladas"
2190
        );
2191
        $this->dom->addChild(
2192
            $vag,
2193
            "tpVag",
2194
            $std->tpVag,
2195
            false,
2196
            $identificador . "Tipo de Vagão"
2197
        );
2198
        $this->dom->addChild(
2199
            $vag,
2200
            "serie",
2201
            $std->serie,
2202
            true,
2203
            $identificador . "Serie de Identificação do vagão"
2204
        );
2205
        $this->dom->addChild(
2206
            $vag,
2207
            "nVag",
2208
            $std->nVag,
2209
            true,
2210
            $identificador . "Número de Identificação do vagão"
2211
        );
2212
        $this->dom->addChild(
2213
            $vag,
2214
            "nSeq",
2215
            $std->nSeq,
2216
            false,
2217
            $identificador . "Sequência do vagão na composição"
2218
        );
2219
        $this->dom->addChild(
2220
            $vag,
2221
            "TU",
2222
            $this->conditionalNumberFormatting($std->TU, 3),
2223
            true,
2224
            $identificador . "Tonelada Útil"
2225
        );
2226
        $this->vag[] = $vag;
2227
        return $vag;
2228
    }
2229
2230
    /**
2231
     * tagaquav
2232
     * tag MDFe/infMDFe/infModal/aquav
2233
     *
2234
     * @param stdClass $std
2235
     * @return DOMElement
2236
     */
2237
2238
    public function tagaquav(stdClass $std)
2239
    {
2240
        $possible = [
2241
            'irin',
2242
            'tpEmb',
2243
            'cEmbar',
2244
            'xEmbar',
2245
            'nViag',
2246
            'cPrtEmb',
2247
            'cPrtDest',
2248
            'prtTrans',
2249
            'tpNav',
2250
            'infTermCarreg',
2251
            'infTermDescarreg',
2252
            'infEmbComb',
2253
            'infUnidCargaVazia',
2254
            'infUnidTranspVazia'
2255
        ];
2256
        $identificador = '[1] <aquav> - ';
2257
        $std = $this->equilizeParameters($std, $possible);
2258
        $aquav = $this->dom->createElement("aquav");
2259
        $this->dom->addChild(
2260
            $aquav,
2261
            "irin",
2262
            $std->irin,
2263
            true,
2264
            $identificador . "Irin do navio sempre deverá ser informado"
2265
        );
2266
        $this->dom->addChild(
2267
            $aquav,
2268
            "tpEmb",
2269
            $std->tpEmb,
2270
            true,
2271
            $identificador . "Código do tipo de embarcação"
2272
        );
2273
        $this->dom->addChild(
2274
            $aquav,
2275
            "cEmbar",
2276
            $std->cEmbar,
2277
            true,
2278
            $identificador . "Código da embarcação"
2279
        );
2280
        $this->dom->addChild(
2281
            $aquav,
2282
            "xEmbar",
2283
            $std->xEmbar,
2284
            true,
2285
            $identificador . "Nome da embarcação"
2286
        );
2287
        $this->dom->addChild(
2288
            $aquav,
2289
            "nViag",
2290
            $std->nViag,
2291
            true,
2292
            $identificador . "Número da Viagem"
2293
        );
2294
        $this->dom->addChild(
2295
            $aquav,
2296
            "cPrtEmb",
2297
            $std->cPrtEmb,
2298
            true,
2299
            $identificador . "Código do Porto de Embarque"
2300
        );
2301
        $this->dom->addChild(
2302
            $aquav,
2303
            "cPrtDest",
2304
            $std->cPrtDest,
2305
            true,
2306
            $identificador . "Código do Porto de Destino"
2307
        );
2308
        $this->dom->addChild(
2309
            $aquav,
2310
            "prtTrans",
2311
            $std->prtTrans,
2312
            false,
2313
            $identificador . "Porto de Transbordo"
2314
        );
2315
        $this->dom->addChild(
2316
            $aquav,
2317
            "tpNav",
2318
            $std->tpNav,
2319
            false,
2320
            $identificador . "Tipo de Navegação"
2321
        );
2322
        if ($std->infTermCarreg) {
2323
            foreach ($std->infTermCarreg as $value) {
2324
                $this->dom->appChild(
2325
                    $aquav,
2326
                    $this->taginfTermCarreg($value),
2327
                    'Falta tag "infTermCarreg"'
2328
                );
2329
            }
2330
        }
2331
        if ($std->infTermDescarreg) {
2332
            foreach ($std->infTermDescarreg as $value) {
2333
                $this->dom->appChild(
2334
                    $aquav,
2335
                    $this->taginfTermDescarreg($value),
2336
                    'Falta tag "infTermDescarreg"'
2337
                );
2338
            }
2339
        }
2340
        if ($std->infEmbComb) {
2341
            foreach ($std->infEmbComb as $value) {
2342
                $this->dom->appChild(
2343
                    $aquav,
2344
                    $this->taginfEmbComb($value),
2345
                    'Falta tag "infEmbComb"'
2346
                );
2347
            }
2348
        }
2349
        if ($std->infUnidCargaVazia) {
2350
            foreach ($std->infUnidCargaVazia as $value) {
2351
                $this->dom->appChild(
2352
                    $aquav,
2353
                    $this->taginfUnidCargaVazia($value),
2354
                    'Falta tag "infUnidCargaVazia"'
2355
                );
2356
            }
2357
        }
2358
        if ($std->infUnidTranspVazia) {
2359
            foreach ($std->infUnidTranspVazia as $value) {
2360
                $this->dom->appChild(
2361
                    $aquav,
2362
                    $this->taginfUnidTranspVazia($value),
2363
                    'Falta tag "infUnidTranspVazia"'
2364
                );
2365
            }
2366
        }
2367
        $this->aquav = $aquav;
2368
        return $aquav;
2369
    }
2370
2371
    /**
2372
     * infUnidTranspVazia
2373
     * tag MDFe/infMDFe/infModal/Aqua/infUnidTranspVazia
2374
     *
2375
     * @return DOMElement
2376
     */
2377
    public function taginfUnidTranspVazia(stdClass $std)
2378
    {
2379
        $possible = [
2380
            'idUnidTranspVazia',
2381
            'tpUnidTranspVazia'
2382
        ];
2383
        $identificador = '[1] <infUnidTranspVazia> - ';
2384
        $std = $this->equilizeParameters($std, $possible);
2385
        $infUnidTranspVazia = $this->dom->createElement("infUnidTranspVazia");
2386
        $this->dom->addChild(
2387
            $infUnidTranspVazia,
2388
            "idUnidTranspVazia",
2389
            $std->idUnidTranspVazia,
2390
            true,
2391
            $identificador . "dentificação da unidades de transporte vazia"
2392
        );
2393
        $this->dom->addChild(
2394
            $infUnidTranspVazia,
2395
            "tpUnidTranspVazia",
2396
            $std->tpUnidTranspVazia,
2397
            true,
2398
            $identificador . "Tipo da unidade de transporte vazia"
2399
        );
2400
        return $infUnidTranspVazia;
2401
    }
2402
2403
    /**
2404
     * infUnidCargaVazia
2405
     * tag MDFe/infMDFe/infModal/Aqua/infUnidCargaVazia
2406
     *
2407
     * @return DOMElement
2408
     */
2409
    public function taginfUnidCargaVazia(stdClass $std)
2410
    {
2411
        $possible = [
2412
            'idUnidCargaVazia',
2413
            'tpUnidCargaVazia'
2414
        ];
2415
        $identificador = '[1] <infUnidCargaVazia> - ';
2416
        $std = $this->equilizeParameters($std, $possible);
2417
        $infUnidCargaVazia = $this->dom->createElement("infUnidCargaVazia");
2418
        $this->dom->addChild(
2419
            $infUnidCargaVazia,
2420
            "idUnidCargaVazia",
2421
            $std->idUnidCargaVazia,
2422
            true,
2423
            $identificador . "Identificação da unidades de carga vazia"
2424
        );
2425
        $this->dom->addChild(
2426
            $infUnidCargaVazia,
2427
            "tpUnidCargaVazia",
2428
            $std->tpUnidCargaVazia,
2429
            true,
2430
            $identificador . "Tipo da unidade de carga vazia"
2431
        );
2432
        return $infUnidCargaVazia;
2433
    }
2434
2435
    /**
2436
     * taginfTermDescarreg
2437
     * tag MDFe/infMDFe/infModal/Aqua/infTermDescarreg
2438
     *
2439
     * @return DOMElement
2440
     */
2441
    public function taginfTermDescarreg(stdClass $std)
2442
    {
2443
        $possible = [
2444
            'cTermDescarreg',
2445
            'xTermDescarreg'
2446
        ];
2447
        $identificador = '[1] <infTermDescarreg> - ';
2448
        $std = $this->equilizeParameters($std, $possible);
2449
        $infTermDescarreg = $this->dom->createElement("infTermDescarreg");
2450
        $this->dom->addChild(
2451
            $infTermDescarreg,
2452
            "cTermDescarreg",
2453
            $std->cTermDescarreg,
2454
            true,
2455
            $identificador . "Código do Terminal de Descarregamento"
2456
        );
2457
        $this->dom->addChild(
2458
            $infTermDescarreg,
2459
            "xTermDescarreg",
2460
            $std->xTermDescarreg,
2461
            true,
2462
            $identificador . "Nome do Terminal de Descarregamento"
2463
        );
2464
        return $infTermDescarreg;
2465
    }
2466
2467
    /**
2468
     * tagInfTermCarreg
2469
     * tag MDFe/infMDFe/infModal/aquav/infTermCarreg
2470
     *
2471
     * @return DOMElement
2472
     */
2473
    public function taginfTermCarreg(stdClass $std)
2474
    {
2475
        $possible = [
2476
            'cTermCarreg',
2477
            'xTermCarreg'
2478
        ];
2479
        $identificador = '[1] <infTermCarreg> - ';
2480
        $std = $this->equilizeParameters($std, $possible);
2481
        $infTermCarreg = $this->dom->createElement("infTermCarreg");
2482
2483
        $this->dom->addChild(
2484
            $infTermCarreg,
2485
            "cTermCarreg",
2486
            $std->cTermCarreg,
2487
            true,
2488
            $identificador . "Código do Terminal de Carregamento"
2489
        );
2490
        $this->dom->addChild(
2491
            $infTermCarreg,
2492
            "xTermCarreg",
2493
            $std->xTermCarreg,
2494
            true,
2495
            $identificador . "Nome do Terminal de Carregamento"
2496
        );
2497
        return $infTermCarreg;
2498
    }
2499
2500
    /**
2501
     * tagInfTermCarreg
2502
     * tag MDFe/infMDFe/infModal/aquav/infEmbComb
2503
     *
2504
     * @param stdClass $std
2505
     * @return DOMElement
2506
     */
2507
    public function taginfEmbComb(stdClass $std)
2508
    {
2509
        $possible = [
2510
            'cEmbComb',
2511
            'xBalsa'
2512
        ];
2513
        $identificador = '[1] <infEmbComb> - ';
2514
        $std = $this->equilizeParameters($std, $possible);
2515
        $infEmbComb = $this->dom->createElement("infEmbComb");
2516
2517
        $this->dom->addChild(
2518
            $infEmbComb,
2519
            "cEmbComb",
2520
            $std->cEmbComb,
2521
            true,
2522
            $identificador . "Código da embarcação do comboio"
2523
        );
2524
        $this->dom->addChild(
2525
            $infEmbComb,
2526
            "xBalsa",
2527
            $std->xBalsa,
2528
            true,
2529
            $identificador . "Identificador da Balsa"
2530
        );
2531
        return $infEmbComb;
2532
    }
2533
2534
    /**
2535
     * condutor
2536
     * tag MDFe/infMDFe/infModal/rodo/veicTracao/condutor
2537
     *
2538
     * @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...
2539
     *
2540
     * @return DOMElement
2541
     */
2542
    private function tagcondutor(stdClass $std)
2543
    {
2544
        $possible = [
2545
            'xNome',
2546
            'CPF'
2547
        ];
2548
        $std = $this->equilizeParameters($std, $possible);
2549
        $condutor = $this->dom->createElement("condutor");
2550
        $identificador = '[4] <condutor> - ';
2551
        $this->dom->addChild(
2552
            $condutor,
2553
            "xNome",
2554
            $std->xNome,
2555
            true,
2556
            $identificador . "Nome do Condutor "
2557
        );
2558
        $this->dom->addChild(
2559
            $condutor,
2560
            "CPF",
2561
            $std->CPF,
2562
            true,
2563
            $identificador . "CPF do Condutor "
2564
        );
2565
        return $condutor;
2566
    }
2567
2568
    /**
2569
     * tagVeicTracao
2570
     * tag MDFe/infMDFe/infModal/rodo/veicTracao
2571
     *
2572
     * @param  stdClass $std
2573
     * @return DOMElement
2574
     */
2575
    public function tagveicTracao(stdClass $std)
2576
    {
2577
        $possible = [
2578
            'cInt',
2579
            'placa',
2580
            'RENAVAM',
2581
            'tara',
2582
            'capKG',
2583
            'capM3',
2584
            'prop',
2585
            'tpRod',
2586
            'tpCar',
2587
            'UF',
2588
            'condutor'
2589
        ];
2590
        $std = $this->equilizeParameters($std, $possible);
2591
        $veicTracao = $this->dom->createElement("veicTracao");
2592
        $identificador = '[4] <disp> - ';
2593
        $this->dom->addChild(
2594
            $veicTracao,
2595
            "cInt",
2596
            $std->cInt,
2597
            false,
2598
            $identificador . "Código interno do veículo"
2599
        );
2600
        $this->dom->addChild(
2601
            $veicTracao,
2602
            "placa",
2603
            $std->placa,
2604
            true,
2605
            $identificador . "Placa do veículo"
2606
        );
2607
        $this->dom->addChild(
2608
            $veicTracao,
2609
            "RENAVAM",
2610
            $std->RENAVAM,
2611
            false,
2612
            $identificador . "RENAVAM"
2613
        );
2614
        $this->dom->addChild(
2615
            $veicTracao,
2616
            "tara",
2617
            $std->tara,
2618
            true,
2619
            $identificador . "Tara em KG"
2620
        );
2621
        $this->dom->addChild(
2622
            $veicTracao,
2623
            "capKG",
2624
            $std->capKG,
2625
            false,
2626
            $identificador . "Capacidade em KG"
2627
        );
2628
        $this->dom->addChild(
2629
            $veicTracao,
2630
            "capM3",
2631
            $std->capM3,
2632
            false,
2633
            $identificador . "Capacidade em M3"
2634
        );
2635
        if ($std->prop != null) {
2636
            $possible = [
2637
                'CPF',
2638
                'CNPJ',
2639
                'RNTRC',
2640
                'xNome',
2641
                'IE',
2642
                'UF',
2643
                'tpProp'
2644
            ];
2645
            $identificadorProp = '[4] <prop> - ';
2646
            $stdprop = $this->equilizeParameters($std->prop, $possible);
2647
            $prop = $this->dom->createElement("prop");
2648
            if ($stdprop->CPF) {
2649
                $this->dom->addChild(
2650
                    $prop,
2651
                    "CPF",
2652
                    $stdprop->CPF,
2653
                    true,
2654
                    $identificadorProp . "Número do CPF"
2655
                );
2656
            } else {
2657
                $this->dom->addChild(
2658
                    $prop,
2659
                    "CNPJ",
2660
                    $stdprop->CNPJ,
2661
                    true,
2662
                    $identificadorProp . "Número do CNPJ"
2663
                );
2664
            }
2665
            $this->dom->addChild(
2666
                $prop,
2667
                "RNTRC",
2668
                $stdprop->RNTRC,
2669
                true,
2670
                $identificadorProp . "RNTRC"
2671
            );
2672
            $this->dom->addChild(
2673
                $prop,
2674
                "xNome",
2675
                $stdprop->xNome,
2676
                true,
2677
                $identificadorProp . "Razão Social"
2678
            );
2679
            $this->dom->addChild(
2680
                $prop,
2681
                "IE",
2682
                $stdprop->IE,
2683
                false,
2684
                $identificadorProp . "Inscrição Estadual"
2685
            );
2686
            $this->dom->addChild(
2687
                $prop,
2688
                "UF",
2689
                $stdprop->UF,
2690
                false,
2691
                $identificadorProp . "Unidade da Federação"
2692
            );
2693
            $this->dom->addChild(
2694
                $prop,
2695
                "tpProp",
2696
                $stdprop->tpProp,
2697
                true,
2698
                $identificadorProp . "Tipo Proprietário"
2699
            );
2700
            $this->dom->appChild($veicTracao, $prop, 'Falta tag "veicTracao"');
2701
        }
2702
        if ($std->condutor) {
2703
            foreach ($std->condutor as $value) {
2704
                $this->dom->appChild(
2705
                    $veicTracao,
2706
                    $this->tagcondutor($value),
2707
                    'Falta tag "condutor"'
2708
                );
2709
            }
2710
        }
2711
        $this->dom->addChild(
2712
            $veicTracao,
2713
            "tpRod",
2714
            $std->tpRod,
2715
            true,
2716
            $identificador . "Tipo de rodado"
2717
        );
2718
        $this->dom->addChild(
2719
            $veicTracao,
2720
            "tpCar",
2721
            $std->tpCar,
2722
            true,
2723
            $identificador . "Tipo de carroceria"
2724
        );
2725
        $this->dom->addChild(
2726
            $veicTracao,
2727
            "UF",
2728
            $std->UF,
2729
            true,
2730
            $identificador . "UF de licenciamento do veículo"
2731
        );
2732
        $this->veicTracao = $veicTracao;
2733
        return $veicTracao;
2734
    }
2735
2736
    /**
2737
     * tagVeicReboque
2738
     * tag MDFe/infMDFe/infModal/rodo/VeicReboque
2739
     *
2740
     * @param  stdClass $std
2741
     * @return DOMElement
2742
     */
2743
    public function tagveicReboque(stdClass $std)
2744
    {
2745
        $possible = [
2746
            'cInt',
2747
            'placa',
2748
            'RENAVAM',
2749
            'tara',
2750
            'capKG',
2751
            'capM3',
2752
            'prop',
2753
            'tpCar',
2754
            'UF'
2755
        ];
2756
        $std = $this->equilizeParameters($std, $possible);
2757
        $veicReboque = $this->dom->createElement("veicReboque");
2758
        $identificador = '[4] <veicReboque> - ';
2759
        $this->dom->addChild(
2760
            $veicReboque,
2761
            "cInt",
2762
            $std->cInt,
2763
            false,
2764
            $identificador . "Código interno do veículo"
2765
        );
2766
        $this->dom->addChild(
2767
            $veicReboque,
2768
            "placa",
2769
            $std->placa,
2770
            true,
2771
            $identificador . "Placa do veículo"
2772
        );
2773
        $this->dom->addChild(
2774
            $veicReboque,
2775
            "RENAVAM",
2776
            $std->RENAVAM,
2777
            false,
2778
            $identificador . "RENAVAM"
2779
        );
2780
        $this->dom->addChild(
2781
            $veicReboque,
2782
            "tara",
2783
            $std->tara,
2784
            true,
2785
            $identificador . "Tara em KG"
2786
        );
2787
        $this->dom->addChild(
2788
            $veicReboque,
2789
            "capKG",
2790
            $std->capKG,
2791
            false,
2792
            $identificador . "Capacidade em KG"
2793
        );
2794
        $this->dom->addChild(
2795
            $veicReboque,
2796
            "capM3",
2797
            $std->capM3,
2798
            false,
2799
            $identificador . "Capacidade em M3"
2800
        );
2801
        if ($std->prop != null) {
2802
            $identificadorprop = '[4] <prop> - ';
2803
            $possible = [
2804
                'CPF',
2805
                'CNPJ',
2806
                'RNTRC',
2807
                'xNome',
2808
                'IE',
2809
                'UF',
2810
                'tpProp'
2811
            ];
2812
            $stdprop = $this->equilizeParameters($std->prop, $possible);
2813
            $prop = $this->dom->createElement("prop");
2814
            if ($stdprop->CPF) {
2815
                $this->dom->addChild(
2816
                    $prop,
2817
                    "CPF",
2818
                    $stdprop->CPF,
2819
                    true,
2820
                    $identificadorprop . "Número do CPF"
2821
                );
2822
            } else {
2823
                $this->dom->addChild(
2824
                    $prop,
2825
                    "CNPJ",
2826
                    $stdprop->CNPJ,
2827
                    true,
2828
                    $identificadorprop . "Número do CNPJ"
2829
                );
2830
            }
2831
            $this->dom->addChild(
2832
                $prop,
2833
                "RNTRC",
2834
                $stdprop->RNTRC,
2835
                true,
2836
                $identificadorprop . "RNTRC"
2837
            );
2838
            $this->dom->addChild(
2839
                $prop,
2840
                "xNome",
2841
                $stdprop->xNome,
2842
                true,
2843
                $identificadorprop . "Razão Social"
2844
            );
2845
            $this->dom->addChild(
2846
                $prop,
2847
                "IE",
2848
                $stdprop->IE,
2849
                false,
2850
                $identificadorprop . "Inscrição Estadual"
2851
            );
2852
            $this->dom->addChild(
2853
                $prop,
2854
                "UF",
2855
                $stdprop->UF,
2856
                false,
2857
                $identificadorprop . "Unidade da Federação"
2858
            );
2859
            $this->dom->addChild(
2860
                $prop,
2861
                "tpProp",
2862
                $stdprop->tpProp,
2863
                true,
2864
                $identificadorprop . "Tipo Proprietário"
2865
            );
2866
            $this->dom->appChild($veicReboque, $prop, 'Falta tag "veicReboque"');
2867
        }
2868
        $this->dom->addChild(
2869
            $veicReboque,
2870
            "tpCar",
2871
            $std->tpCar,
2872
            true,
2873
            $identificador . "Tipo de carroceria"
2874
        );
2875
        $this->dom->addChild(
2876
            $veicReboque,
2877
            "UF",
2878
            $std->UF,
2879
            true,
2880
            $identificador . "UF de licenciamento do veículo"
2881
        );
2882
        $this->veicReboque[] = $veicReboque;
2883
        return $veicReboque;
2884
    }
2885
2886
    /**
2887
     * tagcodAgPorto
2888
     * tag MDFe/infMDFe/infModal/rodo/codAgPorto
2889
     *
2890
     * @param  stdClass $std
2891
     * @return DOMElement
2892
     */
2893
    public function tagcodAgPorto(stdClass $std)
2894
    {
2895
        $possible = [
2896
            'codAgPorto'
2897
        ];
2898
        $std = $this->equilizeParameters($std, $possible);
2899
        $this->dom->addChild(
2900
            $this->rodo,
2901
            "codAgPorto",
2902
            $std->codAgPorto,
2903
            false,
2904
            "Código de Agendamento no porto"
2905
        );
2906
        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 2906 which is incompatible with the return type documented by NFePHP\MDFe\Make::tagcodAgPorto of type DOMElement.
Loading history...
2907
    }
2908
2909
    /**
2910
     * taglacRodo
2911
     * tag MDFe/infMDFe/infModal/rodo/lacRodo
2912
     *
2913
     * @param  stdClass $std
2914
     * @return DOMElement
2915
     */
2916
    public function taglacRodo(stdClass $std)
2917
    {
2918
        $possible = [
2919
            'nLacre'
2920
        ];
2921
        $std = $this->equilizeParameters($std, $possible);
2922
        $lacRodo = $this->dom->createElement("lacRodo");
2923
        $this->dom->addChild(
2924
            $lacRodo,
2925
            "nLacre",
2926
            $std->nLacre,
2927
            true,
2928
            "Número do Lacre"
2929
        );
2930
        $this->lacRodo[] = $lacRodo;
2931
        return $lacRodo;
2932
    }
2933
2934
    /**
2935
     * Informações do Responsável técnico ZD01 pai A01
2936
     * tag NFe/infNFe/infRespTec (opcional)
2937
     * @param stdClass $std
2938
     * @return DOMElement
2939
     * @throws RuntimeException
2940
     */
2941
    public function taginfRespTec(stdClass $std)
2942
    {
2943
        $possible = [
2944
            'CNPJ',
2945
            'xContato',
2946
            'email',
2947
            'fone',
2948
            'CSRT',
2949
            'idCSRT'
2950
        ];
2951
        $std = $this->equilizeParameters($std, $possible);
2952
        $infRespTec = $this->dom->createElement("infRespTec");
2953
        $this->dom->addChild(
2954
            $infRespTec,
2955
            "CNPJ",
2956
            $std->CNPJ,
2957
            true,
2958
            "Informar o CNPJ da pessoa jurídica responsável pelo sistema "
2959
                . "utilizado na emissão do documento fiscal eletrônico"
2960
        );
2961
        $this->dom->addChild(
2962
            $infRespTec,
2963
            "xContato",
2964
            $std->xContato,
2965
            true,
2966
            "Informar o nome da pessoa a ser contatada na empresa desenvolvedora "
2967
                . "do sistema utilizado na emissão do documento fiscal eletrônico"
2968
        );
2969
        $this->dom->addChild(
2970
            $infRespTec,
2971
            "email",
2972
            $std->email,
2973
            true,
2974
            "Informar o e-mail da pessoa a ser contatada na empresa "
2975
                . "desenvolvedora do sistema."
2976
        );
2977
        $this->dom->addChild(
2978
            $infRespTec,
2979
            "fone",
2980
            $std->fone,
2981
            true,
2982
            "Informar o telefone da pessoa a ser contatada na empresa "
2983
                . "desenvolvedora do sistema."
2984
        );
2985
        if (!empty($std->CSRT) && !empty($std->idCSRT)) {
2986
            $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...
2987
            $this->dom->addChild(
2988
                $infRespTec,
2989
                "idCSRT",
2990
                $std->idCSRT,
2991
                true,
2992
                "Identificador do CSRT utilizado para montar o hash do CSRT"
2993
            );
2994
            $this->dom->addChild(
2995
                $infRespTec,
2996
                "hashCSRT",
2997
                $std->CSRT,
2998
                true,
2999
                "hash do CSRT"
3000
            );
3001
        }
3002
        $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...
3003
        return $infRespTec;
3004
    }
3005
3006
    /**
3007
     * Metodo responsavel para montagem da tag ingPag - Informações do Pagamento do Frete
3008
     *
3009
     * @param stdClass $std
3010
     * @return DOMElement
3011
     * @throws RuntimeException
3012
     */
3013
    public function taginfPag(stdClass $std)
3014
    {
3015
        $possible = [
3016
            'xNome',
3017
            'CPF',
3018
            'CNPJ',
3019
            'idEstrangeiro',
3020
            'Comp',
3021
            'vContrato',
3022
            'indAltoDesemp',
3023
            'indPag',
3024
            'vAdiant',
3025
            'infPrazo',
3026
            'infBanc'
3027
        ];
3028
        $std = $this->equilizeParameters($std, $possible);
3029
        $infPag = $this->dom->createElement("infPag");
3030
        $identificador = '[4] <infPag> - ';
3031
        $this->dom->addChild(
3032
            $infPag,
3033
            "xNome",
3034
            $std->xNome,
3035
            true,
3036
            $identificador . "Nome do responsável pelo pgto"
3037
        );
3038
        if (!empty($std->CPF)) {
3039
            $this->dom->addChild(
3040
                $infPag,
3041
                "CPF",
3042
                $std->CPF,
3043
                true,
3044
                $identificador . "Número do CPF do responsável pelo pgto"
3045
            );
3046
        } elseif (!empty($std->CNPJ)) {
3047
            $this->dom->addChild(
3048
                $infPag,
3049
                "CNPJ",
3050
                $std->CNPJ,
3051
                true,
3052
                $identificador . "Número do CNPJ do responsável pelo pgto"
3053
            );
3054
        } else {
3055
            $this->dom->addChild(
3056
                $infPag,
3057
                "idEstrangeiro",
3058
                $std->idEstrangeiro,
3059
                true,
3060
                $identificador . "Identificador do responsável pelo pgto em "
3061
                    . "caso de ser estrangeiro"
3062
            );
3063
        }
3064
        foreach ($std->Comp as $value) {
3065
            $this->dom->appChild($infPag, $this->compPag($value), 'Falta tag "Comp"');
3066
        }
3067
        $this->dom->addChild(
3068
            $infPag,
3069
            "vContrato",
3070
            $std->vContrato,
3071
            true,
3072
            $identificador . "Valor total do contrato"
3073
        );
3074
        $this->dom->addChild(
3075
            $infPag,
3076
            "indAltoDesemp",
3077
            $std->indAltoDesemp,
3078
            false,
3079
            $identificador . "Indicador de operação de transporte de alto desempenho"
3080
        );
3081
        $this->dom->addChild(
3082
            $infPag,
3083
            "indPag",
3084
            $std->indPag,
3085
            true,
3086
            $identificador . "Indicador da Forma de Pagamento"
3087
        );
3088
        if ($std->indPag == 1) {
3089
            $this->dom->addChild(
3090
                $infPag,
3091
                "vAdiant",
3092
                $this->conditionalNumberFormatting($std->vAdiant),
3093
                false,
3094
                $identificador . "Valor do Adiantamento"
3095
            );
3096
        }
3097
        if ($std->indPag == 1) {
3098
            foreach ($std->infPrazo as $value) {
3099
                $this->dom->appChild($infPag, $this->infPrazo($value), 'Falta tag "infPrazo"');
3100
            }
3101
        }
3102
        $this->dom->appChild($infPag, $this->infBanc($std->infBanc), 'Falta tag "infBanc"');
3103
        $this->infPag[] = $infPag;
3104
        return $infPag;
3105
    }
3106
3107
    /**
3108
     * Componentes do Pagamento do Frete
3109
     * @param stdClass
3110
     *
3111
     */
3112
    private function compPag(stdClass $std)
3113
    {
3114
        $possible = [
3115
            'tpComp',
3116
            'vComp',
3117
            'xComp'
3118
        ];
3119
        $stdComp = $this->equilizeParameters($std, $possible);
3120
        $comp = $this->dom->createElement("Comp");
3121
        $identificador = '[4] <Comp> - ';
3122
        $this->dom->addChild(
3123
            $comp,
3124
            "tpComp",
3125
            $stdComp->tpComp,
3126
            true,
3127
            $identificador . "Tipo do Componente"
3128
        );
3129
        $this->dom->addChild(
3130
            $comp,
3131
            "vComp",
3132
            $stdComp->vComp,
3133
            true,
3134
            $identificador . "Valor do Componente"
3135
        );
3136
        $this->dom->addChild(
3137
            $comp,
3138
            "xComp",
3139
            $stdComp->xComp,
3140
            false,
3141
            $identificador . "Descrição do componente do tipo Outros"
3142
        );
3143
        return $comp;
3144
    }
3145
3146
    /***
3147
     * Informações do pagamento a prazo. Obs: Informar somente se indPag for à Prazo.
3148
     *
3149
     */
3150
    private function infPrazo(stdClass $std)
3151
    {
3152
        $possible = [
3153
            'nParcela',
3154
            'dVenc',
3155
            'vParcela'
3156
        ];
3157
        $stdPraz = $this->equilizeParameters($std, $possible);
3158
        $prazo = $this->dom->createElement("infPrazo");
3159
        $identificador = '[4] <infPrazo> - ';
3160
        $this->dom->addChild(
3161
            $prazo,
3162
            "nParcela",
3163
            $stdPraz->nParcela,
3164
            false,
3165
            $identificador . "Número da parcela"
3166
        );
3167
        $this->dom->addChild(
3168
            $prazo,
3169
            "dVenc",
3170
            $stdPraz->dVenc,
3171
            false,
3172
            $identificador . "Data de vencimento da Parcela (AAAA-MMDD)"
3173
        );
3174
        $this->dom->addChild(
3175
            $prazo,
3176
            "vParcela",
3177
            $this->conditionalNumberFormatting($stdPraz->vParcela),
3178
            true,
3179
            $identificador . "Valor da Parcela"
3180
        );
3181
        return $prazo;
3182
    }
3183
3184
    /**
3185
     * Informações bancárias.
3186
     *
3187
     */
3188
    private function infBanc(stdClass $std)
3189
    {
3190
        $possible = [
3191
            'codBanco',
3192
            'codAgencia',
3193
            'CNPJIPEF',
3194
            'PIX'
3195
        ];
3196
        $stdBanco = $this->equilizeParameters($std, $possible);
3197
        $banco = $this->dom->createElement("infBanc");
3198
        $identificador = '[4] <infBanc> - ';
3199
        if (!empty($stdBanco->codBanco)) {
3200
            $this->dom->addChild(
3201
                $banco,
3202
                "codBanco",
3203
                $stdBanco->codBanco,
3204
                true,
3205
                $identificador . "Número do banco"
3206
            );
3207
            $this->dom->addChild(
3208
                $banco,
3209
                "codAgencia",
3210
                $stdBanco->codAgencia,
3211
                true,
3212
                $identificador . "Número da Agência"
3213
            );
3214
        } elseif (!empty($stdBanco->CNPJIPEF)) {
3215
            $this->dom->addChild(
3216
                $banco,
3217
                "CNPJIPEF",
3218
                $stdBanco->CNPJIPEF,
3219
                true,
3220
                $identificador . "Número do CNPJ da Instituição de pagamento Eletrônico do Frete"
3221
            );
3222
        } else {
3223
            $this->dom->addChild(
3224
                $banco,
3225
                "PIX",
3226
                $stdBanco->PIX,
3227
                true,
3228
                $identificador . "Chave PIX"
3229
            );
3230
        }
3231
        return $banco;
3232
    }
3233
3234
    /**
3235
     * buildMDFe
3236
     * Tag raiz da MDFe
3237
     * tag MDFe DOMNode
3238
     * Função chamada pelo método [ monta ]
3239
     *
3240
     * @return DOMElement
3241
     */
3242
    protected function buildMDFe()
3243
    {
3244
        if (empty($this->MDFe)) {
3245
            $this->MDFe = $this->dom->createElement("MDFe");
3246
            $this->MDFe->setAttribute("xmlns", "http://www.portalfiscal.inf.br/mdfe");
3247
        }
3248
        return $this->MDFe;
3249
    }
3250
3251
    /**
3252
     * checkMDFKey
3253
     * Remonta a chave do MDFe de 44 digitos com base em seus dados
3254
     * Isso é útil no caso da chave informada estar errada
3255
     * se a chave estiver errada a mesma é substituida
3256
     *
3257
     * @param object $dom
3258
     */
3259
    private function checkMDFKey($dom)
3260
    {
3261
        $infMDFe = $dom->getElementsByTagName("infMDFe")->item(0);
3262
        $ide = $dom->getElementsByTagName("ide")->item(0);
3263
        $emit = $dom->getElementsByTagName("emit")->item(0);
3264
        $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue;
3265
        $dhEmi = $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue;
3266
        if (!empty($emit->getElementsByTagName('CNPJ')->item(0)->nodeValue)) {
3267
            $doc = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3268
        } else {
3269
            $doc = $emit->getElementsByTagName('CPF')->item(0)->nodeValue;
3270
        }
3271
        $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue;
3272
        $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
3273
        $nMDF = $ide->getElementsByTagName('nMDF')->item(0)->nodeValue;
3274
        $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue;
3275
        $cNF = $ide->getElementsByTagName('cMDF')->item(0)->nodeValue;
3276
        $chave = str_replace('MDFe', '', $infMDFe->getAttribute("Id"));
3277
        $dt = new \DateTime($dhEmi);
3278
        $chaveMontada = Keys::build(
3279
            $cUF,
3280
            $dt->format('y'),
3281
            $dt->format('m'),
3282
            $doc,
3283
            $mod,
3284
            $serie,
3285
            $nMDF,
3286
            $tpEmis,
3287
            $cNF
3288
        );
3289
        //caso a chave contida na NFe esteja errada
3290
        //substituir a chave
3291
        if ($chaveMontada != $chave) {
3292
            $ide->getElementsByTagName('cDV')->item(0)->nodeValue = substr($chaveMontada, -1);
3293
            $infMDFe = $dom->getElementsByTagName("infMDFe")->item(0);
3294
            $infMDFe->setAttribute("Id", "MDFe" . $chaveMontada);
3295
            $infMDFe->setAttribute("versao", $this->versao);
3296
            $this->chMDFe = $chaveMontada;
3297
        }
3298
    }
3299
3300
    /**
3301
     * Retorna os erros detectados
3302
     * @return array
3303
     */
3304
    public function getErrors()
3305
    {
3306
        return $this->errors;
3307
    }
3308
3309
    /**
3310
     * Includes missing or unsupported properties in stdClass
3311
     * Replace all unsuported chars
3312
     *
3313
     * @param  stdClass $std
3314
     * @param  array $possible
3315
     * @return stdClass
3316
     */
3317
    private function equilizeParameters(stdClass $std, $possible)
3318
    {
3319
        return Strings::equilizeParameters($std, $possible, $this->replaceAccentedChars);
3320
    }
3321
3322
    /**
3323
     * Formatação numerica condicional
3324
     * @param string|float|int|null $value
3325
     * @param int $decimal
3326
     * @return string
3327
     */
3328
    protected function conditionalNumberFormatting($value = null, $decimal = 2)
3329
    {
3330
        if (is_numeric($value)) {
3331
            return number_format($value, $decimal, '.', '');
3332
        }
3333
        return null;
3334
    }
3335
}
3336