Test Setup Failed
Push — master ( 7cc9e6...aae526 )
by
unknown
39s queued 10s
created

src/Make.php (13 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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