Passed
Push — master ( d728ab...44f17b )
by
unknown
53s queued 11s
created

Make::compPag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
3180
    }
3181
}
3182