Passed
Push — master ( e7e57d...5a5376 )
by Roberto
11:50 queued 09:43
created

Make::conditionalNumberFormatting()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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