Passed
Push — master ( 4ee088...7bd5bf )
by
unknown
02:17
created

Make::taginfGlobalizado()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 0
cts 17
cp 0
rs 9.6
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace NFePHP\CTe;
4
5
/**
6
 *
7
 * @category  Library
8
 * @package   nfephp-org/sped-cte
9
 * @copyright 2009-2016 NFePHP
10
 * @name      Make.php
11
 * @license   http://www.gnu.org/licenses/gpl.html GNU/GPL v.3
12
 * @link      http://github.com/nfephp-org/sped-cte for the canonical source repository
13
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
14
 */
15
16
use DOMElement;
17
use NFePHP\Common\DOMImproved as Dom;
18
use NFePHP\Common\Keys;
19
use NFePHP\Common\Strings;
20
use RuntimeException;
21
use stdClass;
22
23
class Make
24
{
25
    /**
26
     * @var array
27
     */
28
    public $errors = [];
29
30
    /**
31
     * versao
32
     * numero da versão do xml da CTe
33
     * @var string
34
     */
35
    public $versao = '3.00';
36
    /**
37
     * mod
38
     * modelo da CTe 57
39
     * @var integer
40
     */
41
    public $mod = 57;
42
    /**
43
     * chave da MDFe
44
     * @var string
45
     */
46
    public $chCTe = '';
47
    /**
48
     * xml
49
     * String com o xml do documento fiscal montado
50
     * @var string
51
     */
52
    public $xml = '';
53
    /**
54
     * dom
55
     * Variável onde será montado o xml do documento fiscal
56
     * @var \NFePHP\Common\Dom\Dom
57
     */
58
    public $dom;
59
    /**
60
     * tpAmb
61
     * tipo de ambiente
62
     * @var string
63
     */
64
    public $tpAmb = '2';
65
    /**
66
     * Modal do Cte
67
     * @var integer
68
     */
69
    private $modal = 0;
70
    /**
71
     * Tag CTe
72
     * @var \DOMNode
73
     */
74
    private $CTe = '';
75
    /**
76
     * Informações do CT-e
77
     * @var \DOMNode
78
     */
79
    private $infCte = '';
80
    /**
81
     * Identificação do CT-e
82
     * @var \DOMNode
83
     */
84
    private $ide = '';
85
    /**
86
     * Percurso do CT-e OS
87
     * @var \DOMNode
88
     */
89
    private $infPercurso = [];
90
    /**
91
     * Tipo do Serviço
92
     * @var integer
93
     */
94
    private $tpServ = 0;
95
    /**
96
     * Indicador do "papel" do tomador do serviço no CT-e
97
     * @var \DOMNode
98
     */
99
    private $toma3 = '';
100
    /**
101
     * Indicador do "papel" do tomador do serviço no CT-e
102
     * @var \DOMNode
103
     */
104
    private $toma4 = '';
105
    /**
106
     * Indicador do "papel" do tomador do serviço no CT-e OS
107
     * @var \DOMNode
108
     */
109
    private $toma = '';
110
    /**
111
     * Dados do endereço
112
     * @var \DOMNode
113
     */
114
    private $enderToma = '';
115
    /**
116
     * Dados complementares do CT-e para fins operacionais ou comerciais
117
     * @var \DOMNode
118
     */
119
    private $compl = '';
120
    /**
121
     * Previsão do fluxo da carga
122
     * @var \DOMNode
123
     */
124
    private $fluxo = '';
125
    /**
126
     * Passagem
127
     * @var array
128
     */
129
    private $pass = array();
130
    /**
131
     * Informações ref. a previsão de entrega
132
     * @var \DOMNode
133
     */
134
    private $entrega = '';
135
    /**
136
     * Entrega sem data definida
137
     * @var \DOMNode
138
     */
139
    private $semData = '';
140
    /**
141
     * Entrega com data definida
142
     * @var \DOMNode
143
     */
144
    private $comData = '';
145
    /**
146
     * Entrega no período definido
147
     * @var \DOMNode
148
     */
149
    private $noPeriodo = '';
150
    /**
151
     * Entrega sem hora definida
152
     * @var \DOMNode
153
     */
154
    private $semHora = '';
155
    /**
156
     * Entrega com hora definida
157
     * @var \DOMNode
158
     */
159
    private $comHora = '';
160
    /**
161
     * Entrega no intervalo de horário definido
162
     * @var \DOMNode
163
     */
164
    private $noInter = '';
165
    /**
166
     * Campo de uso livre do contribuinte
167
     * @var array
168
     */
169
    private $obsCont = array();
170
    /**
171
     * Campo de uso livre do contribuinte
172
     * @var array
173
     */
174
    private $obsFisco = array();
175
    /**
176
     * Identificação do Emitente do CT-e
177
     * @var \DOMNode
178
     */
179
    private $emit = '';
180
    /**
181
     * Endereço do emitente
182
     * @var \DOMNode
183
     */
184
    private $enderEmit = '';
185
    /**
186
     * Informações do Remetente das mercadorias transportadas pelo CT-e
187
     * @var \DOMNode
188
     */
189
    private $rem = '';
190
    /**
191
     * Dados do endereço
192
     * @var \DOMNode
193
     */
194
    private $enderReme = '';
195
    /**
196
     * Informações do Expedidor da Carga
197
     * @var \DOMNode
198
     */
199
    private $exped = '';
200
    /**
201
     * Dados do endereço
202
     * @var \DOMNode
203
     */
204
    private $enderExped = '';
205
    /**
206
     * Informações do Recebedor da Carga
207
     * @var \DOMNode
208
     */
209
    private $receb = '';
210
    /**
211
     * Dados do endereço
212
     * @var \DOMNode
213
     */
214
    private $enderReceb = '';
215
    /**
216
     * Informações do Destinatário do CT-e
217
     * @var \DOMNode
218
     */
219
    private $dest = '';
220
    /**
221
     * Dados do endereço
222
     * @var \DOMNode
223
     */
224
    private $enderDest = '';
225
    /**
226
     * Valores da Prestação de Serviço
227
     * @var \DOMNode
228
     */
229
    private $vPrest = '';
230
    /**
231
     * Componentes do Valor da Prestação
232
     * @var array
233
     */
234
    private $comp = array();
235
    /**
236
     * Informações relativas aos Impostos
237
     * @var \DOMNode
238
     */
239
    private $imp = '';
240
    /**
241
     * Observações adicionais da CT-e
242
     * @var string
243
     */
244
    private $xObs = '';
245
    /**
246
     * Grupo de informações do CT-e Normal e Substituto
247
     * @var \DOMNode
248
     */
249
    private $infCTeNorm = '';
250
    /**
251
     * Informações da Carga do CT-e
252
     * @var \DOMNode
253
     */
254
    private $infCarga = '';
255
    /**
256
     * Informações da Prestação do Serviço
257
     * @var \DOMNode
258
     */
259
    private $infServico = '';
260
    /**
261
     * Informações de quantidades da Carga do CT-e
262
     * @var \DOMNode
263
     */
264
    private $infQ = array();
265
    /**
266
     * Informações dos documentos transportados pelo CT-e Opcional para Redespacho Intermediario
267
     * e Serviço vinculado a multimodal.
268
     * @var \DOMNode
269
     */
270
    private $infDoc = array();
271
    /**
272
     * Informações das NF
273
     * @var array
274
     */
275
    private $infNF = array();
276
    /**
277
     * Informações das NF-e
278
     * @var array
279
     */
280
    private $infNFe = array();
281
    /**
282
     * Informações dos demais documentos
283
     * @var array
284
     */
285
    private $infOutros = array();
286
    /**
287
     * Informações dos demais documentos
288
     * @var array
289
     */
290
    private $infDocRef = array();
291
    /**
292
     * Informações das Unidades de Transporte (Carreta/Reboque/Vagão)
293
     * @var array
294
     */
295
    private $infUnidTransp = array();
296
    /**
297
     * Lacres das Unidades de Transporte
298
     * @var array
299
     */
300
    private $lacUnidTransp = array();
301
    /**
302
     * Informações das Unidades de Carga (Containeres/ULD/Outros)
303
     * @var array
304
     */
305
    private $infUnidCarga = array();
306
    /**
307
     * Lacres das Unidades de Carga
308
     * @var array
309
     */
310
    private $lacUnidCarga = array();
311
    /**
312
     * Documentos de Transporte Anterior
313
     * @var \DOMNode
314
     */
315
    private $docAnt = array();
316
    /**
317
     * Emissor do documento anterior
318
     * @var array
319
     */
320
    private $emiDocAnt = array();
321
    /**
322
     * Informações de identificação dos documentos de Transporte Anterior
323
     * @var array
324
     */
325
    private $idDocAnt = array();
326
    /**
327
     * Documentos de transporte anterior em papel
328
     * @var array
329
     */
330
    private $idDocAntPap = array();
331
    /**
332
     * Documentos de transporte anterior eletrônicos
333
     * @var array
334
     */
335
    private $idDocAntEle = array();
336
    /**
337
     * Informações de Seguro da Carga
338
     * @var array
339
     */
340
    private $seg = array();
341
    /**
342
     * Informações do modal
343
     * @var \DOMNode
344
     */
345
    private $infModal = '';
346
    /**
347
     * Preenchido quando for transporte de produtos classificados pela ONU como perigosos.
348
     * @var array
349
     */
350
    private $peri = array();
351
    /**
352
     * informações dos veículos transportados
353
     * @var array
354
     */
355
    private $veicNovos = array();
356
    /**
357
     * Dados da cobrança do CT-e
358
     * @var \DOMNode
359
     */
360
    private $cobr = '';
361
    /**
362
     * Dados da fatura
363
     * @var \DOMNode
364
     */
365
    private $fat = '';
366
    /**
367
     * Dados das duplicatas
368
     * @var array
369
     */
370
    private $dup = array();
371
    /**
372
     * Informações do CT-e de substituição
373
     * @var \DOMNode
374
     */
375
    private $infCteSub = '';
376
    /**
377
     * Informações do Serviço Vinculado a Multimodal
378
     * @var \DOMNode
379
     */
380
    private $infServVinc = '';
381
    /**
382
     * Informações do CT-e multimodal vinculado
383
     * @var \DOMNode
384
     */
385
    private $infCTeMultimodal = array();
386
    /**
387
     * Tomador é contribuinte do ICMS
388
     * @var \DOMNode
389
     */
390
    private $tomaICMS = '';
391
    /**
392
     * Informação da NFe emitida pelo Tomador
393
     * @var \DOMNode
394
     */
395
    private $refNFe = '';
396
    /**
397
     * Informação da NF ou CT emitido pelo Tomador
398
     * @var \DOMNode
399
     */
400
    private $refNF = '';
401
    /**
402
     * Informação da NF ou CT emitido pelo Tomador
403
     * @var \DOMNode
404
     */
405
    private $infCteComp = '';
406
    /**
407
     * Detalhamento do CT-e do tipo Anulação
408
     * @var \DOMNode
409
     */
410
    private $infCteAnu = '';
411
    /**
412
     * Informações do modal Rodoviário
413
     * @var \DOMNode
414
     */
415
    private $rodo = '';
416
    /**
417
     * Informações do modal Aéreo
418
     * @var \DOMNode
419
     */
420
    private $aereo = '';
421
    /**
422
     * Informações do modal Ferroviario
423
     * @var \DOMNode
424
     */
425
    private $ferrov = '';
426
427
    private $ferroEnv = '';
428
    /**
429
     * Informações do modal Aquaviario
430
     * @var \DOMNode
431
     */
432
    private $aquav = '';
433
    /**
434
     * Informações de Lacre para modal Aquaviario
435
     * @var array
436
     */
437
    private $lacre = array();
438
    /**
439
     * Informações de Balsa para modal Aquaviario
440
     * @var array
441
     */
442
    private $balsa = array();
443
    /**
444
     * Informações de Container para modal Aquaviario
445
     * @var array
446
     */
447
    private $detCont = array();
448
    /**
449
     * Informações dos documentos de conteiner para modal Aquaviario
450
     * @var array
451
     */
452
    private $infDocCont = array();
453
    /**
454
     * Informações de NF de conteiner para modal Aquaviario
455
     * @var array
456
     */
457
    private $infNFCont = array();
458
    /**
459
     * Informações de NFe de conteiner para modal Aquaviario
460
     * @var array
461
     */
462
    private $infNFeCont = array();
463
464
    /**
465
     * Informações do modal Dutoviário
466
     * @var \DOMNode
467
     */
468
    private $duto = '';
469
    /**
470
     * Ordens de Coleta associados
471
     * @var array
472
     */
473
    private $occ = array();
474
    /**
475
     * @var \DOMNode
476
     */
477
    private $emiOcc = array();
478
    /**
479
     * Informações de Vale Pedágio
480
     * @var array
481
     */
482
    private $valePed = array();
483
    /**
484
     * Dados dos Veículos
485
     * @var array
486
     */
487
    private $veic = array();
488
    /**
489
     * Proprietários do Veículo. Só preenchido quando o veículo não pertencer à empresa emitente do CT-e
490
     * @var array
491
     */
492
    private $prop = array();
493
    /**
494
     * Informações do CTe Multimodal
495
     * @var array
496
     */
497
    private $multimodal = '';
498
    /**
499
     * Informações do seguro no CTe Multimodal
500
     * @var array
501
     */
502
    private $segMultim = '';
503
    /**
504
     * Autorizados para download do XML do DF-e
505
     * @var array
506
     */
507
    private $autXML = array();
508
    /**
509
     * Dados do Fretamento - CTe-OS
510
     * @var
511
     */
512
    private $infFretamento;
513
    /**
514
     * @var DOMElement
515
     */
516
    protected $infRespTec;
517
    /**
518
     * @var DOMElement
519
     */
520
    protected $indAlteraToma;
521
    /**
522
     * @var DOMElement
523
     */
524
    protected $infGlobalizado;
525
    /**
526
     * @var boolean
527
     */
528
    protected $replaceAccentedChars = false;
529
530
    public function __construct()
531
    {
532
        $this->dom = new Dom('1.0', 'UTF-8');
0 ignored issues
show
Documentation Bug introduced by
It seems like new \NFePHP\Common\DOMImproved('1.0', 'UTF-8') of type object<NFePHP\Common\DOMImproved> is incompatible with the declared type object<NFePHP\Common\Dom\Dom> of property $dom.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
533
        $this->dom->preserveWhiteSpace = false;
534
        $this->dom->formatOutput = false;
535
    }
536
537
    /**
538
     * Returns xml string and assembly it is necessary
539
     * @return string
540
     */
541
    public function getXML()
542
    {
543
        if (empty($this->xml)) {
544
            $this->montaCTe();
545
        }
546
        return $this->xml;
547
    }
548
549
    /**
550
     * Retorns the key number of NFe (44 digits)
551
     * @return string
552
     */
553
    public function getChave()
554
    {
555
        return $this->chCTe;
556
    }
557
558
    /**
559
     * Returns the model of CTe 57 or 67
560
     * @return int
561
     */
562
    public function getModelo()
563
    {
564
        return $this->mod;
565
    }
566
567
    /**
568
     * Set character convertion to ASCII only ou not
569
     * @param bool $option
570
     */
571
    public function setOnlyAscii($option = false)
572
    {
573
        $this->replaceAccentedChars = $option;
574
    }
575
576
    /**
577
     * Call method of xml assembly. For compatibility only.
578
     * @return boolean
579
     */
580
    public function montaCTe()
581
    {
582
        return $this->monta();
583
    }
584
585
    /**
586
     * Monta o arquivo XML usando as tag's já preenchidas
587
     *
588
     * @return bool
589
     */
590
    public function monta()
591
    {
592
        $this->errors = $this->dom->errors;
593
        if ($this->mod == 57) {
594
            $this->buildCTe();
595
        } else {
596
            return $this->montaCTeOS();
597
        }
598
        if ($this->toma3 != '') {
599
            $this->dom->appChild($this->ide, $this->toma3, 'Falta tag "ide"');
600
        } else {
601
            $this->dom->appChild($this->ide, $this->toma4, 'Falta tag "ide"');
602
        }
603
        $this->dom->appChild($this->infCte, $this->ide, 'Falta tag "infCte"');
604
        if ($this->compl != '') {
605
            foreach ($this->obsCont as $obsCont) {
606
                $this->dom->appChild($this->compl, $obsCont, 'Falta tag "compl"');
607
            }
608
            foreach ($this->obsFisco as $obsFisco) {
609
                $this->dom->appChild($this->compl, $obsFisco, 'Falta tag "compl"');
610
            }
611
            $this->dom->appChild($this->infCte, $this->compl, 'Falta tag "infCte"');
612
        }
613
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "emit"');
614
        $this->dom->appChild($this->infCte, $this->emit, 'Falta tag "infCte"');
615
        if ($this->rem != '') {
616
            $this->dom->appChild($this->infCte, $this->rem, 'Falta tag "infCte"');
617
        }
618
        if ($this->exped != '') {
619
            $this->dom->appChild($this->infCte, $this->exped, 'Falta tag "infCte"');
620
        }
621
        if ($this->receb != '') {
622
            $this->dom->appChild($this->infCte, $this->receb, 'Falta tag "infCte"');
623
        }
624
        if ($this->dest != '') {
625
            $this->dom->appChild($this->infCte, $this->dest, 'Falta tag "infCte"');
626
        }
627
        foreach ($this->comp as $comp) {
628
            $this->dom->appChild($this->vPrest, $comp, 'Falta tag "vPrest"');
629
        }
630
        $this->dom->appChild($this->infCte, $this->vPrest, 'Falta tag "infCte"');
631
        $this->dom->appChild($this->infCte, $this->imp, 'Falta tag "imp"');
632
        if ($this->infCteComp != '') { // Caso seja um CTe tipo complemento de valores
633
            $this->dom->appChild($this->infCte, $this->infCteComp, 'Falta tag "infCteComp"');
634
        }
635
        if ($this->infCteAnu != '') { // Caso seja um CTe tipo anulação
636
            $this->dom->appChild($this->infCte, $this->infCteAnu, 'Falta tag "infCteAnu"');
637
        }
638
        if ($this->infCTeNorm != '') { // Caso seja um CTe tipo normal
639
            $this->dom->appChild($this->infCte, $this->infCTeNorm, 'Falta tag "infCTeNorm"');
640
            $this->dom->appChild($this->infCTeNorm, $this->infCarga, 'Falta tag "infCarga"');
641
            foreach ($this->infQ as $infQ) {
0 ignored issues
show
Bug introduced by
The expression $this->infQ of type object<DOMNode> is not traversable.
Loading history...
642
                $this->dom->appChild($this->infCarga, $infQ, 'Falta tag "infQ"');
643
            }
644
            foreach ($this->infNF as $infNF) {
645
                $this->dom->appChild($this->infDoc, $infNF, 'Falta tag "infNF"');
646
            }
647
            foreach ($this->infNFe as $infNFe) {
648
                $this->dom->appChild($this->infDoc, $infNFe, 'Falta tag "infNFe"');
649
            }
650
            foreach ($this->infOutros as $infOutros) {
651
                $this->dom->appChild($this->infDoc, $infOutros, 'Falta tag "infOutros"');
652
            }
653
            if (!empty($this->infDoc)) {
654
                $this->dom->appChild($this->infCTeNorm, $this->infDoc, 'Falta tag "infCTeNorm"');
655
            }
656
            if ($this->idDocAntEle != [] || $this->idDocAntPap != []) { //Caso tenha CT-es Anteriores viculados
657
                $this->dom->appChild($this->infCTeNorm, $this->docAnt, 'Falta tag "docAnt"');
658
                foreach ($this->emiDocAnt as $indice => $emiDocAnt) {
659
                    $this->dom->appChild($this->docAnt, $emiDocAnt, 'Falta tag "emiDocAnt"');
660
                    $indiceIdDocant = 0;
661
                    if (array_key_exists($indice, $this->idDocAntEle)) {
662
                        $this->dom->appChild($emiDocAnt, $this->idDocAnt[$indice][$indiceIdDocant], 'Falta tag "idDocAnt"');
663
                        foreach ($this->idDocAntEle[$indice] as $idDocAntEle) {
664
                            $this->dom->appChild($this->idDocAnt[$indice][$indiceIdDocant], $idDocAntEle, 'Falta tag "emiDocAnt"');
665
                        }
666
                    }
667
                    if (count($this->idDocAnt[$indice]) > 1) $indiceIdDocant = $indiceIdDocant + 1;
668
                    if (array_key_exists($indice, $this->idDocAntPap)) {
669
                        $this->dom->appChild($emiDocAnt, $this->idDocAnt[$indice][$indiceIdDocant], 'Falta tag "idDocAnt"');
670
                        foreach ($this->idDocAntPap[$indice] as $idDocAntPap) {
671
                            $this->dom->appChild($this->idDocAnt[$indice][$indiceIdDocant], $idDocAntPap, 'Falta tag "idDocAntEle"');
672
                        }
673
                    }
674
                }
675
            }
676
            foreach ($this->seg as $seg) {
677
                $this->dom->appChild($this->infCTeNorm, $seg, 'Falta tag "seg"');
678
            }
679
            $this->dom->appChild($this->infCTeNorm, $this->infModal, 'Falta tag "infModal"');
680
            if ($this->modal == '01') {
681
                if ($this->rodo) {
682
                    foreach ($this->occ as $occ) {
683
                        $this->dom->appChild($this->rodo, $occ, 'Falta tag "occ"');
684
                    }
685
                    $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "rodo"');
686
                }
687
            } elseif ($this->modal == '02') {
688
                foreach ($this->peri as $peri) {
689
                    $this->dom->appChild($this->aereo, $peri, 'Falta tag "aereo"');
690
                }
691
                $this->dom->appChild($this->infModal, $this->aereo, 'Falta tag "aereo"');
692
            } elseif ($this->modal == '04') {
693
                foreach ($this->ferroEnv as $ferroEnv) {
0 ignored issues
show
Bug introduced by
The expression $this->ferroEnv of type string is not traversable.
Loading history...
694
                    $this->ferrov->insertBefore($ferroEnv, $this->ferrov->getElementsByTagName('fluxo')->item(0));
695
                }
696
                $this->dom->appChild($this->infModal, $this->ferrov, 'Falta tag "ferrov"');
697
            } elseif ($this->modal == '03') {
698
                $this->dom->appChild($this->infModal, $this->aquav, 'Falta tag "aquav"');
699
                if ($this->detCont != []) { //Caso tenha informações de conteiner
700
                    foreach ($this->detCont as $indice => $conteiner) {
701
                        $this->dom->appChild($this->aquav, $conteiner, 'Falta tag "detCont"');
702
                        if (array_key_exists($indice, $this->lacre)) {
703
                            foreach ($this->lacre[$indice] as $lacre) {
704
                                $this->dom->appChild($this->detCont[$indice], $lacre, 'Falta tag "lacre"');
705
                            }
706
                        }
707
                        if (array_key_exists($indice, $this->infNFCont)) {
708
                            foreach ($this->infNFCont[$indice] as $infNFCont) {
709
                                $this->dom->appChild($this->infDocCont[$indice], $infNFCont, 'Falta tag "infNF"');
710
                            }
711
                        }
712
                        if (array_key_exists($indice, $this->infNFeCont)) {
713
                            foreach ($this->infNFeCont[$indice] as $infNFeCont) {
714
                                $this->dom->appChild($this->infDocCont[$indice], $infNFeCont, 'Falta tag "infNFe"');
715
                            }
716
                        }
717
                        if (array_key_exists($indice, $this->infDocCont)) {
718
                            $this->dom->appChild(
719
                                $this->detCont[$indice],
720
                                $this->infDocCont[$indice],
721
                                'Falta tag "infDoc"'
722
                            );
723
                        }
724
                    }
725
                }
726
                foreach ($this->balsa as $balsa) {
727
                    $this->aquav->insertBefore($balsa, $this->aquav->getElementsByTagName('nViag')->item(0));
728
                }
729
            } elseif ($this->modal == '05') {
730
                $this->dom->appChild($this->infModal, $this->duto, 'Falta tag "duto"');
731
            } elseif ($this->modal == '06') {
732
                if ($this->segMultim != '') {
733
                    $this->dom->appChild($this->multimodal, $this->segMultim, 'Falta tag "seg"');
734
                }
735
                $this->dom->appChild($this->infModal, $this->multimodal, 'Falta tag "multimodal"');
736
            } else {
737
                throw new Exception('Modal não informado ou não suportado.');
738
            }
739
            foreach ($this->veicNovos as $veicNovos) {
740
                $this->dom->appChild($this->infCTeNorm, $veicNovos, 'Falta tag "infCte"');
741
            }
742
            if ($this->infCteSub != '') {
743
                $this->dom->appChild($this->infCTeNorm, $this->infCteSub, 'Falta tag "infCteSub"');
744
745
                if ($this->tomaICMS != '') {
746
                    $this->dom->appChild($this->infCteSub, $this->tomaICMS, 'Falta tag "infCteSub"');
747
                }
748
                if (!empty($this->indAlteraToma)) {
749
                    $this->dom->addChild(
750
                        $this->infCteSub,
751
                        'indAlteraToma',
752
                        $this->indAlteraToma,
753
                        false,
754
                        'Indicador de CT-e Alteração de Tomador'
755
                    );
756
                }
757
            }
758
            if ($this->infGlobalizado != '') {
759
                $this->dom->appChild($this->infCTeNorm, $this->infGlobalizado, 'Falta tag "infGlobalizado"');
760
            }
761
            if ($this->infServVinc != '') {
762
                $this->dom->appChild($this->infCTeNorm, $this->infServVinc, 'Falta tag "infServVinc"');
763
764
                foreach ($this->infCTeMultimodal as $infCTeMultimodal) {
0 ignored issues
show
Bug introduced by
The expression $this->infCTeMultimodal of type object<DOMNode> is not traversable.
Loading history...
765
                    $this->dom->appChild($this->infServVinc, $infCTeMultimodal, 'Falta tag "infCTeMultimodal"');
766
                }
767
            }
768
        }
769
        if ($this->cobr != '') {
770
            $this->dom->appChild($this->infCTeNorm, $this->cobr, 'Falta tag "infCte"');
771
        }
772
        foreach ($this->autXML as $autXML) {
773
            $this->dom->appChild($this->infCte, $autXML, 'Falta tag "infCte"');
774
        }
775
        $this->dom->appChild($this->infCte, $this->infRespTec, 'Falta tag "infCte"');
776
        //[1] tag infCTe
777
        $this->dom->appChild($this->CTe, $this->infCte, 'Falta tag "CTe"');
778
        //[0] tag CTe
779
        $this->dom->appendChild($this->CTe);
780
        // testa da chave
781
        $this->checkCTeKey($this->dom);
782
        $this->xml = $this->dom->saveXML();
783
        if (count($this->errors) > 0) {
784
            throw new RuntimeException('Existem erros nas tags. Obtenha os erros com getErrors().');
785
        }
786
        return true;
787
    }
788
789
    /**
790
     * Gera as tags para o elemento: "occ" (ordem de coletas)
791
     * #3
792
     * Nível:1
793
     * Os parâmetros para esta função são todos os elementos da tag "occ" do
794
     * tipo elemento (Ele = E|CE|A) e nível 1
795
     *
796
     * @return \DOMElement
797
     */
798
799
    public function tagocc($std)
800
    {
801
802
        $possible = [
803
            'serie',
804
            'nOcc',
805
            'dEmi',
806
            'CNPJ',
807
            'cInt',
808
            'IE',
809
            'UF',
810
            'fone'
811
        ];
812
813
        $std = $this->equilizeParameters($std, $possible);
814
815
        $identificador = '#3 <occ> - ';
816
        $occ = $this->dom->createElement('occ');
817
        $this->dom->addChild(
818
            $occ,
819
            'serie',
820
            $std->serie,
821
            false,
822
            $identificador . 'Série da OCC'
823
        );
824
        $this->dom->addChild(
825
            $occ,
826
            'nOcc',
827
            $std->nOcc,
828
            true,
829
            $identificador . 'Número da Ordem de coleta'
830
        );
831
        $this->dom->addChild(
832
            $occ,
833
            'dEmi',
834
            $std->dEmi,
835
            true,
836
            $identificador . 'Data de emissão da ordem de coleta'
837
        );
838
        //emitente
839
        $identificador = '#7 <emiOcc> - ';
840
        $emiOcc = $this->dom->createElement('emiOcc');
841
        $this->dom->addChild(
842
            $emiOcc,
843
            'CNPJ',
844
            $std->CNPJ,
845
            true,
846
            $identificador . 'Número do CNPJ'
847
        );
848
        $this->dom->addChild(
849
            $emiOcc,
850
            'cInt',
851
            $std->cInt,
852
            false,
853
            $identificador . 'Código interno de uso da transportadora'
854
        );
855
        $this->dom->addChild(
856
            $emiOcc,
857
            'IE',
858
            $std->IE,
859
            true,
860
            $identificador . 'Inscrição Estadual'
861
        );
862
        $this->dom->addChild(
863
            $emiOcc,
864
            'UF',
865
            $std->UF,
866
            true,
867
            $identificador . 'Sigla da UF'
868
        );
869
        $this->dom->addChild(
870
            $emiOcc,
871
            'fone',
872
            $std->fone,
873
            false,
874
            $identificador . 'Telefone'
875
        );
876
        $this->dom->appChild($occ, $emiOcc, 'Falta tag "emiOcc"');
877
        $this->occ[] = $occ;
878
        return $occ;
879
    }
880
881
882
    /**
883
     * Monta o arquivo XML usando as tag's já preenchidas
884
     *
885
     * @return bool
886
     */
887
    public function montaCTeOS()
888
    {
889
        $this->errors = $this->dom->errors;
890
        if (count($this->errors) > 0) {
891
            return false;
892
        }
893
        $this->buildCTeOS();
894
        if ($this->infPercurso != '') {
895
            foreach ($this->infPercurso as $perc) {
0 ignored issues
show
Bug introduced by
The expression $this->infPercurso of type object<DOMNode> is not traversable.
Loading history...
896
                $this->dom->appChild($this->ide, $perc, 'Falta tag "infPercurso"');
897
            }
898
        }
899
        $this->dom->appChild($this->infCte, $this->ide, 'Falta tag "infCte"');
900
        if ($this->compl != '') {
901
            $this->dom->appChild($this->infCte, $this->compl, 'Falta tag "infCte"');
902
        }
903
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "emit"');
904
        $this->dom->appChild($this->infCte, $this->emit, 'Falta tag "infCte"');
905
        if ($this->toma != '') {
906
            $this->dom->appChild($this->infCte, $this->toma, 'Falta tag "infCte"');
907
        }
908
        foreach ($this->comp as $comp) {
909
            $this->dom->appChild($this->vPrest, $comp, 'Falta tag "vPrest"');
910
        }
911
        $this->dom->appChild($this->infCte, $this->vPrest, 'Falta tag "infCte"');
912
        $this->dom->appChild($this->infCte, $this->imp, 'Falta tag "imp"');
913
        if ($this->infCteComp != '') { // Caso seja um CTe tipo complemento de valores
914
            $this->dom->appChild($this->infCte, $this->infCteComp, 'Falta tag "infCteComp"');
915
        } elseif ($this->infCteAnu != '') { // Caso seja um CTe tipo anulação
916
            $this->dom->appChild($this->infCte, $this->infCteAnu, 'Falta tag "infCteAnu"');
917
        } elseif ($this->infCTeNorm != '') { // Caso seja um CTe tipo normal
918
            $this->dom->appChild($this->infCte, $this->infCTeNorm, 'Falta tag "infCTeNorm"');
919
            $this->dom->appChild($this->infCTeNorm, $this->infServico, 'Falta tag "infServico"');
920
            foreach ($this->infDocRef as $infDocRef) {
921
                $this->dom->appChild($this->infCTeNorm, $infDocRef, 'Falta tag "infDocRef"');
922
            }
923
            foreach ($this->seg as $seg) {
924
                $this->dom->appChild($this->infCTeNorm, $seg, 'Falta tag "seg"');
925
            }
926
            if ($this->infModal != '') {
927
                $this->dom->appChild($this->infCTeNorm, $this->infModal, 'Falta tag "infModal"');
928
                if (!empty($this->veic)) {
929
                    $this->dom->appChild($this->rodo, $this->veic, 'Falta tag "veic"');
930
                }
931
                $this->dom->appChild($this->rodo, $this->infFretamento, 'Falta tag "infFretamento"');
932
                $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "rodo"');
933
            }
934
        }
935
        if ($this->cobr != '') {
936
            $this->dom->appChild($this->infCte, $this->cobr, 'Falta tag "infCte"');
937
        }
938
        foreach ($this->autXML as $autXML) {
939
            $this->dom->appChild($this->infCte, $autXML, 'Falta tag "infCte"');
940
        }
941
        $this->dom->appChild($this->infCte, $this->infRespTec, 'Falta tag "infCte"');
942
        $this->dom->appChild($this->CTe, $this->infCte, 'Falta tag "CTe"');
943
        $this->dom->appendChild($this->CTe);
944
        // testa da chave
945
        $this->checkCTeKey($this->dom);
946
        $this->xml = $this->dom->saveXML();
947
        return true;
948
    }
949
950
    /**
951
     * Gera o grupo básico: Informações do CT-e
952
     * #1
953
     * Nível: 0
954
     * @param stdClass $std
955
     * @return \DOMElement
956
     */
957
    public function taginfCTe($std)
958
    {
959
        $chave = preg_replace('/[^0-9]/', '', $std->Id);
960
        $this->infCte = $this->dom->createElement('infCte');
961
        $this->infCte->setAttribute('Id', 'CTe' . $chave);
962
        $this->infCte->setAttribute('versao', $std->versao);
963
        return $this->infCte;
964
    }
965
966
    /**
967
     * Gera as tags para o elemento: Identificação do CT-e
968
     * #4
969
     * Nível: 1
970
     * @param stdClass $std
971
     * @return DOMElement|\DOMNode
972
     */
973
    public function tagide($std)
974
    {
975
976
        $possible = [
977
            'cUF',
978
            'cCT',
979
            'CFOP',
980
            'natOp',
981
            'mod',
982
            'serie',
983
            'nCT',
984
            'dhEmi',
985
            'tpImp',
986
            'tpEmis',
987
            'cDV',
988
            'tpEmis',
989
            'tpAmb',
990
            'tpCTe',
991
            'procEmi',
992
            'verProc',
993
            'indGlobalizado',
994
            'cMunEnv',
995
            'xMunEnv',
996
            'UFEnv',
997
            'modal',
998
            'tpServ',
999
            'indIEToma',
1000
            'cMunIni',
1001
            'xMunIni',
1002
            'UFIni',
1003
            'cMunFim',
1004
            'xMunFim',
1005
            'UFFim',
1006
            'retira',
1007
            'xDetRetira',
1008
            'indIEToma',
1009
            'dhCont',
1010
            'xJust'
1011
        ];
1012
1013
        $std = $this->equilizeParameters($std, $possible);
1014
1015
        $this->tpAmb = $std->tpAmb;
1016
        $this->mod = $std->mod;
1017
        $identificador = '#4 <ide> - ';
1018
        $this->ide = $this->dom->createElement('ide');
1019
        $this->dom->addChild(
1020
            $this->ide,
1021
            'cUF',
1022
            $std->cUF,
1023
            true,
1024
            $identificador . 'Código da UF do emitente do CT-e'
1025
        );
1026
        $this->dom->addChild(
1027
            $this->ide,
1028
            'cCT',
1029
            str_pad($std->cCT, 8, '0', STR_PAD_LEFT),
1030
            true,
1031
            $identificador . 'Código numérico que compõe a Chave de Acesso'
1032
        );
1033
        $this->dom->addChild(
1034
            $this->ide,
1035
            'CFOP',
1036
            $std->CFOP,
1037
            true,
1038
            $identificador . 'Código Fiscal de Operações e Prestações'
1039
        );
1040
        $this->dom->addChild(
1041
            $this->ide,
1042
            'natOp',
1043
            Strings::replaceSpecialsChars(substr(trim($std->natOp), 0, 60)),
1044
            true,
1045
            $identificador . 'Natureza da Operação'
1046
        );
1047
        $this->dom->addChild(
1048
            $this->ide,
1049
            'mod',
1050
            $std->mod,
1051
            true,
1052
            $identificador . 'Modelo do documento fiscal'
1053
        );
1054
        $this->dom->addChild(
1055
            $this->ide,
1056
            'serie',
1057
            $std->serie,
1058
            true,
1059
            $identificador . 'Série do CT-e'
1060
        );
1061
        $this->dom->addChild(
1062
            $this->ide,
1063
            'nCT',
1064
            $std->nCT,
1065
            true,
1066
            $identificador . 'Número do CT-e'
1067
        );
1068
        $this->dom->addChild(
1069
            $this->ide,
1070
            'dhEmi',
1071
            $std->dhEmi,
1072
            true,
1073
            $identificador . 'Data e hora de emissão do CT-e'
1074
        );
1075
        $this->dom->addChild(
1076
            $this->ide,
1077
            'tpImp',
1078
            $std->tpImp,
1079
            true,
1080
            $identificador . 'Formato de impressão do DACTE'
1081
        );
1082
        $this->dom->addChild(
1083
            $this->ide,
1084
            'tpEmis',
1085
            $std->tpEmis,
1086
            true,
1087
            $identificador . 'Forma de emissão do CT-e'
1088
        );
1089
        $this->dom->addChild(
1090
            $this->ide,
1091
            'cDV',
1092
            $std->cDV,
1093
            false,
1094
            $identificador . 'Digito Verificador da chave de acesso do CT-e'
1095
        );
1096
        $this->dom->addChild(
1097
            $this->ide,
1098
            'tpAmb',
1099
            $std->tpAmb,
1100
            true,
1101
            $identificador . 'Tipo do Ambiente'
1102
        );
1103
        $this->dom->addChild(
1104
            $this->ide,
1105
            'tpCTe',
1106
            $std->tpCTe,
1107
            true,
1108
            $identificador . 'Tipo do CT-e'
1109
        );
1110
        $this->dom->addChild(
1111
            $this->ide,
1112
            'procEmi',
1113
            $std->procEmi,
1114
            true,
1115
            $identificador . 'Identificador do processo de emissão do CT-e'
1116
        );
1117
        $this->dom->addChild(
1118
            $this->ide,
1119
            'verProc',
1120
            $std->verProc,
1121
            true,
1122
            $identificador . 'Versão do processo de emissão'
1123
        );
1124
        if ($this->mod == 57) {
1125
            $this->dom->addChild(
1126
                $this->ide,
1127
                'indGlobalizado',
1128
                $std->indGlobalizado,
1129
                false,
1130
                $identificador . 'Indicador de CT-e Globalizado'
1131
            );
1132
        }
1133
        $this->dom->addChild(
1134
            $this->ide,
1135
            'cMunEnv',
1136
            $std->cMunEnv,
1137
            true,
1138
            $identificador . 'Código do Município de envio do CT-e (de onde o documento foi transmitido)'
1139
        );
1140
        $this->dom->addChild(
1141
            $this->ide,
1142
            'xMunEnv',
1143
            $std->xMunEnv,
1144
            true,
1145
            $identificador . 'Nome do Município de envio do CT-e (de onde o documento foi transmitido)'
1146
        );
1147
        $this->dom->addChild(
1148
            $this->ide,
1149
            'UFEnv',
1150
            $std->UFEnv,
1151
            true,
1152
            $identificador . 'Sigla da UF de envio do CT-e (de onde o documento foi transmitido)'
1153
        );
1154
        $this->dom->addChild(
1155
            $this->ide,
1156
            'modal',
1157
            $std->modal,
1158
            true,
1159
            $identificador . 'Modal'
1160
        );
1161
        $this->modal = $std->modal;
1162
        $this->dom->addChild(
1163
            $this->ide,
1164
            'tpServ',
1165
            $std->tpServ,
1166
            true,
1167
            $identificador . 'Tipo do Serviço'
1168
        );
1169
        if ($this->mod == 67) {
1170
            $this->dom->addChild(
1171
                $this->ide,
1172
                'indIEToma',
1173
                $std->indIEToma,
1174
                true,
1175
                $identificador . 'Indicador do papel do tomador na prestação do serviço'
1176
            );
1177
        }
1178
        $this->dom->addChild(
1179
            $this->ide,
1180
            'cMunIni',
1181
            $std->cMunIni,
1182
            true,
1183
            $identificador . 'Nome do Município do início da prestação'
1184
        );
1185
        $this->dom->addChild(
1186
            $this->ide,
1187
            'xMunIni',
1188
            $std->xMunIni,
1189
            true,
1190
            $identificador . 'Nome do Município do início da prestação'
1191
        );
1192
        $this->dom->addChild(
1193
            $this->ide,
1194
            'UFIni',
1195
            $std->UFIni,
1196
            true,
1197
            $identificador . 'UF do início da prestação'
1198
        );
1199
        $this->dom->addChild(
1200
            $this->ide,
1201
            'cMunFim',
1202
            $std->cMunFim,
1203
            true,
1204
            $identificador . 'Código do Município de término da prestação'
1205
        );
1206
        $this->dom->addChild(
1207
            $this->ide,
1208
            'xMunFim',
1209
            $std->xMunFim,
1210
            true,
1211
            $identificador . 'Nome do Município do término da prestação'
1212
        );
1213
        $this->dom->addChild(
1214
            $this->ide,
1215
            'UFFim',
1216
            $std->UFFim,
1217
            true,
1218
            $identificador . 'UF do término da prestação'
1219
        );
1220
        if ($this->mod == 57) {
1221
            $this->dom->addChild(
1222
                $this->ide,
1223
                'retira',
1224
                $std->retira,
1225
                true,
1226
                $identificador . 'Indicador se o Recebedor retira no Aeroporto, Filial, Porto ou Estação de Destino'
1227
            );
1228
            $this->dom->addChild(
1229
                $this->ide,
1230
                'xDetRetira',
1231
                $std->xDetRetira,
1232
                false,
1233
                $identificador . 'Detalhes do retira'
1234
            );
1235
            $this->dom->addChild(
1236
                $this->ide,
1237
                'indIEToma',
1238
                $std->indIEToma,
1239
                true,
1240
                $identificador . 'Indicador do papel do tomador na prestação do serviço'
1241
            );
1242
        }
1243
        $this->dom->addChild(
1244
            $this->ide,
1245
            'dhCont',
1246
            $std->dhCont,
1247
            false,
1248
            $identificador . 'Data e Hora da entrada em contingência'
1249
        );
1250
        $this->dom->addChild(
1251
            $this->ide,
1252
            'xJust',
1253
            Strings::replaceSpecialsChars(substr(trim($std->xJust), 0, 256)),
1254
            false,
1255
            $identificador . 'Justificativa da entrada em contingência'
1256
        );
1257
        $this->tpServ = $std->tpServ;
1258
        return $this->ide;
1259
    }
1260
1261
    public function taginfPercurso($std)
1262
    {
1263
1264
        $possible = [
1265
            'UFPer'
1266
        ];
1267
1268
        $std = $this->equilizeParameters($std, $possible);
1269
1270
        $identificador = '#4 <infPercurso> - ';
1271
        $this->infPercurso[] = $this->dom->createElement('infPercurso');
1272
        $posicao = (int)count($this->infPercurso) - 1;
1273
        $this->dom->addChild(
1274
            $this->infPercurso[$posicao],
1275
            'UFPer',
1276
            $std->UFPer,
1277
            true,
1278
            $identificador . 'Código da UF do percurso'
1279
        );
1280
1281
        return $this->infPercurso[$posicao];
1282
    }
1283
1284
    /**
1285
     * Gera as tags para o elemento: toma3 (Indicador do "papel" do tomador do serviço no CT-e)
1286
     * e adiciona ao grupo ide
1287
     * #35
1288
     * Nível: 2
1289
     * @param string $toma Tomador do Serviço
0 ignored issues
show
Bug introduced by
There is no parameter named $toma. 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...
1290
     * @param stdClass $std
1291
     * @return \DOMElement
1292
     */
1293
    public function tagtoma3($std)
1294
    {
1295
1296
        $possible = [
1297
            'toma'
1298
        ];
1299
1300
        $std = $this->equilizeParameters($std, $possible);
1301
1302
        $identificador = '#35 <toma3> - ';
1303
        $this->toma3 = $this->dom->createElement('toma3');
1304
        $this->dom->addChild(
1305
            $this->toma3,
1306
            'toma',
1307
            $std->toma,
1308
            true,
1309
            $identificador . 'Tomador do Serviço'
1310
        );
1311
        return $this->toma3;
1312
    }
1313
1314
    /**
1315
     * Gera as tags para o elemento: toma4 (Indicador do "papel" do tomador
1316
     * do serviço no CT-e) e adiciona ao grupo ide
1317
     * #37
1318
     * Nível: 2
1319
     * @param stdClass $std
1320
     * @return \DOMElement
1321
     */
1322
    public function tagtoma4($std)
1323
    {
1324
1325
        $possible = [
1326
            'toma',
1327
            'CNPJ',
1328
            'CPF',
1329
            'IE',
1330
            'xNome',
1331
            'xFant',
1332
            'fone',
1333
            'email'
1334
        ];
1335
1336
        $std = $this->equilizeParameters($std, $possible);
1337
1338
        $identificador = '#37 <toma4> - ';
1339
        $this->toma4 = $this->dom->createElement('toma4');
1340
        $this->dom->addChild(
1341
            $this->toma4,
1342
            'toma',
1343
            $std->toma,
1344
            true,
1345
            $identificador . 'Tomador do Serviço'
1346
        );
1347
        if ($std->CNPJ != '') {
1348
            $this->dom->addChild(
1349
                $this->toma4,
1350
                'CNPJ',
1351
                $std->CNPJ,
1352
                true,
1353
                $identificador . 'Número do CNPJ'
1354
            );
1355
        } elseif ($std->CPF != '') {
1356
            $this->dom->addChild(
1357
                $this->toma4,
1358
                'CPF',
1359
                $std->CPF,
1360
                true,
1361
                $identificador . 'Número do CPF'
1362
            );
1363
        } else {
1364
            $this->dom->addChild(
1365
                $this->toma4,
1366
                'CNPJ',
1367
                $std->CNPJ,
1368
                true,
1369
                $identificador . 'Número do CNPJ'
1370
            );
1371
            $this->dom->addChild(
1372
                $this->toma4,
1373
                'CPF',
1374
                $std->CPF,
1375
                true,
1376
                $identificador . 'Número do CPF'
1377
            );
1378
        }
1379
        $this->dom->addChild(
1380
            $this->toma4,
1381
            'IE',
1382
            $std->IE,
1383
            false,
1384
            $identificador . 'Inscrição Estadual'
1385
        );
1386
        $this->dom->addChild(
1387
            $this->toma4,
1388
            'xNome',
1389
            $std->xNome,
1390
            true,
1391
            $identificador . 'Razão Social ou Nome'
1392
        );
1393
        $this->dom->addChild(
1394
            $this->toma4,
1395
            'xFant',
1396
            $std->xFant,
1397
            false,
1398
            $identificador . 'Nome Fantasia'
1399
        );
1400
        $this->dom->addChild(
1401
            $this->toma4,
1402
            'fone',
1403
            $std->fone,
1404
            false,
1405
            $identificador . 'Telefone'
1406
        );
1407
        $this->dom->addChild(
1408
            $this->toma4,
1409
            'email',
1410
            $std->email,
1411
            false,
1412
            $identificador . 'Endereço de email'
1413
        );
1414
        return $this->toma4;
1415
    }
1416
1417
    /**
1418
     * Gera as tags para o elemento: toma4 (Indicador do "papel" do tomador
1419
     * do serviço no CT-e OS) e adiciona ao grupo ide
1420
     * #37
1421
     * Nível: 2
1422
     *
1423
     * @return \DOMElement
1424
     */
1425
    public function tagtomador($std)
1426
    {
1427
1428
        $possible = [
1429
            'CNPJ',
1430
            'CPF',
1431
            'IE',
1432
            'xNome',
1433
            'xFant',
1434
            'fone',
1435
            'xLgr',
1436
            'nro',
1437
            'xCpl',
1438
            'xBairro',
1439
            'cMun',
1440
            'xMun',
1441
            'CEP',
1442
            'UF',
1443
            'cPais',
1444
            'xPais',
1445
            'email'
1446
        ];
1447
1448
        $std = $this->equilizeParameters($std, $possible);
1449
1450
        $identificador = '#37 <toma> - ';
1451
        $this->toma = $this->dom->createElement('toma');
1452
        if ($std->CNPJ != '') {
1453
            $this->dom->addChild(
1454
                $this->toma,
1455
                'CNPJ',
1456
                $std->CNPJ,
1457
                true,
1458
                $identificador . 'Número do CNPJ'
1459
            );
1460
        } elseif ($std->CPF != '') {
1461
            $this->dom->addChild(
1462
                $this->toma,
1463
                'CPF',
1464
                $std->CPF,
1465
                true,
1466
                $identificador . 'Número do CPF'
1467
            );
1468
        } else {
1469
            $this->dom->addChild(
1470
                $this->toma,
1471
                'CNPJ',
1472
                $std->CNPJ,
1473
                true,
1474
                $identificador . 'Número do CNPJ'
1475
            );
1476
            $this->dom->addChild(
1477
                $this->toma,
1478
                'CPF',
1479
                $std->CPF,
1480
                true,
1481
                $identificador . 'Número do CPF'
1482
            );
1483
        }
1484
        $this->dom->addChild(
1485
            $this->toma,
1486
            'IE',
1487
            $std->IE,
1488
            false,
1489
            $identificador . 'Inscrição Estadual'
1490
        );
1491
        $this->dom->addChild(
1492
            $this->toma,
1493
            'xNome',
1494
            $std->xNome,
1495
            true,
1496
            $identificador . 'Razão Social ou Nome'
1497
        );
1498
        $this->dom->addChild(
1499
            $this->toma,
1500
            'xFant',
1501
            $std->xFant,
1502
            false,
1503
            $identificador . 'Nome Fantasia'
1504
        );
1505
        $this->dom->addChild(
1506
            $this->toma,
1507
            'fone',
1508
            $std->fone,
1509
            false,
1510
            $identificador . 'Telefone'
1511
        );
1512
        //Endereço Tomador
1513
        $this->enderToma = $this->dom->createElement('enderToma');
1514
        $this->dom->addChild(
1515
            $this->enderToma,
1516
            'xLgr',
1517
            $std->xLgr,
1518
            true,
1519
            $identificador . 'Logradouro'
1520
        );
1521
        $this->dom->addChild(
1522
            $this->enderToma,
1523
            'nro',
1524
            $std->nro,
1525
            true,
1526
            $identificador . 'Número'
1527
        );
1528
        $this->dom->addChild(
1529
            $this->enderToma,
1530
            'xCpl',
1531
            $std->xCpl,
1532
            false,
1533
            $identificador . 'Complemento'
1534
        );
1535
        $this->dom->addChild(
1536
            $this->enderToma,
1537
            'xBairro',
1538
            $std->xBairro,
1539
            true,
1540
            $identificador . 'Bairro'
1541
        );
1542
        $this->dom->addChild(
1543
            $this->enderToma,
1544
            'cMun',
1545
            $std->cMun,
1546
            true,
1547
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
1548
        );
1549
        $this->dom->addChild(
1550
            $this->enderToma,
1551
            'xMun',
1552
            $std->xMun,
1553
            true,
1554
            $identificador . 'Nome do município'
1555
        );
1556
        $this->dom->addChild(
1557
            $this->enderToma,
1558
            'CEP',
1559
            $std->CEP,
1560
            false,
1561
            $identificador . 'CEP'
1562
        );
1563
        $this->dom->addChild(
1564
            $this->enderToma,
1565
            'UF',
1566
            $std->UF,
1567
            true,
1568
            $identificador . 'Sigla da UF'
1569
        );
1570
        $this->dom->addChild(
1571
            $this->enderToma,
1572
            'cPais',
1573
            $std->cPais,
1574
            false,
1575
            $identificador . 'Código do país'
1576
        );
1577
        $this->dom->addChild(
1578
            $this->enderToma,
1579
            'xPais',
1580
            $std->xPais,
1581
            false,
1582
            $identificador . 'Nome do país'
1583
        );
1584
        $this->dom->appChild($this->toma, $this->enderToma, 'Falta tag "enderToma"');
1585
        $this->dom->addChild(
1586
            $this->toma,
1587
            'email',
1588
            $std->email,
1589
            false,
1590
            $identificador . 'Endereço de email'
1591
        );
1592
        return $this->toma;
1593
    }
1594
1595
    /**
1596
     * Gera as tags para o elemento: "enderToma" (Dados do endereço) e adiciona ao grupo "toma4"
1597
     * #45
1598
     * Nível: 3
1599
     *
1600
     * @return \DOMElement
1601
     */
1602
    public function tagenderToma($std)
1603
    {
1604
1605
        $possible = [
1606
            'xLgr',
1607
            'nro',
1608
            'xCpl',
1609
            'xBairro',
1610
            'cMun',
1611
            'xMun',
1612
            'CEP',
1613
            'UF',
1614
            'cPais',
1615
            'xPais'
1616
        ];
1617
1618
        $std = $this->equilizeParameters($std, $possible);
1619
1620
        $identificador = '#45 <enderToma> - ';
1621
        $this->enderToma = $this->dom->createElement('enderToma');
1622
        $this->dom->addChild(
1623
            $this->enderToma,
1624
            'xLgr',
1625
            $std->xLgr,
1626
            true,
1627
            $identificador . 'Logradouro'
1628
        );
1629
        $this->dom->addChild(
1630
            $this->enderToma,
1631
            'nro',
1632
            $std->nro,
1633
            true,
1634
            $identificador . 'Número'
1635
        );
1636
        $this->dom->addChild(
1637
            $this->enderToma,
1638
            'xCpl',
1639
            $std->xCpl,
1640
            false,
1641
            $identificador . 'Complemento'
1642
        );
1643
        $this->dom->addChild(
1644
            $this->enderToma,
1645
            'xBairro',
1646
            $std->xBairro,
1647
            true,
1648
            $identificador . 'Bairro'
1649
        );
1650
        $this->dom->addChild(
1651
            $this->enderToma,
1652
            'cMun',
1653
            $std->cMun,
1654
            true,
1655
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
1656
        );
1657
        $this->dom->addChild(
1658
            $this->enderToma,
1659
            'xMun',
1660
            $std->xMun,
1661
            true,
1662
            $identificador . 'Nome do município'
1663
        );
1664
        $this->dom->addChild(
1665
            $this->enderToma,
1666
            'CEP',
1667
            $std->CEP,
1668
            false,
1669
            $identificador . 'CEP'
1670
        );
1671
        $this->dom->addChild(
1672
            $this->enderToma,
1673
            'UF',
1674
            $std->UF,
1675
            true,
1676
            $identificador . 'Sigla da UF'
1677
        );
1678
        $this->dom->addChild(
1679
            $this->enderToma,
1680
            'cPais',
1681
            $std->cPais,
1682
            false,
1683
            $identificador . 'Código do país'
1684
        );
1685
        $this->dom->addChild(
1686
            $this->enderToma,
1687
            'xPais',
1688
            $std->xPais,
1689
            false,
1690
            $identificador . 'Nome do país'
1691
        );
1692
1693
        if (!empty($this->toma4)) {
1694
            $this->toma4->insertBefore($this->enderToma, $this->toma4->getElementsByTagName("email")->item(0));
1695
        }
1696
        return $this->enderToma;
1697
    }
1698
1699
    /**
1700
     * Gera as tags para o elemento: "compl" (Dados complementares do CT-e para fins operacionais ou comerciais)
1701
     * #59
1702
     * Nível: 1
1703
     *
1704
     * @return \DOMElement
1705
     */
1706
    public function tagcompl($std)
1707
    {
1708
1709
        $possible = [
1710
            'xCaracAd',
1711
            'xCaracSer',
1712
            'xEmi',
1713
            'origCalc',
1714
            'destCalc',
1715
            'xObs'
1716
        ];
1717
1718
        $std = $this->equilizeParameters($std, $possible);
1719
1720
        $identificador = '#59 <compl> - ';
1721
        if ($this->compl == '') {
1722
            $this->compl = $this->dom->createElement('compl');
1723
        }
1724
        $this->dom->addChild(
1725
            $this->compl,
1726
            'xCaracAd',
1727
            $std->xCaracAd,
1728
            false,
1729
            $identificador . 'Característica adicional do transporte'
1730
        );
1731
        $this->dom->addChild(
1732
            $this->compl,
1733
            'xCaracSer',
1734
            $std->xCaracSer,
1735
            false,
1736
            $identificador . 'Característica adicional do serviço'
1737
        );
1738
        $this->dom->addChild(
1739
            $this->compl,
1740
            'xEmi',
1741
            $std->xEmi,
1742
            false,
1743
            $identificador . 'Funcionário emissor do CTe'
1744
        );
1745
        if ($this->fluxo != '') {
1746
            foreach ($this->pass as $pass) {
1747
                $this->dom->appChild($this->fluxo, $pass, 'Falta tag "fluxo"');
1748
            }
1749
            $this->dom->appChild($this->compl, $this->fluxo, 'Falta tag "infCte"');
1750
        }
1751
        if ($this->semData != '') {
1752
            $this->tagEntrega();
1753
            $this->dom->appChild($this->entrega, $this->semData, 'Falta tag "Entrega"');
1754
        }
1755
        if ($this->comData != '') {
1756
            $this->tagEntrega();
1757
            $this->dom->appChild($this->entrega, $this->comData, 'Falta tag "Entrega"');
1758
        }
1759
        if ($this->noPeriodo != '') {
1760
            $this->tagEntrega();
1761
            $this->dom->appChild($this->entrega, $this->noPeriodo, 'Falta tag "Entrega"');
1762
        }
1763
        if ($this->semHora != '') {
1764
            $this->tagEntrega();
1765
            $this->dom->appChild($this->entrega, $this->semHora, 'Falta tag "Entrega"');
1766
        }
1767
        if ($this->comHora != '') {
1768
            $this->tagEntrega();
1769
            $this->dom->appChild($this->entrega, $this->comHora, 'Falta tag "Entrega"');
1770
        }
1771
        if ($this->noInter != '') {
1772
            $this->tagEntrega();
1773
            $this->dom->appChild($this->entrega, $this->noInter, 'Falta tag "Entrega"');
1774
        }
1775
        if ($this->mod == 57) {
1776
            $this->dom->addChild(
1777
                $this->compl,
1778
                'origCalc',
1779
                $std->origCalc,
1780
                false,
1781
                $identificador . 'Município de origem para efeito de cálculo do frete'
1782
            );
1783
            $this->dom->addChild(
1784
                $this->compl,
1785
                'destCalc',
1786
                $std->destCalc,
1787
                false,
1788
                $identificador . 'Município de destino para efeito de cálculo do frete'
1789
            );
1790
        }
1791
        $this->dom->addChild(
1792
            $this->compl,
1793
            'xObs',
1794
            $std->xObs,
1795
            false,
1796
            $identificador . 'Observações Gerais'
1797
        );
1798
        return $this->compl;
1799
    }
1800
1801
    /**
1802
     * Gera as tags para o elemento: "compl" (Dados complementares do CT-e OS para fins operacionais ou comerciais)
1803
     * #59
1804
     * Nível: 1
1805
     *
1806
     * @return \DOMElement
1807
     */
1808
    public function tagcomplCTeOs($std)
1809
    {
1810
1811
        $possible = [
1812
            'xCaracAd',
1813
            'xCaracSer',
1814
            'xEmi',
1815
            'xObs'
1816
        ];
1817
1818
        $std = $this->equilizeParameters($std, $possible);
1819
1820
        $identificador = '#59 <compl> - ';
1821
        $this->compl = $this->dom->createElement('compl');
1822
        $this->dom->addChild(
1823
            $this->compl,
1824
            'xCaracAd',
1825
            $std->xCaracAd,
1826
            false,
1827
            $identificador . 'Característica adicional do transporte'
1828
        );
1829
        $this->dom->addChild(
1830
            $this->compl,
1831
            'xCaracSer',
1832
            $std->xCaracSer,
1833
            false,
1834
            $identificador . 'Característica adicional do serviço'
1835
        );
1836
        $this->dom->addChild(
1837
            $this->compl,
1838
            'xEmi',
1839
            $std->xEmi,
1840
            false,
1841
            $identificador . 'Funcionário emissor do CTe'
1842
        );
1843
        $this->dom->addChild(
1844
            $this->compl,
1845
            'xObs',
1846
            $std->xObs,
1847
            false,
1848
            $identificador . 'Observações Gerais'
1849
        );
1850
        return $this->compl;
1851
    }
1852
1853
    /**
1854
     * Gera as tags para o elemento: "fluxo" (Previsão do fluxo da carga)
1855
     * #63
1856
     * Nível: 2
1857
     * Os parâmetros para esta função são todos os elementos da tag "fluxo" do
1858
     * tipo elemento (Ele = E|CE|A) e nível 3
1859
     *
1860
     * @return \DOMElement
1861
     */
1862
    public function tagfluxo($std)
1863
    {
1864
1865
        $possible = [
1866
            'xOrig',
1867
            'xDest',
1868
            'xRota'
1869
        ];
1870
1871
        $std = $this->equilizeParameters($std, $possible);
1872
1873
        $identificador = '#63 <fluxo> - ';
1874
        $this->fluxo = $this->dom->createElement('fluxo');
1875
        $this->dom->addChild(
1876
            $this->fluxo,
1877
            'xOrig',
1878
            $std->xOrig,
1879
            false,
1880
            $identificador . 'Sigla ou código interno da Filial/Porto/Estação/ Aeroporto de Origem'
1881
        );
1882
        $this->dom->addChild(
1883
            $this->fluxo,
1884
            'xDest',
1885
            $std->xDest,
1886
            false,
1887
            $identificador . 'Sigla ou código interno da Filial/Porto/Estação/Aeroporto de Destino'
1888
        );
1889
        $this->dom->addChild(
1890
            $this->fluxo,
1891
            'xRota',
1892
            $std->xRota,
1893
            false,
1894
            $identificador . 'Código da Rota de Entrega'
1895
        );
1896
        return $this->fluxo;
1897
    }
1898
1899
    /**
1900
     * Gera as tags para o elemento: "pass"
1901
     * #65
1902
     * Nível: 3
1903
     *
1904
     * @return \DOMElement
1905
     */
1906
    public function tagpass($std)
1907
    {
1908
1909
        $possible = [
1910
            'xPass'
1911
        ];
1912
1913
        $std = $this->equilizeParameters($std, $possible);
1914
1915
        $identificador = '#65 <pass> - ';
1916
        $this->pass[] = $this->dom->createElement('pass');
1917
        $posicao = (int)count($this->pass) - 1;
1918
        $this->dom->addChild(
1919
            $this->pass[$posicao],
1920
            'xPass',
1921
            $std->xPass,
1922
            false,
1923
            $identificador . 'Sigla ou código interno da Filial/Porto/Estação/Aeroporto de Passagem'
1924
        );
1925
        return $this->pass[$posicao];
1926
    }
1927
1928
    /**
1929
     * Gera as tags para o elemento: "semData" (Entrega sem data definida)
1930
     * #70
1931
     * Nível: 3
1932
     *
1933
     * @return \DOMElement
1934
     */
1935
    public function tagsemData($std)
1936
    {
1937
1938
        $possible = [
1939
            'tpPer'
1940
        ];
1941
1942
        $std = $this->equilizeParameters($std, $possible);
1943
1944
        $identificador = '#70 <semData> - ';
1945
        $this->semData = $this->dom->createElement('semData');
1946
        $this->dom->addChild(
1947
            $this->semData,
1948
            'tpPer',
1949
            $std->tpPer,
1950
            true,
1951
            $identificador . 'Tipo de data/período programado para entrega'
1952
        );
1953
        return $this->semData;
1954
    }
1955
1956
    /**
1957
     * Gera as tags para o elemento: "comData" (Entrega com data definida)
1958
     * #72
1959
     * Nível: 3
1960
     *
1961
     * @return \DOMElement
1962
     */
1963
    public function tagcomData($std)
1964
    {
1965
1966
        $possible = [
1967
            'tpPer',
1968
            'dProg'
1969
        ];
1970
1971
        $std = $this->equilizeParameters($std, $possible);
1972
1973
        $identificador = '#72 <comData> - ';
1974
        $this->comData = $this->dom->createElement('comData');
1975
        $this->dom->addChild(
1976
            $this->comData,
1977
            'tpPer',
1978
            $std->tpPer,
1979
            true,
1980
            $identificador . 'Tipo de data/período programado para entrega'
1981
        );
1982
        $this->dom->addChild(
1983
            $this->comData,
1984
            'dProg',
1985
            $std->dProg,
1986
            true,
1987
            $identificador . 'Data programada'
1988
        );
1989
        return $this->comData;
1990
    }
1991
1992
    /**
1993
     * Gera as tags para o elemento: "noPeriodo" (Entrega no período definido)
1994
     * #75
1995
     * Nível: 3
1996
     *
1997
     * @return \DOMElement
1998
     */
1999
    public function tagnoPeriodo($std)
2000
    {
2001
2002
        $possible = [
2003
            'tpPer',
2004
            'dIni',
2005
            'dFim'
2006
        ];
2007
2008
        $std = $this->equilizeParameters($std, $possible);
2009
2010
        $identificador = '#75 <noPeriodo> - ';
2011
        $this->noPeriodo = $this->dom->createElement('noPeriodo');
2012
        $this->dom->addChild(
2013
            $this->noPeriodo,
2014
            'tpPer',
2015
            $std->tpPer,
2016
            true,
2017
            $identificador . 'Tipo de data/período programado para entrega'
2018
        );
2019
        $this->dom->addChild(
2020
            $this->noPeriodo,
2021
            'dIni',
2022
            $std->dIni,
2023
            true,
2024
            $identificador . 'Data inicial'
2025
        );
2026
        $this->dom->addChild(
2027
            $this->noPeriodo,
2028
            'dFim',
2029
            $std->dFim,
2030
            true,
2031
            $identificador . 'Data final'
2032
        );
2033
        return $this->noPeriodo;
2034
    }
2035
2036
    /**
2037
     * Gera as tags para o elemento: "semHora" (Entrega sem hora definida)
2038
     * #79
2039
     * Nível: 3
2040
     * Os parâmetros para esta função são todos os elementos da tag "semHora" do
2041
     * tipo elemento (Ele = E|CE|A) e nível 4
2042
     *
2043
     * @return \DOMElement
2044
     */
2045
    public function tagsemHora($std)
2046
    {
2047
2048
        $possible = [
2049
            'tpHor'
2050
        ];
2051
2052
        $std = $this->equilizeParameters($std, $possible);
2053
2054
        $identificador = '#79 <semHora> - ';
2055
        $this->semHora = $this->dom->createElement('semHora');
2056
        $this->dom->addChild(
2057
            $this->semHora,
2058
            'tpHor',
2059
            $std->tpHor,
2060
            true,
2061
            $identificador . 'Tipo de hora'
2062
        );
2063
        return $this->semHora;
2064
    }
2065
2066
    /**
2067
     * Gera as tags para o elemento: "comHora" (Entrega sem hora definida)
2068
     * # = 81
2069
     * Nível = 3
2070
     * Os parâmetros para esta função são todos os elementos da tag "comHora" do
2071
     * tipo elemento (Ele = E|CE|A) e nível 4
2072
     *
2073
     * @return \DOMElement
2074
     */
2075
    public function tagcomHora($std)
2076
    {
2077
2078
        $possible = [
2079
            'tpHor',
2080
            'hProg'
2081
        ];
2082
2083
        $std = $this->equilizeParameters($std, $possible);
2084
2085
        $identificador = '#81 <comHora> - ';
2086
        $this->comHora = $this->dom->createElement('comHora');
2087
        $this->dom->addChild(
2088
            $this->comHora,
2089
            'tpHor',
2090
            $std->tpHor,
2091
            true,
2092
            $identificador . 'Tipo de hora'
2093
        );
2094
        $this->dom->addChild(
2095
            $this->comHora,
2096
            'hProg',
2097
            $std->hProg,
2098
            true,
2099
            $identificador . 'Hora programada'
2100
        );
2101
        return $this->comHora;
2102
    }
2103
2104
    /**
2105
     * Gera as tags para o elemento: "noInter" (Entrega no intervalo de horário definido)
2106
     * #84
2107
     * Nível: 3
2108
     * Os parâmetros para esta função são todos os elementos da tag "noInter" do
2109
     * tipo elemento (Ele = E|CE|A) e nível 4
2110
     *
2111
     * @return \DOMElement
2112
     */
2113
    public function tagnoInter($std)
2114
    {
2115
2116
        $possible = [
2117
            'tpHor',
2118
            'hIni',
2119
            'hFim'
2120
        ];
2121
2122
        $std = $this->equilizeParameters($std, $possible);
2123
2124
        $identificador = '#84 <noInter> - ';
2125
        $this->noInter = $this->dom->createElement('noInter');
2126
        $this->dom->addChild(
2127
            $this->noInter,
2128
            'tpHor',
2129
            $std->tpHor,
2130
            true,
2131
            $identificador . 'Tipo de hora'
2132
        );
2133
        $this->dom->addChild(
2134
            $this->noInter,
2135
            'hIni',
2136
            $std->hIni,
2137
            true,
2138
            $identificador . 'Hora inicial'
2139
        );
2140
        $this->dom->addChild(
2141
            $this->noInter,
2142
            'hFim',
2143
            $std->hFim,
2144
            true,
2145
            $identificador . 'Hora final'
2146
        );
2147
        return $this->noInter;
2148
    }
2149
2150
    /**
2151
     * Gera as tags para o elemento: "ObsCont" (Campo de uso livre do contribuinte)
2152
     * #91
2153
     * Nível: 2
2154
     * Os parâmetros para esta função são todos os elementos da tag "ObsCont" do
2155
     * tipo elemento (Ele = E|CE|A) e nível 3
2156
     *
2157
     * @return boolean
2158
     */
2159
    public function tagobsCont($std)
2160
    {
2161
2162
        $possible = [
2163
            'xCampo',
2164
            'xTexto'
2165
        ];
2166
2167
        $std = $this->equilizeParameters($std, $possible);
2168
2169
        $identificador = '#91 <ObsCont> - ';
2170
        if (count($this->obsCont) <= 10) {
2171
            $this->obsCont[] = $this->dom->createElement('ObsCont');
2172
            $posicao = (int)count($this->obsCont) - 1;
2173
            $this->obsCont[$posicao]->setAttribute('xCampo', $std->xCampo);
2174
            $this->dom->addChild(
2175
                $this->obsCont[$posicao],
2176
                'xTexto',
2177
                $std->xTexto,
2178
                true,
2179
                $identificador . 'Conteúdo do campo'
2180
            );
2181
            return true;
2182
        }
2183
        $this->errors[] = array(
2184
            'tag' => (string)'<ObsCont>',
2185
            'desc' => (string)'Campo de uso livre do contribuinte',
2186
            'erro' => (string)'Tag deve aparecer de 0 a 10 vezes'
2187
        );
2188
        return false;
2189
    }
2190
2191
    /**
2192
     * Gera as tags para o elemento: "ObsFisco" (Campo de uso livre do contribuinte)
2193
     * #94
2194
     * Nível: 2
2195
     * Os parâmetros para esta função são todos os elementos da tag "ObsFisco" do tipo
2196
     * elemento (Ele = E|CE|A) e nível 3
2197
     *
2198
     * @return boolean
2199
     */
2200
    public function tagobsFisco($std)
2201
    {
2202
2203
        $possible = [
2204
            'xCampo',
2205
            'xTexto'
2206
        ];
2207
2208
        $std = $this->equilizeParameters($std, $possible);
2209
2210
        $identificador = '#94 <ObsFisco> - ';
2211
        if (count($this->obsFisco) <= 10) {
2212
            $this->obsFisco[] = $this->dom->createElement('ObsFisco');
2213
            $posicao = (int)count($this->obsFisco) - 1;
2214
            $this->obsFisco[$posicao]->setAttribute('xCampo', $std->xCampo);
2215
            $this->dom->addChild(
2216
                $this->obsFisco[$posicao],
2217
                'xTexto',
2218
                $std->xTexto,
2219
                true,
2220
                $identificador . 'Conteúdo do campo'
2221
            );
2222
            return true;
2223
        }
2224
        $this->errors[] = array(
2225
            'tag' => (string)'<ObsFisco>',
2226
            'desc' => (string)'Campo de uso livre do contribuinte',
2227
            'erro' => (string)'Tag deve aparecer de 0 a 10 vezes'
2228
        );
2229
        return false;
2230
    }
2231
2232
    /**
2233
     * Gera as tags para o elemento: "emit" (Identificação do Emitente do CT-e)
2234
     * #97
2235
     * Nível: 1
2236
     * Os parâmetros para esta função são todos os elementos da tag "emit" do
2237
     * tipo elemento (Ele = E|CE|A) e nível 2
2238
     *
2239
     * @return \DOMElement
2240
     */
2241
    public function tagemit($std)
2242
    {
2243
2244
        $possible = [
2245
            'CNPJ',
2246
            'IE',
2247
            'IEST',
2248
            'xNome',
2249
            'xFant'
2250
        ];
2251
2252
        $std = $this->equilizeParameters($std, $possible);
2253
2254
        $identificador = '#97 <emit> - ';
2255
        $this->emit = $this->dom->createElement('emit');
2256
        $this->dom->addChild(
2257
            $this->emit,
2258
            'CNPJ',
2259
            $std->CNPJ,
2260
            true,
2261
            $identificador . 'CNPJ do emitente'
2262
        );
2263
        $this->dom->addChild(
2264
            $this->emit,
2265
            'IE',
2266
            Strings::onlyNumbers($std->IE),
2267
            false,
2268
            $identificador . 'Inscrição Estadual do Emitente'
2269
        );
2270
        $this->dom->addChild(
2271
            $this->emit,
2272
            'IEST',
2273
            Strings::onlyNumbers($std->IEST),
2274
            false,
2275
            $identificador . 'Inscrição Estadual do Substituto Tributário'
2276
        );
2277
        $this->dom->addChild(
2278
            $this->emit,
2279
            'xNome',
2280
            $std->xNome,
2281
            true,
2282
            $identificador . 'Razão social ou Nome do emitente'
2283
        );
2284
        $this->dom->addChild(
2285
            $this->emit,
2286
            'xFant',
2287
            $std->xFant,
2288
            false,
2289
            $identificador . 'Nome fantasia'
2290
        );
2291
        return $this->emit;
2292
    }
2293
2294
    /**
2295
     * Gera as tags para o elemento: "enderEmit" (Endereço do emitente)
2296
     * #102
2297
     * Nível: 2
2298
     * Os parâmetros para esta função são todos os elementos da tag "enderEmit" do
2299
     * tipo elemento (Ele = E|CE|A) e nível 3
2300
     *
2301
     * @return \DOMElement
2302
     */
2303
    public function tagenderEmit($std)
2304
    {
2305
2306
        $possible = [
2307
            'xLgr',
2308
            'nro',
2309
            'xCpl',
2310
            'xBairro',
2311
            'cMun',
2312
            'xMun',
2313
            'CEP',
2314
            'UF',
2315
            'fone'
2316
        ];
2317
2318
        $std = $this->equilizeParameters($std, $possible);
2319
2320
        $identificador = '#102 <enderEmit> - ';
2321
        $this->enderEmit = $this->dom->createElement('enderEmit');
2322
        $this->dom->addChild(
2323
            $this->enderEmit,
2324
            'xLgr',
2325
            $std->xLgr,
2326
            true,
2327
            $identificador . 'Logradouro'
2328
        );
2329
        $this->dom->addChild(
2330
            $this->enderEmit,
2331
            'nro',
2332
            $std->nro,
2333
            true,
2334
            $identificador . 'Número'
2335
        );
2336
        $this->dom->addChild(
2337
            $this->enderEmit,
2338
            'xCpl',
2339
            $std->xCpl,
2340
            false,
2341
            $identificador . 'Complemento'
2342
        );
2343
        $this->dom->addChild(
2344
            $this->enderEmit,
2345
            'xBairro',
2346
            $std->xBairro,
2347
            true,
2348
            $identificador . 'Bairro'
2349
        );
2350
        $this->dom->addChild(
2351
            $this->enderEmit,
2352
            'cMun',
2353
            $std->cMun,
2354
            true,
2355
            $identificador . 'Código do município'
2356
        );
2357
        $this->dom->addChild(
2358
            $this->enderEmit,
2359
            'xMun',
2360
            $std->xMun,
2361
            true,
2362
            $identificador . 'Nome do município'
2363
        );
2364
        $this->dom->addChild(
2365
            $this->enderEmit,
2366
            'CEP',
2367
            $std->CEP,
2368
            false,
2369
            $identificador . 'CEP'
2370
        );
2371
        $this->dom->addChild(
2372
            $this->enderEmit,
2373
            'UF',
2374
            $std->UF,
2375
            true,
2376
            $identificador . 'Sigla da UF'
2377
        );
2378
        $this->dom->addChild(
2379
            $this->enderEmit,
2380
            'fone',
2381
            $std->fone,
2382
            false,
2383
            $identificador . 'Telefone'
2384
        );
2385
        return $this->enderEmit;
2386
    }
2387
2388
    /**
2389
     * Gera as tags para o elemento: "rem" (Informações do Remetente das mercadorias
2390
     * transportadas pelo CT-e)
2391
     * #112
2392
     * Nível = 1
2393
     * Os parâmetros para esta função são todos os elementos da tag "rem" do
2394
     * tipo elemento (Ele = E|CE|A) e nível 2
2395
     *
2396
     * @return \DOMElement
2397
     */
2398
    public function tagrem($std)
2399
    {
2400
2401
        $possible = [
2402
            'CNPJ',
2403
            'CPF',
2404
            'IE',
2405
            'xNome',
2406
            'xFant',
2407
            'fone',
2408
            'email'
2409
        ];
2410
2411
        $std = $this->equilizeParameters($std, $possible);
2412
2413
        $identificador = '#97 <rem> - ';
2414
        $this->rem = $this->dom->createElement('rem');
2415
        if ($std->CNPJ != '') {
2416
            $this->dom->addChild(
2417
                $this->rem,
2418
                'CNPJ',
2419
                $std->CNPJ,
2420
                true,
2421
                $identificador . 'CNPJ do Remente'
2422
            );
2423
        } elseif ($std->CPF != '') {
2424
            $this->dom->addChild(
2425
                $this->rem,
2426
                'CPF',
2427
                $std->CPF,
2428
                true,
2429
                $identificador . 'CPF do Remente'
2430
            );
2431
        } else {
2432
            $this->dom->addChild(
2433
                $this->rem,
2434
                'CNPJ',
2435
                $std->CNPJ,
2436
                true,
2437
                $identificador . 'CNPJ do Remente'
2438
            );
2439
            $this->dom->addChild(
2440
                $this->rem,
2441
                'CPF',
2442
                $std->CPF,
2443
                true,
2444
                $identificador . 'CPF do remente'
2445
            );
2446
        }
2447
        $this->dom->addChild(
2448
            $this->rem,
2449
            'IE',
2450
            $std->IE,
2451
            false,
2452
            $identificador . 'Inscrição Estadual do remente'
2453
        );
2454
        $xNome = $std->xNome;
2455
        if ($this->tpAmb == '2') {
2456
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2457
        }
2458
        $this->dom->addChild(
2459
            $this->rem,
2460
            'xNome',
2461
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2462
            true,
2463
            $identificador . 'Razão social ou Nome do remente'
2464
        );
2465
        $this->dom->addChild(
2466
            $this->rem,
2467
            'xFant',
2468
            $std->xFant,
2469
            false,
2470
            $identificador . 'Nome fantasia'
2471
        );
2472
        $this->dom->addChild(
2473
            $this->rem,
2474
            'fone',
2475
            $std->fone,
2476
            false,
2477
            $identificador . 'Telefone'
2478
        );
2479
        $this->dom->addChild(
2480
            $this->rem,
2481
            'email',
2482
            $std->email,
2483
            false,
2484
            $identificador . 'Endereço de email'
2485
        );
2486
        return $this->rem;
2487
    }
2488
2489
    /**
2490
     * Gera as tags para o elemento: "enderReme" (Dados do endereço)
2491
     * #120
2492
     * Nível: 2
2493
     * Os parâmetros para esta função são todos os elementos da tag "enderReme" do
2494
     * tipo elemento (Ele = E|CE|A) e nível 3
2495
     *
2496
     * @return \DOMElement
2497
     */
2498
    public function tagenderReme($std)
2499
    {
2500
2501
        $possible = [
2502
            'xLgr',
2503
            'nro',
2504
            'xCpl',
2505
            'xBairro',
2506
            'cMun',
2507
            'xMun',
2508
            'CEP',
2509
            'UF',
2510
            'cPais',
2511
            'xPais'
2512
        ];
2513
2514
        $std = $this->equilizeParameters($std, $possible);
2515
2516
        $identificador = '#119 <enderReme> - ';
2517
        $this->enderReme = $this->dom->createElement('enderReme');
2518
        $this->dom->addChild(
2519
            $this->enderReme,
2520
            'xLgr',
2521
            $std->xLgr,
2522
            true,
2523
            $identificador . 'Logradouro'
2524
        );
2525
        $this->dom->addChild(
2526
            $this->enderReme,
2527
            'nro',
2528
            $std->nro,
2529
            true,
2530
            $identificador . 'Número'
2531
        );
2532
        $this->dom->addChild(
2533
            $this->enderReme,
2534
            'xCpl',
2535
            $std->xCpl,
2536
            false,
2537
            $identificador . 'Complemento'
2538
        );
2539
        $this->dom->addChild(
2540
            $this->enderReme,
2541
            'xBairro',
2542
            $std->xBairro,
2543
            true,
2544
            $identificador . 'Bairro'
2545
        );
2546
        $this->dom->addChild(
2547
            $this->enderReme,
2548
            'cMun',
2549
            $std->cMun,
2550
            true,
2551
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2552
        );
2553
        $this->dom->addChild(
2554
            $this->enderReme,
2555
            'xMun',
2556
            $std->xMun,
2557
            true,
2558
            $identificador . 'Nome do município'
2559
        );
2560
        $this->dom->addChild(
2561
            $this->enderReme,
2562
            'CEP',
2563
            $std->CEP,
2564
            false,
2565
            $identificador . 'CEP'
2566
        );
2567
        $this->dom->addChild(
2568
            $this->enderReme,
2569
            'UF',
2570
            $std->UF,
2571
            true,
2572
            $identificador . 'Sigla da UF'
2573
        );
2574
        $this->dom->addChild(
2575
            $this->enderReme,
2576
            'cPais',
2577
            $std->cPais,
2578
            false,
2579
            $identificador . 'Código do país'
2580
        );
2581
        $this->dom->addChild(
2582
            $this->enderReme,
2583
            'xPais',
2584
            $std->xPais,
2585
            false,
2586
            $identificador . 'Nome do país'
2587
        );
2588
2589
        $node = $this->rem->getElementsByTagName("email")->item(0);
2590
        $this->rem->insertBefore($this->enderReme, $node);
2591
        return $this->enderReme;
2592
    }
2593
2594
    /**
2595
     * Gera as tags para o elemento: "exped" (Informações do Expedidor da Carga)
2596
     * #132
2597
     * Nível: 1
2598
     * Os parâmetros para esta função são todos os elementos da tag "exped" do
2599
     * tipo elemento (Ele = E|CE|A) e nível 2
2600
     *
2601
     * @return \DOMElement
2602
     */
2603
    public function tagexped($std)
2604
    {
2605
2606
        $possible = [
2607
            'CNPJ',
2608
            'CPF',
2609
            'IE',
2610
            'xNome',
2611
            'fone',
2612
            'email'
2613
        ];
2614
2615
        $std = $this->equilizeParameters($std, $possible);
2616
2617
        $identificador = '#142 <exped> - ';
2618
        $this->exped = $this->dom->createElement('exped');
2619
        if ($std->CNPJ != '') {
2620
            $this->dom->addChild(
2621
                $this->exped,
2622
                'CNPJ',
2623
                $std->CNPJ,
2624
                true,
2625
                $identificador . 'Número do CNPJ'
2626
            );
2627
        } elseif ($std->CPF != '') {
2628
            $this->dom->addChild(
2629
                $this->exped,
2630
                'CPF',
2631
                $std->CPF,
2632
                true,
2633
                $identificador . 'Número do CPF'
2634
            );
2635
        } else {
2636
            $this->dom->addChild(
2637
                $this->exped,
2638
                'CNPJ',
2639
                $std->CNPJ,
2640
                true,
2641
                $identificador . 'Número do CNPJ'
2642
            );
2643
            $this->dom->addChild(
2644
                $this->exped,
2645
                'CPF',
2646
                $std->CPF,
2647
                true,
2648
                $identificador . 'Número do CPF'
2649
            );
2650
        }
2651
        if (!empty($std->IE)) {
2652
            $this->dom->addChild(
2653
                $this->exped,
2654
                'IE',
2655
                $std->IE,
2656
                true,
2657
                $identificador . 'Inscrição Estadual'
2658
            );
2659
        }
2660
        $xNome = $std->xNome;
2661
        if ($this->tpAmb == '2') {
2662
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2663
        }
2664
        $this->dom->addChild(
2665
            $this->exped,
2666
            'xNome',
2667
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2668
            true,
2669
            $identificador . 'Razão social ou Nome'
2670
        );
2671
        $this->dom->addChild(
2672
            $this->exped,
2673
            'fone',
2674
            $std->fone,
2675
            false,
2676
            $identificador . 'Telefone'
2677
        );
2678
        $this->dom->addChild(
2679
            $this->exped,
2680
            'email',
2681
            $std->email,
2682
            false,
2683
            $identificador . 'Endereço de email'
2684
        );
2685
        return $this->exped;
2686
    }
2687
2688
    /**
2689
     * Gera as tags para o elemento: "enderExped" (Dados do endereço)
2690
     * #138
2691
     * Nível: 2
2692
     * Os parâmetros para esta função são todos os elementos da tag "enderExped" do
2693
     * tipo elemento (Ele = E|CE|A) e nível 3
2694
     *
2695
     * @return \DOMElement
2696
     */
2697
    public function tagenderExped($std)
2698
    {
2699
2700
        $possible = [
2701
            'xLgr',
2702
            'nro',
2703
            'xCpl',
2704
            'xBairro',
2705
            'cMun',
2706
            'xMun',
2707
            'CEP',
2708
            'UF',
2709
            'cPais',
2710
            'xPais'
2711
        ];
2712
2713
        $std = $this->equilizeParameters($std, $possible);
2714
2715
        $identificador = '#148 <enderExped> - ';
2716
        $this->enderExped = $this->dom->createElement('enderExped');
2717
        $this->dom->addChild(
2718
            $this->enderExped,
2719
            'xLgr',
2720
            $std->xLgr,
2721
            true,
2722
            $identificador . 'Logradouro'
2723
        );
2724
        $this->dom->addChild(
2725
            $this->enderExped,
2726
            'nro',
2727
            $std->nro,
2728
            true,
2729
            $identificador . 'Número'
2730
        );
2731
        $this->dom->addChild(
2732
            $this->enderExped,
2733
            'xCpl',
2734
            $std->xCpl,
2735
            false,
2736
            $identificador . 'Complemento'
2737
        );
2738
        $this->dom->addChild(
2739
            $this->enderExped,
2740
            'xBairro',
2741
            $std->xBairro,
2742
            true,
2743
            $identificador . 'Bairro'
2744
        );
2745
        $this->dom->addChild(
2746
            $this->enderExped,
2747
            'cMun',
2748
            $std->cMun,
2749
            true,
2750
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2751
        );
2752
        $this->dom->addChild(
2753
            $this->enderExped,
2754
            'xMun',
2755
            $std->xMun,
2756
            true,
2757
            $identificador . 'Nome do município'
2758
        );
2759
        $this->dom->addChild(
2760
            $this->enderExped,
2761
            'CEP',
2762
            $std->CEP,
2763
            false,
2764
            $identificador . 'CEP'
2765
        );
2766
        $this->dom->addChild(
2767
            $this->enderExped,
2768
            'UF',
2769
            $std->UF,
2770
            true,
2771
            $identificador . 'Sigla da UF'
2772
        );
2773
        $this->dom->addChild(
2774
            $this->enderExped,
2775
            'cPais',
2776
            $std->cPais,
2777
            false,
2778
            $identificador . 'Código do país'
2779
        );
2780
        $this->dom->addChild(
2781
            $this->enderExped,
2782
            'xPais',
2783
            $std->xPais,
2784
            false,
2785
            $identificador . 'Nome do país'
2786
        );
2787
        $node = $this->exped->getElementsByTagName("email")->item(0);
2788
        $this->exped->insertBefore($this->enderExped, $node);
2789
        return $this->enderExped;
2790
    }
2791
2792
    /**
2793
     * Gera as tags para o elemento: "receb" (Informações do Recebedor da Carga)
2794
     * #150
2795
     * Nível: 1
2796
     * Os parâmetros para esta função são todos os elementos da tag "receb" do
2797
     * tipo elemento (Ele = E|CE|A) e nível 2
2798
     *
2799
     * @return \DOMElement
2800
     */
2801
    public function tagreceb($std)
2802
    {
2803
2804
        $possible = [
2805
            'CNPJ',
2806
            'CPF',
2807
            'IE',
2808
            'xNome',
2809
            'fone',
2810
            'email'
2811
        ];
2812
2813
        $std = $this->equilizeParameters($std, $possible);
2814
2815
        $identificador = '#160 <receb> - ';
2816
        $this->receb = $this->dom->createElement('receb');
2817
        if ($std->CNPJ != '') {
2818
            $this->dom->addChild(
2819
                $this->receb,
2820
                'CNPJ',
2821
                $std->CNPJ,
2822
                true,
2823
                $identificador . 'Número do CNPJ'
2824
            );
2825
        } elseif ($std->CPF != '') {
2826
            $this->dom->addChild(
2827
                $this->receb,
2828
                'CPF',
2829
                $std->CPF,
2830
                true,
2831
                $identificador . 'Número do CPF'
2832
            );
2833
        } else {
2834
            $this->dom->addChild(
2835
                $this->receb,
2836
                'CNPJ',
2837
                $std->CNPJ,
2838
                true,
2839
                $identificador . 'Número do CNPJ'
2840
            );
2841
            $this->dom->addChild(
2842
                $this->receb,
2843
                'CPF',
2844
                $std->CPF,
2845
                true,
2846
                $identificador . 'Número do CPF'
2847
            );
2848
        }
2849
        if (!empty($std->IE)) {
2850
            $this->dom->addChild(
2851
                $this->receb,
2852
                'IE',
2853
                $std->IE,
2854
                true,
2855
                $identificador . 'Inscrição Estadual'
2856
            );
2857
        }
2858
        $xNome = $std->xNome;
2859
        if ($this->tpAmb == '2') {
2860
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2861
        }
2862
        $this->dom->addChild(
2863
            $this->receb,
2864
            'xNome',
2865
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2866
            true,
2867
            $identificador . 'Razão social ou Nome'
2868
        );
2869
        $this->dom->addChild(
2870
            $this->receb,
2871
            'fone',
2872
            $std->fone,
2873
            false,
2874
            $identificador . 'Telefone'
2875
        );
2876
        $this->dom->addChild(
2877
            $this->receb,
2878
            'email',
2879
            $std->email,
2880
            false,
2881
            $identificador . 'Endereço de email'
2882
        );
2883
        return $this->receb;
2884
    }
2885
2886
    /**
2887
     * Gera as tags para o elemento: "enderReceb" (Informações do Recebedor da Carga)
2888
     * #156
2889
     * Nível: 2
2890
     * Os parâmetros para esta função são todos os elementos da tag "enderReceb" do
2891
     * tipo elemento (Ele = E|CE|A) e nível 3
2892
     *
2893
     * @return \DOMElement
2894
     */
2895
    public function tagenderReceb($std)
2896
    {
2897
2898
        $possible = [
2899
            'xLgr',
2900
            'nro',
2901
            'xCpl',
2902
            'xBairro',
2903
            'cMun',
2904
            'xMun',
2905
            'CEP',
2906
            'UF',
2907
            'cPais',
2908
            'xPais'
2909
        ];
2910
2911
        $std = $this->equilizeParameters($std, $possible);
2912
2913
        $identificador = '#160 <enderReceb> - ';
2914
        $this->enderReceb = $this->dom->createElement('enderReceb');
2915
        $this->dom->addChild(
2916
            $this->enderReceb,
2917
            'xLgr',
2918
            $std->xLgr,
2919
            true,
2920
            $identificador . 'Logradouro'
2921
        );
2922
        $this->dom->addChild(
2923
            $this->enderReceb,
2924
            'nro',
2925
            $std->nro,
2926
            true,
2927
            $identificador . 'Número'
2928
        );
2929
        $this->dom->addChild(
2930
            $this->enderReceb,
2931
            'xCpl',
2932
            $std->xCpl,
2933
            false,
2934
            $identificador . 'Complemento'
2935
        );
2936
        $this->dom->addChild(
2937
            $this->enderReceb,
2938
            'xBairro',
2939
            $std->xBairro,
2940
            true,
2941
            $identificador . 'Bairro'
2942
        );
2943
        $this->dom->addChild(
2944
            $this->enderReceb,
2945
            'cMun',
2946
            $std->cMun,
2947
            true,
2948
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2949
        );
2950
        $this->dom->addChild(
2951
            $this->enderReceb,
2952
            'xMun',
2953
            $std->xMun,
2954
            true,
2955
            $identificador . 'Nome do município'
2956
        );
2957
        $this->dom->addChild(
2958
            $this->enderReceb,
2959
            'CEP',
2960
            $std->CEP,
2961
            false,
2962
            $identificador . 'CEP'
2963
        );
2964
        $this->dom->addChild(
2965
            $this->enderReceb,
2966
            'UF',
2967
            $std->UF,
2968
            true,
2969
            $identificador . 'Sigla da UF'
2970
        );
2971
        $this->dom->addChild(
2972
            $this->enderReceb,
2973
            'cPais',
2974
            $std->cPais,
2975
            false,
2976
            $identificador . 'Código do país'
2977
        );
2978
        $this->dom->addChild(
2979
            $this->enderReceb,
2980
            'xPais',
2981
            $std->xPais,
2982
            false,
2983
            $identificador . 'Nome do país'
2984
        );
2985
        $node = $this->receb->getElementsByTagName("email")->item(0);
2986
        $this->receb->insertBefore($this->enderReceb, $node);
2987
        return $this->enderReceb;
2988
    }
2989
2990
    /**
2991
     * Gera as tags para o elemento: "dest" (Informações do Destinatário do CT-e)
2992
     * #168
2993
     * Nível: 1
2994
     * Os parâmetros para esta função são todos os elementos da tag "dest" do
2995
     * tipo elemento (Ele = E|CE|A) e nível 2
2996
     *
2997
     * @return \DOMElement
2998
     */
2999
    public function tagdest($std)
3000
    {
3001
3002
        $possible = [
3003
            'CNPJ',
3004
            'CPF',
3005
            'IE',
3006
            'xNome',
3007
            'fone',
3008
            'ISUF',
3009
            'email'
3010
        ];
3011
3012
        $std = $this->equilizeParameters($std, $possible);
3013
3014
        $identificador = '#178 <dest> - ';
3015
        $this->dest = $this->dom->createElement('dest');
3016
        if ($std->CNPJ != '') {
3017
            $this->dom->addChild(
3018
                $this->dest,
3019
                'CNPJ',
3020
                $std->CNPJ,
3021
                true,
3022
                $identificador . 'Número do CNPJ'
3023
            );
3024
        } elseif ($std->CPF != '') {
3025
            $this->dom->addChild(
3026
                $this->dest,
3027
                'CPF',
3028
                $std->CPF,
3029
                true,
3030
                $identificador . 'Número do CPF'
3031
            );
3032
        } else {
3033
            $this->dom->addChild(
3034
                $this->dest,
3035
                'CNPJ',
3036
                $std->CNPJ,
3037
                true,
3038
                $identificador . 'Número do CNPJ'
3039
            );
3040
            $this->dom->addChild(
3041
                $this->dest,
3042
                'CPF',
3043
                $std->CPF,
3044
                true,
3045
                $identificador . 'Número do CPF'
3046
            );
3047
        }
3048
        if (!empty($std->IE)) {
3049
            $this->dom->addChild(
3050
                $this->dest,
3051
                'IE',
3052
                $std->IE,
3053
                true,
3054
                $identificador . 'Inscrição Estadual'
3055
            );
3056
        }
3057
        $xNome = $std->xNome;
3058
        if ($this->tpAmb == '2') {
3059
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
3060
        }
3061
        $this->dom->addChild(
3062
            $this->dest,
3063
            'xNome',
3064
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
3065
            true,
3066
            $identificador . 'Razão social ou Nome'
3067
        );
3068
        $this->dom->addChild(
3069
            $this->dest,
3070
            'fone',
3071
            $std->fone,
3072
            false,
3073
            $identificador . 'Telefone'
3074
        );
3075
        $this->dom->addChild(
3076
            $this->dest,
3077
            'ISUF',
3078
            $std->ISUF,
3079
            false,
3080
            $identificador . 'Inscrição na SUFRAMA'
3081
        );
3082
        $this->dom->addChild(
3083
            $this->dest,
3084
            'email',
3085
            $std->email,
3086
            false,
3087
            $identificador . 'Endereço de email'
3088
        );
3089
        return $this->dest;
3090
    }
3091
3092
    /**
3093
     * Gera as tags para o elemento: "enderDest" (Informações do Recebedor da Carga)
3094
     * # = 175
3095
     * Nível = 2
3096
     * Os parâmetros para esta função são todos os elementos da tag "enderDest" do
3097
     * tipo elemento (Ele = E|CE|A) e nível 3
3098
     *
3099
     * @return \DOMElement
3100
     */
3101
    public function tagenderDest($std)
3102
    {
3103
3104
        $possible = [
3105
            'xLgr',
3106
            'nro',
3107
            'xCpl',
3108
            'xBairro',
3109
            'cMun',
3110
            'xMun',
3111
            'CEP',
3112
            'UF',
3113
            'cPais',
3114
            'xPais'
3115
        ];
3116
3117
        $std = $this->equilizeParameters($std, $possible);
3118
3119
        $identificador = '#185 <enderDest> - ';
3120
        $this->enderDest = $this->dom->createElement('enderDest');
3121
        $this->dom->addChild(
3122
            $this->enderDest,
3123
            'xLgr',
3124
            $std->xLgr,
3125
            true,
3126
            $identificador . 'Logradouro'
3127
        );
3128
        $this->dom->addChild(
3129
            $this->enderDest,
3130
            'nro',
3131
            $std->nro,
3132
            true,
3133
            $identificador . 'Número'
3134
        );
3135
        $this->dom->addChild(
3136
            $this->enderDest,
3137
            'xCpl',
3138
            $std->xCpl,
3139
            false,
3140
            $identificador . 'Complemento'
3141
        );
3142
        $this->dom->addChild(
3143
            $this->enderDest,
3144
            'xBairro',
3145
            $std->xBairro,
3146
            true,
3147
            $identificador . 'Bairro'
3148
        );
3149
        $this->dom->addChild(
3150
            $this->enderDest,
3151
            'cMun',
3152
            $std->cMun,
3153
            true,
3154
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
3155
        );
3156
        $this->dom->addChild(
3157
            $this->enderDest,
3158
            'xMun',
3159
            $std->xMun,
3160
            true,
3161
            $identificador . 'Nome do município'
3162
        );
3163
        $this->dom->addChild(
3164
            $this->enderDest,
3165
            'CEP',
3166
            $std->CEP,
3167
            false,
3168
            $identificador . 'CEP'
3169
        );
3170
        $this->dom->addChild(
3171
            $this->enderDest,
3172
            'UF',
3173
            $std->UF,
3174
            true,
3175
            $identificador . 'Sigla da UF'
3176
        );
3177
        $this->dom->addChild(
3178
            $this->enderDest,
3179
            'cPais',
3180
            $std->cPais,
3181
            false,
3182
            $identificador . 'Código do país'
3183
        );
3184
        $this->dom->addChild(
3185
            $this->enderDest,
3186
            'xPais',
3187
            $std->xPais,
3188
            false,
3189
            $identificador . 'Nome do país'
3190
        );
3191
        $node = $this->dest->getElementsByTagName("email")->item(0);
3192
        $this->dest->insertBefore($this->enderDest, $node);
3193
        return $this->enderDest;
3194
    }
3195
3196
    /**
3197
     * Gera as tags para o elemento: "vPrest" (Valores da Prestação de Serviço)
3198
     * #187
3199
     * Nível: 1
3200
     * Os parâmetros para esta função são todos os elementos da tag "vPrest" do
3201
     * tipo elemento (Ele = E|CE|A) e nível 2
3202
     *
3203
     * @return \DOMElement
3204
     */
3205
    public function tagvPrest($std)
3206
    {
3207
3208
        $possible = [
3209
            'vTPrest',
3210
            'vRec'
3211
        ];
3212
3213
        $std = $this->equilizeParameters($std, $possible);
3214
3215
        $identificador = '#208 <vPrest> - ';
3216
        $this->vPrest = $this->dom->createElement('vPrest');
3217
        $this->dom->addChild(
3218
            $this->vPrest,
3219
            'vTPrest',
3220
            $std->vTPrest,
3221
            true,
3222
            $identificador . 'Valor Total da Prestação do Serviço'
3223
        );
3224
        $this->dom->addChild(
3225
            $this->vPrest,
3226
            'vRec',
3227
            $std->vRec,
3228
            true,
3229
            $identificador . 'Valor a Receber'
3230
        );
3231
        return $this->vPrest;
3232
    }
3233
3234
    /**
3235
     * Gera as tags para o elemento: "Comp" (Componentes do Valor da Prestação)
3236
     * #211
3237
     * Nível: 2
3238
     * Os parâmetros para esta função são todos os elementos da tag "Comp" do
3239
     * tipo elemento (Ele = E|CE|A) e nível 3
3240
     *
3241
     * @return \DOMElement
3242
     */
3243
    public function tagComp($std)
3244
    {
3245
3246
        $possible = [
3247
            'xNome',
3248
            'vComp'
3249
        ];
3250
3251
        $std = $this->equilizeParameters($std, $possible);
3252
3253
        $identificador = '#65 <pass> - ';
3254
        $this->comp[] = $this->dom->createElement('Comp');
3255
        $posicao = (int)count($this->comp) - 1;
3256
        $this->dom->addChild(
3257
            $this->comp[$posicao],
3258
            'xNome',
3259
            $std->xNome,
3260
            false,
3261
            $identificador . 'Nome do componente'
3262
        );
3263
        $this->dom->addChild(
3264
            $this->comp[$posicao],
3265
            'vComp',
3266
            $std->vComp,
3267
            false,
3268
            $identificador . 'Valor do componente'
3269
        );
3270
        return $this->comp[$posicao];
3271
    }
3272
3273
    /**
3274
     * tagICMS
3275
     * Informações relativas ao ICMS
3276
     * #194
3277
     *
3278
     * @return DOMElement
3279
     */
3280
    public function tagicms($std)
3281
    {
3282
3283
        $possible = [
3284
            'cst',
3285
            'vBC',
3286
            'pICMS',
3287
            'vICMS',
3288
            'pRedBC',
3289
            'vBCSTRet',
3290
            'vICMSSTRet',
3291
            'pICMSSTRet',
3292
            'vCred',
3293
            'pRedBCOutraUF',
3294
            'vBCOutraUF',
3295
            'pICMSOutraUF',
3296
            'vICMSOutraUF',
3297
            'pRedBC',
3298
            'vTotTrib',
3299
            'infAdFisco',
3300
            'vBCUFFim',
3301
            'pFCPUFFim',
3302
            'pICMSUFFim',
3303
            'pICMSInter',
3304
            'vFCPUFFim',
3305
            'vICMSUFFim',
3306
            'vICMSUFIni'
3307
        ];
3308
3309
        $std = $this->equilizeParameters($std, $possible);
3310
3311
        $identificador = 'N01 <ICMSxx> - ';
3312
        switch ($std->cst) {
3313
            case '00':
3314
                $icms = $this->dom->createElement("ICMS00");
3315
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 00");
3316
                $this->dom->addChild($icms, 'vBC', $std->vBC, true, "$identificador  Valor da BC do ICMS");
3317
                $this->dom->addChild($icms, 'pICMS', $std->pICMS, true, "$identificador  Alíquota do imposto");
3318
                $this->dom->addChild($icms, 'vICMS', $std->vICMS, true, "$identificador  Valor do ICMS");
3319
                break;
3320
            case '20':
3321
                $icms = $this->dom->createElement("ICMS20");
3322
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 20");
3323
                $this->dom->addChild(
3324
                    $icms,
3325
                    'pRedBC',
3326
                    $std->pRedBC,
3327
                    true,
3328
                    "$identificador  Percentual da Redução de BC"
3329
                );
3330
                $this->dom->addChild($icms, 'vBC', $std->vBC, true, "$identificador  Valor da BC do ICMS");
3331
                $this->dom->addChild($icms, 'pICMS', $std->pICMS, true, "$identificador  Alíquota do imposto");
3332
                $this->dom->addChild($icms, 'vICMS', $std->vICMS, true, "$identificador  Valor do ICMS");
3333
                break;
3334
            case '40':
3335
                $icms = $this->dom->createElement("ICMS45");
3336
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 40");
3337
                break;
3338
            case '41':
3339
                $icms = $this->dom->createElement("ICMS45");
3340
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 41");
3341
                break;
3342
            case '51':
3343
                $icms = $this->dom->createElement("ICMS45");
3344
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 51");
3345
                break;
3346
            case '60':
3347
                $icms = $this->dom->createElement("ICMS60");
3348
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 60");
3349
                $this->dom->addChild(
3350
                    $icms,
3351
                    'vBCSTRet',
3352
                    $std->vBCSTRet,
3353
                    true,
3354
                    "$identificador  Valor BC do ICMS ST retido"
3355
                );
3356
                $this->dom->addChild(
3357
                    $icms,
3358
                    'vICMSSTRet',
3359
                    $std->vICMSSTRet,
3360
                    true,
3361
                    "$identificador  Valor do ICMS ST retido"
3362
                );
3363
                $this->dom->addChild(
3364
                    $icms,
3365
                    'pICMSSTRet',
3366
                    $std->pICMSSTRet,
3367
                    true,
3368
                    "$identificador  Valor do ICMS ST retido"
3369
                );
3370
                if ($std->vCred > 0) {
3371
                    $this->dom->addChild($icms, 'vCred', $std->vCred, false, "$identificador  Valor do Crédito");
3372
                }
3373
                break;
3374
            case '90':
3375
                if ($std->outraUF == true) {
3376
                    $icms = $this->dom->createElement("ICMSOutraUF");
3377
                    $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 90");
3378
                    if ($std->vICMSOutraUF > 0) {
3379
                        $this->dom->addChild(
3380
                            $icms,
3381
                            'pRedBCOutraUF',
3382
                            $std->pRedBCOutraUF,
3383
                            false,
3384
                            "$identificador Percentual Red "
3385
                            . "BC Outra UF"
3386
                        );
3387
                    }
3388
                    $this->dom->addChild(
3389
                        $icms,
3390
                        'vBCOutraUF',
3391
                        $std->vBCOutraUF,
3392
                        true,
3393
                        "$identificador Valor BC ICMS Outra UF"
3394
                    );
3395
                    $this->dom->addChild(
3396
                        $icms,
3397
                        'pICMSOutraUF',
3398
                        $std->pICMSOutraUF,
3399
                        true,
3400
                        "$identificador Alíquota do imposto Outra UF"
3401
                    );
3402
                    $this->dom->addChild(
3403
                        $icms,
3404
                        'vICMSOutraUF',
3405
                        $std->vICMSOutraUF,
3406
                        true,
3407
                        "$identificador Valor ICMS Outra UF"
3408
                    );
3409
                } else {
3410
                    $icms = $this->dom->createElement("ICMS90");
3411
                    $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador Tributação do ICMS = 90");
3412
                    if ($std->pRedBC > 0) {
3413
                        $this->dom->addChild(
3414
                            $icms,
3415
                            'pRedBC',
3416
                            $std->pRedBC,
3417
                            false,
3418
                            "$identificador Percentual Redução BC"
3419
                        );
3420
                    }
3421
                    $this->dom->addChild($icms, 'vBC', $std->vBC, true, "$identificador  Valor da BC do ICMS");
3422
                    $this->dom->addChild($icms, 'pICMS', $std->pICMS, true, "$identificador  Alíquota do imposto");
3423
                    $this->dom->addChild($icms, 'vICMS', $std->vICMS, true, "$identificador  Valor do ICMS");
3424
                    if ($std->vCred > 0) {
3425
                        $this->dom->addChild($icms, 'vCred', $std->vCred, false, "$identificador  Valor do Crédido");
3426
                    }
3427
                }
3428
                break;
3429
            case 'SN':
3430
                $icms = $this->dom->createElement("ICMSSN");
3431
                $this->dom->addChild($icms, 'CST', 90, true, "$identificador Tributação do ICMS = 90");
3432
                $this->dom->addChild($icms, 'indSN', '1', true, "$identificador  Indica se contribuinte é SN");
3433
                break;
3434
        }
3435
        $this->imp = $this->dom->createElement('imp');
3436
        $tagIcms = $this->dom->createElement('ICMS');
3437
        if (isset($icms)) {
3438
            $this->imp->appendChild($tagIcms);
3439
        }
3440
        if (isset($icms)) {
3441
            $tagIcms->appendChild($icms);
3442
        }
3443
        if ($std->vTotTrib > 0) {
3444
            $this->dom->addChild(
3445
                $this->imp,
3446
                'vTotTrib',
3447
                $std->vTotTrib,
3448
                false,
3449
                "$identificador Valor Total dos Tributos"
3450
            );
3451
        }
3452
        if (isset($std->infAdFisco)) {
3453
            $this->dom->addChild(
3454
                $this->imp,
3455
                'infAdFisco',
3456
                $std->infAdFisco,
3457
                false,
3458
                "$identificador Informações adicionais de interesse do Fisco"
3459
            );
3460
        }
3461
3462
        if ($std->vICMSUFFim != '' || $std->vICMSUFIni != '') {
3463
            $icmsDifal = $this->dom->createElement("ICMSUFFim");
3464
            $this->dom->addChild(
3465
                $icmsDifal,
3466
                'vBCUFFim',
3467
                $std->vBCUFFim,
3468
                true,
3469
                "$identificador Valor da BC do ICMS na UF
3470
                de término da prestação do serviço de transporte"
3471
            );
3472
            $this->dom->addChild(
3473
                $icmsDifal,
3474
                'pFCPUFFim',
3475
                $std->pFCPUFFim,
3476
                true,
3477
                "$identificador Percentual do ICMS
3478
                relativo ao Fundo de Combate à pobreza (FCP) na UF de término da prestação do serviço de
3479
                transporte"
3480
            );
3481
            $this->dom->addChild(
3482
                $icmsDifal,
3483
                'pICMSUFFim',
3484
                $std->pICMSUFFim,
3485
                true,
3486
                "$identificador Alíquota interna da UF
3487
                de término da prestação do serviço de transporte"
3488
            );
3489
            $this->dom->addChild(
3490
                $icmsDifal,
3491
                'pICMSInter',
3492
                $std->pICMSInter,
3493
                true,
3494
                "$identificador Alíquota interestadual
3495
                das UF envolvidas"
3496
            );
3497
            $this->dom->addChild(
3498
                $icmsDifal,
3499
                'vFCPUFFim',
3500
                $std->vFCPUFFim,
3501
                true,
3502
                "$identificador Valor do ICMS relativo
3503
                ao Fundo de Combate á Pobreza (FCP) da UF de término da prestação"
3504
            );
3505
            $this->dom->addChild(
3506
                $icmsDifal,
3507
                'vICMSUFFim',
3508
                $std->vICMSUFFim,
3509
                true,
3510
                "$identificador Valor do ICMS de
3511
                partilha para a UF de término da prestação do serviço de transporte"
3512
            );
3513
            $this->dom->addChild(
3514
                $icmsDifal,
3515
                'vICMSUFIni',
3516
                $std->vICMSUFIni,
3517
                true,
3518
                "$identificador Valor do ICMS de
3519
                partilha para a UF de início da prestação do serviço de transporte"
3520
            );
3521
3522
            $this->imp->appendChild($icmsDifal);
3523
        }
3524
3525
        return $tagIcms;
3526
    }
3527
3528
    /**
3529
     * tagInfTribFed
3530
     * Informações do Impostos Federais
3531
     * CTe OS
3532
     * @return DOMElement
3533
     */
3534
    public function taginfTribFed($std)
3535
    {
3536
3537
        $possible = [
3538
            'vPIS',
3539
            'vCOFINS',
3540
            'vIR',
3541
            'vINSS',
3542
            'vCSLL'
3543
        ];
3544
3545
        $std = $this->equilizeParameters($std, $possible);
3546
3547
        $identificador = 'N02 <imp> - ';
3548
        $tagInfTribFed = $this->dom->createElement('infTribFed');
3549
        $this->dom->addChild($tagInfTribFed, 'vPIS', $std->vPIS, false, "$identificador  Valor de PIS");
3550
        $this->dom->addChild($tagInfTribFed, 'vCOFINS', $std->vCOFINS, false, "$identificador  Valor de COFINS");
3551
        $this->dom->addChild($tagInfTribFed, 'vIR', $std->vIR, false, "$identificador  Valor de IR");
3552
        $this->dom->addChild($tagInfTribFed, 'vINSS', $std->vINSS, false, "$identificador  Valor de INSS");
3553
        $this->dom->addChild($tagInfTribFed, 'vCSLL', $std->vCSLL, false, "$identificador  Valor de CSLL");
3554
        $this->imp->appendChild($tagInfTribFed);
3555
    }
3556
3557
3558
    /**
3559
     * Tag raiz do documento xml
3560
     * Função chamada pelo método [ monta ]
3561
     * @return \DOMElement
3562
     */
3563
    private function buildCTe()
3564
    {
3565
        if (empty($this->CTe)) {
3566
            $this->CTe = $this->dom->createElement('CTe');
3567
            $this->CTe->setAttribute('xmlns', 'http://www.portalfiscal.inf.br/cte');
3568
        }
3569
        return $this->CTe;
3570
    }
3571
3572
    /**
3573
     * Tag raiz do documento xml
3574
     * Função chamada pelo método [ monta ]
3575
     * @return \DOMElement
3576
     */
3577
    private function buildCTeOS()
3578
    {
3579
        if (empty($this->CTe)) {
3580
            $this->CTe = $this->dom->createElement('CTeOS');
3581
            $this->CTe->setAttribute('versao', '3.00');
3582
            $this->CTe->setAttribute('xmlns', 'http://www.portalfiscal.inf.br/cte');
3583
        }
3584
        return $this->CTe;
3585
    }
3586
3587
    /**
3588
     * Gera as tags para o elemento: "Entrega" (Informações ref. a previsão de entrega)
3589
     * #69
3590
     * Nível: 2
3591
     * Os parâmetros para esta função são todos os elementos da tag "Entrega" do
3592
     * tipo elemento (Ele = E|CE|A) e nível 3
3593
     *
3594
     * @return \DOMElement
3595
     */
3596
    private function tagEntrega()
3597
    {
3598
        if ($this->compl == '') {
3599
            $this->compl = $this->dom->createElement('compl');
3600
        }
3601
        if ($this->entrega == '') {
3602
            $this->entrega = $this->dom->createElement('Entrega');
3603
            $this->dom->appChild($this->compl, $this->entrega, 'Falta tag "compl"');
3604
        }
3605
        return $this->entrega;
3606
    }
3607
3608
    /**
3609
     * #241
3610
     * @return type
3611
     */
3612
    public function taginfCTeNorm()
3613
    {
3614
        $this->infCTeNorm = $this->dom->createElement('infCTeNorm');
3615
        return $this->infCTeNorm;
3616
    }
3617
3618
    /**
3619
     * Gera as tags para o elemento: "infCarga" (Informações da Carga do CT-e)
3620
     * #242
3621
     * Nível: 2
3622
     *
3623
     * @return \DOMElement
3624
     */
3625
    public function taginfCarga($std)
3626
    {
3627
3628
        $possible = [
3629
            'vCarga',
3630
            'proPred',
3631
            'xOutCat'
3632
        ];
3633
3634
        $std = $this->equilizeParameters($std, $possible);
3635
3636
        $identificador = '#242 <infCarga> - ';
3637
        $this->infCarga = $this->dom->createElement('infCarga');
3638
        $this->dom->addChild(
3639
            $this->infCarga,
3640
            'vCarga',
3641
            $std->vCarga,
3642
            false,
3643
            $identificador . 'Valor Total da Carga'
3644
        );
3645
        $this->dom->addChild(
3646
            $this->infCarga,
3647
            'proPred',
3648
            $std->proPred,
3649
            true,
3650
            $identificador . 'Produto Predominante'
3651
        );
3652
        $this->dom->addChild(
3653
            $this->infCarga,
3654
            'xOutCat',
3655
            $std->xOutCat,
3656
            false,
3657
            $identificador . 'Outras Caract. da Carga'
3658
        );
3659
        return $this->infCarga;
3660
    }
3661
3662
    /**
3663
     * Gera as tags para o elemento: "infCTeNorm" (Informações da Carga do CT-e OS)
3664
     * #253
3665
     * Nível: 2
3666
     * Os parâmetros para esta função são todos os elementos da tag "infServico"
3667
     *
3668
     * @return \DOMElement
3669
     */
3670
    public function taginfServico($std)
3671
    {
3672
3673
        $possible = [
3674
            'xDescServ'
3675
        ];
3676
3677
        $std = $this->equilizeParameters($std, $possible);
3678
3679
        $identificador = '#253 <infServico> - ';
3680
        $this->infServico = $this->dom->createElement('infServico');
3681
        $this->dom->addChild(
3682
            $this->infServico,
3683
            'xDescServ',
3684
            $std->xDescServ,
3685
            true,
3686
            $identificador . 'Descrição do Serviço Prestado'
3687
        );
3688
        $infQ = $this->dom->createElement('infQ');
3689
        $this->dom->addChild($infQ, 'qCarga', $std->qCarga, false, $identificador . 'Quantidade');
3690
        $this->infServico->appendChild($infQ);
3691
        return $this->infServico;
3692
    }
3693
3694
    /**
3695
     * Gera as tags para o elemento: "infQ" (Informações de quantidades da Carga do CT-e)
3696
     * #246
3697
     * Nível: 3
3698
     * Os parâmetros para esta função são todos os elementos da tag "infQ"
3699
     *
3700
     * @return mixed
3701
     */
3702
    public function taginfQ($std)
3703
    {
3704
3705
        $possible = [
3706
            'cUnid',
3707
            'tpMed',
3708
            'qCarga',
3709
            'vCargaAverb'
3710
        ];
3711
3712
        $std = $this->equilizeParameters($std, $possible);
3713
3714
        $identificador = '#257 <infQ> - ';
3715
        $this->infQ[] = $this->dom->createElement('infQ');
3716
        $posicao = (int)count($this->infQ) - 1;
3717
        $this->dom->addChild(
3718
            $this->infQ[$posicao],
3719
            'cUnid',
3720
            $std->cUnid,
3721
            true,
3722
            $identificador . 'Código da Unidade de Medida'
3723
        );
3724
        $this->dom->addChild(
3725
            $this->infQ[$posicao],
3726
            'tpMed',
3727
            $std->tpMed,
3728
            true,
3729
            $identificador . 'Tipo da Medida'
3730
        );
3731
        $this->dom->addChild(
3732
            $this->infQ[$posicao],
3733
            'qCarga',
3734
            $std->qCarga,
3735
            true,
3736
            $identificador . 'Quantidade'
3737
        );
3738
        $this->dom->addChild(
3739
            $this->infQ[$posicao],
3740
            'vCargaAverb',
3741
            $std->vCargaAverb,
3742
            false,
3743
            $identificador . 'Valor da Carga para efeito de averbação'
3744
        );
3745
        return $this->infQ[$posicao];
3746
    }
3747
3748
    private function taginfDoc()
3749
    {
3750
        if (empty($this->infDoc)) {
3751
            $this->infDoc = $this->dom->createElement('infDoc');
3752
        }
3753
        return $this->infDoc;
3754
    }
3755
3756
    /**
3757
     * Documentos de Transporte Anterior
3758
     * @return DOMElement|\DOMNode
3759
     */
3760
    public function tagdocAnt()
3761
    {
3762
        $this->docAnt = $this->dom->createElement('docAnt');
3763
        return $this->docAnt;
3764
    }
3765
3766
    /**
3767
     * Informações de identificação dos documentos de Transporte Anterior
3768
     * @return array|DOMElement
3769
     */
3770
    public function tagidDocAnt()
3771
    {
3772
        $this->idDocAnt[count($this->emiDocAnt) - 1][] = $this->dom->createElement('idDocAnt');
3773
        return $this->idDocAnt;
3774
    }
3775
3776
    /**
3777
     * Gera as tags para o elemento: "infNF" (Informações das NF)
3778
     * #262
3779
     * Nível: 3
3780
     * @return mixed
3781
     */
3782
    public function taginfNF($std)
3783
    {
3784
3785
        $possible = [
3786
            'nRoma',
3787
            'nPed',
3788
            'mod',
3789
            'serie',
3790
            'nDoc',
3791
            'dEmi',
3792
            'vBC',
3793
            'vICMS',
3794
            'vBCST',
3795
            'vST',
3796
            'vProd',
3797
            'vNF',
3798
            'nCFOP',
3799
            'nPeso',
3800
            'PIN',
3801
            'dPrev',
3802
            'infUnidCarga',
3803
            'infUnidTransp'
3804
        ];
3805
        $this->taginfDoc();
3806
        $std = $this->equilizeParameters($std, $possible);
3807
3808
        $identificador = '#262 <infNF> - ';
3809
        $infNF = $this->dom->createElement('infNF');
3810
        $this->dom->addChild(
3811
            $infNF,
3812
            'nRoma',
3813
            $std->nRoma,
3814
            false,
3815
            $identificador . 'Número do Romaneio da NF'
3816
        );
3817
        $this->dom->addChild(
3818
            $infNF,
3819
            'nPed',
3820
            $std->nPed,
3821
            false,
3822
            $identificador . 'Número do Pedido da NF'
3823
        );
3824
        $this->dom->addChild(
3825
            $infNF,
3826
            'mod',
3827
            $std->mod,
3828
            true,
3829
            $identificador . 'Modelo da Nota Fiscal'
3830
        );
3831
        $this->dom->addChild(
3832
            $infNF,
3833
            'serie',
3834
            $std->serie,
3835
            true,
3836
            $identificador . 'Série'
3837
        );
3838
        $this->dom->addChild(
3839
            $infNF,
3840
            'nDoc',
3841
            $std->nDoc,
3842
            true,
3843
            $identificador . 'Número'
3844
        );
3845
        $this->dom->addChild(
3846
            $infNF,
3847
            'dEmi',
3848
            $std->dEmi,
3849
            true,
3850
            $identificador . 'Data de Emissão'
3851
        );
3852
        $this->dom->addChild(
3853
            $infNF,
3854
            'vBC',
3855
            $std->vBC,
3856
            true,
3857
            $identificador . 'Valor da Base de Cálculo do ICMS'
3858
        );
3859
        $this->dom->addChild(
3860
            $infNF,
3861
            'vICMS',
3862
            $std->vICMS,
3863
            true,
3864
            $identificador . 'Valor Totaldo ICMS'
3865
        );
3866
        $this->dom->addChild(
3867
            $infNF,
3868
            'vBCST',
3869
            $std->vBCST,
3870
            true,
3871
            $identificador . 'Valor da Base de Cálculo do ICMS ST'
3872
        );
3873
        $this->dom->addChild(
3874
            $infNF,
3875
            'vST',
3876
            $std->vST,
3877
            true,
3878
            $identificador . 'Valor Total do ICMS ST'
3879
        );
3880
        $this->dom->addChild(
3881
            $infNF,
3882
            'vProd',
3883
            $std->vProd,
3884
            true,
3885
            $identificador . 'Valor Total dos Produtos'
3886
        );
3887
        $this->dom->addChild(
3888
            $infNF,
3889
            'vNF',
3890
            $std->vNF,
3891
            true,
3892
            $identificador . 'Valor Total da NF'
3893
        );
3894
        $this->dom->addChild(
3895
            $infNF,
3896
            'nCFOP',
3897
            $std->nCFOP,
3898
            true,
3899
            $identificador . 'CFOP Predominante'
3900
        );
3901
        $this->dom->addChild(
3902
            $infNF,
3903
            'nPeso',
3904
            $std->nPeso,
3905
            false,
3906
            $identificador . 'Peso total em Kg'
3907
        );
3908
        $this->dom->addChild(
3909
            $infNF,
3910
            'PIN',
3911
            $std->PIN,
3912
            false,
3913
            $identificador . 'PIN SUFRAMA'
3914
        );
3915
        $this->dom->addChild(
3916
            $infNF,
3917
            'dPrev',
3918
            $std->dPrev,
3919
            false,
3920
            $identificador . 'Data prevista de entrega'
3921
        );
3922
        if ($std->infUnidCarga) {
3923
            foreach ($std->infUnidCarga as $value) {
3924
                $this->dom->appChild($infNF, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
3925
            }
3926
        }
3927
        if ($std->infUnidTransp) {
3928
            foreach ($std->infUnidTransp as $value) {
3929
                $this->dom->appChild($infNF, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
3930
            }
3931
        }
3932
        $this->infNF[] = $infNF;
3933
        return $infNF;
3934
    }
3935
3936
    /**
3937
     * Gera as tags para o elemento: "infNFe" (Informações das NF-e)
3938
     * #297
3939
     * Nível: 3
3940
     * @return mixed
3941
     */
3942
    public function taginfNFe($std)
3943
    {
3944
3945
        $possible = [
3946
            'chave',
3947
            'PIN',
3948
            'dPrev',
3949
            'infUnidCarga',
3950
            'infUnidTransp'
3951
        ];
3952
        $this->taginfDoc();
3953
        $std = $this->equilizeParameters($std, $possible);
3954
3955
        $identificador = '#297 <infNFe> - ';
3956
        $infNFe = $this->dom->createElement('infNFe');
3957
        $this->dom->addChild(
3958
            $infNFe,
3959
            'chave',
3960
            $std->chave,
3961
            true,
3962
            $identificador . 'Chave de acesso da NF-e'
3963
        );
3964
        $this->dom->addChild(
3965
            $infNFe,
3966
            'PIN',
3967
            $std->PIN,
3968
            false,
3969
            $identificador . 'PIN SUFRAMA'
3970
        );
3971
        $this->dom->addChild(
3972
            $infNFe,
3973
            'dPrev',
3974
            $std->dPrev,
3975
            false,
3976
            $identificador . 'Data prevista de entrega'
3977
        );
3978
        if ($std->infUnidCarga) {
3979
            foreach ($std->infUnidCarga as $value) {
3980
                $this->dom->appChild($infNFe, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
3981
            }
3982
        }
3983
        if ($std->infUnidTransp) {
3984
            foreach ($std->infUnidTransp as $value) {
3985
                $this->dom->appChild($infNFe, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
3986
            }
3987
        }
3988
        $this->infNFe[] = $infNFe;
3989
        return $infNFe;
3990
    }
3991
3992
    /**
3993
     * Gera as tags para o elemento: "infOutros" (Informações dos demais documentos)
3994
     * #319
3995
     * Nível: 3
3996
     * @return mixed
3997
     */
3998
    public function taginfOutros($std)
3999
    {
4000
4001
        $possible = [
4002
            'tpDoc',
4003
            'descOutros',
4004
            'nDoc',
4005
            'dEmi',
4006
            'vDocFisc',
4007
            'dPrev',
4008
            'infUnidCarga',
4009
            'infUnidTransp'
4010
        ];
4011
        $this->taginfDoc();
4012
        $std = $this->equilizeParameters($std, $possible);
4013
4014
        $ident = '#319 <infOutros> - ';
4015
        $infOutros = $this->dom->createElement('infOutros');
4016
        $this->dom->addChild(
4017
            $infOutros,
4018
            'tpDoc',
4019
            $std->tpDoc,
4020
            true,
4021
            $ident . 'Tipo de documento originário'
4022
        );
4023
        $this->dom->addChild(
4024
            $infOutros,
4025
            'descOutros',
4026
            $std->descOutros,
4027
            false,
4028
            $ident . 'Descrição do documento'
4029
        );
4030
        $this->dom->addChild(
4031
            $infOutros,
4032
            'nDoc',
4033
            $std->nDoc,
4034
            false,
4035
            $ident . 'Número do documento'
4036
        );
4037
        $this->dom->addChild(
4038
            $infOutros,
4039
            'dEmi',
4040
            $std->dEmi,
4041
            false,
4042
            $ident . 'Data de Emissão'
4043
        );
4044
        $this->dom->addChild(
4045
            $infOutros,
4046
            'vDocFisc',
4047
            $std->vDocFisc,
4048
            false,
4049
            $ident . 'Valor do documento'
4050
        );
4051
        $this->dom->addChild(
4052
            $infOutros,
4053
            'dPrev',
4054
            $std->dPrev,
4055
            false,
4056
            $ident . 'Data ista de entrega'
4057
        );
4058
        if ($std->infUnidCarga) {
4059
            foreach ($std->infUnidCarga as $value) {
4060
                $this->dom->appChild($infOutros, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
4061
            }
4062
        }
4063
        if ($std->infUnidTransp) {
4064
            foreach ($std->infUnidTransp as $value) {
4065
                $this->dom->appChild($infOutros, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
4066
            }
4067
        }
4068
        $this->infOutros[] = $infOutros;
4069
        return $infOutros;
4070
    }
4071
4072
    /**
4073
     * taginfUnidCarga
4074
     * tag CTe/infCte/infDoc/(infNF/infNFe/infOutros)/infUnidCarga
4075
     *
4076
     * @param stdClass $std
4077
     * @return DOMElement
4078
     */
4079
    private function taginfUnidCarga(stdClass $std)
4080
    {
4081
        $possible = [
4082
            'tpUnidCarga',
4083
            'idUnidCarga',
4084
            'lacUnidCarga',
4085
            'qtdRat'
4086
        ];
4087
        $std = $this->equilizeParameters($std, $possible);
4088
        $infUnidCarga = $this->dom->createElement("infUnidCarga");
4089
        $this->dom->addChild(
4090
            $infUnidCarga,
4091
            "tpUnidCarga",
4092
            $std->tpUnidCarga,
4093
            false,
4094
            "Tipo da Unidade de Carga"
4095
        );
4096
        $this->dom->addChild(
4097
            $infUnidCarga,
4098
            "idUnidCarga",
4099
            $std->idUnidCarga,
4100
            false,
4101
            "Identificação da Unidade de Carga "
4102
        );
4103
        if ($std->lacUnidCarga != null) {
4104
            $possible = [
4105
                'nLacre'
4106
            ];
4107
            $stdlacUnidCarga = $this->equilizeParameters($std->lacUnidCarga, $possible);
4108
            foreach ($stdlacUnidCarga->nLacre as $nLacre) {
4109
                $lacUnidCarga = $this->dom->createElement("lacUnidCarga");
4110
                $this->dom->addChild(
4111
                    $lacUnidCarga,
4112
                    "nLacre",
4113
                    $nLacre,
4114
                    true,
4115
                    "Número do lacre"
4116
                );
4117
                $this->dom->appChild($infUnidCarga, $lacUnidCarga, 'Falta tag "infUnidCarga"');
4118
            }
4119
        }
4120
        $this->dom->addChild(
4121
            $infUnidCarga,
4122
            "qtdRat",
4123
            $std->qtdRat,
4124
            false,
4125
            "Quantidade rateada (Peso,Volume)"
4126
        );
4127
        return $infUnidCarga;
4128
    }
4129
4130
    /**
4131
     * taginfUnidTransp
4132
     * tag CTe/infCte/infDoc/(infNF/infNFe/infOutros)/infUnidTransp
4133
     *
4134
     * @param stdClass $std
4135
     * @return DOMElement
4136
     */
4137
    private function taginfUnidTransp(stdClass $std)
4138
    {
4139
        $possible = [
4140
            'tpUnidTransp',
4141
            'idUnidTransp',
4142
            'qtdRat',
4143
            'lacUnidTransp',
4144
            'infUnidCarga'
4145
        ];
4146
        $std = $this->equilizeParameters($std, $possible);
4147
        $infUnidTransp = $this->dom->createElement("infUnidTransp");
4148
        $this->dom->addChild(
4149
            $infUnidTransp,
4150
            "tpUnidTransp",
4151
            $std->tpUnidTransp,
4152
            true,
4153
            "Tipo da Unidade de Transporte"
4154
        );
4155
        $this->dom->addChild(
4156
            $infUnidTransp,
4157
            "idUnidTransp",
4158
            $std->idUnidTransp,
4159
            false,
4160
            "Identificação da Unidade de Transporte"
4161
        );
4162
        if ($std->lacUnidTransp != null) {
4163
            $possible = [
4164
                'nLacre'
4165
            ];
4166
            $stdlacUnidTransp = $this->equilizeParameters($std->lacUnidTransp, $possible);
4167
            foreach ($stdlacUnidTransp->nLacre as $nLacre) {
4168
                $lacUnidTransp = $this->dom->createElement("lacUnidTransp");
4169
                $this->dom->addChild(
4170
                    $lacUnidTransp,
4171
                    "nLacre",
4172
                    $nLacre,
4173
                    true,
4174
                    "Número do lacre"
4175
                );
4176
                $this->dom->appChild($infUnidTransp, $lacUnidTransp, 'Falta tag "infUnidTransp"');
4177
            }
4178
        }
4179
        if ($std->infUnidCarga) {
4180
            foreach ($std->infUnidCarga as $value) {
4181
                $this->dom->appChild($infUnidTransp, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
4182
            }
4183
        }
4184
        $this->dom->addChild(
4185
            $infUnidTransp,
4186
            "qtdRat",
4187
            $std->qtdRat,
4188
            false,
4189
            "Quantidade rateada (Peso,Volume) "
4190
        );
4191
        return $infUnidTransp;
4192
    }
4193
4194
    /**
4195
     * Gera as tags para o elemento: "infDocRef" (Informações dos demais documentos)
4196
     * #319
4197
     * Nível: 3
4198
     * @return mixed
4199
     */
4200
    public function taginfDocRef($std)
4201
    {
4202
4203
        $possible = [
4204
            'nDoc',
4205
            'serie',
4206
            'subserie',
4207
            'dEmi',
4208
            'vDoc'
4209
        ];
4210
4211
        $std = $this->equilizeParameters($std, $possible);
4212
4213
        $ident = '#319 <infDocRef> - ';
4214
        $this->infDocRef[] = $this->dom->createElement('infDocRef');
4215
        $posicao = (int)count($this->infDocRef) - 1;
4216
        $this->dom->addChild(
4217
            $this->infDocRef[$posicao],
4218
            'nDoc',
4219
            $std->nDoc,
4220
            false,
4221
            $ident . 'Número do documento'
4222
        );
4223
        $this->dom->addChild(
4224
            $this->infDocRef[$posicao],
4225
            'serie',
4226
            $std->serie,
4227
            false,
4228
            $ident . 'Série do documento'
4229
        );
4230
        $this->dom->addChild(
4231
            $this->infDocRef[$posicao],
4232
            'subserie',
4233
            $std->subserie,
4234
            false,
4235
            $ident . 'Subserie do documento'
4236
        );
4237
        $this->dom->addChild(
4238
            $this->infDocRef[$posicao],
4239
            'dEmi',
4240
            $std->dEmi,
4241
            false,
4242
            $ident . 'Data de Emissão'
4243
        );
4244
        $this->dom->addChild(
4245
            $this->infDocRef[$posicao],
4246
            'vDoc',
4247
            $std->vDoc,
4248
            false,
4249
            $ident . 'Valor do documento'
4250
        );
4251
        return $this->infDocRef[$posicao];
4252
    }
4253
4254
    /**
4255
     * Gera as tags para o elemento: "emiDocAnt" (Informações dos CT-es Anteriores)
4256
     * #345
4257
     * Nível: 3
4258
     * @return mixed
4259
     */
4260
    public function tagemiDocAnt($std)
4261
    {
4262
4263
        $possible = [
4264
            'CNPJ',
4265
            'IE',
4266
            'UF',
4267
            'CPF',
4268
            'xNome'
4269
        ];
4270
4271
        $std = $this->equilizeParameters($std, $possible);
4272
4273
        $identificador = '#345 <emiDocAnt> - ';
4274
        $this->emiDocAnt[] = $this->dom->createElement('emiDocAnt');
4275
        $posicao = (int)count($this->emiDocAnt) - 1;
4276
        if ($std->CNPJ != '') {
4277
            $this->dom->addChild(
4278
                $this->emiDocAnt[$posicao],
4279
                'CNPJ',
4280
                $std->CNPJ,
4281
                true,
4282
                $identificador . 'Número do CNPJ'
4283
            );
4284
            $this->dom->addChild(
4285
                $this->emiDocAnt[$posicao],
4286
                'IE',
4287
                Strings::onlyNumbers($std->IE),
4288
                true,
4289
                $identificador . 'Inscrição Estadual'
4290
            );
4291
            $this->dom->addChild(
4292
                $this->emiDocAnt[$posicao],
4293
                'UF',
4294
                $std->UF,
4295
                true,
4296
                $identificador . 'Sigla da UF'
4297
            );
4298
        } else {
4299
            $this->dom->addChild(
4300
                $this->emiDocAnt[$posicao],
4301
                'CPF',
4302
                $std->CPF,
4303
                true,
4304
                $identificador . 'Número do CPF'
4305
            );
4306
        }
4307
        $this->dom->addChild(
4308
            $this->emiDocAnt[$posicao],
4309
            'xNome',
4310
            $std->xNome,
4311
            true,
4312
            $identificador . 'Razão Social ou Nome do Expedidor'
4313
        );
4314
        return $this->emiDocAnt[$posicao];
4315
    }
4316
4317
    /**
4318
     * Gera as tags para o elemento: "idDocAntEle" (Informações dos CT-es Anteriores)
4319
     * #348
4320
     * Nível: 4
4321
     * @return mixed
4322
     */
4323
    public function tagidDocAntEle($std)
4324
    {
4325
4326
        $possible = [
4327
            'chCTe'
4328
        ];
4329
4330
        $std = $this->equilizeParameters($std, $possible);
4331
4332
        $identificador = '#358 <idDocAntEle> - ';
4333
        $this->idDocAntEle[count($this->emiDocAnt) - 1][] = $this->dom->createElement('idDocAntEle');
4334
        $posicao = (int)count($this->idDocAntEle[count($this->emiDocAnt) - 1]) - 1;
4335
        $this->dom->addChild(
4336
            $this->idDocAntEle[count($this->emiDocAnt) - 1][$posicao],
4337
            'chCTe',
4338
            $std->chCTe,
4339
            true,
4340
            $identificador . 'Chave de Acesso do CT-e'
4341
        );
4342
        return $this->idDocAntEle[count($this->emiDocAnt) - 1][$posicao];
4343
    }
4344
4345
4346
    /**
4347
     * Gera as tags para o elemento: "seg" (Informações de Seguro da Carga)
4348
     * #360
4349
     * Nível: 2
4350
     * @return mixed
4351
     */
4352
    public function tagseg($std)
4353
    {
4354
4355
        $possible = [
4356
            'respSeg',
4357
            'xSeg',
4358
            'nApol'
4359
        ];
4360
4361
        $std = $this->equilizeParameters($std, $possible);
4362
4363
        $identificador = '#360 <seg> - ';
4364
        $this->seg[] = $this->dom->createElement('seg');
4365
        $posicao = (int)count($this->seg) - 1;
4366
        $this->dom->addChild(
4367
            $this->seg[$posicao],
4368
            'respSeg',
4369
            $std->respSeg,
4370
            true,
4371
            $identificador . 'Responsável pelo Seguro'
4372
        );
4373
        $this->dom->addChild(
4374
            $this->seg[$posicao],
4375
            'xSeg',
4376
            $std->xSeg,
4377
            false,
4378
            $identificador . 'Nome da Seguradora'
4379
        );
4380
        $this->dom->addChild(
4381
            $this->seg[$posicao],
4382
            'nApol',
4383
            $std->nApol,
4384
            false,
4385
            $identificador . 'Número da Apólice'
4386
        );
4387
        return $this->seg[$posicao];
4388
    }
4389
4390
    /**
4391
     * Gera as tags para o elemento: "idDocAntEle" (Informações dos CT-es Anteriores)
4392
     * #348
4393
     * Nível: 4
4394
     * @return mixed
4395
     */
4396
    public function tagidDocAntPap($std)
4397
    {
4398
4399
        $possible = [
4400
            'tpDoc',
4401
            'serie',
4402
            'subser',
4403
            'nDoc',
4404
            'dEmi'
4405
        ];
4406
4407
        $std = $this->equilizeParameters($std, $possible);
4408
4409
        $identificador = '#358 <idDocAntPap> - ';
4410
        $this->idDocAntPap[count($this->emiDocAnt) - 1][] = $this->dom->createElement('idDocAntPap');
4411
        $posicao = (int)count($this->idDocAntPap[count($this->emiDocAnt) - 1]) - 1;
4412
        $this->dom->addChild(
4413
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4414
            'tpDoc',
4415
            $std->tpDoc,
4416
            true,
4417
            $identificador . 'Tipo do Documento de Transporte Anterior'
4418
        );
4419
        $this->dom->addChild(
4420
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4421
            'serie',
4422
            $std->serie,
4423
            true,
4424
            $identificador . 'Série do Documento Fiscal'
4425
        );
4426
        $this->dom->addChild(
4427
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4428
            'subser',
4429
            $std->subser,
4430
            false,
4431
            $identificador . 'Série do Documento Fiscal'
4432
        );
4433
        $this->dom->addChild(
4434
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4435
            'nDoc',
4436
            $std->nDoc,
4437
            true,
4438
            $identificador . 'Número do Documento Fiscal'
4439
        );
4440
        $this->dom->addChild(
4441
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4442
            'dEmi',
4443
            $std->dEmi,
4444
            true,
4445
            $identificador . 'Data de emissão (AAAA-MM-DD)'
4446
        );
4447
        return $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao];
4448
    }
4449
4450
4451
    /**
4452
     * Gera as tags para o elemento: "infModal" (Informações do modal)
4453
     * #366
4454
     * Nível: 2
4455
     * @param string $versaoModal
0 ignored issues
show
Bug introduced by
There is no parameter named $versaoModal. 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...
4456
     * @return DOMElement|\DOMNode
4457
     */
4458
    public function taginfModal($std)
4459
    {
4460
        $this->infModal = $this->dom->createElement('infModal');
4461
        $this->infModal->setAttribute('versaoModal', $std->versaoModal);
4462
        return $this->infModal;
4463
    }
4464
4465
    /**
4466
     * Leiaute - Rodoviário
4467
     * Gera as tags para o elemento: "rodo" (Informações do modal Rodoviário)
4468
     * #1
4469
     * Nível: 0
4470
     * @return DOMElement|\DOMNode
4471
     */
4472
    public function tagrodo($std)
4473
    {
4474
4475
        $possible = [
4476
            'RNTRC'
4477
        ];
4478
4479
        $std = $this->equilizeParameters($std, $possible);
4480
4481
        $identificador = '#1 <rodo> - ';
4482
        $this->rodo = $this->dom->createElement('rodo');
4483
        $this->dom->addChild(
4484
            $this->rodo,
4485
            'RNTRC',
4486
            $std->RNTRC,
4487
            true,
4488
            $identificador . 'Registro nacional de transportadores
4489
            rodoviários de carga'
4490
        );
4491
        return $this->rodo;
4492
    }
4493
4494
    /**
4495
     * Leiaute - Dutoviário
4496
     * Gera as tags para o elemento: "duto" (informações do modal Dutoviário)
4497
     * @return DOMElement|\DOMNode
4498
     * @author Uilasmar Guedes
4499
     * #1
4500
     * Nivel: 0
4501
     */
4502
    public function tagduto($std)
4503
    {
4504
4505
        $possible = [
4506
            'vTar',
4507
            'dIni',
4508
            'dFim'
4509
        ];
4510
4511
        $std = $this->equilizeParameters($std, $possible);
4512
4513
        $identificador = '#1 <duto> - ';
4514
        $this->duto = $this->dom->createElement('duto');
4515
        $this->dom->addChild(
4516
            $this->duto,
4517
            'vTar',
4518
            $std->vTar,
4519
            false,
4520
            $identificador . 'Valor da tarifa '
4521
        );
4522
        $this->dom->addChild(
4523
            $this->duto,
4524
            'dIni',
4525
            $std->dIni,
4526
            true,
4527
            $identificador . 'Data de Início da prestação do serviço'
4528
        );
4529
        $this->dom->addChild(
4530
            $this->duto,
4531
            'dFim',
4532
            $std->dFim,
4533
            true,
4534
            $identificador . 'Data de Fim da prestação do serviço'
4535
        );
4536
        return $this->duto;
4537
    }
4538
4539
    /**
4540
     * Leiaute - Aquaviario
4541
     * Gera as tags para o elemento: "aquav" (informações do modal Aquaviario)
4542
     * @return DOMElement|\DOMNode
4543
     * @author Anderson Minuto Consoni Vaz
4544
     * #1
4545
     * Nivel: 0
4546
     */
4547
    public function tagaquav($std)
4548
    {
4549
4550
        $possible = [
4551
            'vPrest',
4552
            'vAFRMM',
4553
            'xNavio',
4554
            'nViag',
4555
            'direc',
4556
            'irin',
4557
            'tpNav'
4558
        ];
4559
4560
        $std = $this->equilizeParameters($std, $possible);
4561
4562
        $identificador = '#1 <aquav> - ';
4563
        $this->aquav = $this->dom->createElement('aquav');
4564
        $this->dom->addChild(
4565
            $this->aquav,
4566
            'vPrest',
4567
            $std->vPrest,
4568
            true,
4569
            $identificador . 'vPrest'
4570
        );
4571
        $this->dom->addChild(
4572
            $this->aquav,
4573
            'vAFRMM',
4574
            $std->vAFRMM,
4575
            true,
4576
            $identificador . 'vAFRMM'
4577
        );
4578
        $this->dom->addChild(
4579
            $this->aquav,
4580
            'xNavio',
4581
            $std->xNavio,
4582
            true,
4583
            $identificador . 'xNavio'
4584
        );
4585
        $this->dom->addChild(
4586
            $this->aquav,
4587
            'nViag',
4588
            $std->nViag,
4589
            true,
4590
            $identificador . 'nViag'
4591
        );
4592
        $this->dom->addChild(
4593
            $this->aquav,
4594
            'direc',
4595
            $std->direc,
4596
            true,
4597
            $identificador . 'direc'
4598
        );
4599
        $this->dom->addChild(
4600
            $this->aquav,
4601
            'irin',
4602
            $std->irin,
4603
            true,
4604
            $identificador . 'irin'
4605
        );
4606
        $this->dom->addChild(
4607
            $this->aquav,
4608
            'tpNav',
4609
            $std->tpNav,
4610
            false,
4611
            $identificador . 'tpNav'
4612
        );
4613
        return $this->aquav;
4614
    }
4615
4616
    /**
4617
     * Leiaute - Aquaviario
4618
     * Gera as tags de balsa para o elemento: "aquav" (informações do modal Aquaviario)
4619
     * @return DOMElement|\DOMNode
4620
     * @author Gabriel Kliemaschewsk Rondon
4621
     * #5
4622
     * Nivel: 1
4623
     */
4624
    public function tagbalsa($std)
4625
    {
4626
        $possible = [
4627
            'xBalsa',
4628
        ];
4629
4630
        $std = $this->equilizeParameters($std, $possible);
4631
4632
        $identificador = '#5 <balsa> - ';
4633
        $this->balsa[] = $this->dom->createElement('balsa');
4634
4635
        $this->dom->addChild(
4636
            $this->balsa[count($this->balsa) - 1],
4637
            'xBalsa',
4638
            $std->xBalsa,
4639
            true,
4640
            $identificador . 'xBalsa'
4641
        );
4642
        return $this->balsa;
4643
    }
4644
4645
    /**
4646
     * Leiaute - Aquaviario
4647
     * Gera as tags de Conteiner específicas do modal aquaviário
4648
     * @return DOMElement|\DOMNode
4649
     * @author Gabriel Kliemaschewsk Rondon
4650
     * #10
4651
     * Nivel: 1
4652
     */
4653
    public function tagdetCont($std)
4654
    {
4655
        $possible = [
4656
            'nCont',
4657
        ];
4658
4659
        $std = $this->equilizeParameters($std, $possible);
4660
4661
        $identificador = '#10 <detCont> - ';
4662
        $this->detCont[] = $this->dom->createElement('detCont');
4663
4664
        $this->dom->addChild(
4665
            $this->detCont[count($this->detCont) - 1],
4666
            'nCont',
4667
            $std->nCont,
4668
            true,
4669
            $identificador . 'detCont'
4670
        );
4671
        return $this->detCont;
4672
    }
4673
4674
    /**
4675
     * Leiaute - Aquaviario
4676
     * Gera as tags de lacre para os containeres do elemento: "aquav" (informações do modal Aquaviario)
4677
     * @return DOMElement|\DOMNode
4678
     * @author Gabriel Kliemaschewsk Rondon
4679
     * #12
4680
     * Nivel: 2
4681
     */
4682
    public function taglacre($std)
4683
    {
4684
        $possible = [
4685
            'nLacre',
4686
        ];
4687
4688
        $std = $this->equilizeParameters($std, $possible);
4689
4690
        $identificador = '#12 <detCont> - ';
4691
        $this->lacre[count($this->detCont) - 1][] = $this->dom->createElement('lacre');
4692
        $posicao = (int)count($this->lacre[count($this->detCont) - 1]) - 1;
4693
4694
        $this->dom->addChild(
4695
            $this->lacre[count($this->detCont) - 1][$posicao],
4696
            'nLacre',
4697
            $std->nLacre,
4698
            true,
4699
            $identificador . 'Lacre'
4700
        );
4701
        return $this->lacre[count($this->detCont) - 1][$posicao];
4702
    }
4703
4704
    public function taginfDocCont()
4705
    {
4706
        $this->infDocCont[count($this->detCont) - 1] = $this->dom->createElement('infDoc');
4707
        return $this->infDocCont;
4708
    }
4709
4710
    public function taginfNFCont($std)
4711
    {
4712
        $possible = [
4713
            'serie',
4714
            'nDoc',
4715
            'unidRat',
4716
        ];
4717
        $std = $this->equilizeParameters($std, $possible);
4718
        $identificador = '#15 <detCont> <infNF> - ';
4719
        $this->infNFCont[count($this->detCont) - 1][] = $this->dom->createElement('infNF');
4720
        $posicao = (int)count($this->infNFCont[count($this->detCont) - 1]) - 1;
4721
4722
        $this->dom->addChild(
4723
            $this->infNFCont[count($this->detCont) - 1][$posicao],
4724
            'serie',
4725
            $std->serie,
4726
            true,
4727
            $identificador . 'serie'
4728
        );
4729
4730
        $this->dom->addChild(
4731
            $this->infNFCont[count($this->detCont) - 1][$posicao],
4732
            'nDoc',
4733
            $std->nDoc,
4734
            true,
4735
            $identificador . 'nDoc'
4736
        );
4737
4738
        $this->dom->addChild(
4739
            $this->infNFCont[count($this->detCont) - 1][$posicao],
4740
            'unidRat',
4741
            $std->unidRat,
4742
            false,
4743
            $identificador . 'unidRat'
4744
        );
4745
4746
        return $this->infNFCont[count($this->detCont) - 1][$posicao];
4747
    }
4748
4749
    public function taginfNFeCont($std)
4750
    {
4751
        $possible = [
4752
            'chave',
4753
            'unidRat',
4754
        ];
4755
4756
        $std = $this->equilizeParameters($std, $possible);
4757
        $identificador = '#19 <infNFe> - ';
4758
        $this->infNFeCont[count($this->detCont) - 1][] = $this->dom->createElement('infNFe');
4759
        $posicao = (int)count($this->infNFeCont[count($this->detCont) - 1]) - 1;
4760
4761
        $this->dom->addChild(
4762
            $this->infNFeCont[count($this->detCont) - 1][$posicao],
4763
            'chave',
4764
            $std->chave,
4765
            true,
4766
            $identificador . 'chave'
4767
        );
4768
4769
        $this->dom->addChild(
4770
            $this->infNFeCont[count($this->detCont) - 1][$posicao],
4771
            'unidRat',
4772
            $std->unidRat,
4773
            false,
4774
            $identificador . 'unidRat'
4775
        );
4776
    }
4777
    /**
4778
     * Leiaute - Rodoviário
4779
     * Gera as tags para o elemento: "rodo" (Informações do modal Rodoviário) CT-e OS
4780
     * #1
4781
     * Nível: 0
4782
     * @return DOMElement|\DOMNode
4783
     */
4784
    public function tagrodoOS($std)
4785
    {
4786
4787
        $possible = [
4788
            'TAF',
4789
            'NroRegEstadual'
4790
        ];
4791
4792
        $std = $this->equilizeParameters($std, $possible);
4793
4794
        $identificador = '#1 <rodoOS> - ';
4795
        $this->rodo = $this->dom->createElement('rodoOS');
4796
        $this->dom->addChild(
4797
            $this->rodo,
4798
            'TAF',
4799
            $std->TAF,
4800
            false,
4801
            $identificador . 'Termo de Autorização de Fretamento - TAF'
4802
        );
4803
        $this->dom->addChild(
4804
            $this->rodo,
4805
            'NroRegEstadual',
4806
            $std->NroRegEstadual,
4807
            false,
4808
            $identificador . 'Número do Registro Estadual'
4809
        );
4810
        return $this->rodo;
4811
    }
4812
4813
    /**
4814
     * Leiaute - Aéreo
4815
     * Gera as tags para o elemento: "aereo" (Informações do modal Aéreo)
4816
     * @return DOMElement|\DOMNode
4817
     * @author Newton Pasqualini Filho
4818
     * #1
4819
     * Nível: 0
4820
     */
4821
    public function tagaereo($std)
4822
    {
4823
4824
        $possible = [
4825
            'nMinu',
4826
            'nOCA',
4827
            'dPrevAereo',
4828
            'natCarga_xDime',
4829
            'natCarga_cInfManu',
4830
            'tarifa_CL',
4831
            'tarifa_cTar',
4832
            'tarifa_vTar'
4833
        ];
4834
4835
        $std = $this->equilizeParameters($std, $possible);
4836
4837
        $identificador = '#1 <aereo> - ';
4838
        $this->aereo = $this->dom->createElement('aereo');
4839
        $this->dom->addChild(
4840
            $this->aereo,
4841
            'nMinu',
4842
            $std->nMinu,
4843
            false,
4844
            $identificador . 'Número da Minuta'
4845
        );
4846
        $this->dom->addChild(
4847
            $this->aereo,
4848
            'nOCA',
4849
            $std->nOCA,
4850
            false,
4851
            $identificador . 'Número Operacional do Conhecimento Aéreo'
4852
        );
4853
        $this->dom->addChild(
4854
            $this->aereo,
4855
            'dPrevAereo',
4856
            $std->dPrevAereo,
4857
            true,
4858
            $identificador . 'Data prevista da entrega'
4859
        );
4860
        if (isset($std->natCarga_xDime) || isset($std->natCarga_cInfManu)) {
4861
            $identificador = '#1 <aereo> - <natCarga> - ';
4862
            $natCarga = $this->dom->createElement('natCarga');
4863
            $this->dom->addChild(
4864
                $natCarga,
4865
                'xDime',
4866
                $std->natCarga_xDime,
4867
                false,
4868
                $identificador . 'Dimensões da carga, formato: 1234x1234x1234 (cm)'
4869
            );
4870
            if (isset($std->natCarga_cInfManu) && !is_array($std->natCarga_cInfManu)) {
4871
                $std->natCarga_cInfManu = [$std->natCarga_cInfManu];
4872
            }
4873
            $cInfManuX = 0;
4874
            foreach ($std->natCarga_cInfManu as $cInfManu) {
0 ignored issues
show
Bug introduced by
The expression $std->natCarga_cInfManu of type null|array 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...
4875
                $cInfManuX++;
4876
                $this->dom->addChild(
4877
                    $natCarga,
4878
                    'cInfManu',
4879
                    $cInfManu,
4880
                    false,
4881
                    $identificador . 'Informação de manuseio, com dois dígitos, pode ter mais de uma ocorrência.'
4882
                );
4883
            }
4884
            $this->aereo->appendChild($natCarga);
4885
        }
4886
        $identificador = '#1 <aereo> - <tarifa> - ';
4887
        $tarifa = $this->dom->createElement('tarifa');
4888
        $this->dom->addChild(
4889
            $tarifa,
4890
            'CL',
4891
            $std->tarifa_CL,
4892
            true,
4893
            $identificador . 'Classe da tarifa: M - Tarifa Mínima / G - Tarifa Geral / E - Tarifa Específica'
4894
        );
4895
        $this->dom->addChild(
4896
            $tarifa,
4897
            'cTar',
4898
            $std->tarifa_cTar,
4899
            false,
4900
            $identificador . 'Código de três digítos correspondentes à tarifa.'
4901
        );
4902
        $this->dom->addChild(
4903
            $tarifa,
4904
            'vTar',
4905
            $std->tarifa_vTar,
4906
            true,
4907
            $identificador . 'Valor da tarifa. 15 posições, sendo 13 inteiras e 2 decimais.'
4908
        );
4909
        $this->aereo->appendChild($tarifa);
4910
        return $this->aereo;
4911
    }
4912
4913
    /**
4914
     * Leiaute - Aéreo
4915
     * Gera as tags para o elemento: "aereo" (Informações do modal Aéreo)
4916
     * #1
4917
     * Nível: 0
4918
     * @return DOMElement|\DOMNode
4919
     */
4920
    public function tagperi($std)
4921
    {
4922
4923
        $possible = [
4924
            'nONU',
4925
            'qTotEmb',
4926
            'qTotProd',
4927
            'uniAP'
4928
        ];
4929
4930
        $std = $this->equilizeParameters($std, $possible);
4931
4932
        $identificador = '#1 <aereo> - <peri> - ';
4933
        $peri = $this->dom->createElement('peri');
4934
        $this->dom->addChild(
4935
            $peri,
4936
            'nONU',
4937
            $std->nONU,
4938
            true,
4939
            $identificador . 'Número ONU/UN'
4940
        );
4941
        $this->dom->addChild(
4942
            $peri,
4943
            'qTotEmb',
4944
            $std->qTotEmb,
4945
            true,
4946
            $identificador . 'Quantidade total de volumes contendo artigos perigosos'
4947
        );
4948
        $identificador = '#1 <peri> - <infTotAP> - ';
4949
        $infTotAP = $this->dom->createElement('infTotAP');
4950
        $this->dom->addChild(
4951
            $infTotAP,
4952
            'qTotProd',
4953
            $std->qTotProd,
4954
            false,
4955
            $identificador . 'Quantidade total de artigos perigosos'
4956
        );
4957
        $this->dom->addChild(
4958
            $infTotAP,
4959
            'uniAP',
4960
            $std->uniAP,
4961
            true,
4962
            $identificador . 'Unidade de medida'
4963
        );
4964
        $peri->appendChild($infTotAP);
4965
        $this->peri[] = $peri;
4966
        return $peri;
4967
    }
4968
4969
    public function tagferrov($std)
4970
    {
4971
4972
        $possible = [
4973
            'tpTraf',
4974
            'respFat',
4975
            'ferrEmi',
4976
            'vFrete',
4977
            'chCTeFerroOrigem ',
4978
            'fluxo'
4979
        ];
4980
4981
        $std = $this->equilizeParameters($std, $possible);
4982
4983
        $identificador = '#1 <ferrov> - ';
4984
        $this->ferrov = $this->dom->createElement('ferrov');
4985
        $this->dom->addChild(
4986
            $this->ferrov,
4987
            'tpTraf',
4988
            $std->tpTraf,
4989
            true,
4990
            $identificador . 'Tipo de Tráfego'
4991
        );
4992
        $identificador = '#1 <ferrov> - <trafMut> - ';
4993
        $trafMut = $this->dom->createElement('trafMut');
4994
        $this->dom->addChild(
4995
            $trafMut,
4996
            'respFat',
4997
            $std->respFat,
4998
            true,
4999
            $identificador . 'Responsável pelo Faturamento'
5000
        );
5001
        $this->dom->addChild(
5002
            $trafMut,
5003
            'ferrEmi',
5004
            $std->ferrEmi,
5005
            true,
5006
            $identificador . 'Ferrovia Emitente do CTe'
5007
        );
5008
        $this->dom->addChild(
5009
            $trafMut,
5010
            'vFrete',
5011
            $std->vFrete,
5012
            true,
5013
            $identificador . 'Valor do Frete do Tráfego Mútuo '
5014
        );
5015
        $this->dom->addChild(
5016
            $trafMut,
5017
            'chCTeFerroOrigem',
5018
            $std->chCTeFerroOrigem,
5019
            false,
5020
            $identificador . 'Chave de acesso do CT-e emitido pelo ferrovia de origem'
5021
        );
5022
        $this->ferrov->appendChild($trafMut);
5023
        $this->dom->addChild(
5024
            $this->ferrov,
5025
            'fluxo',
5026
            $std->fluxo,
5027
            true,
5028
            $identificador . 'Fluxo Ferroviário '
5029
        );
5030
    }
5031
5032
    public function tagferroEnv($std)
5033
    {
5034
5035
        $possible = [
5036
            'CNPJ',
5037
            'cInt',
5038
            'IE',
5039
            'xNome',
5040
            'xLgr',
5041
            'nro',
5042
            'xCpl',
5043
            'xBairro',
5044
            'cMun',
5045
            'xMun',
5046
            'CEP',
5047
            'UF',
5048
            'fluxo'
5049
        ];
5050
5051
        $std = $this->equilizeParameters($std, $possible);
5052
5053
        $identificador = '#1 <trafMut> - <ferroEnv> - ';
5054
        $ferroEnv = $this->dom->createElement('ferroEnv');
5055
        $this->dom->addChild(
5056
            $ferroEnv,
5057
            'CNPJ',
5058
            $std->CNPJ,
5059
            true,
5060
            $identificador . 'Número do CNPJ'
5061
        );
5062
        $this->dom->addChild(
5063
            $ferroEnv,
5064
            'cInt',
5065
            $std->cInt,
5066
            false,
5067
            $identificador . 'Código interno da Ferrovia envolvida'
5068
        );
5069
        $this->dom->addChild(
5070
            $ferroEnv,
5071
            'IE',
5072
            $std->IE,
5073
            false,
5074
            $identificador . 'Inscrição Estadual'
5075
        );
5076
        $this->dom->addChild(
5077
            $ferroEnv,
5078
            'xNome',
5079
            $std->xNome,
5080
            false,
5081
            $identificador . 'Razão Social ou Nome'
5082
        );
5083
        $identificador = '#1 <ferroEnv> - <enderFerro> - ';
5084
        $enderFerro = $this->dom->createElement('enderFerro');
5085
        $this->dom->addChild(
5086
            $enderFerro,
5087
            'xLgr',
5088
            $std->xLgr,
5089
            true,
5090
            $identificador . 'Logradouro'
5091
        );
5092
        $this->dom->addChild(
5093
            $enderFerro,
5094
            'nro',
5095
            $std->nro,
5096
            false,
5097
            $identificador . 'Número'
5098
        );
5099
        $this->dom->addChild(
5100
            $enderFerro,
5101
            'xCpl',
5102
            $std->xCpl,
5103
            false,
5104
            $identificador . 'Complemento'
5105
        );
5106
        $this->dom->addChild(
5107
            $enderFerro,
5108
            'xBairro',
5109
            $std->xBairro,
5110
            false,
5111
            $identificador . 'Bairro'
5112
        );
5113
        $this->dom->addChild(
5114
            $enderFerro,
5115
            'cMun',
5116
            $std->cMun,
5117
            true,
5118
            $identificador . 'Código do município'
5119
        );
5120
        $this->dom->addChild(
5121
            $enderFerro,
5122
            'xMun',
5123
            $std->xMun,
5124
            true,
5125
            $identificador . 'Nome do município'
5126
        );
5127
        $this->dom->addChild(
5128
            $enderFerro,
5129
            'CEP',
5130
            $std->CEP,
5131
            true,
5132
            $identificador . 'CEP'
5133
        );
5134
        $this->dom->addChild(
5135
            $enderFerro,
5136
            'UF',
5137
            $std->UF,
5138
            true,
5139
            $identificador . 'Sigla da UF'
5140
        );
5141
        $ferroEnv->appendChild($enderFerro);
5142
        $this->ferroEnv[] = $ferroEnv;
5143
        return $ferroEnv;
5144
    }
5145
5146
    /**
5147
     * Leiaute - Multimodal
5148
     * Gera as tags do leaiute específico de multimodal
5149
     * @return DOMElement|\DOMNode
5150
     * @author Gabriel Kliemaschewsk Rondon
5151
     * Nivel: 1
5152
     */
5153
    public function tagmultimodal($std)
5154
    {
5155
5156
        $possible = [
5157
            'COTM',
5158
            'indNegociavel',
5159
        ];
5160
5161
        $std = $this->equilizeParameters($std, $possible);
5162
5163
        $identificador = '#1 <multimodal> - ';
5164
        $this->multimodal = $this->dom->createElement('multimodal');
5165
        $this->dom->addChild(
5166
            $this->multimodal,
5167
            'COTM',
5168
            $std->COTM,
5169
            true,
5170
            $identificador . 'COTM'
5171
        );
5172
        $this->dom->addChild(
5173
            $this->multimodal,
5174
            'indNegociavel',
5175
            $std->indNegociavel,
5176
            true,
5177
            $identificador . 'indNegociavel'
5178
        );
5179
        
5180
        return $this->multimodal;
5181
    }
5182
5183
    public function tagSegMultimodal($std)
5184
    {
5185
5186
        $possible = [
5187
            'xSeg',
5188
            'CNPJ',
5189
            'nApol',
5190
            'nAver'
5191
        ];
5192
5193
        $std = $this->equilizeParameters($std, $possible);
5194
5195
        $identificador = '#4 <multimodal> - ';
5196
        $this->segMultim = $this->dom->createElement('seg');
5197
        $infSeg = $this->dom->createElement('infSeg');
5198
        $this->dom->addChild(
5199
            $infSeg,
5200
            'xSeg',
5201
            $std->xSeg,
5202
            true,
5203
            $identificador . 'xSeg'
5204
        );
5205
        $this->dom->addChild(
5206
            $infSeg,
5207
            'CNPJ',
5208
            $std->CNPJ,
5209
            false,
5210
            $identificador . 'indNegociavel'
5211
        );
5212
        $this->segMultim->appendChild($infSeg);
5213
        $this->dom->addChild(
5214
            $this->segMultim,
5215
            'nApol',
5216
            $std->nApol,
5217
            true,
5218
            $identificador . 'nApol'
5219
        );
5220
        $this->dom->addChild(
5221
            $this->segMultim,
5222
            'nAver',
5223
            $std->nAver,
5224
            false,
5225
            $identificador . 'nAver'
5226
        );
5227
5228
        return $this->segMultim;
5229
    }
5230
    /**
5231
     * CT-e de substituição
5232
     * @return type
5233
     */
5234
    public function taginfCteSub($std)
5235
    {
5236
5237
        $possible = [
5238
            'chCte',
5239
            'refCteAnu'
5240
        ];
5241
5242
        $std = $this->equilizeParameters($std, $possible);
5243
5244
        $identificador = '#149 <infCteSub> - ';
5245
        $this->infCteSub = $this->dom->createElement('infCteSub');
5246
        $this->dom->addChild(
5247
            $this->infCteSub,
5248
            'chCte',
5249
            $std->chCte,
5250
            false,
5251
            "$identificador  Chave de acesso do CTe a ser substituído (original)"
5252
        );
5253
        $this->dom->addChild(
5254
            $this->infCteSub,
5255
            'refCteAnu',
5256
            $std->refCteAnu,
5257
            false,
5258
            "$identificador  Chave de acesso do CT-e de Anulação"
5259
        );
5260
        return $this->infCteSub;
5261
    }
5262
5263
    /**
5264
     * Informações do Serviço Vinculado a Multimodal
5265
     * @return type
5266
     */
5267
    public function infCTeMultimodal($std)
5268
    {
5269
        $possible = [
5270
            'chCTeMultimodal',
5271
        ];
5272
5273
        $std = $this->equilizeParameters($std, $possible);
5274
5275
        if (empty($this->infServVinc)) {
5276
            $this->infServVinc = $this->dom->createElement('infServVinc');
5277
        }
5278
5279
        $identificador = '#388 <infCTeMultimodal> - ';
5280
        $infCTeMultimodal = $this->dom->createElement('infCTeMultimodal');
5281
        $this->dom->addChild(
5282
            $infCTeMultimodal,
5283
            'chCTeMultimodal',
5284
            $std->chCTeMultimodal,
5285
            true,
5286
            $identificador . 'Chave de acesso do CT-e Multimodal '
5287
        );
5288
5289
        $this->infCTeMultimodal[] = $infCTeMultimodal;
5290
        return $infCTeMultimodal;
5291
    }
5292
5293
    /**
5294
     * CT-e de substituição - tomaICMS
5295
     * @param type $std
0 ignored issues
show
Bug introduced by
There is no parameter named $std. 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...
5296
     * @return type
5297
     */
5298
    public function tagtomaICMS()
5299
    {
5300
        $this->tomaICMS = $this->dom->createElement('tomaICMS');
5301
        return $this->tomaICMS;
5302
    }
5303
5304
    /**
5305
     * CT-e de substituição - NF-e
5306
     * @param type $std
5307
     * @return type
5308
     */
5309
    public function tagrefNFe($std)
5310
    {
5311
5312
        $possible = [
5313
            'refNFe'
5314
        ];
5315
5316
        $std = $this->equilizeParameters($std, $possible);
5317
5318
        if (empty($this->tomICMS)) {
0 ignored issues
show
Bug introduced by
The property tomICMS does not seem to exist. Did you mean tomaICMS?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
5319
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
5320
        }
5321
        $identificador = '#153 <refNFe> - ';
5322
        $this->dom->addChild(
5323
            $this->tomaICMS,
5324
            'refNFe',
5325
            $std->refNFe,
5326
            false,
5327
            "$identificador  Chave de acesso da NF-e emitida pelo tomador"
5328
        );
5329
5330
        return $this->tomaICMS;
5331
    }
5332
5333
    /**
5334
     * CT-e de substituição - NF
5335
     * @param type $std
5336
     * @return type
5337
     */
5338
    public function tagrefNF($std)
5339
    {
5340
5341
        $possible = [
5342
            'CNPJ',
5343
            'CPF',
5344
            'mod',
5345
            'serie',
5346
            'subserie',
5347
            'nro',
5348
            'valor',
5349
            'dEmi'
5350
        ];
5351
5352
        $std = $this->equilizeParameters($std, $possible);
5353
5354
        $identificador = '#154 <refNFe> - ';
5355
        if (empty($this->tomICMS)) {
0 ignored issues
show
Bug introduced by
The property tomICMS does not seem to exist. Did you mean tomaICMS?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
5356
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
5357
        }
5358
        $this->refNF = $this->dom->createElement('refNF');
5359
        if ($std->CNPJ != '') {
5360
            $this->dom->addChild(
5361
                $this->refNF,
5362
                'CNPJ',
5363
                $std->CNPJ,
5364
                true,
5365
                $identificador . 'CNPJ do emitente'
5366
            );
5367
        } elseif ($std->CPF != '') {
5368
            $this->dom->addChild(
5369
                $this->refNF,
5370
                'CPF',
5371
                $std->CPF,
5372
                true,
5373
                $identificador . 'CPF do emitente'
5374
            );
5375
        }
5376
        $this->dom->addChild(
5377
            $this->refNF,
5378
            'mod',
5379
            $std->mod,
5380
            false,
5381
            $identificador . 'Modelo'
5382
        );
5383
        $this->dom->addChild(
5384
            $this->refNF,
5385
            'serie',
5386
            $std->serie,
5387
            false,
5388
            $identificador . 'Série do documento'
5389
        );
5390
        $this->dom->addChild(
5391
            $this->refNF,
5392
            'subserie',
5393
            $std->subserie,
5394
            false,
5395
            $identificador . 'Subserie do documento'
5396
        );
5397
        $this->dom->addChild(
5398
            $this->refNF,
5399
            'nro',
5400
            $std->nro,
5401
            false,
5402
            $identificador . 'Número'
5403
        );
5404
        $this->dom->addChild(
5405
            $this->refNF,
5406
            'valor',
5407
            $std->valor,
5408
            false,
5409
            $identificador . 'Valor'
5410
        );
5411
        $this->dom->addChild(
5412
            $this->refNF,
5413
            'dEmi',
5414
            $std->dEmi,
5415
            false,
5416
            $identificador . 'Emissão'
5417
        );
5418
        $this->tomaICMS->appendChild($this->refNF);
5419
        return $this->tomaICMS;
5420
    }
5421
5422
    /**
5423
     * CT-e de substituição - CT-e
5424
     * @param type $std
5425
     * @return type
5426
     */
5427
    public function tagrefCTe($std)
5428
    {
5429
5430
        $possible = [
5431
            'refCte'
5432
        ];
5433
5434
        $std = $this->equilizeParameters($std, $possible);
5435
5436
        if (empty($this->tomICMS)) {
0 ignored issues
show
Bug introduced by
The property tomICMS does not seem to exist. Did you mean tomaICMS?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
5437
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
5438
        }
5439
        $identificador = '#163 <refCte> - ';
5440
        $this->dom->addChild(
5441
            $this->tomaICMS,
5442
            'refCte',
5443
            $std->refCte,
5444
            false,
5445
            "$identificador  Chave de acesso do CT-e emitida pelo tomador"
5446
        );
5447
5448
        return $this->tomaICMS;
5449
    }
5450
5451
    /**
5452
     * CT-e de substituição - CT-e
5453
     * @param type $std
5454
     * @return type
5455
     */
5456
    public function tagindAlteraToma($std)
5457
    {
5458
5459
        $possible = [
5460
            'indAlteraToma'
5461
        ];
5462
5463
        $std = $this->equilizeParameters($std, $possible);
5464
5465
        $this->indAlteraToma = $std->indAlteraToma;
5466
        return $this->indAlteraToma;
5467
    }
5468
5469
    /**
5470
     * Informações do CT-e Globalizado
5471
     * @param type $std
5472
     * @return type
5473
     */
5474
    public function taginfGlobalizado($std)
5475
    {
5476
5477
        $possible = [
5478
            'xObs'
5479
        ];
5480
5481
        $std = $this->equilizeParameters($std, $possible);
5482
5483
        $infGlobalizado = $this->dom->createElement('infGlobalizado');
5484
        $identificador = '#163 <infGlobalizado> - ';
5485
        $this->dom->addChild(
5486
            $infGlobalizado,
5487
            'xObs',
5488
            $std->xObs,
5489
            true,
5490
            "$identificador - Preencher com informações adicionais, legislação do regime especial, etc"
5491
        );
5492
        return $this->infGlobalizado;
5493
    }
5494
5495
    /**
5496
     * Leiaute - Rodoviário
5497
     * Gera as tags para o elemento: "veic" (Dados dos Veículos)
5498
     * #21
5499
     * Nível: 1
5500
     * @return mixed
5501
     */
5502
    public function tagveicCTeOS($std)
5503
    {
5504
5505
        $possible = [
5506
            'placa',
5507
            'RENAVAM',
5508
            'CNPJ',
5509
            'CPF',
5510
            'TAF',
5511
            'NroRegEstadual',
5512
            'xNome',
5513
            'IE',
5514
            'ufProp',
5515
            'tpProp',
5516
            'uf'
5517
        ];
5518
5519
        $std = $this->equilizeParameters($std, $possible);
5520
5521
        $identificador = '#21 <veic> - ';
5522
        $this->veic = $this->dom->createElement('veic');
5523
        $this->dom->addChild(
5524
            $this->veic,
5525
            'placa',
5526
            $std->placa,
5527
            false,
5528
            $identificador . 'Placa do veículo'
5529
        );
5530
        $this->dom->addChild(
5531
            $this->veic,
5532
            'RENAVAM',
5533
            $std->RENAVAM,
5534
            false,
5535
            $identificador . 'RENAVAM do veículo'
5536
        );
5537
        if ($std->xNome != '') { // CASO FOR VEICULO DE TERCEIRO
5538
            $this->prop = $this->dom->createElement('prop');
5539
            if ($std->CNPJ != '') {
5540
                $this->dom->addChild(
5541
                    $this->prop,
5542
                    'CNPJ',
5543
                    $std->CNPJ,
5544
                    true,
5545
                    $identificador . 'CNPJ do proprietario'
5546
                );
5547
            } elseif ($std->CPF != '') {
5548
                $this->dom->addChild(
5549
                    $this->prop,
5550
                    'CPF',
5551
                    $std->CPF,
5552
                    true,
5553
                    $identificador . 'CPF do proprietario'
5554
                );
5555
            }
5556
            if ($std->taf != '') {
5557
                $this->dom->addChild(
5558
                    $this->prop,
5559
                    'TAF',
5560
                    $std->taf,
5561
                    false,
5562
                    $identificador . 'TAF'
5563
                );
5564
            } else {
5565
                $this->dom->addChild(
5566
                    $this->prop,
5567
                    'NroRegEstadual',
5568
                    $std->nroRegEstadual,
5569
                    false,
5570
                    $identificador . 'Número do Registro Estadual'
5571
                );
5572
            }
5573
            $this->dom->addChild(
5574
                $this->prop,
5575
                'xNome',
5576
                $std->xNome,
5577
                true,
5578
                $identificador . 'Nome do proprietario'
5579
            );
5580
            $this->dom->addChild(
5581
                $this->prop,
5582
                'IE',
5583
                Strings::onlyNumbers($std->IE),
5584
                false,
5585
                $identificador . 'IE do proprietario'
5586
            );
5587
            $this->dom->addChild(
5588
                $this->prop,
5589
                'UF',
5590
                $std->ufProp,
5591
                true,
5592
                $identificador . 'UF do proprietario'
5593
            );
5594
            $this->dom->addChild(
5595
                $this->prop,
5596
                'tpProp',
5597
                $std->tpProp,
5598
                true,
5599
                $identificador . 'Tipo Proprietário'
5600
            );
5601
            $this->dom->appChild($this->veic, $this->prop, 'Falta tag "prop"');
5602
        }
5603
        $this->dom->addChild(
5604
            $this->veic,
5605
            'UF',
5606
            $std->uf,
5607
            true,
5608
            $identificador . 'UF em que veículo está licenciado'
5609
        );
5610
        return $this->veic;
5611
    }
5612
5613
    public function infFretamento($std)
5614
    {
5615
5616
        $possible = [
5617
            'tpFretamento',
5618
            'dhViagem'
5619
        ];
5620
5621
        $std = $this->equilizeParameters($std, $possible);
5622
5623
        $identificador = '#21 <infFretamento> - ';
5624
        $this->infFretamento = $this->dom->createElement('infFretamento');
5625
        $this->dom->addChild(
5626
            $this->infFretamento,
5627
            'tpFretamento',
5628
            $std->tpFretamento,
5629
            true,
5630
            $identificador . 'Tipo do Fretamento de Pessoas'
5631
        );
5632
        $this->dom->addChild(
5633
            $this->infFretamento,
5634
            'dhViagem',
5635
            $std->dhViagem,
5636
            false,
5637
            $identificador . 'Data e hora da viagem'
5638
        );
5639
        return $this->infFretamento;
5640
    }
5641
5642
    /**
5643
     * Gera as tags para o elemento: "infCteComp" (Detalhamento do CT-e complementado)
5644
     * #410
5645
     * Nível: 1
5646
     * @return DOMElement|\DOMNode
5647
     */
5648
    public function taginfCTeComp($std)
5649
    {
5650
5651
        $possible = [
5652
            'chCTe'
5653
        ];
5654
5655
        $std = $this->equilizeParameters($std, $possible);
5656
5657
        $identificador = '#410 <infCteComp> - ';
5658
        $this->infCteComp = $this->dom->createElement('infCteComp');
5659
        $this->dom->addChild(
5660
            $this->infCteComp,
5661
            'chCTe',
5662
            $std->chCTe,
5663
            true,
5664
            $identificador . ' Chave do CT-e complementado'
5665
        );
5666
        return $this->infCteComp;
5667
    }
5668
5669
    /**
5670
     * Gera as tags para o elemento: "infCteAnu" (Detalhamento do CT-e de Anulação)
5671
     * #411
5672
     * Nível: 1
5673
     * @return DOMElement|\DOMNode
5674
     */
5675
    public function taginfCteAnu($std)
5676
    {
5677
5678
        $possible = [
5679
            'chCte',
5680
            'dEmi'
5681
        ];
5682
5683
        $std = $this->equilizeParameters($std, $possible);
5684
5685
        $identificador = '#411 <infCteAnu> - ';
5686
        $this->infCteAnu = $this->dom->createElement('infCteAnu');
5687
        $this->dom->addChild(
5688
            $this->infCteAnu,
5689
            'chCte',
5690
            $std->chCte,
5691
            true,
5692
            $identificador . ' Chave do CT-e anulado'
5693
        );
5694
        $this->dom->addChild(
5695
            $this->infCteAnu,
5696
            'dEmi',
5697
            $std->dEmi,
5698
            true,
5699
            $identificador . ' Data de Emissão do CT-e anulado'
5700
        );
5701
        return $this->infCteAnu;
5702
    }
5703
5704
    /**
5705
     * Gera as tags para o elemento: "autXML" (Autorizados para download do XML)
5706
     * #396
5707
     * Nível: 1
5708
     * Os parâmetros para esta função são todos os elementos da tag "autXML"
5709
     *
5710
     * @return boolean
5711
     */
5712
    public function tagveicNovos($std)
5713
    {
5714
5715
        $possible = [
5716
            'chassi',
5717
            'cCor',
5718
            'xCor',
5719
            'cMod',
5720
            'vUnit',
5721
            'vFrete'
5722
        ];
5723
5724
        $std = $this->equilizeParameters($std, $possible);
5725
5726
        $identificador = '#396 <veicNovos> - ';
5727
        $veicNovos = $this->dom->createElement('veicNovos');
5728
        $this->dom->addChild(
5729
            $veicNovos,
5730
            'chassi',
5731
            $std->chassi,
5732
            true,
5733
            $identificador . 'Chassi do veículo '
5734
        );
5735
        $this->dom->addChild(
5736
            $veicNovos,
5737
            'cCor',
5738
            $std->cCor,
5739
            true,
5740
            $identificador . 'Cor do veículo '
5741
        );
5742
        $this->dom->addChild(
5743
            $veicNovos,
5744
            'xCor',
5745
            $std->xCor,
5746
            true,
5747
            $identificador . 'Descrição da cor '
5748
        );
5749
        $this->dom->addChild(
5750
            $veicNovos,
5751
            'cMod',
5752
            $std->cMod,
5753
            true,
5754
            $identificador . 'Código Marca Modelo '
5755
        );
5756
        $this->dom->addChild(
5757
            $veicNovos,
5758
            'vUnit',
5759
            $std->vUnit,
5760
            true,
5761
            $identificador . 'Valor Unitário do Veículo '
5762
        );
5763
        $this->dom->addChild(
5764
            $veicNovos,
5765
            'vFrete',
5766
            $std->vFrete,
5767
            true,
5768
            $identificador . 'Frete Unitário '
5769
        );
5770
        $this->veicNovos[] = $veicNovos;
5771
        return $veicNovos;
5772
    }
5773
5774
    /**
5775
     * Gera as tags para o elemento: "autXML" (Autorizados para download do XML)
5776
     * #396
5777
     * Nível: 1
5778
     * Os parâmetros para esta função são todos os elementos da tag "autXML"
5779
     *
5780
     * @return boolean
5781
     */
5782
    public function tagautXML($std)
5783
    {
5784
5785
        $possible = [
5786
            'CNPJ',
5787
            'CPF'
5788
        ];
5789
5790
        $std = $this->equilizeParameters($std, $possible);
5791
5792
        $identificador = '#396 <autXML> - ';
5793
        $autXML = $this->dom->createElement('autXML');
5794
        if (isset($std->CNPJ) && $std->CNPJ != '') {
5795
            $this->dom->addChild(
5796
                $autXML,
5797
                'CNPJ',
5798
                $std->CNPJ,
5799
                true,
5800
                $identificador . 'CNPJ do Cliente Autorizado'
5801
            );
5802
        } elseif (isset($std->CPF) && $std->CPF != '') {
5803
            $this->dom->addChild(
5804
                $autXML,
5805
                'CPF',
5806
                $std->CPF,
5807
                true,
5808
                $identificador . 'CPF do Cliente Autorizado'
5809
            );
5810
        }
5811
        $this->autXML[] = $autXML;
5812
        return $autXML;
5813
    }
5814
5815
    /**
5816
     * #359
5817
     * tag CTe/infCTe/cobr (opcional)
5818
     * Depende de fat
5819
     */
5820
    protected function buildCobr()
5821
    {
5822
        if (empty($this->cobr)) {
5823
            $this->cobr = $this->dom->createElement("cobr");
5824
        }
5825
    }
5826
5827
    /**
5828
     * #360
5829
     * tag CTe/infCTe/cobr/fat (opcional)
5830
     * @param stdClass $std
5831
     * @return DOMElement
5832
     */
5833
    public function tagfat(stdClass $std)
5834
    {
5835
5836
        $possible = [
5837
            'nFat',
5838
            'vOrig',
5839
            'vDesc',
5840
            'vLiq'
5841
        ];
5842
5843
        $std = $this->equilizeParameters($std, $possible);
5844
5845
        $this->buildCobr();
5846
        $fat = $this->dom->createElement("fat");
5847
        $this->dom->addChild(
5848
            $fat,
5849
            "nFat",
5850
            $std->nFat,
5851
            false,
5852
            "Número da Fatura"
5853
        );
5854
        $this->dom->addChild(
5855
            $fat,
5856
            "vOrig",
5857
            $std->vOrig,
5858
            false,
5859
            "Valor Original da Fatura"
5860
        );
5861
        if ($std->vDesc > 0) {
5862
            $this->dom->addChild(
5863
                $fat,
5864
                "vDesc",
5865
                $std->vDesc,
5866
                false,
5867
                "Valor do desconto"
5868
            );
5869
        }
5870
        $this->dom->addChild(
5871
            $fat,
5872
            "vLiq",
5873
            $std->vLiq,
5874
            false,
5875
            "Valor Líquido da Fatura"
5876
        );
5877
        $this->dom->appChild($this->cobr, $fat);
5878
        return $fat;
5879
    }
5880
5881
    /**
5882
     * #365
5883
     * tag CTe/infCTe/cobr/fat/dup (opcional)
5884
     * É necessário criar a tag fat antes de criar as duplicatas
5885
     * @param stdClass $std
5886
     * @return DOMElement
5887
     */
5888
    public function tagdup(stdClass $std)
5889
    {
5890
5891
        $possible = [
5892
            'nDup',
5893
            'dVenc',
5894
            'vDup'
5895
        ];
5896
5897
        $std = $this->equilizeParameters($std, $possible);
5898
5899
        $this->buildCobr();
5900
        $dup = $this->dom->createElement("dup");
5901
        $this->dom->addChild(
5902
            $dup,
5903
            "nDup",
5904
            $std->nDup,
5905
            false,
5906
            "Número da Duplicata"
5907
        );
5908
        $this->dom->addChild(
5909
            $dup,
5910
            "dVenc",
5911
            $std->dVenc,
5912
            false,
5913
            "Data de vencimento"
5914
        );
5915
        $this->dom->addChild(
5916
            $dup,
5917
            "vDup",
5918
            $std->vDup,
5919
            true,
5920
            "Valor da duplicata"
5921
        );
5922
        $this->dom->appChild($this->cobr, $dup, 'Inclui duplicata na tag cobr');
5923
        return $dup;
5924
    }
5925
5926
    /**
5927
     * Informações do Responsável técnico
5928
     * tag CTe/infCte/infRespTec (opcional)
5929
     * @return DOMElement
5930
     * @throws RuntimeException
5931
     */
5932
    public function taginfRespTec(stdClass $std)
5933
    {
5934
5935
        $possible = [
5936
            'CNPJ',
5937
            'xContato',
5938
            'email',
5939
            'fone',
5940
            'idCSRT',
5941
            'CSRT'
5942
        ];
5943
5944
        $std = $this->equilizeParameters($std, $possible);
5945
5946
        $infRespTec = $this->dom->createElement("infRespTec");
5947
        $this->dom->addChild(
5948
            $infRespTec,
5949
            "CNPJ",
5950
            $std->CNPJ,
5951
            true,
5952
            "Informar o CNPJ da pessoa jurídica responsável pelo sistema "
5953
            . "utilizado na emissão do documento fiscal eletrônico"
5954
        );
5955
        $this->dom->addChild(
5956
            $infRespTec,
5957
            "xContato",
5958
            $std->xContato,
5959
            true,
5960
            "Informar o nome da pessoa a ser contatada na empresa desenvolvedora "
5961
            . "do sistema utilizado na emissão do documento fiscal eletrônico"
5962
        );
5963
        $this->dom->addChild(
5964
            $infRespTec,
5965
            "email",
5966
            $std->email,
5967
            true,
5968
            "Informar o e-mail da pessoa a ser contatada na empresa "
5969
            . "desenvolvedora do sistema."
5970
        );
5971
        $this->dom->addChild(
5972
            $infRespTec,
5973
            "fone",
5974
            $std->fone,
5975
            true,
5976
            "Informar o telefone da pessoa a ser contatada na empresa "
5977
            . "desenvolvedora do sistema."
5978
        );
5979
        if (!empty($std->CSRT) && !empty($std->idCSRT)) {
5980
            $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...
5981
            $this->dom->addChild(
5982
                $infRespTec,
5983
                "idCSRT",
5984
                $std->idCSRT,
5985
                true,
5986
                "Identificador do CSRT utilizado para montar o hash do CSRT"
5987
            );
5988
            $this->dom->addChild(
5989
                $infRespTec,
5990
                "hashCSRT",
5991
                $this->hashCSRT($std->CSRT),
0 ignored issues
show
Bug introduced by
The method hashCSRT() does not seem to exist on object<NFePHP\CTe\Make>.

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...
5992
                true,
5993
                "hash do CSRT"
5994
            );
5995
        }
5996
        $this->infRespTec = $infRespTec;
5997
        return $infRespTec;
5998
    }
5999
6000
    protected function checkCTeKey(Dom $dom)
6001
    {
6002
        $infCTe = $dom->getElementsByTagName("infCte")->item(0);
6003
        $ide = $dom->getElementsByTagName("ide")->item(0);
6004
        $emit = $dom->getElementsByTagName("emit")->item(0);
6005
        $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue;
6006
        $dhEmi = $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue;
6007
        $cnpj = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
6008
        $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue;
6009
        $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
6010
        $nNF = $ide->getElementsByTagName('nCT')->item(0)->nodeValue;
6011
        $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue;
6012
        $cCT = $ide->getElementsByTagName('cCT')->item(0)->nodeValue;
6013
        $chave = str_replace('CTe', '', $infCTe->getAttribute("Id"));
6014
6015
        $dt = new \DateTime($dhEmi);
6016
6017
        $chaveMontada = Keys::build(
6018
            $cUF,
6019
            $dt->format('y'),
6020
            $dt->format('m'),
6021
            $cnpj,
6022
            $mod,
6023
            $serie,
6024
            $nNF,
6025
            $tpEmis,
6026
            $cCT
6027
        );
6028
        //caso a chave contida no CTe esteja errada
6029
        //substituir a chave
6030
        if ($chaveMontada != $chave) {
6031
            $ide->getElementsByTagName('cDV')->item(0)->nodeValue = substr($chaveMontada, -1);
6032
            $infCTe = $dom->getElementsByTagName("infCte")->item(0);
6033
            $infCTe->setAttribute("Id", "CTe" . $chaveMontada);
6034
            $this->chCTe = $chaveMontada;
6035
        }
6036
    }
6037
6038
    /**
6039
     * Retorna os erros detectados
6040
     * @return array
6041
     */
6042
    public function getErrors()
6043
    {
6044
        return $this->errors;
6045
    }
6046
6047
    /**
6048
     * Includes missing or unsupported properties in stdClass
6049
     * Replace all unsuported chars
6050
     *
6051
     * @param stdClass $std
6052
     * @param array $possible
6053
     * @return stdClass
6054
     */
6055
    private function equilizeParameters(stdClass $std, $possible)
6056
    {
6057
        return Strings::equilizeParameters($std, $possible, $this->replaceAccentedChars);
6058
    }
6059
}
6060