Passed
Push — master ( 6509d4...732bfd )
by
unknown
01:04
created

Make::tagautXML()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 17
cp 0
rs 9.2088
c 0
b 0
f 0
cc 5
nc 3
nop 1
crap 30
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 NFePHP\Common\Keys;
17
use NFePHP\Common\DOMImproved as Dom;
18
use NFePHP\Common\Strings;
19
use stdClass;
20
use RuntimeException;
21
use DOMElement;
22
use DateTime;
23
24
class Make
25
{
26
    /**
27
     * @var array
28
     */
29
    public $erros = [];
30
    
31
    /**
32
     * versao
33
     * numero da versão do xml da CTe
34
     * @var string
35
     */
36
    public $versao = '3.00';
37
    /**
38
     * mod
39
     * modelo da CTe 57
40
     * @var integer
41
     */
42
    public $mod = 57;
43
    /**
44
     * chave da MDFe
45
     * @var string
46
     */
47
    public $chCTe = '';
48
    /**
49
     * xml
50
     * String com o xml do documento fiscal montado
51
     * @var string
52
     */
53
    public $xml = '';
54
    /**
55
     * dom
56
     * Variável onde será montado o xml do documento fiscal
57
     * @var \NFePHP\Common\Dom\Dom
58
     */
59
    public $dom;
60
    /**
61
     * tpAmb
62
     * tipo de ambiente
63
     * @var string
64
     */
65
    public $tpAmb = '2';
66
    /**
67
     * Modal do Cte
68
     * @var integer
69
     */
70
    private $modal = 0;
71
    /**
72
     * Tag CTe
73
     * @var \DOMNode
74
     */
75
    private $CTe = '';
76
    /**
77
     * Informações do CT-e
78
     * @var \DOMNode
79
     */
80
    private $infCte = '';
81
    /**
82
     * Identificação do CT-e
83
     * @var \DOMNode
84
     */
85
    private $ide = '';
86
    /**
87
     * Percurso do CT-e OS
88
     * @var \DOMNode
89
     */
90
    private $infPercurso = [];
91
    /**
92
     * Tipo do Serviço
93
     * @var integer
94
     */
95
    private $tpServ = 0;
96
    /**
97
     * Indicador do "papel" do tomador do serviço no CT-e
98
     * @var \DOMNode
99
     */
100
    private $toma3 = '';
101
    /**
102
     * Indicador do "papel" do tomador do serviço no CT-e
103
     * @var \DOMNode
104
     */
105
    private $toma4 = '';
106
    /**
107
     * Indicador do "papel" do tomador do serviço no CT-e OS
108
     * @var \DOMNode
109
     */
110
    private $toma = '';
111
    /**
112
     * Dados do endereço
113
     * @var \DOMNode
114
     */
115
    private $enderToma = '';
116
    /**
117
     * Dados complementares do CT-e para fins operacionais ou comerciais
118
     * @var \DOMNode
119
     */
120
    private $compl = '';
121
    /**
122
     * Previsão do fluxo da carga
123
     * @var \DOMNode
124
     */
125
    private $fluxo = '';
126
    /**
127
     * Passagem
128
     * @var array
129
     */
130
    private $pass = array();
131
    /**
132
     * Informações ref. a previsão de entrega
133
     * @var \DOMNode
134
     */
135
    private $entrega = '';
136
    /**
137
     * Entrega sem data definida
138
     * @var \DOMNode
139
     */
140
    private $semData = '';
141
    /**
142
     * Entrega com data definida
143
     * @var \DOMNode
144
     */
145
    private $comData = '';
146
    /**
147
     * Entrega no período definido
148
     * @var \DOMNode
149
     */
150
    private $noPeriodo = '';
151
    /**
152
     * Entrega sem hora definida
153
     * @var \DOMNode
154
     */
155
    private $semHora = '';
156
    /**
157
     * Entrega com hora definida
158
     * @var \DOMNode
159
     */
160
    private $comHora = '';
161
    /**
162
     * Entrega no intervalo de horário definido
163
     * @var \DOMNode
164
     */
165
    private $noInter = '';
166
    /**
167
     * Campo de uso livre do contribuinte
168
     * @var array
169
     */
170
    private $obsCont = array();
171
    /**
172
     * Campo de uso livre do contribuinte
173
     * @var array
174
     */
175
    private $obsFisco = array();
176
    /**
177
     * Identificação do Emitente do CT-e
178
     * @var \DOMNode
179
     */
180
    private $emit = '';
181
    /**
182
     * Endereço do emitente
183
     * @var \DOMNode
184
     */
185
    private $enderEmit = '';
186
    /**
187
     * Informações do Remetente das mercadorias transportadas pelo CT-e
188
     * @var \DOMNode
189
     */
190
    private $rem = '';
191
    /**
192
     * Dados do endereço
193
     * @var \DOMNode
194
     */
195
    private $enderReme = '';
196
    /**
197
     * Informações do Expedidor da Carga
198
     * @var \DOMNode
199
     */
200
    private $exped = '';
201
    /**
202
     * Dados do endereço
203
     * @var \DOMNode
204
     */
205
    private $enderExped = '';
206
    /**
207
     * Informações do Recebedor da Carga
208
     * @var \DOMNode
209
     */
210
    private $receb = '';
211
    /**
212
     * Dados do endereço
213
     * @var \DOMNode
214
     */
215
    private $enderReceb = '';
216
    /**
217
     * Informações do Destinatário do CT-e
218
     * @var \DOMNode
219
     */
220
    private $dest = '';
221
    /**
222
     * Dados do endereço
223
     * @var \DOMNode
224
     */
225
    private $enderDest = '';
226
    /**
227
     * Valores da Prestação de Serviço
228
     * @var \DOMNode
229
     */
230
    private $vPrest = '';
231
    /**
232
     * Componentes do Valor da Prestação
233
     * @var array
234
     */
235
    private $comp = array();
236
    /**
237
     * Informações relativas aos Impostos
238
     * @var \DOMNode
239
     */
240
    private $imp = '';
241
    /**
242
     * Informações relativas ao ICMS
243
     * @var \DOMNode
244
     */
245
    private $ICMS = '';
0 ignored issues
show
Unused Code introduced by
The property $ICMS is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
246
    /**
247
     * Prestação sujeito à tributação normal do ICMS
248
     * @var \DOMNode
249
     */
250
    private $ICMS00 = '';
0 ignored issues
show
Unused Code introduced by
The property $ICMS00 is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
251
    /**
252
     * Prestação sujeito à tributação com redução de BC do ICMS
253
     * @var \DOMNode
254
     */
255
    private $ICMS20 = '';
0 ignored issues
show
Unused Code introduced by
The property $ICMS20 is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
256
    /**
257
     * ICMS Isento, não Tributado ou diferido
258
     * @var \DOMNode
259
     */
260
    private $ICMS45 = '';
0 ignored issues
show
Unused Code introduced by
The property $ICMS45 is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
261
    /**
262
     * Tributação pelo ICMS60 - ICMS cobrado por substituição tributária.
263
     * Responsabilidade do recolhimento do ICMS atribuído ao tomador ou 3º por ST
264
     * @var \DOMNode
265
     */
266
    private $ICMS60 = '';
0 ignored issues
show
Unused Code introduced by
The property $ICMS60 is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
267
    /**
268
     * ICMS Outros
269
     * @var \DOMNode
270
     */
271
    private $ICMS90 = '';
0 ignored issues
show
Unused Code introduced by
The property $ICMS90 is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
272
    /**
273
     * ICMS devido à UF de origem da prestação, quando diferente da UF do emitente
274
     * @var \DOMNode
275
     */
276
    private $ICMSOutraUF = '';
0 ignored issues
show
Unused Code introduced by
The property $ICMSOutraUF is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
277
    /**
278
     * Simples Nacional
279
     * @var \DOMNode
280
     */
281
    private $ICMSSN = '';
0 ignored issues
show
Unused Code introduced by
The property $ICMSSN is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
282
    /**
283
     * Observações adicionais da CT-e
284
     * @var string
285
     */
286
    private $xObs = '';
0 ignored issues
show
Unused Code introduced by
The property $xObs is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
287
    /**
288
     * Grupo de informações do CT-e Normal e Substituto
289
     * @var \DOMNode
290
     */
291
    private $infCTeNorm = '';
292
    /**
293
     * Informações da Carga do CT-e
294
     * @var \DOMNode
295
     */
296
    private $infCarga = '';
297
    /**
298
     * Informações da Prestação do Serviço
299
     * @var \DOMNode
300
     */
301
    private $infServico = '';
302
    /**
303
     * Informações de quantidades da Carga do CT-e
304
     * @var \DOMNode
305
     */
306
    private $infQ = array();
307
    /**
308
     * Informações dos documentos transportados pelo CT-e Opcional para Redespacho Intermediario
309
     * e Serviço vinculado a multimodal.
310
     * @var \DOMNode
311
     */
312
    private $infDoc = array();
313
    /**
314
     * Informações das NF
315
     * @var array
316
     */
317
    private $infNF = array();
318
    /**
319
     * Informações das NF-e
320
     * @var array
321
     */
322
    private $infNFe = array();
323
    /**
324
     * Informações dos demais documentos
325
     * @var array
326
     */
327
    private $infOutros = array();
328
    /**
329
     * Informações dos demais documentos
330
     * @var array
331
     */
332
    private $infDocRef = array();
333
    /**
334
     * Informações das Unidades de Transporte (Carreta/Reboque/Vagão)
335
     * @var array
336
     */
337
    private $infUnidTransp = array();
0 ignored issues
show
Unused Code introduced by
The property $infUnidTransp is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
338
    /**
339
     * Lacres das Unidades de Transporte
340
     * @var array
341
     */
342
    private $lacUnidTransp = array();
0 ignored issues
show
Unused Code introduced by
The property $lacUnidTransp is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
343
    /**
344
     * Informações das Unidades de Carga (Containeres/ULD/Outros)
345
     * @var array
346
     */
347
    private $infUnidCarga = array();
0 ignored issues
show
Unused Code introduced by
The property $infUnidCarga is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
348
    /**
349
     * Lacres das Unidades de Carga
350
     * @var array
351
     */
352
    private $lacUnidCarga = array();
0 ignored issues
show
Unused Code introduced by
The property $lacUnidCarga is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
353
    /**
354
     * Documentos de Transporte Anterior
355
     * @var \DOMNode
356
     */
357
    private $docAnt = array();
358
    /**
359
     * Emissor do documento anterior
360
     * @var array
361
     */
362
    private $emiDocAnt = array();
363
    /**
364
     * Informações de identificação dos documentos de Transporte Anterior
365
     * @var array
366
     */
367
    private $idDocAnt = array();
368
    /**
369
     * Documentos de transporte anterior em papel
370
     * @var array
371
     */
372
    private $idDocAntPap = array();
0 ignored issues
show
Unused Code introduced by
The property $idDocAntPap is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
373
    /**
374
     * Documentos de transporte anterior eletrônicos
375
     * @var array
376
     */
377
    private $idDocAntEle = array();
378
    /**
379
     * Informações de Seguro da Carga
380
     * @var array
381
     */
382
    private $seg = array();
383
    /**
384
     * Informações do modal
385
     * @var \DOMNode
386
     */
387
    private $infModal = '';
388
    /**
389
     * Preenchido quando for transporte de produtos classificados pela ONU como perigosos.
390
     * @var array
391
     */
392
    private $peri = array();
0 ignored issues
show
Unused Code introduced by
The property $peri is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
393
    /**
394
     * informações dos veículos transportados
395
     * @var array
396
     */
397
    private $veicNovos = array();
0 ignored issues
show
Unused Code introduced by
The property $veicNovos is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
398
    /**
399
     * Dados da cobrança do CT-e
400
     * @var \DOMNode
401
     */
402
    private $cobr = '';
0 ignored issues
show
Unused Code introduced by
The property $cobr is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
403
    /**
404
     * Dados da fatura
405
     * @var \DOMNode
406
     */
407
    private $fat = '';
0 ignored issues
show
Unused Code introduced by
The property $fat is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
408
    /**
409
     * Dados das duplicatas
410
     * @var array
411
     */
412
    private $dup = array();
0 ignored issues
show
Unused Code introduced by
The property $dup is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
413
    /**
414
     * Informações do CT-e de substituição
415
     * @var \DOMNode
416
     */
417
    private $infCteSub = '';
418
    /**
419
     * Tomador é contribuinte do ICMS
420
     * @var \DOMNode
421
     */
422
    private $tomaICMS = '';
423
    /**
424
     * Informação da NFe emitida pelo Tomador
425
     * @var \DOMNode
426
     */
427
    private $refNFe = '';
0 ignored issues
show
Unused Code introduced by
The property $refNFe is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
428
    /**
429
     * Informação da NF ou CT emitido pelo Tomador
430
     * @var \DOMNode
431
     */
432
    private $refNF = '';
433
    /**
434
     * Informação do CTe emitido pelo Tomador
435
     * @var \DOMNode
436
     */
437
    private $refCte = '';
0 ignored issues
show
Unused Code introduced by
The property $refCte is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
438
    /**
439
     * Informação da NF ou CT emitido pelo Tomador
440
     * @var \DOMNode
441
     */
442
    private $infCteComp = '';
443
    /**
444
     * Detalhamento do CT-e do tipo Anulação
445
     * @var \DOMNode
446
     */
447
    private $infCteAnu = '';
448
    /**
449
     * Informações do modal Rodoviário
450
     * @var \DOMNode
451
     */
452
    private $rodo = '';
453
    /**
454
     * Informações do modal Aéreo
455
     * @var \DOMNode
456
     */
457
    private $aereo = '';
458
    /**
459
     * Informações do modal Aéreo -> Dados da Carga
460
     * @var \DOMNode
461
     */
462
    private $natCarga = '';
463
    /**
464
     * Informações do modal Aéreo -> Tarifas
465
     * @var \DOMNode
466
     */
467
    private $tarifa = '';
468
    /**
469
     * Ordens de Coleta associados
470
     * @var array
471
     */
472
    private $occ = array();
0 ignored issues
show
Unused Code introduced by
The property $occ is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
473
    /**
474
     * @var \DOMNode
475
     */
476
    private $emiOcc = array();
0 ignored issues
show
Unused Code introduced by
The property $emiOcc is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
477
    /**
478
     * Informações de Vale Pedágio
479
     * @var array
480
     */
481
    private $valePed = array();
0 ignored issues
show
Unused Code introduced by
The property $valePed is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
482
    /**
483
     * Dados dos Veículos
484
     * @var array
485
     */
486
    private $veic = array();
487
    /**
488
     * Proprietários do Veículo. Só preenchido quando o veículo não pertencer à empresa emitente do CT-e
489
     * @var array
490
     */
491
    private $prop = array();
492
    /**
493
     * Dados dos Veículos
494
     * @var array
495
     */
496
    private $lacRodo = array();
0 ignored issues
show
Unused Code introduced by
The property $lacRodo is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
497
    /**
498
     * Informações do(s) Motorista(s)
499
     * @var array
500
     */
501
    private $moto = array();
0 ignored issues
show
Unused Code introduced by
The property $moto is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
502
    /**
503
     * Autorizados para download do XML do DF-e
504
     * @var array
505
     */
506
    private $autXML = array();
507
    
508 1
    public function __construct()
509
    {
510 1
        $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...
511 1
        $this->dom->preserveWhiteSpace = false;
512 1
        $this->dom->formatOutput = false;
513 1
    }
514
    
515
    /**
516
     * Returns xml string and assembly it is necessary
517
     * @return string
518
     */
519
    public function getXML()
520
    {
521
        if (empty($this->xml)) {
522
            $this->montaCTe();
523
        }
524
        return $this->xml;
525
    }
526
    
527
    /**
528
     * Retorns the key number of NFe (44 digits)
529
     * @return string
530
     */
531
    public function getChave()
532
    {
533
        return $this->chCTe;
534
    }
535
    
536
    /**
537
     * Returns the model of CTe 57 or 67
538
     * @return int
539
     */
540
    public function getModelo()
541
    {
542
        return $this->mod;
543
    }
544
    
545
    /**
546
     * Call method of xml assembly. For compatibility only.
547
     * @return boolean
548
     */
549
    public function montaCTe()
550
    {
551
        return $this->monta();
552
    }
553
    
554
    /**
555
     * Monta o arquivo XML usando as tag's já preenchidas
556
     *
557
     * @return bool
558
     */
559
    public function monta()
560
    {
561
        if (count($this->erros) > 0) {
562
            return false;
563
        }
564
        if ($this->mod == 57) {
565
            $this->buildCTe();
566
        } else {
567
            return $this->montaCTeOS();
568
        }
569
        if ($this->toma3 != '') {
570
            $this->dom->appChild($this->ide, $this->toma3, 'Falta tag "ide"');
571
        } else {
572
            $this->dom->appChild($this->ide, $this->toma4, 'Falta tag "ide"');
573
        }
574
        $this->dom->appChild($this->infCte, $this->ide, 'Falta tag "infCte"');
575
        if ($this->semData != '') {
576
            $this->tagEntrega();
577
            $this->dom->appChild($this->entrega, $this->semData, 'Falta tag "Entrega"');
578
        }
579
        if ($this->comData != '') {
580
            $this->tagEntrega();
581
            $this->dom->appChild($this->entrega, $this->comData, 'Falta tag "Entrega"');
582
        }
583
        if ($this->noPeriodo != '') {
584
            $this->tagEntrega();
585
            $this->dom->appChild($this->entrega, $this->noPeriodo, 'Falta tag "Entrega"');
586
        }
587
        if ($this->semHora != '') {
588
            $this->tagEntrega();
589
            $this->dom->appChild($this->entrega, $this->semHora, 'Falta tag "Entrega"');
590
        }
591
        if ($this->comHora != '') {
592
            $this->tagEntrega();
593
            $this->dom->appChild($this->entrega, $this->comHora, 'Falta tag "Entrega"');
594
        }
595
        if ($this->noInter != '') {
596
            $this->tagEntrega();
597
            $this->dom->appChild($this->entrega, $this->noInter, 'Falta tag "Entrega"');
598
        }
599
        if ($this->compl != '') {
600
            if ($this->fluxo != '') {
601
                foreach ($this->pass as $pass) {
602
                    $this->dom->appChild($this->fluxo, $pass, 'Falta tag "fluxo"');
603
                }
604
                $this->dom->appChild($this->compl, $this->fluxo, 'Falta tag "infCte"');
605
            }
606
            foreach ($this->obsCont as $obsCont) {
607
                $this->dom->appChild($this->compl, $obsCont, 'Falta tag "compl"');
608
            }
609
            foreach ($this->obsFisco as $obsFisco) {
610
                $this->dom->appChild($this->compl, $obsFisco, 'Falta tag "compl"');
611
            }
612
            $this->dom->appChild($this->infCte, $this->compl, 'Falta tag "infCte"');
613
        }
614
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "emit"');
615
        $this->dom->appChild($this->infCte, $this->emit, 'Falta tag "infCte"');
616
        if ($this->rem != '') {
617
            $this->dom->appChild($this->infCte, $this->rem, 'Falta tag "infCte"');
618
        }
619
        if ($this->exped != '') {
620
            $this->dom->appChild($this->infCte, $this->exped, 'Falta tag "infCte"');
621
        }
622
        if ($this->receb != '') {
623
            $this->dom->appChild($this->infCte, $this->receb, 'Falta tag "infCte"');
624
        }
625
        if ($this->dest != '') {
626
            $this->dom->appChild($this->infCte, $this->dest, 'Falta tag "infCte"');
627
        }
628
        foreach ($this->comp as $comp) {
629
            $this->dom->appChild($this->vPrest, $comp, 'Falta tag "vPrest"');
630
        }
631
        $this->dom->appChild($this->infCte, $this->vPrest, 'Falta tag "infCte"');
632
        $this->dom->appChild($this->infCte, $this->imp, 'Falta tag "imp"');
633
        if ($this->infCteComp != '') { // Caso seja um CTe tipo complemento de valores
634
            $this->dom->appChild($this->infCte, $this->infCteComp, 'Falta tag "infCteComp"');
635
        }
636
        if ($this->infCteAnu != '') { // Caso seja um CTe tipo anulação
637
            $this->dom->appChild($this->infCte, $this->infCteAnu, 'Falta tag "infCteAnu"');
638
        }
639
        if ($this->infCTeNorm != '') { // Caso seja um CTe tipo normal
640
            $this->dom->appChild($this->infCte, $this->infCTeNorm, 'Falta tag "infCTeNorm"');
641
            $this->dom->appChild($this->infCTeNorm, $this->infCarga, 'Falta tag "infCarga"');
642
            foreach ($this->infQ as $infQ) {
643
                if (end($this->infQ) == $infQ) {
644
                    $this->infCarga->insertBefore($infQ, $this->infCarga->getElementsByTagName("vCargaAverb")->item(0));
645
                } else {
646
                    $this->dom->appChild($this->infCarga, $infQ, 'Falta tag "infQ"');
647
                }
648
            }
649
650
            $this->dom->appChild($this->infCTeNorm, $this->infDoc, 'Falta tag "infDoc"');
651
            foreach ($this->infNF as $infNF) {
652
                $this->dom->appChild($this->infDoc, $infNF, 'Falta tag "infNF"');
653
            }
654
            foreach ($this->infNFe as $infNFe) {
655
                $this->dom->appChild($this->infDoc, $infNFe, 'Falta tag "infNFe"');
656
            }
657
            foreach ($this->infOutros as $infOutros) {
658
                $this->dom->appChild($this->infDoc, $infOutros, 'Falta tag "infOutros"');
659
            }
660
661
            if ($this->idDocAntEle != []) { //Caso tenha CT-es Anteriores viculados
662
                $this->dom->appChild($this->infCTeNorm, $this->docAnt, 'Falta tag "docAnt"');
663
664
                foreach ($this->emiDocAnt as $emiDocAnt) {
665
                    $this->dom->appChild($this->docAnt, $emiDocAnt, 'Falta tag "emiDocAnt"');
666
                    $this->dom->appChild($emiDocAnt, $this->idDocAnt, 'Falta tag "idDocAnt"');
667
668
                    foreach ($this->idDocAntEle as $idDocAntEle) {
669
                        $this->dom->appChild($this->idDocAnt, $idDocAntEle, 'Falta tag "emiDocAnt"');
670
                    }
671
                }
672
            }
673
674
            foreach ($this->seg as $seg) {
675
                $this->dom->appChild($this->infCTeNorm, $seg, 'Falta tag "seg"');
676
            }
677
678
            $this->dom->appChild($this->infCTeNorm, $this->infModal, 'Falta tag "infModal"');
679
            if ($this->modal=='01') {
680
                $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "rodo"');
681
                foreach ($this->veic as $veic) {
682
                    $this->dom->appChild($this->rodo, $veic, 'Falta tag "veic"');
683
                }
684
            } elseif ($this->modal=='02') {
685
                $this->dom->appChild($this->infModal, $this->aereo, 'Falta tag "aereo"');
686
            } else {
687
                throw new Exception('Modal não informado ou não suportado.');
688
            }
689
        }
690
691
        foreach ($this->autXML as $autXML) {
692
            $this->dom->appChild($this->infCte, $autXML, 'Falta tag "autXML"');
693
        }
694
695
        //[1] tag infCTe
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
696
        $this->dom->appChild($this->CTe, $this->infCte, 'Falta tag "CTe"');
697
        //[0] tag CTe
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
698
        $this->dom->appendChild($this->CTe);
699
        
700
        // testa da chave
701
        $this->checkCTeKey($this->dom);
702
        $this->xml = $this->dom->saveXML();
703
        return true;
704
    }
705
706
    /**
707
     * Monta o arquivo XML usando as tag's já preenchidas
708
     *
709
     * @return bool
710
     */
711
    public function montaCTeOS()
712
    {
713
        if (count($this->erros) > 0) {
714
            return false;
715
        }
716
        $this->buildCTeOS();
717
718
        if ($this->infPercurso != '') {
719
            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...
720
                $this->dom->appChild($this->ide, $perc, 'Falta tag "infPercurso"');
721
            }
722
        }
723
        $this->dom->appChild($this->infCte, $this->ide, 'Falta tag "infCte"');
724
        if ($this->compl != '') {
725
            $this->dom->appChild($this->infCte, $this->compl, 'Falta tag "infCte"');
726
        }
727
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "emit"');
728
        $this->dom->appChild($this->infCte, $this->emit, 'Falta tag "infCte"');
729
730
        if ($this->toma != '') {
731
            //$this->dom->appChild($this->toma, $this->enderToma, 'Falta tag "toma"');
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
732
            $this->dom->appChild($this->infCte, $this->toma, 'Falta tag "infCte"');
733
        }
734
735
        foreach ($this->comp as $comp) {
736
            $this->dom->appChild($this->vPrest, $comp, 'Falta tag "vPrest"');
737
        }
738
        $this->dom->appChild($this->infCte, $this->vPrest, 'Falta tag "infCte"');
739
        $this->dom->appChild($this->infCte, $this->imp, 'Falta tag "imp"');
740
        if ($this->infCteComp != '') { // Caso seja um CTe tipo complemento de valores
741
            $this->dom->appChild($this->infCte, $this->infCteComp, 'Falta tag "infCteComp"');
742
        } elseif ($this->infCteAnu != '') { // Caso seja um CTe tipo anulação
743
            $this->dom->appChild($this->infCte, $this->infCteAnu, 'Falta tag "infCteAnu"');
744
        } elseif ($this->infCTeNorm != '') { // Caso seja um CTe tipo normal
745
            $this->dom->appChild($this->infCte, $this->infCTeNorm, 'Falta tag "infCTeNorm"');
746
            $this->dom->appChild($this->infCTeNorm, $this->infServico, 'Falta tag "infServico"');
747
748
            foreach ($this->infDocRef as $infDocRef) {
749
                $this->dom->appChild($this->infCTeNorm, $infDocRef, 'Falta tag "infDocRef"');
750
            }
751
752
            foreach ($this->seg as $seg) {
753
                $this->dom->appChild($this->infCTeNorm, $seg, 'Falta tag "seg"');
754
            }
755
756
            if ($this->infModal != '') {
757
                $this->dom->appChild($this->infCTeNorm, $this->infModal, 'Falta tag "infModal"');
758
                $this->dom->appChild($this->rodo, $this->veic, 'Falta tag "veic"');
759
                $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "rodo"');
760
            }
761
        }
762
        
763
        $this->dom->appChild($this->CTe, $this->infCte, 'Falta tag "CTe"');
764
        //$this->dom->appChild($this->dom, $this->CTe, 'Falta tag "DOMDocument"');
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
765
        $this->dom->appendChild($this->CTe);
766
        
767
        // testa da chave
768
        $this->checkCTeKey($this->dom);
769
        $this->xml = $this->dom->saveXML();
770
        return true;
771
    }
772
773
    /**
774
     * Gera o grupo básico: Informações do CT-e
775
     * #1
776
     * Nível: 0
777
     * @param  stdClass $std
778
     * @return \DOMElement
779
     */
780 1
    public function taginfCTe($std)
781
    {
782 1
        $chave = preg_replace('/[^0-9]/', '', $std->Id);
783 1
        $this->infCte = $this->dom->createElement('infCte');
784 1
        $this->infCte->setAttribute('Id', 'CTe' . $chave);
785 1
        $this->infCte->setAttribute('versao', $std->versao);
786 1
        return $this->infCte;
787
    }
788
789
    /**
790
     * Gera as tags para o elemento: Identificação do CT-e
791
     * #4
792
     * Nível: 1
793
     * @param  stdClass $std
794
     * @return DOMElement|\DOMNode
795
     */
796
    public function tagide($std)
797
    {
798
        $this->tpAmb = $std->tpAmb;
799
        $this->mod = $std->mod;
800
        $identificador = '#4 <ide> - ';
801
        $this->ide = $this->dom->createElement('ide');
802
        $this->dom->addChild(
803
            $this->ide,
804
            'cUF',
805
            $std->cUF,
806
            true,
807
            $identificador . 'Código da UF do emitente do CT-e'
808
        );
809
        $this->dom->addChild(
810
            $this->ide,
811
            'cCT',
812
            str_pad($std->cCT, 8, '0', STR_PAD_LEFT),
813
            true,
814
            $identificador . 'Código numérico que compõe a Chave de Acesso'
815
        );
816
        $this->dom->addChild(
817
            $this->ide,
818
            'CFOP',
819
            $std->CFOP,
820
            true,
821
            $identificador . 'Código Fiscal de Operações e Prestações'
822
        );
823
        $this->dom->addChild(
824
            $this->ide,
825
            'natOp',
826
            Strings::replaceSpecialsChars(substr(trim($std->natOp), 0, 60)),
827
            true,
828
            $identificador . 'Natureza da Operação'
829
        );
830
        $this->dom->addChild(
831
            $this->ide,
832
            'mod',
833
            $std->mod,
834
            true,
835
            $identificador . 'Modelo do documento fiscal'
836
        );
837
        $this->dom->addChild(
838
            $this->ide,
839
            'serie',
840
            $std->serie,
841
            true,
842
            $identificador . 'Série do CT-e'
843
        );
844
        $this->dom->addChild(
845
            $this->ide,
846
            'nCT',
847
            $std->nCT,
848
            true,
849
            $identificador . 'Número do CT-e'
850
        );
851
        $this->dom->addChild(
852
            $this->ide,
853
            'dhEmi',
854
            $std->dhEmi,
855
            true,
856
            $identificador . 'Data e hora de emissão do CT-e'
857
        );
858
        $this->dom->addChild(
859
            $this->ide,
860
            'tpImp',
861
            $std->tpImp,
862
            true,
863
            $identificador . 'Formato de impressão do DACTE'
864
        );
865
        $this->dom->addChild(
866
            $this->ide,
867
            'tpEmis',
868
            $std->tpEmis,
869
            true,
870
            $identificador . 'Forma de emissão do CT-e'
871
        );
872
        $this->dom->addChild(
873
            $this->ide,
874
            'cDV',
875
            $std->cDV,
876
            true,
877
            $identificador . 'Digito Verificador da chave de acesso do CT-e'
878
        );
879
        $this->dom->addChild(
880
            $this->ide,
881
            'tpAmb',
882
            $std->tpAmb,
883
            true,
884
            $identificador . 'Tipo do Ambiente'
885
        );
886
        $this->dom->addChild(
887
            $this->ide,
888
            'tpCTe',
889
            $std->tpCTe,
890
            true,
891
            $identificador . 'Tipo do CT-e'
892
        );
893
        $this->dom->addChild(
894
            $this->ide,
895
            'procEmi',
896
            $std->procEmi,
897
            true,
898
            $identificador . 'Identificador do processo de emissão do CT-e'
899
        );
900
        $this->dom->addChild(
901
            $this->ide,
902
            'verProc',
903
            $std->verProc,
904
            true,
905
            $identificador . 'Versão do processo de emissão'
906
        );
907
        $this->dom->addChild(
908
            $this->ide,
909
            'indGlobalizado',
910
            $std->indGlobalizado,
911
            false,
912
            $identificador . 'Indicador de CT-e Globalizado'
913
        );
914
        $this->dom->addChild(
915
            $this->ide,
916
            'cMunEnv',
917
            $std->cMunEnv,
918
            true,
919
            $identificador . 'Código do Município de envio do CT-e (de onde o documento foi transmitido)'
920
        );
921
        $this->dom->addChild(
922
            $this->ide,
923
            'xMunEnv',
924
            $std->xMunEnv,
925
            true,
926
            $identificador . 'Nome do Município de envio do CT-e (de onde o documento foi transmitido)'
927
        );
928
        $this->dom->addChild(
929
            $this->ide,
930
            'UFEnv',
931
            $std->UFEnv,
932
            true,
933
            $identificador . 'Sigla da UF de envio do CT-e (de onde o documento foi transmitido)'
934
        );
935
        $this->dom->addChild(
936
            $this->ide,
937
            'modal',
938
            $std->modal,
939
            true,
940
            $identificador . 'Modal'
941
        );
942
        $this->modal = $std->modal;
943
        $this->dom->addChild(
944
            $this->ide,
945
            'tpServ',
946
            $std->tpServ,
947
            true,
948
            $identificador . 'Tipo do Serviço'
949
        );
950
        $this->dom->addChild(
951
            $this->ide,
952
            'cMunIni',
953
            $std->cMunIni,
954
            true,
955
            $identificador . 'Nome do Município do início da prestação'
956
        );
957
        $this->dom->addChild(
958
            $this->ide,
959
            'xMunIni',
960
            $std->xMunIni,
961
            true,
962
            $identificador . 'Nome do Município do início da prestação'
963
        );
964
        $this->dom->addChild(
965
            $this->ide,
966
            'UFIni',
967
            $std->UFIni,
968
            true,
969
            $identificador . 'UF do início da prestação'
970
        );
971
        $this->dom->addChild(
972
            $this->ide,
973
            'cMunFim',
974
            $std->cMunFim,
975
            true,
976
            $identificador . 'Código do Município de término da prestação'
977
        );
978
        $this->dom->addChild(
979
            $this->ide,
980
            'xMunFim',
981
            $std->xMunFim,
982
            true,
983
            $identificador . 'Nome do Município do término da prestação'
984
        );
985
        $this->dom->addChild(
986
            $this->ide,
987
            'UFFim',
988
            $std->UFFim,
989
            true,
990
            $identificador . 'UF do término da prestação'
991
        );
992
        $this->dom->addChild(
993
            $this->ide,
994
            'retira',
995
            $std->retira,
996
            true,
997
            $identificador . 'Indicador se o Recebedor retira no Aeroporto, Filial, Porto ou Estação de Destino'
998
        );
999
        $this->dom->addChild(
1000
            $this->ide,
1001
            'xDetRetira',
1002
            $std->xDetRetira,
1003
            false,
1004
            $identificador . 'Detalhes do retira'
1005
        );
1006
        $this->dom->addChild(
1007
            $this->ide,
1008
            'indIEToma',
1009
            $std->indIEToma,
1010
            true,
1011
            $identificador . 'Indicador do papel do tomador na prestação do serviço'
1012
        );
1013
        $this->dom->addChild(
1014
            $this->ide,
1015
            'dhCont',
1016
            $std->dhCont,
1017
            false,
1018
            $identificador . 'Data e Hora da entrada em contingência'
1019
        );
1020
        $this->dom->addChild(
1021
            $this->ide,
1022
            'xJust',
1023
            Strings::replaceSpecialsChars(substr(trim($std->xJust), 0, 256)),
1024
            false,
1025
            $identificador . 'Justificativa da entrada em contingência'
1026
        );
1027
        $this->tpServ = $std->tpServ;
1028
        return $this->ide;
1029
    }
1030
1031
    /**
1032
     * Gera as tags para o elemento: Identificação do CT-e OS
1033
     * #4
1034
     * Nível: 1
1035
     * Os parâmetros para esta função são todos os elementos da tag "ide" do tipo elemento (Ele = E|CE|A) e nível 2
1036
     *
1037
     * @return DOMElement|\DOMNode
1038
     */
1039
    public function tagideCTeOS($std)
1040
    {
1041
        $this->tpAmb = $std->tpAmb;
1042
        $identificador = '#4 <ide> - ';
1043
        $this->ide = $this->dom->createElement('ide');
1044
        $this->dom->addChild(
1045
            $this->ide,
1046
            'cUF',
1047
            $std->cUF,
1048
            true,
1049
            $identificador . 'Código da UF do emitente do CT-e'
1050
        );
1051
        $this->dom->addChild(
1052
            $this->ide,
1053
            'cCT',
1054
            $std->cCT,
1055
            true,
1056
            $identificador . 'Código numérico que compõe a Chave de Acesso'
1057
        );
1058
        $this->dom->addChild(
1059
            $this->ide,
1060
            'CFOP',
1061
            $std->CFOP,
1062
            true,
1063
            $identificador . 'Código Fiscal de Operações e Prestações'
1064
        );
1065
        $this->dom->addChild(
1066
            $this->ide,
1067
            'natOp',
1068
            $std->natOp,
1069
            true,
1070
            $identificador . 'Natureza da Operação'
1071
        );
1072
        $this->dom->addChild(
1073
            $this->ide,
1074
            'mod',
1075
            $std->mod,
1076
            true,
1077
            $identificador . 'Modelo do documento fiscal'
1078
        );
1079
        $this->mod = $std->mod;
1080
        $this->dom->addChild(
1081
            $this->ide,
1082
            'serie',
1083
            $std->serie,
1084
            true,
1085
            $identificador . 'Série do CT-e'
1086
        );
1087
        $this->dom->addChild(
1088
            $this->ide,
1089
            'nCT',
1090
            $std->nCT,
1091
            true,
1092
            $identificador . 'Número do CT-e'
1093
        );
1094
        $this->dom->addChild(
1095
            $this->ide,
1096
            'dhEmi',
1097
            $std->dhEmi,
1098
            true,
1099
            $identificador . 'Data e hora de emissão do CT-e'
1100
        );
1101
        $this->dom->addChild(
1102
            $this->ide,
1103
            'tpImp',
1104
            $std->tpImp,
1105
            true,
1106
            $identificador . 'Formato de impressão do DACTE'
1107
        );
1108
        $this->dom->addChild(
1109
            $this->ide,
1110
            'tpEmis',
1111
            $std->tpEmis,
1112
            true,
1113
            $identificador . 'Forma de emissão do CT-e'
1114
        );
1115
        $this->dom->addChild(
1116
            $this->ide,
1117
            'cDV',
1118
            $std->cDV,
1119
            true,
1120
            $identificador . 'Digito Verificador da chave de acesso do CT-e'
1121
        );
1122
        $this->dom->addChild(
1123
            $this->ide,
1124
            'tpAmb',
1125
            $std->tpAmb,
1126
            true,
1127
            $identificador . 'Tipo do Ambiente'
1128
        );
1129
        $this->dom->addChild(
1130
            $this->ide,
1131
            'tpCTe',
1132
            $std->tpCTe,
1133
            true,
1134
            $identificador . 'Tipo do CT-e'
1135
        );
1136
        $this->dom->addChild(
1137
            $this->ide,
1138
            'procEmi',
1139
            $std->procEmi,
1140
            true,
1141
            $identificador . 'Identificador do processo de emissão do CT-e'
1142
        );
1143
        $this->dom->addChild(
1144
            $this->ide,
1145
            'verProc',
1146
            $std->verProc,
1147
            true,
1148
            $identificador . 'Versão do processo de emissão'
1149
        );
1150
        $this->dom->addChild(
1151
            $this->ide,
1152
            'cMunEnv',
1153
            $std->cMunEnv,
1154
            true,
1155
            $identificador . 'Código do Município de envio do CT-e (de onde o documento foi transmitido)'
1156
        );
1157
        $this->dom->addChild(
1158
            $this->ide,
1159
            'xMunEnv',
1160
            $std->xMunEnv,
1161
            true,
1162
            $identificador . 'Nome do Município de envio do CT-e (de onde o documento foi transmitido)'
1163
        );
1164
        $this->dom->addChild(
1165
            $this->ide,
1166
            'UFEnv',
1167
            $std->UFEnv,
1168
            true,
1169
            $identificador . 'Sigla da UF de envio do CT-e (de onde o documento foi transmitido)'
1170
        );
1171
        $this->dom->addChild(
1172
            $this->ide,
1173
            'modal',
1174
            $std->modal,
1175
            true,
1176
            $identificador . 'Modal'
1177
        );
1178
        $this->modal = $std->modal;
1179
        $this->dom->addChild(
1180
            $this->ide,
1181
            'tpServ',
1182
            $std->tpServ,
1183
            true,
1184
            $identificador . 'Tipo do Serviço'
1185
        );
1186
        $this->dom->addChild(
1187
            $this->ide,
1188
            'indIEToma',
1189
            $std->indIEToma,
1190
            true,
1191
            $identificador . 'Indicador do papel do tomador na prestação do serviço'
1192
        );
1193
        $this->dom->addChild(
1194
            $this->ide,
1195
            'cMunIni',
1196
            $std->cMunIni,
1197
            false,
1198
            $identificador . 'Nome do Município do início da prestação'
1199
        );
1200
        $this->dom->addChild(
1201
            $this->ide,
1202
            'xMunIni',
1203
            $std->xMunIni,
1204
            false,
1205
            $identificador . 'Nome do Município do início da prestação'
1206
        );
1207
        $this->dom->addChild(
1208
            $this->ide,
1209
            'UFIni',
1210
            $std->UFIni,
1211
            false,
1212
            $identificador . 'UF do início da prestação'
1213
        );
1214
        $this->dom->addChild(
1215
            $this->ide,
1216
            'cMunFim',
1217
            $std->cMunFim,
1218
            false,
1219
            $identificador . 'Código do Município de término da prestação'
1220
        );
1221
        $this->dom->addChild(
1222
            $this->ide,
1223
            'xMunFim',
1224
            $std->xMunFim,
1225
            false,
1226
            $identificador . 'Nome do Município do término da prestação'
1227
        );
1228
        $this->dom->addChild(
1229
            $this->ide,
1230
            'UFFim',
1231
            $std->UFFim,
1232
            false,
1233
            $identificador . 'UF do término da prestação'
1234
        );
1235
1236
        $this->dom->addChild(
1237
            $this->ide,
1238
            'dhCont',
1239
            $std->dhCont,
1240
            false,
1241
            $identificador . 'Data e Hora da entrada em contingência'
1242
        );
1243
        $this->dom->addChild(
1244
            $this->ide,
1245
            'xJust',
1246
            $std->xJust,
1247
            false,
1248
            $identificador . 'Justificativa da entrada em contingência'
1249
        );
1250
        $this->tpServ = $std->tpServ;
1251
        return $this->ide;
1252
    }
1253
1254
    public function taginfPercurso($std)
1255
    {
1256
        $identificador = '#4 <infPercurso> - ';
1257
        $this->infPercurso[] = $this->dom->createElement('infPercurso');
1258
        $posicao = (integer)count($this->infPercurso) - 1;
1259
        $this->dom->addChild(
1260
            $this->infPercurso[$posicao],
1261
            'UFPer',
1262
            $std->uf,
1263
            true,
1264
            $identificador . 'Código da UF do percurso'
1265
        );
1266
1267
        return $this->infPercurso[$posicao];
1268
    }
1269
1270
    /**
1271
     * Gera as tags para o elemento: toma3 (Indicador do "papel" do tomador do serviço no CT-e)
1272
     * e adiciona ao grupo ide
1273
     * #35
1274
     * Nível: 2
1275
     * @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...
1276
     * @param  stdClass $std
1277
     * @return \DOMElement
1278
     */
1279
    public function tagtoma3($std)
1280
    {
1281
        $identificador = '#35 <toma3> - ';
1282
        $this->toma3 = $this->dom->createElement('toma3');
1283
        $this->dom->addChild(
1284
            $this->toma3,
1285
            'toma',
1286
            $std->toma,
1287
            true,
1288
            $identificador . 'Tomador do Serviço'
1289
        );
1290
        return $this->toma3;
1291
    }
1292
1293
    /**
1294
     * Gera as tags para o elemento: toma4 (Indicador do "papel" do tomador
1295
     * do serviço no CT-e) e adiciona ao grupo ide
1296
     * #37
1297
     * Nível: 2
1298
     * @param  stdClass $std
1299
     * @return \DOMElement
1300
     */
1301
    public function tagtoma4($std)
1302
    {
1303
        $identificador = '#37 <toma4> - ';
1304
        $this->toma4 = $this->dom->createElement('toma4');
1305
        $this->dom->addChild(
1306
            $this->toma4,
1307
            'toma',
1308
            $std->toma,
1309
            true,
1310
            $identificador . 'Tomador do Serviço'
1311
        );
1312
        if ($std->CNPJ != '') {
1313
            $this->dom->addChild(
1314
                $this->toma4,
1315
                'CNPJ',
1316
                $std->CNPJ,
1317
                true,
1318
                $identificador . 'Número do CNPJ'
1319
            );
1320
        } elseif ($std->CPF != '') {
1321
            $this->dom->addChild(
1322
                $this->toma4,
1323
                'CPF',
1324
                $std->CPF,
1325
                true,
1326
                $identificador . 'Número do CPF'
1327
            );
1328
        } else {
1329
            $this->dom->addChild(
1330
                $this->toma4,
1331
                'CNPJ',
1332
                $std->CNPJ,
1333
                true,
1334
                $identificador . 'Número do CNPJ'
1335
            );
1336
            $this->dom->addChild(
1337
                $this->toma4,
1338
                'CPF',
1339
                $std->CPF,
1340
                true,
1341
                $identificador . 'Número do CPF'
1342
            );
1343
        }
1344
        $this->dom->addChild(
1345
            $this->toma4,
1346
            'IE',
1347
            $std->IE,
1348
            false,
1349
            $identificador . 'Inscrição Estadual'
1350
        );
1351
        $this->dom->addChild(
1352
            $this->toma4,
1353
            'xNome',
1354
            $std->xNome,
1355
            true,
1356
            $identificador . 'Razão Social ou Nome'
1357
        );
1358
        $this->dom->addChild(
1359
            $this->toma4,
1360
            'xFant',
1361
            $std->xFant,
1362
            false,
1363
            $identificador . 'Nome Fantasia'
1364
        );
1365
        $this->dom->addChild(
1366
            $this->toma4,
1367
            'fone',
1368
            $std->fone,
1369
            false,
1370
            $identificador . 'Telefone'
1371
        );
1372
        $this->dom->addChild(
1373
            $this->toma4,
1374
            'email',
1375
            $std->email,
1376
            false,
1377
            $identificador . 'Endereço de email'
1378
        );
1379
        return $this->toma4;
1380
    }
1381
1382
    /**
1383
     * Gera as tags para o elemento: toma4 (Indicador do "papel" do tomador
1384
     * do serviço no CT-e OS) e adiciona ao grupo ide
1385
     * #37
1386
     * Nível: 2
1387
     *
1388
     * @return \DOMElement
1389
     */
1390
    public function tagtoma4CTeOS($std)
1391
    {
1392
        $identificador = '#37 <toma> - ';
1393
        $this->toma = $this->dom->createElement('toma');
1394
        if ($std->CNPJ != '') {
1395
            $this->dom->addChild(
1396
                $this->toma,
1397
                'CNPJ',
1398
                $std->CNPJ,
1399
                true,
1400
                $identificador . 'Número do CNPJ'
1401
            );
1402
        } elseif ($std->CPF != '') {
1403
            $this->dom->addChild(
1404
                $this->toma,
1405
                'CPF',
1406
                $std->CPF,
1407
                true,
1408
                $identificador . 'Número do CPF'
1409
            );
1410
        } else {
1411
            $this->dom->addChild(
1412
                $this->toma,
1413
                'CNPJ',
1414
                $std->CNPJ,
1415
                true,
1416
                $identificador . 'Número do CNPJ'
1417
            );
1418
            $this->dom->addChild(
1419
                $this->toma,
1420
                'CPF',
1421
                $std->CPF,
1422
                true,
1423
                $identificador . 'Número do CPF'
1424
            );
1425
        }
1426
        $this->dom->addChild(
1427
            $this->toma,
1428
            'IE',
1429
            $std->IE,
1430
            false,
1431
            $identificador . 'Inscrição Estadual'
1432
        );
1433
        $this->dom->addChild(
1434
            $this->toma,
1435
            'xNome',
1436
            $std->xNome,
1437
            true,
1438
            $identificador . 'Razão Social ou Nome'
1439
        );
1440
        $this->dom->addChild(
1441
            $this->toma,
1442
            'xFant',
1443
            $std->xFant,
1444
            false,
1445
            $identificador . 'Nome Fantasia'
1446
        );
1447
        $this->dom->addChild(
1448
            $this->toma,
1449
            'fone',
1450
            $std->fone,
1451
            false,
1452
            $identificador . 'Telefone'
1453
        );
1454
1455
1456
        //Endereço Tomador
1457
        $this->enderToma = $this->dom->createElement('enderToma');
1458
        $this->dom->addChild(
1459
            $this->enderToma,
1460
            'xLgr',
1461
            $std->xLgr,
1462
            true,
1463
            $identificador . 'Logradouro'
1464
        );
1465
        $this->dom->addChild(
1466
            $this->enderToma,
1467
            'nro',
1468
            $std->nro,
1469
            true,
1470
            $identificador . 'Número'
1471
        );
1472
        $this->dom->addChild(
1473
            $this->enderToma,
1474
            'xCpl',
1475
            $std->xCpl,
1476
            false,
1477
            $identificador . 'Complemento'
1478
        );
1479
        $this->dom->addChild(
1480
            $this->enderToma,
1481
            'xBairro',
1482
            $std->xBairro,
1483
            true,
1484
            $identificador . 'Bairro'
1485
        );
1486
        $this->dom->addChild(
1487
            $this->enderToma,
1488
            'cMun',
1489
            $std->cMun,
1490
            true,
1491
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
1492
        );
1493
        $this->dom->addChild(
1494
            $this->enderToma,
1495
            'xMun',
1496
            $std->xMun,
1497
            true,
1498
            $identificador . 'Nome do município'
1499
        );
1500
        $this->dom->addChild(
1501
            $this->enderToma,
1502
            'CEP',
1503
            $std->CEP,
1504
            false,
1505
            $identificador . 'CEP'
1506
        );
1507
        $this->dom->addChild(
1508
            $this->enderToma,
1509
            'UF',
1510
            $std->UF,
1511
            true,
1512
            $identificador . 'Sigla da UF'
1513
        );
1514
        $this->dom->addChild(
1515
            $this->enderToma,
1516
            'cPais',
1517
            $std->cPais,
1518
            false,
1519
            $identificador . 'Código do país'
1520
        );
1521
        $this->dom->addChild(
1522
            $this->enderToma,
1523
            'xPais',
1524
            $std->xPais,
1525
            false,
1526
            $identificador . 'Nome do país'
1527
        );
1528
1529
        $this->dom->appChild($this->toma, $this->enderToma, 'Falta tag "enderToma"');
1530
1531
1532
        $this->dom->addChild(
1533
            $this->toma,
1534
            'email',
1535
            $std->email,
1536
            false,
1537
            $identificador . 'Endereço de email'
1538
        );
1539
        return $this->toma;
1540
    }
1541
1542
    /**
1543
     * Gera as tags para o elemento: "enderToma" (Dados do endereço) e adiciona ao grupo "toma4"
1544
     * #45
1545
     * Nível: 3
1546
     *
1547
     * @return \DOMElement
1548
     */
1549
    public function tagenderToma($std)
1550
    {
1551
        $identificador = '#45 <enderToma> - ';
1552
        $this->enderToma = $this->dom->createElement('enderToma');
1553
        $this->dom->addChild(
1554
            $this->enderToma,
1555
            'xLgr',
1556
            $std->xLgr,
1557
            true,
1558
            $identificador . 'Logradouro'
1559
        );
1560
        $this->dom->addChild(
1561
            $this->enderToma,
1562
            'nro',
1563
            $std->nro,
1564
            true,
1565
            $identificador . 'Número'
1566
        );
1567
        $this->dom->addChild(
1568
            $this->enderToma,
1569
            'xCpl',
1570
            $std->xCpl,
1571
            false,
1572
            $identificador . 'Complemento'
1573
        );
1574
        $this->dom->addChild(
1575
            $this->enderToma,
1576
            'xBairro',
1577
            $std->xBairro,
1578
            true,
1579
            $identificador . 'Bairro'
1580
        );
1581
        $this->dom->addChild(
1582
            $this->enderToma,
1583
            'cMun',
1584
            $std->cMun,
1585
            true,
1586
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
1587
        );
1588
        $this->dom->addChild(
1589
            $this->enderToma,
1590
            'xMun',
1591
            $std->xMun,
1592
            true,
1593
            $identificador . 'Nome do município'
1594
        );
1595
        $this->dom->addChild(
1596
            $this->enderToma,
1597
            'CEP',
1598
            $std->CEP,
1599
            false,
1600
            $identificador . 'CEP'
1601
        );
1602
        $this->dom->addChild(
1603
            $this->enderToma,
1604
            'UF',
1605
            $std->UF,
1606
            true,
1607
            $identificador . 'Sigla da UF'
1608
        );
1609
        $this->dom->addChild(
1610
            $this->enderToma,
1611
            'cPais',
1612
            $std->cPais,
1613
            false,
1614
            $identificador . 'Código do país'
1615
        );
1616
        $this->dom->addChild(
1617
            $this->enderToma,
1618
            'xPais',
1619
            $std->xPais,
1620
            false,
1621
            $identificador . 'Nome do país'
1622
        );
1623
1624
        if (!empty($this->toma4)) {
1625
            $this->toma4->insertBefore($this->enderToma, $this->toma4->getElementsByTagName("email")->item(0));
1626
        }
1627
        return $this->enderToma;
1628
    }
1629
1630
    /**
1631
     * Gera as tags para o elemento: "compl" (Dados complementares do CT-e para fins operacionais ou comerciais)
1632
     * #59
1633
     * Nível: 1
1634
     *
1635
     * @return \DOMElement
1636
     */
1637
    public function tagcompl($std)
1638
    {
1639
        $identificador = '#59 <compl> - ';
1640
        if ($this->compl == '') {
1641
            $this->compl = $this->dom->createElement('compl');
1642
        }
1643
        $this->dom->addChild(
1644
            $this->compl,
1645
            'xCaracAd',
1646
            $std->xCaracAd,
1647
            false,
1648
            $identificador . 'Característica adicional do transporte'
1649
        );
1650
        $this->dom->addChild(
1651
            $this->compl,
1652
            'xCaracSer',
1653
            $std->xCaracSer,
1654
            false,
1655
            $identificador . 'Característica adicional do serviço'
1656
        );
1657
        $this->dom->addChild(
1658
            $this->compl,
1659
            'xEmi',
1660
            $std->xEmi,
1661
            false,
1662
            $identificador . 'Funcionário emissor do CTe'
1663
        );
1664
        $this->dom->addChild(
1665
            $this->compl,
1666
            'origCalc',
1667
            $std->origCalc,
1668
            false,
1669
            $identificador . 'Município de origem para efeito de cálculo do frete'
1670
        );
1671
        $this->dom->addChild(
1672
            $this->compl,
1673
            'destCalc',
1674
            $std->destCalc,
1675
            false,
1676
            $identificador . 'Município de destino para efeito de cálculo do frete'
1677
        );
1678
        $this->dom->addChild(
1679
            $this->compl,
1680
            'xObs',
1681
            $std->xObs,
1682
            false,
1683
            $identificador . 'Observações Gerais'
1684
        );
1685
        return $this->compl;
1686
    }
1687
1688
    /**
1689
     * Gera as tags para o elemento: "compl" (Dados complementares do CT-e OS para fins operacionais ou comerciais)
1690
     * #59
1691
     * Nível: 1
1692
     *
1693
     * @return \DOMElement
1694
     */
1695
    public function tagcomplCTeOs($std)
1696
    {
1697
        $identificador = '#59 <compl> - ';
1698
        $this->compl = $this->dom->createElement('compl');
1699
        $this->dom->addChild(
1700
            $this->compl,
1701
            'xCaracAd',
1702
            $std->xCaracAd,
1703
            false,
1704
            $identificador . 'Característica adicional do transporte'
1705
        );
1706
        $this->dom->addChild(
1707
            $this->compl,
1708
            'xCaracSer',
1709
            $std->xCaracSer,
1710
            false,
1711
            $identificador . 'Característica adicional do serviço'
1712
        );
1713
        $this->dom->addChild(
1714
            $this->compl,
1715
            'xEmi',
1716
            $std->xEmi,
1717
            false,
1718
            $identificador . 'Funcionário emissor do CTe'
1719
        );
1720
        $this->dom->addChild(
1721
            $this->compl,
1722
            'xObs',
1723
            $std->xObs,
1724
            false,
1725
            $identificador . 'Observações Gerais'
1726
        );
1727
        return $this->compl;
1728
    }
1729
1730
    /**
1731
     * Gera as tags para o elemento: "fluxo" (Previsão do fluxo da carga)
1732
     * #63
1733
     * Nível: 2
1734
     * Os parâmetros para esta função são todos os elementos da tag "fluxo" do
1735
     * tipo elemento (Ele = E|CE|A) e nível 3
1736
     *
1737
     * @return \DOMElement
1738
     */
1739
    public function tagfluxo($std)
1740
    {
1741
        $identificador = '#63 <fluxo> - ';
1742
        $this->fluxo = $this->dom->createElement('fluxo');
1743
        $this->dom->addChild(
1744
            $this->fluxo,
1745
            'xOrig',
1746
            $std->xOrig,
1747
            false,
1748
            $identificador . 'Sigla ou código interno da Filial/Porto/Estação/ Aeroporto de Origem'
1749
        );
1750
        $this->dom->addChild(
1751
            $this->fluxo,
1752
            'xDest',
1753
            $std->xDest,
1754
            false,
1755
            $identificador . 'Sigla ou código interno da Filial/Porto/Estação/Aeroporto de Destino'
1756
        );
1757
        $this->dom->addChild(
1758
            $this->fluxo,
1759
            'xRota',
1760
            $std->xRota,
1761
            false,
1762
            $identificador . 'Código da Rota de Entrega'
1763
        );
1764
        return $this->fluxo;
1765
    }
1766
1767
    /**
1768
     * Gera as tags para o elemento: "pass"
1769
     * #65
1770
     * Nível: 3
1771
     *
1772
     * @return \DOMElement
1773
     */
1774
    public function tagpass($std)
1775
    {
1776
        $identificador = '#65 <pass> - ';
1777
        $this->pass[] = $this->dom->createElement('pass');
1778
        $posicao = (integer) count($this->pass) - 1;
1779
        $this->dom->addChild(
1780
            $this->pass[$posicao],
1781
            'xPass',
1782
            $std->xPass,
1783
            false,
1784
            $identificador . 'Sigla ou código interno da Filial/Porto/Estação/Aeroporto de Passagem'
1785
        );
1786
        return $this->pass[$posicao];
1787
    }
1788
1789
    /**
1790
     * Gera as tags para o elemento: "semData" (Entrega sem data definida)
1791
     * #70
1792
     * Nível: 3
1793
     *
1794
     * @return \DOMElement
1795
     */
1796
    public function tagsemData($std)
1797
    {
1798
        $identificador = '#70 <semData> - ';
1799
        $this->semData = $this->dom->createElement('semData');
1800
        $this->dom->addChild(
1801
            $this->semData,
1802
            'tpPer',
1803
            $std->tpPer,
1804
            true,
1805
            $identificador . 'Tipo de data/período programado para entrega'
1806
        );
1807
        return $this->semData;
1808
    }
1809
1810
    /**
1811
     * Gera as tags para o elemento: "comData" (Entrega com data definida)
1812
     * #72
1813
     * Nível: 3
1814
     *
1815
     * @return \DOMElement
1816
     */
1817
    public function tagcomData($std)
1818
    {
1819
        $identificador = '#72 <comData> - ';
1820
        $this->comData = $this->dom->createElement('comData');
1821
        $this->dom->addChild(
1822
            $this->comData,
1823
            'tpPer',
1824
            $std->tpPer,
1825
            true,
1826
            $identificador . 'Tipo de data/período programado para entrega'
1827
        );
1828
        $this->dom->addChild(
1829
            $this->comData,
1830
            'dProg',
1831
            $std->dProg,
1832
            true,
1833
            $identificador . 'Data programada'
1834
        );
1835
        return $this->comData;
1836
    }
1837
1838
    /**
1839
     * Gera as tags para o elemento: "noPeriodo" (Entrega no período definido)
1840
     * #75
1841
     * Nível: 3
1842
     *
1843
     * @return \DOMElement
1844
     */
1845
    public function tagnoPeriodo($std)
1846
    {
1847
        $identificador = '#75 <noPeriodo> - ';
1848
        $this->noPeriodo = $this->dom->createElement('noPeriodo');
1849
        $this->dom->addChild(
1850
            $this->noPeriodo,
1851
            'tpPer',
1852
            $std->tpPer,
1853
            true,
1854
            $identificador . 'Tipo de data/período programado para entrega'
1855
        );
1856
        $this->dom->addChild(
1857
            $this->noPeriodo,
1858
            'dIni',
1859
            $std->dIni,
1860
            true,
1861
            $identificador . 'Data inicial'
1862
        );
1863
        $this->dom->addChild(
1864
            $this->noPeriodo,
1865
            'dFim',
1866
            $std->dFim,
1867
            true,
1868
            $identificador . 'Data final'
1869
        );
1870
        return $this->noPeriodo;
1871
    }
1872
1873
    /**
1874
     * Gera as tags para o elemento: "semHora" (Entrega sem hora definida)
1875
     * #79
1876
     * Nível: 3
1877
     * Os parâmetros para esta função são todos os elementos da tag "semHora" do
1878
     * tipo elemento (Ele = E|CE|A) e nível 4
1879
     *
1880
     * @return \DOMElement
1881
     */
1882
    public function tagsemHora($std)
1883
    {
1884
        $identificador = '#79 <semHora> - ';
1885
        $this->semHora = $this->dom->createElement('semHora');
1886
        $this->dom->addChild(
1887
            $this->semHora,
1888
            'tpHor',
1889
            $std->tpHor,
1890
            true,
1891
            $identificador . 'Tipo de hora'
1892
        );
1893
        return $this->semHora;
1894
    }
1895
1896
    /**
1897
     * Gera as tags para o elemento: "comHora" (Entrega sem hora definida)
1898
     * # = 81
1899
     * Nível = 3
1900
     * Os parâmetros para esta função são todos os elementos da tag "comHora" do
1901
     * tipo elemento (Ele = E|CE|A) e nível 4
1902
     *
1903
     * @return \DOMElement
1904
     */
1905
    public function tagcomHora($std)
1906
    {
1907
        $identificador = '#81 <comHora> - ';
1908
        $this->comHora = $this->dom->createElement('comHora');
1909
        $this->dom->addChild(
1910
            $this->comHora,
1911
            'tpHor',
1912
            $std->tpHor,
1913
            true,
1914
            $identificador . 'Tipo de hora'
1915
        );
1916
        $this->dom->addChild(
1917
            $this->comHora,
1918
            'hProg',
1919
            $std->hProg,
1920
            true,
1921
            $identificador . 'Hora programada'
1922
        );
1923
        return $this->comHora;
1924
    }
1925
1926
    /**
1927
     * Gera as tags para o elemento: "noInter" (Entrega no intervalo de horário definido)
1928
     * #84
1929
     * Nível: 3
1930
     * Os parâmetros para esta função são todos os elementos da tag "noInter" do
1931
     * tipo elemento (Ele = E|CE|A) e nível 4
1932
     *
1933
     * @return \DOMElement
1934
     */
1935
    public function tagnoInter($std)
1936
    {
1937
        $identificador = '#84 <noInter> - ';
1938
        $this->noInter = $this->dom->createElement('noInter');
1939
        $this->dom->addChild(
1940
            $this->noInter,
1941
            'tpHor',
1942
            $std->tpHor,
1943
            true,
1944
            $identificador . 'Tipo de hora'
1945
        );
1946
        $this->dom->addChild(
1947
            $this->noInter,
1948
            'hIni',
1949
            $std->hIni,
1950
            true,
1951
            $identificador . 'Hora inicial'
1952
        );
1953
        $this->dom->addChild(
1954
            $this->noInter,
1955
            'hFim',
1956
            $std->hFim,
1957
            true,
1958
            $identificador . 'Hora final'
1959
        );
1960
        return $this->noInter;
1961
    }
1962
1963
    /**
1964
     * Gera as tags para o elemento: "ObsCont" (Campo de uso livre do contribuinte)
1965
     * #91
1966
     * Nível: 2
1967
     * Os parâmetros para esta função são todos os elementos da tag "ObsCont" do
1968
     * tipo elemento (Ele = E|CE|A) e nível 3
1969
     *
1970
     * @return boolean
1971
     */
1972
    public function tagobsCont($std)
1973
    {
1974
        $identificador = '#91 <ObsCont> - ';
1975
        if (count($this->obsCont) <= 10) {
1976
            $this->obsCont[] = $this->dom->createElement('ObsCont');
1977
            $posicao = (integer) count($this->obsCont) - 1;
1978
            $this->obsCont[$posicao]->setAttribute('xCampo', $std->xCampo);
1979
            $this->dom->addChild(
1980
                $this->obsCont[$posicao],
1981
                'xTexto',
1982
                $std->xTexto,
1983
                true,
1984
                $identificador . 'Conteúdo do campo'
1985
            );
1986
            return true;
1987
        }
1988
        $this->erros[] = array(
1989
            'tag' => (string) '<ObsCont>',
1990
            'desc' => (string) 'Campo de uso livre do contribuinte',
1991
            'erro' => (string) 'Tag deve aparecer de 0 a 10 vezes'
1992
        );
1993
        return false;
1994
    }
1995
1996
    /**
1997
     * Gera as tags para o elemento: "ObsFisco" (Campo de uso livre do contribuinte)
1998
     * #94
1999
     * Nível: 2
2000
     * Os parâmetros para esta função são todos os elementos da tag "ObsFisco" do tipo
2001
     * elemento (Ele = E|CE|A) e nível 3
2002
     *
2003
     * @return boolean
2004
     */
2005
    public function tagobsFisco($std)
2006
    {
2007
        $identificador = '#94 <ObsFisco> - ';
2008
        $posicao = (integer) count($this->obsFisco) - 1;
2009
        if (count($this->obsFisco) <= 10) {
2010
            $this->obsFisco[] = $this->dom->createElement('obsFisco');
2011
            $this->obsFisco[$posicao]->setAttribute('xCampo', $std->xCampo);
2012
            $this->dom->addChild(
2013
                $this->obsFisco[$posicao],
2014
                'xTexto',
2015
                $std->xTexto,
2016
                true,
2017
                $identificador . 'Conteúdo do campo'
2018
            );
2019
            return true;
2020
        }
2021
        $this->erros[] = array(
2022
            'tag' => (string) '<ObsFisco>',
2023
            'desc' => (string) 'Campo de uso livre do contribuinte',
2024
            'erro' => (string) 'Tag deve aparecer de 0 a 10 vezes'
2025
        );
2026
        return false;
2027
    }
2028
2029
    /**
2030
     * Gera as tags para o elemento: "emit" (Identificação do Emitente do CT-e)
2031
     * #97
2032
     * Nível: 1
2033
     * Os parâmetros para esta função são todos os elementos da tag "emit" do
2034
     * tipo elemento (Ele = E|CE|A) e nível 2
2035
     *
2036
     * @return \DOMElement
2037
     */
2038
    public function tagemit($std)
2039
    {
2040
        $identificador = '#97 <emit> - ';
2041
        $this->emit = $this->dom->createElement('emit');
2042
        $this->dom->addChild(
2043
            $this->emit,
2044
            'CNPJ',
2045
            $std->CNPJ,
2046
            true,
2047
            $identificador . 'CNPJ do emitente'
2048
        );
2049
        $this->dom->addChild(
2050
            $this->emit,
2051
            'IE',
2052
            Strings::onlyNumbers($std->IE),
2053
            true,
2054
            $identificador . 'Inscrição Estadual do Emitente'
2055
        );
2056
        $this->dom->addChild(
2057
            $this->emit,
2058
            'IEST',
2059
            Strings::onlyNumbers($std->IEST),
2060
            false,
2061
            $identificador . 'Inscrição Estadual do Substituto Tributário'
2062
        );
2063
        $this->dom->addChild(
2064
            $this->emit,
2065
            'xNome',
2066
            $std->xNome,
2067
            true,
2068
            $identificador . 'Razão social ou Nome do emitente'
2069
        );
2070
        $this->dom->addChild(
2071
            $this->emit,
2072
            'xFant',
2073
            $std->xFant,
2074
            false,
2075
            $identificador . 'Nome fantasia'
2076
        );
2077
        return $this->emit;
2078
    }
2079
2080
    /**
2081
     * Gera as tags para o elemento: "enderEmit" (Endereço do emitente)
2082
     * #102
2083
     * Nível: 2
2084
     * Os parâmetros para esta função são todos os elementos da tag "enderEmit" do
2085
     * tipo elemento (Ele = E|CE|A) e nível 3
2086
     *
2087
     * @return \DOMElement
2088
     */
2089
    public function tagenderEmit($std)
2090
    {
2091
        $identificador = '#102 <enderEmit> - ';
2092
        $this->enderEmit = $this->dom->createElement('enderEmit');
2093
        $this->dom->addChild(
2094
            $this->enderEmit,
2095
            'xLgr',
2096
            $std->xLgr,
2097
            true,
2098
            $identificador . 'Logradouro'
2099
        );
2100
        $this->dom->addChild(
2101
            $this->enderEmit,
2102
            'nro',
2103
            $std->nro,
2104
            true,
2105
            $identificador . 'Número'
2106
        );
2107
        $this->dom->addChild(
2108
            $this->enderEmit,
2109
            'xCpl',
2110
            $std->xCpl,
2111
            false,
2112
            $identificador . 'Complemento'
2113
        );
2114
        $this->dom->addChild(
2115
            $this->enderEmit,
2116
            'xBairro',
2117
            $std->xBairro,
2118
            true,
2119
            $identificador . 'Bairro'
2120
        );
2121
        $this->dom->addChild(
2122
            $this->enderEmit,
2123
            'cMun',
2124
            $std->cMun,
2125
            true,
2126
            $identificador . 'Código do município'
2127
        );
2128
        $this->dom->addChild(
2129
            $this->enderEmit,
2130
            'xMun',
2131
            $std->xMun,
2132
            true,
2133
            $identificador . 'Nome do município'
2134
        );
2135
        $this->dom->addChild(
2136
            $this->enderEmit,
2137
            'CEP',
2138
            $std->CEP,
2139
            false,
2140
            $identificador . 'CEP'
2141
        );
2142
        $this->dom->addChild(
2143
            $this->enderEmit,
2144
            'UF',
2145
            $std->UF,
2146
            true,
2147
            $identificador . 'Sigla da UF'
2148
        );
2149
        $this->dom->addChild(
2150
            $this->enderEmit,
2151
            'fone',
2152
            $std->fone,
2153
            false,
2154
            $identificador . 'Telefone'
2155
        );
2156
        return $this->enderEmit;
2157
    }
2158
2159
    /**
2160
     * Gera as tags para o elemento: "rem" (Informações do Remetente das mercadorias
2161
     * transportadas pelo CT-e)
2162
     * #112
2163
     * Nível = 1
2164
     * Os parâmetros para esta função são todos os elementos da tag "rem" do
2165
     * tipo elemento (Ele = E|CE|A) e nível 2
2166
     *
2167
     * @return \DOMElement
2168
     */
2169
    public function tagrem($std)
2170
    {
2171
        $identificador = '#97 <rem> - ';
2172
        $this->rem = $this->dom->createElement('rem');
2173
        if ($std->CNPJ != '') {
2174
            $this->dom->addChild(
2175
                $this->rem,
2176
                'CNPJ',
2177
                $std->CNPJ,
2178
                true,
2179
                $identificador . 'CNPJ do Remente'
2180
            );
2181
        } elseif ($std->CPF != '') {
2182
            $this->dom->addChild(
2183
                $this->rem,
2184
                'CPF',
2185
                $std->CPF,
2186
                true,
2187
                $identificador . 'CPF do Remente'
2188
            );
2189
        } else {
2190
            $this->dom->addChild(
2191
                $this->rem,
2192
                'CNPJ',
2193
                $std->CNPJ,
2194
                true,
2195
                $identificador . 'CNPJ do Remente'
2196
            );
2197
            $this->dom->addChild(
2198
                $this->rem,
2199
                'CPF',
2200
                $std->CPF,
2201
                true,
2202
                $identificador . 'CPF do remente'
2203
            );
2204
        }
2205
        $this->dom->addChild(
2206
            $this->rem,
2207
            'IE',
2208
            $std->IE,
2209
            true,
2210
            $identificador . 'Inscrição Estadual do remente'
2211
        );
2212
        $xNome = $std->xNome;
2213
        if ($this->tpAmb == '2') {
2214
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2215
        }
2216
        $this->dom->addChild(
2217
            $this->rem,
2218
            'xNome',
2219
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2220
            true,
2221
            $identificador . 'Razão social ou Nome do remente'
2222
        );
2223
        $this->dom->addChild(
2224
            $this->rem,
2225
            'xFant',
2226
            $std->xFant,
2227
            false,
2228
            $identificador . 'Nome fantasia'
2229
        );
2230
        $this->dom->addChild(
2231
            $this->rem,
2232
            'fone',
2233
            $std->fone,
2234
            false,
2235
            $identificador . 'Telefone'
2236
        );
2237
        $this->dom->addChild(
2238
            $this->rem,
2239
            'email',
2240
            $std->email,
2241
            false,
2242
            $identificador . 'Endereço de email'
2243
        );
2244
        return $this->rem;
2245
    }
2246
2247
    /**
2248
     * Gera as tags para o elemento: "enderReme" (Dados do endereço)
2249
     * #120
2250
     * Nível: 2
2251
     * Os parâmetros para esta função são todos os elementos da tag "enderReme" do
2252
     * tipo elemento (Ele = E|CE|A) e nível 3
2253
     *
2254
     * @return \DOMElement
2255
     */
2256
    public function tagenderReme($std)
2257
    {
2258
        $identificador = '#119 <enderReme> - ';
2259
        $this->enderReme = $this->dom->createElement('enderReme');
2260
        $this->dom->addChild(
2261
            $this->enderReme,
2262
            'xLgr',
2263
            $std->xLgr,
2264
            true,
2265
            $identificador . 'Logradouro'
2266
        );
2267
        $this->dom->addChild(
2268
            $this->enderReme,
2269
            'nro',
2270
            $std->nro,
2271
            true,
2272
            $identificador . 'Número'
2273
        );
2274
        $this->dom->addChild(
2275
            $this->enderReme,
2276
            'xCpl',
2277
            $std->xCpl,
2278
            false,
2279
            $identificador . 'Complemento'
2280
        );
2281
        $this->dom->addChild(
2282
            $this->enderReme,
2283
            'xBairro',
2284
            $std->xBairro,
2285
            true,
2286
            $identificador . 'Bairro'
2287
        );
2288
        $this->dom->addChild(
2289
            $this->enderReme,
2290
            'cMun',
2291
            $std->cMun,
2292
            true,
2293
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2294
        );
2295
        $this->dom->addChild(
2296
            $this->enderReme,
2297
            'xMun',
2298
            $std->xMun,
2299
            true,
2300
            $identificador . 'Nome do município'
2301
        );
2302
        $this->dom->addChild(
2303
            $this->enderReme,
2304
            'CEP',
2305
            $std->CEP,
2306
            false,
2307
            $identificador . 'CEP'
2308
        );
2309
        $this->dom->addChild(
2310
            $this->enderReme,
2311
            'UF',
2312
            $std->UF,
2313
            true,
2314
            $identificador . 'Sigla da UF'
2315
        );
2316
        $this->dom->addChild(
2317
            $this->enderReme,
2318
            'cPais',
2319
            $std->cPais,
2320
            false,
2321
            $identificador . 'Código do país'
2322
        );
2323
        $this->dom->addChild(
2324
            $this->enderReme,
2325
            'xPais',
2326
            $std->xPais,
2327
            false,
2328
            $identificador . 'Nome do país'
2329
        );
2330
2331
        $node = $this->rem->getElementsByTagName("email")->item(0);
2332
        $this->rem->insertBefore($this->enderReme, $node);
2333
        return $this->enderReme;
2334
    }
2335
2336
    /**
2337
     * Gera as tags para o elemento: "exped" (Informações do Expedidor da Carga)
2338
     * #132
2339
     * Nível: 1
2340
     * Os parâmetros para esta função são todos os elementos da tag "exped" do
2341
     * tipo elemento (Ele = E|CE|A) e nível 2
2342
     *
2343
     * @return \DOMElement
2344
     */
2345
    public function tagexped($std)
2346
    {
2347
        $identificador = '#142 <exped> - ';
2348
        $this->exped = $this->dom->createElement('exped');
2349
        if ($std->CNPJ != '') {
2350
            $this->dom->addChild(
2351
                $this->exped,
2352
                'CNPJ',
2353
                $std->CNPJ,
2354
                true,
2355
                $identificador . 'Número do CNPJ'
2356
            );
2357
        } elseif ($std->CPF != '') {
2358
            $this->dom->addChild(
2359
                $this->exped,
2360
                'CPF',
2361
                $std->CPF,
2362
                true,
2363
                $identificador . 'Número do CPF'
2364
            );
2365
        } else {
2366
            $this->dom->addChild(
2367
                $this->exped,
2368
                'CNPJ',
2369
                $std->CNPJ,
2370
                true,
2371
                $identificador . 'Número do CNPJ'
2372
            );
2373
            $this->dom->addChild(
2374
                $this->exped,
2375
                'CPF',
2376
                $std->CPF,
2377
                true,
2378
                $identificador . 'Número do CPF'
2379
            );
2380
        }
2381
        if (!empty($std->IE)) {
2382
            $this->dom->addChild(
2383
                $this->exped,
2384
                'IE',
2385
                $std->IE,
2386
                true,
2387
                $identificador . 'Inscrição Estadual'
2388
            );
2389
        }
2390
        $xNome = $std->xNome;
2391
        if ($this->tpAmb == '2') {
2392
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2393
        }
2394
        $this->dom->addChild(
2395
            $this->exped,
2396
            'xNome',
2397
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2398
            true,
2399
            $identificador . 'Razão social ou Nome'
2400
        );
2401
        $this->dom->addChild(
2402
            $this->exped,
2403
            'fone',
2404
            $std->fone,
2405
            false,
2406
            $identificador . 'Telefone'
2407
        );
2408
        $this->dom->addChild(
2409
            $this->exped,
2410
            'email',
2411
            $std->email,
2412
            false,
2413
            $identificador . 'Endereço de email'
2414
        );
2415
        return $this->exped;
2416
    }
2417
2418
    /**
2419
     * Gera as tags para o elemento: "enderExped" (Dados do endereço)
2420
     * #138
2421
     * Nível: 2
2422
     * Os parâmetros para esta função são todos os elementos da tag "enderExped" do
2423
     * tipo elemento (Ele = E|CE|A) e nível 3
2424
     *
2425
     * @return \DOMElement
2426
     */
2427
    public function tagenderExped($std)
2428
    {
2429
        $identificador = '#148 <enderExped> - ';
2430
        $this->enderExped = $this->dom->createElement('enderExped');
2431
        $this->dom->addChild(
2432
            $this->enderExped,
2433
            'xLgr',
2434
            $std->xLgr,
2435
            true,
2436
            $identificador . 'Logradouro'
2437
        );
2438
        $this->dom->addChild(
2439
            $this->enderExped,
2440
            'nro',
2441
            $std->nro,
2442
            true,
2443
            $identificador . 'Número'
2444
        );
2445
        $this->dom->addChild(
2446
            $this->enderExped,
2447
            'xCpl',
2448
            $std->xCpl,
2449
            false,
2450
            $identificador . 'Complemento'
2451
        );
2452
        $this->dom->addChild(
2453
            $this->enderExped,
2454
            'xBairro',
2455
            $std->xBairro,
2456
            true,
2457
            $identificador . 'Bairro'
2458
        );
2459
        $this->dom->addChild(
2460
            $this->enderExped,
2461
            'cMun',
2462
            $std->cMun,
2463
            true,
2464
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2465
        );
2466
        $this->dom->addChild(
2467
            $this->enderExped,
2468
            'xMun',
2469
            $std->xMun,
2470
            true,
2471
            $identificador . 'Nome do município'
2472
        );
2473
        $this->dom->addChild(
2474
            $this->enderExped,
2475
            'CEP',
2476
            $std->CEP,
2477
            false,
2478
            $identificador . 'CEP'
2479
        );
2480
        $this->dom->addChild(
2481
            $this->enderExped,
2482
            'UF',
2483
            $std->UF,
2484
            true,
2485
            $identificador . 'Sigla da UF'
2486
        );
2487
        $this->dom->addChild(
2488
            $this->enderExped,
2489
            'cPais',
2490
            $std->cPais,
2491
            false,
2492
            $identificador . 'Código do país'
2493
        );
2494
        $this->dom->addChild(
2495
            $this->enderExped,
2496
            'xPais',
2497
            $std->xPais,
2498
            false,
2499
            $identificador . 'Nome do país'
2500
        );
2501
        $node = $this->exped->getElementsByTagName("email")->item(0);
2502
        $this->exped->insertBefore($this->enderExped, $node);
2503
        return $this->enderExped;
2504
    }
2505
2506
    /**
2507
     * Gera as tags para o elemento: "receb" (Informações do Recebedor da Carga)
2508
     * #150
2509
     * Nível: 1
2510
     * Os parâmetros para esta função são todos os elementos da tag "receb" do
2511
     * tipo elemento (Ele = E|CE|A) e nível 2
2512
     *
2513
     * @return \DOMElement
2514
     */
2515
    public function tagreceb($std)
2516
    {
2517
        $identificador = '#160 <receb> - ';
2518
        $this->receb = $this->dom->createElement('receb');
2519
        if ($std->CNPJ != '') {
2520
            $this->dom->addChild(
2521
                $this->receb,
2522
                'CNPJ',
2523
                $std->CNPJ,
2524
                true,
2525
                $identificador . 'Número do CNPJ'
2526
            );
2527
        } elseif ($std->CPF != '') {
2528
            $this->dom->addChild(
2529
                $this->receb,
2530
                'CPF',
2531
                $std->CPF,
2532
                true,
2533
                $identificador . 'Número do CPF'
2534
            );
2535
        } else {
2536
            $this->dom->addChild(
2537
                $this->receb,
2538
                'CNPJ',
2539
                $std->CNPJ,
2540
                true,
2541
                $identificador . 'Número do CNPJ'
2542
            );
2543
            $this->dom->addChild(
2544
                $this->receb,
2545
                'CPF',
2546
                $std->CPF,
2547
                true,
2548
                $identificador . 'Número do CPF'
2549
            );
2550
        }
2551
        if (!empty($std->IE)) {
2552
            $this->dom->addChild(
2553
                $this->receb,
2554
                'IE',
2555
                $std->IE,
2556
                true,
2557
                $identificador . 'Inscrição Estadual'
2558
            );
2559
        }
2560
        $xNome = $std->xNome;
2561
        if ($this->tpAmb == '2') {
2562
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2563
        }
2564
        $this->dom->addChild(
2565
            $this->receb,
2566
            'xNome',
2567
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2568
            true,
2569
            $identificador . 'Razão social ou Nome'
2570
        );
2571
        $this->dom->addChild(
2572
            $this->receb,
2573
            'fone',
2574
            $std->fone,
2575
            false,
2576
            $identificador . 'Telefone'
2577
        );
2578
        $this->dom->addChild(
2579
            $this->receb,
2580
            'email',
2581
            $std->email,
2582
            false,
2583
            $identificador . 'Endereço de email'
2584
        );
2585
        return $this->receb;
2586
    }
2587
2588
    /**
2589
     * Gera as tags para o elemento: "enderReceb" (Informações do Recebedor da Carga)
2590
     * #156
2591
     * Nível: 2
2592
     * Os parâmetros para esta função são todos os elementos da tag "enderReceb" do
2593
     * tipo elemento (Ele = E|CE|A) e nível 3
2594
     *
2595
     * @return \DOMElement
2596
     */
2597
    public function tagenderReceb($std)
2598
    {
2599
        $identificador = '#160 <enderReceb> - ';
2600
        $this->enderReceb = $this->dom->createElement('enderReceb');
2601
        $this->dom->addChild(
2602
            $this->enderReceb,
2603
            'xLgr',
2604
            $std->xLgr,
2605
            true,
2606
            $identificador . 'Logradouro'
2607
        );
2608
        $this->dom->addChild(
2609
            $this->enderReceb,
2610
            'nro',
2611
            $std->nro,
2612
            true,
2613
            $identificador . 'Número'
2614
        );
2615
        $this->dom->addChild(
2616
            $this->enderReceb,
2617
            'xCpl',
2618
            $std->xCpl,
2619
            false,
2620
            $identificador . 'Complemento'
2621
        );
2622
        $this->dom->addChild(
2623
            $this->enderReceb,
2624
            'xBairro',
2625
            $std->xBairro,
2626
            true,
2627
            $identificador . 'Bairro'
2628
        );
2629
        $this->dom->addChild(
2630
            $this->enderReceb,
2631
            'cMun',
2632
            $std->cMun,
2633
            true,
2634
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2635
        );
2636
        $this->dom->addChild(
2637
            $this->enderReceb,
2638
            'xMun',
2639
            $std->xMun,
2640
            true,
2641
            $identificador . 'Nome do município'
2642
        );
2643
        $this->dom->addChild(
2644
            $this->enderReceb,
2645
            'CEP',
2646
            $std->CEP,
2647
            false,
2648
            $identificador . 'CEP'
2649
        );
2650
        $this->dom->addChild(
2651
            $this->enderReceb,
2652
            'UF',
2653
            $std->UF,
2654
            true,
2655
            $identificador . 'Sigla da UF'
2656
        );
2657
        $this->dom->addChild(
2658
            $this->enderReceb,
2659
            'cPais',
2660
            $std->cPais,
2661
            false,
2662
            $identificador . 'Código do país'
2663
        );
2664
        $this->dom->addChild(
2665
            $this->enderReceb,
2666
            'xPais',
2667
            $std->xPais,
2668
            false,
2669
            $identificador . 'Nome do país'
2670
        );
2671
        $node = $this->receb->getElementsByTagName("email")->item(0);
2672
        $this->receb->insertBefore($this->enderReceb, $node);
2673
        return $this->enderReceb;
2674
    }
2675
2676
    /**
2677
     * Gera as tags para o elemento: "dest" (Informações do Destinatário do CT-e)
2678
     * #168
2679
     * Nível: 1
2680
     * Os parâmetros para esta função são todos os elementos da tag "dest" do
2681
     * tipo elemento (Ele = E|CE|A) e nível 2
2682
     *
2683
     * @return \DOMElement
2684
     */
2685
    public function tagdest($std)
2686
    {
2687
        $identificador = '#178 <dest> - ';
2688
        $this->dest = $this->dom->createElement('dest');
2689
        if ($std->CNPJ != '') {
2690
            $this->dom->addChild(
2691
                $this->dest,
2692
                'CNPJ',
2693
                $std->CNPJ,
2694
                true,
2695
                $identificador . 'Número do CNPJ'
2696
            );
2697
        } elseif ($std->CPF != '') {
2698
            $this->dom->addChild(
2699
                $this->dest,
2700
                'CPF',
2701
                $std->CPF,
2702
                true,
2703
                $identificador . 'Número do CPF'
2704
            );
2705
        } else {
2706
            $this->dom->addChild(
2707
                $this->dest,
2708
                'CNPJ',
2709
                $std->CNPJ,
2710
                true,
2711
                $identificador . 'Número do CNPJ'
2712
            );
2713
            $this->dom->addChild(
2714
                $this->dest,
2715
                'CPF',
2716
                $std->CPF,
2717
                true,
2718
                $identificador . 'Número do CPF'
2719
            );
2720
        }
2721
        if (!empty($std->IE)) {
2722
            $this->dom->addChild(
2723
                $this->dest,
2724
                'IE',
2725
                $std->IE,
2726
                true,
2727
                $identificador . 'Inscrição Estadual'
2728
            );
2729
        }
2730
        $xNome = $std->xNome;
2731
        if ($this->tpAmb == '2') {
2732
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2733
        }
2734
        $this->dom->addChild(
2735
            $this->dest,
2736
            'xNome',
2737
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2738
            true,
2739
            $identificador . 'Razão social ou Nome'
2740
        );
2741
        $this->dom->addChild(
2742
            $this->dest,
2743
            'fone',
2744
            $std->fone,
2745
            false,
2746
            $identificador . 'Telefone'
2747
        );
2748
        $this->dom->addChild(
2749
            $this->dest,
2750
            'ISUF',
2751
            $std->ISUF,
2752
            false,
2753
            $identificador . 'Inscrição na SUFRAMA'
2754
        );
2755
        $this->dom->addChild(
2756
            $this->dest,
2757
            'email',
2758
            $std->email,
2759
            false,
2760
            $identificador . 'Endereço de email'
2761
        );
2762
        return $this->dest;
2763
    }
2764
2765
    /**
2766
     * Gera as tags para o elemento: "enderDest" (Informações do Recebedor da Carga)
2767
     * # = 175
2768
     * Nível = 2
2769
     * Os parâmetros para esta função são todos os elementos da tag "enderDest" do
2770
     * tipo elemento (Ele = E|CE|A) e nível 3
2771
     *
2772
     * @return \DOMElement
2773
     */
2774
    public function tagenderDest($std)
2775
    {
2776
        $identificador = '#185 <enderDest> - ';
2777
        $this->enderDest = $this->dom->createElement('enderDest');
2778
        $this->dom->addChild(
2779
            $this->enderDest,
2780
            'xLgr',
2781
            $std->xLgr,
2782
            true,
2783
            $identificador . 'Logradouro'
2784
        );
2785
        $this->dom->addChild(
2786
            $this->enderDest,
2787
            'nro',
2788
            $std->nro,
2789
            true,
2790
            $identificador . 'Número'
2791
        );
2792
        $this->dom->addChild(
2793
            $this->enderDest,
2794
            'xCpl',
2795
            $std->xCpl,
2796
            false,
2797
            $identificador . 'Complemento'
2798
        );
2799
        $this->dom->addChild(
2800
            $this->enderDest,
2801
            'xBairro',
2802
            $std->xBairro,
2803
            true,
2804
            $identificador . 'Bairro'
2805
        );
2806
        $this->dom->addChild(
2807
            $this->enderDest,
2808
            'cMun',
2809
            $std->cMun,
2810
            true,
2811
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2812
        );
2813
        $this->dom->addChild(
2814
            $this->enderDest,
2815
            'xMun',
2816
            $std->xMun,
2817
            true,
2818
            $identificador . 'Nome do município'
2819
        );
2820
        $this->dom->addChild(
2821
            $this->enderDest,
2822
            'CEP',
2823
            $std->CEP,
2824
            false,
2825
            $identificador . 'CEP'
2826
        );
2827
        $this->dom->addChild(
2828
            $this->enderDest,
2829
            'UF',
2830
            $std->UF,
2831
            true,
2832
            $identificador . 'Sigla da UF'
2833
        );
2834
        $this->dom->addChild(
2835
            $this->enderDest,
2836
            'cPais',
2837
            $std->cPais,
2838
            false,
2839
            $identificador . 'Código do país'
2840
        );
2841
        $this->dom->addChild(
2842
            $this->enderDest,
2843
            'xPais',
2844
            $std->xPais,
2845
            false,
2846
            $identificador . 'Nome do país'
2847
        );
2848
        $node = $this->dest->getElementsByTagName("email")->item(0);
2849
        $this->dest->insertBefore($this->enderDest, $node);
2850
        return $this->enderDest;
2851
    }
2852
2853
    /**
2854
     * Gera as tags para o elemento: "vPrest" (Valores da Prestação de Serviço)
2855
     * #187
2856
     * Nível: 1
2857
     * Os parâmetros para esta função são todos os elementos da tag "vPrest" do
2858
     * tipo elemento (Ele = E|CE|A) e nível 2
2859
     *
2860
     * @return \DOMElement
2861
     */
2862
    public function tagvPrest($std)
2863
    {
2864
        $identificador = '#208 <vPrest> - ';
2865
        $this->vPrest = $this->dom->createElement('vPrest');
2866
        $this->dom->addChild(
2867
            $this->vPrest,
2868
            'vTPrest',
2869
            $std->vTPrest,
2870
            true,
2871
            $identificador . 'Valor Total da Prestação do Serviço'
2872
        );
2873
        $this->dom->addChild(
2874
            $this->vPrest,
2875
            'vRec',
2876
            $std->vRec,
2877
            true,
2878
            $identificador . 'Valor a Receber'
2879
        );
2880
        return $this->vPrest;
2881
    }
2882
2883
    /**
2884
     * Gera as tags para o elemento: "Comp" (Componentes do Valor da Prestação)
2885
     * #211
2886
     * Nível: 2
2887
     * Os parâmetros para esta função são todos os elementos da tag "Comp" do
2888
     * tipo elemento (Ele = E|CE|A) e nível 3
2889
     *
2890
     * @return \DOMElement
2891
     */
2892
    public function tagComp($std)
2893
    {
2894
        $identificador = '#65 <pass> - ';
2895
        $this->comp[] = $this->dom->createElement('Comp');
2896
        $posicao = (integer)count($this->comp) - 1;
2897
        $this->dom->addChild(
2898
            $this->comp[$posicao],
2899
            'xNome',
2900
            $std->xNome,
2901
            false,
2902
            $identificador . 'Nome do componente'
2903
        );
2904
        $this->dom->addChild(
2905
            $this->comp[$posicao],
2906
            'vComp',
2907
            $std->vComp,
2908
            false,
2909
            $identificador . 'Valor do componente'
2910
        );
2911
        return $this->comp[$posicao];
2912
    }
2913
    
2914
    /**
2915
     * tagICMS
2916
     * Informações relativas ao ICMS
2917
     * #194
2918
     *
2919
     * @return DOMElement
2920
     */
2921
    public function tagicms($std)
2922
    {
2923
        $identificador = 'N01 <ICMSxx> - ';
2924
        switch ($std->cst) {
2925
            case '00':
2926
                $icms = $this->dom->createElement("ICMS00");
2927
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 00");
2928
                $this->dom->addChild($icms, 'vBC', $std->vBC, true, "$identificador  Valor da BC do ICMS");
2929
                $this->dom->addChild($icms, 'pICMS', $std->pICMS, true, "$identificador  Alíquota do imposto");
2930
                $this->dom->addChild($icms, 'vICMS', $std->vICMS, true, "$identificador  Valor do ICMS");
2931
                break;
2932
            case '20':
2933
                $icms = $this->dom->createElement("ICMS20");
2934
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 20");
2935
                $this->dom->addChild(
2936
                    $icms,
2937
                    'pRedBC',
2938
                    $std->pRedBC,
2939
                    true,
2940
                    "$identificador  Percentual da Redução de BC"
2941
                );
2942
                $this->dom->addChild($icms, 'vBC', $std->vBC, true, "$identificador  Valor da BC do ICMS");
2943
                $this->dom->addChild($icms, 'pICMS', $std->pICMS, true, "$identificador  Alíquota do imposto");
2944
                $this->dom->addChild($icms, 'vICMS', $std->vICMS, true, "$identificador  Valor do ICMS");
2945
                break;
2946
            case '40':
2947
                $icms = $this->dom->createElement("ICMS45");
2948
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 40");
2949
                break;
2950
            case '41':
2951
                $icms = $this->dom->createElement("ICMS45");
2952
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 41");
2953
                break;
2954
            case '51':
2955
                $icms = $this->dom->createElement("ICMS45");
2956
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 51");
2957
                break;
2958
            case '60':
2959
                $icms = $this->dom->createElement("ICMS60");
2960
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 60");
2961
                $this->dom->addChild(
2962
                    $icms,
2963
                    'vBCSTRet',
2964
                    $std->vBCSTRet,
2965
                    true,
2966
                    "$identificador  Valor BC do ICMS ST retido"
2967
                );
2968
                $this->dom->addChild(
2969
                    $icms,
2970
                    'vICMSSTRet',
2971
                    $std->vICMSSTRet,
2972
                    true,
2973
                    "$identificador  Valor do ICMS ST retido"
2974
                );
2975
                $this->dom->addChild(
2976
                    $icms,
2977
                    'pICMSSTRet',
2978
                    $std->pICMSSTRet,
2979
                    true,
2980
                    "$identificador  Valor do ICMS ST retido"
2981
                );
2982
                if ($std->vCred > 0) {
2983
                    $this->dom->addChild($icms, 'vCred', $std->vCred, false, "$identificador  Valor do Crédito");
2984
                }
2985
                break;
2986
            case '90':
2987
                if ($std->outraUF == true) {
2988
                    $icms = $this->dom->createElement("ICMSOutraUF");
2989
                    $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 90");
2990
                    if ($std->pRedBC > 0) {
2991
                        $this->dom->addChild(
2992
                            $icms,
2993
                            'pRedBCOutraUF',
2994
                            $std->pRedBC,
2995
                            false,
2996
                            "$identificador Percentual Red "
2997
                            . "BC Outra UF"
2998
                        );
2999
                    }
3000
                    $this->dom->addChild($icms, 'vBCOutraUF', $std->vBC, true, "$identificador Valor BC ICMS Outra UF");
3001
                    $this->dom->addChild($icms, 'pICMSOutraUF', $std->pICMS, true, "$identificador Alíquota do "
3002
                        . "imposto Outra UF");
3003
                    $this->dom->addChild(
3004
                        $icms,
3005
                        'vICMSOutraUF',
3006
                        $std->vICMS,
3007
                        true,
3008
                        "$identificador Valor ICMS Outra UF"
3009
                    );
3010
                } else {
3011
                    $icms = $this->dom->createElement("ICMS90");
3012
                    $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador Tributação do ICMS = 90");
3013
                    if ($std->pRedBC > 0) {
3014
                        $this->dom->addChild(
3015
                            $icms,
3016
                            'pRedBC',
3017
                            $std->pRedBC,
3018
                            false,
3019
                            "$identificador Percentual Redução BC"
3020
                        );
3021
                    }
3022
                    $this->dom->addChild($icms, 'vBC', $std->vBC, true, "$identificador  Valor da BC do ICMS");
3023
                    $this->dom->addChild($icms, 'pICMS', $std->pICMS, true, "$identificador  Alíquota do imposto");
3024
                    $this->dom->addChild($icms, 'vICMS', $std->vICMS, true, "$identificador  Valor do ICMS");
3025
                    if ($std->vCred > 0) {
3026
                        $this->dom->addChild($icms, 'vCred', $std->vCred, false, "$identificador  Valor do Crédido");
3027
                    }
3028
                }
3029
                break;
3030
            case 'SN':
3031
                $icms = $this->dom->createElement("ICMSSN");
3032
                $this->dom->addChild($icms, 'CST', 90, true, "$identificador Tributação do ICMS = 90");
3033
                $this->dom->addChild($icms, 'indSN', '1', true, "$identificador  Indica se contribuinte é SN");
3034
                break;
3035
        }
3036
        $this->imp = $this->dom->createElement('imp');
3037
        $tagIcms = $this->dom->createElement('ICMS');
3038
        if (isset($icms)) {
3039
            $this->imp->appendChild($tagIcms);
3040
        }
3041
        if (isset($icms)) {
3042
            $tagIcms->appendChild($icms);
3043
        }
3044
        if ($std->vTotTrib > 0) {
3045
            $this->dom->addChild(
3046
                $this->imp,
3047
                'vTotTrib',
3048
                $std->vTotTrib,
3049
                false,
3050
                "$identificador Valor Total dos Tributos"
3051
            );
3052
        }
3053
3054
        if ($std->vICMSUFFim != '' || $std->vICMSUFIni != '') {
3055
            $icmsDifal = $this->dom->createElement("ICMSUFFim");
3056
            $this->dom->addChild(
3057
                $icmsDifal,
3058
                'vBCUFFim',
3059
                $std->vBCUFFim,
3060
                true,
3061
                "$identificador Valor da BC do ICMS na UF
3062
                de término da prestação do serviço de transporte"
3063
            );
3064
            $this->dom->addChild(
3065
                $icmsDifal,
3066
                'pFCPUFFim',
3067
                $std->pFCPUFFim,
3068
                true,
3069
                "$identificador Percentual do ICMS
3070
                relativo ao Fundo de Combate à pobreza (FCP) na UF de término da prestação do serviço de
3071
                transporte"
3072
            );
3073
            $this->dom->addChild(
3074
                $icmsDifal,
3075
                'pICMSUFFim',
3076
                $std->pICMSUFFim,
3077
                true,
3078
                "$identificador Alíquota interna da UF
3079
                de término da prestação do serviço de transporte"
3080
            );
3081
            $this->dom->addChild(
3082
                $icmsDifal,
3083
                'pICMSInter',
3084
                $std->pICMSInter,
3085
                true,
3086
                "$identificador Alíquota interestadual
3087
                das UF envolvidas"
3088
            );
3089
            $this->dom->addChild(
3090
                $icmsDifal,
3091
                'pICMSInterPart',
3092
                $std->pICMSInterPart,
3093
                true,
3094
                "$identificador Percentual
3095
                provisório de partilha entre os estados"
3096
            );
3097
            $this->dom->addChild(
3098
                $icmsDifal,
3099
                'vFCPUFFim',
3100
                $std->vFCPUFFim,
3101
                true,
3102
                "$identificador Valor do ICMS relativo
3103
                ao Fundo de Combate á Pobreza (FCP) da UF de término da prestação"
3104
            );
3105
            $this->dom->addChild(
3106
                $icmsDifal,
3107
                'vICMSUFFim',
3108
                $std->vICMSUFFim,
3109
                true,
3110
                "$identificador Valor do ICMS de
3111
                partilha para a UF de término da prestação do serviço de transporte"
3112
            );
3113
            $this->dom->addChild(
3114
                $icmsDifal,
3115
                'vICMSUFIni',
3116
                $std->vICMSUFIni,
3117
                true,
3118
                "$identificador Valor do ICMS de
3119
                partilha para a UF de início da prestação do serviço de transporte"
3120
            );
3121
3122
            $this->imp->appendChild($icmsDifal);
3123
        }
3124
3125
        return $tagIcms;
3126
    }
3127
3128
    /**
3129
     * tagInfTribFed
3130
     * Informações do Impostos Federais
3131
     * CTe OS
3132
     * @return DOMElement
3133
     */
3134
    public function taginfTribFed($std)
3135
    {
3136
        $identificador = 'N02 <imp> - ';
3137
        $tagInfTribFed = $this->dom->createElement('infTribFed');
3138
3139
        $this->dom->addChild($tagInfTribFed, 'vPIS', $std->vPIS, false, "$identificador  Valor de PIS");
3140
        $this->dom->addChild($tagInfTribFed, 'vCOFINS', $std->vCOFINS, false, "$identificador  Valor de COFINS");
3141
        $this->dom->addChild($tagInfTribFed, 'vIR', $std->vIR, false, "$identificador  Valor de IR");
3142
        $this->dom->addChild($tagInfTribFed, 'vINSS', $std->vINSS, false, "$identificador  Valor de INSS");
3143
        $this->dom->addChild($tagInfTribFed, 'vCSLL', $std->vCSLL, false, "$identificador  Valor de CSLL");
3144
3145
        $this->imp->appendChild($tagInfTribFed);
3146
    }
3147
    
3148
3149
    /**
3150
     * Tag raiz do documento xml
3151
     * Função chamada pelo método [ monta ]
3152
     * @return \DOMElement
3153
     */
3154
    private function buildCTe()
3155
    {
3156
        if (empty($this->CTe)) {
3157
            $this->CTe = $this->dom->createElement('CTe');
3158
            $this->CTe->setAttribute('xmlns', 'http://www.portalfiscal.inf.br/cte');
3159
        }
3160
        return $this->CTe;
3161
    }
3162
3163
    /**
3164
     * Tag raiz do documento xml
3165
     * Função chamada pelo método [ monta ]
3166
     * @return \DOMElement
3167
     */
3168
    private function buildCTeOS()
3169
    {
3170
        if (empty($this->CTe)) {
3171
            $this->CTe = $this->dom->createElement('CTeOS');
3172
            $this->CTe->setAttribute('versao', '3.00');
3173
            $this->CTe->setAttribute('xmlns', 'http://www.portalfiscal.inf.br/cte');
3174
        }
3175
        return $this->CTe;
3176
    }
3177
3178
    /**
3179
     * Gera as tags para o elemento: "Entrega" (Informações ref. a previsão de entrega)
3180
     * #69
3181
     * Nível: 2
3182
     * Os parâmetros para esta função são todos os elementos da tag "Entrega" do
3183
     * tipo elemento (Ele = E|CE|A) e nível 3
3184
     *
3185
     * @return \DOMElement
3186
     */
3187
    private function tagEntrega()
3188
    {
3189
        if ($this->compl == '') {
3190
            $this->compl = $this->dom->createElement('compl');
3191
        }
3192
        if ($this->entrega == '') {
3193
            $this->entrega = $this->dom->createElement('Entrega');
3194
            $this->dom->appChild($this->compl, $this->entrega, 'Falta tag "compl"');
3195
        }
3196
        return $this->entrega;
3197
    }
3198
3199
    /**
3200
     * #241
3201
     * @return type
3202
     */
3203
    public function taginfCTeNorm()
3204
    {
3205
        $this->infCTeNorm = $this->dom->createElement('infCTeNorm');
3206
        return $this->infCTeNorm;
3207
    }
3208
3209
    /**
3210
     * Gera as tags para o elemento: "infCarga" (Informações da Carga do CT-e)
3211
     * #242
3212
     * Nível: 2
3213
     *
3214
     * @return \DOMElement
3215
     */
3216
    public function taginfCarga($std)
3217
    {
3218
        $identificador = '#242 <infCarga> - ';
3219
        $this->infCarga = $this->dom->createElement('infCarga');
3220
        $this->dom->addChild(
3221
            $this->infCarga,
3222
            'vCarga',
3223
            $std->vCarga,
3224
            false,
3225
            $identificador . 'Valor Total da Carga'
3226
        );
3227
        $this->dom->addChild(
3228
            $this->infCarga,
3229
            'proPred',
3230
            $std->proPred,
3231
            true,
3232
            $identificador . 'Produto Predominante'
3233
        );
3234
        $this->dom->addChild(
3235
            $this->infCarga,
3236
            'xOutCat',
3237
            $std->xOutCat,
3238
            false,
3239
            $identificador . 'Outras Caract. da Carga'
3240
        );
3241
        $this->dom->addChild(
3242
            $this->infCarga,
3243
            'vCargaAverb',
3244
            $std->vCargaAverb,
3245
            false,
3246
            $identificador . 'Valor da Carga para
3247
            efeito de averbação'
3248
        );
3249
3250
        return $this->infCarga;
3251
    }
3252
3253
    /**
3254
     * Gera as tags para o elemento: "infCTeNorm" (Informações da Carga do CT-e OS)
3255
     * #253
3256
     * Nível: 2
3257
     * Os parâmetros para esta função são todos os elementos da tag "infServico"
3258
     *
3259
     * @return \DOMElement
3260
     */
3261
    public function taginfServico($std)
3262
    {
3263
        $identificador = '#253 <infServico> - ';
3264
3265
        $this->infServico = $this->dom->createElement('infServico');
3266
        $this->dom->addChild(
3267
            $this->infServico,
3268
            'xDescServ',
3269
            $std->xDescServ,
3270
            true,
3271
            $identificador . 'Descrição do Serviço Prestado'
3272
        );
3273
        $infQ = $this->dom->createElement('infQ');
3274
        $this->dom->addChild($infQ, 'qCarga', $std->qCarga, false, $identificador . 'Quantidade');
3275
3276
        $this->infServico->appendChild($infQ);
3277
3278
        return $this->infServico;
3279
    }
3280
3281
    /**
3282
     * Gera as tags para o elemento: "infQ" (Informações de quantidades da Carga do CT-e)
3283
     * #246
3284
     * Nível: 3
3285
     * Os parâmetros para esta função são todos os elementos da tag "infQ"
3286
     *
3287
     * @return mixed
3288
     */
3289
    public function taginfQ($std)
3290
    {
3291
        $identificador = '#257 <infQ> - ';
3292
        $this->infQ[] = $this->dom->createElement('infQ');
3293
        $posicao = (integer)count($this->infQ) - 1;
3294
        $this->dom->addChild($this->infQ[$posicao], 'cUnid', $std->cUnid, true, $identificador . 'Código da
3295
            Unidade de Medida');
3296
        $this->dom->addChild($this->infQ[$posicao], 'tpMed', $std->tpMed, true, $identificador . 'Tipo da Medida');
3297
        $this->dom->addChild($this->infQ[$posicao], 'qCarga', $std->qCarga, true, $identificador . 'Quantidade');
3298
3299
        return $this->infQ[$posicao];
3300
    }
3301
3302
    public function taginfDoc()
3303
    {
3304
        $this->infDoc = $this->dom->createElement('infDoc');
3305
        return $this->infDoc;
3306
    }
3307
3308
    /**
3309
     * Documentos de Transporte Anterior
3310
     * @return DOMElement|\DOMNode
3311
     */
3312
    public function tagdocAnt()
3313
    {
3314
        $this->docAnt = $this->dom->createElement('docAnt');
3315
        return $this->docAnt;
3316
    }
3317
3318
    /**
3319
     * Informações de identificação dos documentos de Transporte Anterior
3320
     * @return array|DOMElement
3321
     */
3322
    public function tagidDocAnt()
3323
    {
3324
        $this->idDocAnt = $this->dom->createElement('idDocAnt');
3325
        return $this->idDocAnt;
3326
    }
3327
3328
    /**
3329
     * Gera as tags para o elemento: "infNF" (Informações das NF)
3330
     * #262
3331
     * Nível: 3
3332
     * @return mixed
3333
     */
3334
    public function taginfNF($std)
3335
    {
3336
        $identificador = '#262 <infNF> - ';
3337
        $this->infNF[] = $this->dom->createElement('infNF');
3338
        $posicao = (integer)count($this->infNF) - 1;
3339
3340
        $this->dom->addChild($this->infNF[$posicao], 'nRoma', $std->nRoma, false, $identificador . 'Número do
3341
            Romaneio da NF');
3342
        $this->dom->addChild($this->infNF[$posicao], 'nPed', $std->nPed, false, $identificador . 'Número do
3343
            Pedido da NF');
3344
        $this->dom->addChild($this->infNF[$posicao], 'mod', $std->mod, true, $identificador . 'Modelo da
3345
            Nota Fiscal');
3346
        $this->dom->addChild($this->infNF[$posicao], 'serie', $std->serie, true, $identificador . 'Série');
3347
        $this->dom->addChild($this->infNF[$posicao], 'nDoc', $std->nDoc, true, $identificador . 'Número');
3348
        $this->dom->addChild($this->infNF[$posicao], 'dEmi', $std->dEmi, true, $identificador . 'Data de Emissão');
3349
        $this->dom->addChild($this->infNF[$posicao], 'vBC', $std->vBC, true, $identificador . 'Valor da Base
3350
            de Cálculo do ICMS');
3351
        $this->dom->addChild($this->infNF[$posicao], 'vICMS', $std->vICMS, true, $identificador . 'Valor Total
3352
            do ICMS');
3353
        $this->dom->addChild($this->infNF[$posicao], 'vBCST', $std->vBCST, true, $identificador . 'Valor da
3354
            Base de Cálculo do ICMS ST');
3355
        $this->dom->addChild($this->infNF[$posicao], 'vST', $std->vST, true, $identificador . 'Valor Total
3356
            do ICMS ST');
3357
        $this->dom->addChild($this->infNF[$posicao], 'vProd', $std->vProd, true, $identificador . 'Valor Total
3358
            dos Produtos');
3359
        $this->dom->addChild($this->infNF[$posicao], 'vNF', $std->vNF, true, $identificador . 'Valor Total da NF');
3360
        $this->dom->addChild($this->infNF[$posicao], 'nCFOP', $std->nCFOP, true, $identificador . 'CFOP Predominante');
3361
        $this->dom->addChild($this->infNF[$posicao], 'nPeso', $std->nPeso, false, $identificador . 'Peso total em Kg');
3362
        $this->dom->addChild($this->infNF[$posicao], 'PIN', $std->PIN, false, $identificador . 'PIN SUFRAMA');
3363
        $this->dom->addChild($this->infNF[$posicao], 'dPrev', $std->dPrev, false, $identificador . 'Data prevista
3364
            de entrega');
3365
3366
        return $this->infNF[$posicao];
3367
    }
3368
3369
    /**
3370
     * Gera as tags para o elemento: "infNFe" (Informações das NF-e)
3371
     * #297
3372
     * Nível: 3
3373
     * @return mixed
3374
     */
3375
    public function taginfNFe($std)
3376
    {
3377
        $identificador = '#297 <infNFe> - ';
3378
        $this->infNFe[] = $this->dom->createElement('infNFe');
3379
        $posicao = (integer)count($this->infNFe) - 1;
3380
        $this->dom->addChild(
3381
            $this->infNFe[$posicao],
3382
            'chave',
3383
            $std->chave,
3384
            true,
3385
            $identificador . 'Chave de acesso da NF-e'
3386
        );
3387
        $this->dom->addChild(
3388
            $this->infNFe[$posicao],
3389
            'PIN',
3390
            $std->PIN,
3391
            false,
3392
            $identificador . 'PIN SUFRAMA'
3393
        );
3394
        $this->dom->addChild(
3395
            $this->infNFe[$posicao],
3396
            'dPrev',
3397
            $std->dPrev,
3398
            false,
3399
            $identificador . 'Data prevista de entrega'
3400
        );
3401
        return $this->infNFe[$posicao];
3402
    }
3403
3404
    /**
3405
     * Gera as tags para o elemento: "infOutros" (Informações dos demais documentos)
3406
     * #319
3407
     * Nível: 3
3408
     * @return mixed
3409
     */
3410
    public function taginfOutros($std)
3411
    {
3412
        $ident = '#319 <infOutros> - ';
3413
        $this->infOutros[] = $this->dom->createElement('infOutros');
3414
        $posicao = (integer)count($this->infOutros) - 1;
3415
        $this->dom->addChild($this->infOutros[$posicao], 'tpDoc', $std->tpDoc, true, $ident . 'Tipo '
3416
            . 'de documento originário');
3417
        $this->dom->addChild($this->infOutros[$posicao], 'descOutros', $std->descOutros, false, $ident . 'Descrição '
3418
            . 'do documento');
3419
        $this->dom->addChild($this->infOutros[$posicao], 'nDoc', $std->nDoc, false, $ident . 'Número '
3420
            . 'do documento');
3421
        $this->dom->addChild($this->infOutros[$posicao], 'dEmi', $std->dEmi, false, $ident . 'Data de Emissão');
3422
        $this->dom->addChild($this->infOutros[$posicao], 'vDocFisc', $std->vDocFisc, false, $ident . 'Valor '
3423
            . 'do documento');
3424
        $this->dom->addChild($this->infOutros[$posicao], 'dPrev', $std->dPrev, false, $ident . 'Data '
3425
            . 'prevista de entrega');
3426
        return $this->infOutros[$posicao];
3427
    }
3428
3429
    /**
3430
     * Gera as tags para o elemento: "infDocRef" (Informações dos demais documentos)
3431
     * #319
3432
     * Nível: 3
3433
     * @return mixed
3434
     */
3435
    public function taginfDocRef($std)
3436
    {
3437
        $ident = '#319 <infDocRef> - ';
3438
        $this->infDocRef[] = $this->dom->createElement('infDocRef');
3439
        $posicao = (integer)count($this->infDocRef) - 1;
3440
        $this->dom->addChild($this->infDocRef[$posicao], 'nDoc', $std->nDoc, false, $ident . 'Número '
3441
            . 'do documento');
3442
        $this->dom->addChild($this->infDocRef[$posicao], 'serie', $std->serie, false, $ident . 'Série '
3443
            . 'do documento');
3444
        $this->dom->addChild($this->infDocRef[$posicao], 'subserie', $std->subserie, false, $ident . 'Subserie '
3445
            . 'do documento');
3446
        $this->dom->addChild($this->infDocRef[$posicao], 'dEmi', $std->dEmi, false, $ident . 'Data de Emissão');
3447
        $this->dom->addChild($this->infDocRef[$posicao], 'vDoc', $std->vDoc, false, $ident . 'Valor '
3448
            . 'do documento');
3449
        return $this->infDocRef[$posicao];
3450
    }
3451
3452
    /**
3453
     * Gera as tags para o elemento: "emiDocAnt" (Informações dos CT-es Anteriores)
3454
     * #345
3455
     * Nível: 3
3456
     * @return mixed
3457
     */
3458
    public function tagemiDocAnt($std)
3459
    {
3460
        $identificador = '#345 <emiDocAnt> - ';
3461
        $this->emiDocAnt[] = $this->dom->createElement('emiDocAnt');
3462
        $posicao = (integer)count($this->emiDocAnt) - 1;
3463
        if ($std->CNPJ != '') {
3464
            $this->dom->addChild(
3465
                $this->emiDocAnt[$posicao],
3466
                'CNPJ',
3467
                $std->CNPJ,
3468
                true,
3469
                $identificador . 'Número do CNPJ'
3470
            );
3471
            $this->dom->addChild(
3472
                $this->emiDocAnt[$posicao],
3473
                'IE',
3474
                Strings::onlyNumbers($std->IE),
3475
                true,
3476
                $identificador . 'Inscrição Estadual'
3477
            );
3478
            $this->dom->addChild($this->emiDocAnt[$posicao], 'UF', $std->UF, true, $identificador . 'Sigla da UF');
3479
        } else {
3480
            $this->dom->addChild($this->emiDocAnt[$posicao], 'CPF', $std->CPF, true, $identificador . 'Número do CPF');
3481
        }
3482
        $this->dom->addChild(
3483
            $this->emiDocAnt[$posicao],
3484
            'xNome',
3485
            $std->xNome,
3486
            true,
3487
            $identificador . 'Razão Social ou Nome do Expedidor'
3488
        );
3489
3490
        return $this->emiDocAnt[$posicao];
3491
    }
3492
3493
    /**
3494
     * Gera as tags para o elemento: "idDocAntEle" (Informações dos CT-es Anteriores)
3495
     * #348
3496
     * Nível: 4
3497
     * @return mixed
3498
     */
3499
    public function tagidDocAntEle($std)
3500
    {
3501
        $identificador = '#358 <idDocAntEle> - ';
3502
        $this->idDocAntEle[] = $this->dom->createElement('idDocAntEle');
3503
        $posicao = (integer)count($this->idDocAntEle) - 1;
3504
        $this->dom->addChild($this->idDocAntEle[$posicao], 'chCTe', $std->chCTe, true, $identificador . 'Chave de '
3505
            . 'Acesso do CT-e');
3506
3507
        return $this->idDocAntEle[$posicao];
3508
    }
3509
3510
3511
    /**
3512
     * Gera as tags para o elemento: "seg" (Informações de Seguro da Carga)
3513
     * #360
3514
     * Nível: 2
3515
     * @return mixed
3516
     */
3517
    public function tagseg($std)
3518
    {
3519
        $identificador = '#360 <seg> - ';
3520
        $this->seg[] = $this->dom->createElement('seg');
3521
        $posicao = (integer)count($this->seg) - 1;
3522
3523
        $this->dom->addChild($this->seg[$posicao], 'respSeg', $std->respSeg, true, $identificador . 'Responsável
3524
            pelo Seguro');
3525
        $this->dom->addChild($this->seg[$posicao], 'xSeg', $std->xSeg, false, $identificador . 'Nome da
3526
            Seguradora');
3527
        $this->dom->addChild($this->seg[$posicao], 'nApol', $std->nApol, false, $identificador . 'Número da Apólice');
3528
        return $this->seg[$posicao];
3529
    }
3530
3531
    /**
3532
     * Gera as tags para o elemento: "infModal" (Informações do modal)
3533
     * #366
3534
     * Nível: 2
3535
     * @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...
3536
     * @return DOMElement|\DOMNode
3537
     */
3538
    public function taginfModal($std)
3539
    {
3540
        $identificador = '#366 <infModal> - ';
0 ignored issues
show
Unused Code introduced by
$identificador is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
3541
        $this->infModal = $this->dom->createElement('infModal');
3542
        $this->infModal->setAttribute('versaoModal', $std->versaoModal);
3543
        return $this->infModal;
3544
    }
3545
3546
    /**
3547
     * Leiaute - Rodoviário
3548
     * Gera as tags para o elemento: "rodo" (Informações do modal Rodoviário)
3549
     * #1
3550
     * Nível: 0
3551
     * @return DOMElement|\DOMNode
3552
     */
3553
    public function tagrodo($std)
3554
    {
3555
        $identificador = '#1 <rodo> - ';
3556
        $this->rodo = $this->dom->createElement('rodo');
3557
        $this->dom->addChild(
3558
            $this->rodo,
3559
            'RNTRC',
3560
            $std->RNTRC,
3561
            true,
3562
            $identificador . 'Registro nacional de transportadores
3563
            rodoviários de carga'
3564
        );
3565
3566
        return $this->rodo;
3567
    }
3568
3569
    /**
3570
     * Leiaute - Rodoviário
3571
     * Gera as tags para o elemento: "rodo" (Informações do modal Rodoviário) CT-e OS
3572
     * #1
3573
     * Nível: 0
3574
     * @return DOMElement|\DOMNode
3575
     */
3576
    public function tagrodoOS($std)
3577
    {
3578
        $identificador = '#1 <rodoOS> - ';
3579
        $this->rodo = $this->dom->createElement('rodoOS');
3580
        $this->dom->addChild($this->rodo, 'TAF', $std->TAF, false, $identificador .
3581
                             'Termo de Autorização de Fretamento - TAF');
3582
        $this->dom->addChild($this->rodo, 'NroRegEstadual', $std->nroRegEstadual, false, $identificador .
3583
                             'Número do Registro Estadual');
3584
3585
        return $this->rodo;
3586
    }
3587
    
3588
    /**
3589
     * Leiaute - Aéreo
3590
     * Gera as tags para o elemento: "aereo" (Informações do modal Aéreo)
3591
     * @author Newton Pasqualini Filho
3592
     * #1
3593
     * Nível: 0
3594
     * @return DOMElement|\DOMNode
3595
     */
3596
    public function tagaereo($std)
3597
    {
3598
        $identificador = '#1 <aereo> - ';
3599
        $this->aereo = $this->dom->createElement('aereo');
3600
        $this->dom->addChild(
3601
            $this->aereo,
3602
            'nMinu',
3603
            $std->nMinu,
3604
            false,
3605
            $identificador . 'Número da Minuta'
3606
        );
3607
        $this->dom->addChild(
3608
            $this->aereo,
3609
            'nOCA',
3610
            $std->nOCA,
3611
            false,
3612
            $identificador . 'Número Operacional do Conhecimento Aéreo'
3613
        );
3614
        $this->dom->addChild(
3615
            $this->aereo,
3616
            'dPrevAereo',
3617
            $std->dPrevAereo,
3618
            true,
3619
            $identificador . 'Data prevista da entrega'
3620
        );
3621
        if (isset($std->natCarga_xDime) || isset($std->natCarga_cInfManu)) {
3622
            $identificador = '#1 <aereo> - <natCarga> - ';
3623
            $this->natCarga = $this->dom->createElement('natCarga');
3624
            $this->dom->addChild(
3625
                $this->natCarga,
3626
                'xDime',
3627
                $std->natCarga_xDime,
3628
                false,
3629
                $identificador . 'Dimensões da carga, formato: 1234x1234x1234 (cm)'
3630
            );
3631
            if (isset($std->natCarga_cInfManu) && !is_array($std->natCarga_cInfManu)) {
3632
                $std->natCarga_cInfManu = [$std->natCarga_cInfManu];
3633
            }
3634
            $cInfManuX = 0;
3635
            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...
3636
                $cInfManuX++;
3637
                $this->dom->addChild(
3638
                    $this->natCarga,
3639
                    'cInfManu',
3640
                    $cInfManu,
3641
                    false,
3642
                    $identificador . 'Informação de manuseio, com dois dígitos, pode ter mais de uma ocorrência.'
3643
                );
3644
            }
3645
            $this->aereo->appendChild($this->natCarga);
3646
        }
3647
        $identificador = '#1 <aereo> - <tarifa> - ';
3648
        $this->tarifa = $this->dom->createElement('tarifa');
3649
        $this->dom->addChild(
3650
            $this->tarifa,
3651
            'CL',
3652
            $std->tarifa_CL,
3653
            true,
3654
            $identificador . 'Classe da tarifa: M - Tarifa Mínima / G - Tarifa Geral / E - Tarifa Específica'
3655
        );
3656
        $this->dom->addChild(
3657
            $this->tarifa,
3658
            'cTar',
3659
            $std->tarifa_cTar,
3660
            false,
3661
            $identificador . 'Código de três digítos correspondentes à tarifa.'
3662
        );
3663
        $this->dom->addChild(
3664
            $this->tarifa,
3665
            'vTar',
3666
            $std->tarifa_vTar,
3667
            true,
3668
            $identificador . 'Valor da tarifa. 15 posições, sendo 13 inteiras e 2 decimais.'
3669
        );
3670
        $this->aereo->appendChild($this->tarifa);
3671
        return $this->aereo;
3672
    }
3673
3674
    /**
3675
     * CT-e de substituição
3676
     * @param type $std
3677
     * @return type
3678
     */
3679
    public function taginfCteSub($std)
3680
    {
3681
        $identificador = '#149 <infCteSub> - ';
3682
        $this->infCteSub = $this->dom->createElement('infCteSub');
3683
3684
        $this->dom->addChild(
3685
            $this->infCteSub,
3686
            'chCTe',
3687
            $std->chCTe,
3688
            false,
3689
            "$identificador  Chave de acesso do CTe a ser substituído (original)"
3690
        );
3691
        $this->dom->addChild(
3692
            $this->infCteSub,
3693
            'retCteAnu',
3694
            $std->retCteAnu,
3695
            false,
3696
            "$identificador  Chave de acesso do CT-e de Anulação"
3697
        );
3698
        return $this->infCteSub;
3699
    }
3700
    
3701
    
3702
    /**
3703
     * CT-e de substituição - tomaICMS
3704
     * @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...
3705
     * @return type
3706
     */
3707
    public function tagtomaICMS()
3708
    {
3709
        $this->tomaICMS = $this->dom->createElement('tomaICMS');
3710
3711
        return $this->tomaICMS;
3712
    }
3713
    
3714
    /**
3715
     * CT-e de substituição - NF-e
3716
     * @param type $std
3717
     * @return type
3718
     */
3719
    public function tagrefNFe($std)
3720
    {
3721
        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...
3722
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
3723
        }
3724
        $identificador = '#153 <refNFe> - ';
3725
        $this->dom->addChild(
3726
            $this->tomaICMS,
3727
            'refNFe',
3728
            $std->refNFe,
3729
            false,
3730
            "$identificador  Chave de acesso da NF-e emitida pelo tomador"
3731
        );
3732
3733
        return $this->tomaICMS;
3734
    }
3735
    
3736
    /**
3737
     * CT-e de substituição - NF
3738
     * @param type $std
3739
     * @return type
3740
     */
3741
    public function tagrefNF($std)
3742
    {
3743
        $identificador = '#154 <refNFe> - ';
3744
        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...
3745
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
3746
        }
3747
        $this->refNF = $this->dom->createElement('refNF');
3748
        if ($std->CNPJ != '') {
3749
                $this->dom->addChild(
3750
                    $this->refNF,
3751
                    'CNPJ',
3752
                    $std->CNPJ,
3753
                    true,
3754
                    $identificador . 'CNPJ do emitente'
3755
                );
3756
        } elseif ($CPF != '') {
0 ignored issues
show
Bug introduced by
The variable $CPF does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
3757
            $this->dom->addChild(
3758
                $this->refNF,
3759
                'CPF',
3760
                $std->CPF,
3761
                true,
3762
                $identificador . 'CPF do emitente'
3763
            );
3764
        }
3765
        $this->dom->addChild($this->refNF, 'mod', $std->mod, false, $identificador . 'Modelo');
3766
        $this->dom->addChild($this->refNF, 'serie', $std->serie, false, $identificador . 'Série '
3767
            . 'do documento');
3768
        $this->dom->addChild($this->refNF, 'subserie', $std->subserie, false, $identificador . 'Subserie '
3769
            . 'do documento');
3770
        $this->dom->addChild($this->refNF, 'nro', $std->nro, false, $identificador . 'Número');
3771
        $this->dom->addChild($this->refNF, 'valor', $std->valor, false, $identificador . 'Valor');
3772
        $this->dom->addChild($this->refNF, 'dEmi', $std->dEmi, false, $identificador . 'Emissão');
3773
        
3774
        $this->tomaICMS->appendChild($this->refNF);
3775
3776
        return $this->tomaICMS;
3777
    }
3778
    
3779
    /**
3780
     * CT-e de substituição - CT-e
3781
     * @param type $std
3782
     * @return type
3783
     */
3784
    public function tagrefCTe($std)
3785
    {
3786
        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...
3787
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
3788
        }
3789
        $identificador = '#163 <refCTe> - ';
3790
        $this->dom->addChild(
3791
            $this->tomaICMS,
3792
            'refCTe',
3793
            $std->refCTe,
3794
            false,
3795
            "$identificador  Chave de acesso do CT-e emitida pelo tomador"
3796
        );
3797
3798
        return $this->tomaICMS;
3799
    }
3800
    
3801
3802
    /**
3803
     * Leiaute - Rodoviário CTe OS
3804
     * Gera as tags para o elemento: "veic" (Dados dos Veículos)
3805
     * #21
3806
     * Nível: 1
3807
     * @return mixed
3808
     */
3809
    public function tagveic($std)
3810
    {
3811
        $identificador = '#21 <veic> - ';
3812
        $this->veic[] = $this->dom->createElement('veic');
3813
        $posicao = (integer)count($this->veic) - 1;
3814
        if ($std->cInt != '') {
3815
            $this->dom->addChild(
3816
                $this->veic[$posicao],
3817
                'cInt',
3818
                $std->cInt,
3819
                false,
3820
                $identificador . 'Código interno do veículo'
3821
            );
3822
        }
3823
        $this->dom->addChild(
3824
            $this->veic[$posicao],
3825
            'RENAVAM',
3826
            $std->RENAVAM,
3827
            false,
3828
            $identificador . 'RENAVAM do veículo'
3829
        );
3830
        $this->dom->addChild(
3831
            $this->veic[$posicao],
3832
            'placa',
3833
            $std->placa,
3834
            false,
3835
            $identificador . 'Placa do veículo'
3836
        );
3837
        $this->dom->addChild(
3838
            $this->veic[$posicao],
3839
            'tara',
3840
            $std->tara,
3841
            false,
3842
            $identificador . 'Tara em KG'
3843
        );
3844
        $this->dom->addChild(
3845
            $this->veic[$posicao],
3846
            'capKG',
3847
            $std->capKG,
3848
            false,
3849
            $identificador . 'Capacidade em KG'
3850
        );
3851
        $this->dom->addChild(
3852
            $this->veic[$posicao],
3853
            'capM3',
3854
            $std->capM3,
3855
            false,
3856
            $identificador . 'Capacidade em M3'
3857
        );
3858
        $this->dom->addChild(
3859
            $this->veic[$posicao],
3860
            'tpProp',
3861
            $std->tpProp,
3862
            false,
3863
            $identificador . 'Tipo de Propriedade de veículo'
3864
        );
3865
        $this->dom->addChild(
3866
            $this->veic[$posicao],
3867
            'tpVeic',
3868
            $std->tpVeic,
3869
            false,
3870
            $identificador . 'Tipo do veículo'
3871
        );
3872
        $this->dom->addChild(
3873
            $this->veic[$posicao],
3874
            'tpRod',
3875
            $std->tpRod,
3876
            false,
3877
            $identificador . 'Tipo do Rodado'
3878
        );
3879
        $this->dom->addChild(
3880
            $this->veic[$posicao],
3881
            'tpCar',
3882
            $std->tpCar,
3883
            false,
3884
            $identificador . 'Tipo de Carroceria'
3885
        );
3886
        $this->dom->addChild(
3887
            $this->veic[$posicao],
3888
            'UF',
3889
            $std->UF,
3890
            false,
3891
            $identificador . 'UF em que veículo está licenciado'
3892
        );
3893
        if ($std->tpProp == 'T') { // CASO FOR VEICULO DE TERCEIRO
3894
            $this->prop[] = $this->dom->createElement('prop');
3895
            $p = (integer)count($this->prop) - 1;
3896
            if ($std->CNPJ != '') {
3897
                $this->dom->addChild(
3898
                    $this->prop[$p],
3899
                    'CNPJ',
3900
                    $std->CNPJ,
3901
                    true,
3902
                    $identificador . 'CNPJ do proprietario'
3903
                );
3904
            } elseif ($CPF != '') {
0 ignored issues
show
Bug introduced by
The variable $CPF does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
3905
                $this->dom->addChild(
3906
                    $this->prop[$p],
3907
                    'CPF',
3908
                    $CPF,
3909
                    true,
3910
                    $identificador . 'CPF do proprietario'
3911
                );
3912
            }
3913
            $this->dom->addChild(
3914
                $this->prop[$p],
3915
                'RNTRC',
3916
                $std->RNTRC,
3917
                true,
3918
                $identificador . 'RNTRC do proprietario'
3919
            );
3920
            $this->dom->addChild(
3921
                $this->prop[$p],
3922
                'xNome',
3923
                $std->xNome,
3924
                true,
3925
                $identificador . 'Nome do proprietario'
3926
            );
3927
            $this->dom->addChild(
3928
                $this->prop[$p],
3929
                'IE',
3930
                Strings::onlyNumbers($std->IE),
3931
                true,
3932
                $identificador . 'IE do proprietario'
3933
            );
3934
            $this->dom->addChild(
3935
                $this->prop[$p],
3936
                'UF',
3937
                $std->propUF,
3938
                true,
3939
                $identificador . 'UF do proprietario'
3940
            );
3941
            $this->dom->addChild(
3942
                $this->prop[$p],
3943
                'tpProp',
3944
                $std->tpPropProp,
3945
                true,
3946
                $identificador . 'Tipo Proprietário'
3947
            );
3948
            $this->dom->appChild($this->veic[$posicao], $this->prop[$p], 'Falta tag "prop"');
3949
        }
3950
        return $this->veic[$posicao];
3951
    }
3952
3953
    /**
3954
     * Leiaute - Rodoviário
3955
     * Gera as tags para o elemento: "veic" (Dados dos Veículos)
3956
     * #21
3957
     * Nível: 1
3958
     * @return mixed
3959
     */
3960
    public function tagveicCTeOS($std)
3961
    {
3962
        $identificador = '#21 <veic> - ';
3963
        $this->veic = $this->dom->createElement('veic');
3964
3965
        $this->dom->addChild(
3966
            $this->veic,
3967
            'placa',
3968
            $std->placa,
3969
            false,
3970
            $identificador . 'Placa do veículo'
3971
        );
3972
        $this->dom->addChild(
3973
            $this->veic,
3974
            'RENAVAM',
3975
            $std->RENAVAM,
3976
            false,
3977
            $identificador . 'RENAVAM do veículo'
3978
        );
3979
        if ($std->xNome != '') { // CASO FOR VEICULO DE TERCEIRO
3980
            $this->prop = $this->dom->createElement('prop');
3981
            if ($std->CNPJ != '') {
3982
                $this->dom->addChild(
3983
                    $this->prop,
3984
                    'CNPJ',
3985
                    $std->CNPJ,
3986
                    true,
3987
                    $identificador . 'CNPJ do proprietario'
3988
                );
3989
            } elseif ($CPF != '') {
0 ignored issues
show
Bug introduced by
The variable $CPF does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
3990
                $this->dom->addChild(
3991
                    $this->prop,
3992
                    'CPF',
3993
                    $std->CPF,
3994
                    true,
3995
                    $identificador . 'CPF do proprietario'
3996
                );
3997
            }
3998
            $this->dom->addChild(
3999
                $this->prop,
4000
                'TAF',
4001
                $std->taf,
4002
                false,
4003
                $identificador . 'TAF'
4004
            );
4005
            $this->dom->addChild(
4006
                $this->prop,
4007
                'NroRegEstadual',
4008
                $std->nroRegEstadual,
4009
                false,
4010
                $identificador . 'Número do Registro Estadual'
4011
            );
4012
            $this->dom->addChild(
4013
                $this->prop,
4014
                'xNome',
4015
                $std->xNome,
4016
                true,
4017
                $identificador . 'Nome do proprietario'
4018
            );
4019
            $this->dom->addChild(
4020
                $this->prop,
4021
                'IE',
4022
                Strings::onlyNumbers($std->IE),
4023
                true,
4024
                $identificador . 'IE do proprietario'
4025
            );
4026
            $this->dom->addChild(
4027
                $this->prop,
4028
                'UF',
4029
                $std->ufProp,
4030
                true,
4031
                $identificador . 'UF do proprietario'
4032
            );
4033
            $this->dom->addChild(
4034
                $this->prop,
4035
                'tpProp',
4036
                $std->tpProp,
4037
                true,
4038
                $identificador . 'Tipo Proprietário'
4039
            );
4040
            $this->dom->appChild($this->veic, $this->prop, 'Falta tag "prop"');
4041
        }
4042
        $this->dom->addChild(
4043
            $this->veic,
4044
            'UF',
4045
            $std->uf,
4046
            false,
4047
            $identificador . 'UF em que veículo está licenciado'
4048
        );
4049
        return $this->veic;
4050
    }
4051
4052
    /**
4053
     * Gera as tags para o elemento: "infCteComp" (Detalhamento do CT-e complementado)
4054
     * #410
4055
     * Nível: 1
4056
     * @return DOMElement|\DOMNode
4057
     */
4058
    public function taginfCTeComp($std)
4059
    {
4060
        $identificador = '#410 <infCteComp> - ';
4061
        $this->infCteComp = $this->dom->createElement('infCteComp');
4062
        $this->dom->addChild(
4063
            $this->infCteComp,
4064
            'chave',
4065
            $std->chave,
4066
            true,
4067
            $identificador . ' Chave do CT-e complementado'
4068
        );
4069
        return $this->infCteComp;
4070
    }
4071
4072
    /**
4073
     * Gera as tags para o elemento: "infCteAnu" (Detalhamento do CT-e de Anulação)
4074
     * #411
4075
     * Nível: 1
4076
     * @return DOMElement|\DOMNode
4077
     */
4078
    public function taginfCteAnu($std)
4079
    {
4080
        $identificador = '#411 <infCteAnu> - ';
4081
        $this->infCteAnu = $this->dom->createElement('infCteAnu');
4082
        $this->dom->addChild(
4083
            $this->infCteAnu,
4084
            'chCte',
4085
            $std->chave,
4086
            true,
4087
            $identificador . ' Chave do CT-e anulado'
4088
        );
4089
        $this->dom->addChild(
4090
            $this->infCteAnu,
4091
            'dEmi',
4092
            $std->data,
4093
            true,
4094
            $identificador . ' Data de Emissão do CT-e anulado'
4095
        );
4096
        return $this->infCteAnu;
4097
    }
4098
4099
    /**
4100
     * Gera as tags para o elemento: "autXML" (Autorizados para download do XML)
4101
     * #396
4102
     * Nível: 1
4103
     * Os parâmetros para esta função são todos os elementos da tag "autXML"
4104
     *
4105
     * @return boolean
4106
     */
4107
    public function tagautXML($std)
4108
    {
4109
        $identificador = '#396 <autXML> - ';
4110
        $autXML = $this->dom->createElement('autXML');
4111
        if (isset($std->CNPJ) && $std->CNPJ != '') {
4112
            $this->dom->addChild(
4113
                $autXML,
4114
                'CNPJ',
4115
                $std->CNPJ,
4116
                true,
4117
                $identificador . 'CNPJ do Cliente Autorizado'
4118
            );
4119
        } elseif (isset($std->CPF) && $std->CPF != '') {
4120
            $this->dom->addChild(
4121
                $autXML,
4122
                'CPF',
4123
                $std->CPF,
4124
                true,
4125
                $identificador . 'CPF do Cliente Autorizado'
4126
            );
4127
        }
4128
4129
        $this->autXML[] = $autXML;
4130
        return $autXML;
4131
    }
4132
    
4133
    protected function checkCTeKey(Dom $dom)
4134
    {
4135
        $infCTe = $dom->getElementsByTagName("infCte")->item(0);
4136
        $ide = $dom->getElementsByTagName("ide")->item(0);
4137
        $emit = $dom->getElementsByTagName("emit")->item(0);
4138
        $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue;
4139
        $dhEmi = $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue;
4140
        $cnpj = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
4141
        $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue;
4142
        $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
4143
        $nNF = $ide->getElementsByTagName('nCT')->item(0)->nodeValue;
4144
        $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue;
4145
        $cCT = $ide->getElementsByTagName('cCT')->item(0)->nodeValue;
4146
        $chave = str_replace('CTe', '', $infCTe->getAttribute("Id"));
4147
4148
        $dt = new DateTime($dhEmi);
4149
4150
        $chaveMontada = Keys::build(
4151
            $cUF,
4152
            $dt->format('y'),
4153
            $dt->format('m'),
4154
            $cnpj,
4155
            $mod,
4156
            $serie,
4157
            $nNF,
4158
            $tpEmis,
4159
            $cCT
4160
        );
4161
        //caso a chave contida no CTe esteja errada
4162
        //substituir a chave
4163
        if ($chaveMontada != $chave) {
4164
            $ide->getElementsByTagName('cDV')->item(0)->nodeValue = substr($chaveMontada, -1);
4165
            $infCTe = $dom->getElementsByTagName("infCte")->item(0);
4166
            $infCTe->setAttribute("Id", "CTe" . $chaveMontada);
4167
            $this->chCTe = $chaveMontada;
4168
        }
4169
    }
4170
}
4171