Passed
Push — master ( 0955ff...5ce3da )
by Roberto
02:48 queued 10s
created

Make::tagemiDocAnt()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 53

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 53
ccs 0
cts 53
cp 0
rs 9.0254
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
            'IE',
2206
            'IEST',
2207
            'xNome',
2208
            'xFant'
2209
        ];
2210
        $std = $this->equilizeParameters($std, $possible);
2211
        $identificador = '#97 <emit> - ';
2212
        $this->emit = $this->dom->createElement('emit');
2213
        $this->dom->addChild(
2214
            $this->emit,
2215
            'CNPJ',
2216
            $std->CNPJ,
2217
            true,
2218
            $identificador . 'CNPJ do emitente'
2219
        );
2220
        $this->dom->addChild(
2221
            $this->emit,
2222
            'IE',
2223
            Strings::onlyNumbers($std->IE),
2224
            false,
2225
            $identificador . 'Inscrição Estadual do Emitente'
2226
        );
2227
        $this->dom->addChild(
2228
            $this->emit,
2229
            'IEST',
2230
            Strings::onlyNumbers($std->IEST),
2231
            false,
2232
            $identificador . 'Inscrição Estadual do Substituto Tributário'
2233
        );
2234
        $this->dom->addChild(
2235
            $this->emit,
2236
            'xNome',
2237
            $std->xNome,
2238
            true,
2239
            $identificador . 'Razão social ou Nome do emitente'
2240
        );
2241
        $this->dom->addChild(
2242
            $this->emit,
2243
            'xFant',
2244
            $std->xFant,
2245
            false,
2246
            $identificador . 'Nome fantasia'
2247
        );
2248
        return $this->emit;
2249
    }
2250
2251
    /**
2252
     * Gera as tags para o elemento: "enderEmit" (Endereço do emitente)
2253
     * #102
2254
     * Nível: 2
2255
     * Os parâmetros para esta função são todos os elementos da tag "enderEmit" do
2256
     * tipo elemento (Ele = E|CE|A) e nível 3
2257
     *
2258
     * @return \DOMElement
2259
     */
2260
    public function tagenderEmit($std)
2261
    {
2262
        $possible = [
2263
            'xLgr',
2264
            'nro',
2265
            'xCpl',
2266
            'xBairro',
2267
            'cMun',
2268
            'xMun',
2269
            'CEP',
2270
            'UF',
2271
            'fone'
2272
        ];
2273
        $std = $this->equilizeParameters($std, $possible);
2274
        $identificador = '#102 <enderEmit> - ';
2275
        $this->enderEmit = $this->dom->createElement('enderEmit');
2276
        $this->dom->addChild(
2277
            $this->enderEmit,
2278
            'xLgr',
2279
            $std->xLgr,
2280
            true,
2281
            $identificador . 'Logradouro'
2282
        );
2283
        $this->dom->addChild(
2284
            $this->enderEmit,
2285
            'nro',
2286
            $std->nro,
2287
            true,
2288
            $identificador . 'Número'
2289
        );
2290
        $this->dom->addChild(
2291
            $this->enderEmit,
2292
            'xCpl',
2293
            $std->xCpl,
2294
            false,
2295
            $identificador . 'Complemento'
2296
        );
2297
        $this->dom->addChild(
2298
            $this->enderEmit,
2299
            'xBairro',
2300
            $std->xBairro,
2301
            true,
2302
            $identificador . 'Bairro'
2303
        );
2304
        $this->dom->addChild(
2305
            $this->enderEmit,
2306
            'cMun',
2307
            $std->cMun,
2308
            true,
2309
            $identificador . 'Código do município'
2310
        );
2311
        $this->dom->addChild(
2312
            $this->enderEmit,
2313
            'xMun',
2314
            $std->xMun,
2315
            true,
2316
            $identificador . 'Nome do município'
2317
        );
2318
        $this->dom->addChild(
2319
            $this->enderEmit,
2320
            'CEP',
2321
            $std->CEP,
2322
            false,
2323
            $identificador . 'CEP'
2324
        );
2325
        $this->dom->addChild(
2326
            $this->enderEmit,
2327
            'UF',
2328
            $std->UF,
2329
            true,
2330
            $identificador . 'Sigla da UF'
2331
        );
2332
        $this->dom->addChild(
2333
            $this->enderEmit,
2334
            'fone',
2335
            $std->fone,
2336
            false,
2337
            $identificador . 'Telefone'
2338
        );
2339
        return $this->enderEmit;
2340
    }
2341
2342
    /**
2343
     * Gera as tags para o elemento: "rem" (Informações do Remetente das mercadorias
2344
     * transportadas pelo CT-e)
2345
     * #112
2346
     * Nível = 1
2347
     * Os parâmetros para esta função são todos os elementos da tag "rem" do
2348
     * tipo elemento (Ele = E|CE|A) e nível 2
2349
     *
2350
     * @return \DOMElement
2351
     */
2352
    public function tagrem($std)
2353
    {
2354
        $possible = [
2355
            'CNPJ',
2356
            'CPF',
2357
            'IE',
2358
            'xNome',
2359
            'xFant',
2360
            'fone',
2361
            'email'
2362
        ];
2363
        $std = $this->equilizeParameters($std, $possible);
2364
        $identificador = '#97 <rem> - ';
2365
        $this->rem = $this->dom->createElement('rem');
2366
        if ($std->CNPJ != '') {
2367
            $this->dom->addChild(
2368
                $this->rem,
2369
                'CNPJ',
2370
                $std->CNPJ,
2371
                true,
2372
                $identificador . 'CNPJ do Remente'
2373
            );
2374
        } elseif ($std->CPF != '') {
2375
            $this->dom->addChild(
2376
                $this->rem,
2377
                'CPF',
2378
                $std->CPF,
2379
                true,
2380
                $identificador . 'CPF do Remente'
2381
            );
2382
        } else {
2383
            $this->dom->addChild(
2384
                $this->rem,
2385
                'CNPJ',
2386
                $std->CNPJ,
2387
                true,
2388
                $identificador . 'CNPJ do Remente'
2389
            );
2390
            $this->dom->addChild(
2391
                $this->rem,
2392
                'CPF',
2393
                $std->CPF,
2394
                true,
2395
                $identificador . 'CPF do remente'
2396
            );
2397
        }
2398
        $this->dom->addChild(
2399
            $this->rem,
2400
            'IE',
2401
            $std->IE,
2402
            false,
2403
            $identificador . 'Inscrição Estadual do remente'
2404
        );
2405
        $xNome = $std->xNome;
2406
        if ($this->tpAmb == '2') {
2407
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2408
        }
2409
        $this->dom->addChild(
2410
            $this->rem,
2411
            'xNome',
2412
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2413
            true,
2414
            $identificador . 'Razão social ou Nome do remente'
2415
        );
2416
        $this->dom->addChild(
2417
            $this->rem,
2418
            'xFant',
2419
            $std->xFant,
2420
            false,
2421
            $identificador . 'Nome fantasia'
2422
        );
2423
        $this->dom->addChild(
2424
            $this->rem,
2425
            'fone',
2426
            $std->fone,
2427
            false,
2428
            $identificador . 'Telefone'
2429
        );
2430
        $this->dom->addChild(
2431
            $this->rem,
2432
            'email',
2433
            $std->email,
2434
            false,
2435
            $identificador . 'Endereço de email'
2436
        );
2437
        return $this->rem;
2438
    }
2439
2440
    /**
2441
     * Gera as tags para o elemento: "enderReme" (Dados do endereço)
2442
     * #120
2443
     * Nível: 2
2444
     * Os parâmetros para esta função são todos os elementos da tag "enderReme" do
2445
     * tipo elemento (Ele = E|CE|A) e nível 3
2446
     *
2447
     * @return \DOMElement
2448
     */
2449
    public function tagenderReme($std)
2450
    {
2451
        $possible = [
2452
            'xLgr',
2453
            'nro',
2454
            'xCpl',
2455
            'xBairro',
2456
            'cMun',
2457
            'xMun',
2458
            'CEP',
2459
            'UF',
2460
            'cPais',
2461
            'xPais'
2462
        ];
2463
        $std = $this->equilizeParameters($std, $possible);
2464
        $identificador = '#119 <enderReme> - ';
2465
        $this->enderReme = $this->dom->createElement('enderReme');
2466
        $this->dom->addChild(
2467
            $this->enderReme,
2468
            'xLgr',
2469
            $std->xLgr,
2470
            true,
2471
            $identificador . 'Logradouro'
2472
        );
2473
        $this->dom->addChild(
2474
            $this->enderReme,
2475
            'nro',
2476
            $std->nro,
2477
            true,
2478
            $identificador . 'Número'
2479
        );
2480
        $this->dom->addChild(
2481
            $this->enderReme,
2482
            'xCpl',
2483
            $std->xCpl,
2484
            false,
2485
            $identificador . 'Complemento'
2486
        );
2487
        $this->dom->addChild(
2488
            $this->enderReme,
2489
            'xBairro',
2490
            $std->xBairro,
2491
            true,
2492
            $identificador . 'Bairro'
2493
        );
2494
        $this->dom->addChild(
2495
            $this->enderReme,
2496
            'cMun',
2497
            $std->cMun,
2498
            true,
2499
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2500
        );
2501
        $this->dom->addChild(
2502
            $this->enderReme,
2503
            'xMun',
2504
            $std->xMun,
2505
            true,
2506
            $identificador . 'Nome do município'
2507
        );
2508
        $this->dom->addChild(
2509
            $this->enderReme,
2510
            'CEP',
2511
            $std->CEP,
2512
            false,
2513
            $identificador . 'CEP'
2514
        );
2515
        $this->dom->addChild(
2516
            $this->enderReme,
2517
            'UF',
2518
            $std->UF,
2519
            true,
2520
            $identificador . 'Sigla da UF'
2521
        );
2522
        $this->dom->addChild(
2523
            $this->enderReme,
2524
            'cPais',
2525
            $std->cPais,
2526
            false,
2527
            $identificador . 'Código do país'
2528
        );
2529
        $this->dom->addChild(
2530
            $this->enderReme,
2531
            'xPais',
2532
            $std->xPais,
2533
            false,
2534
            $identificador . 'Nome do país'
2535
        );
2536
2537
        $node = $this->rem->getElementsByTagName("email")->item(0);
2538
        $this->rem->insertBefore($this->enderReme, $node);
2539
        return $this->enderReme;
2540
    }
2541
2542
    /**
2543
     * Gera as tags para o elemento: "exped" (Informações do Expedidor da Carga)
2544
     * #132
2545
     * Nível: 1
2546
     * Os parâmetros para esta função são todos os elementos da tag "exped" do
2547
     * tipo elemento (Ele = E|CE|A) e nível 2
2548
     *
2549
     * @return \DOMElement
2550
     */
2551
    public function tagexped($std)
2552
    {
2553
        $possible = [
2554
            'CNPJ',
2555
            'CPF',
2556
            'IE',
2557
            'xNome',
2558
            'fone',
2559
            'email'
2560
        ];
2561
        $std = $this->equilizeParameters($std, $possible);
2562
        $identificador = '#142 <exped> - ';
2563
        $this->exped = $this->dom->createElement('exped');
2564
        if ($std->CNPJ != '') {
2565
            $this->dom->addChild(
2566
                $this->exped,
2567
                'CNPJ',
2568
                $std->CNPJ,
2569
                true,
2570
                $identificador . 'Número do CNPJ'
2571
            );
2572
        } elseif ($std->CPF != '') {
2573
            $this->dom->addChild(
2574
                $this->exped,
2575
                'CPF',
2576
                $std->CPF,
2577
                true,
2578
                $identificador . 'Número do CPF'
2579
            );
2580
        } else {
2581
            $this->dom->addChild(
2582
                $this->exped,
2583
                'CNPJ',
2584
                $std->CNPJ,
2585
                true,
2586
                $identificador . 'Número do CNPJ'
2587
            );
2588
            $this->dom->addChild(
2589
                $this->exped,
2590
                'CPF',
2591
                $std->CPF,
2592
                true,
2593
                $identificador . 'Número do CPF'
2594
            );
2595
        }
2596
        if (!empty($std->IE)) {
2597
            $this->dom->addChild(
2598
                $this->exped,
2599
                'IE',
2600
                $std->IE,
2601
                true,
2602
                $identificador . 'Inscrição Estadual'
2603
            );
2604
        }
2605
        $xNome = $std->xNome;
2606
        if ($this->tpAmb == '2') {
2607
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2608
        }
2609
        $this->dom->addChild(
2610
            $this->exped,
2611
            'xNome',
2612
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2613
            true,
2614
            $identificador . 'Razão social ou Nome'
2615
        );
2616
        $this->dom->addChild(
2617
            $this->exped,
2618
            'fone',
2619
            $std->fone,
2620
            false,
2621
            $identificador . 'Telefone'
2622
        );
2623
        $this->dom->addChild(
2624
            $this->exped,
2625
            'email',
2626
            $std->email,
2627
            false,
2628
            $identificador . 'Endereço de email'
2629
        );
2630
        return $this->exped;
2631
    }
2632
2633
    /**
2634
     * Gera as tags para o elemento: "enderExped" (Dados do endereço)
2635
     * #138
2636
     * Nível: 2
2637
     * Os parâmetros para esta função são todos os elementos da tag "enderExped" do
2638
     * tipo elemento (Ele = E|CE|A) e nível 3
2639
     *
2640
     * @return \DOMElement
2641
     */
2642
    public function tagenderExped($std)
2643
    {
2644
        $possible = [
2645
            'xLgr',
2646
            'nro',
2647
            'xCpl',
2648
            'xBairro',
2649
            'cMun',
2650
            'xMun',
2651
            'CEP',
2652
            'UF',
2653
            'cPais',
2654
            'xPais'
2655
        ];
2656
        $std = $this->equilizeParameters($std, $possible);
2657
        $identificador = '#148 <enderExped> - ';
2658
        $this->enderExped = $this->dom->createElement('enderExped');
2659
        $this->dom->addChild(
2660
            $this->enderExped,
2661
            'xLgr',
2662
            $std->xLgr,
2663
            true,
2664
            $identificador . 'Logradouro'
2665
        );
2666
        $this->dom->addChild(
2667
            $this->enderExped,
2668
            'nro',
2669
            $std->nro,
2670
            true,
2671
            $identificador . 'Número'
2672
        );
2673
        $this->dom->addChild(
2674
            $this->enderExped,
2675
            'xCpl',
2676
            $std->xCpl,
2677
            false,
2678
            $identificador . 'Complemento'
2679
        );
2680
        $this->dom->addChild(
2681
            $this->enderExped,
2682
            'xBairro',
2683
            $std->xBairro,
2684
            true,
2685
            $identificador . 'Bairro'
2686
        );
2687
        $this->dom->addChild(
2688
            $this->enderExped,
2689
            'cMun',
2690
            $std->cMun,
2691
            true,
2692
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2693
        );
2694
        $this->dom->addChild(
2695
            $this->enderExped,
2696
            'xMun',
2697
            $std->xMun,
2698
            true,
2699
            $identificador . 'Nome do município'
2700
        );
2701
        $this->dom->addChild(
2702
            $this->enderExped,
2703
            'CEP',
2704
            $std->CEP,
2705
            false,
2706
            $identificador . 'CEP'
2707
        );
2708
        $this->dom->addChild(
2709
            $this->enderExped,
2710
            'UF',
2711
            $std->UF,
2712
            true,
2713
            $identificador . 'Sigla da UF'
2714
        );
2715
        $this->dom->addChild(
2716
            $this->enderExped,
2717
            'cPais',
2718
            $std->cPais,
2719
            false,
2720
            $identificador . 'Código do país'
2721
        );
2722
        $this->dom->addChild(
2723
            $this->enderExped,
2724
            'xPais',
2725
            $std->xPais,
2726
            false,
2727
            $identificador . 'Nome do país'
2728
        );
2729
        $node = $this->exped->getElementsByTagName("email")->item(0);
2730
        $this->exped->insertBefore($this->enderExped, $node);
2731
        return $this->enderExped;
2732
    }
2733
2734
    /**
2735
     * Gera as tags para o elemento: "receb" (Informações do Recebedor da Carga)
2736
     * #150
2737
     * Nível: 1
2738
     * Os parâmetros para esta função são todos os elementos da tag "receb" do
2739
     * tipo elemento (Ele = E|CE|A) e nível 2
2740
     *
2741
     * @return \DOMElement
2742
     */
2743
    public function tagreceb($std)
2744
    {
2745
        $possible = [
2746
            'CNPJ',
2747
            'CPF',
2748
            'IE',
2749
            'xNome',
2750
            'fone',
2751
            'email'
2752
        ];
2753
        $std = $this->equilizeParameters($std, $possible);
2754
        $identificador = '#160 <receb> - ';
2755
        $this->receb = $this->dom->createElement('receb');
2756
        if ($std->CNPJ != '') {
2757
            $this->dom->addChild(
2758
                $this->receb,
2759
                'CNPJ',
2760
                $std->CNPJ,
2761
                true,
2762
                $identificador . 'Número do CNPJ'
2763
            );
2764
        } elseif ($std->CPF != '') {
2765
            $this->dom->addChild(
2766
                $this->receb,
2767
                'CPF',
2768
                $std->CPF,
2769
                true,
2770
                $identificador . 'Número do CPF'
2771
            );
2772
        } else {
2773
            $this->dom->addChild(
2774
                $this->receb,
2775
                'CNPJ',
2776
                $std->CNPJ,
2777
                true,
2778
                $identificador . 'Número do CNPJ'
2779
            );
2780
            $this->dom->addChild(
2781
                $this->receb,
2782
                'CPF',
2783
                $std->CPF,
2784
                true,
2785
                $identificador . 'Número do CPF'
2786
            );
2787
        }
2788
        if (!empty($std->IE)) {
2789
            $this->dom->addChild(
2790
                $this->receb,
2791
                'IE',
2792
                $std->IE,
2793
                true,
2794
                $identificador . 'Inscrição Estadual'
2795
            );
2796
        }
2797
        $xNome = $std->xNome;
2798
        if ($this->tpAmb == '2') {
2799
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2800
        }
2801
        $this->dom->addChild(
2802
            $this->receb,
2803
            'xNome',
2804
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2805
            true,
2806
            $identificador . 'Razão social ou Nome'
2807
        );
2808
        $this->dom->addChild(
2809
            $this->receb,
2810
            'fone',
2811
            $std->fone,
2812
            false,
2813
            $identificador . 'Telefone'
2814
        );
2815
        $this->dom->addChild(
2816
            $this->receb,
2817
            'email',
2818
            $std->email,
2819
            false,
2820
            $identificador . 'Endereço de email'
2821
        );
2822
        return $this->receb;
2823
    }
2824
2825
    /**
2826
     * Gera as tags para o elemento: "enderReceb" (Informações do Recebedor da Carga)
2827
     * #156
2828
     * Nível: 2
2829
     * Os parâmetros para esta função são todos os elementos da tag "enderReceb" do
2830
     * tipo elemento (Ele = E|CE|A) e nível 3
2831
     *
2832
     * @return \DOMElement
2833
     */
2834
    public function tagenderReceb($std)
2835
    {
2836
        $possible = [
2837
            'xLgr',
2838
            'nro',
2839
            'xCpl',
2840
            'xBairro',
2841
            'cMun',
2842
            'xMun',
2843
            'CEP',
2844
            'UF',
2845
            'cPais',
2846
            'xPais'
2847
        ];
2848
        $std = $this->equilizeParameters($std, $possible);
2849
        $identificador = '#160 <enderReceb> - ';
2850
        $this->enderReceb = $this->dom->createElement('enderReceb');
2851
        $this->dom->addChild(
2852
            $this->enderReceb,
2853
            'xLgr',
2854
            $std->xLgr,
2855
            true,
2856
            $identificador . 'Logradouro'
2857
        );
2858
        $this->dom->addChild(
2859
            $this->enderReceb,
2860
            'nro',
2861
            $std->nro,
2862
            true,
2863
            $identificador . 'Número'
2864
        );
2865
        $this->dom->addChild(
2866
            $this->enderReceb,
2867
            'xCpl',
2868
            $std->xCpl,
2869
            false,
2870
            $identificador . 'Complemento'
2871
        );
2872
        $this->dom->addChild(
2873
            $this->enderReceb,
2874
            'xBairro',
2875
            $std->xBairro,
2876
            true,
2877
            $identificador . 'Bairro'
2878
        );
2879
        $this->dom->addChild(
2880
            $this->enderReceb,
2881
            'cMun',
2882
            $std->cMun,
2883
            true,
2884
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2885
        );
2886
        $this->dom->addChild(
2887
            $this->enderReceb,
2888
            'xMun',
2889
            $std->xMun,
2890
            true,
2891
            $identificador . 'Nome do município'
2892
        );
2893
        $this->dom->addChild(
2894
            $this->enderReceb,
2895
            'CEP',
2896
            $std->CEP,
2897
            false,
2898
            $identificador . 'CEP'
2899
        );
2900
        $this->dom->addChild(
2901
            $this->enderReceb,
2902
            'UF',
2903
            $std->UF,
2904
            true,
2905
            $identificador . 'Sigla da UF'
2906
        );
2907
        $this->dom->addChild(
2908
            $this->enderReceb,
2909
            'cPais',
2910
            $std->cPais,
2911
            false,
2912
            $identificador . 'Código do país'
2913
        );
2914
        $this->dom->addChild(
2915
            $this->enderReceb,
2916
            'xPais',
2917
            $std->xPais,
2918
            false,
2919
            $identificador . 'Nome do país'
2920
        );
2921
        $node = $this->receb->getElementsByTagName("email")->item(0);
2922
        $this->receb->insertBefore($this->enderReceb, $node);
2923
        return $this->enderReceb;
2924
    }
2925
2926
    /**
2927
     * Gera as tags para o elemento: "dest" (Informações do Destinatário do CT-e)
2928
     * #168
2929
     * Nível: 1
2930
     * Os parâmetros para esta função são todos os elementos da tag "dest" do
2931
     * tipo elemento (Ele = E|CE|A) e nível 2
2932
     *
2933
     * @return \DOMElement
2934
     */
2935
    public function tagdest($std)
2936
    {
2937
        $possible = [
2938
            'CNPJ',
2939
            'CPF',
2940
            'IE',
2941
            'xNome',
2942
            'fone',
2943
            'ISUF',
2944
            'email'
2945
        ];
2946
        $std = $this->equilizeParameters($std, $possible);
2947
        $identificador = '#178 <dest> - ';
2948
        $this->dest = $this->dom->createElement('dest');
2949
        if ($std->CNPJ != '') {
2950
            $this->dom->addChild(
2951
                $this->dest,
2952
                'CNPJ',
2953
                $std->CNPJ,
2954
                true,
2955
                $identificador . 'Número do CNPJ'
2956
            );
2957
        } elseif ($std->CPF != '') {
2958
            $this->dom->addChild(
2959
                $this->dest,
2960
                'CPF',
2961
                $std->CPF,
2962
                true,
2963
                $identificador . 'Número do CPF'
2964
            );
2965
        } else {
2966
            $this->dom->addChild(
2967
                $this->dest,
2968
                'CNPJ',
2969
                $std->CNPJ,
2970
                true,
2971
                $identificador . 'Número do CNPJ'
2972
            );
2973
            $this->dom->addChild(
2974
                $this->dest,
2975
                'CPF',
2976
                $std->CPF,
2977
                true,
2978
                $identificador . 'Número do CPF'
2979
            );
2980
        }
2981
        if (!empty($std->IE)) {
2982
            $this->dom->addChild(
2983
                $this->dest,
2984
                'IE',
2985
                $std->IE,
2986
                true,
2987
                $identificador . 'Inscrição Estadual'
2988
            );
2989
        }
2990
        $xNome = $std->xNome;
2991
        if ($this->tpAmb == '2') {
2992
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2993
        }
2994
        $this->dom->addChild(
2995
            $this->dest,
2996
            'xNome',
2997
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2998
            true,
2999
            $identificador . 'Razão social ou Nome'
3000
        );
3001
        $this->dom->addChild(
3002
            $this->dest,
3003
            'fone',
3004
            $std->fone,
3005
            false,
3006
            $identificador . 'Telefone'
3007
        );
3008
        $this->dom->addChild(
3009
            $this->dest,
3010
            'ISUF',
3011
            $std->ISUF,
3012
            false,
3013
            $identificador . 'Inscrição na SUFRAMA'
3014
        );
3015
        $this->dom->addChild(
3016
            $this->dest,
3017
            'email',
3018
            $std->email,
3019
            false,
3020
            $identificador . 'Endereço de email'
3021
        );
3022
        return $this->dest;
3023
    }
3024
3025
    /**
3026
     * Gera as tags para o elemento: "enderDest" (Informações do Recebedor da Carga)
3027
     * # = 175
3028
     * Nível = 2
3029
     * Os parâmetros para esta função são todos os elementos da tag "enderDest" do
3030
     * tipo elemento (Ele = E|CE|A) e nível 3
3031
     *
3032
     * @return \DOMElement
3033
     */
3034
    public function tagenderDest($std)
3035
    {
3036
        $possible = [
3037
            'xLgr',
3038
            'nro',
3039
            'xCpl',
3040
            'xBairro',
3041
            'cMun',
3042
            'xMun',
3043
            'CEP',
3044
            'UF',
3045
            'cPais',
3046
            'xPais'
3047
        ];
3048
        $std = $this->equilizeParameters($std, $possible);
3049
        $identificador = '#185 <enderDest> - ';
3050
        $this->enderDest = $this->dom->createElement('enderDest');
3051
        $this->dom->addChild(
3052
            $this->enderDest,
3053
            'xLgr',
3054
            $std->xLgr,
3055
            true,
3056
            $identificador . 'Logradouro'
3057
        );
3058
        $this->dom->addChild(
3059
            $this->enderDest,
3060
            'nro',
3061
            $std->nro,
3062
            true,
3063
            $identificador . 'Número'
3064
        );
3065
        $this->dom->addChild(
3066
            $this->enderDest,
3067
            'xCpl',
3068
            $std->xCpl,
3069
            false,
3070
            $identificador . 'Complemento'
3071
        );
3072
        $this->dom->addChild(
3073
            $this->enderDest,
3074
            'xBairro',
3075
            $std->xBairro,
3076
            true,
3077
            $identificador . 'Bairro'
3078
        );
3079
        $this->dom->addChild(
3080
            $this->enderDest,
3081
            'cMun',
3082
            $std->cMun,
3083
            true,
3084
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
3085
        );
3086
        $this->dom->addChild(
3087
            $this->enderDest,
3088
            'xMun',
3089
            $std->xMun,
3090
            true,
3091
            $identificador . 'Nome do município'
3092
        );
3093
        $this->dom->addChild(
3094
            $this->enderDest,
3095
            'CEP',
3096
            $std->CEP,
3097
            false,
3098
            $identificador . 'CEP'
3099
        );
3100
        $this->dom->addChild(
3101
            $this->enderDest,
3102
            'UF',
3103
            $std->UF,
3104
            true,
3105
            $identificador . 'Sigla da UF'
3106
        );
3107
        $this->dom->addChild(
3108
            $this->enderDest,
3109
            'cPais',
3110
            $std->cPais,
3111
            false,
3112
            $identificador . 'Código do país'
3113
        );
3114
        $this->dom->addChild(
3115
            $this->enderDest,
3116
            'xPais',
3117
            $std->xPais,
3118
            false,
3119
            $identificador . 'Nome do país'
3120
        );
3121
        $node = $this->dest->getElementsByTagName("email")->item(0);
3122
        $this->dest->insertBefore($this->enderDest, $node);
3123
        return $this->enderDest;
3124
    }
3125
3126
    /**
3127
     * Gera as tags para o elemento: "vPrest" (Valores da Prestação de Serviço)
3128
     * #187
3129
     * Nível: 1
3130
     * Os parâmetros para esta função são todos os elementos da tag "vPrest" do
3131
     * tipo elemento (Ele = E|CE|A) e nível 2
3132
     *
3133
     * @return \DOMElement
3134
     */
3135
    public function tagvPrest($std)
3136
    {
3137
        $possible = [
3138
            'vTPrest',
3139
            'vRec'
3140
        ];
3141
        $std = $this->equilizeParameters($std, $possible);
3142
        $identificador = '#208 <vPrest> - ';
3143
        $this->vPrest = $this->dom->createElement('vPrest');
3144
        $this->dom->addChild(
3145
            $this->vPrest,
3146
            'vTPrest',
3147
            $this->conditionalNumberFormatting($std->vTPrest),
3148
            true,
3149
            $identificador . 'Valor Total da Prestação do Serviço'
3150
        );
3151
        $this->dom->addChild(
3152
            $this->vPrest,
3153
            'vRec',
3154
            $this->conditionalNumberFormatting($std->vRec),
3155
            true,
3156
            $identificador . 'Valor a Receber'
3157
        );
3158
        return $this->vPrest;
3159
    }
3160
3161
    /**
3162
     * Gera as tags para o elemento: "Comp" (Componentes do Valor da Prestação)
3163
     * #211
3164
     * Nível: 2
3165
     * Os parâmetros para esta função são todos os elementos da tag "Comp" do
3166
     * tipo elemento (Ele = E|CE|A) e nível 3
3167
     *
3168
     * @return \DOMElement
3169
     */
3170
    public function tagComp($std)
3171
    {
3172
        $possible = [
3173
            'xNome',
3174
            'vComp'
3175
        ];
3176
        $std = $this->equilizeParameters($std, $possible);
3177
        $identificador = '#65 <pass> - ';
3178
        $this->comp[] = $this->dom->createElement('Comp');
3179
        $posicao = (int)count($this->comp) - 1;
3180
        $this->dom->addChild(
3181
            $this->comp[$posicao],
3182
            'xNome',
3183
            $std->xNome,
3184
            false,
3185
            $identificador . 'Nome do componente'
3186
        );
3187
        $this->dom->addChild(
3188
            $this->comp[$posicao],
3189
            'vComp',
3190
            $std->vComp,
3191
            false,
3192
            $identificador . 'Valor do componente'
3193
        );
3194
        return $this->comp[$posicao];
3195
    }
3196
3197
    /**
3198
     * tagICMS
3199
     * Informações relativas ao ICMS
3200
     * #194
3201
     *
3202
     * @return DOMElement
3203
     */
3204
    public function tagicms($std)
3205
    {
3206
        $possible = [
3207
            'cst',
3208
            'vBC',
3209
            'pICMS',
3210
            'vICMS',
3211
            'pRedBC',
3212
            'vBCSTRet',
3213
            'vICMSSTRet',
3214
            'pICMSSTRet',
3215
            'vCred',
3216
            'pRedBCOutraUF',
3217
            'vBCOutraUF',
3218
            'pICMSOutraUF',
3219
            'vICMSOutraUF',
3220
            'pRedBC',
3221
            'vTotTrib',
3222
            'infAdFisco',
3223
            'vBCUFFim',
3224
            'pFCPUFFim',
3225
            'pICMSUFFim',
3226
            'pICMSInter',
3227
            'vFCPUFFim',
3228
            'vICMSUFFim',
3229
            'vICMSUFIni'
3230
        ];
3231
        $std = $this->equilizeParameters($std, $possible);
3232
        $identificador = 'N01 <ICMSxx> - ';
3233
        switch ($std->cst) {
3234
            case '00':
3235
                $icms = $this->dom->createElement("ICMS00");
3236
                $this->dom->addChild(
3237
                    $icms,
3238
                    'CST',
3239
                    $std->cst,
3240
                    true,
3241
                    "$identificador  Tributação do ICMS = 00"
3242
                );
3243
                $this->dom->addChild(
3244
                    $icms,
3245
                    'vBC',
3246
                    $this->conditionalNumberFormatting($std->vBC),
3247
                    true,
3248
                    "$identificador  Valor da BC do ICMS"
3249
                );
3250
                $this->dom->addChild(
3251
                    $icms,
3252
                    'pICMS',
3253
                    $this->conditionalNumberFormatting($std->pICMS),
3254
                    true,
3255
                    "$identificador  Alíquota do imposto"
3256
                );
3257
                $this->dom->addChild(
3258
                    $icms,
3259
                    'vICMS',
3260
                    $this->conditionalNumberFormatting($std->vICMS),
3261
                    true,
3262
                    "$identificador  Valor do ICMS"
3263
                );
3264
                break;
3265
            case '20':
3266
                $icms = $this->dom->createElement("ICMS20");
3267
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 20");
3268
                $this->dom->addChild(
3269
                    $icms,
3270
                    'pRedBC',
3271
                    $this->conditionalNumberFormatting($std->pRedBC),
3272
                    true,
3273
                    "$identificador  Percentual da Redução de BC"
3274
                );
3275
                $this->dom->addChild(
3276
                    $icms,
3277
                    'vBC',
3278
                    $this->conditionalNumberFormatting($std->vBC),
3279
                    true,
3280
                    "$identificador  Valor da BC do ICMS"
3281
                );
3282
                $this->dom->addChild(
3283
                    $icms,
3284
                    'pICMS',
3285
                    $this->conditionalNumberFormatting($std->pICMS),
3286
                    true,
3287
                    "$identificador  Alíquota do imposto"
3288
                );
3289
                $this->dom->addChild(
3290
                    $icms,
3291
                    'vICMS',
3292
                    $this->conditionalNumberFormatting($std->vICMS),
3293
                    true,
3294
                    "$identificador  Valor do ICMS"
3295
                );
3296
                break;
3297
            case '40':
3298
                $icms = $this->dom->createElement("ICMS45");
3299
                $this->dom->addChild(
3300
                    $icms,
3301
                    'CST',
3302
                    $std->cst,
3303
                    true,
3304
                    "$identificador  Tributação do ICMS = 40"
3305
                );
3306
                break;
3307
            case '41':
3308
                $icms = $this->dom->createElement("ICMS45");
3309
                $this->dom->addChild(
3310
                    $icms,
3311
                    'CST',
3312
                    $std->cst,
3313
                    true,
3314
                    "$identificador  Tributação do ICMS = 41"
3315
                );
3316
                break;
3317
            case '51':
3318
                $icms = $this->dom->createElement("ICMS45");
3319
                $this->dom->addChild(
3320
                    $icms,
3321
                    'CST',
3322
                    $std->cst,
3323
                    true,
3324
                    "$identificador  Tributação do ICMS = 51"
3325
                );
3326
                break;
3327
            case '60':
3328
                $icms = $this->dom->createElement("ICMS60");
3329
                $this->dom->addChild(
3330
                    $icms,
3331
                    'CST',
3332
                    $std->cst,
3333
                    true,
3334
                    "$identificador  Tributação do ICMS = 60"
3335
                );
3336
                $this->dom->addChild(
3337
                    $icms,
3338
                    'vBCSTRet',
3339
                    $this->conditionalNumberFormatting($std->vBCSTRet),
3340
                    true,
3341
                    "$identificador  Valor BC do ICMS ST retido"
3342
                );
3343
                $this->dom->addChild(
3344
                    $icms,
3345
                    'vICMSSTRet',
3346
                    $this->conditionalNumberFormatting($std->vICMSSTRet),
3347
                    true,
3348
                    "$identificador  Valor do ICMS ST retido"
3349
                );
3350
                $this->dom->addChild(
3351
                    $icms,
3352
                    'pICMSSTRet',
3353
                    $this->conditionalNumberFormatting($std->pICMSSTRet),
3354
                    true,
3355
                    "$identificador  Valor do ICMS ST retido"
3356
                );
3357
                if ($std->vCred > 0) {
3358
                    $this->dom->addChild(
3359
                        $icms,
3360
                        'vCred',
3361
                        $this->conditionalNumberFormatting($std->vCred),
3362
                        false,
3363
                        "$identificador  Valor do Crédito"
3364
                    );
3365
                }
3366
                break;
3367
            case '90':
3368
                if ($std->outraUF == true) {
3369
                    $icms = $this->dom->createElement("ICMSOutraUF");
3370
                    $this->dom->addChild(
3371
                        $icms,
3372
                        'CST',
3373
                        $std->cst,
3374
                        true,
3375
                        "$identificador  Tributação do ICMS = 90"
3376
                    );
3377
                    if ($std->vICMSOutraUF > 0) {
3378
                        $this->dom->addChild(
3379
                            $icms,
3380
                            'pRedBCOutraUF',
3381
                            $this->conditionalNumberFormatting($std->pRedBCOutraUF),
3382
                            false,
3383
                            "$identificador Percentual Red "
3384
                            . "BC Outra UF"
3385
                        );
3386
                    }
3387
                    $this->dom->addChild(
3388
                        $icms,
3389
                        'vBCOutraUF',
3390
                        $this->conditionalNumberFormatting($std->vBCOutraUF),
3391
                        true,
3392
                        "$identificador Valor BC ICMS Outra UF"
3393
                    );
3394
                    $this->dom->addChild(
3395
                        $icms,
3396
                        'pICMSOutraUF',
3397
                        $this->conditionalNumberFormatting($std->pICMSOutraUF),
3398
                        true,
3399
                        "$identificador Alíquota do imposto Outra UF"
3400
                    );
3401
                    $this->dom->addChild(
3402
                        $icms,
3403
                        'vICMSOutraUF',
3404
                        $this->conditionalNumberFormatting($std->vICMSOutraUF),
3405
                        true,
3406
                        "$identificador Valor ICMS Outra UF"
3407
                    );
3408
                } else {
3409
                    $icms = $this->dom->createElement("ICMS90");
3410
                    $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador Tributação do ICMS = 90");
3411
                    if ($std->pRedBC > 0) {
3412
                        $this->dom->addChild(
3413
                            $icms,
3414
                            'pRedBC',
3415
                            $this->conditionalNumberFormatting($std->pRedBC),
3416
                            false,
3417
                            "$identificador Percentual Redução BC"
3418
                        );
3419
                    }
3420
                    $this->dom->addChild(
3421
                        $icms,
3422
                        'vBC',
3423
                        $this->conditionalNumberFormatting($std->vBC),
3424
                        true,
3425
                        "$identificador  Valor da BC do ICMS"
3426
                    );
3427
                    $this->dom->addChild(
3428
                        $icms,
3429
                        'pICMS',
3430
                        $this->conditionalNumberFormatting($std->pICMS),
3431
                        true,
3432
                        "$identificador  Alíquota do imposto"
3433
                    );
3434
                    $this->dom->addChild(
3435
                        $icms,
3436
                        'vICMS',
3437
                        $this->conditionalNumberFormatting($std->vICMS),
3438
                        true,
3439
                        "$identificador  Valor do ICMS"
3440
                    );
3441
                    if ($std->vCred > 0) {
3442
                        $this->dom->addChild(
3443
                            $icms,
3444
                            'vCred',
3445
                            $this->conditionalNumberFormatting($std->vCred),
3446
                            false,
3447
                            "$identificador  Valor do Crédido"
3448
                        );
3449
                    }
3450
                }
3451
                break;
3452
            case 'SN':
3453
                $icms = $this->dom->createElement("ICMSSN");
3454
                $this->dom->addChild(
3455
                    $icms,
3456
                    'CST',
3457
                    90,
3458
                    true,
3459
                    "$identificador Tributação do ICMS = 90"
3460
                );
3461
                $this->dom->addChild(
3462
                    $icms,
3463
                    'indSN',
3464
                    '1',
3465
                    true,
3466
                    "$identificador  Indica se contribuinte é SN"
3467
                );
3468
                break;
3469
        }
3470
        $this->imp = $this->dom->createElement('imp');
3471
        $tagIcms = $this->dom->createElement('ICMS');
3472
        if (isset($icms)) {
3473
            $this->imp->appendChild($tagIcms);
3474
        }
3475
        if (isset($icms)) {
3476
            $tagIcms->appendChild($icms);
3477
        }
3478
        if ($std->vTotTrib > 0) {
3479
            $this->dom->addChild(
3480
                $this->imp,
3481
                'vTotTrib',
3482
                $this->conditionalNumberFormatting($std->vTotTrib),
3483
                false,
3484
                "$identificador Valor Total dos Tributos"
3485
            );
3486
        }
3487
        if (isset($std->infAdFisco)) {
3488
            $this->dom->addChild(
3489
                $this->imp,
3490
                'infAdFisco',
3491
                $std->infAdFisco,
3492
                false,
3493
                "$identificador Informações adicionais de interesse do Fisco"
3494
            );
3495
        }
3496
3497
        if ($std->vICMSUFFim != '' || $std->vICMSUFIni != '') {
3498
            $icmsDifal = $this->dom->createElement("ICMSUFFim");
3499
            $this->dom->addChild(
3500
                $icmsDifal,
3501
                'vBCUFFim',
3502
                $this->conditionalNumberFormatting($std->vBCUFFim),
3503
                true,
3504
                "$identificador Valor da BC do ICMS na UF
3505
                de término da prestação do serviço de transporte"
3506
            );
3507
            $this->dom->addChild(
3508
                $icmsDifal,
3509
                'pFCPUFFim',
3510
                $this->conditionalNumberFormatting($std->pFCPUFFim),
3511
                true,
3512
                "$identificador Percentual do ICMS
3513
                relativo ao Fundo de Combate à pobreza (FCP) na UF de término da prestação do serviço de
3514
                transporte"
3515
            );
3516
            $this->dom->addChild(
3517
                $icmsDifal,
3518
                'pICMSUFFim',
3519
                $this->conditionalNumberFormatting($std->pICMSUFFim),
3520
                true,
3521
                "$identificador Alíquota interna da UF
3522
                de término da prestação do serviço de transporte"
3523
            );
3524
            $this->dom->addChild(
3525
                $icmsDifal,
3526
                'pICMSInter',
3527
                $this->conditionalNumberFormatting($std->pICMSInter),
3528
                true,
3529
                "$identificador Alíquota interestadual
3530
                das UF envolvidas"
3531
            );
3532
            $this->dom->addChild(
3533
                $icmsDifal,
3534
                'vFCPUFFim',
3535
                $this->conditionalNumberFormatting($std->vFCPUFFim),
3536
                true,
3537
                "$identificador Valor do ICMS relativo
3538
                ao Fundo de Combate á Pobreza (FCP) da UF de término da prestação"
3539
            );
3540
            $this->dom->addChild(
3541
                $icmsDifal,
3542
                'vICMSUFFim',
3543
                $this->conditionalNumberFormatting($std->vICMSUFFim),
3544
                true,
3545
                "$identificador Valor do ICMS de
3546
                partilha para a UF de término da prestação do serviço de transporte"
3547
            );
3548
            $this->dom->addChild(
3549
                $icmsDifal,
3550
                'vICMSUFIni',
3551
                $this->conditionalNumberFormatting($std->vICMSUFIni),
3552
                true,
3553
                "$identificador Valor do ICMS de
3554
                partilha para a UF de início da prestação do serviço de transporte"
3555
            );
3556
3557
            $this->imp->appendChild($icmsDifal);
3558
        }
3559
3560
        return $tagIcms;
3561
    }
3562
3563
    /**
3564
     * tagInfTribFed
3565
     * Informações do Impostos Federais
3566
     * CTe OS
3567
     * @return DOMElement
3568
     */
3569
    public function taginfTribFed($std)
3570
    {
3571
        $possible = [
3572
            'vPIS',
3573
            'vCOFINS',
3574
            'vIR',
3575
            'vINSS',
3576
            'vCSLL'
3577
        ];
3578
        $std = $this->equilizeParameters($std, $possible);
3579
        $identificador = 'N02 <imp> - ';
3580
        $tagInfTribFed = $this->dom->createElement('infTribFed');
3581
        $this->dom->addChild(
3582
            $tagInfTribFed,
3583
            'vPIS',
3584
            $this->conditionalNumberFormatting($std->vPIS),
3585
            false,
3586
            "$identificador  Valor de PIS"
3587
        );
3588
        $this->dom->addChild(
3589
            $tagInfTribFed,
3590
            'vCOFINS',
3591
            $this->conditionalNumberFormatting($std->vCOFINS),
3592
            false,
3593
            "$identificador  Valor de COFINS"
3594
        );
3595
        $this->dom->addChild(
3596
            $tagInfTribFed,
3597
            'vIR',
3598
            $this->conditionalNumberFormatting($std->vIR),
3599
            false,
3600
            "$identificador  Valor de IR"
3601
        );
3602
        $this->dom->addChild(
3603
            $tagInfTribFed,
3604
            'vINSS',
3605
            $this->conditionalNumberFormatting($std->vINSS),
3606
            false,
3607
            "$identificador  Valor de INSS"
3608
        );
3609
        $this->dom->addChild(
3610
            $tagInfTribFed,
3611
            'vCSLL',
3612
            $this->conditionalNumberFormatting($std->vCSLL),
3613
            false,
3614
            "$identificador  Valor de CSLL"
3615
        );
3616
        $this->imp->appendChild($tagInfTribFed);
3617
    }
3618
3619
    /**
3620
     * Tag raiz do documento xml
3621
     * Função chamada pelo método [ monta ]
3622
     * @return \DOMElement
3623
     */
3624
    private function buildCTe()
3625
    {
3626
        if (empty($this->CTe)) {
3627
            $this->CTe = $this->dom->createElement('CTe');
3628
            $this->CTe->setAttribute('xmlns', 'http://www.portalfiscal.inf.br/cte');
3629
        }
3630
        return $this->CTe;
3631
    }
3632
3633
    /**
3634
     * Tag raiz do documento xml
3635
     * Função chamada pelo método [ monta ]
3636
     * @return \DOMElement
3637
     */
3638
    private function buildCTeOS()
3639
    {
3640
        if (empty($this->CTe)) {
3641
            $this->CTe = $this->dom->createElement('CTeOS');
3642
            $this->CTe->setAttribute('versao', '3.00');
3643
            $this->CTe->setAttribute('xmlns', 'http://www.portalfiscal.inf.br/cte');
3644
        }
3645
        return $this->CTe;
3646
    }
3647
3648
    /**
3649
     * Gera as tags para o elemento: "Entrega" (Informações ref. a previsão de entrega)
3650
     * #69
3651
     * Nível: 2
3652
     * Os parâmetros para esta função são todos os elementos da tag "Entrega" do
3653
     * tipo elemento (Ele = E|CE|A) e nível 3
3654
     *
3655
     * @return \DOMElement
3656
     */
3657
    private function tagEntrega()
3658
    {
3659
        if ($this->compl == '') {
3660
            $this->compl = $this->dom->createElement('compl');
3661
        }
3662
        if ($this->entrega == '') {
3663
            $this->entrega = $this->dom->createElement('Entrega');
3664
            $this->dom->appChild($this->compl, $this->entrega, 'Falta tag "compl"');
3665
        }
3666
        return $this->entrega;
3667
    }
3668
3669
    /**
3670
     * #241
3671
     * @return type
3672
     */
3673
    public function taginfCTeNorm()
3674
    {
3675
        $this->infCTeNorm = $this->dom->createElement('infCTeNorm');
3676
        return $this->infCTeNorm;
3677
    }
3678
3679
    /**
3680
     * Gera as tags para o elemento: "infCarga" (Informações da Carga do CT-e)
3681
     * #242
3682
     * Nível: 2
3683
     *
3684
     * @return \DOMElement
3685
     */
3686
    public function taginfCarga($std)
3687
    {
3688
        $possible = [
3689
            'vCarga',
3690
            'proPred',
3691
            'xOutCat'
3692
        ];
3693
        $std = $this->equilizeParameters($std, $possible);
3694
        $identificador = '#242 <infCarga> - ';
3695
        $this->infCarga = $this->dom->createElement('infCarga');
3696
        $this->dom->addChild(
3697
            $this->infCarga,
3698
            'vCarga',
3699
            $this->conditionalNumberFormatting($std->vCarga),
3700
            false,
3701
            $identificador . 'Valor Total da Carga'
3702
        );
3703
        $this->dom->addChild(
3704
            $this->infCarga,
3705
            'proPred',
3706
            $std->proPred,
3707
            true,
3708
            $identificador . 'Produto Predominante'
3709
        );
3710
        $this->dom->addChild(
3711
            $this->infCarga,
3712
            'xOutCat',
3713
            $std->xOutCat,
3714
            false,
3715
            $identificador . 'Outras Caract. da Carga'
3716
        );
3717
        return $this->infCarga;
3718
    }
3719
3720
    /**
3721
     * Gera as tags para o elemento: "infCTeNorm" (Informações da Carga do CT-e OS)
3722
     * #253
3723
     * Nível: 2
3724
     * Os parâmetros para esta função são todos os elementos da tag "infServico"
3725
     *
3726
     * @return \DOMElement
3727
     */
3728
    public function taginfServico($std)
3729
    {
3730
        $possible = [
3731
            'xDescServ'
3732
        ];
3733
        $std = $this->equilizeParameters($std, $possible);
3734
        $identificador = '#253 <infServico> - ';
3735
        $this->infServico = $this->dom->createElement('infServico');
3736
        $this->dom->addChild(
3737
            $this->infServico,
3738
            'xDescServ',
3739
            $std->xDescServ,
3740
            true,
3741
            $identificador . 'Descrição do Serviço Prestado'
3742
        );
3743
        $infQ = $this->dom->createElement('infQ');
3744
        $this->dom->addChild($infQ, 'qCarga', $std->qCarga, false, $identificador . 'Quantidade');
3745
        $this->infServico->appendChild($infQ);
3746
        return $this->infServico;
3747
    }
3748
3749
    /**
3750
     * Gera as tags para o elemento: "infQ" (Informações de quantidades da Carga do CT-e)
3751
     * #246
3752
     * Nível: 3
3753
     * Os parâmetros para esta função são todos os elementos da tag "infQ"
3754
     *
3755
     * @return mixed
3756
     */
3757
    public function taginfQ($std)
3758
    {
3759
        $possible = [
3760
            'cUnid',
3761
            'tpMed',
3762
            'qCarga',
3763
            'vCargaAverb'
3764
        ];
3765
        $std = $this->equilizeParameters($std, $possible);
3766
        $identificador = '#257 <infQ> - ';
3767
        $this->infQ[] = $this->dom->createElement('infQ');
3768
        $posicao = (int)count($this->infQ) - 1;
3769
        $this->dom->addChild(
3770
            $this->infQ[$posicao],
3771
            'cUnid',
3772
            $std->cUnid,
3773
            true,
3774
            $identificador . 'Código da Unidade de Medida'
3775
        );
3776
        $this->dom->addChild(
3777
            $this->infQ[$posicao],
3778
            'tpMed',
3779
            $std->tpMed,
3780
            true,
3781
            $identificador . 'Tipo da Medida'
3782
        );
3783
        $this->dom->addChild(
3784
            $this->infQ[$posicao],
3785
            'qCarga',
3786
            $this->conditionalNumberFormatting($std->qCarga, 4),
3787
            true,
3788
            $identificador . 'Quantidade'
3789
        );
3790
        $this->dom->addChild(
3791
            $this->infQ[$posicao],
3792
            'vCargaAverb',
3793
            $this->conditionalNumberFormatting($std->vCargaAverb, 2),
3794
            false,
3795
            $identificador . 'Valor da Carga para efeito de averbação'
3796
        );
3797
        return $this->infQ[$posicao];
3798
    }
3799
3800
    private function taginfDoc()
3801
    {
3802
        if (empty($this->infDoc)) {
3803
            $this->infDoc = $this->dom->createElement('infDoc');
3804
        }
3805
        return $this->infDoc;
3806
    }
3807
3808
    /**
3809
     * Documentos de Transporte Anterior
3810
     * @return DOMElement|\DOMNode
3811
     */
3812
    public function tagdocAnt()
3813
    {
3814
        $this->docAnt = $this->dom->createElement('docAnt');
3815
        return $this->docAnt;
3816
    }
3817
3818
    /**
3819
     * Informações de identificação dos documentos de Transporte Anterior
3820
     * @return array|DOMElement
3821
     */
3822
    public function tagidDocAnt()
3823
    {
3824
        $this->idDocAnt[count($this->emiDocAnt) - 1][] = $this->dom->createElement('idDocAnt');
3825
        return $this->idDocAnt;
3826
    }
3827
3828
    /**
3829
     * Gera as tags para o elemento: "infNF" (Informações das NF)
3830
     * #262
3831
     * Nível: 3
3832
     * @return mixed
3833
     */
3834
    public function taginfNF($std)
3835
    {
3836
        $possible = [
3837
            'nRoma',
3838
            'nPed',
3839
            'mod',
3840
            'serie',
3841
            'nDoc',
3842
            'dEmi',
3843
            'vBC',
3844
            'vICMS',
3845
            'vBCST',
3846
            'vST',
3847
            'vProd',
3848
            'vNF',
3849
            'nCFOP',
3850
            'nPeso',
3851
            'PIN',
3852
            'dPrev',
3853
            'infUnidCarga',
3854
            'infUnidTransp'
3855
        ];
3856
        $this->taginfDoc();
3857
        $std = $this->equilizeParameters($std, $possible);
3858
        $identificador = '#262 <infNF> - ';
3859
        $infNF = $this->dom->createElement('infNF');
3860
        $this->dom->addChild(
3861
            $infNF,
3862
            'nRoma',
3863
            $std->nRoma,
3864
            false,
3865
            $identificador . 'Número do Romaneio da NF'
3866
        );
3867
        $this->dom->addChild(
3868
            $infNF,
3869
            'nPed',
3870
            $std->nPed,
3871
            false,
3872
            $identificador . 'Número do Pedido da NF'
3873
        );
3874
        $this->dom->addChild(
3875
            $infNF,
3876
            'mod',
3877
            $std->mod,
3878
            true,
3879
            $identificador . 'Modelo da Nota Fiscal'
3880
        );
3881
        $this->dom->addChild(
3882
            $infNF,
3883
            'serie',
3884
            $std->serie,
3885
            true,
3886
            $identificador . 'Série'
3887
        );
3888
        $this->dom->addChild(
3889
            $infNF,
3890
            'nDoc',
3891
            $std->nDoc,
3892
            true,
3893
            $identificador . 'Número'
3894
        );
3895
        $this->dom->addChild(
3896
            $infNF,
3897
            'dEmi',
3898
            $std->dEmi,
3899
            true,
3900
            $identificador . 'Data de Emissão'
3901
        );
3902
        $this->dom->addChild(
3903
            $infNF,
3904
            'vBC',
3905
            $this->conditionalNumberFormatting($std->vBC),
3906
            true,
3907
            $identificador . 'Valor da Base de Cálculo do ICMS'
3908
        );
3909
        $this->dom->addChild(
3910
            $infNF,
3911
            'vICMS',
3912
            $this->conditionalNumberFormatting($std->vICMS),
3913
            true,
3914
            $identificador . 'Valor Totaldo ICMS'
3915
        );
3916
        $this->dom->addChild(
3917
            $infNF,
3918
            'vBCST',
3919
            $this->conditionalNumberFormatting($std->vBCST),
3920
            true,
3921
            $identificador . 'Valor da Base de Cálculo do ICMS ST'
3922
        );
3923
        $this->dom->addChild(
3924
            $infNF,
3925
            'vST',
3926
            $this->conditionalNumberFormatting($std->vST),
3927
            true,
3928
            $identificador . 'Valor Total do ICMS ST'
3929
        );
3930
        $this->dom->addChild(
3931
            $infNF,
3932
            'vProd',
3933
            $this->conditionalNumberFormatting($std->vProd),
3934
            true,
3935
            $identificador . 'Valor Total dos Produtos'
3936
        );
3937
        $this->dom->addChild(
3938
            $infNF,
3939
            'vNF',
3940
            $this->conditionalNumberFormatting($std->vNF),
3941
            true,
3942
            $identificador . 'Valor Total da NF'
3943
        );
3944
        $this->dom->addChild(
3945
            $infNF,
3946
            'nCFOP',
3947
            $std->nCFOP,
3948
            true,
3949
            $identificador . 'CFOP Predominante'
3950
        );
3951
        $this->dom->addChild(
3952
            $infNF,
3953
            'nPeso',
3954
            $this->conditionalNumberFormatting($std->nPeso, 3),
3955
            false,
3956
            $identificador . 'Peso total em Kg'
3957
        );
3958
        $this->dom->addChild(
3959
            $infNF,
3960
            'PIN',
3961
            $std->PIN,
3962
            false,
3963
            $identificador . 'PIN SUFRAMA'
3964
        );
3965
        $this->dom->addChild(
3966
            $infNF,
3967
            'dPrev',
3968
            $std->dPrev,
3969
            false,
3970
            $identificador . 'Data prevista de entrega'
3971
        );
3972
        if ($std->infUnidCarga) {
3973
            foreach ($std->infUnidCarga as $value) {
3974
                $this->dom->appChild($infNF, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
3975
            }
3976
        }
3977
        if ($std->infUnidTransp) {
3978
            foreach ($std->infUnidTransp as $value) {
3979
                $this->dom->appChild($infNF, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
3980
            }
3981
        }
3982
        $this->infNF[] = $infNF;
3983
        return $infNF;
3984
    }
3985
3986
    /**
3987
     * Gera as tags para o elemento: "infNFe" (Informações das NF-e)
3988
     * #297
3989
     * Nível: 3
3990
     * @return mixed
3991
     */
3992
    public function taginfNFe($std)
3993
    {
3994
        $possible = [
3995
            'chave',
3996
            'PIN',
3997
            'dPrev',
3998
            'infUnidCarga',
3999
            'infUnidTransp'
4000
        ];
4001
        $this->taginfDoc();
4002
        $std = $this->equilizeParameters($std, $possible);
4003
        $identificador = '#297 <infNFe> - ';
4004
        $infNFe = $this->dom->createElement('infNFe');
4005
        $this->dom->addChild(
4006
            $infNFe,
4007
            'chave',
4008
            $std->chave,
4009
            true,
4010
            $identificador . 'Chave de acesso da NF-e'
4011
        );
4012
        $this->dom->addChild(
4013
            $infNFe,
4014
            'PIN',
4015
            $std->PIN,
4016
            false,
4017
            $identificador . 'PIN SUFRAMA'
4018
        );
4019
        $this->dom->addChild(
4020
            $infNFe,
4021
            'dPrev',
4022
            $std->dPrev,
4023
            false,
4024
            $identificador . 'Data prevista de entrega'
4025
        );
4026
        if ($std->infUnidCarga) {
4027
            foreach ($std->infUnidCarga as $value) {
4028
                $this->dom->appChild($infNFe, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
4029
            }
4030
        }
4031
        if ($std->infUnidTransp) {
4032
            foreach ($std->infUnidTransp as $value) {
4033
                $this->dom->appChild($infNFe, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
4034
            }
4035
        }
4036
        $this->infNFe[] = $infNFe;
4037
        return $infNFe;
4038
    }
4039
4040
    /**
4041
     * Gera as tags para o elemento: "infOutros" (Informações dos demais documentos)
4042
     * #319
4043
     * Nível: 3
4044
     * @return mixed
4045
     */
4046
    public function taginfOutros($std)
4047
    {
4048
        $possible = [
4049
            'tpDoc',
4050
            'descOutros',
4051
            'nDoc',
4052
            'dEmi',
4053
            'vDocFisc',
4054
            'dPrev',
4055
            'infUnidCarga',
4056
            'infUnidTransp'
4057
        ];
4058
        $this->taginfDoc();
4059
        $std = $this->equilizeParameters($std, $possible);
4060
        $ident = '#319 <infOutros> - ';
4061
        $infOutros = $this->dom->createElement('infOutros');
4062
        $this->dom->addChild(
4063
            $infOutros,
4064
            'tpDoc',
4065
            $std->tpDoc,
4066
            true,
4067
            $ident . 'Tipo de documento originário'
4068
        );
4069
        $this->dom->addChild(
4070
            $infOutros,
4071
            'descOutros',
4072
            $std->descOutros,
4073
            false,
4074
            $ident . 'Descrição do documento'
4075
        );
4076
        $this->dom->addChild(
4077
            $infOutros,
4078
            'nDoc',
4079
            $std->nDoc,
4080
            false,
4081
            $ident . 'Número do documento'
4082
        );
4083
        $this->dom->addChild(
4084
            $infOutros,
4085
            'dEmi',
4086
            $std->dEmi,
4087
            false,
4088
            $ident . 'Data de Emissão'
4089
        );
4090
        $this->dom->addChild(
4091
            $infOutros,
4092
            'vDocFisc',
4093
            $this->conditionalNumberFormatting($std->vDocFisc),
4094
            false,
4095
            $ident . 'Valor do documento'
4096
        );
4097
        $this->dom->addChild(
4098
            $infOutros,
4099
            'dPrev',
4100
            $std->dPrev,
4101
            false,
4102
            $ident . 'Data ista de entrega'
4103
        );
4104
        if ($std->infUnidCarga) {
4105
            foreach ($std->infUnidCarga as $value) {
4106
                $this->dom->appChild($infOutros, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
4107
            }
4108
        }
4109
        if ($std->infUnidTransp) {
4110
            foreach ($std->infUnidTransp as $value) {
4111
                $this->dom->appChild($infOutros, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
4112
            }
4113
        }
4114
        $this->infOutros[] = $infOutros;
4115
        return $infOutros;
4116
    }
4117
4118
    /**
4119
     * taginfUnidCarga
4120
     * tag CTe/infCte/infDoc/(infNF/infNFe/infOutros)/infUnidCarga
4121
     *
4122
     * @param stdClass $std
4123
     * @return DOMElement
4124
     */
4125
    private function taginfUnidCarga(stdClass $std)
4126
    {
4127
        $possible = [
4128
            'tpUnidCarga',
4129
            'idUnidCarga',
4130
            'lacUnidCarga',
4131
            'qtdRat'
4132
        ];
4133
        $std = $this->equilizeParameters($std, $possible);
4134
        $infUnidCarga = $this->dom->createElement("infUnidCarga");
4135
        $this->dom->addChild(
4136
            $infUnidCarga,
4137
            "tpUnidCarga",
4138
            $std->tpUnidCarga,
4139
            false,
4140
            "Tipo da Unidade de Carga"
4141
        );
4142
        $this->dom->addChild(
4143
            $infUnidCarga,
4144
            "idUnidCarga",
4145
            $std->idUnidCarga,
4146
            false,
4147
            "Identificação da Unidade de Carga "
4148
        );
4149
        if ($std->lacUnidCarga != null) {
4150
            $possible = [
4151
                'nLacre'
4152
            ];
4153
            $stdlacUnidCarga = $this->equilizeParameters($std->lacUnidCarga, $possible);
4154
            foreach ($stdlacUnidCarga->nLacre as $nLacre) {
4155
                $lacUnidCarga = $this->dom->createElement("lacUnidCarga");
4156
                $this->dom->addChild(
4157
                    $lacUnidCarga,
4158
                    "nLacre",
4159
                    $nLacre,
4160
                    true,
4161
                    "Número do lacre"
4162
                );
4163
                $this->dom->appChild($infUnidCarga, $lacUnidCarga, 'Falta tag "infUnidCarga"');
4164
            }
4165
        }
4166
        $this->dom->addChild(
4167
            $infUnidCarga,
4168
            "qtdRat",
4169
            $this->conditionalNumberFormatting($std->qtdRat),
4170
            false,
4171
            "Quantidade rateada (Peso,Volume)"
4172
        );
4173
        return $infUnidCarga;
4174
    }
4175
4176
    /**
4177
     * taginfUnidTransp
4178
     * tag CTe/infCte/infDoc/(infNF/infNFe/infOutros)/infUnidTransp
4179
     *
4180
     * @param stdClass $std
4181
     * @return DOMElement
4182
     */
4183
    private function taginfUnidTransp(stdClass $std)
4184
    {
4185
        $possible = [
4186
            'tpUnidTransp',
4187
            'idUnidTransp',
4188
            'qtdRat',
4189
            'lacUnidTransp',
4190
            'infUnidCarga'
4191
        ];
4192
        $std = $this->equilizeParameters($std, $possible);
4193
        $infUnidTransp = $this->dom->createElement("infUnidTransp");
4194
        $this->dom->addChild(
4195
            $infUnidTransp,
4196
            "tpUnidTransp",
4197
            $std->tpUnidTransp,
4198
            true,
4199
            "Tipo da Unidade de Transporte"
4200
        );
4201
        $this->dom->addChild(
4202
            $infUnidTransp,
4203
            "idUnidTransp",
4204
            $std->idUnidTransp,
4205
            false,
4206
            "Identificação da Unidade de Transporte"
4207
        );
4208
        if ($std->lacUnidTransp != null) {
4209
            $possible = [
4210
                'nLacre'
4211
            ];
4212
            $stdlacUnidTransp = $this->equilizeParameters($std->lacUnidTransp, $possible);
4213
            foreach ($stdlacUnidTransp->nLacre as $nLacre) {
4214
                $lacUnidTransp = $this->dom->createElement("lacUnidTransp");
4215
                $this->dom->addChild(
4216
                    $lacUnidTransp,
4217
                    "nLacre",
4218
                    $nLacre,
4219
                    true,
4220
                    "Número do lacre"
4221
                );
4222
                $this->dom->appChild($infUnidTransp, $lacUnidTransp, 'Falta tag "infUnidTransp"');
4223
            }
4224
        }
4225
        if ($std->infUnidCarga) {
4226
            foreach ($std->infUnidCarga as $value) {
4227
                $this->dom->appChild($infUnidTransp, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
4228
            }
4229
        }
4230
        $this->dom->addChild(
4231
            $infUnidTransp,
4232
            "qtdRat",
4233
            $this->conditionalNumberFormatting($std->qtdRat),
4234
            false,
4235
            "Quantidade rateada (Peso,Volume) "
4236
        );
4237
        return $infUnidTransp;
4238
    }
4239
4240
    /**
4241
     * Gera as tags para o elemento: "infDocRef" (Informações dos demais documentos)
4242
     * #319
4243
     * Nível: 3
4244
     * @return mixed
4245
     */
4246
    public function taginfDocRef($std)
4247
    {
4248
        $possible = [
4249
            'nDoc',
4250
            'serie',
4251
            'subserie',
4252
            'dEmi',
4253
            'vDoc'
4254
        ];
4255
        $std = $this->equilizeParameters($std, $possible);
4256
        $ident = '#319 <infDocRef> - ';
4257
        $this->infDocRef[] = $this->dom->createElement('infDocRef');
4258
        $posicao = (int)count($this->infDocRef) - 1;
4259
        $this->dom->addChild(
4260
            $this->infDocRef[$posicao],
4261
            'nDoc',
4262
            $std->nDoc,
4263
            false,
4264
            $ident . 'Número do documento'
4265
        );
4266
        $this->dom->addChild(
4267
            $this->infDocRef[$posicao],
4268
            'serie',
4269
            $std->serie,
4270
            false,
4271
            $ident . 'Série do documento'
4272
        );
4273
        $this->dom->addChild(
4274
            $this->infDocRef[$posicao],
4275
            'subserie',
4276
            $std->subserie,
4277
            false,
4278
            $ident . 'Subserie do documento'
4279
        );
4280
        $this->dom->addChild(
4281
            $this->infDocRef[$posicao],
4282
            'dEmi',
4283
            $std->dEmi,
4284
            false,
4285
            $ident . 'Data de Emissão'
4286
        );
4287
        $this->dom->addChild(
4288
            $this->infDocRef[$posicao],
4289
            'vDoc',
4290
            $this->conditionalNumberFormatting($std->vDoc),
4291
            false,
4292
            $ident . 'Valor do documento'
4293
        );
4294
        return $this->infDocRef[$posicao];
4295
    }
4296
4297
    /**
4298
     * Gera as tags para o elemento: "emiDocAnt" (Informações dos CT-es Anteriores)
4299
     * #345
4300
     * Nível: 3
4301
     * @return mixed
4302
     */
4303
    public function tagemiDocAnt($std)
4304
    {
4305
        $possible = [
4306
            'CNPJ',
4307
            'IE',
4308
            'UF',
4309
            'CPF',
4310
            'xNome'
4311
        ];
4312
        $std = $this->equilizeParameters($std, $possible);
4313
        $identificador = '#345 <emiDocAnt> - ';
4314
        $this->emiDocAnt[] = $this->dom->createElement('emiDocAnt');
4315
        $posicao = (int)count($this->emiDocAnt) - 1;
4316
        if ($std->CNPJ != '') {
4317
            $this->dom->addChild(
4318
                $this->emiDocAnt[$posicao],
4319
                'CNPJ',
4320
                $std->CNPJ,
4321
                true,
4322
                $identificador . 'Número do CNPJ'
4323
            );
4324
            $this->dom->addChild(
4325
                $this->emiDocAnt[$posicao],
4326
                'IE',
4327
                Strings::onlyNumbers($std->IE),
4328
                true,
4329
                $identificador . 'Inscrição Estadual'
4330
            );
4331
            $this->dom->addChild(
4332
                $this->emiDocAnt[$posicao],
4333
                'UF',
4334
                $std->UF,
4335
                true,
4336
                $identificador . 'Sigla da UF'
4337
            );
4338
        } else {
4339
            $this->dom->addChild(
4340
                $this->emiDocAnt[$posicao],
4341
                'CPF',
4342
                $std->CPF,
4343
                true,
4344
                $identificador . 'Número do CPF'
4345
            );
4346
        }
4347
        $this->dom->addChild(
4348
            $this->emiDocAnt[$posicao],
4349
            'xNome',
4350
            $std->xNome,
4351
            true,
4352
            $identificador . 'Razão Social ou Nome do Expedidor'
4353
        );
4354
        return $this->emiDocAnt[$posicao];
4355
    }
4356
4357
    /**
4358
     * Gera as tags para o elemento: "idDocAntEle" (Informações dos CT-es Anteriores)
4359
     * #348
4360
     * Nível: 4
4361
     * @return mixed
4362
     */
4363
    public function tagidDocAntEle($std)
4364
    {
4365
        $possible = [
4366
            'chCTe'
4367
        ];
4368
        $std = $this->equilizeParameters($std, $possible);
4369
        $identificador = '#358 <idDocAntEle> - ';
4370
        $this->idDocAntEle[count($this->emiDocAnt) - 1][] = $this->dom->createElement('idDocAntEle');
4371
        $posicao = (int)count($this->idDocAntEle[count($this->emiDocAnt) - 1]) - 1;
4372
        $this->dom->addChild(
4373
            $this->idDocAntEle[count($this->emiDocAnt) - 1][$posicao],
4374
            'chCTe',
4375
            $std->chCTe,
4376
            true,
4377
            $identificador . 'Chave de Acesso do CT-e'
4378
        );
4379
        return $this->idDocAntEle[count($this->emiDocAnt) - 1][$posicao];
4380
    }
4381
4382
4383
    /**
4384
     * Gera as tags para o elemento: "seg" (Informações de Seguro da Carga)
4385
     * #360
4386
     * Nível: 2
4387
     * @return mixed
4388
     */
4389
    public function tagseg($std)
4390
    {
4391
        $possible = [
4392
            'respSeg',
4393
            'xSeg',
4394
            'nApol'
4395
        ];
4396
        $std = $this->equilizeParameters($std, $possible);
4397
        $identificador = '#360 <seg> - ';
4398
        $this->seg[] = $this->dom->createElement('seg');
4399
        $posicao = (int)count($this->seg) - 1;
4400
        $this->dom->addChild(
4401
            $this->seg[$posicao],
4402
            'respSeg',
4403
            $std->respSeg,
4404
            true,
4405
            $identificador . 'Responsável pelo Seguro'
4406
        );
4407
        $this->dom->addChild(
4408
            $this->seg[$posicao],
4409
            'xSeg',
4410
            $std->xSeg,
4411
            false,
4412
            $identificador . 'Nome da Seguradora'
4413
        );
4414
        $this->dom->addChild(
4415
            $this->seg[$posicao],
4416
            'nApol',
4417
            $std->nApol,
4418
            false,
4419
            $identificador . 'Número da Apólice'
4420
        );
4421
        return $this->seg[$posicao];
4422
    }
4423
4424
    /**
4425
     * Gera as tags para o elemento: "idDocAntEle" (Informações dos CT-es Anteriores)
4426
     * #348
4427
     * Nível: 4
4428
     * @return mixed
4429
     */
4430
    public function tagidDocAntPap($std)
4431
    {
4432
        $possible = [
4433
            'tpDoc',
4434
            'serie',
4435
            'subser',
4436
            'nDoc',
4437
            'dEmi'
4438
        ];
4439
        $std = $this->equilizeParameters($std, $possible);
4440
        $identificador = '#358 <idDocAntPap> - ';
4441
        $this->idDocAntPap[count($this->emiDocAnt) - 1][] = $this->dom->createElement('idDocAntPap');
4442
        $posicao = (int)count($this->idDocAntPap[count($this->emiDocAnt) - 1]) - 1;
4443
        $this->dom->addChild(
4444
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4445
            'tpDoc',
4446
            $std->tpDoc,
4447
            true,
4448
            $identificador . 'Tipo do Documento de Transporte Anterior'
4449
        );
4450
        $this->dom->addChild(
4451
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4452
            'serie',
4453
            $std->serie,
4454
            true,
4455
            $identificador . 'Série do Documento Fiscal'
4456
        );
4457
        $this->dom->addChild(
4458
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4459
            'subser',
4460
            $std->subser,
4461
            false,
4462
            $identificador . 'Série do Documento Fiscal'
4463
        );
4464
        $this->dom->addChild(
4465
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4466
            'nDoc',
4467
            $std->nDoc,
4468
            true,
4469
            $identificador . 'Número do Documento Fiscal'
4470
        );
4471
        $this->dom->addChild(
4472
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4473
            'dEmi',
4474
            $std->dEmi,
4475
            true,
4476
            $identificador . 'Data de emissão (AAAA-MM-DD)'
4477
        );
4478
        return $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao];
4479
    }
4480
4481
4482
    /**
4483
     * Gera as tags para o elemento: "infModal" (Informações do modal)
4484
     * #366
4485
     * Nível: 2
4486
     * @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...
4487
     * @return DOMElement|\DOMNode
4488
     */
4489
    public function taginfModal($std)
4490
    {
4491
        $this->infModal = $this->dom->createElement('infModal');
4492
        $this->infModal->setAttribute('versaoModal', $std->versaoModal);
4493
        return $this->infModal;
4494
    }
4495
4496
    /**
4497
     * Leiaute - Rodoviário
4498
     * Gera as tags para o elemento: "rodo" (Informações do modal Rodoviário)
4499
     * #1
4500
     * Nível: 0
4501
     * @return DOMElement|\DOMNode
4502
     */
4503
    public function tagrodo($std)
4504
    {
4505
        $possible = [
4506
            'RNTRC'
4507
        ];
4508
        $std = $this->equilizeParameters($std, $possible);
4509
        $identificador = '#1 <rodo> - ';
4510
        $this->rodo = $this->dom->createElement('rodo');
4511
        $this->dom->addChild(
4512
            $this->rodo,
4513
            'RNTRC',
4514
            $std->RNTRC,
4515
            true,
4516
            $identificador . 'Registro nacional de transportadores
4517
            rodoviários de carga'
4518
        );
4519
        return $this->rodo;
4520
    }
4521
4522
    /**
4523
     * Leiaute - Dutoviário
4524
     * Gera as tags para o elemento: "duto" (informações do modal Dutoviário)
4525
     * @return DOMElement|\DOMNode
4526
     * @author Uilasmar Guedes
4527
     * #1
4528
     * Nivel: 0
4529
     */
4530
    public function tagduto($std)
4531
    {
4532
        $possible = [
4533
            'vTar',
4534
            'dIni',
4535
            'dFim'
4536
        ];
4537
4538
        $std = $this->equilizeParameters($std, $possible);
4539
4540
        $identificador = '#1 <duto> - ';
4541
        $this->duto = $this->dom->createElement('duto');
4542
        $this->dom->addChild(
4543
            $this->duto,
4544
            'vTar',
4545
            $this->conditionalNumberFormatting($std->vTar),
4546
            false,
4547
            $identificador . 'Valor da tarifa '
4548
        );
4549
        $this->dom->addChild(
4550
            $this->duto,
4551
            'dIni',
4552
            $std->dIni,
4553
            true,
4554
            $identificador . 'Data de Início da prestação do serviço'
4555
        );
4556
        $this->dom->addChild(
4557
            $this->duto,
4558
            'dFim',
4559
            $std->dFim,
4560
            true,
4561
            $identificador . 'Data de Fim da prestação do serviço'
4562
        );
4563
        return $this->duto;
4564
    }
4565
4566
    /**
4567
     * Leiaute - Aquaviario
4568
     * Gera as tags para o elemento: "aquav" (informações do modal Aquaviario)
4569
     * @return DOMElement|\DOMNode
4570
     * @author Anderson Minuto Consoni Vaz
4571
     * #1
4572
     * Nivel: 0
4573
     */
4574
    public function tagaquav($std)
4575
    {
4576
        $possible = [
4577
            'vPrest',
4578
            'vAFRMM',
4579
            'xNavio',
4580
            'nViag',
4581
            'direc',
4582
            'irin',
4583
            'tpNav'
4584
        ];
4585
        $std = $this->equilizeParameters($std, $possible);
4586
        $identificador = '#1 <aquav> - ';
4587
        $this->aquav = $this->dom->createElement('aquav');
4588
        $this->dom->addChild(
4589
            $this->aquav,
4590
            'vPrest',
4591
            $this->conditionalNumberFormatting($std->vPrest),
4592
            true,
4593
            $identificador . 'vPrest'
4594
        );
4595
        $this->dom->addChild(
4596
            $this->aquav,
4597
            'vAFRMM',
4598
            $this->conditionalNumberFormatting($std->vAFRMM),
4599
            true,
4600
            $identificador . 'vAFRMM'
4601
        );
4602
        $this->dom->addChild(
4603
            $this->aquav,
4604
            'xNavio',
4605
            $std->xNavio,
4606
            true,
4607
            $identificador . 'xNavio'
4608
        );
4609
        $this->dom->addChild(
4610
            $this->aquav,
4611
            'nViag',
4612
            $std->nViag,
4613
            true,
4614
            $identificador . 'nViag'
4615
        );
4616
        $this->dom->addChild(
4617
            $this->aquav,
4618
            'direc',
4619
            $std->direc,
4620
            true,
4621
            $identificador . 'direc'
4622
        );
4623
        $this->dom->addChild(
4624
            $this->aquav,
4625
            'irin',
4626
            $std->irin,
4627
            true,
4628
            $identificador . 'irin'
4629
        );
4630
        $this->dom->addChild(
4631
            $this->aquav,
4632
            'tpNav',
4633
            $std->tpNav,
4634
            false,
4635
            $identificador . 'tpNav'
4636
        );
4637
        return $this->aquav;
4638
    }
4639
4640
    /**
4641
     * Leiaute - Aquaviario
4642
     * Gera as tags de balsa para o elemento: "aquav" (informações do modal Aquaviario)
4643
     * @return DOMElement|\DOMNode
4644
     * @author Gabriel Kliemaschewsk Rondon
4645
     * #5
4646
     * Nivel: 1
4647
     */
4648
    public function tagbalsa($std)
4649
    {
4650
        $possible = [
4651
            'xBalsa',
4652
        ];
4653
        $std = $this->equilizeParameters($std, $possible);
4654
        $identificador = '#5 <balsa> - ';
4655
        $this->balsa[] = $this->dom->createElement('balsa');
4656
        $this->dom->addChild(
4657
            $this->balsa[count($this->balsa) - 1],
4658
            'xBalsa',
4659
            $std->xBalsa,
4660
            true,
4661
            $identificador . 'xBalsa'
4662
        );
4663
        return $this->balsa;
4664
    }
4665
4666
    /**
4667
     * Leiaute - Aquaviario
4668
     * Gera as tags de Conteiner específicas do modal aquaviário
4669
     * @return DOMElement|\DOMNode
4670
     * @author Gabriel Kliemaschewsk Rondon
4671
     * #10
4672
     * Nivel: 1
4673
     */
4674
    public function tagdetCont($std)
4675
    {
4676
        $possible = [
4677
            'nCont',
4678
        ];
4679
        $std = $this->equilizeParameters($std, $possible);
4680
        $identificador = '#10 <detCont> - ';
4681
        $this->detCont[] = $this->dom->createElement('detCont');
4682
        $this->dom->addChild(
4683
            $this->detCont[count($this->detCont) - 1],
4684
            'nCont',
4685
            $std->nCont,
4686
            true,
4687
            $identificador . 'detCont'
4688
        );
4689
        return $this->detCont;
4690
    }
4691
4692
    /**
4693
     * Leiaute - Aquaviario
4694
     * Gera as tags de lacre para os containeres do elemento: "aquav" (informações do modal Aquaviario)
4695
     * @return DOMElement|\DOMNode
4696
     * @author Gabriel Kliemaschewsk Rondon
4697
     * #12
4698
     * Nivel: 2
4699
     */
4700
    public function taglacre($std)
4701
    {
4702
        $possible = [
4703
            'nLacre',
4704
        ];
4705
        $std = $this->equilizeParameters($std, $possible);
4706
        $identificador = '#12 <detCont> - ';
4707
        $this->lacre[count($this->detCont) - 1][] = $this->dom->createElement('lacre');
4708
        $posicao = (int)count($this->lacre[count($this->detCont) - 1]) - 1;
4709
        $this->dom->addChild(
4710
            $this->lacre[count($this->detCont) - 1][$posicao],
4711
            'nLacre',
4712
            $std->nLacre,
4713
            true,
4714
            $identificador . 'Lacre'
4715
        );
4716
        return $this->lacre[count($this->detCont) - 1][$posicao];
4717
    }
4718
4719
    public function taginfDocCont()
4720
    {
4721
        $this->infDocCont[count($this->detCont) - 1] = $this->dom->createElement('infDoc');
4722
        return $this->infDocCont;
4723
    }
4724
4725
    public function taginfNFCont($std)
4726
    {
4727
        $possible = [
4728
            'serie',
4729
            'nDoc',
4730
            'unidRat',
4731
        ];
4732
        $std = $this->equilizeParameters($std, $possible);
4733
        $identificador = '#15 <detCont> <infNF> - ';
4734
        $this->infNFCont[count($this->detCont) - 1][] = $this->dom->createElement('infNF');
4735
        $posicao = (int)count($this->infNFCont[count($this->detCont) - 1]) - 1;
4736
        $this->dom->addChild(
4737
            $this->infNFCont[count($this->detCont) - 1][$posicao],
4738
            'serie',
4739
            $std->serie,
4740
            true,
4741
            $identificador . 'serie'
4742
        );
4743
4744
        $this->dom->addChild(
4745
            $this->infNFCont[count($this->detCont) - 1][$posicao],
4746
            'nDoc',
4747
            $std->nDoc,
4748
            true,
4749
            $identificador . 'nDoc'
4750
        );
4751
4752
        $this->dom->addChild(
4753
            $this->infNFCont[count($this->detCont) - 1][$posicao],
4754
            'unidRat',
4755
            $std->unidRat,
4756
            false,
4757
            $identificador . 'unidRat'
4758
        );
4759
4760
        return $this->infNFCont[count($this->detCont) - 1][$posicao];
4761
    }
4762
4763
    public function taginfNFeCont($std)
4764
    {
4765
        $possible = [
4766
            'chave',
4767
            'unidRat',
4768
        ];
4769
        $std = $this->equilizeParameters($std, $possible);
4770
        $identificador = '#19 <infNFe> - ';
4771
        $this->infNFeCont[count($this->detCont) - 1][] = $this->dom->createElement('infNFe');
4772
        $posicao = (int)count($this->infNFeCont[count($this->detCont) - 1]) - 1;
4773
        $this->dom->addChild(
4774
            $this->infNFeCont[count($this->detCont) - 1][$posicao],
4775
            'chave',
4776
            $std->chave,
4777
            true,
4778
            $identificador . 'chave'
4779
        );
4780
        $this->dom->addChild(
4781
            $this->infNFeCont[count($this->detCont) - 1][$posicao],
4782
            'unidRat',
4783
            $std->unidRat,
4784
            false,
4785
            $identificador . 'unidRat'
4786
        );
4787
    }
4788
    /**
4789
     * Leiaute - Rodoviário
4790
     * Gera as tags para o elemento: "rodo" (Informações do modal Rodoviário) CT-e OS
4791
     * #1
4792
     * Nível: 0
4793
     * @return DOMElement|\DOMNode
4794
     */
4795
    public function tagrodoOS($std)
4796
    {
4797
4798
        $possible = [
4799
            'TAF',
4800
            'NroRegEstadual'
4801
        ];
4802
        $std = $this->equilizeParameters($std, $possible);
4803
        $identificador = '#1 <rodoOS> - ';
4804
        $this->rodo = $this->dom->createElement('rodoOS');
4805
        $this->dom->addChild(
4806
            $this->rodo,
4807
            'TAF',
4808
            $std->TAF,
4809
            false,
4810
            $identificador . 'Termo de Autorização de Fretamento - TAF'
4811
        );
4812
        $this->dom->addChild(
4813
            $this->rodo,
4814
            'NroRegEstadual',
4815
            $std->NroRegEstadual,
4816
            false,
4817
            $identificador . 'Número do Registro Estadual'
4818
        );
4819
        return $this->rodo;
4820
    }
4821
4822
    /**
4823
     * Leiaute - Aéreo
4824
     * Gera as tags para o elemento: "aereo" (Informações do modal Aéreo)
4825
     * @return DOMElement|\DOMNode
4826
     * @author Newton Pasqualini Filho
4827
     * #1
4828
     * Nível: 0
4829
     */
4830
    public function tagaereo($std)
4831
    {
4832
4833
        $possible = [
4834
            'nMinu',
4835
            'nOCA',
4836
            'dPrevAereo',
4837
            'natCarga_xDime',
4838
            'natCarga_cInfManu',
4839
            'tarifa_CL',
4840
            'tarifa_cTar',
4841
            'tarifa_vTar'
4842
        ];
4843
        $std = $this->equilizeParameters($std, $possible);
4844
        $identificador = '#1 <aereo> - ';
4845
        $this->aereo = $this->dom->createElement('aereo');
4846
        $this->dom->addChild(
4847
            $this->aereo,
4848
            'nMinu',
4849
            $std->nMinu,
4850
            false,
4851
            $identificador . 'Número da Minuta'
4852
        );
4853
        $this->dom->addChild(
4854
            $this->aereo,
4855
            'nOCA',
4856
            $std->nOCA,
4857
            false,
4858
            $identificador . 'Número Operacional do Conhecimento Aéreo'
4859
        );
4860
        $this->dom->addChild(
4861
            $this->aereo,
4862
            'dPrevAereo',
4863
            $std->dPrevAereo,
4864
            true,
4865
            $identificador . 'Data prevista da entrega'
4866
        );
4867
        if (isset($std->natCarga_xDime) || isset($std->natCarga_cInfManu)) {
4868
            $identificador = '#1 <aereo> - <natCarga> - ';
4869
            $natCarga = $this->dom->createElement('natCarga');
4870
            $this->dom->addChild(
4871
                $natCarga,
4872
                'xDime',
4873
                $std->natCarga_xDime,
4874
                false,
4875
                $identificador . 'Dimensões da carga, formato: 1234x1234x1234 (cm)'
4876
            );
4877
            if (isset($std->natCarga_cInfManu) && !is_array($std->natCarga_cInfManu)) {
4878
                $std->natCarga_cInfManu = [$std->natCarga_cInfManu];
4879
            }
4880
            $cInfManuX = 0;
4881
            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...
4882
                $cInfManuX++;
4883
                $this->dom->addChild(
4884
                    $natCarga,
4885
                    'cInfManu',
4886
                    $cInfManu,
4887
                    false,
4888
                    $identificador . 'Informação de manuseio, com dois dígitos, pode ter mais de uma ocorrência.'
4889
                );
4890
            }
4891
            $this->aereo->appendChild($natCarga);
4892
        }
4893
        $identificador = '#1 <aereo> - <tarifa> - ';
4894
        $tarifa = $this->dom->createElement('tarifa');
4895
        $this->dom->addChild(
4896
            $tarifa,
4897
            'CL',
4898
            $std->tarifa_CL,
4899
            true,
4900
            $identificador . 'Classe da tarifa: M - Tarifa Mínima / G - Tarifa Geral / E - Tarifa Específica'
4901
        );
4902
        $this->dom->addChild(
4903
            $tarifa,
4904
            'cTar',
4905
            $std->tarifa_cTar,
4906
            false,
4907
            $identificador . 'Código de três digítos correspondentes à tarifa.'
4908
        );
4909
        $this->dom->addChild(
4910
            $tarifa,
4911
            'vTar',
4912
            $this->conditionalNumberFormatting($std->tarifa_vTar),
4913
            true,
4914
            $identificador . 'Valor da tarifa. 15 posições, sendo 13 inteiras e 2 decimais.'
4915
        );
4916
        $this->aereo->appendChild($tarifa);
4917
        return $this->aereo;
4918
    }
4919
4920
    /**
4921
     * Leiaute - Aéreo
4922
     * Gera as tags para o elemento: "aereo" (Informações do modal Aéreo)
4923
     * #1
4924
     * Nível: 0
4925
     * @return DOMElement|\DOMNode
4926
     */
4927
    public function tagperi($std)
4928
    {
4929
        $possible = [
4930
            'nONU',
4931
            'qTotEmb',
4932
            'qTotProd',
4933
            'uniAP'
4934
        ];
4935
        $std = $this->equilizeParameters($std, $possible);
4936
        $identificador = '#1 <aereo> - <peri> - ';
4937
        $peri = $this->dom->createElement('peri');
4938
        $this->dom->addChild(
4939
            $peri,
4940
            'nONU',
4941
            $std->nONU,
4942
            true,
4943
            $identificador . 'Número ONU/UN'
4944
        );
4945
        $this->dom->addChild(
4946
            $peri,
4947
            'qTotEmb',
4948
            $this->conditionalNumberFormatting($std->qTotEmb, 0),
4949
            true,
4950
            $identificador . 'Quantidade total de volumes contendo artigos perigosos'
4951
        );
4952
        $identificador = '#1 <peri> - <infTotAP> - ';
4953
        $infTotAP = $this->dom->createElement('infTotAP');
4954
        $this->dom->addChild(
4955
            $infTotAP,
4956
            'qTotProd',
4957
            $this->conditionalNumberFormatting($std->qTotProd, 4),
4958
            false,
4959
            $identificador . 'Quantidade total de artigos perigosos'
4960
        );
4961
        $this->dom->addChild(
4962
            $infTotAP,
4963
            'uniAP',
4964
            $std->uniAP,
4965
            true,
4966
            $identificador . 'Unidade de medida'
4967
        );
4968
        $peri->appendChild($infTotAP);
4969
        $this->peri[] = $peri;
4970
        return $peri;
4971
    }
4972
4973
    public function tagferrov($std)
4974
    {
4975
        $possible = [
4976
            'tpTraf',
4977
            'respFat',
4978
            'ferrEmi',
4979
            'vFrete',
4980
            'chCTeFerroOrigem ',
4981
            'fluxo'
4982
        ];
4983
        $std = $this->equilizeParameters($std, $possible);
4984
        $identificador = '#1 <ferrov> - ';
4985
        $this->ferrov = $this->dom->createElement('ferrov');
4986
        $this->dom->addChild(
4987
            $this->ferrov,
4988
            'tpTraf',
4989
            $std->tpTraf,
4990
            true,
4991
            $identificador . 'Tipo de Tráfego'
4992
        );
4993
        $identificador = '#1 <ferrov> - <trafMut> - ';
4994
        $trafMut = $this->dom->createElement('trafMut');
4995
        $this->dom->addChild(
4996
            $trafMut,
4997
            'respFat',
4998
            $std->respFat,
4999
            true,
5000
            $identificador . 'Responsável pelo Faturamento'
5001
        );
5002
        $this->dom->addChild(
5003
            $trafMut,
5004
            'ferrEmi',
5005
            $std->ferrEmi,
5006
            true,
5007
            $identificador . 'Ferrovia Emitente do CTe'
5008
        );
5009
        $this->dom->addChild(
5010
            $trafMut,
5011
            'vFrete',
5012
            $this->conditionalNumberFormatting($std->vFrete),
5013
            true,
5014
            $identificador . 'Valor do Frete do Tráfego Mútuo '
5015
        );
5016
        $this->dom->addChild(
5017
            $trafMut,
5018
            'chCTeFerroOrigem',
5019
            $std->chCTeFerroOrigem,
5020
            false,
5021
            $identificador . 'Chave de acesso do CT-e emitido pelo ferrovia de origem'
5022
        );
5023
        $this->ferrov->appendChild($trafMut);
5024
        $this->dom->addChild(
5025
            $this->ferrov,
5026
            'fluxo',
5027
            $std->fluxo,
5028
            true,
5029
            $identificador . 'Fluxo Ferroviário '
5030
        );
5031
    }
5032
5033
    public function tagferroEnv($std)
5034
    {
5035
        $possible = [
5036
            'CNPJ',
5037
            'cInt',
5038
            'IE',
5039
            'xNome',
5040
            'xLgr',
5041
            'nro',
5042
            'xCpl',
5043
            'xBairro',
5044
            'cMun',
5045
            'xMun',
5046
            'CEP',
5047
            'UF',
5048
            'fluxo'
5049
        ];
5050
        $std = $this->equilizeParameters($std, $possible);
5051
        $identificador = '#1 <trafMut> - <ferroEnv> - ';
5052
        $ferroEnv = $this->dom->createElement('ferroEnv');
5053
        $this->dom->addChild(
5054
            $ferroEnv,
5055
            'CNPJ',
5056
            $std->CNPJ,
5057
            true,
5058
            $identificador . 'Número do CNPJ'
5059
        );
5060
        $this->dom->addChild(
5061
            $ferroEnv,
5062
            'cInt',
5063
            $std->cInt,
5064
            false,
5065
            $identificador . 'Código interno da Ferrovia envolvida'
5066
        );
5067
        $this->dom->addChild(
5068
            $ferroEnv,
5069
            'IE',
5070
            $std->IE,
5071
            false,
5072
            $identificador . 'Inscrição Estadual'
5073
        );
5074
        $this->dom->addChild(
5075
            $ferroEnv,
5076
            'xNome',
5077
            $std->xNome,
5078
            false,
5079
            $identificador . 'Razão Social ou Nome'
5080
        );
5081
        $identificador = '#1 <ferroEnv> - <enderFerro> - ';
5082
        $enderFerro = $this->dom->createElement('enderFerro');
5083
        $this->dom->addChild(
5084
            $enderFerro,
5085
            'xLgr',
5086
            $std->xLgr,
5087
            true,
5088
            $identificador . 'Logradouro'
5089
        );
5090
        $this->dom->addChild(
5091
            $enderFerro,
5092
            'nro',
5093
            $std->nro,
5094
            false,
5095
            $identificador . 'Número'
5096
        );
5097
        $this->dom->addChild(
5098
            $enderFerro,
5099
            'xCpl',
5100
            $std->xCpl,
5101
            false,
5102
            $identificador . 'Complemento'
5103
        );
5104
        $this->dom->addChild(
5105
            $enderFerro,
5106
            'xBairro',
5107
            $std->xBairro,
5108
            false,
5109
            $identificador . 'Bairro'
5110
        );
5111
        $this->dom->addChild(
5112
            $enderFerro,
5113
            'cMun',
5114
            $std->cMun,
5115
            true,
5116
            $identificador . 'Código do município'
5117
        );
5118
        $this->dom->addChild(
5119
            $enderFerro,
5120
            'xMun',
5121
            $std->xMun,
5122
            true,
5123
            $identificador . 'Nome do município'
5124
        );
5125
        $this->dom->addChild(
5126
            $enderFerro,
5127
            'CEP',
5128
            $std->CEP,
5129
            true,
5130
            $identificador . 'CEP'
5131
        );
5132
        $this->dom->addChild(
5133
            $enderFerro,
5134
            'UF',
5135
            $std->UF,
5136
            true,
5137
            $identificador . 'Sigla da UF'
5138
        );
5139
        $ferroEnv->appendChild($enderFerro);
5140
        $this->ferroEnv[] = $ferroEnv;
5141
        return $ferroEnv;
5142
    }
5143
5144
    /**
5145
     * Leiaute - Multimodal
5146
     * Gera as tags do leaiute específico de multimodal
5147
     * @return DOMElement|\DOMNode
5148
     * @author Gabriel Kliemaschewsk Rondon
5149
     * Nivel: 1
5150
     */
5151
    public function tagmultimodal($std)
5152
    {
5153
        $possible = [
5154
            'COTM',
5155
            'indNegociavel',
5156
        ];
5157
        $std = $this->equilizeParameters($std, $possible);
5158
        $identificador = '#1 <multimodal> - ';
5159
        $this->multimodal = $this->dom->createElement('multimodal');
5160
        $this->dom->addChild(
5161
            $this->multimodal,
5162
            'COTM',
5163
            $std->COTM,
5164
            true,
5165
            $identificador . 'COTM'
5166
        );
5167
        $this->dom->addChild(
5168
            $this->multimodal,
5169
            'indNegociavel',
5170
            $std->indNegociavel,
5171
            true,
5172
            $identificador . 'indNegociavel'
5173
        );
5174
        
5175
        return $this->multimodal;
5176
    }
5177
5178
    public function tagSegMultimodal($std)
5179
    {
5180
        $possible = [
5181
            'xSeg',
5182
            'CNPJ',
5183
            'nApol',
5184
            'nAver'
5185
        ];
5186
        $std = $this->equilizeParameters($std, $possible);
5187
        $identificador = '#4 <multimodal> - ';
5188
        $this->segMultim = $this->dom->createElement('seg');
5189
        $infSeg = $this->dom->createElement('infSeg');
5190
        $this->dom->addChild(
5191
            $infSeg,
5192
            'xSeg',
5193
            $std->xSeg,
5194
            true,
5195
            $identificador . 'xSeg'
5196
        );
5197
        $this->dom->addChild(
5198
            $infSeg,
5199
            'CNPJ',
5200
            $std->CNPJ,
5201
            false,
5202
            $identificador . 'indNegociavel'
5203
        );
5204
        $this->segMultim->appendChild($infSeg);
5205
        $this->dom->addChild(
5206
            $this->segMultim,
5207
            'nApol',
5208
            $std->nApol,
5209
            true,
5210
            $identificador . 'nApol'
5211
        );
5212
        $this->dom->addChild(
5213
            $this->segMultim,
5214
            'nAver',
5215
            $std->nAver,
5216
            false,
5217
            $identificador . 'nAver'
5218
        );
5219
5220
        return $this->segMultim;
5221
    }
5222
    /**
5223
     * CT-e de substituição
5224
     * @return type
5225
     */
5226
    public function taginfCteSub($std)
5227
    {
5228
        $possible = [
5229
            'chCte',
5230
            'refCteAnu'
5231
        ];
5232
        $std = $this->equilizeParameters($std, $possible);
5233
        $identificador = '#149 <infCteSub> - ';
5234
        $this->infCteSub = $this->dom->createElement('infCteSub');
5235
        $this->dom->addChild(
5236
            $this->infCteSub,
5237
            'chCte',
5238
            $std->chCte,
5239
            false,
5240
            "$identificador  Chave de acesso do CTe a ser substituído (original)"
5241
        );
5242
        $this->dom->addChild(
5243
            $this->infCteSub,
5244
            'refCteAnu',
5245
            $std->refCteAnu,
5246
            false,
5247
            "$identificador  Chave de acesso do CT-e de Anulação"
5248
        );
5249
        return $this->infCteSub;
5250
    }
5251
5252
    /**
5253
     * Informações do Serviço Vinculado a Multimodal
5254
     * @return type
5255
     */
5256
    public function infCTeMultimodal($std)
5257
    {
5258
        $possible = [
5259
            'chCTeMultimodal',
5260
        ];
5261
        $std = $this->equilizeParameters($std, $possible);
5262
        if (empty($this->infServVinc)) {
5263
            $this->infServVinc = $this->dom->createElement('infServVinc');
5264
        }
5265
        $identificador = '#388 <infCTeMultimodal> - ';
5266
        $infCTeMultimodal = $this->dom->createElement('infCTeMultimodal');
5267
        $this->dom->addChild(
5268
            $infCTeMultimodal,
5269
            'chCTeMultimodal',
5270
            $std->chCTeMultimodal,
5271
            true,
5272
            $identificador . 'Chave de acesso do CT-e Multimodal '
5273
        );
5274
        $this->infCTeMultimodal[] = $infCTeMultimodal;
5275
        return $infCTeMultimodal;
5276
    }
5277
5278
    /**
5279
     * CT-e de substituição - tomaICMS
5280
     * @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...
5281
     * @return type
5282
     */
5283
    public function tagtomaICMS()
5284
    {
5285
        $this->tomaICMS = $this->dom->createElement('tomaICMS');
5286
        return $this->tomaICMS;
5287
    }
5288
5289
    /**
5290
     * CT-e de substituição - NF-e
5291
     * @param type $std
5292
     * @return type
5293
     */
5294
    public function tagrefNFe($std)
5295
    {
5296
        $possible = [
5297
            'refNFe'
5298
        ];
5299
        $std = $this->equilizeParameters($std, $possible);
5300
        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...
5301
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
5302
        }
5303
        $identificador = '#153 <refNFe> - ';
5304
        $this->dom->addChild(
5305
            $this->tomaICMS,
5306
            'refNFe',
5307
            $std->refNFe,
5308
            false,
5309
            "$identificador  Chave de acesso da NF-e emitida pelo tomador"
5310
        );
5311
        return $this->tomaICMS;
5312
    }
5313
5314
    /**
5315
     * CT-e de substituição - NF
5316
     * @param type $std
5317
     * @return type
5318
     */
5319
    public function tagrefNF($std)
5320
    {
5321
        $possible = [
5322
            'CNPJ',
5323
            'CPF',
5324
            'mod',
5325
            'serie',
5326
            'subserie',
5327
            'nro',
5328
            'valor',
5329
            'dEmi'
5330
        ];
5331
        $std = $this->equilizeParameters($std, $possible);
5332
        $identificador = '#154 <refNFe> - ';
5333
        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...
5334
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
5335
        }
5336
        $this->refNF = $this->dom->createElement('refNF');
5337
        if ($std->CNPJ != '') {
5338
            $this->dom->addChild(
5339
                $this->refNF,
5340
                'CNPJ',
5341
                $std->CNPJ,
5342
                true,
5343
                $identificador . 'CNPJ do emitente'
5344
            );
5345
        } elseif ($std->CPF != '') {
5346
            $this->dom->addChild(
5347
                $this->refNF,
5348
                'CPF',
5349
                $std->CPF,
5350
                true,
5351
                $identificador . 'CPF do emitente'
5352
            );
5353
        }
5354
        $this->dom->addChild(
5355
            $this->refNF,
5356
            'mod',
5357
            $std->mod,
5358
            false,
5359
            $identificador . 'Modelo'
5360
        );
5361
        $this->dom->addChild(
5362
            $this->refNF,
5363
            'serie',
5364
            $std->serie,
5365
            false,
5366
            $identificador . 'Série do documento'
5367
        );
5368
        $this->dom->addChild(
5369
            $this->refNF,
5370
            'subserie',
5371
            $std->subserie,
5372
            false,
5373
            $identificador . 'Subserie do documento'
5374
        );
5375
        $this->dom->addChild(
5376
            $this->refNF,
5377
            'nro',
5378
            $std->nro,
5379
            false,
5380
            $identificador . 'Número'
5381
        );
5382
        $this->dom->addChild(
5383
            $this->refNF,
5384
            'valor',
5385
            $this->conditionalNumberFormatting($std->valor),
5386
            false,
5387
            $identificador . 'Valor'
5388
        );
5389
        $this->dom->addChild(
5390
            $this->refNF,
5391
            'dEmi',
5392
            $std->dEmi,
5393
            false,
5394
            $identificador . 'Emissão'
5395
        );
5396
        $this->tomaICMS->appendChild($this->refNF);
5397
        return $this->tomaICMS;
5398
    }
5399
5400
    /**
5401
     * CT-e de substituição - CT-e
5402
     * @param type $std
5403
     * @return type
5404
     */
5405
    public function tagrefCTe($std)
5406
    {
5407
        $possible = [
5408
            'refCte'
5409
        ];
5410
        $std = $this->equilizeParameters($std, $possible);
5411
        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...
5412
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
5413
        }
5414
        $identificador = '#163 <refCte> - ';
5415
        $this->dom->addChild(
5416
            $this->tomaICMS,
5417
            'refCte',
5418
            $std->refCte,
5419
            false,
5420
            "$identificador  Chave de acesso do CT-e emitida pelo tomador"
5421
        );
5422
        return $this->tomaICMS;
5423
    }
5424
5425
    /**
5426
     * CT-e de substituição - CT-e
5427
     * @param type $std
5428
     * @return type
5429
     */
5430
    public function tagindAlteraToma($std)
5431
    {
5432
        $possible = [
5433
            'indAlteraToma'
5434
        ];
5435
        $std = $this->equilizeParameters($std, $possible);
5436
        $this->indAlteraToma = $std->indAlteraToma;
5437
        return $this->indAlteraToma;
5438
    }
5439
5440
    /**
5441
     * Informações do CT-e Globalizado
5442
     * @param type $std
5443
     * @return type
5444
     */
5445
    public function taginfGlobalizado($std)
5446
    {
5447
        $possible = [
5448
            'xObs'
5449
        ];
5450
        $std = $this->equilizeParameters($std, $possible);
5451
        $infGlobalizado = $this->dom->createElement('infGlobalizado');
5452
        $identificador = '#163 <infGlobalizado> - ';
5453
        $this->dom->addChild(
5454
            $infGlobalizado,
5455
            'xObs',
5456
            $std->xObs,
5457
            true,
5458
            "$identificador - Preencher com informações adicionais, legislação do regime especial, etc"
5459
        );
5460
        return $this->infGlobalizado;
5461
    }
5462
5463
    /**
5464
     * Leiaute - Rodoviário
5465
     * Gera as tags para o elemento: "veic" (Dados dos Veículos)
5466
     * #21
5467
     * Nível: 1
5468
     * @return mixed
5469
     */
5470
    public function tagveicCTeOS($std)
5471
    {
5472
        $possible = [
5473
            'placa',
5474
            'RENAVAM',
5475
            'CNPJ',
5476
            'CPF',
5477
            'TAF',
5478
            'NroRegEstadual',
5479
            'xNome',
5480
            'IE',
5481
            'ufProp',
5482
            'tpProp',
5483
            'uf'
5484
        ];
5485
        $std = $this->equilizeParameters($std, $possible);
5486
        $identificador = '#21 <veic> - ';
5487
        $this->veic = $this->dom->createElement('veic');
5488
        $this->dom->addChild(
5489
            $this->veic,
5490
            'placa',
5491
            $std->placa,
5492
            false,
5493
            $identificador . 'Placa do veículo'
5494
        );
5495
        $this->dom->addChild(
5496
            $this->veic,
5497
            'RENAVAM',
5498
            $std->RENAVAM,
5499
            false,
5500
            $identificador . 'RENAVAM do veículo'
5501
        );
5502
        if ($std->xNome != '') { // CASO FOR VEICULO DE TERCEIRO
5503
            $this->prop = $this->dom->createElement('prop');
5504
            if ($std->CNPJ != '') {
5505
                $this->dom->addChild(
5506
                    $this->prop,
5507
                    'CNPJ',
5508
                    $std->CNPJ,
5509
                    true,
5510
                    $identificador . 'CNPJ do proprietario'
5511
                );
5512
            } elseif ($std->CPF != '') {
5513
                $this->dom->addChild(
5514
                    $this->prop,
5515
                    'CPF',
5516
                    $std->CPF,
5517
                    true,
5518
                    $identificador . 'CPF do proprietario'
5519
                );
5520
            }
5521
            if ($std->taf != '') {
5522
                $this->dom->addChild(
5523
                    $this->prop,
5524
                    'TAF',
5525
                    $std->taf,
5526
                    false,
5527
                    $identificador . 'TAF'
5528
                );
5529
            } else {
5530
                $this->dom->addChild(
5531
                    $this->prop,
5532
                    'NroRegEstadual',
5533
                    $std->nroRegEstadual,
5534
                    false,
5535
                    $identificador . 'Número do Registro Estadual'
5536
                );
5537
            }
5538
            $this->dom->addChild(
5539
                $this->prop,
5540
                'xNome',
5541
                $std->xNome,
5542
                true,
5543
                $identificador . 'Nome do proprietario'
5544
            );
5545
            $this->dom->addChild(
5546
                $this->prop,
5547
                'IE',
5548
                Strings::onlyNumbers($std->IE),
5549
                false,
5550
                $identificador . 'IE do proprietario'
5551
            );
5552
            $this->dom->addChild(
5553
                $this->prop,
5554
                'UF',
5555
                $std->ufProp,
5556
                true,
5557
                $identificador . 'UF do proprietario'
5558
            );
5559
            $this->dom->addChild(
5560
                $this->prop,
5561
                'tpProp',
5562
                $std->tpProp,
5563
                true,
5564
                $identificador . 'Tipo Proprietário'
5565
            );
5566
            $this->dom->appChild($this->veic, $this->prop, 'Falta tag "prop"');
5567
        }
5568
        $this->dom->addChild(
5569
            $this->veic,
5570
            'UF',
5571
            $std->uf,
5572
            true,
5573
            $identificador . 'UF em que veículo está licenciado'
5574
        );
5575
        return $this->veic;
5576
    }
5577
5578
    public function infFretamento($std)
5579
    {
5580
        $possible = [
5581
            'tpFretamento',
5582
            'dhViagem'
5583
        ];
5584
        $std = $this->equilizeParameters($std, $possible);
5585
        $identificador = '#21 <infFretamento> - ';
5586
        $this->infFretamento = $this->dom->createElement('infFretamento');
5587
        $this->dom->addChild(
5588
            $this->infFretamento,
5589
            'tpFretamento',
5590
            $std->tpFretamento,
5591
            true,
5592
            $identificador . 'Tipo do Fretamento de Pessoas'
5593
        );
5594
        $this->dom->addChild(
5595
            $this->infFretamento,
5596
            'dhViagem',
5597
            $std->dhViagem,
5598
            false,
5599
            $identificador . 'Data e hora da viagem'
5600
        );
5601
        return $this->infFretamento;
5602
    }
5603
5604
    /**
5605
     * Gera as tags para o elemento: "infCteComp" (Detalhamento do CT-e complementado)
5606
     * #410
5607
     * Nível: 1
5608
     * @return DOMElement|\DOMNode
5609
     */
5610
    public function taginfCTeComp($std)
5611
    {
5612
        $possible = [
5613
            'chCTe'
5614
        ];
5615
        $std = $this->equilizeParameters($std, $possible);
5616
        $identificador = '#410 <infCteComp> - ';
5617
        $this->infCteComp = $this->dom->createElement('infCteComp');
5618
        $this->dom->addChild(
5619
            $this->infCteComp,
5620
            'chCTe',
5621
            $std->chCTe,
5622
            true,
5623
            $identificador . ' Chave do CT-e complementado'
5624
        );
5625
        return $this->infCteComp;
5626
    }
5627
5628
    /**
5629
     * Gera as tags para o elemento: "infCteAnu" (Detalhamento do CT-e de Anulação)
5630
     * #411
5631
     * Nível: 1
5632
     * @return DOMElement|\DOMNode
5633
     */
5634
    public function taginfCteAnu($std)
5635
    {
5636
        $possible = [
5637
            'chCte',
5638
            'dEmi'
5639
        ];
5640
        $std = $this->equilizeParameters($std, $possible);
5641
        $identificador = '#411 <infCteAnu> - ';
5642
        $this->infCteAnu = $this->dom->createElement('infCteAnu');
5643
        $this->dom->addChild(
5644
            $this->infCteAnu,
5645
            'chCte',
5646
            $std->chCte,
5647
            true,
5648
            $identificador . ' Chave do CT-e anulado'
5649
        );
5650
        $this->dom->addChild(
5651
            $this->infCteAnu,
5652
            'dEmi',
5653
            $std->dEmi,
5654
            true,
5655
            $identificador . ' Data de Emissão do CT-e anulado'
5656
        );
5657
        return $this->infCteAnu;
5658
    }
5659
5660
    /**
5661
     * Gera as tags para o elemento: "autXML" (Autorizados para download do XML)
5662
     * #396
5663
     * Nível: 1
5664
     * Os parâmetros para esta função são todos os elementos da tag "autXML"
5665
     *
5666
     * @return boolean
5667
     */
5668
    public function tagveicNovos($std)
5669
    {
5670
        $possible = [
5671
            'chassi',
5672
            'cCor',
5673
            'xCor',
5674
            'cMod',
5675
            'vUnit',
5676
            'vFrete'
5677
        ];
5678
        $std = $this->equilizeParameters($std, $possible);
5679
        $identificador = '#396 <veicNovos> - ';
5680
        $veicNovos = $this->dom->createElement('veicNovos');
5681
        $this->dom->addChild(
5682
            $veicNovos,
5683
            'chassi',
5684
            $std->chassi,
5685
            true,
5686
            $identificador . 'Chassi do veículo '
5687
        );
5688
        $this->dom->addChild(
5689
            $veicNovos,
5690
            'cCor',
5691
            $std->cCor,
5692
            true,
5693
            $identificador . 'Cor do veículo '
5694
        );
5695
        $this->dom->addChild(
5696
            $veicNovos,
5697
            'xCor',
5698
            $std->xCor,
5699
            true,
5700
            $identificador . 'Descrição da cor '
5701
        );
5702
        $this->dom->addChild(
5703
            $veicNovos,
5704
            'cMod',
5705
            $std->cMod,
5706
            true,
5707
            $identificador . 'Código Marca Modelo '
5708
        );
5709
        $this->dom->addChild(
5710
            $veicNovos,
5711
            'vUnit',
5712
            $std->vUnit,
5713
            true,
5714
            $identificador . 'Valor Unitário do Veículo '
5715
        );
5716
        $this->dom->addChild(
5717
            $veicNovos,
5718
            'vFrete',
5719
            $this->conditionalNumberFormatting($std->vFrete),
5720
            true,
5721
            $identificador . 'Frete Unitário '
5722
        );
5723
        $this->veicNovos[] = $veicNovos;
5724
        return $veicNovos;
5725
    }
5726
5727
    /**
5728
     * Gera as tags para o elemento: "autXML" (Autorizados para download do XML)
5729
     * #396
5730
     * Nível: 1
5731
     * Os parâmetros para esta função são todos os elementos da tag "autXML"
5732
     *
5733
     * @return boolean
5734
     */
5735
    public function tagautXML($std)
5736
    {
5737
        $possible = [
5738
            'CNPJ',
5739
            'CPF'
5740
        ];
5741
        $std = $this->equilizeParameters($std, $possible);
5742
        $identificador = '#396 <autXML> - ';
5743
        $autXML = $this->dom->createElement('autXML');
5744
        if (isset($std->CNPJ) && $std->CNPJ != '') {
5745
            $this->dom->addChild(
5746
                $autXML,
5747
                'CNPJ',
5748
                $std->CNPJ,
5749
                true,
5750
                $identificador . 'CNPJ do Cliente Autorizado'
5751
            );
5752
        } elseif (isset($std->CPF) && $std->CPF != '') {
5753
            $this->dom->addChild(
5754
                $autXML,
5755
                'CPF',
5756
                $std->CPF,
5757
                true,
5758
                $identificador . 'CPF do Cliente Autorizado'
5759
            );
5760
        }
5761
        $this->autXML[] = $autXML;
5762
        return $autXML;
5763
    }
5764
5765
    /**
5766
     * #359
5767
     * tag CTe/infCTe/cobr (opcional)
5768
     * Depende de fat
5769
     */
5770
    protected function buildCobr()
5771
    {
5772
        if (empty($this->cobr)) {
5773
            $this->cobr = $this->dom->createElement("cobr");
5774
        }
5775
    }
5776
5777
    /**
5778
     * #360
5779
     * tag CTe/infCTe/cobr/fat (opcional)
5780
     * @param stdClass $std
5781
     * @return DOMElement
5782
     */
5783
    public function tagfat(stdClass $std)
5784
    {
5785
        $possible = [
5786
            'nFat',
5787
            'vOrig',
5788
            'vDesc',
5789
            'vLiq'
5790
        ];
5791
        $std = $this->equilizeParameters($std, $possible);
5792
        $this->buildCobr();
5793
        $fat = $this->dom->createElement("fat");
5794
        $this->dom->addChild(
5795
            $fat,
5796
            "nFat",
5797
            $std->nFat,
5798
            false,
5799
            "Número da Fatura"
5800
        );
5801
        $this->dom->addChild(
5802
            $fat,
5803
            "vOrig",
5804
            $this->conditionalNumberFormatting($std->vOrig),
5805
            false,
5806
            "Valor Original da Fatura"
5807
        );
5808
        if ($std->vDesc > 0) {
5809
            $this->dom->addChild(
5810
                $fat,
5811
                "vDesc",
5812
                $this->conditionalNumberFormatting($std->vDesc),
5813
                false,
5814
                "Valor do desconto"
5815
            );
5816
        }
5817
        $this->dom->addChild(
5818
            $fat,
5819
            "vLiq",
5820
            $this->conditionalNumberFormatting($std->vLiq),
5821
            false,
5822
            "Valor Líquido da Fatura"
5823
        );
5824
        $this->dom->appChild($this->cobr, $fat);
5825
        return $fat;
5826
    }
5827
5828
    /**
5829
     * #365
5830
     * tag CTe/infCTe/cobr/fat/dup (opcional)
5831
     * É necessário criar a tag fat antes de criar as duplicatas
5832
     * @param stdClass $std
5833
     * @return DOMElement
5834
     */
5835
    public function tagdup(stdClass $std)
5836
    {
5837
        $possible = [
5838
            'nDup',
5839
            'dVenc',
5840
            'vDup'
5841
        ];
5842
        $std = $this->equilizeParameters($std, $possible);
5843
        $this->buildCobr();
5844
        $dup = $this->dom->createElement("dup");
5845
        $this->dom->addChild(
5846
            $dup,
5847
            "nDup",
5848
            $std->nDup,
5849
            false,
5850
            "Número da Duplicata"
5851
        );
5852
        $this->dom->addChild(
5853
            $dup,
5854
            "dVenc",
5855
            $std->dVenc,
5856
            false,
5857
            "Data de vencimento"
5858
        );
5859
        $this->dom->addChild(
5860
            $dup,
5861
            "vDup",
5862
            $this->conditionalNumberFormatting($std->vDup),
5863
            true,
5864
            "Valor da duplicata"
5865
        );
5866
        $this->dom->appChild($this->cobr, $dup, 'Inclui duplicata na tag cobr');
5867
        return $dup;
5868
    }
5869
5870
    /**
5871
     * Informações do Responsável técnico
5872
     * tag CTe/infCte/infRespTec (opcional)
5873
     * @return DOMElement
5874
     * @throws RuntimeException
5875
     */
5876
    public function taginfRespTec(stdClass $std)
5877
    {
5878
        $possible = [
5879
            'CNPJ',
5880
            'xContato',
5881
            'email',
5882
            'fone',
5883
            'idCSRT',
5884
            'CSRT'
5885
        ];
5886
        $std = $this->equilizeParameters($std, $possible);
5887
        $infRespTec = $this->dom->createElement("infRespTec");
5888
        $this->dom->addChild(
5889
            $infRespTec,
5890
            "CNPJ",
5891
            $std->CNPJ,
5892
            true,
5893
            "Informar o CNPJ da pessoa jurídica responsável pelo sistema "
5894
            . "utilizado na emissão do documento fiscal eletrônico"
5895
        );
5896
        $this->dom->addChild(
5897
            $infRespTec,
5898
            "xContato",
5899
            $std->xContato,
5900
            true,
5901
            "Informar o nome da pessoa a ser contatada na empresa desenvolvedora "
5902
            . "do sistema utilizado na emissão do documento fiscal eletrônico"
5903
        );
5904
        $this->dom->addChild(
5905
            $infRespTec,
5906
            "email",
5907
            $std->email,
5908
            true,
5909
            "Informar o e-mail da pessoa a ser contatada na empresa "
5910
            . "desenvolvedora do sistema."
5911
        );
5912
        $this->dom->addChild(
5913
            $infRespTec,
5914
            "fone",
5915
            $std->fone,
5916
            true,
5917
            "Informar o telefone da pessoa a ser contatada na empresa "
5918
            . "desenvolvedora do sistema."
5919
        );
5920
        if (!empty($std->CSRT) && !empty($std->idCSRT)) {
5921
            $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...
5922
            $this->dom->addChild(
5923
                $infRespTec,
5924
                "idCSRT",
5925
                $std->idCSRT,
5926
                true,
5927
                "Identificador do CSRT utilizado para montar o hash do CSRT"
5928
            );
5929
            $this->dom->addChild(
5930
                $infRespTec,
5931
                "hashCSRT",
5932
                $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...
5933
                true,
5934
                "hash do CSRT"
5935
            );
5936
        }
5937
        $this->infRespTec = $infRespTec;
5938
        return $infRespTec;
5939
    }
5940
5941
    protected function checkCTeKey(Dom $dom)
5942
    {
5943
        $infCTe = $dom->getElementsByTagName("infCte")->item(0);
5944
        $ide = $dom->getElementsByTagName("ide")->item(0);
5945
        $emit = $dom->getElementsByTagName("emit")->item(0);
5946
        $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue;
5947
        $dhEmi = $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue;
5948
        $cnpj = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
5949
        $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue;
5950
        $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
5951
        $nNF = $ide->getElementsByTagName('nCT')->item(0)->nodeValue;
5952
        $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue;
5953
        $cCT = $ide->getElementsByTagName('cCT')->item(0)->nodeValue;
5954
        $chave = str_replace('CTe', '', $infCTe->getAttribute("Id"));
5955
5956
        $dt = new \DateTime($dhEmi);
5957
5958
        $chaveMontada = Keys::build(
5959
            $cUF,
5960
            $dt->format('y'),
5961
            $dt->format('m'),
5962
            $cnpj,
5963
            $mod,
5964
            $serie,
5965
            $nNF,
5966
            $tpEmis,
5967
            $cCT
5968
        );
5969
        //caso a chave contida no CTe esteja errada
5970
        //substituir a chave
5971
        if ($chaveMontada != $chave) {
5972
            $ide->getElementsByTagName('cDV')->item(0)->nodeValue = substr($chaveMontada, -1);
5973
            $infCTe = $dom->getElementsByTagName("infCte")->item(0);
5974
            $infCTe->setAttribute("Id", "CTe" . $chaveMontada);
5975
            $this->chCTe = $chaveMontada;
5976
        }
5977
    }
5978
5979
    /**
5980
     * Retorna os erros detectados
5981
     * @return array
5982
     */
5983
    public function getErrors()
5984
    {
5985
        return $this->errors;
5986
    }
5987
5988
    /**
5989
     * Includes missing or unsupported properties in stdClass
5990
     * Replace all unsuported chars
5991
     *
5992
     * @param stdClass $std
5993
     * @param array $possible
5994
     * @return stdClass
5995
     */
5996
    private function equilizeParameters(stdClass $std, $possible)
5997
    {
5998
        return Strings::equilizeParameters($std, $possible, $this->replaceAccentedChars);
5999
    }
6000
    
6001
        /**
6002
     * Formatação numerica condicional
6003
     * @param string|float|int|null $value
6004
     * @param int $decimal
6005
     * @return string
6006
     */
6007
    protected function conditionalNumberFormatting($value = null, $decimal = 2)
6008
    {
6009
        if (is_numeric($value)) {
6010
            return number_format($value, $decimal, '.', '');
6011
        }
6012
        return null;
6013
    }
6014
6015
    /*
6016
    protected function conditionalNumberFormatting($value = null, array $decimal): string
6017
    {
6018
        if (!is_numeric($value)) {
6019
            return null;
6020
        }
6021
        $num = (float) $value;
6022
        $l = explode('.', $num);
6023
        $declen = 0;
6024
        if (!empty($l[1])) {
6025
            $declen = strlen($l[1]);
6026
        }
6027
        if ($declen < $decimal[0]) {
6028
            return number_format($num, $decimal[0], '.', '');
6029
        } elseif ($declen > $decimal[1]) {
6030
            return number_format($num, $decimal[1], '.', '');
6031
        }
6032
        return $num;
6033
    }*/
6034
}
6035