Passed
Pull Request — master (#108)
by
unknown
02:27
created

Make::CompPag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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

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

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

Loading history...
3076
    }
3077
}
3078