Completed
Push — master ( 533603...d08d87 )
by
unknown
06:08 queued 04:05
created

Make::tagenderReceb()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 78

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 78
ccs 0
cts 66
cp 0
rs 8.48
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
namespace NFePHP\CTe;
4
5
/**
6
 *
7
 * @category  Library
8
 * @package   nfephp-org/sped-cte
9
 * @copyright 2009-2016 NFePHP
10
 * @name      Make.php
11
 * @license   http://www.gnu.org/licenses/gpl.html GNU/GPL v.3
12
 * @link      http://github.com/nfephp-org/sped-cte for the canonical source repository
13
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
14
 */
15
16
use 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 $errors = [];
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 = '';
246
    /**
247
     * Prestação sujeito à tributação normal do ICMS
248
     * @var \DOMNode
249
     */
250
    private $ICMS00 = '';
251
    /**
252
     * Prestação sujeito à tributação com redução de BC do ICMS
253
     * @var \DOMNode
254
     */
255
    private $ICMS20 = '';
256
    /**
257
     * ICMS Isento, não Tributado ou diferido
258
     * @var \DOMNode
259
     */
260
    private $ICMS45 = '';
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 = '';
267
    /**
268
     * ICMS Outros
269
     * @var \DOMNode
270
     */
271
    private $ICMS90 = '';
272
    /**
273
     * ICMS devido à UF de origem da prestação, quando diferente da UF do emitente
274
     * @var \DOMNode
275
     */
276
    private $ICMSOutraUF = '';
277
    /**
278
     * Simples Nacional
279
     * @var \DOMNode
280
     */
281
    private $ICMSSN = '';
282
    /**
283
     * Observações adicionais da CT-e
284
     * @var string
285
     */
286
    private $xObs = '';
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();
338
    /**
339
     * Lacres das Unidades de Transporte
340
     * @var array
341
     */
342
    private $lacUnidTransp = array();
343
    /**
344
     * Informações das Unidades de Carga (Containeres/ULD/Outros)
345
     * @var array
346
     */
347
    private $infUnidCarga = array();
348
    /**
349
     * Lacres das Unidades de Carga
350
     * @var array
351
     */
352
    private $lacUnidCarga = array();
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();
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();
393
    /**
394
     * informações dos veículos transportados
395
     * @var array
396
     */
397
    private $veicNovos = array();
398
    /**
399
     * Dados da cobrança do CT-e
400
     * @var \DOMNode
401
     */
402
    private $cobr = '';
403
    /**
404
     * Dados da fatura
405
     * @var \DOMNode
406
     */
407
    private $fat = '';
408
    /**
409
     * Dados das duplicatas
410
     * @var array
411
     */
412
    private $dup = array();
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 = '';
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 = '';
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 Aquaviario
460
     * @var \DOMNode
461
     */
462
    private $aquav = '';
463
    /**
464
     * Informações do modal Aéreo -> Dados da Carga
465
     * @var \DOMNode
466
     */
467
    private $natCarga = '';
468
    /**
469
     * Informações do modal Aéreo -> Tarifas
470
     * @var \DOMNode
471
     */
472
    private $tarifa = '';
473
    /**
474
     * Ordens de Coleta associados
475
     * @var array
476
     */
477
    private $occ = array();
478
    /**
479
     * @var \DOMNode
480
     */
481
    private $emiOcc = array();
482
    /**
483
     * Informações de Vale Pedágio
484
     * @var array
485
     */
486
    private $valePed = array();
487
    /**
488
     * Dados dos Veículos
489
     * @var array
490
     */
491
    private $veic = array();
492
    /**
493
     * Proprietários do Veículo. Só preenchido quando o veículo não pertencer à empresa emitente do CT-e
494
     * @var array
495
     */
496
    private $prop = array();
497
    /**
498
     * Autorizados para download do XML do DF-e
499
     * @var array
500
     */
501
    private $autXML = array();
502
    /**
503
     * Dados do Fretamento - CTe-OS
504
     * @var
505
     */
506
    private $infFretamento;
507
    /**
508
     * @var DOMElement
509
     */
510
    protected $infRespTec;
511
512 1
    public function __construct()
513
    {
514 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...
515 1
        $this->dom->preserveWhiteSpace = false;
516 1
        $this->dom->formatOutput = false;
517 1
    }
518
519
    /**
520
     * Returns xml string and assembly it is necessary
521
     * @return string
522
     */
523
    public function getXML()
524
    {
525
        if (empty($this->xml)) {
526
            $this->montaCTe();
527
        }
528
        return $this->xml;
529
    }
530
531
    /**
532
     * Retorns the key number of NFe (44 digits)
533
     * @return string
534
     */
535
    public function getChave()
536
    {
537
        return $this->chCTe;
538
    }
539
540
    /**
541
     * Returns the model of CTe 57 or 67
542
     * @return int
543
     */
544
    public function getModelo()
545
    {
546
        return $this->mod;
547
    }
548
549
    /**
550
     * Call method of xml assembly. For compatibility only.
551
     * @return boolean
552
     */
553
    public function montaCTe()
554
    {
555
        return $this->monta();
556
    }
557
558
    /**
559
     * Monta o arquivo XML usando as tag's já preenchidas
560
     *
561
     * @return bool
562
     */
563
    public function monta()
564
    {
565
        $this->errors = $this->dom->errors;
566
        if (count($this->errors) > 0) {
567
            return false;
568
        }
569
        if ($this->mod == 57) {
570
            $this->buildCTe();
571
        } else {
572
            return $this->montaCTeOS();
573
        }
574
        if ($this->toma3 != '') {
575
            $this->dom->appChild($this->ide, $this->toma3, 'Falta tag "ide"');
576
        } else {
577
            $this->dom->appChild($this->ide, $this->toma4, 'Falta tag "ide"');
578
        }
579
        $this->dom->appChild($this->infCte, $this->ide, 'Falta tag "infCte"');
580
        if ($this->compl != '') {
581
            if ($this->fluxo != '') {
582
                foreach ($this->pass as $pass) {
583
                    $this->dom->appChild($this->fluxo, $pass, 'Falta tag "fluxo"');
584
                }
585
                $this->dom->appChild($this->compl, $this->fluxo, 'Falta tag "infCte"');
586
            }
587
            if ($this->semData != '') {
588
                $this->tagEntrega();
589
                $this->dom->appChild($this->entrega, $this->semData, 'Falta tag "Entrega"');
590
            }
591
            if ($this->comData != '') {
592
                $this->tagEntrega();
593
                $this->dom->appChild($this->entrega, $this->comData, 'Falta tag "Entrega"');
594
            }
595
            if ($this->noPeriodo != '') {
596
                $this->tagEntrega();
597
                $this->dom->appChild($this->entrega, $this->noPeriodo, 'Falta tag "Entrega"');
598
            }
599
            if ($this->semHora != '') {
600
                $this->tagEntrega();
601
                $this->dom->appChild($this->entrega, $this->semHora, 'Falta tag "Entrega"');
602
            }
603
            if ($this->comHora != '') {
604
                $this->tagEntrega();
605
                $this->dom->appChild($this->entrega, $this->comHora, 'Falta tag "Entrega"');
606
            }
607
            if ($this->noInter != '') {
608
                $this->tagEntrega();
609
                $this->dom->appChild($this->entrega, $this->noInter, 'Falta tag "Entrega"');
610
            }
611
            foreach ($this->obsCont as $obsCont) {
612
                $this->dom->appChild($this->compl, $obsCont, 'Falta tag "compl"');
613
            }
614
            foreach ($this->obsFisco as $obsFisco) {
615
                $this->dom->appChild($this->compl, $obsFisco, 'Falta tag "compl"');
616
            }
617
            $this->dom->appChild($this->infCte, $this->compl, 'Falta tag "infCte"');
618
        }
619
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "emit"');
620
        $this->dom->appChild($this->infCte, $this->emit, 'Falta tag "infCte"');
621
        if ($this->rem != '') {
622
            $this->dom->appChild($this->infCte, $this->rem, 'Falta tag "infCte"');
623
        }
624
        if ($this->exped != '') {
625
            $this->dom->appChild($this->infCte, $this->exped, 'Falta tag "infCte"');
626
        }
627
        if ($this->receb != '') {
628
            $this->dom->appChild($this->infCte, $this->receb, 'Falta tag "infCte"');
629
        }
630
        if ($this->dest != '') {
631
            $this->dom->appChild($this->infCte, $this->dest, 'Falta tag "infCte"');
632
        }
633
        foreach ($this->comp as $comp) {
634
            $this->dom->appChild($this->vPrest, $comp, 'Falta tag "vPrest"');
635
        }
636
        $this->dom->appChild($this->infCte, $this->vPrest, 'Falta tag "infCte"');
637
        $this->dom->appChild($this->infCte, $this->imp, 'Falta tag "imp"');
638
        if ($this->infCteComp != '') { // Caso seja um CTe tipo complemento de valores
639
            $this->dom->appChild($this->infCte, $this->infCteComp, 'Falta tag "infCteComp"');
640
        }
641
        if ($this->infCteAnu != '') { // Caso seja um CTe tipo anulação
642
            $this->dom->appChild($this->infCte, $this->infCteAnu, 'Falta tag "infCteAnu"');
643
        }
644
        if ($this->infCteSub != '') { // Caso seja um CTe tipo anulação
645
            $this->dom->appChild($this->infCte, $this->infCteSub, 'Falta tag "infCteSub"');
646
        }
647
        if ($this->infCTeNorm != '') { // Caso seja um CTe tipo normal
648
            $this->dom->appChild($this->infCte, $this->infCTeNorm, 'Falta tag "infCTeNorm"');
649
            $this->dom->appChild($this->infCTeNorm, $this->infCarga, 'Falta tag "infCarga"');
650
            foreach ($this->infQ as $infQ) {
0 ignored issues
show
Bug introduced by
The expression $this->infQ of type object<DOMNode> is not traversable.
Loading history...
651
                $this->dom->appChild($this->infCarga, $infQ, 'Falta tag "infQ"');
652
            }
653
            foreach ($this->infNF as $infNF) {
654
                $this->dom->appChild($this->infDoc, $infNF, 'Falta tag "infNF"');
655
            }
656
            foreach ($this->infNFe as $infNFe) {
657
                $this->dom->appChild($this->infDoc, $infNFe, 'Falta tag "infNFe"');
658
            }
659
            foreach ($this->infOutros as $infOutros) {
660
                $this->dom->appChild($this->infDoc, $infOutros, 'Falta tag "infOutros"');
661
            }
662
            $this->dom->appChild($this->infCTeNorm, $this->infDoc, 'Falta tag "infCTeNorm"');
663
            if ($this->idDocAntEle != [] || $this->idDocAntPap != []) { //Caso tenha CT-es Anteriores viculados
664
                $this->dom->appChild($this->infCTeNorm, $this->docAnt, 'Falta tag "docAnt"');
665
                foreach ($this->emiDocAnt as $indice => $emiDocAnt) {
666
                    $this->dom->appChild($this->docAnt, $emiDocAnt, 'Falta tag "emiDocAnt"');
667
                    $this->dom->appChild($emiDocAnt, $this->idDocAnt[$indice], 'Falta tag "idDocAnt"');
668
                    if (array_key_exists($indice, $this->idDocAntEle)) {
669
                        foreach ($this->idDocAntEle[$indice] as $idDocAntEle) {
670
                            $this->dom->appChild($this->idDocAnt[$indice], $idDocAntEle, 'Falta tag "emiDocAnt"');
671
                        }
672
                    }
673
                    if (array_key_exists($indice, $this->idDocAntPap)) {
674
                        foreach ($this->idDocAntPap[$indice] as $idDocAntPap) {
675
                            $this->dom->appChild($this->idDocAnt[$indice], $idDocAntPap, 'Falta tag "idDocAntEle"');
676
                        }
677
                    }
678
                }
679
            }
680
            foreach ($this->seg as $seg) {
681
                $this->dom->appChild($this->infCTeNorm, $seg, 'Falta tag "seg"');
682
            }
683
            $this->dom->appChild($this->infCTeNorm, $this->infModal, 'Falta tag "infModal"');
684
            if ($this->modal == '01') {
685
                if ($this->rodo) {
686
                    foreach ($this->occ as $occ) {
687
                        $this->dom->appChild($this->rodo, $occ, 'Falta tag "occ"');
688
                    }
689
                    $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "rodo"');
690
                }
691
            } elseif ($this->modal == '02') {
692
                $this->dom->appChild($this->infModal, $this->aereo, 'Falta tag "aereo"');
693
            } elseif ($this->modal == '03') {
694
                $this->dom->appChild($this->infModal, $this->aquav, 'Falta tag "aquav"');
695
            } else {
696
                throw new Exception('Modal não informado ou não suportado.');
697
            }
698
        }
699
        foreach ($this->veicNovos as $veicNovos) {
700
            $this->dom->appChild($this->infCte, $veicNovos, 'Falta tag "infCte"');
701
        }
702
        if ($this->cobr != '') {
703
            $this->dom->appChild($this->infCte, $this->cobr, 'Falta tag "infCte"');
704
        }
705
        foreach ($this->autXML as $autXML) {
706
            $this->dom->appChild($this->infCte, $autXML, 'Falta tag "infCte"');
707
        }
708
        $this->dom->appChild($this->infCte, $this->infRespTec, 'Falta tag "infCte"');
709
        //[1] tag infCTe
710
        $this->dom->appChild($this->CTe, $this->infCte, 'Falta tag "CTe"');
711
        //[0] tag CTe
712
        $this->dom->appendChild($this->CTe);
713
        // testa da chave
714
        $this->checkCTeKey($this->dom);
715
        $this->xml = $this->dom->saveXML();
716
        return true;
717
    }
718
719
    /**
720
     * Gera as tags para o elemento: "occ" (ordem de coletas)
721
     * #3
722
     * Nível:1
723
     * Os parâmetros para esta função são todos os elementos da tag "occ" do
724
     * tipo elemento (Ele = E|CE|A) e nível 1
725
     *
726
     * @return \DOMElement
727
     */
728
729
    public function tagocc($std)
730
    {
731
        $identificador = '#3 <occ> - ';
732
        $occ = $this->dom->createElement('occ');
733
        $this->dom->addChild(
734
            $occ,
735
            'serie',
736
            $std->serie,
737
            false,
738
            $identificador . 'Série da OCC'
739
        );
740
        $this->dom->addChild(
741
            $occ,
742
            'nOcc',
743
            $std->nOcc,
744
            true,
745
            $identificador . 'Número da Ordem de coleta'
746
        );
747
        $this->dom->addChild(
748
            $occ,
749
            'dEmi',
750
            $std->dEmi,
751
            true,
752
            $identificador . 'Data de emissão da ordem de coleta'
753
        );
754
        //emitente
755
        $identificador = '#7 <emiOcc> - ';
756
        $emiOcc = $this->dom->createElement('emiOcc');
757
        $this->dom->addChild(
758
            $emiOcc,
759
            'CNPJ',
760
            $std->CNPJ,
761
            true,
762
            $identificador . 'Número do CNPJ'
763
        );
764
        $this->dom->addChild(
765
            $emiOcc,
766
            'cInt',
767
            $std->cInt,
768
            false,
769
            $identificador . 'Código interno de uso da transportadora'
770
        );
771
        $this->dom->addChild(
772
            $emiOcc,
773
            'IE',
774
            $std->IE,
775
            true,
776
            $identificador . 'Inscrição Estadual'
777
        );
778
        $this->dom->addChild(
779
            $emiOcc,
780
            'UF',
781
            $std->UF,
782
            true,
783
            $identificador . 'Sigla da UF'
784
        );
785
        $this->dom->addChild(
786
            $emiOcc,
787
            'fone',
788
            $std->fone,
789
            false,
790
            $identificador . 'Telefone'
791
        );
792
793
        $this->dom->appChild($occ, $emiOcc, 'Falta tag "emiOcc"');
794
        $this->occ[] = $occ;
795
        return $occ;
796
    }
797
798
799
    /**
800
     * Monta o arquivo XML usando as tag's já preenchidas
801
     *
802
     * @return bool
803
     */
804
    public function montaCTeOS()
805
    {
806
        $this->errors = $this->dom->errors;
807
        if (count($this->errors) > 0) {
808
            return false;
809
        }
810
        $this->buildCTeOS();
811
        if ($this->infPercurso != '') {
812
            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...
813
                $this->dom->appChild($this->ide, $perc, 'Falta tag "infPercurso"');
814
            }
815
        }
816
        $this->dom->appChild($this->infCte, $this->ide, 'Falta tag "infCte"');
817
        if ($this->compl != '') {
818
            $this->dom->appChild($this->infCte, $this->compl, 'Falta tag "infCte"');
819
        }
820
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "emit"');
821
        $this->dom->appChild($this->infCte, $this->emit, 'Falta tag "infCte"');
822
        if ($this->toma != '') {
823
            $this->dom->appChild($this->infCte, $this->toma, 'Falta tag "infCte"');
824
        }
825
        foreach ($this->comp as $comp) {
826
            $this->dom->appChild($this->vPrest, $comp, 'Falta tag "vPrest"');
827
        }
828
        $this->dom->appChild($this->infCte, $this->vPrest, 'Falta tag "infCte"');
829
        $this->dom->appChild($this->infCte, $this->imp, 'Falta tag "imp"');
830
        if ($this->infCteComp != '') { // Caso seja um CTe tipo complemento de valores
831
            $this->dom->appChild($this->infCte, $this->infCteComp, 'Falta tag "infCteComp"');
832
        } elseif ($this->infCteAnu != '') { // Caso seja um CTe tipo anulação
833
            $this->dom->appChild($this->infCte, $this->infCteAnu, 'Falta tag "infCteAnu"');
834
        } elseif ($this->infCTeNorm != '') { // Caso seja um CTe tipo normal
835
            $this->dom->appChild($this->infCte, $this->infCTeNorm, 'Falta tag "infCTeNorm"');
836
            $this->dom->appChild($this->infCTeNorm, $this->infServico, 'Falta tag "infServico"');
837
            foreach ($this->infDocRef as $infDocRef) {
838
                $this->dom->appChild($this->infCTeNorm, $infDocRef, 'Falta tag "infDocRef"');
839
            }
840
            foreach ($this->seg as $seg) {
841
                $this->dom->appChild($this->infCTeNorm, $seg, 'Falta tag "seg"');
842
            }
843
            if ($this->infModal != '') {
844
                $this->dom->appChild($this->infCTeNorm, $this->infModal, 'Falta tag "infModal"');
845
                $this->dom->appChild($this->rodo, $this->veic, 'Falta tag "veic"');
846
                $this->dom->appChild($this->rodo, $this->infFretamento, 'Falta tag "infFretamento"');
847
                $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "rodo"');
848
            }
849
        }
850
        if ($this->cobr != '') {
851
            $this->dom->appChild($this->infCte, $this->cobr, 'Falta tag "infCte"');
852
        }
853
        foreach ($this->autXML as $autXML) {
854
            $this->dom->appChild($this->infCte, $autXML, 'Falta tag "infCte"');
855
        }
856
        $this->dom->appChild($this->infCte, $this->infRespTec, 'Falta tag "infCte"');
857
        $this->dom->appChild($this->CTe, $this->infCte, 'Falta tag "CTe"');
858
        $this->dom->appendChild($this->CTe);
859
        // testa da chave
860
        $this->checkCTeKey($this->dom);
861
        $this->xml = $this->dom->saveXML();
862
        return true;
863
    }
864
865
    /**
866
     * Gera o grupo básico: Informações do CT-e
867
     * #1
868
     * Nível: 0
869
     * @param stdClass $std
870
     * @return \DOMElement
871
     */
872 1
    public function taginfCTe($std)
873
    {
874 1
        $chave = preg_replace('/[^0-9]/', '', $std->Id);
875 1
        $this->infCte = $this->dom->createElement('infCte');
876 1
        $this->infCte->setAttribute('Id', 'CTe' . $chave);
877 1
        $this->infCte->setAttribute('versao', $std->versao);
878 1
        return $this->infCte;
879
    }
880
881
    /**
882
     * Gera as tags para o elemento: Identificação do CT-e
883
     * #4
884
     * Nível: 1
885
     * @param stdClass $std
886
     * @return DOMElement|\DOMNode
887
     */
888
    public function tagide($std)
889
    {
890
        $this->tpAmb = $std->tpAmb;
891
        $this->mod = $std->mod;
892
        $identificador = '#4 <ide> - ';
893
        $this->ide = $this->dom->createElement('ide');
894
        $this->dom->addChild(
895
            $this->ide,
896
            'cUF',
897
            $std->cUF,
898
            true,
899
            $identificador . 'Código da UF do emitente do CT-e'
900
        );
901
        $this->dom->addChild(
902
            $this->ide,
903
            'cCT',
904
            str_pad($std->cCT, 8, '0', STR_PAD_LEFT),
905
            true,
906
            $identificador . 'Código numérico que compõe a Chave de Acesso'
907
        );
908
        $this->dom->addChild(
909
            $this->ide,
910
            'CFOP',
911
            $std->CFOP,
912
            true,
913
            $identificador . 'Código Fiscal de Operações e Prestações'
914
        );
915
        $this->dom->addChild(
916
            $this->ide,
917
            'natOp',
918
            Strings::replaceSpecialsChars(substr(trim($std->natOp), 0, 60)),
919
            true,
920
            $identificador . 'Natureza da Operação'
921
        );
922
        $this->dom->addChild(
923
            $this->ide,
924
            'mod',
925
            $std->mod,
926
            true,
927
            $identificador . 'Modelo do documento fiscal'
928
        );
929
        $this->dom->addChild(
930
            $this->ide,
931
            'serie',
932
            $std->serie,
933
            true,
934
            $identificador . 'Série do CT-e'
935
        );
936
        $this->dom->addChild(
937
            $this->ide,
938
            'nCT',
939
            $std->nCT,
940
            true,
941
            $identificador . 'Número do CT-e'
942
        );
943
        $this->dom->addChild(
944
            $this->ide,
945
            'dhEmi',
946
            $std->dhEmi,
947
            true,
948
            $identificador . 'Data e hora de emissão do CT-e'
949
        );
950
        $this->dom->addChild(
951
            $this->ide,
952
            'tpImp',
953
            $std->tpImp,
954
            true,
955
            $identificador . 'Formato de impressão do DACTE'
956
        );
957
        $this->dom->addChild(
958
            $this->ide,
959
            'tpEmis',
960
            $std->tpEmis,
961
            true,
962
            $identificador . 'Forma de emissão do CT-e'
963
        );
964
        $this->dom->addChild(
965
            $this->ide,
966
            'cDV',
967
            $std->cDV,
968
            false,
969
            $identificador . 'Digito Verificador da chave de acesso do CT-e'
970
        );
971
        $this->dom->addChild(
972
            $this->ide,
973
            'tpAmb',
974
            $std->tpAmb,
975
            true,
976
            $identificador . 'Tipo do Ambiente'
977
        );
978
        $this->dom->addChild(
979
            $this->ide,
980
            'tpCTe',
981
            $std->tpCTe,
982
            true,
983
            $identificador . 'Tipo do CT-e'
984
        );
985
        $this->dom->addChild(
986
            $this->ide,
987
            'procEmi',
988
            $std->procEmi,
989
            true,
990
            $identificador . 'Identificador do processo de emissão do CT-e'
991
        );
992
        $this->dom->addChild(
993
            $this->ide,
994
            'verProc',
995
            $std->verProc,
996
            true,
997
            $identificador . 'Versão do processo de emissão'
998
        );
999
        if ($this->mod == 57) {
1000
            $this->dom->addChild(
1001
                $this->ide,
1002
                'indGlobalizado',
1003
                $std->indGlobalizado,
1004
                false,
1005
                $identificador . 'Indicador de CT-e Globalizado'
1006
            );
1007
        }
1008
        $this->dom->addChild(
1009
            $this->ide,
1010
            'cMunEnv',
1011
            $std->cMunEnv,
1012
            true,
1013
            $identificador . 'Código do Município de envio do CT-e (de onde o documento foi transmitido)'
1014
        );
1015
        $this->dom->addChild(
1016
            $this->ide,
1017
            'xMunEnv',
1018
            $std->xMunEnv,
1019
            true,
1020
            $identificador . 'Nome do Município de envio do CT-e (de onde o documento foi transmitido)'
1021
        );
1022
        $this->dom->addChild(
1023
            $this->ide,
1024
            'UFEnv',
1025
            $std->UFEnv,
1026
            true,
1027
            $identificador . 'Sigla da UF de envio do CT-e (de onde o documento foi transmitido)'
1028
        );
1029
        $this->dom->addChild(
1030
            $this->ide,
1031
            'modal',
1032
            $std->modal,
1033
            true,
1034
            $identificador . 'Modal'
1035
        );
1036
        $this->modal = $std->modal;
1037
        $this->dom->addChild(
1038
            $this->ide,
1039
            'tpServ',
1040
            $std->tpServ,
1041
            true,
1042
            $identificador . 'Tipo do Serviço'
1043
        );
1044
        if ($this->mod == 67) {
1045
            $this->dom->addChild(
1046
                $this->ide,
1047
                'indIEToma',
1048
                $std->indIEToma,
1049
                true,
1050
                $identificador . 'Indicador do papel do tomador na prestação do serviço'
1051
            );
1052
        }
1053
        $this->dom->addChild(
1054
            $this->ide,
1055
            'cMunIni',
1056
            $std->cMunIni,
1057
            true,
1058
            $identificador . 'Nome do Município do início da prestação'
1059
        );
1060
        $this->dom->addChild(
1061
            $this->ide,
1062
            'xMunIni',
1063
            $std->xMunIni,
1064
            true,
1065
            $identificador . 'Nome do Município do início da prestação'
1066
        );
1067
        $this->dom->addChild(
1068
            $this->ide,
1069
            'UFIni',
1070
            $std->UFIni,
1071
            true,
1072
            $identificador . 'UF do início da prestação'
1073
        );
1074
        $this->dom->addChild(
1075
            $this->ide,
1076
            'cMunFim',
1077
            $std->cMunFim,
1078
            true,
1079
            $identificador . 'Código do Município de término da prestação'
1080
        );
1081
        $this->dom->addChild(
1082
            $this->ide,
1083
            'xMunFim',
1084
            $std->xMunFim,
1085
            true,
1086
            $identificador . 'Nome do Município do término da prestação'
1087
        );
1088
        $this->dom->addChild(
1089
            $this->ide,
1090
            'UFFim',
1091
            $std->UFFim,
1092
            true,
1093
            $identificador . 'UF do término da prestação'
1094
        );
1095
        if ($this->mod == 57) {
1096
            $this->dom->addChild(
1097
                $this->ide,
1098
                'retira',
1099
                $std->retira,
1100
                true,
1101
                $identificador . 'Indicador se o Recebedor retira no Aeroporto, Filial, Porto ou Estação de Destino'
1102
            );
1103
            $this->dom->addChild(
1104
                $this->ide,
1105
                'xDetRetira',
1106
                $std->xDetRetira,
1107
                false,
1108
                $identificador . 'Detalhes do retira'
1109
            );
1110
            $this->dom->addChild(
1111
                $this->ide,
1112
                'indIEToma',
1113
                $std->indIEToma,
1114
                true,
1115
                $identificador . 'Indicador do papel do tomador na prestação do serviço'
1116
            );
1117
        }
1118
        $this->dom->addChild(
1119
            $this->ide,
1120
            'dhCont',
1121
            $std->dhCont,
1122
            false,
1123
            $identificador . 'Data e Hora da entrada em contingência'
1124
        );
1125
        $this->dom->addChild(
1126
            $this->ide,
1127
            'xJust',
1128
            Strings::replaceSpecialsChars(substr(trim($std->xJust), 0, 256)),
1129
            false,
1130
            $identificador . 'Justificativa da entrada em contingência'
1131
        );
1132
        $this->tpServ = $std->tpServ;
1133
        return $this->ide;
1134
    }
1135
1136
    public function taginfPercurso($std)
1137
    {
1138
        $identificador = '#4 <infPercurso> - ';
1139
        $this->infPercurso[] = $this->dom->createElement('infPercurso');
1140
        $posicao = (int)count($this->infPercurso) - 1;
1141
        $this->dom->addChild(
1142
            $this->infPercurso[$posicao],
1143
            'UFPer',
1144
            $std->uf,
1145
            true,
1146
            $identificador . 'Código da UF do percurso'
1147
        );
1148
1149
        return $this->infPercurso[$posicao];
1150
    }
1151
1152
    /**
1153
     * Gera as tags para o elemento: toma3 (Indicador do "papel" do tomador do serviço no CT-e)
1154
     * e adiciona ao grupo ide
1155
     * #35
1156
     * Nível: 2
1157
     * @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...
1158
     * @param stdClass $std
1159
     * @return \DOMElement
1160
     */
1161
    public function tagtoma3($std)
1162
    {
1163
        $identificador = '#35 <toma3> - ';
1164
        $this->toma3 = $this->dom->createElement('toma3');
1165
        $this->dom->addChild(
1166
            $this->toma3,
1167
            'toma',
1168
            $std->toma,
1169
            true,
1170
            $identificador . 'Tomador do Serviço'
1171
        );
1172
        return $this->toma3;
1173
    }
1174
1175
    /**
1176
     * Gera as tags para o elemento: toma4 (Indicador do "papel" do tomador
1177
     * do serviço no CT-e) e adiciona ao grupo ide
1178
     * #37
1179
     * Nível: 2
1180
     * @param stdClass $std
1181
     * @return \DOMElement
1182
     */
1183
    public function tagtoma4($std)
1184
    {
1185
        $identificador = '#37 <toma4> - ';
1186
        $this->toma4 = $this->dom->createElement('toma4');
1187
        $this->dom->addChild(
1188
            $this->toma4,
1189
            'toma',
1190
            $std->toma,
1191
            true,
1192
            $identificador . 'Tomador do Serviço'
1193
        );
1194
        if ($std->CNPJ != '') {
1195
            $this->dom->addChild(
1196
                $this->toma4,
1197
                'CNPJ',
1198
                $std->CNPJ,
1199
                true,
1200
                $identificador . 'Número do CNPJ'
1201
            );
1202
        } elseif ($std->CPF != '') {
1203
            $this->dom->addChild(
1204
                $this->toma4,
1205
                'CPF',
1206
                $std->CPF,
1207
                true,
1208
                $identificador . 'Número do CPF'
1209
            );
1210
        } else {
1211
            $this->dom->addChild(
1212
                $this->toma4,
1213
                'CNPJ',
1214
                $std->CNPJ,
1215
                true,
1216
                $identificador . 'Número do CNPJ'
1217
            );
1218
            $this->dom->addChild(
1219
                $this->toma4,
1220
                'CPF',
1221
                $std->CPF,
1222
                true,
1223
                $identificador . 'Número do CPF'
1224
            );
1225
        }
1226
        $this->dom->addChild(
1227
            $this->toma4,
1228
            'IE',
1229
            $std->IE,
1230
            false,
1231
            $identificador . 'Inscrição Estadual'
1232
        );
1233
        $this->dom->addChild(
1234
            $this->toma4,
1235
            'xNome',
1236
            $std->xNome,
1237
            true,
1238
            $identificador . 'Razão Social ou Nome'
1239
        );
1240
        $this->dom->addChild(
1241
            $this->toma4,
1242
            'xFant',
1243
            $std->xFant,
1244
            false,
1245
            $identificador . 'Nome Fantasia'
1246
        );
1247
        $this->dom->addChild(
1248
            $this->toma4,
1249
            'fone',
1250
            $std->fone,
1251
            false,
1252
            $identificador . 'Telefone'
1253
        );
1254
        $this->dom->addChild(
1255
            $this->toma4,
1256
            'email',
1257
            $std->email,
1258
            false,
1259
            $identificador . 'Endereço de email'
1260
        );
1261
        return $this->toma4;
1262
    }
1263
1264
    /**
1265
     * Gera as tags para o elemento: toma4 (Indicador do "papel" do tomador
1266
     * do serviço no CT-e OS) e adiciona ao grupo ide
1267
     * #37
1268
     * Nível: 2
1269
     *
1270
     * @return \DOMElement
1271
     */
1272
    public function tagtomador($std)
1273
    {
1274
        $identificador = '#37 <toma> - ';
1275
        $this->toma = $this->dom->createElement('toma');
1276
        if ($std->CNPJ != '') {
1277
            $this->dom->addChild(
1278
                $this->toma,
1279
                'CNPJ',
1280
                $std->CNPJ,
1281
                true,
1282
                $identificador . 'Número do CNPJ'
1283
            );
1284
        } elseif ($std->CPF != '') {
1285
            $this->dom->addChild(
1286
                $this->toma,
1287
                'CPF',
1288
                $std->CPF,
1289
                true,
1290
                $identificador . 'Número do CPF'
1291
            );
1292
        } else {
1293
            $this->dom->addChild(
1294
                $this->toma,
1295
                'CNPJ',
1296
                $std->CNPJ,
1297
                true,
1298
                $identificador . 'Número do CNPJ'
1299
            );
1300
            $this->dom->addChild(
1301
                $this->toma,
1302
                'CPF',
1303
                $std->CPF,
1304
                true,
1305
                $identificador . 'Número do CPF'
1306
            );
1307
        }
1308
        $this->dom->addChild(
1309
            $this->toma,
1310
            'IE',
1311
            $std->IE,
1312
            false,
1313
            $identificador . 'Inscrição Estadual'
1314
        );
1315
        $this->dom->addChild(
1316
            $this->toma,
1317
            'xNome',
1318
            $std->xNome,
1319
            true,
1320
            $identificador . 'Razão Social ou Nome'
1321
        );
1322
        $this->dom->addChild(
1323
            $this->toma,
1324
            'xFant',
1325
            $std->xFant,
1326
            false,
1327
            $identificador . 'Nome Fantasia'
1328
        );
1329
        $this->dom->addChild(
1330
            $this->toma,
1331
            'fone',
1332
            $std->fone,
1333
            false,
1334
            $identificador . 'Telefone'
1335
        );
1336
        //Endereço Tomador
1337
        $this->enderToma = $this->dom->createElement('enderToma');
1338
        $this->dom->addChild(
1339
            $this->enderToma,
1340
            'xLgr',
1341
            $std->xLgr,
1342
            true,
1343
            $identificador . 'Logradouro'
1344
        );
1345
        $this->dom->addChild(
1346
            $this->enderToma,
1347
            'nro',
1348
            $std->nro,
1349
            true,
1350
            $identificador . 'Número'
1351
        );
1352
        $this->dom->addChild(
1353
            $this->enderToma,
1354
            'xCpl',
1355
            $std->xCpl,
1356
            false,
1357
            $identificador . 'Complemento'
1358
        );
1359
        $this->dom->addChild(
1360
            $this->enderToma,
1361
            'xBairro',
1362
            $std->xBairro,
1363
            true,
1364
            $identificador . 'Bairro'
1365
        );
1366
        $this->dom->addChild(
1367
            $this->enderToma,
1368
            'cMun',
1369
            $std->cMun,
1370
            true,
1371
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
1372
        );
1373
        $this->dom->addChild(
1374
            $this->enderToma,
1375
            'xMun',
1376
            $std->xMun,
1377
            true,
1378
            $identificador . 'Nome do município'
1379
        );
1380
        $this->dom->addChild(
1381
            $this->enderToma,
1382
            'CEP',
1383
            $std->CEP,
1384
            false,
1385
            $identificador . 'CEP'
1386
        );
1387
        $this->dom->addChild(
1388
            $this->enderToma,
1389
            'UF',
1390
            $std->UF,
1391
            true,
1392
            $identificador . 'Sigla da UF'
1393
        );
1394
        $this->dom->addChild(
1395
            $this->enderToma,
1396
            'cPais',
1397
            $std->cPais,
1398
            false,
1399
            $identificador . 'Código do país'
1400
        );
1401
        $this->dom->addChild(
1402
            $this->enderToma,
1403
            'xPais',
1404
            $std->xPais,
1405
            false,
1406
            $identificador . 'Nome do país'
1407
        );
1408
        $this->dom->appChild($this->toma, $this->enderToma, 'Falta tag "enderToma"');
1409
        $this->dom->addChild(
1410
            $this->toma,
1411
            'email',
1412
            $std->email,
1413
            false,
1414
            $identificador . 'Endereço de email'
1415
        );
1416
        return $this->toma;
1417
    }
1418
1419
    /**
1420
     * Gera as tags para o elemento: "enderToma" (Dados do endereço) e adiciona ao grupo "toma4"
1421
     * #45
1422
     * Nível: 3
1423
     *
1424
     * @return \DOMElement
1425
     */
1426
    public function tagenderToma($std)
1427
    {
1428
        $identificador = '#45 <enderToma> - ';
1429
        $this->enderToma = $this->dom->createElement('enderToma');
1430
        $this->dom->addChild(
1431
            $this->enderToma,
1432
            'xLgr',
1433
            $std->xLgr,
1434
            true,
1435
            $identificador . 'Logradouro'
1436
        );
1437
        $this->dom->addChild(
1438
            $this->enderToma,
1439
            'nro',
1440
            $std->nro,
1441
            true,
1442
            $identificador . 'Número'
1443
        );
1444
        $this->dom->addChild(
1445
            $this->enderToma,
1446
            'xCpl',
1447
            $std->xCpl,
1448
            false,
1449
            $identificador . 'Complemento'
1450
        );
1451
        $this->dom->addChild(
1452
            $this->enderToma,
1453
            'xBairro',
1454
            $std->xBairro,
1455
            true,
1456
            $identificador . 'Bairro'
1457
        );
1458
        $this->dom->addChild(
1459
            $this->enderToma,
1460
            'cMun',
1461
            $std->cMun,
1462
            true,
1463
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
1464
        );
1465
        $this->dom->addChild(
1466
            $this->enderToma,
1467
            'xMun',
1468
            $std->xMun,
1469
            true,
1470
            $identificador . 'Nome do município'
1471
        );
1472
        $this->dom->addChild(
1473
            $this->enderToma,
1474
            'CEP',
1475
            $std->CEP,
1476
            false,
1477
            $identificador . 'CEP'
1478
        );
1479
        $this->dom->addChild(
1480
            $this->enderToma,
1481
            'UF',
1482
            $std->UF,
1483
            true,
1484
            $identificador . 'Sigla da UF'
1485
        );
1486
        $this->dom->addChild(
1487
            $this->enderToma,
1488
            'cPais',
1489
            $std->cPais,
1490
            false,
1491
            $identificador . 'Código do país'
1492
        );
1493
        $this->dom->addChild(
1494
            $this->enderToma,
1495
            'xPais',
1496
            $std->xPais,
1497
            false,
1498
            $identificador . 'Nome do país'
1499
        );
1500
1501
        if (!empty($this->toma4)) {
1502
            $this->toma4->insertBefore($this->enderToma, $this->toma4->getElementsByTagName("email")->item(0));
1503
        }
1504
        return $this->enderToma;
1505
    }
1506
1507
    /**
1508
     * Gera as tags para o elemento: "compl" (Dados complementares do CT-e para fins operacionais ou comerciais)
1509
     * #59
1510
     * Nível: 1
1511
     *
1512
     * @return \DOMElement
1513
     */
1514
    public function tagcompl($std)
1515
    {
1516
        $identificador = '#59 <compl> - ';
1517
        if ($this->compl == '') {
1518
            $this->compl = $this->dom->createElement('compl');
1519
        }
1520
        $this->dom->addChild(
1521
            $this->compl,
1522
            'xCaracAd',
1523
            $std->xCaracAd,
1524
            false,
1525
            $identificador . 'Característica adicional do transporte'
1526
        );
1527
        $this->dom->addChild(
1528
            $this->compl,
1529
            'xCaracSer',
1530
            $std->xCaracSer,
1531
            false,
1532
            $identificador . 'Característica adicional do serviço'
1533
        );
1534
        $this->dom->addChild(
1535
            $this->compl,
1536
            'xEmi',
1537
            $std->xEmi,
1538
            false,
1539
            $identificador . 'Funcionário emissor do CTe'
1540
        );
1541
        if ($this->mod == 57) {
1542
            $this->dom->addChild(
1543
                $this->compl,
1544
                'origCalc',
1545
                $std->origCalc,
1546
                false,
1547
                $identificador . 'Município de origem para efeito de cálculo do frete'
1548
            );
1549
            $this->dom->addChild(
1550
                $this->compl,
1551
                'destCalc',
1552
                $std->destCalc,
1553
                false,
1554
                $identificador . 'Município de destino para efeito de cálculo do frete'
1555
            );
1556
        }
1557
        $this->dom->addChild(
1558
            $this->compl,
1559
            'xObs',
1560
            $std->xObs,
1561
            false,
1562
            $identificador . 'Observações Gerais'
1563
        );
1564
        return $this->compl;
1565
    }
1566
1567
    /**
1568
     * Gera as tags para o elemento: "compl" (Dados complementares do CT-e OS para fins operacionais ou comerciais)
1569
     * #59
1570
     * Nível: 1
1571
     *
1572
     * @return \DOMElement
1573
     */
1574
    public function tagcomplCTeOs($std)
1575
    {
1576
        $identificador = '#59 <compl> - ';
1577
        $this->compl = $this->dom->createElement('compl');
1578
        $this->dom->addChild(
1579
            $this->compl,
1580
            'xCaracAd',
1581
            $std->xCaracAd,
1582
            false,
1583
            $identificador . 'Característica adicional do transporte'
1584
        );
1585
        $this->dom->addChild(
1586
            $this->compl,
1587
            'xCaracSer',
1588
            $std->xCaracSer,
1589
            false,
1590
            $identificador . 'Característica adicional do serviço'
1591
        );
1592
        $this->dom->addChild(
1593
            $this->compl,
1594
            'xEmi',
1595
            $std->xEmi,
1596
            false,
1597
            $identificador . 'Funcionário emissor do CTe'
1598
        );
1599
        $this->dom->addChild(
1600
            $this->compl,
1601
            'xObs',
1602
            $std->xObs,
1603
            false,
1604
            $identificador . 'Observações Gerais'
1605
        );
1606
        return $this->compl;
1607
    }
1608
1609
    /**
1610
     * Gera as tags para o elemento: "fluxo" (Previsão do fluxo da carga)
1611
     * #63
1612
     * Nível: 2
1613
     * Os parâmetros para esta função são todos os elementos da tag "fluxo" do
1614
     * tipo elemento (Ele = E|CE|A) e nível 3
1615
     *
1616
     * @return \DOMElement
1617
     */
1618
    public function tagfluxo($std)
1619
    {
1620
        $identificador = '#63 <fluxo> - ';
1621
        $this->fluxo = $this->dom->createElement('fluxo');
1622
        $this->dom->addChild(
1623
            $this->fluxo,
1624
            'xOrig',
1625
            $std->xOrig,
1626
            false,
1627
            $identificador . 'Sigla ou código interno da Filial/Porto/Estação/ Aeroporto de Origem'
1628
        );
1629
        $this->dom->addChild(
1630
            $this->fluxo,
1631
            'xDest',
1632
            $std->xDest,
1633
            false,
1634
            $identificador . 'Sigla ou código interno da Filial/Porto/Estação/Aeroporto de Destino'
1635
        );
1636
        $this->dom->addChild(
1637
            $this->fluxo,
1638
            'xRota',
1639
            $std->xRota,
1640
            false,
1641
            $identificador . 'Código da Rota de Entrega'
1642
        );
1643
        return $this->fluxo;
1644
    }
1645
1646
    /**
1647
     * Gera as tags para o elemento: "pass"
1648
     * #65
1649
     * Nível: 3
1650
     *
1651
     * @return \DOMElement
1652
     */
1653
    public function tagpass($std)
1654
    {
1655
        $identificador = '#65 <pass> - ';
1656
        $this->pass[] = $this->dom->createElement('pass');
1657
        $posicao = (int)count($this->pass) - 1;
1658
        $this->dom->addChild(
1659
            $this->pass[$posicao],
1660
            'xPass',
1661
            $std->xPass,
1662
            false,
1663
            $identificador . 'Sigla ou código interno da Filial/Porto/Estação/Aeroporto de Passagem'
1664
        );
1665
        return $this->pass[$posicao];
1666
    }
1667
1668
    /**
1669
     * Gera as tags para o elemento: "semData" (Entrega sem data definida)
1670
     * #70
1671
     * Nível: 3
1672
     *
1673
     * @return \DOMElement
1674
     */
1675
    public function tagsemData($std)
1676
    {
1677
        $identificador = '#70 <semData> - ';
1678
        $this->semData = $this->dom->createElement('semData');
1679
        $this->dom->addChild(
1680
            $this->semData,
1681
            'tpPer',
1682
            $std->tpPer,
1683
            true,
1684
            $identificador . 'Tipo de data/período programado para entrega'
1685
        );
1686
        return $this->semData;
1687
    }
1688
1689
    /**
1690
     * Gera as tags para o elemento: "comData" (Entrega com data definida)
1691
     * #72
1692
     * Nível: 3
1693
     *
1694
     * @return \DOMElement
1695
     */
1696
    public function tagcomData($std)
1697
    {
1698
        $identificador = '#72 <comData> - ';
1699
        $this->comData = $this->dom->createElement('comData');
1700
        $this->dom->addChild(
1701
            $this->comData,
1702
            'tpPer',
1703
            $std->tpPer,
1704
            true,
1705
            $identificador . 'Tipo de data/período programado para entrega'
1706
        );
1707
        $this->dom->addChild(
1708
            $this->comData,
1709
            'dProg',
1710
            $std->dProg,
1711
            true,
1712
            $identificador . 'Data programada'
1713
        );
1714
        return $this->comData;
1715
    }
1716
1717
    /**
1718
     * Gera as tags para o elemento: "noPeriodo" (Entrega no período definido)
1719
     * #75
1720
     * Nível: 3
1721
     *
1722
     * @return \DOMElement
1723
     */
1724
    public function tagnoPeriodo($std)
1725
    {
1726
        $identificador = '#75 <noPeriodo> - ';
1727
        $this->noPeriodo = $this->dom->createElement('noPeriodo');
1728
        $this->dom->addChild(
1729
            $this->noPeriodo,
1730
            'tpPer',
1731
            $std->tpPer,
1732
            true,
1733
            $identificador . 'Tipo de data/período programado para entrega'
1734
        );
1735
        $this->dom->addChild(
1736
            $this->noPeriodo,
1737
            'dIni',
1738
            $std->dIni,
1739
            true,
1740
            $identificador . 'Data inicial'
1741
        );
1742
        $this->dom->addChild(
1743
            $this->noPeriodo,
1744
            'dFim',
1745
            $std->dFim,
1746
            true,
1747
            $identificador . 'Data final'
1748
        );
1749
        return $this->noPeriodo;
1750
    }
1751
1752
    /**
1753
     * Gera as tags para o elemento: "semHora" (Entrega sem hora definida)
1754
     * #79
1755
     * Nível: 3
1756
     * Os parâmetros para esta função são todos os elementos da tag "semHora" do
1757
     * tipo elemento (Ele = E|CE|A) e nível 4
1758
     *
1759
     * @return \DOMElement
1760
     */
1761
    public function tagsemHora($std)
1762
    {
1763
        $identificador = '#79 <semHora> - ';
1764
        $this->semHora = $this->dom->createElement('semHora');
1765
        $this->dom->addChild(
1766
            $this->semHora,
1767
            'tpHor',
1768
            $std->tpHor,
1769
            true,
1770
            $identificador . 'Tipo de hora'
1771
        );
1772
        return $this->semHora;
1773
    }
1774
1775
    /**
1776
     * Gera as tags para o elemento: "comHora" (Entrega sem hora definida)
1777
     * # = 81
1778
     * Nível = 3
1779
     * Os parâmetros para esta função são todos os elementos da tag "comHora" do
1780
     * tipo elemento (Ele = E|CE|A) e nível 4
1781
     *
1782
     * @return \DOMElement
1783
     */
1784
    public function tagcomHora($std)
1785
    {
1786
        $identificador = '#81 <comHora> - ';
1787
        $this->comHora = $this->dom->createElement('comHora');
1788
        $this->dom->addChild(
1789
            $this->comHora,
1790
            'tpHor',
1791
            $std->tpHor,
1792
            true,
1793
            $identificador . 'Tipo de hora'
1794
        );
1795
        $this->dom->addChild(
1796
            $this->comHora,
1797
            'hProg',
1798
            $std->hProg,
1799
            true,
1800
            $identificador . 'Hora programada'
1801
        );
1802
        return $this->comHora;
1803
    }
1804
1805
    /**
1806
     * Gera as tags para o elemento: "noInter" (Entrega no intervalo de horário definido)
1807
     * #84
1808
     * Nível: 3
1809
     * Os parâmetros para esta função são todos os elementos da tag "noInter" do
1810
     * tipo elemento (Ele = E|CE|A) e nível 4
1811
     *
1812
     * @return \DOMElement
1813
     */
1814
    public function tagnoInter($std)
1815
    {
1816
        $identificador = '#84 <noInter> - ';
1817
        $this->noInter = $this->dom->createElement('noInter');
1818
        $this->dom->addChild(
1819
            $this->noInter,
1820
            'tpHor',
1821
            $std->tpHor,
1822
            true,
1823
            $identificador . 'Tipo de hora'
1824
        );
1825
        $this->dom->addChild(
1826
            $this->noInter,
1827
            'hIni',
1828
            $std->hIni,
1829
            true,
1830
            $identificador . 'Hora inicial'
1831
        );
1832
        $this->dom->addChild(
1833
            $this->noInter,
1834
            'hFim',
1835
            $std->hFim,
1836
            true,
1837
            $identificador . 'Hora final'
1838
        );
1839
        return $this->noInter;
1840
    }
1841
1842
    /**
1843
     * Gera as tags para o elemento: "ObsCont" (Campo de uso livre do contribuinte)
1844
     * #91
1845
     * Nível: 2
1846
     * Os parâmetros para esta função são todos os elementos da tag "ObsCont" do
1847
     * tipo elemento (Ele = E|CE|A) e nível 3
1848
     *
1849
     * @return boolean
1850
     */
1851
    public function tagobsCont($std)
1852
    {
1853
        $identificador = '#91 <ObsCont> - ';
1854
        if (count($this->obsCont) <= 10) {
1855
            $this->obsCont[] = $this->dom->createElement('ObsCont');
1856
            $posicao = (int)count($this->obsCont) - 1;
1857
            $this->obsCont[$posicao]->setAttribute('xCampo', $std->xCampo);
1858
            $this->dom->addChild(
1859
                $this->obsCont[$posicao],
1860
                'xTexto',
1861
                $std->xTexto,
1862
                true,
1863
                $identificador . 'Conteúdo do campo'
1864
            );
1865
            return true;
1866
        }
1867
        $this->errors[] = array(
1868
            'tag' => (string)'<ObsCont>',
1869
            'desc' => (string)'Campo de uso livre do contribuinte',
1870
            'erro' => (string)'Tag deve aparecer de 0 a 10 vezes'
1871
        );
1872
        return false;
1873
    }
1874
1875
    /**
1876
     * Gera as tags para o elemento: "ObsFisco" (Campo de uso livre do contribuinte)
1877
     * #94
1878
     * Nível: 2
1879
     * Os parâmetros para esta função são todos os elementos da tag "ObsFisco" do tipo
1880
     * elemento (Ele = E|CE|A) e nível 3
1881
     *
1882
     * @return boolean
1883
     */
1884
    public function tagobsFisco($std)
1885
    {
1886
        $identificador = '#94 <ObsFisco> - ';
1887
        if (count($this->obsFisco) <= 10) {
1888
            $this->obsFisco[] = $this->dom->createElement('ObsFisco');
1889
            $posicao = (int)count($this->obsFisco) - 1;
1890
            $this->obsFisco[$posicao]->setAttribute('xCampo', $std->xCampo);
1891
            $this->dom->addChild(
1892
                $this->obsFisco[$posicao],
1893
                'xTexto',
1894
                $std->xTexto,
1895
                true,
1896
                $identificador . 'Conteúdo do campo'
1897
            );
1898
            return true;
1899
        }
1900
        $this->errors[] = array(
1901
            'tag' => (string)'<ObsFisco>',
1902
            'desc' => (string)'Campo de uso livre do contribuinte',
1903
            'erro' => (string)'Tag deve aparecer de 0 a 10 vezes'
1904
        );
1905
        return false;
1906
    }
1907
1908
    /**
1909
     * Gera as tags para o elemento: "emit" (Identificação do Emitente do CT-e)
1910
     * #97
1911
     * Nível: 1
1912
     * Os parâmetros para esta função são todos os elementos da tag "emit" do
1913
     * tipo elemento (Ele = E|CE|A) e nível 2
1914
     *
1915
     * @return \DOMElement
1916
     */
1917
    public function tagemit($std)
1918
    {
1919
        $identificador = '#97 <emit> - ';
1920
        $this->emit = $this->dom->createElement('emit');
1921
        $this->dom->addChild(
1922
            $this->emit,
1923
            'CNPJ',
1924
            $std->CNPJ,
1925
            true,
1926
            $identificador . 'CNPJ do emitente'
1927
        );
1928
        $this->dom->addChild(
1929
            $this->emit,
1930
            'IE',
1931
            Strings::onlyNumbers($std->IE),
1932
            false,
1933
            $identificador . 'Inscrição Estadual do Emitente'
1934
        );
1935
        $this->dom->addChild(
1936
            $this->emit,
1937
            'IEST',
1938
            Strings::onlyNumbers($std->IEST),
1939
            false,
1940
            $identificador . 'Inscrição Estadual do Substituto Tributário'
1941
        );
1942
        $this->dom->addChild(
1943
            $this->emit,
1944
            'xNome',
1945
            $std->xNome,
1946
            true,
1947
            $identificador . 'Razão social ou Nome do emitente'
1948
        );
1949
        $this->dom->addChild(
1950
            $this->emit,
1951
            'xFant',
1952
            $std->xFant,
1953
            false,
1954
            $identificador . 'Nome fantasia'
1955
        );
1956
        return $this->emit;
1957
    }
1958
1959
    /**
1960
     * Gera as tags para o elemento: "enderEmit" (Endereço do emitente)
1961
     * #102
1962
     * Nível: 2
1963
     * Os parâmetros para esta função são todos os elementos da tag "enderEmit" do
1964
     * tipo elemento (Ele = E|CE|A) e nível 3
1965
     *
1966
     * @return \DOMElement
1967
     */
1968
    public function tagenderEmit($std)
1969
    {
1970
        $identificador = '#102 <enderEmit> - ';
1971
        $this->enderEmit = $this->dom->createElement('enderEmit');
1972
        $this->dom->addChild(
1973
            $this->enderEmit,
1974
            'xLgr',
1975
            $std->xLgr,
1976
            true,
1977
            $identificador . 'Logradouro'
1978
        );
1979
        $this->dom->addChild(
1980
            $this->enderEmit,
1981
            'nro',
1982
            $std->nro,
1983
            true,
1984
            $identificador . 'Número'
1985
        );
1986
        $this->dom->addChild(
1987
            $this->enderEmit,
1988
            'xCpl',
1989
            $std->xCpl,
1990
            false,
1991
            $identificador . 'Complemento'
1992
        );
1993
        $this->dom->addChild(
1994
            $this->enderEmit,
1995
            'xBairro',
1996
            $std->xBairro,
1997
            true,
1998
            $identificador . 'Bairro'
1999
        );
2000
        $this->dom->addChild(
2001
            $this->enderEmit,
2002
            'cMun',
2003
            $std->cMun,
2004
            true,
2005
            $identificador . 'Código do município'
2006
        );
2007
        $this->dom->addChild(
2008
            $this->enderEmit,
2009
            'xMun',
2010
            $std->xMun,
2011
            true,
2012
            $identificador . 'Nome do município'
2013
        );
2014
        $this->dom->addChild(
2015
            $this->enderEmit,
2016
            'CEP',
2017
            $std->CEP,
2018
            false,
2019
            $identificador . 'CEP'
2020
        );
2021
        $this->dom->addChild(
2022
            $this->enderEmit,
2023
            'UF',
2024
            $std->UF,
2025
            true,
2026
            $identificador . 'Sigla da UF'
2027
        );
2028
        $this->dom->addChild(
2029
            $this->enderEmit,
2030
            'fone',
2031
            $std->fone,
2032
            false,
2033
            $identificador . 'Telefone'
2034
        );
2035
        return $this->enderEmit;
2036
    }
2037
2038
    /**
2039
     * Gera as tags para o elemento: "rem" (Informações do Remetente das mercadorias
2040
     * transportadas pelo CT-e)
2041
     * #112
2042
     * Nível = 1
2043
     * Os parâmetros para esta função são todos os elementos da tag "rem" do
2044
     * tipo elemento (Ele = E|CE|A) e nível 2
2045
     *
2046
     * @return \DOMElement
2047
     */
2048
    public function tagrem($std)
2049
    {
2050
        $identificador = '#97 <rem> - ';
2051
        $this->rem = $this->dom->createElement('rem');
2052
        if ($std->CNPJ != '') {
2053
            $this->dom->addChild(
2054
                $this->rem,
2055
                'CNPJ',
2056
                $std->CNPJ,
2057
                true,
2058
                $identificador . 'CNPJ do Remente'
2059
            );
2060
        } elseif ($std->CPF != '') {
2061
            $this->dom->addChild(
2062
                $this->rem,
2063
                'CPF',
2064
                $std->CPF,
2065
                true,
2066
                $identificador . 'CPF do Remente'
2067
            );
2068
        } else {
2069
            $this->dom->addChild(
2070
                $this->rem,
2071
                'CNPJ',
2072
                $std->CNPJ,
2073
                true,
2074
                $identificador . 'CNPJ do Remente'
2075
            );
2076
            $this->dom->addChild(
2077
                $this->rem,
2078
                'CPF',
2079
                $std->CPF,
2080
                true,
2081
                $identificador . 'CPF do remente'
2082
            );
2083
        }
2084
        $this->dom->addChild(
2085
            $this->rem,
2086
            'IE',
2087
            $std->IE,
2088
            false,
2089
            $identificador . 'Inscrição Estadual do remente'
2090
        );
2091
        $xNome = $std->xNome;
2092
        if ($this->tpAmb == '2') {
2093
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2094
        }
2095
        $this->dom->addChild(
2096
            $this->rem,
2097
            'xNome',
2098
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2099
            true,
2100
            $identificador . 'Razão social ou Nome do remente'
2101
        );
2102
        $this->dom->addChild(
2103
            $this->rem,
2104
            'xFant',
2105
            $std->xFant,
2106
            false,
2107
            $identificador . 'Nome fantasia'
2108
        );
2109
        $this->dom->addChild(
2110
            $this->rem,
2111
            'fone',
2112
            $std->fone,
2113
            false,
2114
            $identificador . 'Telefone'
2115
        );
2116
        $this->dom->addChild(
2117
            $this->rem,
2118
            'email',
2119
            $std->email,
2120
            false,
2121
            $identificador . 'Endereço de email'
2122
        );
2123
        return $this->rem;
2124
    }
2125
2126
    /**
2127
     * Gera as tags para o elemento: "enderReme" (Dados do endereço)
2128
     * #120
2129
     * Nível: 2
2130
     * Os parâmetros para esta função são todos os elementos da tag "enderReme" do
2131
     * tipo elemento (Ele = E|CE|A) e nível 3
2132
     *
2133
     * @return \DOMElement
2134
     */
2135
    public function tagenderReme($std)
2136
    {
2137
        $identificador = '#119 <enderReme> - ';
2138
        $this->enderReme = $this->dom->createElement('enderReme');
2139
        $this->dom->addChild(
2140
            $this->enderReme,
2141
            'xLgr',
2142
            $std->xLgr,
2143
            true,
2144
            $identificador . 'Logradouro'
2145
        );
2146
        $this->dom->addChild(
2147
            $this->enderReme,
2148
            'nro',
2149
            $std->nro,
2150
            true,
2151
            $identificador . 'Número'
2152
        );
2153
        $this->dom->addChild(
2154
            $this->enderReme,
2155
            'xCpl',
2156
            $std->xCpl,
2157
            false,
2158
            $identificador . 'Complemento'
2159
        );
2160
        $this->dom->addChild(
2161
            $this->enderReme,
2162
            'xBairro',
2163
            $std->xBairro,
2164
            true,
2165
            $identificador . 'Bairro'
2166
        );
2167
        $this->dom->addChild(
2168
            $this->enderReme,
2169
            'cMun',
2170
            $std->cMun,
2171
            true,
2172
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2173
        );
2174
        $this->dom->addChild(
2175
            $this->enderReme,
2176
            'xMun',
2177
            $std->xMun,
2178
            true,
2179
            $identificador . 'Nome do município'
2180
        );
2181
        $this->dom->addChild(
2182
            $this->enderReme,
2183
            'CEP',
2184
            $std->CEP,
2185
            false,
2186
            $identificador . 'CEP'
2187
        );
2188
        $this->dom->addChild(
2189
            $this->enderReme,
2190
            'UF',
2191
            $std->UF,
2192
            true,
2193
            $identificador . 'Sigla da UF'
2194
        );
2195
        $this->dom->addChild(
2196
            $this->enderReme,
2197
            'cPais',
2198
            $std->cPais,
2199
            false,
2200
            $identificador . 'Código do país'
2201
        );
2202
        $this->dom->addChild(
2203
            $this->enderReme,
2204
            'xPais',
2205
            $std->xPais,
2206
            false,
2207
            $identificador . 'Nome do país'
2208
        );
2209
2210
        $node = $this->rem->getElementsByTagName("email")->item(0);
2211
        $this->rem->insertBefore($this->enderReme, $node);
2212
        return $this->enderReme;
2213
    }
2214
2215
    /**
2216
     * Gera as tags para o elemento: "exped" (Informações do Expedidor da Carga)
2217
     * #132
2218
     * Nível: 1
2219
     * Os parâmetros para esta função são todos os elementos da tag "exped" do
2220
     * tipo elemento (Ele = E|CE|A) e nível 2
2221
     *
2222
     * @return \DOMElement
2223
     */
2224
    public function tagexped($std)
2225
    {
2226
        $identificador = '#142 <exped> - ';
2227
        $this->exped = $this->dom->createElement('exped');
2228
        if ($std->CNPJ != '') {
2229
            $this->dom->addChild(
2230
                $this->exped,
2231
                'CNPJ',
2232
                $std->CNPJ,
2233
                true,
2234
                $identificador . 'Número do CNPJ'
2235
            );
2236
        } elseif ($std->CPF != '') {
2237
            $this->dom->addChild(
2238
                $this->exped,
2239
                'CPF',
2240
                $std->CPF,
2241
                true,
2242
                $identificador . 'Número do CPF'
2243
            );
2244
        } else {
2245
            $this->dom->addChild(
2246
                $this->exped,
2247
                'CNPJ',
2248
                $std->CNPJ,
2249
                true,
2250
                $identificador . 'Número do CNPJ'
2251
            );
2252
            $this->dom->addChild(
2253
                $this->exped,
2254
                'CPF',
2255
                $std->CPF,
2256
                true,
2257
                $identificador . 'Número do CPF'
2258
            );
2259
        }
2260
        if (!empty($std->IE)) {
2261
            $this->dom->addChild(
2262
                $this->exped,
2263
                'IE',
2264
                $std->IE,
2265
                true,
2266
                $identificador . 'Inscrição Estadual'
2267
            );
2268
        }
2269
        $xNome = $std->xNome;
2270
        if ($this->tpAmb == '2') {
2271
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2272
        }
2273
        $this->dom->addChild(
2274
            $this->exped,
2275
            'xNome',
2276
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2277
            true,
2278
            $identificador . 'Razão social ou Nome'
2279
        );
2280
        $this->dom->addChild(
2281
            $this->exped,
2282
            'fone',
2283
            $std->fone,
2284
            false,
2285
            $identificador . 'Telefone'
2286
        );
2287
        $this->dom->addChild(
2288
            $this->exped,
2289
            'email',
2290
            $std->email,
2291
            false,
2292
            $identificador . 'Endereço de email'
2293
        );
2294
        return $this->exped;
2295
    }
2296
2297
    /**
2298
     * Gera as tags para o elemento: "enderExped" (Dados do endereço)
2299
     * #138
2300
     * Nível: 2
2301
     * Os parâmetros para esta função são todos os elementos da tag "enderExped" do
2302
     * tipo elemento (Ele = E|CE|A) e nível 3
2303
     *
2304
     * @return \DOMElement
2305
     */
2306
    public function tagenderExped($std)
2307
    {
2308
        $identificador = '#148 <enderExped> - ';
2309
        $this->enderExped = $this->dom->createElement('enderExped');
2310
        $this->dom->addChild(
2311
            $this->enderExped,
2312
            'xLgr',
2313
            $std->xLgr,
2314
            true,
2315
            $identificador . 'Logradouro'
2316
        );
2317
        $this->dom->addChild(
2318
            $this->enderExped,
2319
            'nro',
2320
            $std->nro,
2321
            true,
2322
            $identificador . 'Número'
2323
        );
2324
        $this->dom->addChild(
2325
            $this->enderExped,
2326
            'xCpl',
2327
            $std->xCpl,
2328
            false,
2329
            $identificador . 'Complemento'
2330
        );
2331
        $this->dom->addChild(
2332
            $this->enderExped,
2333
            'xBairro',
2334
            $std->xBairro,
2335
            true,
2336
            $identificador . 'Bairro'
2337
        );
2338
        $this->dom->addChild(
2339
            $this->enderExped,
2340
            'cMun',
2341
            $std->cMun,
2342
            true,
2343
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2344
        );
2345
        $this->dom->addChild(
2346
            $this->enderExped,
2347
            'xMun',
2348
            $std->xMun,
2349
            true,
2350
            $identificador . 'Nome do município'
2351
        );
2352
        $this->dom->addChild(
2353
            $this->enderExped,
2354
            'CEP',
2355
            $std->CEP,
2356
            false,
2357
            $identificador . 'CEP'
2358
        );
2359
        $this->dom->addChild(
2360
            $this->enderExped,
2361
            'UF',
2362
            $std->UF,
2363
            true,
2364
            $identificador . 'Sigla da UF'
2365
        );
2366
        $this->dom->addChild(
2367
            $this->enderExped,
2368
            'cPais',
2369
            $std->cPais,
2370
            false,
2371
            $identificador . 'Código do país'
2372
        );
2373
        $this->dom->addChild(
2374
            $this->enderExped,
2375
            'xPais',
2376
            $std->xPais,
2377
            false,
2378
            $identificador . 'Nome do país'
2379
        );
2380
        $node = $this->exped->getElementsByTagName("email")->item(0);
2381
        $this->exped->insertBefore($this->enderExped, $node);
2382
        return $this->enderExped;
2383
    }
2384
2385
    /**
2386
     * Gera as tags para o elemento: "receb" (Informações do Recebedor da Carga)
2387
     * #150
2388
     * Nível: 1
2389
     * Os parâmetros para esta função são todos os elementos da tag "receb" do
2390
     * tipo elemento (Ele = E|CE|A) e nível 2
2391
     *
2392
     * @return \DOMElement
2393
     */
2394
    public function tagreceb($std)
2395
    {
2396
        $identificador = '#160 <receb> - ';
2397
        $this->receb = $this->dom->createElement('receb');
2398
        if ($std->CNPJ != '') {
2399
            $this->dom->addChild(
2400
                $this->receb,
2401
                'CNPJ',
2402
                $std->CNPJ,
2403
                true,
2404
                $identificador . 'Número do CNPJ'
2405
            );
2406
        } elseif ($std->CPF != '') {
2407
            $this->dom->addChild(
2408
                $this->receb,
2409
                'CPF',
2410
                $std->CPF,
2411
                true,
2412
                $identificador . 'Número do CPF'
2413
            );
2414
        } else {
2415
            $this->dom->addChild(
2416
                $this->receb,
2417
                'CNPJ',
2418
                $std->CNPJ,
2419
                true,
2420
                $identificador . 'Número do CNPJ'
2421
            );
2422
            $this->dom->addChild(
2423
                $this->receb,
2424
                'CPF',
2425
                $std->CPF,
2426
                true,
2427
                $identificador . 'Número do CPF'
2428
            );
2429
        }
2430
        if (!empty($std->IE)) {
2431
            $this->dom->addChild(
2432
                $this->receb,
2433
                'IE',
2434
                $std->IE,
2435
                true,
2436
                $identificador . 'Inscrição Estadual'
2437
            );
2438
        }
2439
        $xNome = $std->xNome;
2440
        if ($this->tpAmb == '2') {
2441
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2442
        }
2443
        $this->dom->addChild(
2444
            $this->receb,
2445
            'xNome',
2446
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2447
            true,
2448
            $identificador . 'Razão social ou Nome'
2449
        );
2450
        $this->dom->addChild(
2451
            $this->receb,
2452
            'fone',
2453
            $std->fone,
2454
            false,
2455
            $identificador . 'Telefone'
2456
        );
2457
        $this->dom->addChild(
2458
            $this->receb,
2459
            'email',
2460
            $std->email,
2461
            false,
2462
            $identificador . 'Endereço de email'
2463
        );
2464
        return $this->receb;
2465
    }
2466
2467
    /**
2468
     * Gera as tags para o elemento: "enderReceb" (Informações do Recebedor da Carga)
2469
     * #156
2470
     * Nível: 2
2471
     * Os parâmetros para esta função são todos os elementos da tag "enderReceb" do
2472
     * tipo elemento (Ele = E|CE|A) e nível 3
2473
     *
2474
     * @return \DOMElement
2475
     */
2476
    public function tagenderReceb($std)
2477
    {
2478
        $identificador = '#160 <enderReceb> - ';
2479
        $this->enderReceb = $this->dom->createElement('enderReceb');
2480
        $this->dom->addChild(
2481
            $this->enderReceb,
2482
            'xLgr',
2483
            $std->xLgr,
2484
            true,
2485
            $identificador . 'Logradouro'
2486
        );
2487
        $this->dom->addChild(
2488
            $this->enderReceb,
2489
            'nro',
2490
            $std->nro,
2491
            true,
2492
            $identificador . 'Número'
2493
        );
2494
        $this->dom->addChild(
2495
            $this->enderReceb,
2496
            'xCpl',
2497
            $std->xCpl,
2498
            false,
2499
            $identificador . 'Complemento'
2500
        );
2501
        $this->dom->addChild(
2502
            $this->enderReceb,
2503
            'xBairro',
2504
            $std->xBairro,
2505
            true,
2506
            $identificador . 'Bairro'
2507
        );
2508
        $this->dom->addChild(
2509
            $this->enderReceb,
2510
            'cMun',
2511
            $std->cMun,
2512
            true,
2513
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2514
        );
2515
        $this->dom->addChild(
2516
            $this->enderReceb,
2517
            'xMun',
2518
            $std->xMun,
2519
            true,
2520
            $identificador . 'Nome do município'
2521
        );
2522
        $this->dom->addChild(
2523
            $this->enderReceb,
2524
            'CEP',
2525
            $std->CEP,
2526
            false,
2527
            $identificador . 'CEP'
2528
        );
2529
        $this->dom->addChild(
2530
            $this->enderReceb,
2531
            'UF',
2532
            $std->UF,
2533
            true,
2534
            $identificador . 'Sigla da UF'
2535
        );
2536
        $this->dom->addChild(
2537
            $this->enderReceb,
2538
            'cPais',
2539
            $std->cPais,
2540
            false,
2541
            $identificador . 'Código do país'
2542
        );
2543
        $this->dom->addChild(
2544
            $this->enderReceb,
2545
            'xPais',
2546
            $std->xPais,
2547
            false,
2548
            $identificador . 'Nome do país'
2549
        );
2550
        $node = $this->receb->getElementsByTagName("email")->item(0);
2551
        $this->receb->insertBefore($this->enderReceb, $node);
2552
        return $this->enderReceb;
2553
    }
2554
2555
    /**
2556
     * Gera as tags para o elemento: "dest" (Informações do Destinatário do CT-e)
2557
     * #168
2558
     * Nível: 1
2559
     * Os parâmetros para esta função são todos os elementos da tag "dest" do
2560
     * tipo elemento (Ele = E|CE|A) e nível 2
2561
     *
2562
     * @return \DOMElement
2563
     */
2564
    public function tagdest($std)
2565
    {
2566
        $identificador = '#178 <dest> - ';
2567
        $this->dest = $this->dom->createElement('dest');
2568
        if ($std->CNPJ != '') {
2569
            $this->dom->addChild(
2570
                $this->dest,
2571
                'CNPJ',
2572
                $std->CNPJ,
2573
                true,
2574
                $identificador . 'Número do CNPJ'
2575
            );
2576
        } elseif ($std->CPF != '') {
2577
            $this->dom->addChild(
2578
                $this->dest,
2579
                'CPF',
2580
                $std->CPF,
2581
                true,
2582
                $identificador . 'Número do CPF'
2583
            );
2584
        } else {
2585
            $this->dom->addChild(
2586
                $this->dest,
2587
                'CNPJ',
2588
                $std->CNPJ,
2589
                true,
2590
                $identificador . 'Número do CNPJ'
2591
            );
2592
            $this->dom->addChild(
2593
                $this->dest,
2594
                'CPF',
2595
                $std->CPF,
2596
                true,
2597
                $identificador . 'Número do CPF'
2598
            );
2599
        }
2600
        if (!empty($std->IE)) {
2601
            $this->dom->addChild(
2602
                $this->dest,
2603
                'IE',
2604
                $std->IE,
2605
                true,
2606
                $identificador . 'Inscrição Estadual'
2607
            );
2608
        }
2609
        $xNome = $std->xNome;
2610
        if ($this->tpAmb == '2') {
2611
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2612
        }
2613
        $this->dom->addChild(
2614
            $this->dest,
2615
            'xNome',
2616
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2617
            true,
2618
            $identificador . 'Razão social ou Nome'
2619
        );
2620
        $this->dom->addChild(
2621
            $this->dest,
2622
            'fone',
2623
            $std->fone,
2624
            false,
2625
            $identificador . 'Telefone'
2626
        );
2627
        $this->dom->addChild(
2628
            $this->dest,
2629
            'ISUF',
2630
            $std->ISUF,
2631
            false,
2632
            $identificador . 'Inscrição na SUFRAMA'
2633
        );
2634
        $this->dom->addChild(
2635
            $this->dest,
2636
            'email',
2637
            $std->email,
2638
            false,
2639
            $identificador . 'Endereço de email'
2640
        );
2641
        return $this->dest;
2642
    }
2643
2644
    /**
2645
     * Gera as tags para o elemento: "enderDest" (Informações do Recebedor da Carga)
2646
     * # = 175
2647
     * Nível = 2
2648
     * Os parâmetros para esta função são todos os elementos da tag "enderDest" do
2649
     * tipo elemento (Ele = E|CE|A) e nível 3
2650
     *
2651
     * @return \DOMElement
2652
     */
2653
    public function tagenderDest($std)
2654
    {
2655
        $identificador = '#185 <enderDest> - ';
2656
        $this->enderDest = $this->dom->createElement('enderDest');
2657
        $this->dom->addChild(
2658
            $this->enderDest,
2659
            'xLgr',
2660
            $std->xLgr,
2661
            true,
2662
            $identificador . 'Logradouro'
2663
        );
2664
        $this->dom->addChild(
2665
            $this->enderDest,
2666
            'nro',
2667
            $std->nro,
2668
            true,
2669
            $identificador . 'Número'
2670
        );
2671
        $this->dom->addChild(
2672
            $this->enderDest,
2673
            'xCpl',
2674
            $std->xCpl,
2675
            false,
2676
            $identificador . 'Complemento'
2677
        );
2678
        $this->dom->addChild(
2679
            $this->enderDest,
2680
            'xBairro',
2681
            $std->xBairro,
2682
            true,
2683
            $identificador . 'Bairro'
2684
        );
2685
        $this->dom->addChild(
2686
            $this->enderDest,
2687
            'cMun',
2688
            $std->cMun,
2689
            true,
2690
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2691
        );
2692
        $this->dom->addChild(
2693
            $this->enderDest,
2694
            'xMun',
2695
            $std->xMun,
2696
            true,
2697
            $identificador . 'Nome do município'
2698
        );
2699
        $this->dom->addChild(
2700
            $this->enderDest,
2701
            'CEP',
2702
            $std->CEP,
2703
            false,
2704
            $identificador . 'CEP'
2705
        );
2706
        $this->dom->addChild(
2707
            $this->enderDest,
2708
            'UF',
2709
            $std->UF,
2710
            true,
2711
            $identificador . 'Sigla da UF'
2712
        );
2713
        $this->dom->addChild(
2714
            $this->enderDest,
2715
            'cPais',
2716
            $std->cPais,
2717
            false,
2718
            $identificador . 'Código do país'
2719
        );
2720
        $this->dom->addChild(
2721
            $this->enderDest,
2722
            'xPais',
2723
            $std->xPais,
2724
            false,
2725
            $identificador . 'Nome do país'
2726
        );
2727
        $node = $this->dest->getElementsByTagName("email")->item(0);
2728
        $this->dest->insertBefore($this->enderDest, $node);
2729
        return $this->enderDest;
2730
    }
2731
2732
    /**
2733
     * Gera as tags para o elemento: "vPrest" (Valores da Prestação de Serviço)
2734
     * #187
2735
     * Nível: 1
2736
     * Os parâmetros para esta função são todos os elementos da tag "vPrest" do
2737
     * tipo elemento (Ele = E|CE|A) e nível 2
2738
     *
2739
     * @return \DOMElement
2740
     */
2741
    public function tagvPrest($std)
2742
    {
2743
        $identificador = '#208 <vPrest> - ';
2744
        $this->vPrest = $this->dom->createElement('vPrest');
2745
        $this->dom->addChild(
2746
            $this->vPrest,
2747
            'vTPrest',
2748
            $std->vTPrest,
2749
            true,
2750
            $identificador . 'Valor Total da Prestação do Serviço'
2751
        );
2752
        $this->dom->addChild(
2753
            $this->vPrest,
2754
            'vRec',
2755
            $std->vRec,
2756
            true,
2757
            $identificador . 'Valor a Receber'
2758
        );
2759
        return $this->vPrest;
2760
    }
2761
2762
    /**
2763
     * Gera as tags para o elemento: "Comp" (Componentes do Valor da Prestação)
2764
     * #211
2765
     * Nível: 2
2766
     * Os parâmetros para esta função são todos os elementos da tag "Comp" do
2767
     * tipo elemento (Ele = E|CE|A) e nível 3
2768
     *
2769
     * @return \DOMElement
2770
     */
2771
    public function tagComp($std)
2772
    {
2773
        $identificador = '#65 <pass> - ';
2774
        $this->comp[] = $this->dom->createElement('Comp');
2775
        $posicao = (int)count($this->comp) - 1;
2776
        $this->dom->addChild(
2777
            $this->comp[$posicao],
2778
            'xNome',
2779
            $std->xNome,
2780
            false,
2781
            $identificador . 'Nome do componente'
2782
        );
2783
        $this->dom->addChild(
2784
            $this->comp[$posicao],
2785
            'vComp',
2786
            $std->vComp,
2787
            false,
2788
            $identificador . 'Valor do componente'
2789
        );
2790
        return $this->comp[$posicao];
2791
    }
2792
2793
    /**
2794
     * tagICMS
2795
     * Informações relativas ao ICMS
2796
     * #194
2797
     *
2798
     * @return DOMElement
2799
     */
2800
    public function tagicms($std)
2801
    {
2802
        $identificador = 'N01 <ICMSxx> - ';
2803
        switch ($std->cst) {
2804
            case '00':
2805
                $icms = $this->dom->createElement("ICMS00");
2806
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 00");
2807
                $this->dom->addChild($icms, 'vBC', $std->vBC, true, "$identificador  Valor da BC do ICMS");
2808
                $this->dom->addChild($icms, 'pICMS', $std->pICMS, true, "$identificador  Alíquota do imposto");
2809
                $this->dom->addChild($icms, 'vICMS', $std->vICMS, true, "$identificador  Valor do ICMS");
2810
                break;
2811
            case '20':
2812
                $icms = $this->dom->createElement("ICMS20");
2813
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 20");
2814
                $this->dom->addChild(
2815
                    $icms,
2816
                    'pRedBC',
2817
                    $std->pRedBC,
2818
                    true,
2819
                    "$identificador  Percentual da Redução de BC"
2820
                );
2821
                $this->dom->addChild($icms, 'vBC', $std->vBC, true, "$identificador  Valor da BC do ICMS");
2822
                $this->dom->addChild($icms, 'pICMS', $std->pICMS, true, "$identificador  Alíquota do imposto");
2823
                $this->dom->addChild($icms, 'vICMS', $std->vICMS, true, "$identificador  Valor do ICMS");
2824
                break;
2825
            case '40':
2826
                $icms = $this->dom->createElement("ICMS45");
2827
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 40");
2828
                break;
2829
            case '41':
2830
                $icms = $this->dom->createElement("ICMS45");
2831
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 41");
2832
                break;
2833
            case '51':
2834
                $icms = $this->dom->createElement("ICMS45");
2835
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 51");
2836
                break;
2837
            case '60':
2838
                $icms = $this->dom->createElement("ICMS60");
2839
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 60");
2840
                $this->dom->addChild(
2841
                    $icms,
2842
                    'vBCSTRet',
2843
                    $std->vBCSTRet,
2844
                    true,
2845
                    "$identificador  Valor BC do ICMS ST retido"
2846
                );
2847
                $this->dom->addChild(
2848
                    $icms,
2849
                    'vICMSSTRet',
2850
                    $std->vICMSSTRet,
2851
                    true,
2852
                    "$identificador  Valor do ICMS ST retido"
2853
                );
2854
                $this->dom->addChild(
2855
                    $icms,
2856
                    'pICMSSTRet',
2857
                    $std->pICMSSTRet,
2858
                    true,
2859
                    "$identificador  Valor do ICMS ST retido"
2860
                );
2861
                if ($std->vCred > 0) {
2862
                    $this->dom->addChild($icms, 'vCred', $std->vCred, false, "$identificador  Valor do Crédito");
2863
                }
2864
                break;
2865
            case '90':
2866
                if ($std->outraUF == true) {
2867
                    $icms = $this->dom->createElement("ICMSOutraUF");
2868
                    $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 90");
2869
                    if ($std->pRedBC > 0) {
2870
                        $this->dom->addChild(
2871
                            $icms,
2872
                            'pRedBCOutraUF',
2873
                            $std->pRedBC,
2874
                            false,
2875
                            "$identificador Percentual Red "
2876
                            . "BC Outra UF"
2877
                        );
2878
                    }
2879
                    $this->dom->addChild($icms, 'vBCOutraUF', $std->vBC, true, "$identificador Valor BC ICMS Outra UF");
2880
                    $this->dom->addChild($icms, 'pICMSOutraUF', $std->pICMS, true, "$identificador Alíquota do "
2881
                        . "imposto Outra UF");
2882
                    $this->dom->addChild(
2883
                        $icms,
2884
                        'vICMSOutraUF',
2885
                        $std->vICMS,
2886
                        true,
2887
                        "$identificador Valor ICMS Outra UF"
2888
                    );
2889
                } else {
2890
                    $icms = $this->dom->createElement("ICMS90");
2891
                    $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador Tributação do ICMS = 90");
2892
                    if ($std->pRedBC > 0) {
2893
                        $this->dom->addChild(
2894
                            $icms,
2895
                            'pRedBC',
2896
                            $std->pRedBC,
2897
                            false,
2898
                            "$identificador Percentual Redução BC"
2899
                        );
2900
                    }
2901
                    $this->dom->addChild($icms, 'vBC', $std->vBC, true, "$identificador  Valor da BC do ICMS");
2902
                    $this->dom->addChild($icms, 'pICMS', $std->pICMS, true, "$identificador  Alíquota do imposto");
2903
                    $this->dom->addChild($icms, 'vICMS', $std->vICMS, true, "$identificador  Valor do ICMS");
2904
                    if ($std->vCred > 0) {
2905
                        $this->dom->addChild($icms, 'vCred', $std->vCred, false, "$identificador  Valor do Crédido");
2906
                    }
2907
                }
2908
                break;
2909
            case 'SN':
2910
                $icms = $this->dom->createElement("ICMSSN");
2911
                $this->dom->addChild($icms, 'CST', 90, true, "$identificador Tributação do ICMS = 90");
2912
                $this->dom->addChild($icms, 'indSN', '1', true, "$identificador  Indica se contribuinte é SN");
2913
                break;
2914
        }
2915
        $this->imp = $this->dom->createElement('imp');
2916
        $tagIcms = $this->dom->createElement('ICMS');
2917
        if (isset($icms)) {
2918
            $this->imp->appendChild($tagIcms);
2919
        }
2920
        if (isset($icms)) {
2921
            $tagIcms->appendChild($icms);
2922
        }
2923
        if ($std->vTotTrib > 0) {
2924
            $this->dom->addChild(
2925
                $this->imp,
2926
                'vTotTrib',
2927
                $std->vTotTrib,
2928
                false,
2929
                "$identificador Valor Total dos Tributos"
2930
            );
2931
        }
2932
        if (isset($std->infAdFisco)) {
2933
            $this->dom->addChild(
2934
                $this->imp,
2935
                'infAdFisco',
2936
                $std->infAdFisco,
2937
                false,
2938
                "$identificador Informações adicionais de interesse do Fisco"
2939
            );
2940
        }
2941
2942
        if ($std->vICMSUFFim != '' || $std->vICMSUFIni != '') {
2943
            $icmsDifal = $this->dom->createElement("ICMSUFFim");
2944
            $this->dom->addChild(
2945
                $icmsDifal,
2946
                'vBCUFFim',
2947
                $std->vBCUFFim,
2948
                true,
2949
                "$identificador Valor da BC do ICMS na UF
2950
                de término da prestação do serviço de transporte"
2951
            );
2952
            $this->dom->addChild(
2953
                $icmsDifal,
2954
                'pFCPUFFim',
2955
                $std->pFCPUFFim,
2956
                true,
2957
                "$identificador Percentual do ICMS
2958
                relativo ao Fundo de Combate à pobreza (FCP) na UF de término da prestação do serviço de
2959
                transporte"
2960
            );
2961
            $this->dom->addChild(
2962
                $icmsDifal,
2963
                'pICMSUFFim',
2964
                $std->pICMSUFFim,
2965
                true,
2966
                "$identificador Alíquota interna da UF
2967
                de término da prestação do serviço de transporte"
2968
            );
2969
            $this->dom->addChild(
2970
                $icmsDifal,
2971
                'pICMSInter',
2972
                $std->pICMSInter,
2973
                true,
2974
                "$identificador Alíquota interestadual
2975
                das UF envolvidas"
2976
            );
2977
            $this->dom->addChild(
2978
                $icmsDifal,
2979
                'pICMSInterPart',
2980
                $std->pICMSInterPart,
2981
                true,
2982
                "$identificador Percentual
2983
                provisório de partilha entre os estados"
2984
            );
2985
            $this->dom->addChild(
2986
                $icmsDifal,
2987
                'vFCPUFFim',
2988
                $std->vFCPUFFim,
2989
                true,
2990
                "$identificador Valor do ICMS relativo
2991
                ao Fundo de Combate á Pobreza (FCP) da UF de término da prestação"
2992
            );
2993
            $this->dom->addChild(
2994
                $icmsDifal,
2995
                'vICMSUFFim',
2996
                $std->vICMSUFFim,
2997
                true,
2998
                "$identificador Valor do ICMS de
2999
                partilha para a UF de término da prestação do serviço de transporte"
3000
            );
3001
            $this->dom->addChild(
3002
                $icmsDifal,
3003
                'vICMSUFIni',
3004
                $std->vICMSUFIni,
3005
                true,
3006
                "$identificador Valor do ICMS de
3007
                partilha para a UF de início da prestação do serviço de transporte"
3008
            );
3009
3010
            $this->imp->appendChild($icmsDifal);
3011
        }
3012
3013
        return $tagIcms;
3014
    }
3015
3016
    /**
3017
     * tagInfTribFed
3018
     * Informações do Impostos Federais
3019
     * CTe OS
3020
     * @return DOMElement
3021
     */
3022
    public function taginfTribFed($std)
3023
    {
3024
        $identificador = 'N02 <imp> - ';
3025
        $tagInfTribFed = $this->dom->createElement('infTribFed');
3026
3027
        $this->dom->addChild($tagInfTribFed, 'vPIS', $std->vPIS, false, "$identificador  Valor de PIS");
3028
        $this->dom->addChild($tagInfTribFed, 'vCOFINS', $std->vCOFINS, false, "$identificador  Valor de COFINS");
3029
        $this->dom->addChild($tagInfTribFed, 'vIR', $std->vIR, false, "$identificador  Valor de IR");
3030
        $this->dom->addChild($tagInfTribFed, 'vINSS', $std->vINSS, false, "$identificador  Valor de INSS");
3031
        $this->dom->addChild($tagInfTribFed, 'vCSLL', $std->vCSLL, false, "$identificador  Valor de CSLL");
3032
3033
        $this->imp->appendChild($tagInfTribFed);
3034
    }
3035
3036
3037
    /**
3038
     * Tag raiz do documento xml
3039
     * Função chamada pelo método [ monta ]
3040
     * @return \DOMElement
3041
     */
3042
    private function buildCTe()
3043
    {
3044
        if (empty($this->CTe)) {
3045
            $this->CTe = $this->dom->createElement('CTe');
3046
            $this->CTe->setAttribute('xmlns', 'http://www.portalfiscal.inf.br/cte');
3047
        }
3048
        return $this->CTe;
3049
    }
3050
3051
    /**
3052
     * Tag raiz do documento xml
3053
     * Função chamada pelo método [ monta ]
3054
     * @return \DOMElement
3055
     */
3056
    private function buildCTeOS()
3057
    {
3058
        if (empty($this->CTe)) {
3059
            $this->CTe = $this->dom->createElement('CTeOS');
3060
            $this->CTe->setAttribute('versao', '3.00');
3061
            $this->CTe->setAttribute('xmlns', 'http://www.portalfiscal.inf.br/cte');
3062
        }
3063
        return $this->CTe;
3064
    }
3065
3066
    /**
3067
     * Gera as tags para o elemento: "Entrega" (Informações ref. a previsão de entrega)
3068
     * #69
3069
     * Nível: 2
3070
     * Os parâmetros para esta função são todos os elementos da tag "Entrega" do
3071
     * tipo elemento (Ele = E|CE|A) e nível 3
3072
     *
3073
     * @return \DOMElement
3074
     */
3075
    private function tagEntrega()
3076
    {
3077
        if ($this->compl == '') {
3078
            $this->compl = $this->dom->createElement('compl');
3079
        }
3080
        if ($this->entrega == '') {
3081
            $this->entrega = $this->dom->createElement('Entrega');
3082
            $this->dom->appChild($this->compl, $this->entrega, 'Falta tag "compl"');
3083
        }
3084
        return $this->entrega;
3085
    }
3086
3087
    /**
3088
     * #241
3089
     * @return type
3090
     */
3091
    public function taginfCTeNorm()
3092
    {
3093
        $this->infCTeNorm = $this->dom->createElement('infCTeNorm');
3094
        return $this->infCTeNorm;
3095
    }
3096
3097
    /**
3098
     * Gera as tags para o elemento: "infCarga" (Informações da Carga do CT-e)
3099
     * #242
3100
     * Nível: 2
3101
     *
3102
     * @return \DOMElement
3103
     */
3104
    public function taginfCarga($std)
3105
    {
3106
        $identificador = '#242 <infCarga> - ';
3107
        $this->infCarga = $this->dom->createElement('infCarga');
3108
        $this->dom->addChild(
3109
            $this->infCarga,
3110
            'vCarga',
3111
            $std->vCarga,
3112
            false,
3113
            $identificador . 'Valor Total da Carga'
3114
        );
3115
        $this->dom->addChild(
3116
            $this->infCarga,
3117
            'proPred',
3118
            $std->proPred,
3119
            true,
3120
            $identificador . 'Produto Predominante'
3121
        );
3122
        $this->dom->addChild(
3123
            $this->infCarga,
3124
            'xOutCat',
3125
            $std->xOutCat,
3126
            false,
3127
            $identificador . 'Outras Caract. da Carga'
3128
        );
3129
        return $this->infCarga;
3130
    }
3131
3132
    /**
3133
     * Gera as tags para o elemento: "infCTeNorm" (Informações da Carga do CT-e OS)
3134
     * #253
3135
     * Nível: 2
3136
     * Os parâmetros para esta função são todos os elementos da tag "infServico"
3137
     *
3138
     * @return \DOMElement
3139
     */
3140
    public function taginfServico($std)
3141
    {
3142
        $identificador = '#253 <infServico> - ';
3143
3144
        $this->infServico = $this->dom->createElement('infServico');
3145
        $this->dom->addChild(
3146
            $this->infServico,
3147
            'xDescServ',
3148
            $std->xDescServ,
3149
            true,
3150
            $identificador . 'Descrição do Serviço Prestado'
3151
        );
3152
        $infQ = $this->dom->createElement('infQ');
3153
        $this->dom->addChild($infQ, 'qCarga', $std->qCarga, false, $identificador . 'Quantidade');
3154
3155
        $this->infServico->appendChild($infQ);
3156
3157
        return $this->infServico;
3158
    }
3159
3160
    /**
3161
     * Gera as tags para o elemento: "infQ" (Informações de quantidades da Carga do CT-e)
3162
     * #246
3163
     * Nível: 3
3164
     * Os parâmetros para esta função são todos os elementos da tag "infQ"
3165
     *
3166
     * @return mixed
3167
     */
3168
    public function taginfQ($std)
3169
    {
3170
        $identificador = '#257 <infQ> - ';
3171
        $this->infQ[] = $this->dom->createElement('infQ');
3172
        $posicao = (int)count($this->infQ) - 1;
3173
        $this->dom->addChild($this->infQ[$posicao], 'cUnid', $std->cUnid, true, $identificador . 'Código da
3174
            Unidade de Medida');
3175
        $this->dom->addChild($this->infQ[$posicao], 'tpMed', $std->tpMed, true, $identificador . 'Tipo da Medida');
3176
        $this->dom->addChild($this->infQ[$posicao], 'qCarga', $std->qCarga, true, $identificador . 'Quantidade');
3177
        $this->dom->addChild($this->infQ[$posicao], 'vCargaAverb', $std->vCargaAverb, false, $identificador . 'Valor da Carga para efeito de averbação');
3178
3179
        return $this->infQ[$posicao];
3180
    }
3181
3182
    public function taginfDoc()
3183
    {
3184
        $this->infDoc = $this->dom->createElement('infDoc');
3185
        return $this->infDoc;
3186
    }
3187
3188
    /**
3189
     * Documentos de Transporte Anterior
3190
     * @return DOMElement|\DOMNode
3191
     */
3192
    public function tagdocAnt()
3193
    {
3194
        $this->docAnt = $this->dom->createElement('docAnt');
3195
        return $this->docAnt;
3196
    }
3197
3198
    /**
3199
     * Informações de identificação dos documentos de Transporte Anterior
3200
     * @return array|DOMElement
3201
     */
3202
    public function tagidDocAnt()
3203
    {
3204
        $this->idDocAnt[count($this->emiDocAnt) - 1] = $this->dom->createElement('idDocAnt');
3205
        return $this->idDocAnt;
3206
    }
3207
3208
    /**
3209
     * Gera as tags para o elemento: "infNF" (Informações das NF)
3210
     * #262
3211
     * Nível: 3
3212
     * @return mixed
3213
     */
3214
    public function taginfNF($std)
3215
    {
3216
        $identificador = '#262 <infNF> - ';
3217
        $this->infNF[] = $this->dom->createElement('infNF');
3218
        $posicao = (int)count($this->infNF) - 1;
3219
3220
        $this->dom->addChild($this->infNF[$posicao], 'nRoma', $std->nRoma, false, $identificador . 'Número do
3221
            Romaneio da NF');
3222
        $this->dom->addChild($this->infNF[$posicao], 'nPed', $std->nPed, false, $identificador . 'Número do
3223
            Pedido da NF');
3224
        $this->dom->addChild($this->infNF[$posicao], 'mod', $std->mod, true, $identificador . 'Modelo da
3225
            Nota Fiscal');
3226
        $this->dom->addChild($this->infNF[$posicao], 'serie', $std->serie, true, $identificador . 'Série');
3227
        $this->dom->addChild($this->infNF[$posicao], 'nDoc', $std->nDoc, true, $identificador . 'Número');
3228
        $this->dom->addChild($this->infNF[$posicao], 'dEmi', $std->dEmi, true, $identificador . 'Data de Emissão');
3229
        $this->dom->addChild($this->infNF[$posicao], 'vBC', $std->vBC, true, $identificador . 'Valor da Base
3230
            de Cálculo do ICMS');
3231
        $this->dom->addChild($this->infNF[$posicao], 'vICMS', $std->vICMS, true, $identificador . 'Valor Total
3232
            do ICMS');
3233
        $this->dom->addChild($this->infNF[$posicao], 'vBCST', $std->vBCST, true, $identificador . 'Valor da
3234
            Base de Cálculo do ICMS ST');
3235
        $this->dom->addChild($this->infNF[$posicao], 'vST', $std->vST, true, $identificador . 'Valor Total
3236
            do ICMS ST');
3237
        $this->dom->addChild($this->infNF[$posicao], 'vProd', $std->vProd, true, $identificador . 'Valor Total
3238
            dos Produtos');
3239
        $this->dom->addChild($this->infNF[$posicao], 'vNF', $std->vNF, true, $identificador . 'Valor Total da NF');
3240
        $this->dom->addChild($this->infNF[$posicao], 'nCFOP', $std->nCFOP, true, $identificador . 'CFOP Predominante');
3241
        $this->dom->addChild($this->infNF[$posicao], 'nPeso', $std->nPeso, false, $identificador . 'Peso total em Kg');
3242
        $this->dom->addChild($this->infNF[$posicao], 'PIN', $std->PIN, false, $identificador . 'PIN SUFRAMA');
3243
        $this->dom->addChild($this->infNF[$posicao], 'dPrev', $std->dPrev, false, $identificador . 'Data prevista
3244
            de entrega');
3245
3246
        return $this->infNF[$posicao];
3247
    }
3248
3249
    /**
3250
     * Gera as tags para o elemento: "infNFe" (Informações das NF-e)
3251
     * #297
3252
     * Nível: 3
3253
     * @return mixed
3254
     */
3255
    public function taginfNFe($std)
3256
    {
3257
        $identificador = '#297 <infNFe> - ';
3258
        $this->infNFe[] = $this->dom->createElement('infNFe');
3259
        $posicao = (int)count($this->infNFe) - 1;
3260
        $this->dom->addChild(
3261
            $this->infNFe[$posicao],
3262
            'chave',
3263
            $std->chave,
3264
            true,
3265
            $identificador . 'Chave de acesso da NF-e'
3266
        );
3267
        $this->dom->addChild(
3268
            $this->infNFe[$posicao],
3269
            'PIN',
3270
            $std->PIN,
3271
            false,
3272
            $identificador . 'PIN SUFRAMA'
3273
        );
3274
        $this->dom->addChild(
3275
            $this->infNFe[$posicao],
3276
            'dPrev',
3277
            $std->dPrev,
3278
            false,
3279
            $identificador . 'Data prevista de entrega'
3280
        );
3281
        return $this->infNFe[$posicao];
3282
    }
3283
3284
    /**
3285
     * Gera as tags para o elemento: "infOutros" (Informações dos demais documentos)
3286
     * #319
3287
     * Nível: 3
3288
     * @return mixed
3289
     */
3290
    public function taginfOutros($std)
3291
    {
3292
        $ident = '#319 <infOutros> - ';
3293
        $this->infOutros[] = $this->dom->createElement('infOutros');
3294
        $posicao = (int)count($this->infOutros) - 1;
3295
        $this->dom->addChild($this->infOutros[$posicao], 'tpDoc', $std->tpDoc, true, $ident . 'Tipo '
3296
            . 'de documento originário');
3297
        $this->dom->addChild($this->infOutros[$posicao], 'descOutros', $std->descOutros, false, $ident . 'Descrição '
3298
            . 'do documento');
3299
        $this->dom->addChild($this->infOutros[$posicao], 'nDoc', $std->nDoc, false, $ident . 'Número '
3300
            . 'do documento');
3301
        $this->dom->addChild($this->infOutros[$posicao], 'dEmi', $std->dEmi, false, $ident . 'Data de Emissão');
3302
        $this->dom->addChild($this->infOutros[$posicao], 'vDocFisc', $std->vDocFisc, false, $ident . 'Valor '
3303
            . 'do documento');
3304
        $this->dom->addChild($this->infOutros[$posicao], 'dPrev', $std->dPrev, false, $ident . 'Data '
3305
            . 'prevista de entrega');
3306
        return $this->infOutros[$posicao];
3307
    }
3308
3309
    /**
3310
     * Gera as tags para o elemento: "infDocRef" (Informações dos demais documentos)
3311
     * #319
3312
     * Nível: 3
3313
     * @return mixed
3314
     */
3315
    public function taginfDocRef($std)
3316
    {
3317
        $ident = '#319 <infDocRef> - ';
3318
        $this->infDocRef[] = $this->dom->createElement('infDocRef');
3319
        $posicao = (int)count($this->infDocRef) - 1;
3320
        $this->dom->addChild($this->infDocRef[$posicao], 'nDoc', $std->nDoc, false, $ident . 'Número '
3321
            . 'do documento');
3322
        $this->dom->addChild($this->infDocRef[$posicao], 'serie', $std->serie, false, $ident . 'Série '
3323
            . 'do documento');
3324
        $this->dom->addChild($this->infDocRef[$posicao], 'subserie', $std->subserie, false, $ident . 'Subserie '
3325
            . 'do documento');
3326
        $this->dom->addChild($this->infDocRef[$posicao], 'dEmi', $std->dEmi, false, $ident . 'Data de Emissão');
3327
        $this->dom->addChild($this->infDocRef[$posicao], 'vDoc', $std->vDoc, false, $ident . 'Valor '
3328
            . 'do documento');
3329
        return $this->infDocRef[$posicao];
3330
    }
3331
3332
    /**
3333
     * Gera as tags para o elemento: "emiDocAnt" (Informações dos CT-es Anteriores)
3334
     * #345
3335
     * Nível: 3
3336
     * @return mixed
3337
     */
3338
    public function tagemiDocAnt($std)
3339
    {
3340
        $identificador = '#345 <emiDocAnt> - ';
3341
        $this->emiDocAnt[] = $this->dom->createElement('emiDocAnt');
3342
        $posicao = (int)count($this->emiDocAnt) - 1;
3343
        if ($std->CNPJ != '') {
3344
            $this->dom->addChild(
3345
                $this->emiDocAnt[$posicao],
3346
                'CNPJ',
3347
                $std->CNPJ,
3348
                true,
3349
                $identificador . 'Número do CNPJ'
3350
            );
3351
            $this->dom->addChild(
3352
                $this->emiDocAnt[$posicao],
3353
                'IE',
3354
                Strings::onlyNumbers($std->IE),
3355
                true,
3356
                $identificador . 'Inscrição Estadual'
3357
            );
3358
            $this->dom->addChild($this->emiDocAnt[$posicao], 'UF', $std->UF, true, $identificador . 'Sigla da UF');
3359
        } else {
3360
            $this->dom->addChild($this->emiDocAnt[$posicao], 'CPF', $std->CPF, true, $identificador . 'Número do CPF');
3361
        }
3362
        $this->dom->addChild(
3363
            $this->emiDocAnt[$posicao],
3364
            'xNome',
3365
            $std->xNome,
3366
            true,
3367
            $identificador . 'Razão Social ou Nome do Expedidor'
3368
        );
3369
3370
        return $this->emiDocAnt[$posicao];
3371
    }
3372
3373
    /**
3374
     * Gera as tags para o elemento: "idDocAntEle" (Informações dos CT-es Anteriores)
3375
     * #348
3376
     * Nível: 4
3377
     * @return mixed
3378
     */
3379
    public function tagidDocAntEle($std)
3380
    {
3381
        $identificador = '#358 <idDocAntEle> - ';
3382
        $this->idDocAntEle[count($this->emiDocAnt) - 1][] = $this->dom->createElement('idDocAntEle');
3383
        $posicao = (int)count($this->idDocAntEle[count($this->emiDocAnt) - 1]) - 1;
3384
        $this->dom->addChild($this->idDocAntEle[count($this->emiDocAnt) - 1][$posicao], 'chCTe', $std->chCTe, true, $identificador . 'Chave de Acesso do CT-e');
3385
        return $this->idDocAntEle[count($this->emiDocAnt) - 1][$posicao];
3386
    }
3387
3388
3389
    /**
3390
     * Gera as tags para o elemento: "seg" (Informações de Seguro da Carga)
3391
     * #360
3392
     * Nível: 2
3393
     * @return mixed
3394
     */
3395
    public function tagseg($std)
3396
    {
3397
        $identificador = '#360 <seg> - ';
3398
        $this->seg[] = $this->dom->createElement('seg');
3399
        $posicao = (int)count($this->seg) - 1;
3400
3401
        $this->dom->addChild($this->seg[$posicao], 'respSeg', $std->respSeg, true, $identificador . 'Responsável
3402
            pelo Seguro');
3403
        $this->dom->addChild($this->seg[$posicao], 'xSeg', $std->xSeg, false, $identificador . 'Nome da
3404
            Seguradora');
3405
        $this->dom->addChild($this->seg[$posicao], 'nApol', $std->nApol, false, $identificador . 'Número da Apólice');
3406
        return $this->seg[$posicao];
3407
    }
3408
3409
    /**
3410
     * Gera as tags para o elemento: "idDocAntEle" (Informações dos CT-es Anteriores)
3411
     * #348
3412
     * Nível: 4
3413
     * @return mixed
3414
     */
3415
    public function tagidDocAntPap($std)
3416
    {
3417
        $identificador = '#358 <idDocAntPap> - ';
3418
3419
        $this->idDocAntPap[count($this->emiDocAnt) - 1][] = $this->dom->createElement('idDocAntPap');
3420
        $posicao = (int)count($this->idDocAntPap[count($this->emiDocAnt) - 1]) - 1;
3421
3422
        $this->dom->addChild($this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao], 'tpDoc', $std->tpDoc, true, $identificador . 'Tipo do Documento de Transporte Anterior');
3423
        $this->dom->addChild($this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao], 'serie', $std->serie, true, $identificador . 'Série do Documento Fiscal');
3424
        $this->dom->addChild($this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao], 'subser', $std->subser, false, $identificador . 'Série do Documento Fiscal');
3425
        $this->dom->addChild($this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao], 'nDoc', $std->nDoc, true, $identificador . 'Número do Documento Fiscal');
3426
        $this->dom->addChild($this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao], 'dEmi', $std->dEmi, true, $identificador . 'Data de emissão (AAAA-MM-DD)');
3427
        return $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao];
3428
    }
3429
3430
3431
    /**
3432
     * Gera as tags para o elemento: "infModal" (Informações do modal)
3433
     * #366
3434
     * Nível: 2
3435
     * @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...
3436
     * @return DOMElement|\DOMNode
3437
     */
3438
    public function taginfModal($std)
3439
    {
3440
        $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...
3441
        $this->infModal = $this->dom->createElement('infModal');
3442
        $this->infModal->setAttribute('versaoModal', $std->versaoModal);
3443
        return $this->infModal;
3444
    }
3445
3446
    /**
3447
     * Leiaute - Rodoviário
3448
     * Gera as tags para o elemento: "rodo" (Informações do modal Rodoviário)
3449
     * #1
3450
     * Nível: 0
3451
     * @return DOMElement|\DOMNode
3452
     */
3453
    public function tagrodo($std)
3454
    {
3455
        $identificador = '#1 <rodo> - ';
3456
        $this->rodo = $this->dom->createElement('rodo');
3457
        $this->dom->addChild(
3458
            $this->rodo,
3459
            'RNTRC',
3460
            $std->RNTRC,
3461
            true,
3462
            $identificador . 'Registro nacional de transportadores
3463
            rodoviários de carga'
3464
        );
3465
3466
        return $this->rodo;
3467
    }
3468
3469
    /**
3470
     * Leiaute - Aquaviario
3471
     * Gera as tags para o elemento: "aquav" (informações do modal Aquaviario)
3472
     * @author Anderson Minuto Consoni Vaz
3473
     * #1
3474
     * Nivel: 0
3475
     * @return DOMElement|\DOMNode
3476
     */
3477
    public function tagaquav($std)
3478
    {
3479
        $identificador = '#1 <aquav> - ';
3480
        $this->aquav = $this->dom->createElement('aquav');
3481
        $this->dom->addChild(
3482
            $this->aquav,
3483
            'vPrest',
3484
            $std->vPrest,
3485
            true,
3486
            $identificador . 'vPrest'
3487
        );
3488
        $this->dom->addChild(
3489
            $this->aquav,
3490
            'vAFRMM',
3491
            $std->vAFRMM,
3492
            true,
3493
            $identificador . 'vAFRMM'
3494
        );
3495
        $this->dom->addChild(
3496
            $this->aquav,
3497
            'xNavio',
3498
            $std->xNavio,
3499
            true,
3500
            $identificador . 'xNavio'
3501
        );
3502
        $this->dom->addChild(
3503
            $this->aquav,
3504
            'nViag',
3505
            $std->nViag,
3506
            true,
3507
            $identificador . 'nViag'
3508
        );
3509
        $this->dom->addChild(
3510
            $this->aquav,
3511
            'direc',
3512
            $std->direc,
3513
            true,
3514
            $identificador . 'direc'
3515
        );
3516
        $this->dom->addChild(
3517
            $this->aquav,
3518
            'irin',
3519
            $std->irin,
3520
            true,
3521
            $identificador . 'irin'
3522
        );
3523
        $this->dom->addChild(
3524
            $this->aquav,
3525
            'tpNav',
3526
            $std->tpNav,
3527
            true,
3528
            $identificador . 'tpNav'
3529
        );
3530
        return $this->aquav;
3531
    }
3532
3533
    /**
3534
     * Leiaute - Rodoviário
3535
     * Gera as tags para o elemento: "rodo" (Informações do modal Rodoviário) CT-e OS
3536
     * #1
3537
     * Nível: 0
3538
     * @return DOMElement|\DOMNode
3539
     */
3540
    public function tagrodoOS($std)
3541
    {
3542
        $identificador = '#1 <rodoOS> - ';
3543
        $this->rodo = $this->dom->createElement('rodoOS');
3544
        $this->dom->addChild($this->rodo, 'TAF', $std->TAF, false, $identificador .
3545
            'Termo de Autorização de Fretamento - TAF');
3546
        $this->dom->addChild($this->rodo, 'NroRegEstadual', $std->nroRegEstadual, false, $identificador .
3547
            'Número do Registro Estadual');
3548
3549
        return $this->rodo;
3550
    }
3551
3552
    /**
3553
     * Leiaute - Aéreo
3554
     * Gera as tags para o elemento: "aereo" (Informações do modal Aéreo)
3555
     * @author Newton Pasqualini Filho
3556
     * #1
3557
     * Nível: 0
3558
     * @return DOMElement|\DOMNode
3559
     */
3560
    public function tagaereo($std)
3561
    {
3562
        $identificador = '#1 <aereo> - ';
3563
        $this->aereo = $this->dom->createElement('aereo');
3564
        $this->dom->addChild(
3565
            $this->aereo,
3566
            'nMinu',
3567
            $std->nMinu,
3568
            false,
3569
            $identificador . 'Número da Minuta'
3570
        );
3571
        $this->dom->addChild(
3572
            $this->aereo,
3573
            'nOCA',
3574
            $std->nOCA,
3575
            false,
3576
            $identificador . 'Número Operacional do Conhecimento Aéreo'
3577
        );
3578
        $this->dom->addChild(
3579
            $this->aereo,
3580
            'dPrevAereo',
3581
            $std->dPrevAereo,
3582
            true,
3583
            $identificador . 'Data prevista da entrega'
3584
        );
3585
        if (isset($std->natCarga_xDime) || isset($std->natCarga_cInfManu)) {
3586
            $identificador = '#1 <aereo> - <natCarga> - ';
3587
            $this->natCarga = $this->dom->createElement('natCarga');
3588
            $this->dom->addChild(
3589
                $this->natCarga,
3590
                'xDime',
3591
                $std->natCarga_xDime,
3592
                false,
3593
                $identificador . 'Dimensões da carga, formato: 1234x1234x1234 (cm)'
3594
            );
3595
            if (isset($std->natCarga_cInfManu) && !is_array($std->natCarga_cInfManu)) {
3596
                $std->natCarga_cInfManu = [$std->natCarga_cInfManu];
3597
            }
3598
            $cInfManuX = 0;
3599
            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...
3600
                $cInfManuX++;
3601
                $this->dom->addChild(
3602
                    $this->natCarga,
3603
                    'cInfManu',
3604
                    $cInfManu,
3605
                    false,
3606
                    $identificador . 'Informação de manuseio, com dois dígitos, pode ter mais de uma ocorrência.'
3607
                );
3608
            }
3609
            $this->aereo->appendChild($this->natCarga);
3610
        }
3611
        $identificador = '#1 <aereo> - <tarifa> - ';
3612
        $this->tarifa = $this->dom->createElement('tarifa');
3613
        $this->dom->addChild(
3614
            $this->tarifa,
3615
            'CL',
3616
            $std->tarifa_CL,
3617
            true,
3618
            $identificador . 'Classe da tarifa: M - Tarifa Mínima / G - Tarifa Geral / E - Tarifa Específica'
3619
        );
3620
        $this->dom->addChild(
3621
            $this->tarifa,
3622
            'cTar',
3623
            $std->tarifa_cTar,
3624
            false,
3625
            $identificador . 'Código de três digítos correspondentes à tarifa.'
3626
        );
3627
        $this->dom->addChild(
3628
            $this->tarifa,
3629
            'vTar',
3630
            $std->tarifa_vTar,
3631
            true,
3632
            $identificador . 'Valor da tarifa. 15 posições, sendo 13 inteiras e 2 decimais.'
3633
        );
3634
        $this->aereo->appendChild($this->tarifa);
3635
        return $this->aereo;
3636
    }
3637
3638
    /**
3639
     * CT-e de substituição
3640
     * @return type
3641
     */
3642
    public function taginfCteSub($std)
3643
    {
3644
        $identificador = '#149 <infCteSub> - ';
3645
        $this->infCteSub = $this->dom->createElement('infCteSub');
3646
3647
        $this->dom->addChild(
3648
            $this->infCteSub,
3649
            'chCTe',
3650
            $std->chCTe,
3651
            false,
3652
            "$identificador  Chave de acesso do CTe a ser substituído (original)"
3653
        );
3654
        $this->dom->addChild(
3655
            $this->infCteSub,
3656
            'retCteAnu',
3657
            $std->retCteAnu,
3658
            false,
3659
            "$identificador  Chave de acesso do CT-e de Anulação"
3660
        );
3661
        return $this->infCteSub;
3662
    }
3663
3664
3665
    /**
3666
     * CT-e de substituição - tomaICMS
3667
     * @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...
3668
     * @return type
3669
     */
3670
    public function tagtomaICMS()
3671
    {
3672
        $this->tomaICMS = $this->dom->createElement('tomaICMS');
3673
3674
        return $this->tomaICMS;
3675
    }
3676
3677
    /**
3678
     * CT-e de substituição - NF-e
3679
     * @param type $std
3680
     * @return type
3681
     */
3682
    public function tagrefNFe($std)
3683
    {
3684
        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...
3685
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
3686
        }
3687
        $identificador = '#153 <refNFe> - ';
3688
        $this->dom->addChild(
3689
            $this->tomaICMS,
3690
            'refNFe',
3691
            $std->refNFe,
3692
            false,
3693
            "$identificador  Chave de acesso da NF-e emitida pelo tomador"
3694
        );
3695
3696
        return $this->tomaICMS;
3697
    }
3698
3699
    /**
3700
     * CT-e de substituição - NF
3701
     * @param type $std
3702
     * @return type
3703
     */
3704
    public function tagrefNF($std)
3705
    {
3706
        $identificador = '#154 <refNFe> - ';
3707
        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...
3708
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
3709
        }
3710
        $this->refNF = $this->dom->createElement('refNF');
3711
        if ($std->CNPJ != '') {
3712
            $this->dom->addChild(
3713
                $this->refNF,
3714
                'CNPJ',
3715
                $std->CNPJ,
3716
                true,
3717
                $identificador . 'CNPJ do emitente'
3718
            );
3719
        } elseif ($std->CPF != '') {
3720
            $this->dom->addChild(
3721
                $this->refNF,
3722
                'CPF',
3723
                $std->CPF,
3724
                true,
3725
                $identificador . 'CPF do emitente'
3726
            );
3727
        }
3728
        $this->dom->addChild($this->refNF, 'mod', $std->mod, false, $identificador . 'Modelo');
3729
        $this->dom->addChild($this->refNF, 'serie', $std->serie, false, $identificador . 'Série '
3730
            . 'do documento');
3731
        $this->dom->addChild($this->refNF, 'subserie', $std->subserie, false, $identificador . 'Subserie '
3732
            . 'do documento');
3733
        $this->dom->addChild($this->refNF, 'nro', $std->nro, false, $identificador . 'Número');
3734
        $this->dom->addChild($this->refNF, 'valor', $std->valor, false, $identificador . 'Valor');
3735
        $this->dom->addChild($this->refNF, 'dEmi', $std->dEmi, false, $identificador . 'Emissão');
3736
3737
        $this->tomaICMS->appendChild($this->refNF);
3738
3739
        return $this->tomaICMS;
3740
    }
3741
3742
    /**
3743
     * CT-e de substituição - CT-e
3744
     * @param type $std
3745
     * @return type
3746
     */
3747
    public function tagrefCTe($std)
3748
    {
3749
        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...
3750
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
3751
        }
3752
        $identificador = '#163 <refCTe> - ';
3753
        $this->dom->addChild(
3754
            $this->tomaICMS,
3755
            'refCTe',
3756
            $std->refCTe,
3757
            false,
3758
            "$identificador  Chave de acesso do CT-e emitida pelo tomador"
3759
        );
3760
3761
        return $this->tomaICMS;
3762
    }
3763
3764
    /**
3765
     * Leiaute - Rodoviário
3766
     * Gera as tags para o elemento: "veic" (Dados dos Veículos)
3767
     * #21
3768
     * Nível: 1
3769
     * @return mixed
3770
     */
3771
    public function tagveicCTeOS($std)
3772
    {
3773
        $identificador = '#21 <veic> - ';
3774
        $this->veic = $this->dom->createElement('veic');
3775
3776
        $this->dom->addChild(
3777
            $this->veic,
3778
            'placa',
3779
            $std->placa,
3780
            false,
3781
            $identificador . 'Placa do veículo'
3782
        );
3783
        $this->dom->addChild(
3784
            $this->veic,
3785
            'RENAVAM',
3786
            $std->RENAVAM,
3787
            false,
3788
            $identificador . 'RENAVAM do veículo'
3789
        );
3790
        if ($std->xNome != '') { // CASO FOR VEICULO DE TERCEIRO
3791
            $this->prop = $this->dom->createElement('prop');
3792
            if ($std->CNPJ != '') {
3793
                $this->dom->addChild(
3794
                    $this->prop,
3795
                    'CNPJ',
3796
                    $std->CNPJ,
3797
                    true,
3798
                    $identificador . 'CNPJ do proprietario'
3799
                );
3800
            } elseif ($std->CPF != '') {
3801
                $this->dom->addChild(
3802
                    $this->prop,
3803
                    'CPF',
3804
                    $std->CPF,
3805
                    true,
3806
                    $identificador . 'CPF do proprietario'
3807
                );
3808
            }
3809
            if ($std->taf != '') {
3810
                $this->dom->addChild(
3811
                    $this->prop,
3812
                    'TAF',
3813
                    $std->taf,
3814
                    false,
3815
                    $identificador . 'TAF'
3816
                );
3817
            } else {
3818
                $this->dom->addChild(
3819
                    $this->prop,
3820
                    'NroRegEstadual',
3821
                    $std->nroRegEstadual,
3822
                    false,
3823
                    $identificador . 'Número do Registro Estadual'
3824
                );
3825
            }
3826
            $this->dom->addChild(
3827
                $this->prop,
3828
                'xNome',
3829
                $std->xNome,
3830
                true,
3831
                $identificador . 'Nome do proprietario'
3832
            );
3833
            $this->dom->addChild(
3834
                $this->prop,
3835
                'IE',
3836
                Strings::onlyNumbers($std->IE),
3837
                false,
3838
                $identificador . 'IE do proprietario'
3839
            );
3840
            $this->dom->addChild(
3841
                $this->prop,
3842
                'UF',
3843
                $std->ufProp,
3844
                true,
3845
                $identificador . 'UF do proprietario'
3846
            );
3847
            $this->dom->addChild(
3848
                $this->prop,
3849
                'tpProp',
3850
                $std->tpProp,
3851
                true,
3852
                $identificador . 'Tipo Proprietário'
3853
            );
3854
            $this->dom->appChild($this->veic, $this->prop, 'Falta tag "prop"');
3855
        }
3856
        $this->dom->addChild(
3857
            $this->veic,
3858
            'UF',
3859
            $std->uf,
3860
            true,
3861
            $identificador . 'UF em que veículo está licenciado'
3862
        );
3863
        return $this->veic;
3864
    }
3865
3866
    public function infFretamento($std)
3867
    {
3868
        $identificador = '#21 <infFretamento> - ';
3869
        $this->infFretamento = $this->dom->createElement('infFretamento');
3870
3871
        $this->dom->addChild(
3872
            $this->infFretamento,
3873
            'tpFretamento',
3874
            $std->tpFretamento,
3875
            true,
3876
            $identificador . 'Tipo do Fretamento de Pessoas'
3877
        );
3878
        $this->dom->addChild(
3879
            $this->infFretamento,
3880
            'dhViagem',
3881
            $std->dhViagem,
3882
            false,
3883
            $identificador . 'Data e hora da viagem'
3884
        );
3885
        return $this->infFretamento;
3886
    }
3887
3888
    /**
3889
     * Gera as tags para o elemento: "infCteComp" (Detalhamento do CT-e complementado)
3890
     * #410
3891
     * Nível: 1
3892
     * @return DOMElement|\DOMNode
3893
     */
3894
    public function taginfCTeComp($std)
3895
    {
3896
        $identificador = '#410 <infCteComp> - ';
3897
        $this->infCteComp = $this->dom->createElement('infCteComp');
3898
        $this->dom->addChild(
3899
            $this->infCteComp,
3900
            'chCTe',
3901
            $std->chCTe,
3902
            true,
3903
            $identificador . ' Chave do CT-e complementado'
3904
        );
3905
        return $this->infCteComp;
3906
    }
3907
3908
    /**
3909
     * Gera as tags para o elemento: "infCteAnu" (Detalhamento do CT-e de Anulação)
3910
     * #411
3911
     * Nível: 1
3912
     * @return DOMElement|\DOMNode
3913
     */
3914
    public function taginfCteAnu($std)
3915
    {
3916
        $identificador = '#411 <infCteAnu> - ';
3917
        $this->infCteAnu = $this->dom->createElement('infCteAnu');
3918
        $this->dom->addChild(
3919
            $this->infCteAnu,
3920
            'chCte',
3921
            $std->chave,
3922
            true,
3923
            $identificador . ' Chave do CT-e anulado'
3924
        );
3925
        $this->dom->addChild(
3926
            $this->infCteAnu,
3927
            'dEmi',
3928
            $std->data,
3929
            true,
3930
            $identificador . ' Data de Emissão do CT-e anulado'
3931
        );
3932
        return $this->infCteAnu;
3933
    }
3934
3935
    /**
3936
     * Gera as tags para o elemento: "autXML" (Autorizados para download do XML)
3937
     * #396
3938
     * Nível: 1
3939
     * Os parâmetros para esta função são todos os elementos da tag "autXML"
3940
     *
3941
     * @return boolean
3942
     */
3943
    public function tagveicNovos($std)
3944
    {
3945
        $identificador = '#396 <veicNovos> - ';
3946
        $veicNovos = $this->dom->createElement('veicNovos');
3947
        $this->dom->addChild(
3948
            $veicNovos,
3949
            'chassi',
3950
            $std->chassi,
3951
            true,
3952
            $identificador . 'Chassi do veículo '
3953
        );
3954
        $this->dom->addChild(
3955
            $veicNovos,
3956
            'cCor',
3957
            $std->cCor,
3958
            true,
3959
            $identificador . 'Cor do veículo '
3960
        );
3961
        $this->dom->addChild(
3962
            $veicNovos,
3963
            'xCor',
3964
            $std->xCor,
3965
            true,
3966
            $identificador . 'Descrição da cor '
3967
        );
3968
        $this->dom->addChild(
3969
            $veicNovos,
3970
            'cMod',
3971
            $std->cMod,
3972
            true,
3973
            $identificador . 'Código Marca Modelo '
3974
        );
3975
        $this->dom->addChild(
3976
            $veicNovos,
3977
            'vUnit',
3978
            $std->vUnit,
3979
            true,
3980
            $identificador . 'Valor Unitário do Veículo '
3981
        );
3982
        $this->dom->addChild(
3983
            $veicNovos,
3984
            'vFrete',
3985
            $std->vFrete,
3986
            true,
3987
            $identificador . 'Frete Unitário '
3988
        );
3989
        $this->veicNovos[] = $veicNovos;
3990
        return $veicNovos;
3991
    }
3992
3993
    /**
3994
     * Gera as tags para o elemento: "autXML" (Autorizados para download do XML)
3995
     * #396
3996
     * Nível: 1
3997
     * Os parâmetros para esta função são todos os elementos da tag "autXML"
3998
     *
3999
     * @return boolean
4000
     */
4001
    public function tagautXML($std)
4002
    {
4003
        $identificador = '#396 <autXML> - ';
4004
        $autXML = $this->dom->createElement('autXML');
4005
        if (isset($std->CNPJ) && $std->CNPJ != '') {
4006
            $this->dom->addChild(
4007
                $autXML,
4008
                'CNPJ',
4009
                $std->CNPJ,
4010
                true,
4011
                $identificador . 'CNPJ do Cliente Autorizado'
4012
            );
4013
        } elseif (isset($std->CPF) && $std->CPF != '') {
4014
            $this->dom->addChild(
4015
                $autXML,
4016
                'CPF',
4017
                $std->CPF,
4018
                true,
4019
                $identificador . 'CPF do Cliente Autorizado'
4020
            );
4021
        }
4022
4023
        $this->autXML[] = $autXML;
4024
        return $autXML;
4025
    }
4026
4027
    /**
4028
     * #359
4029
     * tag CTe/infCTe/cobr (opcional)
4030
     * Depende de fat
4031
     */
4032
    protected function buildCobr()
4033
    {
4034
        if (empty($this->cobr)) {
4035
            $this->cobr = $this->dom->createElement("cobr");
4036
        }
4037
    }
4038
4039
    /**
4040
     * #360
4041
     * tag CTe/infCTe/cobr/fat (opcional)
4042
     * @param stdClass $std
4043
     * @return DOMElement
4044
     */
4045
    public function tagfat(stdClass $std)
4046
    {
4047
        $this->buildCobr();
4048
        $fat = $this->dom->createElement("fat");
4049
        $this->dom->addChild(
4050
            $fat,
4051
            "nFat",
4052
            $std->nFat,
4053
            false,
4054
            "Número da Fatura"
4055
        );
4056
        $this->dom->addChild(
4057
            $fat,
4058
            "vOrig",
4059
            $std->vOrig,
4060
            false,
4061
            "Valor Original da Fatura"
4062
        );
4063
        $this->dom->addChild(
4064
            $fat,
4065
            "vDesc",
4066
            $std->vDesc,
4067
            false,
4068
            "Valor do desconto"
4069
        );
4070
        $this->dom->addChild(
4071
            $fat,
4072
            "vLiq",
4073
            $std->vLiq,
4074
            false,
4075
            "Valor Líquido da Fatura"
4076
        );
4077
        $this->dom->appChild($this->cobr, $fat);
4078
        return $fat;
4079
    }
4080
4081
    /**
4082
     * #365
4083
     * tag CTe/infCTe/cobr/fat/dup (opcional)
4084
     * É necessário criar a tag fat antes de criar as duplicatas
4085
     * @param stdClass $std
4086
     * @return DOMElement
4087
     */
4088
    public function tagdup(stdClass $std)
4089
    {
4090
        $this->buildCobr();
4091
        $dup = $this->dom->createElement("dup");
4092
        $this->dom->addChild(
4093
            $dup,
4094
            "nDup",
4095
            $std->nDup,
4096
            false,
4097
            "Número da Duplicata"
4098
        );
4099
        $this->dom->addChild(
4100
            $dup,
4101
            "dVenc",
4102
            $std->dVenc,
4103
            false,
4104
            "Data de vencimento"
4105
        );
4106
        $this->dom->addChild(
4107
            $dup,
4108
            "vDup",
4109
            $std->vDup,
4110
            true,
4111
            "Valor da duplicata"
4112
        );
4113
        $this->dom->appChild($this->cobr, $dup, 'Inclui duplicata na tag cobr');
4114
        return $dup;
4115
    }
4116
4117
    /**
4118
     * Informações do Responsável técnico
4119
     * tag CTe/infCte/infRespTec (opcional)
4120
     * @return DOMElement
4121
     * @throws RuntimeException
4122
     */
4123
    public function taginfRespTec(stdClass $std)
4124
    {
4125
        $infRespTec = $this->dom->createElement("infRespTec");
4126
        $this->dom->addChild(
4127
            $infRespTec,
4128
            "CNPJ",
4129
            $std->CNPJ,
4130
            true,
4131
            "Informar o CNPJ da pessoa jurídica responsável pelo sistema "
4132
            . "utilizado na emissão do documento fiscal eletrônico"
4133
        );
4134
        $this->dom->addChild(
4135
            $infRespTec,
4136
            "xContato",
4137
            $std->xContato,
4138
            true,
4139
            "Informar o nome da pessoa a ser contatada na empresa desenvolvedora "
4140
            . "do sistema utilizado na emissão do documento fiscal eletrônico"
4141
        );
4142
        $this->dom->addChild(
4143
            $infRespTec,
4144
            "email",
4145
            $std->email,
4146
            true,
4147
            "Informar o e-mail da pessoa a ser contatada na empresa "
4148
            . "desenvolvedora do sistema."
4149
        );
4150
        $this->dom->addChild(
4151
            $infRespTec,
4152
            "fone",
4153
            $std->fone,
4154
            true,
4155
            "Informar o telefone da pessoa a ser contatada na empresa "
4156
            . "desenvolvedora do sistema."
4157
        );
4158
        if (!empty($std->CSRT) && !empty($std->idCSRT)) {
4159
            $this->csrt = $std->CSRT;
0 ignored issues
show
Bug introduced by
The property csrt does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
4160
            $this->dom->addChild(
4161
                $infRespTec,
4162
                "idCSRT",
4163
                $std->idCSRT,
4164
                true,
4165
                "Identificador do CSRT utilizado para montar o hash do CSRT"
4166
            );
4167
            $this->dom->addChild(
4168
                $infRespTec,
4169
                "hashCSRT",
4170
                $this->hashCSRT($std->CSRT),
0 ignored issues
show
Bug introduced by
The method hashCSRT() does not seem to exist on object<NFePHP\CTe\Make>.

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

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

Loading history...
4171
                true,
4172
                "hash do CSRT"
4173
            );
4174
        }
4175
        $this->infRespTec = $infRespTec;
4176
        return $infRespTec;
4177
    }
4178
4179
    protected function checkCTeKey(Dom $dom)
4180
    {
4181
        $infCTe = $dom->getElementsByTagName("infCte")->item(0);
4182
        $ide = $dom->getElementsByTagName("ide")->item(0);
4183
        $emit = $dom->getElementsByTagName("emit")->item(0);
4184
        $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue;
4185
        $dhEmi = $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue;
4186
        $cnpj = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
4187
        $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue;
4188
        $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
4189
        $nNF = $ide->getElementsByTagName('nCT')->item(0)->nodeValue;
4190
        $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue;
4191
        $cCT = $ide->getElementsByTagName('cCT')->item(0)->nodeValue;
4192
        $chave = str_replace('CTe', '', $infCTe->getAttribute("Id"));
4193
4194
        $dt = new DateTime($dhEmi);
4195
4196
        $chaveMontada = Keys::build(
4197
            $cUF,
4198
            $dt->format('y'),
4199
            $dt->format('m'),
4200
            $cnpj,
4201
            $mod,
4202
            $serie,
4203
            $nNF,
4204
            $tpEmis,
4205
            $cCT
4206
        );
4207
        //caso a chave contida no CTe esteja errada
4208
        //substituir a chave
4209
        if ($chaveMontada != $chave) {
4210
            $ide->getElementsByTagName('cDV')->item(0)->nodeValue = substr($chaveMontada, -1);
4211
            $infCTe = $dom->getElementsByTagName("infCte")->item(0);
4212
            $infCTe->setAttribute("Id", "CTe" . $chaveMontada);
4213
            $this->chCTe = $chaveMontada;
4214
        }
4215
    }
4216
}
4217