Passed
Push — master ( 5d2310...77fcce )
by
unknown
02:36
created

Make::tagemit()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 60

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 60
ccs 0
cts 60
cp 0
rs 8.8727
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

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