Passed
Push — master ( e44e5d...e73a1b )
by
unknown
58s queued 18s
created

Make::infCTeMultimodal()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 0
cts 19
cp 0
rs 9.552
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace NFePHP\CTe;
4
5
/**
6
 *
7
 * @category  Library
8
 * @package   nfephp-org/sped-cte
9
 * @copyright 2009-2016 NFePHP
10
 * @name      Make.php
11
 * @license   http://www.gnu.org/licenses/gpl.html GNU/GPL v.3
12
 * @link      http://github.com/nfephp-org/sped-cte for the canonical source repository
13
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
14
 */
15
16
use DOMElement;
17
use NFePHP\Common\DOMImproved as Dom;
18
use NFePHP\Common\Keys;
19
use NFePHP\Common\Strings;
20
use RuntimeException;
21
use stdClass;
22
23
class Make
24
{
25
    /**
26
     * @var array
27
     */
28
    public $errors = [];
29
30
    /**
31
     * versao
32
     * numero da versão do xml da CTe
33
     * @var string
34
     */
35
    public $versao = '3.00';
36
    /**
37
     * mod
38
     * modelo da CTe 57
39
     * @var integer
40
     */
41
    public $mod = 57;
42
    /**
43
     * chave da MDFe
44
     * @var string
45
     */
46
    public $chCTe = '';
47
    /**
48
     * xml
49
     * String com o xml do documento fiscal montado
50
     * @var string
51
     */
52
    public $xml = '';
53
    /**
54
     * dom
55
     * Variável onde será montado o xml do documento fiscal
56
     * @var \NFePHP\Common\Dom\Dom
57
     */
58
    public $dom;
59
    /**
60
     * tpAmb
61
     * tipo de ambiente
62
     * @var string
63
     */
64
    public $tpAmb = '2';
65
    /**
66
     * Modal do Cte
67
     * @var integer
68
     */
69
    private $modal = 0;
70
    /**
71
     * Tag CTe
72
     * @var \DOMNode
73
     */
74
    private $CTe = '';
75
    /**
76
     * Informações do CT-e
77
     * @var \DOMNode
78
     */
79
    private $infCte = '';
80
    /**
81
     * Identificação do CT-e
82
     * @var \DOMNode
83
     */
84
    private $ide = '';
85
    /**
86
     * Percurso do CT-e OS
87
     * @var \DOMNode
88
     */
89
    private $infPercurso = [];
90
    /**
91
     * Tipo do Serviço
92
     * @var integer
93
     */
94
    private $tpServ = 0;
95
    /**
96
     * Indicador do "papel" do tomador do serviço no CT-e
97
     * @var \DOMNode
98
     */
99
    private $toma3 = '';
100
    /**
101
     * Indicador do "papel" do tomador do serviço no CT-e
102
     * @var \DOMNode
103
     */
104
    private $toma4 = '';
105
    /**
106
     * Indicador do "papel" do tomador do serviço no CT-e OS
107
     * @var \DOMNode
108
     */
109
    private $toma = '';
110
    /**
111
     * Dados do endereço
112
     * @var \DOMNode
113
     */
114
    private $enderToma = '';
115
    /**
116
     * Dados complementares do CT-e para fins operacionais ou comerciais
117
     * @var \DOMNode
118
     */
119
    private $compl = '';
120
    /**
121
     * Previsão do fluxo da carga
122
     * @var \DOMNode
123
     */
124
    private $fluxo = '';
125
    /**
126
     * Passagem
127
     * @var array
128
     */
129
    private $pass = array();
130
    /**
131
     * Informações ref. a previsão de entrega
132
     * @var \DOMNode
133
     */
134
    private $entrega = '';
135
    /**
136
     * Entrega sem data definida
137
     * @var \DOMNode
138
     */
139
    private $semData = '';
140
    /**
141
     * Entrega com data definida
142
     * @var \DOMNode
143
     */
144
    private $comData = '';
145
    /**
146
     * Entrega no período definido
147
     * @var \DOMNode
148
     */
149
    private $noPeriodo = '';
150
    /**
151
     * Entrega sem hora definida
152
     * @var \DOMNode
153
     */
154
    private $semHora = '';
155
    /**
156
     * Entrega com hora definida
157
     * @var \DOMNode
158
     */
159
    private $comHora = '';
160
    /**
161
     * Entrega no intervalo de horário definido
162
     * @var \DOMNode
163
     */
164
    private $noInter = '';
165
    /**
166
     * Campo de uso livre do contribuinte
167
     * @var array
168
     */
169
    private $obsCont = array();
170
    /**
171
     * Campo de uso livre do contribuinte
172
     * @var array
173
     */
174
    private $obsFisco = array();
175
    /**
176
     * Identificação do Emitente do CT-e
177
     * @var \DOMNode
178
     */
179
    private $emit = '';
180
    /**
181
     * Endereço do emitente
182
     * @var \DOMNode
183
     */
184
    private $enderEmit = '';
185
    /**
186
     * Informações do Remetente das mercadorias transportadas pelo CT-e
187
     * @var \DOMNode
188
     */
189
    private $rem = '';
190
    /**
191
     * Dados do endereço
192
     * @var \DOMNode
193
     */
194
    private $enderReme = '';
195
    /**
196
     * Informações do Expedidor da Carga
197
     * @var \DOMNode
198
     */
199
    private $exped = '';
200
    /**
201
     * Dados do endereço
202
     * @var \DOMNode
203
     */
204
    private $enderExped = '';
205
    /**
206
     * Informações do Recebedor da Carga
207
     * @var \DOMNode
208
     */
209
    private $receb = '';
210
    /**
211
     * Dados do endereço
212
     * @var \DOMNode
213
     */
214
    private $enderReceb = '';
215
    /**
216
     * Informações do Destinatário do CT-e
217
     * @var \DOMNode
218
     */
219
    private $dest = '';
220
    /**
221
     * Dados do endereço
222
     * @var \DOMNode
223
     */
224
    private $enderDest = '';
225
    /**
226
     * Valores da Prestação de Serviço
227
     * @var \DOMNode
228
     */
229
    private $vPrest = '';
230
    /**
231
     * Componentes do Valor da Prestação
232
     * @var array
233
     */
234
    private $comp = array();
235
    /**
236
     * Informações relativas aos Impostos
237
     * @var \DOMNode
238
     */
239
    private $imp = '';
240
    /**
241
     * Observações adicionais da CT-e
242
     * @var string
243
     */
244
    private $xObs = '';
245
    /**
246
     * Grupo de informações do CT-e Normal e Substituto
247
     * @var \DOMNode
248
     */
249
    private $infCTeNorm = '';
250
    /**
251
     * Informações da Carga do CT-e
252
     * @var \DOMNode
253
     */
254
    private $infCarga = '';
255
    /**
256
     * Informações da Prestação do Serviço
257
     * @var \DOMNode
258
     */
259
    private $infServico = '';
260
    /**
261
     * Informações de quantidades da Carga do CT-e
262
     * @var \DOMNode
263
     */
264
    private $infQ = array();
265
    /**
266
     * Informações dos documentos transportados pelo CT-e Opcional para Redespacho Intermediario
267
     * e Serviço vinculado a multimodal.
268
     * @var \DOMNode
269
     */
270
    private $infDoc = array();
271
    /**
272
     * Informações das NF
273
     * @var array
274
     */
275
    private $infNF = array();
276
    /**
277
     * Informações das NF-e
278
     * @var array
279
     */
280
    private $infNFe = array();
281
    /**
282
     * Informações dos demais documentos
283
     * @var array
284
     */
285
    private $infOutros = array();
286
    /**
287
     * Informações dos demais documentos
288
     * @var array
289
     */
290
    private $infDocRef = array();
291
    /**
292
     * Informações das Unidades de Transporte (Carreta/Reboque/Vagão)
293
     * @var array
294
     */
295
    private $infUnidTransp = array();
296
    /**
297
     * Lacres das Unidades de Transporte
298
     * @var array
299
     */
300
    private $lacUnidTransp = array();
301
    /**
302
     * Informações das Unidades de Carga (Containeres/ULD/Outros)
303
     * @var array
304
     */
305
    private $infUnidCarga = array();
306
    /**
307
     * Lacres das Unidades de Carga
308
     * @var array
309
     */
310
    private $lacUnidCarga = array();
311
    /**
312
     * Documentos de Transporte Anterior
313
     * @var \DOMNode
314
     */
315
    private $docAnt = array();
316
    /**
317
     * Emissor do documento anterior
318
     * @var array
319
     */
320
    private $emiDocAnt = array();
321
    /**
322
     * Informações de identificação dos documentos de Transporte Anterior
323
     * @var array
324
     */
325
    private $idDocAnt = array();
326
    /**
327
     * Documentos de transporte anterior em papel
328
     * @var array
329
     */
330
    private $idDocAntPap = array();
331
    /**
332
     * Documentos de transporte anterior eletrônicos
333
     * @var array
334
     */
335
    private $idDocAntEle = array();
336
    /**
337
     * Informações de Seguro da Carga
338
     * @var array
339
     */
340
    private $seg = array();
341
    /**
342
     * Informações do modal
343
     * @var \DOMNode
344
     */
345
    private $infModal = '';
346
    /**
347
     * Preenchido quando for transporte de produtos classificados pela ONU como perigosos.
348
     * @var array
349
     */
350
    private $peri = array();
351
    /**
352
     * informações dos veículos transportados
353
     * @var array
354
     */
355
    private $veicNovos = array();
356
    /**
357
     * Dados da cobrança do CT-e
358
     * @var \DOMNode
359
     */
360
    private $cobr = '';
361
    /**
362
     * Dados da fatura
363
     * @var \DOMNode
364
     */
365
    private $fat = '';
366
    /**
367
     * Dados das duplicatas
368
     * @var array
369
     */
370
    private $dup = array();
371
    /**
372
     * Informações do CT-e de substituição
373
     * @var \DOMNode
374
     */
375
    private $infCteSub = '';
376
    /**
377
     * Informações do Serviço Vinculado a Multimodal
378
     * @var \DOMNode
379
     */
380
    private $infServVinc = '';
381
    /**
382
     * Informações do CT-e multimodal vinculado
383
     * @var \DOMNode
384
     */
385
    private $infCTeMultimodal = array();
386
    /**
387
     * Tomador é contribuinte do ICMS
388
     * @var \DOMNode
389
     */
390
    private $tomaICMS = '';
391
    /**
392
     * Informação da NFe emitida pelo Tomador
393
     * @var \DOMNode
394
     */
395
    private $refNFe = '';
396
    /**
397
     * Informação da NF ou CT emitido pelo Tomador
398
     * @var \DOMNode
399
     */
400
    private $refNF = '';
401
    /**
402
     * Informação da NF ou CT emitido pelo Tomador
403
     * @var \DOMNode
404
     */
405
    private $infCteComp = '';
406
    /**
407
     * Detalhamento do CT-e do tipo Anulação
408
     * @var \DOMNode
409
     */
410
    private $infCteAnu = '';
411
    /**
412
     * Informações do modal Rodoviário
413
     * @var \DOMNode
414
     */
415
    private $rodo = '';
416
    /**
417
     * Informações do modal Aéreo
418
     * @var \DOMNode
419
     */
420
    private $aereo = '';
421
    /**
422
     * Informações do modal Ferroviario
423
     * @var \DOMNode
424
     */
425
    private $ferrov = '';
426
427
    private $ferroEnv = '';
428
    /**
429
     * Informações do modal Aquaviario
430
     * @var \DOMNode
431
     */
432
    private $aquav = '';
433
    /**
434
     * Informações do modal Dutoviário
435
     * @var \DOMNode
436
     */
437
    private $duto = '';
438
    /**
439
     * Ordens de Coleta associados
440
     * @var array
441
     */
442
    private $occ = array();
443
    /**
444
     * @var \DOMNode
445
     */
446
    private $emiOcc = array();
447
    /**
448
     * Informações de Vale Pedágio
449
     * @var array
450
     */
451
    private $valePed = array();
452
    /**
453
     * Dados dos Veículos
454
     * @var array
455
     */
456
    private $veic = array();
457
    /**
458
     * Proprietários do Veículo. Só preenchido quando o veículo não pertencer à empresa emitente do CT-e
459
     * @var array
460
     */
461
    private $prop = array();
462
    /**
463
     * Autorizados para download do XML do DF-e
464
     * @var array
465
     */
466
    private $autXML = array();
467
    /**
468
     * Dados do Fretamento - CTe-OS
469
     * @var
470
     */
471
    private $infFretamento;
472
    /**
473
     * @var DOMElement
474
     */
475
    protected $infRespTec;
476
    /**
477
     * @var boolean
478
     */
479
    protected $replaceAccentedChars = false;
480
481
    public function __construct()
482
    {
483
        $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...
484
        $this->dom->preserveWhiteSpace = false;
485
        $this->dom->formatOutput = false;
486
    }
487
488
    /**
489
     * Returns xml string and assembly it is necessary
490
     * @return string
491
     */
492
    public function getXML()
493
    {
494
        if (empty($this->xml)) {
495
            $this->montaCTe();
496
        }
497
        return $this->xml;
498
    }
499
500
    /**
501
     * Retorns the key number of NFe (44 digits)
502
     * @return string
503
     */
504
    public function getChave()
505
    {
506
        return $this->chCTe;
507
    }
508
509
    /**
510
     * Returns the model of CTe 57 or 67
511
     * @return int
512
     */
513
    public function getModelo()
514
    {
515
        return $this->mod;
516
    }
517
518
    /**
519
     * Set character convertion to ASCII only ou not
520
     * @param bool $option
521
     */
522
    public function setOnlyAscii($option = false)
523
    {
524
        $this->replaceAccentedChars = $option;
525
    }
526
527
    /**
528
     * Call method of xml assembly. For compatibility only.
529
     * @return boolean
530
     */
531
    public function montaCTe()
532
    {
533
        return $this->monta();
534
    }
535
536
    /**
537
     * Monta o arquivo XML usando as tag's já preenchidas
538
     *
539
     * @return bool
540
     */
541
    public function monta()
542
    {
543
        $this->errors = $this->dom->errors;
544
        if ($this->mod == 57) {
545
            $this->buildCTe();
546
        } else {
547
            return $this->montaCTeOS();
548
        }
549
        if ($this->toma3 != '') {
550
            $this->dom->appChild($this->ide, $this->toma3, 'Falta tag "ide"');
551
        } else {
552
            $this->dom->appChild($this->ide, $this->toma4, 'Falta tag "ide"');
553
        }
554
        $this->dom->appChild($this->infCte, $this->ide, 'Falta tag "infCte"');
555
        if ($this->compl != '') {
556
            foreach ($this->obsCont as $obsCont) {
557
                $this->dom->appChild($this->compl, $obsCont, 'Falta tag "compl"');
558
            }
559
            foreach ($this->obsFisco as $obsFisco) {
560
                $this->dom->appChild($this->compl, $obsFisco, 'Falta tag "compl"');
561
            }
562
            $this->dom->appChild($this->infCte, $this->compl, 'Falta tag "infCte"');
563
        }
564
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "emit"');
565
        $this->dom->appChild($this->infCte, $this->emit, 'Falta tag "infCte"');
566
        if ($this->rem != '') {
567
            $this->dom->appChild($this->infCte, $this->rem, 'Falta tag "infCte"');
568
        }
569
        if ($this->exped != '') {
570
            $this->dom->appChild($this->infCte, $this->exped, 'Falta tag "infCte"');
571
        }
572
        if ($this->receb != '') {
573
            $this->dom->appChild($this->infCte, $this->receb, 'Falta tag "infCte"');
574
        }
575
        if ($this->dest != '') {
576
            $this->dom->appChild($this->infCte, $this->dest, 'Falta tag "infCte"');
577
        }
578
        foreach ($this->comp as $comp) {
579
            $this->dom->appChild($this->vPrest, $comp, 'Falta tag "vPrest"');
580
        }
581
        $this->dom->appChild($this->infCte, $this->vPrest, 'Falta tag "infCte"');
582
        $this->dom->appChild($this->infCte, $this->imp, 'Falta tag "imp"');
583
        if ($this->infCteComp != '') { // Caso seja um CTe tipo complemento de valores
584
            $this->dom->appChild($this->infCte, $this->infCteComp, 'Falta tag "infCteComp"');
585
        }
586
        if ($this->infCteAnu != '') { // Caso seja um CTe tipo anulação
587
            $this->dom->appChild($this->infCte, $this->infCteAnu, 'Falta tag "infCteAnu"');
588
        }
589
        if ($this->infCTeNorm != '') { // Caso seja um CTe tipo normal
590
            $this->dom->appChild($this->infCte, $this->infCTeNorm, 'Falta tag "infCTeNorm"');
591
            $this->dom->appChild($this->infCTeNorm, $this->infCarga, 'Falta tag "infCarga"');
592
            foreach ($this->infQ as $infQ) {
0 ignored issues
show
Bug introduced by
The expression $this->infQ of type object<DOMNode> is not traversable.
Loading history...
593
                $this->dom->appChild($this->infCarga, $infQ, 'Falta tag "infQ"');
594
            }
595
            foreach ($this->infNF as $infNF) {
596
                $this->dom->appChild($this->infDoc, $infNF, 'Falta tag "infNF"');
597
            }
598
            foreach ($this->infNFe as $infNFe) {
599
                $this->dom->appChild($this->infDoc, $infNFe, 'Falta tag "infNFe"');
600
            }
601
            foreach ($this->infOutros as $infOutros) {
602
                $this->dom->appChild($this->infDoc, $infOutros, 'Falta tag "infOutros"');
603
            }
604
            if (!empty($this->infDoc)) {
605
                $this->dom->appChild($this->infCTeNorm, $this->infDoc, 'Falta tag "infCTeNorm"');
606
            }
607
            if ($this->idDocAntEle != [] || $this->idDocAntPap != []) { //Caso tenha CT-es Anteriores viculados
608
                $this->dom->appChild($this->infCTeNorm, $this->docAnt, 'Falta tag "docAnt"');
609
                foreach ($this->emiDocAnt as $indice => $emiDocAnt) {
610
                    $this->dom->appChild($this->docAnt, $emiDocAnt, 'Falta tag "emiDocAnt"');
611
                    $this->dom->appChild($emiDocAnt, $this->idDocAnt[$indice], 'Falta tag "idDocAnt"');
612
                    if (array_key_exists($indice, $this->idDocAntEle)) {
613
                        foreach ($this->idDocAntEle[$indice] as $idDocAntEle) {
614
                            $this->dom->appChild($this->idDocAnt[$indice], $idDocAntEle, 'Falta tag "emiDocAnt"');
615
                        }
616
                    }
617
                    if (array_key_exists($indice, $this->idDocAntPap)) {
618
                        foreach ($this->idDocAntPap[$indice] as $idDocAntPap) {
619
                            $this->dom->appChild($this->idDocAnt[$indice], $idDocAntPap, 'Falta tag "idDocAntEle"');
620
                        }
621
                    }
622
                }
623
            }
624
            foreach ($this->seg as $seg) {
625
                $this->dom->appChild($this->infCTeNorm, $seg, 'Falta tag "seg"');
626
            }
627
            $this->dom->appChild($this->infCTeNorm, $this->infModal, 'Falta tag "infModal"');
628
            if ($this->modal == '01') {
629
                if ($this->rodo) {
630
                    foreach ($this->occ as $occ) {
631
                        $this->dom->appChild($this->rodo, $occ, 'Falta tag "occ"');
632
                    }
633
                    $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "rodo"');
634
                }
635
            } elseif ($this->modal == '02') {
636
                foreach ($this->peri as $peri) {
637
                    $this->dom->appChild($this->aereo, $peri, 'Falta tag "aereo"');
638
                }
639
                $this->dom->appChild($this->infModal, $this->aereo, 'Falta tag "aereo"');
640
            } elseif ($this->modal == '04') {
641
                foreach ($this->ferroEnv as $ferroEnv) {
0 ignored issues
show
Bug introduced by
The expression $this->ferroEnv of type string is not traversable.
Loading history...
642
                    $this->ferrov->insertBefore($ferroEnv, $this->ferrov->getElementsByTagName('fluxo')->item(0));
643
                }
644
                $this->dom->appChild($this->infModal, $this->ferrov, 'Falta tag "ferrov"');
645
            } elseif ($this->modal == '03') {
646
                $this->dom->appChild($this->infModal, $this->aquav, 'Falta tag "aquav"');
647
            } elseif ($this->modal == '05') {
648
                $this->dom->appChild($this->infModal, $this->duto, 'Falta tag "duto"');
649
            } else {
650
                throw new Exception('Modal não informado ou não suportado.');
651
            }
652
            foreach ($this->veicNovos as $veicNovos) {
653
                $this->dom->appChild($this->infCTeNorm, $veicNovos, 'Falta tag "infCte"');
654
            }
655
            if ($this->infCteSub != '') {
656
                $this->dom->appChild($this->infCTeNorm, $this->infCteSub, 'Falta tag "infCteSub"');
657
658
                if ($this->tomaICMS != '') {
659
                    $this->dom->appChild($this->infCteSub, $this->tomaICMS, 'Falta tag "infCteSub"');
660
                }
661
            }
662
            if ($this->infServVinc != '') {
663
                $this->dom->appChild($this->infCTeNorm, $this->infServVinc, 'Falta tag "infServVinc"');
664
665
                foreach ($this->infCTeMultimodal as $infCTeMultimodal) {
0 ignored issues
show
Bug introduced by
The expression $this->infCTeMultimodal of type object<DOMNode> is not traversable.
Loading history...
666
                    $this->dom->appChild($this->infServVinc, $infCTeMultimodal, 'Falta tag "infCTeMultimodal"');
667
                }
668
            }
669
        }
670
        if ($this->cobr != '') {
671
            $this->dom->appChild($this->infCTeNorm, $this->cobr, 'Falta tag "infCte"');
672
        }
673
        foreach ($this->autXML as $autXML) {
674
            $this->dom->appChild($this->infCte, $autXML, 'Falta tag "infCte"');
675
        }
676
        $this->dom->appChild($this->infCte, $this->infRespTec, 'Falta tag "infCte"');
677
        //[1] tag infCTe
678
        $this->dom->appChild($this->CTe, $this->infCte, 'Falta tag "CTe"');
679
        //[0] tag CTe
680
        $this->dom->appendChild($this->CTe);
681
        // testa da chave
682
        $this->checkCTeKey($this->dom);
683
        $this->xml = $this->dom->saveXML();
684
        if (count($this->errors) > 0) {
685
            throw new RuntimeException('Existem erros nas tags. Obtenha os erros com getErrors().');
686
        }
687
        return true;
688
    }
689
690
    /**
691
     * Gera as tags para o elemento: "occ" (ordem de coletas)
692
     * #3
693
     * Nível:1
694
     * Os parâmetros para esta função são todos os elementos da tag "occ" do
695
     * tipo elemento (Ele = E|CE|A) e nível 1
696
     *
697
     * @return \DOMElement
698
     */
699
700
    public function tagocc($std)
701
    {
702
703
        $possible = [
704
            'serie',
705
            'nOcc',
706
            'dEmi',
707
            'CNPJ',
708
            'cInt',
709
            'IE',
710
            'UF',
711
            'fone'
712
        ];
713
714
        $std = $this->equilizeParameters($std, $possible);
715
716
        $identificador = '#3 <occ> - ';
717
        $occ = $this->dom->createElement('occ');
718
        $this->dom->addChild(
719
            $occ,
720
            'serie',
721
            $std->serie,
722
            false,
723
            $identificador . 'Série da OCC'
724
        );
725
        $this->dom->addChild(
726
            $occ,
727
            'nOcc',
728
            $std->nOcc,
729
            true,
730
            $identificador . 'Número da Ordem de coleta'
731
        );
732
        $this->dom->addChild(
733
            $occ,
734
            'dEmi',
735
            $std->dEmi,
736
            true,
737
            $identificador . 'Data de emissão da ordem de coleta'
738
        );
739
        //emitente
740
        $identificador = '#7 <emiOcc> - ';
741
        $emiOcc = $this->dom->createElement('emiOcc');
742
        $this->dom->addChild(
743
            $emiOcc,
744
            'CNPJ',
745
            $std->CNPJ,
746
            true,
747
            $identificador . 'Número do CNPJ'
748
        );
749
        $this->dom->addChild(
750
            $emiOcc,
751
            'cInt',
752
            $std->cInt,
753
            false,
754
            $identificador . 'Código interno de uso da transportadora'
755
        );
756
        $this->dom->addChild(
757
            $emiOcc,
758
            'IE',
759
            $std->IE,
760
            true,
761
            $identificador . 'Inscrição Estadual'
762
        );
763
        $this->dom->addChild(
764
            $emiOcc,
765
            'UF',
766
            $std->UF,
767
            true,
768
            $identificador . 'Sigla da UF'
769
        );
770
        $this->dom->addChild(
771
            $emiOcc,
772
            'fone',
773
            $std->fone,
774
            false,
775
            $identificador . 'Telefone'
776
        );
777
        $this->dom->appChild($occ, $emiOcc, 'Falta tag "emiOcc"');
778
        $this->occ[] = $occ;
779
        return $occ;
780
    }
781
782
783
    /**
784
     * Monta o arquivo XML usando as tag's já preenchidas
785
     *
786
     * @return bool
787
     */
788
    public function montaCTeOS()
789
    {
790
        $this->errors = $this->dom->errors;
791
        if (count($this->errors) > 0) {
792
            return false;
793
        }
794
        $this->buildCTeOS();
795
        if ($this->infPercurso != '') {
796
            foreach ($this->infPercurso as $perc) {
0 ignored issues
show
Bug introduced by
The expression $this->infPercurso of type object<DOMNode> is not traversable.
Loading history...
797
                $this->dom->appChild($this->ide, $perc, 'Falta tag "infPercurso"');
798
            }
799
        }
800
        $this->dom->appChild($this->infCte, $this->ide, 'Falta tag "infCte"');
801
        if ($this->compl != '') {
802
            $this->dom->appChild($this->infCte, $this->compl, 'Falta tag "infCte"');
803
        }
804
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "emit"');
805
        $this->dom->appChild($this->infCte, $this->emit, 'Falta tag "infCte"');
806
        if ($this->toma != '') {
807
            $this->dom->appChild($this->infCte, $this->toma, 'Falta tag "infCte"');
808
        }
809
        foreach ($this->comp as $comp) {
810
            $this->dom->appChild($this->vPrest, $comp, 'Falta tag "vPrest"');
811
        }
812
        $this->dom->appChild($this->infCte, $this->vPrest, 'Falta tag "infCte"');
813
        $this->dom->appChild($this->infCte, $this->imp, 'Falta tag "imp"');
814
        if ($this->infCteComp != '') { // Caso seja um CTe tipo complemento de valores
815
            $this->dom->appChild($this->infCte, $this->infCteComp, 'Falta tag "infCteComp"');
816
        } elseif ($this->infCteAnu != '') { // Caso seja um CTe tipo anulação
817
            $this->dom->appChild($this->infCte, $this->infCteAnu, 'Falta tag "infCteAnu"');
818
        } elseif ($this->infCTeNorm != '') { // Caso seja um CTe tipo normal
819
            $this->dom->appChild($this->infCte, $this->infCTeNorm, 'Falta tag "infCTeNorm"');
820
            $this->dom->appChild($this->infCTeNorm, $this->infServico, 'Falta tag "infServico"');
821
            foreach ($this->infDocRef as $infDocRef) {
822
                $this->dom->appChild($this->infCTeNorm, $infDocRef, 'Falta tag "infDocRef"');
823
            }
824
            foreach ($this->seg as $seg) {
825
                $this->dom->appChild($this->infCTeNorm, $seg, 'Falta tag "seg"');
826
            }
827
            if ($this->infModal != '') {
828
                $this->dom->appChild($this->infCTeNorm, $this->infModal, 'Falta tag "infModal"');
829
                if (!empty($this->veic)) {
830
                    $this->dom->appChild($this->rodo, $this->veic, 'Falta tag "veic"');
831
                }
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
877
        $possible = [
878
            'cUF',
879
            'cCT',
880
            'CFOP',
881
            'natOp',
882
            'mod',
883
            'serie',
884
            'nCT',
885
            'dhEmi',
886
            'tpImp',
887
            'tpEmis',
888
            'cDV',
889
            'tpEmis',
890
            'tpAmb',
891
            'tpCTe',
892
            'procEmi',
893
            'verProc',
894
            'indGlobalizado',
895
            'cMunEnv',
896
            'xMunEnv',
897
            'UFEnv',
898
            'modal',
899
            'tpServ',
900
            'indIEToma',
901
            'cMunIni',
902
            'xMunIni',
903
            'UFIni',
904
            'cMunFim',
905
            'xMunFim',
906
            'UFFim',
907
            'retira',
908
            'xDetRetira',
909
            'indIEToma',
910
            'dhCont',
911
            'xJust'
912
        ];
913
914
        $std = $this->equilizeParameters($std, $possible);
915
916
        $this->tpAmb = $std->tpAmb;
917
        $this->mod = $std->mod;
918
        $identificador = '#4 <ide> - ';
919
        $this->ide = $this->dom->createElement('ide');
920
        $this->dom->addChild(
921
            $this->ide,
922
            'cUF',
923
            $std->cUF,
924
            true,
925
            $identificador . 'Código da UF do emitente do CT-e'
926
        );
927
        $this->dom->addChild(
928
            $this->ide,
929
            'cCT',
930
            str_pad($std->cCT, 8, '0', STR_PAD_LEFT),
931
            true,
932
            $identificador . 'Código numérico que compõe a Chave de Acesso'
933
        );
934
        $this->dom->addChild(
935
            $this->ide,
936
            'CFOP',
937
            $std->CFOP,
938
            true,
939
            $identificador . 'Código Fiscal de Operações e Prestações'
940
        );
941
        $this->dom->addChild(
942
            $this->ide,
943
            'natOp',
944
            Strings::replaceSpecialsChars(substr(trim($std->natOp), 0, 60)),
945
            true,
946
            $identificador . 'Natureza da Operação'
947
        );
948
        $this->dom->addChild(
949
            $this->ide,
950
            'mod',
951
            $std->mod,
952
            true,
953
            $identificador . 'Modelo do documento fiscal'
954
        );
955
        $this->dom->addChild(
956
            $this->ide,
957
            'serie',
958
            $std->serie,
959
            true,
960
            $identificador . 'Série do CT-e'
961
        );
962
        $this->dom->addChild(
963
            $this->ide,
964
            'nCT',
965
            $std->nCT,
966
            true,
967
            $identificador . 'Número do CT-e'
968
        );
969
        $this->dom->addChild(
970
            $this->ide,
971
            'dhEmi',
972
            $std->dhEmi,
973
            true,
974
            $identificador . 'Data e hora de emissão do CT-e'
975
        );
976
        $this->dom->addChild(
977
            $this->ide,
978
            'tpImp',
979
            $std->tpImp,
980
            true,
981
            $identificador . 'Formato de impressão do DACTE'
982
        );
983
        $this->dom->addChild(
984
            $this->ide,
985
            'tpEmis',
986
            $std->tpEmis,
987
            true,
988
            $identificador . 'Forma de emissão do CT-e'
989
        );
990
        $this->dom->addChild(
991
            $this->ide,
992
            'cDV',
993
            $std->cDV,
994
            false,
995
            $identificador . 'Digito Verificador da chave de acesso do CT-e'
996
        );
997
        $this->dom->addChild(
998
            $this->ide,
999
            'tpAmb',
1000
            $std->tpAmb,
1001
            true,
1002
            $identificador . 'Tipo do Ambiente'
1003
        );
1004
        $this->dom->addChild(
1005
            $this->ide,
1006
            'tpCTe',
1007
            $std->tpCTe,
1008
            true,
1009
            $identificador . 'Tipo do CT-e'
1010
        );
1011
        $this->dom->addChild(
1012
            $this->ide,
1013
            'procEmi',
1014
            $std->procEmi,
1015
            true,
1016
            $identificador . 'Identificador do processo de emissão do CT-e'
1017
        );
1018
        $this->dom->addChild(
1019
            $this->ide,
1020
            'verProc',
1021
            $std->verProc,
1022
            true,
1023
            $identificador . 'Versão do processo de emissão'
1024
        );
1025
        if ($this->mod == 57) {
1026
            $this->dom->addChild(
1027
                $this->ide,
1028
                'indGlobalizado',
1029
                $std->indGlobalizado,
1030
                false,
1031
                $identificador . 'Indicador de CT-e Globalizado'
1032
            );
1033
        }
1034
        $this->dom->addChild(
1035
            $this->ide,
1036
            'cMunEnv',
1037
            $std->cMunEnv,
1038
            true,
1039
            $identificador . 'Código do Município de envio do CT-e (de onde o documento foi transmitido)'
1040
        );
1041
        $this->dom->addChild(
1042
            $this->ide,
1043
            'xMunEnv',
1044
            $std->xMunEnv,
1045
            true,
1046
            $identificador . 'Nome do Município de envio do CT-e (de onde o documento foi transmitido)'
1047
        );
1048
        $this->dom->addChild(
1049
            $this->ide,
1050
            'UFEnv',
1051
            $std->UFEnv,
1052
            true,
1053
            $identificador . 'Sigla da UF de envio do CT-e (de onde o documento foi transmitido)'
1054
        );
1055
        $this->dom->addChild(
1056
            $this->ide,
1057
            'modal',
1058
            $std->modal,
1059
            true,
1060
            $identificador . 'Modal'
1061
        );
1062
        $this->modal = $std->modal;
1063
        $this->dom->addChild(
1064
            $this->ide,
1065
            'tpServ',
1066
            $std->tpServ,
1067
            true,
1068
            $identificador . 'Tipo do Serviço'
1069
        );
1070
        if ($this->mod == 67) {
1071
            $this->dom->addChild(
1072
                $this->ide,
1073
                'indIEToma',
1074
                $std->indIEToma,
1075
                true,
1076
                $identificador . 'Indicador do papel do tomador na prestação do serviço'
1077
            );
1078
        }
1079
        $this->dom->addChild(
1080
            $this->ide,
1081
            'cMunIni',
1082
            $std->cMunIni,
1083
            true,
1084
            $identificador . 'Nome do Município do início da prestação'
1085
        );
1086
        $this->dom->addChild(
1087
            $this->ide,
1088
            'xMunIni',
1089
            $std->xMunIni,
1090
            true,
1091
            $identificador . 'Nome do Município do início da prestação'
1092
        );
1093
        $this->dom->addChild(
1094
            $this->ide,
1095
            'UFIni',
1096
            $std->UFIni,
1097
            true,
1098
            $identificador . 'UF do início da prestação'
1099
        );
1100
        $this->dom->addChild(
1101
            $this->ide,
1102
            'cMunFim',
1103
            $std->cMunFim,
1104
            true,
1105
            $identificador . 'Código do Município de término da prestação'
1106
        );
1107
        $this->dom->addChild(
1108
            $this->ide,
1109
            'xMunFim',
1110
            $std->xMunFim,
1111
            true,
1112
            $identificador . 'Nome do Município do término da prestação'
1113
        );
1114
        $this->dom->addChild(
1115
            $this->ide,
1116
            'UFFim',
1117
            $std->UFFim,
1118
            true,
1119
            $identificador . 'UF do término da prestação'
1120
        );
1121
        if ($this->mod == 57) {
1122
            $this->dom->addChild(
1123
                $this->ide,
1124
                'retira',
1125
                $std->retira,
1126
                true,
1127
                $identificador . 'Indicador se o Recebedor retira no Aeroporto, Filial, Porto ou Estação de Destino'
1128
            );
1129
            $this->dom->addChild(
1130
                $this->ide,
1131
                'xDetRetira',
1132
                $std->xDetRetira,
1133
                false,
1134
                $identificador . 'Detalhes do retira'
1135
            );
1136
            $this->dom->addChild(
1137
                $this->ide,
1138
                'indIEToma',
1139
                $std->indIEToma,
1140
                true,
1141
                $identificador . 'Indicador do papel do tomador na prestação do serviço'
1142
            );
1143
        }
1144
        $this->dom->addChild(
1145
            $this->ide,
1146
            'dhCont',
1147
            $std->dhCont,
1148
            false,
1149
            $identificador . 'Data e Hora da entrada em contingência'
1150
        );
1151
        $this->dom->addChild(
1152
            $this->ide,
1153
            'xJust',
1154
            Strings::replaceSpecialsChars(substr(trim($std->xJust), 0, 256)),
1155
            false,
1156
            $identificador . 'Justificativa da entrada em contingência'
1157
        );
1158
        $this->tpServ = $std->tpServ;
1159
        return $this->ide;
1160
    }
1161
1162
    public function taginfPercurso($std)
1163
    {
1164
1165
        $possible = [
1166
            'UFPer'
1167
        ];
1168
1169
        $std = $this->equilizeParameters($std, $possible);
1170
1171
        $identificador = '#4 <infPercurso> - ';
1172
        $this->infPercurso[] = $this->dom->createElement('infPercurso');
1173
        $posicao = (int)count($this->infPercurso) - 1;
1174
        $this->dom->addChild(
1175
            $this->infPercurso[$posicao],
1176
            'UFPer',
1177
            $std->UFPer,
1178
            true,
1179
            $identificador . 'Código da UF do percurso'
1180
        );
1181
1182
        return $this->infPercurso[$posicao];
1183
    }
1184
1185
    /**
1186
     * Gera as tags para o elemento: toma3 (Indicador do "papel" do tomador do serviço no CT-e)
1187
     * e adiciona ao grupo ide
1188
     * #35
1189
     * Nível: 2
1190
     * @param string $toma Tomador do Serviço
0 ignored issues
show
Bug introduced by
There is no parameter named $toma. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1191
     * @param stdClass $std
1192
     * @return \DOMElement
1193
     */
1194
    public function tagtoma3($std)
1195
    {
1196
1197
        $possible = [
1198
            'toma'
1199
        ];
1200
1201
        $std = $this->equilizeParameters($std, $possible);
1202
1203
        $identificador = '#35 <toma3> - ';
1204
        $this->toma3 = $this->dom->createElement('toma3');
1205
        $this->dom->addChild(
1206
            $this->toma3,
1207
            'toma',
1208
            $std->toma,
1209
            true,
1210
            $identificador . 'Tomador do Serviço'
1211
        );
1212
        return $this->toma3;
1213
    }
1214
1215
    /**
1216
     * Gera as tags para o elemento: toma4 (Indicador do "papel" do tomador
1217
     * do serviço no CT-e) e adiciona ao grupo ide
1218
     * #37
1219
     * Nível: 2
1220
     * @param stdClass $std
1221
     * @return \DOMElement
1222
     */
1223
    public function tagtoma4($std)
1224
    {
1225
1226
        $possible = [
1227
            'toma',
1228
            'CNPJ',
1229
            'CPF',
1230
            'IE',
1231
            'xNome',
1232
            'xFant',
1233
            'fone',
1234
            'email'
1235
        ];
1236
1237
        $std = $this->equilizeParameters($std, $possible);
1238
1239
        $identificador = '#37 <toma4> - ';
1240
        $this->toma4 = $this->dom->createElement('toma4');
1241
        $this->dom->addChild(
1242
            $this->toma4,
1243
            'toma',
1244
            $std->toma,
1245
            true,
1246
            $identificador . 'Tomador do Serviço'
1247
        );
1248
        if ($std->CNPJ != '') {
1249
            $this->dom->addChild(
1250
                $this->toma4,
1251
                'CNPJ',
1252
                $std->CNPJ,
1253
                true,
1254
                $identificador . 'Número do CNPJ'
1255
            );
1256
        } elseif ($std->CPF != '') {
1257
            $this->dom->addChild(
1258
                $this->toma4,
1259
                'CPF',
1260
                $std->CPF,
1261
                true,
1262
                $identificador . 'Número do CPF'
1263
            );
1264
        } else {
1265
            $this->dom->addChild(
1266
                $this->toma4,
1267
                'CNPJ',
1268
                $std->CNPJ,
1269
                true,
1270
                $identificador . 'Número do CNPJ'
1271
            );
1272
            $this->dom->addChild(
1273
                $this->toma4,
1274
                'CPF',
1275
                $std->CPF,
1276
                true,
1277
                $identificador . 'Número do CPF'
1278
            );
1279
        }
1280
        $this->dom->addChild(
1281
            $this->toma4,
1282
            'IE',
1283
            $std->IE,
1284
            false,
1285
            $identificador . 'Inscrição Estadual'
1286
        );
1287
        $this->dom->addChild(
1288
            $this->toma4,
1289
            'xNome',
1290
            $std->xNome,
1291
            true,
1292
            $identificador . 'Razão Social ou Nome'
1293
        );
1294
        $this->dom->addChild(
1295
            $this->toma4,
1296
            'xFant',
1297
            $std->xFant,
1298
            false,
1299
            $identificador . 'Nome Fantasia'
1300
        );
1301
        $this->dom->addChild(
1302
            $this->toma4,
1303
            'fone',
1304
            $std->fone,
1305
            false,
1306
            $identificador . 'Telefone'
1307
        );
1308
        $this->dom->addChild(
1309
            $this->toma4,
1310
            'email',
1311
            $std->email,
1312
            false,
1313
            $identificador . 'Endereço de email'
1314
        );
1315
        return $this->toma4;
1316
    }
1317
1318
    /**
1319
     * Gera as tags para o elemento: toma4 (Indicador do "papel" do tomador
1320
     * do serviço no CT-e OS) e adiciona ao grupo ide
1321
     * #37
1322
     * Nível: 2
1323
     *
1324
     * @return \DOMElement
1325
     */
1326
    public function tagtomador($std)
1327
    {
1328
1329
        $possible = [
1330
            'CNPJ',
1331
            'CPF',
1332
            'IE',
1333
            'xNome',
1334
            'xFant',
1335
            'fone',
1336
            'xLgr',
1337
            'nro',
1338
            'xCpl',
1339
            'xBairro',
1340
            'cMun',
1341
            'xMun',
1342
            'CEP',
1343
            'UF',
1344
            'cPais',
1345
            'xPais',
1346
            'email'
1347
        ];
1348
1349
        $std = $this->equilizeParameters($std, $possible);
1350
1351
        $identificador = '#37 <toma> - ';
1352
        $this->toma = $this->dom->createElement('toma');
1353
        if ($std->CNPJ != '') {
1354
            $this->dom->addChild(
1355
                $this->toma,
1356
                'CNPJ',
1357
                $std->CNPJ,
1358
                true,
1359
                $identificador . 'Número do CNPJ'
1360
            );
1361
        } elseif ($std->CPF != '') {
1362
            $this->dom->addChild(
1363
                $this->toma,
1364
                'CPF',
1365
                $std->CPF,
1366
                true,
1367
                $identificador . 'Número do CPF'
1368
            );
1369
        } else {
1370
            $this->dom->addChild(
1371
                $this->toma,
1372
                'CNPJ',
1373
                $std->CNPJ,
1374
                true,
1375
                $identificador . 'Número do CNPJ'
1376
            );
1377
            $this->dom->addChild(
1378
                $this->toma,
1379
                'CPF',
1380
                $std->CPF,
1381
                true,
1382
                $identificador . 'Número do CPF'
1383
            );
1384
        }
1385
        $this->dom->addChild(
1386
            $this->toma,
1387
            'IE',
1388
            $std->IE,
1389
            false,
1390
            $identificador . 'Inscrição Estadual'
1391
        );
1392
        $this->dom->addChild(
1393
            $this->toma,
1394
            'xNome',
1395
            $std->xNome,
1396
            true,
1397
            $identificador . 'Razão Social ou Nome'
1398
        );
1399
        $this->dom->addChild(
1400
            $this->toma,
1401
            'xFant',
1402
            $std->xFant,
1403
            false,
1404
            $identificador . 'Nome Fantasia'
1405
        );
1406
        $this->dom->addChild(
1407
            $this->toma,
1408
            'fone',
1409
            $std->fone,
1410
            false,
1411
            $identificador . 'Telefone'
1412
        );
1413
        //Endereço Tomador
1414
        $this->enderToma = $this->dom->createElement('enderToma');
1415
        $this->dom->addChild(
1416
            $this->enderToma,
1417
            'xLgr',
1418
            $std->xLgr,
1419
            true,
1420
            $identificador . 'Logradouro'
1421
        );
1422
        $this->dom->addChild(
1423
            $this->enderToma,
1424
            'nro',
1425
            $std->nro,
1426
            true,
1427
            $identificador . 'Número'
1428
        );
1429
        $this->dom->addChild(
1430
            $this->enderToma,
1431
            'xCpl',
1432
            $std->xCpl,
1433
            false,
1434
            $identificador . 'Complemento'
1435
        );
1436
        $this->dom->addChild(
1437
            $this->enderToma,
1438
            'xBairro',
1439
            $std->xBairro,
1440
            true,
1441
            $identificador . 'Bairro'
1442
        );
1443
        $this->dom->addChild(
1444
            $this->enderToma,
1445
            'cMun',
1446
            $std->cMun,
1447
            true,
1448
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
1449
        );
1450
        $this->dom->addChild(
1451
            $this->enderToma,
1452
            'xMun',
1453
            $std->xMun,
1454
            true,
1455
            $identificador . 'Nome do município'
1456
        );
1457
        $this->dom->addChild(
1458
            $this->enderToma,
1459
            'CEP',
1460
            $std->CEP,
1461
            false,
1462
            $identificador . 'CEP'
1463
        );
1464
        $this->dom->addChild(
1465
            $this->enderToma,
1466
            'UF',
1467
            $std->UF,
1468
            true,
1469
            $identificador . 'Sigla da UF'
1470
        );
1471
        $this->dom->addChild(
1472
            $this->enderToma,
1473
            'cPais',
1474
            $std->cPais,
1475
            false,
1476
            $identificador . 'Código do país'
1477
        );
1478
        $this->dom->addChild(
1479
            $this->enderToma,
1480
            'xPais',
1481
            $std->xPais,
1482
            false,
1483
            $identificador . 'Nome do país'
1484
        );
1485
        $this->dom->appChild($this->toma, $this->enderToma, 'Falta tag "enderToma"');
1486
        $this->dom->addChild(
1487
            $this->toma,
1488
            'email',
1489
            $std->email,
1490
            false,
1491
            $identificador . 'Endereço de email'
1492
        );
1493
        return $this->toma;
1494
    }
1495
1496
    /**
1497
     * Gera as tags para o elemento: "enderToma" (Dados do endereço) e adiciona ao grupo "toma4"
1498
     * #45
1499
     * Nível: 3
1500
     *
1501
     * @return \DOMElement
1502
     */
1503
    public function tagenderToma($std)
1504
    {
1505
1506
        $possible = [
1507
            'xLgr',
1508
            'nro',
1509
            'xCpl',
1510
            'xBairro',
1511
            'cMun',
1512
            'xMun',
1513
            'CEP',
1514
            'UF',
1515
            'cPais',
1516
            'xPais'
1517
        ];
1518
1519
        $std = $this->equilizeParameters($std, $possible);
1520
1521
        $identificador = '#45 <enderToma> - ';
1522
        $this->enderToma = $this->dom->createElement('enderToma');
1523
        $this->dom->addChild(
1524
            $this->enderToma,
1525
            'xLgr',
1526
            $std->xLgr,
1527
            true,
1528
            $identificador . 'Logradouro'
1529
        );
1530
        $this->dom->addChild(
1531
            $this->enderToma,
1532
            'nro',
1533
            $std->nro,
1534
            true,
1535
            $identificador . 'Número'
1536
        );
1537
        $this->dom->addChild(
1538
            $this->enderToma,
1539
            'xCpl',
1540
            $std->xCpl,
1541
            false,
1542
            $identificador . 'Complemento'
1543
        );
1544
        $this->dom->addChild(
1545
            $this->enderToma,
1546
            'xBairro',
1547
            $std->xBairro,
1548
            true,
1549
            $identificador . 'Bairro'
1550
        );
1551
        $this->dom->addChild(
1552
            $this->enderToma,
1553
            'cMun',
1554
            $std->cMun,
1555
            true,
1556
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
1557
        );
1558
        $this->dom->addChild(
1559
            $this->enderToma,
1560
            'xMun',
1561
            $std->xMun,
1562
            true,
1563
            $identificador . 'Nome do município'
1564
        );
1565
        $this->dom->addChild(
1566
            $this->enderToma,
1567
            'CEP',
1568
            $std->CEP,
1569
            false,
1570
            $identificador . 'CEP'
1571
        );
1572
        $this->dom->addChild(
1573
            $this->enderToma,
1574
            'UF',
1575
            $std->UF,
1576
            true,
1577
            $identificador . 'Sigla da UF'
1578
        );
1579
        $this->dom->addChild(
1580
            $this->enderToma,
1581
            'cPais',
1582
            $std->cPais,
1583
            false,
1584
            $identificador . 'Código do país'
1585
        );
1586
        $this->dom->addChild(
1587
            $this->enderToma,
1588
            'xPais',
1589
            $std->xPais,
1590
            false,
1591
            $identificador . 'Nome do país'
1592
        );
1593
1594
        if (!empty($this->toma4)) {
1595
            $this->toma4->insertBefore($this->enderToma, $this->toma4->getElementsByTagName("email")->item(0));
1596
        }
1597
        return $this->enderToma;
1598
    }
1599
1600
    /**
1601
     * Gera as tags para o elemento: "compl" (Dados complementares do CT-e para fins operacionais ou comerciais)
1602
     * #59
1603
     * Nível: 1
1604
     *
1605
     * @return \DOMElement
1606
     */
1607
    public function tagcompl($std)
1608
    {
1609
1610
        $possible = [
1611
            'xCaracAd',
1612
            'xCaracSer',
1613
            'xEmi',
1614
            'origCalc',
1615
            'destCalc',
1616
            'xObs'
1617
        ];
1618
1619
        $std = $this->equilizeParameters($std, $possible);
1620
1621
        $identificador = '#59 <compl> - ';
1622
        if ($this->compl == '') {
1623
            $this->compl = $this->dom->createElement('compl');
1624
        }
1625
        $this->dom->addChild(
1626
            $this->compl,
1627
            'xCaracAd',
1628
            $std->xCaracAd,
1629
            false,
1630
            $identificador . 'Característica adicional do transporte'
1631
        );
1632
        $this->dom->addChild(
1633
            $this->compl,
1634
            'xCaracSer',
1635
            $std->xCaracSer,
1636
            false,
1637
            $identificador . 'Característica adicional do serviço'
1638
        );
1639
        $this->dom->addChild(
1640
            $this->compl,
1641
            'xEmi',
1642
            $std->xEmi,
1643
            false,
1644
            $identificador . 'Funcionário emissor do CTe'
1645
        );
1646
        if ($this->fluxo != '') {
1647
            foreach ($this->pass as $pass) {
1648
                $this->dom->appChild($this->fluxo, $pass, 'Falta tag "fluxo"');
1649
            }
1650
            $this->dom->appChild($this->compl, $this->fluxo, 'Falta tag "infCte"');
1651
        }
1652
        if ($this->semData != '') {
1653
            $this->tagEntrega();
1654
            $this->dom->appChild($this->entrega, $this->semData, 'Falta tag "Entrega"');
1655
        }
1656
        if ($this->comData != '') {
1657
            $this->tagEntrega();
1658
            $this->dom->appChild($this->entrega, $this->comData, 'Falta tag "Entrega"');
1659
        }
1660
        if ($this->noPeriodo != '') {
1661
            $this->tagEntrega();
1662
            $this->dom->appChild($this->entrega, $this->noPeriodo, 'Falta tag "Entrega"');
1663
        }
1664
        if ($this->semHora != '') {
1665
            $this->tagEntrega();
1666
            $this->dom->appChild($this->entrega, $this->semHora, 'Falta tag "Entrega"');
1667
        }
1668
        if ($this->comHora != '') {
1669
            $this->tagEntrega();
1670
            $this->dom->appChild($this->entrega, $this->comHora, 'Falta tag "Entrega"');
1671
        }
1672
        if ($this->noInter != '') {
1673
            $this->tagEntrega();
1674
            $this->dom->appChild($this->entrega, $this->noInter, 'Falta tag "Entrega"');
1675
        }
1676
        if ($this->mod == 57) {
1677
            $this->dom->addChild(
1678
                $this->compl,
1679
                'origCalc',
1680
                $std->origCalc,
1681
                false,
1682
                $identificador . 'Município de origem para efeito de cálculo do frete'
1683
            );
1684
            $this->dom->addChild(
1685
                $this->compl,
1686
                'destCalc',
1687
                $std->destCalc,
1688
                false,
1689
                $identificador . 'Município de destino para efeito de cálculo do frete'
1690
            );
1691
        }
1692
        $this->dom->addChild(
1693
            $this->compl,
1694
            'xObs',
1695
            $std->xObs,
1696
            false,
1697
            $identificador . 'Observações Gerais'
1698
        );
1699
        return $this->compl;
1700
    }
1701
1702
    /**
1703
     * Gera as tags para o elemento: "compl" (Dados complementares do CT-e OS para fins operacionais ou comerciais)
1704
     * #59
1705
     * Nível: 1
1706
     *
1707
     * @return \DOMElement
1708
     */
1709
    public function tagcomplCTeOs($std)
1710
    {
1711
1712
        $possible = [
1713
            'xCaracAd',
1714
            'xCaracSer',
1715
            'xEmi',
1716
            'xObs'
1717
        ];
1718
1719
        $std = $this->equilizeParameters($std, $possible);
1720
1721
        $identificador = '#59 <compl> - ';
1722
        $this->compl = $this->dom->createElement('compl');
1723
        $this->dom->addChild(
1724
            $this->compl,
1725
            'xCaracAd',
1726
            $std->xCaracAd,
1727
            false,
1728
            $identificador . 'Característica adicional do transporte'
1729
        );
1730
        $this->dom->addChild(
1731
            $this->compl,
1732
            'xCaracSer',
1733
            $std->xCaracSer,
1734
            false,
1735
            $identificador . 'Característica adicional do serviço'
1736
        );
1737
        $this->dom->addChild(
1738
            $this->compl,
1739
            'xEmi',
1740
            $std->xEmi,
1741
            false,
1742
            $identificador . 'Funcionário emissor do CTe'
1743
        );
1744
        $this->dom->addChild(
1745
            $this->compl,
1746
            'xObs',
1747
            $std->xObs,
1748
            false,
1749
            $identificador . 'Observações Gerais'
1750
        );
1751
        return $this->compl;
1752
    }
1753
1754
    /**
1755
     * Gera as tags para o elemento: "fluxo" (Previsão do fluxo da carga)
1756
     * #63
1757
     * Nível: 2
1758
     * Os parâmetros para esta função são todos os elementos da tag "fluxo" do
1759
     * tipo elemento (Ele = E|CE|A) e nível 3
1760
     *
1761
     * @return \DOMElement
1762
     */
1763
    public function tagfluxo($std)
1764
    {
1765
1766
        $possible = [
1767
            'xOrig',
1768
            'xDest',
1769
            'xRota'
1770
        ];
1771
1772
        $std = $this->equilizeParameters($std, $possible);
1773
1774
        $identificador = '#63 <fluxo> - ';
1775
        $this->fluxo = $this->dom->createElement('fluxo');
1776
        $this->dom->addChild(
1777
            $this->fluxo,
1778
            'xOrig',
1779
            $std->xOrig,
1780
            false,
1781
            $identificador . 'Sigla ou código interno da Filial/Porto/Estação/ Aeroporto de Origem'
1782
        );
1783
        $this->dom->addChild(
1784
            $this->fluxo,
1785
            'xDest',
1786
            $std->xDest,
1787
            false,
1788
            $identificador . 'Sigla ou código interno da Filial/Porto/Estação/Aeroporto de Destino'
1789
        );
1790
        $this->dom->addChild(
1791
            $this->fluxo,
1792
            'xRota',
1793
            $std->xRota,
1794
            false,
1795
            $identificador . 'Código da Rota de Entrega'
1796
        );
1797
        return $this->fluxo;
1798
    }
1799
1800
    /**
1801
     * Gera as tags para o elemento: "pass"
1802
     * #65
1803
     * Nível: 3
1804
     *
1805
     * @return \DOMElement
1806
     */
1807
    public function tagpass($std)
1808
    {
1809
1810
        $possible = [
1811
            'xPass'
1812
        ];
1813
1814
        $std = $this->equilizeParameters($std, $possible);
1815
1816
        $identificador = '#65 <pass> - ';
1817
        $this->pass[] = $this->dom->createElement('pass');
1818
        $posicao = (int)count($this->pass) - 1;
1819
        $this->dom->addChild(
1820
            $this->pass[$posicao],
1821
            'xPass',
1822
            $std->xPass,
1823
            false,
1824
            $identificador . 'Sigla ou código interno da Filial/Porto/Estação/Aeroporto de Passagem'
1825
        );
1826
        return $this->pass[$posicao];
1827
    }
1828
1829
    /**
1830
     * Gera as tags para o elemento: "semData" (Entrega sem data definida)
1831
     * #70
1832
     * Nível: 3
1833
     *
1834
     * @return \DOMElement
1835
     */
1836
    public function tagsemData($std)
1837
    {
1838
1839
        $possible = [
1840
            'tpPer'
1841
        ];
1842
1843
        $std = $this->equilizeParameters($std, $possible);
1844
1845
        $identificador = '#70 <semData> - ';
1846
        $this->semData = $this->dom->createElement('semData');
1847
        $this->dom->addChild(
1848
            $this->semData,
1849
            'tpPer',
1850
            $std->tpPer,
1851
            true,
1852
            $identificador . 'Tipo de data/período programado para entrega'
1853
        );
1854
        return $this->semData;
1855
    }
1856
1857
    /**
1858
     * Gera as tags para o elemento: "comData" (Entrega com data definida)
1859
     * #72
1860
     * Nível: 3
1861
     *
1862
     * @return \DOMElement
1863
     */
1864
    public function tagcomData($std)
1865
    {
1866
1867
        $possible = [
1868
            'tpPer',
1869
            'dProg'
1870
        ];
1871
1872
        $std = $this->equilizeParameters($std, $possible);
1873
1874
        $identificador = '#72 <comData> - ';
1875
        $this->comData = $this->dom->createElement('comData');
1876
        $this->dom->addChild(
1877
            $this->comData,
1878
            'tpPer',
1879
            $std->tpPer,
1880
            true,
1881
            $identificador . 'Tipo de data/período programado para entrega'
1882
        );
1883
        $this->dom->addChild(
1884
            $this->comData,
1885
            'dProg',
1886
            $std->dProg,
1887
            true,
1888
            $identificador . 'Data programada'
1889
        );
1890
        return $this->comData;
1891
    }
1892
1893
    /**
1894
     * Gera as tags para o elemento: "noPeriodo" (Entrega no período definido)
1895
     * #75
1896
     * Nível: 3
1897
     *
1898
     * @return \DOMElement
1899
     */
1900
    public function tagnoPeriodo($std)
1901
    {
1902
1903
        $possible = [
1904
            'tpPer',
1905
            'dIni',
1906
            'dFim'
1907
        ];
1908
1909
        $std = $this->equilizeParameters($std, $possible);
1910
1911
        $identificador = '#75 <noPeriodo> - ';
1912
        $this->noPeriodo = $this->dom->createElement('noPeriodo');
1913
        $this->dom->addChild(
1914
            $this->noPeriodo,
1915
            'tpPer',
1916
            $std->tpPer,
1917
            true,
1918
            $identificador . 'Tipo de data/período programado para entrega'
1919
        );
1920
        $this->dom->addChild(
1921
            $this->noPeriodo,
1922
            'dIni',
1923
            $std->dIni,
1924
            true,
1925
            $identificador . 'Data inicial'
1926
        );
1927
        $this->dom->addChild(
1928
            $this->noPeriodo,
1929
            'dFim',
1930
            $std->dFim,
1931
            true,
1932
            $identificador . 'Data final'
1933
        );
1934
        return $this->noPeriodo;
1935
    }
1936
1937
    /**
1938
     * Gera as tags para o elemento: "semHora" (Entrega sem hora definida)
1939
     * #79
1940
     * Nível: 3
1941
     * Os parâmetros para esta função são todos os elementos da tag "semHora" do
1942
     * tipo elemento (Ele = E|CE|A) e nível 4
1943
     *
1944
     * @return \DOMElement
1945
     */
1946
    public function tagsemHora($std)
1947
    {
1948
1949
        $possible = [
1950
            'tpHor'
1951
        ];
1952
1953
        $std = $this->equilizeParameters($std, $possible);
1954
1955
        $identificador = '#79 <semHora> - ';
1956
        $this->semHora = $this->dom->createElement('semHora');
1957
        $this->dom->addChild(
1958
            $this->semHora,
1959
            'tpHor',
1960
            $std->tpHor,
1961
            true,
1962
            $identificador . 'Tipo de hora'
1963
        );
1964
        return $this->semHora;
1965
    }
1966
1967
    /**
1968
     * Gera as tags para o elemento: "comHora" (Entrega sem hora definida)
1969
     * # = 81
1970
     * Nível = 3
1971
     * Os parâmetros para esta função são todos os elementos da tag "comHora" do
1972
     * tipo elemento (Ele = E|CE|A) e nível 4
1973
     *
1974
     * @return \DOMElement
1975
     */
1976
    public function tagcomHora($std)
1977
    {
1978
1979
        $possible = [
1980
            'tpHor',
1981
            'hProg'
1982
        ];
1983
1984
        $std = $this->equilizeParameters($std, $possible);
1985
1986
        $identificador = '#81 <comHora> - ';
1987
        $this->comHora = $this->dom->createElement('comHora');
1988
        $this->dom->addChild(
1989
            $this->comHora,
1990
            'tpHor',
1991
            $std->tpHor,
1992
            true,
1993
            $identificador . 'Tipo de hora'
1994
        );
1995
        $this->dom->addChild(
1996
            $this->comHora,
1997
            'hProg',
1998
            $std->hProg,
1999
            true,
2000
            $identificador . 'Hora programada'
2001
        );
2002
        return $this->comHora;
2003
    }
2004
2005
    /**
2006
     * Gera as tags para o elemento: "noInter" (Entrega no intervalo de horário definido)
2007
     * #84
2008
     * Nível: 3
2009
     * Os parâmetros para esta função são todos os elementos da tag "noInter" do
2010
     * tipo elemento (Ele = E|CE|A) e nível 4
2011
     *
2012
     * @return \DOMElement
2013
     */
2014
    public function tagnoInter($std)
2015
    {
2016
2017
        $possible = [
2018
            'tpHor',
2019
            'hIni',
2020
            'hFim'
2021
        ];
2022
2023
        $std = $this->equilizeParameters($std, $possible);
2024
2025
        $identificador = '#84 <noInter> - ';
2026
        $this->noInter = $this->dom->createElement('noInter');
2027
        $this->dom->addChild(
2028
            $this->noInter,
2029
            'tpHor',
2030
            $std->tpHor,
2031
            true,
2032
            $identificador . 'Tipo de hora'
2033
        );
2034
        $this->dom->addChild(
2035
            $this->noInter,
2036
            'hIni',
2037
            $std->hIni,
2038
            true,
2039
            $identificador . 'Hora inicial'
2040
        );
2041
        $this->dom->addChild(
2042
            $this->noInter,
2043
            'hFim',
2044
            $std->hFim,
2045
            true,
2046
            $identificador . 'Hora final'
2047
        );
2048
        return $this->noInter;
2049
    }
2050
2051
    /**
2052
     * Gera as tags para o elemento: "ObsCont" (Campo de uso livre do contribuinte)
2053
     * #91
2054
     * Nível: 2
2055
     * Os parâmetros para esta função são todos os elementos da tag "ObsCont" do
2056
     * tipo elemento (Ele = E|CE|A) e nível 3
2057
     *
2058
     * @return boolean
2059
     */
2060
    public function tagobsCont($std)
2061
    {
2062
2063
        $possible = [
2064
            'xCampo',
2065
            'xTexto'
2066
        ];
2067
2068
        $std = $this->equilizeParameters($std, $possible);
2069
2070
        $identificador = '#91 <ObsCont> - ';
2071
        if (count($this->obsCont) <= 10) {
2072
            $this->obsCont[] = $this->dom->createElement('ObsCont');
2073
            $posicao = (int)count($this->obsCont) - 1;
2074
            $this->obsCont[$posicao]->setAttribute('xCampo', $std->xCampo);
2075
            $this->dom->addChild(
2076
                $this->obsCont[$posicao],
2077
                'xTexto',
2078
                $std->xTexto,
2079
                true,
2080
                $identificador . 'Conteúdo do campo'
2081
            );
2082
            return true;
2083
        }
2084
        $this->errors[] = array(
2085
            'tag' => (string)'<ObsCont>',
2086
            'desc' => (string)'Campo de uso livre do contribuinte',
2087
            'erro' => (string)'Tag deve aparecer de 0 a 10 vezes'
2088
        );
2089
        return false;
2090
    }
2091
2092
    /**
2093
     * Gera as tags para o elemento: "ObsFisco" (Campo de uso livre do contribuinte)
2094
     * #94
2095
     * Nível: 2
2096
     * Os parâmetros para esta função são todos os elementos da tag "ObsFisco" do tipo
2097
     * elemento (Ele = E|CE|A) e nível 3
2098
     *
2099
     * @return boolean
2100
     */
2101
    public function tagobsFisco($std)
2102
    {
2103
2104
        $possible = [
2105
            'xCampo',
2106
            'xTexto'
2107
        ];
2108
2109
        $std = $this->equilizeParameters($std, $possible);
2110
2111
        $identificador = '#94 <ObsFisco> - ';
2112
        if (count($this->obsFisco) <= 10) {
2113
            $this->obsFisco[] = $this->dom->createElement('ObsFisco');
2114
            $posicao = (int)count($this->obsFisco) - 1;
2115
            $this->obsFisco[$posicao]->setAttribute('xCampo', $std->xCampo);
2116
            $this->dom->addChild(
2117
                $this->obsFisco[$posicao],
2118
                'xTexto',
2119
                $std->xTexto,
2120
                true,
2121
                $identificador . 'Conteúdo do campo'
2122
            );
2123
            return true;
2124
        }
2125
        $this->errors[] = array(
2126
            'tag' => (string)'<ObsFisco>',
2127
            'desc' => (string)'Campo de uso livre do contribuinte',
2128
            'erro' => (string)'Tag deve aparecer de 0 a 10 vezes'
2129
        );
2130
        return false;
2131
    }
2132
2133
    /**
2134
     * Gera as tags para o elemento: "emit" (Identificação do Emitente do CT-e)
2135
     * #97
2136
     * Nível: 1
2137
     * Os parâmetros para esta função são todos os elementos da tag "emit" do
2138
     * tipo elemento (Ele = E|CE|A) e nível 2
2139
     *
2140
     * @return \DOMElement
2141
     */
2142
    public function tagemit($std)
2143
    {
2144
2145
        $possible = [
2146
            'CNPJ',
2147
            'IE',
2148
            'IEST',
2149
            'xNome',
2150
            'xFant'
2151
        ];
2152
2153
        $std = $this->equilizeParameters($std, $possible);
2154
2155
        $identificador = '#97 <emit> - ';
2156
        $this->emit = $this->dom->createElement('emit');
2157
        $this->dom->addChild(
2158
            $this->emit,
2159
            'CNPJ',
2160
            $std->CNPJ,
2161
            true,
2162
            $identificador . 'CNPJ do emitente'
2163
        );
2164
        $this->dom->addChild(
2165
            $this->emit,
2166
            'IE',
2167
            Strings::onlyNumbers($std->IE),
2168
            false,
2169
            $identificador . 'Inscrição Estadual do Emitente'
2170
        );
2171
        $this->dom->addChild(
2172
            $this->emit,
2173
            'IEST',
2174
            Strings::onlyNumbers($std->IEST),
2175
            false,
2176
            $identificador . 'Inscrição Estadual do Substituto Tributário'
2177
        );
2178
        $this->dom->addChild(
2179
            $this->emit,
2180
            'xNome',
2181
            $std->xNome,
2182
            true,
2183
            $identificador . 'Razão social ou Nome do emitente'
2184
        );
2185
        $this->dom->addChild(
2186
            $this->emit,
2187
            'xFant',
2188
            $std->xFant,
2189
            false,
2190
            $identificador . 'Nome fantasia'
2191
        );
2192
        return $this->emit;
2193
    }
2194
2195
    /**
2196
     * Gera as tags para o elemento: "enderEmit" (Endereço do emitente)
2197
     * #102
2198
     * Nível: 2
2199
     * Os parâmetros para esta função são todos os elementos da tag "enderEmit" do
2200
     * tipo elemento (Ele = E|CE|A) e nível 3
2201
     *
2202
     * @return \DOMElement
2203
     */
2204
    public function tagenderEmit($std)
2205
    {
2206
2207
        $possible = [
2208
            'xLgr',
2209
            'nro',
2210
            'xCpl',
2211
            'xBairro',
2212
            'cMun',
2213
            'xMun',
2214
            'CEP',
2215
            'UF',
2216
            'fone'
2217
        ];
2218
2219
        $std = $this->equilizeParameters($std, $possible);
2220
2221
        $identificador = '#102 <enderEmit> - ';
2222
        $this->enderEmit = $this->dom->createElement('enderEmit');
2223
        $this->dom->addChild(
2224
            $this->enderEmit,
2225
            'xLgr',
2226
            $std->xLgr,
2227
            true,
2228
            $identificador . 'Logradouro'
2229
        );
2230
        $this->dom->addChild(
2231
            $this->enderEmit,
2232
            'nro',
2233
            $std->nro,
2234
            true,
2235
            $identificador . 'Número'
2236
        );
2237
        $this->dom->addChild(
2238
            $this->enderEmit,
2239
            'xCpl',
2240
            $std->xCpl,
2241
            false,
2242
            $identificador . 'Complemento'
2243
        );
2244
        $this->dom->addChild(
2245
            $this->enderEmit,
2246
            'xBairro',
2247
            $std->xBairro,
2248
            true,
2249
            $identificador . 'Bairro'
2250
        );
2251
        $this->dom->addChild(
2252
            $this->enderEmit,
2253
            'cMun',
2254
            $std->cMun,
2255
            true,
2256
            $identificador . 'Código do município'
2257
        );
2258
        $this->dom->addChild(
2259
            $this->enderEmit,
2260
            'xMun',
2261
            $std->xMun,
2262
            true,
2263
            $identificador . 'Nome do município'
2264
        );
2265
        $this->dom->addChild(
2266
            $this->enderEmit,
2267
            'CEP',
2268
            $std->CEP,
2269
            false,
2270
            $identificador . 'CEP'
2271
        );
2272
        $this->dom->addChild(
2273
            $this->enderEmit,
2274
            'UF',
2275
            $std->UF,
2276
            true,
2277
            $identificador . 'Sigla da UF'
2278
        );
2279
        $this->dom->addChild(
2280
            $this->enderEmit,
2281
            'fone',
2282
            $std->fone,
2283
            false,
2284
            $identificador . 'Telefone'
2285
        );
2286
        return $this->enderEmit;
2287
    }
2288
2289
    /**
2290
     * Gera as tags para o elemento: "rem" (Informações do Remetente das mercadorias
2291
     * transportadas pelo CT-e)
2292
     * #112
2293
     * Nível = 1
2294
     * Os parâmetros para esta função são todos os elementos da tag "rem" do
2295
     * tipo elemento (Ele = E|CE|A) e nível 2
2296
     *
2297
     * @return \DOMElement
2298
     */
2299
    public function tagrem($std)
2300
    {
2301
2302
        $possible = [
2303
            'CNPJ',
2304
            'CPF',
2305
            'IE',
2306
            'xNome',
2307
            'xFant',
2308
            'fone',
2309
            'email'
2310
        ];
2311
2312
        $std = $this->equilizeParameters($std, $possible);
2313
2314
        $identificador = '#97 <rem> - ';
2315
        $this->rem = $this->dom->createElement('rem');
2316
        if ($std->CNPJ != '') {
2317
            $this->dom->addChild(
2318
                $this->rem,
2319
                'CNPJ',
2320
                $std->CNPJ,
2321
                true,
2322
                $identificador . 'CNPJ do Remente'
2323
            );
2324
        } elseif ($std->CPF != '') {
2325
            $this->dom->addChild(
2326
                $this->rem,
2327
                'CPF',
2328
                $std->CPF,
2329
                true,
2330
                $identificador . 'CPF do Remente'
2331
            );
2332
        } else {
2333
            $this->dom->addChild(
2334
                $this->rem,
2335
                'CNPJ',
2336
                $std->CNPJ,
2337
                true,
2338
                $identificador . 'CNPJ do Remente'
2339
            );
2340
            $this->dom->addChild(
2341
                $this->rem,
2342
                'CPF',
2343
                $std->CPF,
2344
                true,
2345
                $identificador . 'CPF do remente'
2346
            );
2347
        }
2348
        $this->dom->addChild(
2349
            $this->rem,
2350
            'IE',
2351
            $std->IE,
2352
            false,
2353
            $identificador . 'Inscrição Estadual do remente'
2354
        );
2355
        $xNome = $std->xNome;
2356
        if ($this->tpAmb == '2') {
2357
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2358
        }
2359
        $this->dom->addChild(
2360
            $this->rem,
2361
            'xNome',
2362
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2363
            true,
2364
            $identificador . 'Razão social ou Nome do remente'
2365
        );
2366
        $this->dom->addChild(
2367
            $this->rem,
2368
            'xFant',
2369
            $std->xFant,
2370
            false,
2371
            $identificador . 'Nome fantasia'
2372
        );
2373
        $this->dom->addChild(
2374
            $this->rem,
2375
            'fone',
2376
            $std->fone,
2377
            false,
2378
            $identificador . 'Telefone'
2379
        );
2380
        $this->dom->addChild(
2381
            $this->rem,
2382
            'email',
2383
            $std->email,
2384
            false,
2385
            $identificador . 'Endereço de email'
2386
        );
2387
        return $this->rem;
2388
    }
2389
2390
    /**
2391
     * Gera as tags para o elemento: "enderReme" (Dados do endereço)
2392
     * #120
2393
     * Nível: 2
2394
     * Os parâmetros para esta função são todos os elementos da tag "enderReme" do
2395
     * tipo elemento (Ele = E|CE|A) e nível 3
2396
     *
2397
     * @return \DOMElement
2398
     */
2399
    public function tagenderReme($std)
2400
    {
2401
2402
        $possible = [
2403
            'xLgr',
2404
            'nro',
2405
            'xCpl',
2406
            'xBairro',
2407
            'cMun',
2408
            'xMun',
2409
            'CEP',
2410
            'UF',
2411
            'cPais',
2412
            'xPais'
2413
        ];
2414
2415
        $std = $this->equilizeParameters($std, $possible);
2416
2417
        $identificador = '#119 <enderReme> - ';
2418
        $this->enderReme = $this->dom->createElement('enderReme');
2419
        $this->dom->addChild(
2420
            $this->enderReme,
2421
            'xLgr',
2422
            $std->xLgr,
2423
            true,
2424
            $identificador . 'Logradouro'
2425
        );
2426
        $this->dom->addChild(
2427
            $this->enderReme,
2428
            'nro',
2429
            $std->nro,
2430
            true,
2431
            $identificador . 'Número'
2432
        );
2433
        $this->dom->addChild(
2434
            $this->enderReme,
2435
            'xCpl',
2436
            $std->xCpl,
2437
            false,
2438
            $identificador . 'Complemento'
2439
        );
2440
        $this->dom->addChild(
2441
            $this->enderReme,
2442
            'xBairro',
2443
            $std->xBairro,
2444
            true,
2445
            $identificador . 'Bairro'
2446
        );
2447
        $this->dom->addChild(
2448
            $this->enderReme,
2449
            'cMun',
2450
            $std->cMun,
2451
            true,
2452
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2453
        );
2454
        $this->dom->addChild(
2455
            $this->enderReme,
2456
            'xMun',
2457
            $std->xMun,
2458
            true,
2459
            $identificador . 'Nome do município'
2460
        );
2461
        $this->dom->addChild(
2462
            $this->enderReme,
2463
            'CEP',
2464
            $std->CEP,
2465
            false,
2466
            $identificador . 'CEP'
2467
        );
2468
        $this->dom->addChild(
2469
            $this->enderReme,
2470
            'UF',
2471
            $std->UF,
2472
            true,
2473
            $identificador . 'Sigla da UF'
2474
        );
2475
        $this->dom->addChild(
2476
            $this->enderReme,
2477
            'cPais',
2478
            $std->cPais,
2479
            false,
2480
            $identificador . 'Código do país'
2481
        );
2482
        $this->dom->addChild(
2483
            $this->enderReme,
2484
            'xPais',
2485
            $std->xPais,
2486
            false,
2487
            $identificador . 'Nome do país'
2488
        );
2489
2490
        $node = $this->rem->getElementsByTagName("email")->item(0);
2491
        $this->rem->insertBefore($this->enderReme, $node);
2492
        return $this->enderReme;
2493
    }
2494
2495
    /**
2496
     * Gera as tags para o elemento: "exped" (Informações do Expedidor da Carga)
2497
     * #132
2498
     * Nível: 1
2499
     * Os parâmetros para esta função são todos os elementos da tag "exped" do
2500
     * tipo elemento (Ele = E|CE|A) e nível 2
2501
     *
2502
     * @return \DOMElement
2503
     */
2504
    public function tagexped($std)
2505
    {
2506
2507
        $possible = [
2508
            'CNPJ',
2509
            'CPF',
2510
            'IE',
2511
            'xNome',
2512
            'fone',
2513
            'email'
2514
        ];
2515
2516
        $std = $this->equilizeParameters($std, $possible);
2517
2518
        $identificador = '#142 <exped> - ';
2519
        $this->exped = $this->dom->createElement('exped');
2520
        if ($std->CNPJ != '') {
2521
            $this->dom->addChild(
2522
                $this->exped,
2523
                'CNPJ',
2524
                $std->CNPJ,
2525
                true,
2526
                $identificador . 'Número do CNPJ'
2527
            );
2528
        } elseif ($std->CPF != '') {
2529
            $this->dom->addChild(
2530
                $this->exped,
2531
                'CPF',
2532
                $std->CPF,
2533
                true,
2534
                $identificador . 'Número do CPF'
2535
            );
2536
        } else {
2537
            $this->dom->addChild(
2538
                $this->exped,
2539
                'CNPJ',
2540
                $std->CNPJ,
2541
                true,
2542
                $identificador . 'Número do CNPJ'
2543
            );
2544
            $this->dom->addChild(
2545
                $this->exped,
2546
                'CPF',
2547
                $std->CPF,
2548
                true,
2549
                $identificador . 'Número do CPF'
2550
            );
2551
        }
2552
        if (!empty($std->IE)) {
2553
            $this->dom->addChild(
2554
                $this->exped,
2555
                'IE',
2556
                $std->IE,
2557
                true,
2558
                $identificador . 'Inscrição Estadual'
2559
            );
2560
        }
2561
        $xNome = $std->xNome;
2562
        if ($this->tpAmb == '2') {
2563
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2564
        }
2565
        $this->dom->addChild(
2566
            $this->exped,
2567
            'xNome',
2568
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2569
            true,
2570
            $identificador . 'Razão social ou Nome'
2571
        );
2572
        $this->dom->addChild(
2573
            $this->exped,
2574
            'fone',
2575
            $std->fone,
2576
            false,
2577
            $identificador . 'Telefone'
2578
        );
2579
        $this->dom->addChild(
2580
            $this->exped,
2581
            'email',
2582
            $std->email,
2583
            false,
2584
            $identificador . 'Endereço de email'
2585
        );
2586
        return $this->exped;
2587
    }
2588
2589
    /**
2590
     * Gera as tags para o elemento: "enderExped" (Dados do endereço)
2591
     * #138
2592
     * Nível: 2
2593
     * Os parâmetros para esta função são todos os elementos da tag "enderExped" do
2594
     * tipo elemento (Ele = E|CE|A) e nível 3
2595
     *
2596
     * @return \DOMElement
2597
     */
2598
    public function tagenderExped($std)
2599
    {
2600
2601
        $possible = [
2602
            'xLgr',
2603
            'nro',
2604
            'xCpl',
2605
            'xBairro',
2606
            'cMun',
2607
            'xMun',
2608
            'CEP',
2609
            'UF',
2610
            'cPais',
2611
            'xPais'
2612
        ];
2613
2614
        $std = $this->equilizeParameters($std, $possible);
2615
2616
        $identificador = '#148 <enderExped> - ';
2617
        $this->enderExped = $this->dom->createElement('enderExped');
2618
        $this->dom->addChild(
2619
            $this->enderExped,
2620
            'xLgr',
2621
            $std->xLgr,
2622
            true,
2623
            $identificador . 'Logradouro'
2624
        );
2625
        $this->dom->addChild(
2626
            $this->enderExped,
2627
            'nro',
2628
            $std->nro,
2629
            true,
2630
            $identificador . 'Número'
2631
        );
2632
        $this->dom->addChild(
2633
            $this->enderExped,
2634
            'xCpl',
2635
            $std->xCpl,
2636
            false,
2637
            $identificador . 'Complemento'
2638
        );
2639
        $this->dom->addChild(
2640
            $this->enderExped,
2641
            'xBairro',
2642
            $std->xBairro,
2643
            true,
2644
            $identificador . 'Bairro'
2645
        );
2646
        $this->dom->addChild(
2647
            $this->enderExped,
2648
            'cMun',
2649
            $std->cMun,
2650
            true,
2651
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2652
        );
2653
        $this->dom->addChild(
2654
            $this->enderExped,
2655
            'xMun',
2656
            $std->xMun,
2657
            true,
2658
            $identificador . 'Nome do município'
2659
        );
2660
        $this->dom->addChild(
2661
            $this->enderExped,
2662
            'CEP',
2663
            $std->CEP,
2664
            false,
2665
            $identificador . 'CEP'
2666
        );
2667
        $this->dom->addChild(
2668
            $this->enderExped,
2669
            'UF',
2670
            $std->UF,
2671
            true,
2672
            $identificador . 'Sigla da UF'
2673
        );
2674
        $this->dom->addChild(
2675
            $this->enderExped,
2676
            'cPais',
2677
            $std->cPais,
2678
            false,
2679
            $identificador . 'Código do país'
2680
        );
2681
        $this->dom->addChild(
2682
            $this->enderExped,
2683
            'xPais',
2684
            $std->xPais,
2685
            false,
2686
            $identificador . 'Nome do país'
2687
        );
2688
        $node = $this->exped->getElementsByTagName("email")->item(0);
2689
        $this->exped->insertBefore($this->enderExped, $node);
2690
        return $this->enderExped;
2691
    }
2692
2693
    /**
2694
     * Gera as tags para o elemento: "receb" (Informações do Recebedor da Carga)
2695
     * #150
2696
     * Nível: 1
2697
     * Os parâmetros para esta função são todos os elementos da tag "receb" do
2698
     * tipo elemento (Ele = E|CE|A) e nível 2
2699
     *
2700
     * @return \DOMElement
2701
     */
2702
    public function tagreceb($std)
2703
    {
2704
2705
        $possible = [
2706
            'CNPJ',
2707
            'CPF',
2708
            'IE',
2709
            'xNome',
2710
            'fone',
2711
            'email'
2712
        ];
2713
2714
        $std = $this->equilizeParameters($std, $possible);
2715
2716
        $identificador = '#160 <receb> - ';
2717
        $this->receb = $this->dom->createElement('receb');
2718
        if ($std->CNPJ != '') {
2719
            $this->dom->addChild(
2720
                $this->receb,
2721
                'CNPJ',
2722
                $std->CNPJ,
2723
                true,
2724
                $identificador . 'Número do CNPJ'
2725
            );
2726
        } elseif ($std->CPF != '') {
2727
            $this->dom->addChild(
2728
                $this->receb,
2729
                'CPF',
2730
                $std->CPF,
2731
                true,
2732
                $identificador . 'Número do CPF'
2733
            );
2734
        } else {
2735
            $this->dom->addChild(
2736
                $this->receb,
2737
                'CNPJ',
2738
                $std->CNPJ,
2739
                true,
2740
                $identificador . 'Número do CNPJ'
2741
            );
2742
            $this->dom->addChild(
2743
                $this->receb,
2744
                'CPF',
2745
                $std->CPF,
2746
                true,
2747
                $identificador . 'Número do CPF'
2748
            );
2749
        }
2750
        if (!empty($std->IE)) {
2751
            $this->dom->addChild(
2752
                $this->receb,
2753
                'IE',
2754
                $std->IE,
2755
                true,
2756
                $identificador . 'Inscrição Estadual'
2757
            );
2758
        }
2759
        $xNome = $std->xNome;
2760
        if ($this->tpAmb == '2') {
2761
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2762
        }
2763
        $this->dom->addChild(
2764
            $this->receb,
2765
            'xNome',
2766
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2767
            true,
2768
            $identificador . 'Razão social ou Nome'
2769
        );
2770
        $this->dom->addChild(
2771
            $this->receb,
2772
            'fone',
2773
            $std->fone,
2774
            false,
2775
            $identificador . 'Telefone'
2776
        );
2777
        $this->dom->addChild(
2778
            $this->receb,
2779
            'email',
2780
            $std->email,
2781
            false,
2782
            $identificador . 'Endereço de email'
2783
        );
2784
        return $this->receb;
2785
    }
2786
2787
    /**
2788
     * Gera as tags para o elemento: "enderReceb" (Informações do Recebedor da Carga)
2789
     * #156
2790
     * Nível: 2
2791
     * Os parâmetros para esta função são todos os elementos da tag "enderReceb" do
2792
     * tipo elemento (Ele = E|CE|A) e nível 3
2793
     *
2794
     * @return \DOMElement
2795
     */
2796
    public function tagenderReceb($std)
2797
    {
2798
2799
        $possible = [
2800
            'xLgr',
2801
            'nro',
2802
            'xCpl',
2803
            'xBairro',
2804
            'cMun',
2805
            'xMun',
2806
            'CEP',
2807
            'UF',
2808
            'cPais',
2809
            'xPais'
2810
        ];
2811
2812
        $std = $this->equilizeParameters($std, $possible);
2813
2814
        $identificador = '#160 <enderReceb> - ';
2815
        $this->enderReceb = $this->dom->createElement('enderReceb');
2816
        $this->dom->addChild(
2817
            $this->enderReceb,
2818
            'xLgr',
2819
            $std->xLgr,
2820
            true,
2821
            $identificador . 'Logradouro'
2822
        );
2823
        $this->dom->addChild(
2824
            $this->enderReceb,
2825
            'nro',
2826
            $std->nro,
2827
            true,
2828
            $identificador . 'Número'
2829
        );
2830
        $this->dom->addChild(
2831
            $this->enderReceb,
2832
            'xCpl',
2833
            $std->xCpl,
2834
            false,
2835
            $identificador . 'Complemento'
2836
        );
2837
        $this->dom->addChild(
2838
            $this->enderReceb,
2839
            'xBairro',
2840
            $std->xBairro,
2841
            true,
2842
            $identificador . 'Bairro'
2843
        );
2844
        $this->dom->addChild(
2845
            $this->enderReceb,
2846
            'cMun',
2847
            $std->cMun,
2848
            true,
2849
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2850
        );
2851
        $this->dom->addChild(
2852
            $this->enderReceb,
2853
            'xMun',
2854
            $std->xMun,
2855
            true,
2856
            $identificador . 'Nome do município'
2857
        );
2858
        $this->dom->addChild(
2859
            $this->enderReceb,
2860
            'CEP',
2861
            $std->CEP,
2862
            false,
2863
            $identificador . 'CEP'
2864
        );
2865
        $this->dom->addChild(
2866
            $this->enderReceb,
2867
            'UF',
2868
            $std->UF,
2869
            true,
2870
            $identificador . 'Sigla da UF'
2871
        );
2872
        $this->dom->addChild(
2873
            $this->enderReceb,
2874
            'cPais',
2875
            $std->cPais,
2876
            false,
2877
            $identificador . 'Código do país'
2878
        );
2879
        $this->dom->addChild(
2880
            $this->enderReceb,
2881
            'xPais',
2882
            $std->xPais,
2883
            false,
2884
            $identificador . 'Nome do país'
2885
        );
2886
        $node = $this->receb->getElementsByTagName("email")->item(0);
2887
        $this->receb->insertBefore($this->enderReceb, $node);
2888
        return $this->enderReceb;
2889
    }
2890
2891
    /**
2892
     * Gera as tags para o elemento: "dest" (Informações do Destinatário do CT-e)
2893
     * #168
2894
     * Nível: 1
2895
     * Os parâmetros para esta função são todos os elementos da tag "dest" do
2896
     * tipo elemento (Ele = E|CE|A) e nível 2
2897
     *
2898
     * @return \DOMElement
2899
     */
2900
    public function tagdest($std)
2901
    {
2902
2903
        $possible = [
2904
            'CNPJ',
2905
            'CPF',
2906
            'IE',
2907
            'xNome',
2908
            'fone',
2909
            'ISUF',
2910
            'email'
2911
        ];
2912
2913
        $std = $this->equilizeParameters($std, $possible);
2914
2915
        $identificador = '#178 <dest> - ';
2916
        $this->dest = $this->dom->createElement('dest');
2917
        if ($std->CNPJ != '') {
2918
            $this->dom->addChild(
2919
                $this->dest,
2920
                'CNPJ',
2921
                $std->CNPJ,
2922
                true,
2923
                $identificador . 'Número do CNPJ'
2924
            );
2925
        } elseif ($std->CPF != '') {
2926
            $this->dom->addChild(
2927
                $this->dest,
2928
                'CPF',
2929
                $std->CPF,
2930
                true,
2931
                $identificador . 'Número do CPF'
2932
            );
2933
        } else {
2934
            $this->dom->addChild(
2935
                $this->dest,
2936
                'CNPJ',
2937
                $std->CNPJ,
2938
                true,
2939
                $identificador . 'Número do CNPJ'
2940
            );
2941
            $this->dom->addChild(
2942
                $this->dest,
2943
                'CPF',
2944
                $std->CPF,
2945
                true,
2946
                $identificador . 'Número do CPF'
2947
            );
2948
        }
2949
        if (!empty($std->IE)) {
2950
            $this->dom->addChild(
2951
                $this->dest,
2952
                'IE',
2953
                $std->IE,
2954
                true,
2955
                $identificador . 'Inscrição Estadual'
2956
            );
2957
        }
2958
        $xNome = $std->xNome;
2959
        if ($this->tpAmb == '2') {
2960
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2961
        }
2962
        $this->dom->addChild(
2963
            $this->dest,
2964
            'xNome',
2965
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2966
            true,
2967
            $identificador . 'Razão social ou Nome'
2968
        );
2969
        $this->dom->addChild(
2970
            $this->dest,
2971
            'fone',
2972
            $std->fone,
2973
            false,
2974
            $identificador . 'Telefone'
2975
        );
2976
        $this->dom->addChild(
2977
            $this->dest,
2978
            'ISUF',
2979
            $std->ISUF,
2980
            false,
2981
            $identificador . 'Inscrição na SUFRAMA'
2982
        );
2983
        $this->dom->addChild(
2984
            $this->dest,
2985
            'email',
2986
            $std->email,
2987
            false,
2988
            $identificador . 'Endereço de email'
2989
        );
2990
        return $this->dest;
2991
    }
2992
2993
    /**
2994
     * Gera as tags para o elemento: "enderDest" (Informações do Recebedor da Carga)
2995
     * # = 175
2996
     * Nível = 2
2997
     * Os parâmetros para esta função são todos os elementos da tag "enderDest" do
2998
     * tipo elemento (Ele = E|CE|A) e nível 3
2999
     *
3000
     * @return \DOMElement
3001
     */
3002
    public function tagenderDest($std)
3003
    {
3004
3005
        $possible = [
3006
            'xLgr',
3007
            'nro',
3008
            'xCpl',
3009
            'xBairro',
3010
            'cMun',
3011
            'xMun',
3012
            'CEP',
3013
            'UF',
3014
            'cPais',
3015
            'xPais'
3016
        ];
3017
3018
        $std = $this->equilizeParameters($std, $possible);
3019
3020
        $identificador = '#185 <enderDest> - ';
3021
        $this->enderDest = $this->dom->createElement('enderDest');
3022
        $this->dom->addChild(
3023
            $this->enderDest,
3024
            'xLgr',
3025
            $std->xLgr,
3026
            true,
3027
            $identificador . 'Logradouro'
3028
        );
3029
        $this->dom->addChild(
3030
            $this->enderDest,
3031
            'nro',
3032
            $std->nro,
3033
            true,
3034
            $identificador . 'Número'
3035
        );
3036
        $this->dom->addChild(
3037
            $this->enderDest,
3038
            'xCpl',
3039
            $std->xCpl,
3040
            false,
3041
            $identificador . 'Complemento'
3042
        );
3043
        $this->dom->addChild(
3044
            $this->enderDest,
3045
            'xBairro',
3046
            $std->xBairro,
3047
            true,
3048
            $identificador . 'Bairro'
3049
        );
3050
        $this->dom->addChild(
3051
            $this->enderDest,
3052
            'cMun',
3053
            $std->cMun,
3054
            true,
3055
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
3056
        );
3057
        $this->dom->addChild(
3058
            $this->enderDest,
3059
            'xMun',
3060
            $std->xMun,
3061
            true,
3062
            $identificador . 'Nome do município'
3063
        );
3064
        $this->dom->addChild(
3065
            $this->enderDest,
3066
            'CEP',
3067
            $std->CEP,
3068
            false,
3069
            $identificador . 'CEP'
3070
        );
3071
        $this->dom->addChild(
3072
            $this->enderDest,
3073
            'UF',
3074
            $std->UF,
3075
            true,
3076
            $identificador . 'Sigla da UF'
3077
        );
3078
        $this->dom->addChild(
3079
            $this->enderDest,
3080
            'cPais',
3081
            $std->cPais,
3082
            false,
3083
            $identificador . 'Código do país'
3084
        );
3085
        $this->dom->addChild(
3086
            $this->enderDest,
3087
            'xPais',
3088
            $std->xPais,
3089
            false,
3090
            $identificador . 'Nome do país'
3091
        );
3092
        $node = $this->dest->getElementsByTagName("email")->item(0);
3093
        $this->dest->insertBefore($this->enderDest, $node);
3094
        return $this->enderDest;
3095
    }
3096
3097
    /**
3098
     * Gera as tags para o elemento: "vPrest" (Valores da Prestação de Serviço)
3099
     * #187
3100
     * Nível: 1
3101
     * Os parâmetros para esta função são todos os elementos da tag "vPrest" do
3102
     * tipo elemento (Ele = E|CE|A) e nível 2
3103
     *
3104
     * @return \DOMElement
3105
     */
3106
    public function tagvPrest($std)
3107
    {
3108
3109
        $possible = [
3110
            'vTPrest',
3111
            'vRec'
3112
        ];
3113
3114
        $std = $this->equilizeParameters($std, $possible);
3115
3116
        $identificador = '#208 <vPrest> - ';
3117
        $this->vPrest = $this->dom->createElement('vPrest');
3118
        $this->dom->addChild(
3119
            $this->vPrest,
3120
            'vTPrest',
3121
            $std->vTPrest,
3122
            true,
3123
            $identificador . 'Valor Total da Prestação do Serviço'
3124
        );
3125
        $this->dom->addChild(
3126
            $this->vPrest,
3127
            'vRec',
3128
            $std->vRec,
3129
            true,
3130
            $identificador . 'Valor a Receber'
3131
        );
3132
        return $this->vPrest;
3133
    }
3134
3135
    /**
3136
     * Gera as tags para o elemento: "Comp" (Componentes do Valor da Prestação)
3137
     * #211
3138
     * Nível: 2
3139
     * Os parâmetros para esta função são todos os elementos da tag "Comp" do
3140
     * tipo elemento (Ele = E|CE|A) e nível 3
3141
     *
3142
     * @return \DOMElement
3143
     */
3144
    public function tagComp($std)
3145
    {
3146
3147
        $possible = [
3148
            'xNome',
3149
            'vComp'
3150
        ];
3151
3152
        $std = $this->equilizeParameters($std, $possible);
3153
3154
        $identificador = '#65 <pass> - ';
3155
        $this->comp[] = $this->dom->createElement('Comp');
3156
        $posicao = (int)count($this->comp) - 1;
3157
        $this->dom->addChild(
3158
            $this->comp[$posicao],
3159
            'xNome',
3160
            $std->xNome,
3161
            false,
3162
            $identificador . 'Nome do componente'
3163
        );
3164
        $this->dom->addChild(
3165
            $this->comp[$posicao],
3166
            'vComp',
3167
            $std->vComp,
3168
            false,
3169
            $identificador . 'Valor do componente'
3170
        );
3171
        return $this->comp[$posicao];
3172
    }
3173
3174
    /**
3175
     * tagICMS
3176
     * Informações relativas ao ICMS
3177
     * #194
3178
     *
3179
     * @return DOMElement
3180
     */
3181
    public function tagicms($std)
3182
    {
3183
3184
        $possible = [
3185
            'cst',
3186
            'vBC',
3187
            'pICMS',
3188
            'vICMS',
3189
            'pRedBC',
3190
            'vBCSTRet',
3191
            'vICMSSTRet',
3192
            'pICMSSTRet',
3193
            'vCred',
3194
            'pRedBCOutraUF',
3195
            'vBCOutraUF',
3196
            'pICMSOutraUF',
3197
            'vICMSOutraUF',
3198
            'pRedBC',
3199
            'vTotTrib',
3200
            'infAdFisco',
3201
            'vBCUFFim',
3202
            'pFCPUFFim',
3203
            'pICMSUFFim',
3204
            'pICMSInter',
3205
            'vFCPUFFim',
3206
            'vICMSUFFim',
3207
            'vICMSUFIni'
3208
        ];
3209
3210
        $std = $this->equilizeParameters($std, $possible);
3211
3212
        $identificador = 'N01 <ICMSxx> - ';
3213
        switch ($std->cst) {
3214
            case '00':
3215
                $icms = $this->dom->createElement("ICMS00");
3216
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 00");
3217
                $this->dom->addChild($icms, 'vBC', $std->vBC, true, "$identificador  Valor da BC do ICMS");
3218
                $this->dom->addChild($icms, 'pICMS', $std->pICMS, true, "$identificador  Alíquota do imposto");
3219
                $this->dom->addChild($icms, 'vICMS', $std->vICMS, true, "$identificador  Valor do ICMS");
3220
                break;
3221
            case '20':
3222
                $icms = $this->dom->createElement("ICMS20");
3223
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 20");
3224
                $this->dom->addChild(
3225
                    $icms,
3226
                    'pRedBC',
3227
                    $std->pRedBC,
3228
                    true,
3229
                    "$identificador  Percentual da Redução de BC"
3230
                );
3231
                $this->dom->addChild($icms, 'vBC', $std->vBC, true, "$identificador  Valor da BC do ICMS");
3232
                $this->dom->addChild($icms, 'pICMS', $std->pICMS, true, "$identificador  Alíquota do imposto");
3233
                $this->dom->addChild($icms, 'vICMS', $std->vICMS, true, "$identificador  Valor do ICMS");
3234
                break;
3235
            case '40':
3236
                $icms = $this->dom->createElement("ICMS45");
3237
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 40");
3238
                break;
3239
            case '41':
3240
                $icms = $this->dom->createElement("ICMS45");
3241
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 41");
3242
                break;
3243
            case '51':
3244
                $icms = $this->dom->createElement("ICMS45");
3245
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 51");
3246
                break;
3247
            case '60':
3248
                $icms = $this->dom->createElement("ICMS60");
3249
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 60");
3250
                $this->dom->addChild(
3251
                    $icms,
3252
                    'vBCSTRet',
3253
                    $std->vBCSTRet,
3254
                    true,
3255
                    "$identificador  Valor BC do ICMS ST retido"
3256
                );
3257
                $this->dom->addChild(
3258
                    $icms,
3259
                    'vICMSSTRet',
3260
                    $std->vICMSSTRet,
3261
                    true,
3262
                    "$identificador  Valor do ICMS ST retido"
3263
                );
3264
                $this->dom->addChild(
3265
                    $icms,
3266
                    'pICMSSTRet',
3267
                    $std->pICMSSTRet,
3268
                    true,
3269
                    "$identificador  Valor do ICMS ST retido"
3270
                );
3271
                if ($std->vCred > 0) {
3272
                    $this->dom->addChild($icms, 'vCred', $std->vCred, false, "$identificador  Valor do Crédito");
3273
                }
3274
                break;
3275
            case '90':
3276
                if ($std->outraUF == true) {
3277
                    $icms = $this->dom->createElement("ICMSOutraUF");
3278
                    $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 90");
3279
                    if ($std->vICMSOutraUF > 0) {
3280
                        $this->dom->addChild(
3281
                            $icms,
3282
                            'pRedBCOutraUF',
3283
                            $std->pRedBCOutraUF,
3284
                            false,
3285
                            "$identificador Percentual Red "
3286
                            . "BC Outra UF"
3287
                        );
3288
                    }
3289
                    $this->dom->addChild(
3290
                        $icms,
3291
                        'vBCOutraUF',
3292
                        $std->vBCOutraUF,
3293
                        true,
3294
                        "$identificador Valor BC ICMS Outra UF"
3295
                    );
3296
                    $this->dom->addChild(
3297
                        $icms,
3298
                        'pICMSOutraUF',
3299
                        $std->pICMSOutraUF,
3300
                        true,
3301
                        "$identificador Alíquota do imposto Outra UF"
3302
                    );
3303
                    $this->dom->addChild(
3304
                        $icms,
3305
                        'vICMSOutraUF',
3306
                        $std->vICMSOutraUF,
3307
                        true,
3308
                        "$identificador Valor ICMS Outra UF"
3309
                    );
3310
                } else {
3311
                    $icms = $this->dom->createElement("ICMS90");
3312
                    $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador Tributação do ICMS = 90");
3313
                    if ($std->pRedBC > 0) {
3314
                        $this->dom->addChild(
3315
                            $icms,
3316
                            'pRedBC',
3317
                            $std->pRedBC,
3318
                            false,
3319
                            "$identificador Percentual Redução BC"
3320
                        );
3321
                    }
3322
                    $this->dom->addChild($icms, 'vBC', $std->vBC, true, "$identificador  Valor da BC do ICMS");
3323
                    $this->dom->addChild($icms, 'pICMS', $std->pICMS, true, "$identificador  Alíquota do imposto");
3324
                    $this->dom->addChild($icms, 'vICMS', $std->vICMS, true, "$identificador  Valor do ICMS");
3325
                    if ($std->vCred > 0) {
3326
                        $this->dom->addChild($icms, 'vCred', $std->vCred, false, "$identificador  Valor do Crédido");
3327
                    }
3328
                }
3329
                break;
3330
            case 'SN':
3331
                $icms = $this->dom->createElement("ICMSSN");
3332
                $this->dom->addChild($icms, 'CST', 90, true, "$identificador Tributação do ICMS = 90");
3333
                $this->dom->addChild($icms, 'indSN', '1', true, "$identificador  Indica se contribuinte é SN");
3334
                break;
3335
        }
3336
        $this->imp = $this->dom->createElement('imp');
3337
        $tagIcms = $this->dom->createElement('ICMS');
3338
        if (isset($icms)) {
3339
            $this->imp->appendChild($tagIcms);
3340
        }
3341
        if (isset($icms)) {
3342
            $tagIcms->appendChild($icms);
3343
        }
3344
        if ($std->vTotTrib > 0) {
3345
            $this->dom->addChild(
3346
                $this->imp,
3347
                'vTotTrib',
3348
                $std->vTotTrib,
3349
                false,
3350
                "$identificador Valor Total dos Tributos"
3351
            );
3352
        }
3353
        if (isset($std->infAdFisco)) {
3354
            $this->dom->addChild(
3355
                $this->imp,
3356
                'infAdFisco',
3357
                $std->infAdFisco,
3358
                false,
3359
                "$identificador Informações adicionais de interesse do Fisco"
3360
            );
3361
        }
3362
3363
        if ($std->vICMSUFFim != '' || $std->vICMSUFIni != '') {
3364
            $icmsDifal = $this->dom->createElement("ICMSUFFim");
3365
            $this->dom->addChild(
3366
                $icmsDifal,
3367
                'vBCUFFim',
3368
                $std->vBCUFFim,
3369
                true,
3370
                "$identificador Valor da BC do ICMS na UF
3371
                de término da prestação do serviço de transporte"
3372
            );
3373
            $this->dom->addChild(
3374
                $icmsDifal,
3375
                'pFCPUFFim',
3376
                $std->pFCPUFFim,
3377
                true,
3378
                "$identificador Percentual do ICMS
3379
                relativo ao Fundo de Combate à pobreza (FCP) na UF de término da prestação do serviço de
3380
                transporte"
3381
            );
3382
            $this->dom->addChild(
3383
                $icmsDifal,
3384
                'pICMSUFFim',
3385
                $std->pICMSUFFim,
3386
                true,
3387
                "$identificador Alíquota interna da UF
3388
                de término da prestação do serviço de transporte"
3389
            );
3390
            $this->dom->addChild(
3391
                $icmsDifal,
3392
                'pICMSInter',
3393
                $std->pICMSInter,
3394
                true,
3395
                "$identificador Alíquota interestadual
3396
                das UF envolvidas"
3397
            );
3398
            $this->dom->addChild(
3399
                $icmsDifal,
3400
                'vFCPUFFim',
3401
                $std->vFCPUFFim,
3402
                true,
3403
                "$identificador Valor do ICMS relativo
3404
                ao Fundo de Combate á Pobreza (FCP) da UF de término da prestação"
3405
            );
3406
            $this->dom->addChild(
3407
                $icmsDifal,
3408
                'vICMSUFFim',
3409
                $std->vICMSUFFim,
3410
                true,
3411
                "$identificador Valor do ICMS de
3412
                partilha para a UF de término da prestação do serviço de transporte"
3413
            );
3414
            $this->dom->addChild(
3415
                $icmsDifal,
3416
                'vICMSUFIni',
3417
                $std->vICMSUFIni,
3418
                true,
3419
                "$identificador Valor do ICMS de
3420
                partilha para a UF de início da prestação do serviço de transporte"
3421
            );
3422
3423
            $this->imp->appendChild($icmsDifal);
3424
        }
3425
3426
        return $tagIcms;
3427
    }
3428
3429
    /**
3430
     * tagInfTribFed
3431
     * Informações do Impostos Federais
3432
     * CTe OS
3433
     * @return DOMElement
3434
     */
3435
    public function taginfTribFed($std)
3436
    {
3437
3438
        $possible = [
3439
            'vPIS',
3440
            'vCOFINS',
3441
            'vIR',
3442
            'vINSS',
3443
            'vCSLL'
3444
        ];
3445
3446
        $std = $this->equilizeParameters($std, $possible);
3447
3448
        $identificador = 'N02 <imp> - ';
3449
        $tagInfTribFed = $this->dom->createElement('infTribFed');
3450
        $this->dom->addChild($tagInfTribFed, 'vPIS', $std->vPIS, false, "$identificador  Valor de PIS");
3451
        $this->dom->addChild($tagInfTribFed, 'vCOFINS', $std->vCOFINS, false, "$identificador  Valor de COFINS");
3452
        $this->dom->addChild($tagInfTribFed, 'vIR', $std->vIR, false, "$identificador  Valor de IR");
3453
        $this->dom->addChild($tagInfTribFed, 'vINSS', $std->vINSS, false, "$identificador  Valor de INSS");
3454
        $this->dom->addChild($tagInfTribFed, 'vCSLL', $std->vCSLL, false, "$identificador  Valor de CSLL");
3455
        $this->imp->appendChild($tagInfTribFed);
3456
    }
3457
3458
3459
    /**
3460
     * Tag raiz do documento xml
3461
     * Função chamada pelo método [ monta ]
3462
     * @return \DOMElement
3463
     */
3464
    private function buildCTe()
3465
    {
3466
        if (empty($this->CTe)) {
3467
            $this->CTe = $this->dom->createElement('CTe');
3468
            $this->CTe->setAttribute('xmlns', 'http://www.portalfiscal.inf.br/cte');
3469
        }
3470
        return $this->CTe;
3471
    }
3472
3473
    /**
3474
     * Tag raiz do documento xml
3475
     * Função chamada pelo método [ monta ]
3476
     * @return \DOMElement
3477
     */
3478
    private function buildCTeOS()
3479
    {
3480
        if (empty($this->CTe)) {
3481
            $this->CTe = $this->dom->createElement('CTeOS');
3482
            $this->CTe->setAttribute('versao', '3.00');
3483
            $this->CTe->setAttribute('xmlns', 'http://www.portalfiscal.inf.br/cte');
3484
        }
3485
        return $this->CTe;
3486
    }
3487
3488
    /**
3489
     * Gera as tags para o elemento: "Entrega" (Informações ref. a previsão de entrega)
3490
     * #69
3491
     * Nível: 2
3492
     * Os parâmetros para esta função são todos os elementos da tag "Entrega" do
3493
     * tipo elemento (Ele = E|CE|A) e nível 3
3494
     *
3495
     * @return \DOMElement
3496
     */
3497
    private function tagEntrega()
3498
    {
3499
        if ($this->compl == '') {
3500
            $this->compl = $this->dom->createElement('compl');
3501
        }
3502
        if ($this->entrega == '') {
3503
            $this->entrega = $this->dom->createElement('Entrega');
3504
            $this->dom->appChild($this->compl, $this->entrega, 'Falta tag "compl"');
3505
        }
3506
        return $this->entrega;
3507
    }
3508
3509
    /**
3510
     * #241
3511
     * @return type
3512
     */
3513
    public function taginfCTeNorm()
3514
    {
3515
        $this->infCTeNorm = $this->dom->createElement('infCTeNorm');
3516
        return $this->infCTeNorm;
3517
    }
3518
3519
    /**
3520
     * Gera as tags para o elemento: "infCarga" (Informações da Carga do CT-e)
3521
     * #242
3522
     * Nível: 2
3523
     *
3524
     * @return \DOMElement
3525
     */
3526
    public function taginfCarga($std)
3527
    {
3528
3529
        $possible = [
3530
            'vCarga',
3531
            'proPred',
3532
            'xOutCat'
3533
        ];
3534
3535
        $std = $this->equilizeParameters($std, $possible);
3536
3537
        $identificador = '#242 <infCarga> - ';
3538
        $this->infCarga = $this->dom->createElement('infCarga');
3539
        $this->dom->addChild(
3540
            $this->infCarga,
3541
            'vCarga',
3542
            $std->vCarga,
3543
            false,
3544
            $identificador . 'Valor Total da Carga'
3545
        );
3546
        $this->dom->addChild(
3547
            $this->infCarga,
3548
            'proPred',
3549
            $std->proPred,
3550
            true,
3551
            $identificador . 'Produto Predominante'
3552
        );
3553
        $this->dom->addChild(
3554
            $this->infCarga,
3555
            'xOutCat',
3556
            $std->xOutCat,
3557
            false,
3558
            $identificador . 'Outras Caract. da Carga'
3559
        );
3560
        return $this->infCarga;
3561
    }
3562
3563
    /**
3564
     * Gera as tags para o elemento: "infCTeNorm" (Informações da Carga do CT-e OS)
3565
     * #253
3566
     * Nível: 2
3567
     * Os parâmetros para esta função são todos os elementos da tag "infServico"
3568
     *
3569
     * @return \DOMElement
3570
     */
3571
    public function taginfServico($std)
3572
    {
3573
3574
        $possible = [
3575
            'xDescServ'
3576
        ];
3577
3578
        $std = $this->equilizeParameters($std, $possible);
3579
3580
        $identificador = '#253 <infServico> - ';
3581
        $this->infServico = $this->dom->createElement('infServico');
3582
        $this->dom->addChild(
3583
            $this->infServico,
3584
            'xDescServ',
3585
            $std->xDescServ,
3586
            true,
3587
            $identificador . 'Descrição do Serviço Prestado'
3588
        );
3589
        $infQ = $this->dom->createElement('infQ');
3590
        $this->dom->addChild($infQ, 'qCarga', $std->qCarga, false, $identificador . 'Quantidade');
3591
        $this->infServico->appendChild($infQ);
3592
        return $this->infServico;
3593
    }
3594
3595
    /**
3596
     * Gera as tags para o elemento: "infQ" (Informações de quantidades da Carga do CT-e)
3597
     * #246
3598
     * Nível: 3
3599
     * Os parâmetros para esta função são todos os elementos da tag "infQ"
3600
     *
3601
     * @return mixed
3602
     */
3603
    public function taginfQ($std)
3604
    {
3605
3606
        $possible = [
3607
            'cUnid',
3608
            'tpMed',
3609
            'qCarga',
3610
            'vCargaAverb'
3611
        ];
3612
3613
        $std = $this->equilizeParameters($std, $possible);
3614
3615
        $identificador = '#257 <infQ> - ';
3616
        $this->infQ[] = $this->dom->createElement('infQ');
3617
        $posicao = (int)count($this->infQ) - 1;
3618
        $this->dom->addChild(
3619
            $this->infQ[$posicao],
3620
            'cUnid',
3621
            $std->cUnid,
3622
            true,
3623
            $identificador . 'Código da Unidade de Medida'
3624
        );
3625
        $this->dom->addChild(
3626
            $this->infQ[$posicao],
3627
            'tpMed',
3628
            $std->tpMed,
3629
            true,
3630
            $identificador . 'Tipo da Medida'
3631
        );
3632
        $this->dom->addChild(
3633
            $this->infQ[$posicao],
3634
            'qCarga',
3635
            $std->qCarga,
3636
            true,
3637
            $identificador . 'Quantidade'
3638
        );
3639
        $this->dom->addChild(
3640
            $this->infQ[$posicao],
3641
            'vCargaAverb',
3642
            $std->vCargaAverb,
3643
            false,
3644
            $identificador . 'Valor da Carga para efeito de averbação'
3645
        );
3646
        return $this->infQ[$posicao];
3647
    }
3648
3649
    private function taginfDoc()
3650
    {
3651
        if (empty($this->infDoc)) {
3652
            $this->infDoc = $this->dom->createElement('infDoc');
3653
        }
3654
        return $this->infDoc;
3655
    }
3656
3657
    /**
3658
     * Documentos de Transporte Anterior
3659
     * @return DOMElement|\DOMNode
3660
     */
3661
    public function tagdocAnt()
3662
    {
3663
        $this->docAnt = $this->dom->createElement('docAnt');
3664
        return $this->docAnt;
3665
    }
3666
3667
    /**
3668
     * Informações de identificação dos documentos de Transporte Anterior
3669
     * @return array|DOMElement
3670
     */
3671
    public function tagidDocAnt()
3672
    {
3673
        $this->idDocAnt[count($this->emiDocAnt) - 1] = $this->dom->createElement('idDocAnt');
3674
        return $this->idDocAnt;
3675
    }
3676
3677
    /**
3678
     * Gera as tags para o elemento: "infNF" (Informações das NF)
3679
     * #262
3680
     * Nível: 3
3681
     * @return mixed
3682
     */
3683
    public function taginfNF($std)
3684
    {
3685
3686
        $possible = [
3687
            'nRoma',
3688
            'nPed',
3689
            'mod',
3690
            'serie',
3691
            'nDoc',
3692
            'dEmi',
3693
            'vBC',
3694
            'vICMS',
3695
            'vBCST',
3696
            'vST',
3697
            'vProd',
3698
            'vNF',
3699
            'nCFOP',
3700
            'nPeso',
3701
            'PIN',
3702
            'dPrev',
3703
            'infUnidCarga',
3704
            'infUnidTransp'
3705
        ];
3706
        $this->taginfDoc();
3707
        $std = $this->equilizeParameters($std, $possible);
3708
3709
        $identificador = '#262 <infNF> - ';
3710
        $infNF = $this->dom->createElement('infNF');
3711
        $this->dom->addChild(
3712
            $infNF,
3713
            'nRoma',
3714
            $std->nRoma,
3715
            false,
3716
            $identificador . 'Número do Romaneio da NF'
3717
        );
3718
        $this->dom->addChild(
3719
            $infNF,
3720
            'nPed',
3721
            $std->nPed,
3722
            false,
3723
            $identificador . 'Número do Pedido da NF'
3724
        );
3725
        $this->dom->addChild(
3726
            $infNF,
3727
            'mod',
3728
            $std->mod,
3729
            true,
3730
            $identificador . 'Modelo da Nota Fiscal'
3731
        );
3732
        $this->dom->addChild(
3733
            $infNF,
3734
            'serie',
3735
            $std->serie,
3736
            true,
3737
            $identificador . 'Série'
3738
        );
3739
        $this->dom->addChild(
3740
            $infNF,
3741
            'nDoc',
3742
            $std->nDoc,
3743
            true,
3744
            $identificador . 'Número'
3745
        );
3746
        $this->dom->addChild(
3747
            $infNF,
3748
            'dEmi',
3749
            $std->dEmi,
3750
            true,
3751
            $identificador . 'Data de Emissão'
3752
        );
3753
        $this->dom->addChild(
3754
            $infNF,
3755
            'vBC',
3756
            $std->vBC,
3757
            true,
3758
            $identificador . 'Valor da Base de Cálculo do ICMS'
3759
        );
3760
        $this->dom->addChild(
3761
            $infNF,
3762
            'vICMS',
3763
            $std->vICMS,
3764
            true,
3765
            $identificador . 'Valor Totaldo ICMS'
3766
        );
3767
        $this->dom->addChild(
3768
            $infNF,
3769
            'vBCST',
3770
            $std->vBCST,
3771
            true,
3772
            $identificador . 'Valor da Base de Cálculo do ICMS ST'
3773
        );
3774
        $this->dom->addChild(
3775
            $infNF,
3776
            'vST',
3777
            $std->vST,
3778
            true,
3779
            $identificador . 'Valor Total do ICMS ST'
3780
        );
3781
        $this->dom->addChild(
3782
            $infNF,
3783
            'vProd',
3784
            $std->vProd,
3785
            true,
3786
            $identificador . 'Valor Total dos Produtos'
3787
        );
3788
        $this->dom->addChild(
3789
            $infNF,
3790
            'vNF',
3791
            $std->vNF,
3792
            true,
3793
            $identificador . 'Valor Total da NF'
3794
        );
3795
        $this->dom->addChild(
3796
            $infNF,
3797
            'nCFOP',
3798
            $std->nCFOP,
3799
            true,
3800
            $identificador . 'CFOP Predominante'
3801
        );
3802
        $this->dom->addChild(
3803
            $infNF,
3804
            'nPeso',
3805
            $std->nPeso,
3806
            false,
3807
            $identificador . 'Peso total em Kg'
3808
        );
3809
        $this->dom->addChild(
3810
            $infNF,
3811
            'PIN',
3812
            $std->PIN,
3813
            false,
3814
            $identificador . 'PIN SUFRAMA'
3815
        );
3816
        $this->dom->addChild(
3817
            $infNF,
3818
            'dPrev',
3819
            $std->dPrev,
3820
            false,
3821
            $identificador . 'Data prevista de entrega'
3822
        );
3823
        if ($std->infUnidCarga) {
3824
            foreach ($std->infUnidCarga as $value) {
3825
                $this->dom->appChild($infNF, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
3826
            }
3827
        }
3828
        if ($std->infUnidTransp) {
3829
            foreach ($std->infUnidTransp as $value) {
3830
                $this->dom->appChild($infNF, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
3831
            }
3832
        }
3833
        $this->infNF[] = $infNF;
3834
        return $infNF;
3835
    }
3836
3837
    /**
3838
     * Gera as tags para o elemento: "infNFe" (Informações das NF-e)
3839
     * #297
3840
     * Nível: 3
3841
     * @return mixed
3842
     */
3843
    public function taginfNFe($std)
3844
    {
3845
3846
        $possible = [
3847
            'chave',
3848
            'PIN',
3849
            'dPrev',
3850
            'infUnidCarga',
3851
            'infUnidTransp'
3852
        ];
3853
        $this->taginfDoc();
3854
        $std = $this->equilizeParameters($std, $possible);
3855
3856
        $identificador = '#297 <infNFe> - ';
3857
        $infNFe = $this->dom->createElement('infNFe');
3858
        $this->dom->addChild(
3859
            $infNFe,
3860
            'chave',
3861
            $std->chave,
3862
            true,
3863
            $identificador . 'Chave de acesso da NF-e'
3864
        );
3865
        $this->dom->addChild(
3866
            $infNFe,
3867
            'PIN',
3868
            $std->PIN,
3869
            false,
3870
            $identificador . 'PIN SUFRAMA'
3871
        );
3872
        $this->dom->addChild(
3873
            $infNFe,
3874
            'dPrev',
3875
            $std->dPrev,
3876
            false,
3877
            $identificador . 'Data prevista de entrega'
3878
        );
3879
        if ($std->infUnidCarga) {
3880
            foreach ($std->infUnidCarga as $value) {
3881
                $this->dom->appChild($infNFe, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
3882
            }
3883
        }
3884
        if ($std->infUnidTransp) {
3885
            foreach ($std->infUnidTransp as $value) {
3886
                $this->dom->appChild($infNFe, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
3887
            }
3888
        }
3889
        $this->infNFe[] = $infNFe;
3890
        return $infNFe;
3891
    }
3892
3893
    /**
3894
     * Gera as tags para o elemento: "infOutros" (Informações dos demais documentos)
3895
     * #319
3896
     * Nível: 3
3897
     * @return mixed
3898
     */
3899
    public function taginfOutros($std)
3900
    {
3901
3902
        $possible = [
3903
            'tpDoc',
3904
            'descOutros',
3905
            'nDoc',
3906
            'dEmi',
3907
            'vDocFisc',
3908
            'dPrev',
3909
            'infUnidCarga',
3910
            'infUnidTransp'
3911
        ];
3912
        $this->taginfDoc();
3913
        $std = $this->equilizeParameters($std, $possible);
3914
3915
        $ident = '#319 <infOutros> - ';
3916
        $infOutros = $this->dom->createElement('infOutros');
3917
        $this->dom->addChild(
3918
            $infOutros,
3919
            'tpDoc',
3920
            $std->tpDoc,
3921
            true,
3922
            $ident . 'Tipo de documento originário'
3923
        );
3924
        $this->dom->addChild(
3925
            $infOutros,
3926
            'descOutros',
3927
            $std->descOutros,
3928
            false,
3929
            $ident . 'Descrição do documento'
3930
        );
3931
        $this->dom->addChild(
3932
            $infOutros,
3933
            'nDoc',
3934
            $std->nDoc,
3935
            false,
3936
            $ident . 'Número do documento'
3937
        );
3938
        $this->dom->addChild(
3939
            $infOutros,
3940
            'dEmi',
3941
            $std->dEmi,
3942
            false,
3943
            $ident . 'Data de Emissão'
3944
        );
3945
        $this->dom->addChild(
3946
            $infOutros,
3947
            'vDocFisc',
3948
            $std->vDocFisc,
3949
            false,
3950
            $ident . 'Valor do documento'
3951
        );
3952
        $this->dom->addChild(
3953
            $infOutros,
3954
            'dPrev',
3955
            $std->dPrev,
3956
            false,
3957
            $ident . 'Data ista de entrega'
3958
        );
3959
        if ($std->infUnidCarga) {
3960
            foreach ($std->infUnidCarga as $value) {
3961
                $this->dom->appChild($infOutros, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
3962
            }
3963
        }
3964
        if ($std->infUnidTransp) {
3965
            foreach ($std->infUnidTransp as $value) {
3966
                $this->dom->appChild($infOutros, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
3967
            }
3968
        }
3969
        $this->infOutros[] = $infOutros;
3970
        return $infOutros;
3971
    }
3972
3973
    /**
3974
     * taginfUnidCarga
3975
     * tag CTe/infCte/infDoc/(infNF/infNFe/infOutros)/infUnidCarga
3976
     *
3977
     * @param stdClass $std
3978
     * @return DOMElement
3979
     */
3980
    private function taginfUnidCarga(stdClass $std)
3981
    {
3982
        $possible = [
3983
            'tpUnidCarga',
3984
            'idUnidCarga',
3985
            'lacUnidCarga',
3986
            'qtdRat'
3987
        ];
3988
        $std = $this->equilizeParameters($std, $possible);
3989
        $infUnidCarga = $this->dom->createElement("infUnidCarga");
3990
        $this->dom->addChild(
3991
            $infUnidCarga,
3992
            "tpUnidCarga",
3993
            $std->tpUnidCarga,
3994
            false,
3995
            "Tipo da Unidade de Carga"
3996
        );
3997
        $this->dom->addChild(
3998
            $infUnidCarga,
3999
            "idUnidCarga",
4000
            $std->idUnidCarga,
4001
            false,
4002
            "Identificação da Unidade de Carga "
4003
        );
4004
        if ($std->lacUnidCarga != null) {
4005
            $possible = [
4006
                'nLacre'
4007
            ];
4008
            $stdlacUnidCarga = $this->equilizeParameters($std->lacUnidCarga, $possible);
4009
            foreach ($stdlacUnidCarga->nLacre as $nLacre) {
4010
                $lacUnidCarga = $this->dom->createElement("lacUnidCarga");
4011
                $this->dom->addChild(
4012
                    $lacUnidCarga,
4013
                    "nLacre",
4014
                    $nLacre,
4015
                    true,
4016
                    "Número do lacre"
4017
                );
4018
                $this->dom->appChild($infUnidCarga, $lacUnidCarga, 'Falta tag "infUnidCarga"');
4019
            }
4020
        }
4021
        $this->dom->addChild(
4022
            $infUnidCarga,
4023
            "qtdRat",
4024
            $std->qtdRat,
4025
            false,
4026
            "Quantidade rateada (Peso,Volume)"
4027
        );
4028
        return $infUnidCarga;
4029
    }
4030
4031
    /**
4032
     * taginfUnidTransp
4033
     * tag CTe/infCte/infDoc/(infNF/infNFe/infOutros)/infUnidTransp
4034
     *
4035
     * @param stdClass $std
4036
     * @return DOMElement
4037
     */
4038
    private function taginfUnidTransp(stdClass $std)
4039
    {
4040
        $possible = [
4041
            'tpUnidTransp',
4042
            'idUnidTransp',
4043
            'qtdRat',
4044
            'lacUnidTransp',
4045
            'infUnidCarga'
4046
        ];
4047
        $std = $this->equilizeParameters($std, $possible);
4048
        $infUnidTransp = $this->dom->createElement("infUnidTransp");
4049
        $this->dom->addChild(
4050
            $infUnidTransp,
4051
            "tpUnidTransp",
4052
            $std->tpUnidTransp,
4053
            true,
4054
            "Tipo da Unidade de Transporte"
4055
        );
4056
        $this->dom->addChild(
4057
            $infUnidTransp,
4058
            "idUnidTransp",
4059
            $std->idUnidTransp,
4060
            false,
4061
            "Identificação da Unidade de Transporte"
4062
        );
4063
        if ($std->lacUnidTransp != null) {
4064
            $possible = [
4065
                'nLacre'
4066
            ];
4067
            $stdlacUnidTransp = $this->equilizeParameters($std->lacUnidTransp, $possible);
4068
            foreach ($stdlacUnidTransp->nLacre as $nLacre) {
4069
                $lacUnidTransp = $this->dom->createElement("lacUnidTransp");
4070
                $this->dom->addChild(
4071
                    $lacUnidTransp,
4072
                    "nLacre",
4073
                    $nLacre,
4074
                    true,
4075
                    "Número do lacre"
4076
                );
4077
                $this->dom->appChild($infUnidTransp, $lacUnidTransp, 'Falta tag "infUnidTransp"');
4078
            }
4079
        }
4080
        if ($std->infUnidCarga) {
4081
            foreach ($std->infUnidCarga as $value) {
4082
                $this->dom->appChild($infUnidTransp, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
4083
            }
4084
        }
4085
        $this->dom->addChild(
4086
            $infUnidTransp,
4087
            "qtdRat",
4088
            $std->qtdRat,
4089
            false,
4090
            "Quantidade rateada (Peso,Volume) "
4091
        );
4092
        return $infUnidTransp;
4093
    }
4094
4095
    /**
4096
     * Gera as tags para o elemento: "infDocRef" (Informações dos demais documentos)
4097
     * #319
4098
     * Nível: 3
4099
     * @return mixed
4100
     */
4101
    public function taginfDocRef($std)
4102
    {
4103
4104
        $possible = [
4105
            'nDoc',
4106
            'serie',
4107
            'subserie',
4108
            'dEmi',
4109
            'vDoc'
4110
        ];
4111
4112
        $std = $this->equilizeParameters($std, $possible);
4113
4114
        $ident = '#319 <infDocRef> - ';
4115
        $this->infDocRef[] = $this->dom->createElement('infDocRef');
4116
        $posicao = (int)count($this->infDocRef) - 1;
4117
        $this->dom->addChild(
4118
            $this->infDocRef[$posicao],
4119
            'nDoc',
4120
            $std->nDoc,
4121
            false,
4122
            $ident . 'Número do documento'
4123
        );
4124
        $this->dom->addChild(
4125
            $this->infDocRef[$posicao],
4126
            'serie',
4127
            $std->serie,
4128
            false,
4129
            $ident . 'Série do documento'
4130
        );
4131
        $this->dom->addChild(
4132
            $this->infDocRef[$posicao],
4133
            'subserie',
4134
            $std->subserie,
4135
            false,
4136
            $ident . 'Subserie do documento'
4137
        );
4138
        $this->dom->addChild(
4139
            $this->infDocRef[$posicao],
4140
            'dEmi',
4141
            $std->dEmi,
4142
            false,
4143
            $ident . 'Data de Emissão'
4144
        );
4145
        $this->dom->addChild(
4146
            $this->infDocRef[$posicao],
4147
            'vDoc',
4148
            $std->vDoc,
4149
            false,
4150
            $ident . 'Valor do documento'
4151
        );
4152
        return $this->infDocRef[$posicao];
4153
    }
4154
4155
    /**
4156
     * Gera as tags para o elemento: "emiDocAnt" (Informações dos CT-es Anteriores)
4157
     * #345
4158
     * Nível: 3
4159
     * @return mixed
4160
     */
4161
    public function tagemiDocAnt($std)
4162
    {
4163
4164
        $possible = [
4165
            'CNPJ',
4166
            'IE',
4167
            'UF',
4168
            'CPF',
4169
            'xNome'
4170
        ];
4171
4172
        $std = $this->equilizeParameters($std, $possible);
4173
4174
        $identificador = '#345 <emiDocAnt> - ';
4175
        $this->emiDocAnt[] = $this->dom->createElement('emiDocAnt');
4176
        $posicao = (int)count($this->emiDocAnt) - 1;
4177
        if ($std->CNPJ != '') {
4178
            $this->dom->addChild(
4179
                $this->emiDocAnt[$posicao],
4180
                'CNPJ',
4181
                $std->CNPJ,
4182
                true,
4183
                $identificador . 'Número do CNPJ'
4184
            );
4185
            $this->dom->addChild(
4186
                $this->emiDocAnt[$posicao],
4187
                'IE',
4188
                Strings::onlyNumbers($std->IE),
4189
                true,
4190
                $identificador . 'Inscrição Estadual'
4191
            );
4192
            $this->dom->addChild(
4193
                $this->emiDocAnt[$posicao],
4194
                'UF',
4195
                $std->UF,
4196
                true,
4197
                $identificador . 'Sigla da UF'
4198
            );
4199
        } else {
4200
            $this->dom->addChild(
4201
                $this->emiDocAnt[$posicao],
4202
                'CPF',
4203
                $std->CPF,
4204
                true,
4205
                $identificador . 'Número do CPF'
4206
            );
4207
        }
4208
        $this->dom->addChild(
4209
            $this->emiDocAnt[$posicao],
4210
            'xNome',
4211
            $std->xNome,
4212
            true,
4213
            $identificador . 'Razão Social ou Nome do Expedidor'
4214
        );
4215
        return $this->emiDocAnt[$posicao];
4216
    }
4217
4218
    /**
4219
     * Gera as tags para o elemento: "idDocAntEle" (Informações dos CT-es Anteriores)
4220
     * #348
4221
     * Nível: 4
4222
     * @return mixed
4223
     */
4224
    public function tagidDocAntEle($std)
4225
    {
4226
4227
        $possible = [
4228
            'chCTe'
4229
        ];
4230
4231
        $std = $this->equilizeParameters($std, $possible);
4232
4233
        $identificador = '#358 <idDocAntEle> - ';
4234
        $this->idDocAntEle[count($this->emiDocAnt) - 1][] = $this->dom->createElement('idDocAntEle');
4235
        $posicao = (int)count($this->idDocAntEle[count($this->emiDocAnt) - 1]) - 1;
4236
        $this->dom->addChild(
4237
            $this->idDocAntEle[count($this->emiDocAnt) - 1][$posicao],
4238
            'chCTe',
4239
            $std->chCTe,
4240
            true,
4241
            $identificador . 'Chave de Acesso do CT-e'
4242
        );
4243
        return $this->idDocAntEle[count($this->emiDocAnt) - 1][$posicao];
4244
    }
4245
4246
4247
    /**
4248
     * Gera as tags para o elemento: "seg" (Informações de Seguro da Carga)
4249
     * #360
4250
     * Nível: 2
4251
     * @return mixed
4252
     */
4253
    public function tagseg($std)
4254
    {
4255
4256
        $possible = [
4257
            'respSeg',
4258
            'xSeg',
4259
            'nApol'
4260
        ];
4261
4262
        $std = $this->equilizeParameters($std, $possible);
4263
4264
        $identificador = '#360 <seg> - ';
4265
        $this->seg[] = $this->dom->createElement('seg');
4266
        $posicao = (int)count($this->seg) - 1;
4267
        $this->dom->addChild(
4268
            $this->seg[$posicao],
4269
            'respSeg',
4270
            $std->respSeg,
4271
            true,
4272
            $identificador . 'Responsável pelo Seguro'
4273
        );
4274
        $this->dom->addChild(
4275
            $this->seg[$posicao],
4276
            'xSeg',
4277
            $std->xSeg,
4278
            false,
4279
            $identificador . 'Nome da Seguradora'
4280
        );
4281
        $this->dom->addChild(
4282
            $this->seg[$posicao],
4283
            'nApol',
4284
            $std->nApol,
4285
            false,
4286
            $identificador . 'Número da Apólice'
4287
        );
4288
        return $this->seg[$posicao];
4289
    }
4290
4291
    /**
4292
     * Gera as tags para o elemento: "idDocAntEle" (Informações dos CT-es Anteriores)
4293
     * #348
4294
     * Nível: 4
4295
     * @return mixed
4296
     */
4297
    public function tagidDocAntPap($std)
4298
    {
4299
4300
        $possible = [
4301
            'tpDoc',
4302
            'serie',
4303
            'subser',
4304
            'nDoc',
4305
            'dEmi'
4306
        ];
4307
4308
        $std = $this->equilizeParameters($std, $possible);
4309
4310
        $identificador = '#358 <idDocAntPap> - ';
4311
        $this->idDocAntPap[count($this->emiDocAnt) - 1][] = $this->dom->createElement('idDocAntPap');
4312
        $posicao = (int)count($this->idDocAntPap[count($this->emiDocAnt) - 1]) - 1;
4313
        $this->dom->addChild(
4314
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4315
            'tpDoc',
4316
            $std->tpDoc,
4317
            true,
4318
            $identificador . 'Tipo do Documento de Transporte Anterior'
4319
        );
4320
        $this->dom->addChild(
4321
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4322
            'serie',
4323
            $std->serie,
4324
            true,
4325
            $identificador . 'Série do Documento Fiscal'
4326
        );
4327
        $this->dom->addChild(
4328
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4329
            'subser',
4330
            $std->subser,
4331
            false,
4332
            $identificador . 'Série do Documento Fiscal'
4333
        );
4334
        $this->dom->addChild(
4335
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4336
            'nDoc',
4337
            $std->nDoc,
4338
            true,
4339
            $identificador . 'Número do Documento Fiscal'
4340
        );
4341
        $this->dom->addChild(
4342
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4343
            'dEmi',
4344
            $std->dEmi,
4345
            true,
4346
            $identificador . 'Data de emissão (AAAA-MM-DD)'
4347
        );
4348
        return $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao];
4349
    }
4350
4351
4352
    /**
4353
     * Gera as tags para o elemento: "infModal" (Informações do modal)
4354
     * #366
4355
     * Nível: 2
4356
     * @param string $versaoModal
0 ignored issues
show
Bug introduced by
There is no parameter named $versaoModal. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
4357
     * @return DOMElement|\DOMNode
4358
     */
4359
    public function taginfModal($std)
4360
    {
4361
        $this->infModal = $this->dom->createElement('infModal');
4362
        $this->infModal->setAttribute('versaoModal', $std->versaoModal);
4363
        return $this->infModal;
4364
    }
4365
4366
    /**
4367
     * Leiaute - Rodoviário
4368
     * Gera as tags para o elemento: "rodo" (Informações do modal Rodoviário)
4369
     * #1
4370
     * Nível: 0
4371
     * @return DOMElement|\DOMNode
4372
     */
4373
    public function tagrodo($std)
4374
    {
4375
4376
        $possible = [
4377
            'RNTRC'
4378
        ];
4379
4380
        $std = $this->equilizeParameters($std, $possible);
4381
4382
        $identificador = '#1 <rodo> - ';
4383
        $this->rodo = $this->dom->createElement('rodo');
4384
        $this->dom->addChild(
4385
            $this->rodo,
4386
            'RNTRC',
4387
            $std->RNTRC,
4388
            true,
4389
            $identificador . 'Registro nacional de transportadores
4390
            rodoviários de carga'
4391
        );
4392
        return $this->rodo;
4393
    }
4394
4395
    /**
4396
     * Leiaute - Dutoviário
4397
     * Gera as tags para o elemento: "duto" (informações do modal Dutoviário)
4398
     * @return DOMElement|\DOMNode
4399
     * @author Uilasmar Guedes
4400
     * #1
4401
     * Nivel: 0
4402
     */
4403
    public function tagduto($std)
4404
    {
4405
4406
        $possible = [
4407
            'vTar',
4408
            'dIni',
4409
            'dFim'
4410
        ];
4411
4412
        $std = $this->equilizeParameters($std, $possible);
4413
4414
        $identificador = '#1 <duto> - ';
4415
        $this->duto = $this->dom->createElement('duto');
4416
        $this->dom->addChild(
4417
            $this->duto,
4418
            'vTar',
4419
            $std->vTar,
4420
            false,
4421
            $identificador . 'Valor da tarifa '
4422
        );
4423
        $this->dom->addChild(
4424
            $this->duto,
4425
            'dIni',
4426
            $std->dIni,
4427
            true,
4428
            $identificador . 'Data de Início da prestação do serviço'
4429
        );
4430
        $this->dom->addChild(
4431
            $this->duto,
4432
            'dFim',
4433
            $std->dFim,
4434
            true,
4435
            $identificador . 'Data de Fim da prestação do serviço'
4436
        );
4437
        return $this->duto;
4438
    }
4439
4440
    /**
4441
     * Leiaute - Aquaviario
4442
     * Gera as tags para o elemento: "aquav" (informações do modal Aquaviario)
4443
     * @return DOMElement|\DOMNode
4444
     * @author Anderson Minuto Consoni Vaz
4445
     * #1
4446
     * Nivel: 0
4447
     */
4448
    public function tagaquav($std)
4449
    {
4450
4451
        $possible = [
4452
            'vPrest',
4453
            'vAFRMM',
4454
            'xNavio',
4455
            'nViag',
4456
            'direc',
4457
            'irin',
4458
            'tpNav'
4459
        ];
4460
4461
        $std = $this->equilizeParameters($std, $possible);
4462
4463
        $identificador = '#1 <aquav> - ';
4464
        $this->aquav = $this->dom->createElement('aquav');
4465
        $this->dom->addChild(
4466
            $this->aquav,
4467
            'vPrest',
4468
            $std->vPrest,
4469
            true,
4470
            $identificador . 'vPrest'
4471
        );
4472
        $this->dom->addChild(
4473
            $this->aquav,
4474
            'vAFRMM',
4475
            $std->vAFRMM,
4476
            true,
4477
            $identificador . 'vAFRMM'
4478
        );
4479
        $this->dom->addChild(
4480
            $this->aquav,
4481
            'xNavio',
4482
            $std->xNavio,
4483
            true,
4484
            $identificador . 'xNavio'
4485
        );
4486
        $this->dom->addChild(
4487
            $this->aquav,
4488
            'nViag',
4489
            $std->nViag,
4490
            true,
4491
            $identificador . 'nViag'
4492
        );
4493
        $this->dom->addChild(
4494
            $this->aquav,
4495
            'direc',
4496
            $std->direc,
4497
            true,
4498
            $identificador . 'direc'
4499
        );
4500
        $this->dom->addChild(
4501
            $this->aquav,
4502
            'irin',
4503
            $std->irin,
4504
            true,
4505
            $identificador . 'irin'
4506
        );
4507
        $this->dom->addChild(
4508
            $this->aquav,
4509
            'tpNav',
4510
            $std->tpNav,
4511
            false,
4512
            $identificador . 'tpNav'
4513
        );
4514
        return $this->aquav;
4515
    }
4516
4517
    /**
4518
     * Leiaute - Rodoviário
4519
     * Gera as tags para o elemento: "rodo" (Informações do modal Rodoviário) CT-e OS
4520
     * #1
4521
     * Nível: 0
4522
     * @return DOMElement|\DOMNode
4523
     */
4524
    public function tagrodoOS($std)
4525
    {
4526
4527
        $possible = [
4528
            'TAF',
4529
            'NroRegEstadual'
4530
        ];
4531
4532
        $std = $this->equilizeParameters($std, $possible);
4533
4534
        $identificador = '#1 <rodoOS> - ';
4535
        $this->rodo = $this->dom->createElement('rodoOS');
4536
        $this->dom->addChild(
4537
            $this->rodo,
4538
            'TAF',
4539
            $std->TAF,
4540
            false,
4541
            $identificador . 'Termo de Autorização de Fretamento - TAF'
4542
        );
4543
        $this->dom->addChild(
4544
            $this->rodo,
4545
            'NroRegEstadual',
4546
            $std->NroRegEstadual,
4547
            false,
4548
            $identificador . 'Número do Registro Estadual'
4549
        );
4550
        return $this->rodo;
4551
    }
4552
4553
    /**
4554
     * Leiaute - Aéreo
4555
     * Gera as tags para o elemento: "aereo" (Informações do modal Aéreo)
4556
     * @return DOMElement|\DOMNode
4557
     * @author Newton Pasqualini Filho
4558
     * #1
4559
     * Nível: 0
4560
     */
4561
    public function tagaereo($std)
4562
    {
4563
4564
        $possible = [
4565
            'nMinu',
4566
            'nOCA',
4567
            'dPrevAereo',
4568
            'natCarga_xDime',
4569
            'natCarga_cInfManu',
4570
            'tarifa_CL',
4571
            'tarifa_cTar',
4572
            'tarifa_vTar'
4573
        ];
4574
4575
        $std = $this->equilizeParameters($std, $possible);
4576
4577
        $identificador = '#1 <aereo> - ';
4578
        $this->aereo = $this->dom->createElement('aereo');
4579
        $this->dom->addChild(
4580
            $this->aereo,
4581
            'nMinu',
4582
            $std->nMinu,
4583
            false,
4584
            $identificador . 'Número da Minuta'
4585
        );
4586
        $this->dom->addChild(
4587
            $this->aereo,
4588
            'nOCA',
4589
            $std->nOCA,
4590
            false,
4591
            $identificador . 'Número Operacional do Conhecimento Aéreo'
4592
        );
4593
        $this->dom->addChild(
4594
            $this->aereo,
4595
            'dPrevAereo',
4596
            $std->dPrevAereo,
4597
            true,
4598
            $identificador . 'Data prevista da entrega'
4599
        );
4600
        if (isset($std->natCarga_xDime) || isset($std->natCarga_cInfManu)) {
4601
            $identificador = '#1 <aereo> - <natCarga> - ';
4602
            $natCarga = $this->dom->createElement('natCarga');
4603
            $this->dom->addChild(
4604
                $natCarga,
4605
                'xDime',
4606
                $std->natCarga_xDime,
4607
                false,
4608
                $identificador . 'Dimensões da carga, formato: 1234x1234x1234 (cm)'
4609
            );
4610
            if (isset($std->natCarga_cInfManu) && !is_array($std->natCarga_cInfManu)) {
4611
                $std->natCarga_cInfManu = [$std->natCarga_cInfManu];
4612
            }
4613
            $cInfManuX = 0;
4614
            foreach ($std->natCarga_cInfManu as $cInfManu) {
0 ignored issues
show
Bug introduced by
The expression $std->natCarga_cInfManu of type null|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
4615
                $cInfManuX++;
4616
                $this->dom->addChild(
4617
                    $natCarga,
4618
                    'cInfManu',
4619
                    $cInfManu,
4620
                    false,
4621
                    $identificador . 'Informação de manuseio, com dois dígitos, pode ter mais de uma ocorrência.'
4622
                );
4623
            }
4624
            $this->aereo->appendChild($natCarga);
4625
        }
4626
        $identificador = '#1 <aereo> - <tarifa> - ';
4627
        $tarifa = $this->dom->createElement('tarifa');
4628
        $this->dom->addChild(
4629
            $tarifa,
4630
            'CL',
4631
            $std->tarifa_CL,
4632
            true,
4633
            $identificador . 'Classe da tarifa: M - Tarifa Mínima / G - Tarifa Geral / E - Tarifa Específica'
4634
        );
4635
        $this->dom->addChild(
4636
            $tarifa,
4637
            'cTar',
4638
            $std->tarifa_cTar,
4639
            false,
4640
            $identificador . 'Código de três digítos correspondentes à tarifa.'
4641
        );
4642
        $this->dom->addChild(
4643
            $tarifa,
4644
            'vTar',
4645
            $std->tarifa_vTar,
4646
            true,
4647
            $identificador . 'Valor da tarifa. 15 posições, sendo 13 inteiras e 2 decimais.'
4648
        );
4649
        $this->aereo->appendChild($tarifa);
4650
        return $this->aereo;
4651
    }
4652
4653
    /**
4654
     * Leiaute - Aéreo
4655
     * Gera as tags para o elemento: "aereo" (Informações do modal Aéreo)
4656
     * #1
4657
     * Nível: 0
4658
     * @return DOMElement|\DOMNode
4659
     */
4660
    public function tagperi($std)
4661
    {
4662
4663
        $possible = [
4664
            'nONU',
4665
            'qTotEmb',
4666
            'qTotProd',
4667
            'uniAP'
4668
        ];
4669
4670
        $std = $this->equilizeParameters($std, $possible);
4671
4672
        $identificador = '#1 <aereo> - <peri> - ';
4673
        $peri = $this->dom->createElement('peri');
4674
        $this->dom->addChild(
4675
            $peri,
4676
            'nONU',
4677
            $std->nONU,
4678
            true,
4679
            $identificador . 'Número ONU/UN'
4680
        );
4681
        $this->dom->addChild(
4682
            $peri,
4683
            'qTotEmb',
4684
            $std->qTotEmb,
4685
            true,
4686
            $identificador . 'Quantidade total de volumes contendo artigos perigosos'
4687
        );
4688
        $identificador = '#1 <peri> - <infTotAP> - ';
4689
        $infTotAP = $this->dom->createElement('infTotAP');
4690
        $this->dom->addChild(
4691
            $infTotAP,
4692
            'qTotProd',
4693
            $std->qTotProd,
4694
            false,
4695
            $identificador . 'Quantidade total de artigos perigosos'
4696
        );
4697
        $this->dom->addChild(
4698
            $infTotAP,
4699
            'uniAP',
4700
            $std->uniAP,
4701
            true,
4702
            $identificador . 'Unidade de medida'
4703
        );
4704
        $peri->appendChild($infTotAP);
4705
        $this->peri[] = $peri;
4706
        return $peri;
4707
    }
4708
4709
    public function tagferrov($std)
4710
    {
4711
4712
        $possible = [
4713
            'tpTraf',
4714
            'respFat',
4715
            'ferrEmi',
4716
            'vFrete',
4717
            'chCTeFerroOrigem ',
4718
            'fluxo'
4719
        ];
4720
4721
        $std = $this->equilizeParameters($std, $possible);
4722
4723
        $identificador = '#1 <ferrov> - ';
4724
        $this->ferrov = $this->dom->createElement('ferrov');
4725
        $this->dom->addChild(
4726
            $this->ferrov,
4727
            'tpTraf',
4728
            $std->tpTraf,
4729
            true,
4730
            $identificador . 'Tipo de Tráfego'
4731
        );
4732
        $identificador = '#1 <ferrov> - <trafMut> - ';
4733
        $trafMut = $this->dom->createElement('trafMut');
4734
        $this->dom->addChild(
4735
            $trafMut,
4736
            'respFat',
4737
            $std->respFat,
4738
            true,
4739
            $identificador . 'Responsável pelo Faturamento'
4740
        );
4741
        $this->dom->addChild(
4742
            $trafMut,
4743
            'ferrEmi',
4744
            $std->ferrEmi,
4745
            true,
4746
            $identificador . 'Ferrovia Emitente do CTe'
4747
        );
4748
        $this->dom->addChild(
4749
            $trafMut,
4750
            'vFrete',
4751
            $std->vFrete,
4752
            true,
4753
            $identificador . 'Valor do Frete do Tráfego Mútuo '
4754
        );
4755
        $this->dom->addChild(
4756
            $trafMut,
4757
            'chCTeFerroOrigem',
4758
            $std->chCTeFerroOrigem,
4759
            false,
4760
            $identificador . 'Chave de acesso do CT-e emitido pelo ferrovia de origem'
4761
        );
4762
        $this->ferrov->appendChild($trafMut);
4763
        $this->dom->addChild(
4764
            $this->ferrov,
4765
            'fluxo',
4766
            $std->fluxo,
4767
            true,
4768
            $identificador . 'Fluxo Ferroviário '
4769
        );
4770
    }
4771
4772
    public function tagferroEnv($std)
4773
    {
4774
4775
        $possible = [
4776
            'CNPJ',
4777
            'cInt',
4778
            'IE',
4779
            'xNome',
4780
            'xLgr',
4781
            'nro',
4782
            'xCpl',
4783
            'xBairro',
4784
            'cMun',
4785
            'xMun',
4786
            'CEP',
4787
            'UF',
4788
            'fluxo'
4789
        ];
4790
4791
        $std = $this->equilizeParameters($std, $possible);
4792
4793
        $identificador = '#1 <trafMut> - <ferroEnv> - ';
4794
        $ferroEnv = $this->dom->createElement('ferroEnv');
4795
        $this->dom->addChild(
4796
            $ferroEnv,
4797
            'CNPJ',
4798
            $std->CNPJ,
4799
            true,
4800
            $identificador . 'Número do CNPJ'
4801
        );
4802
        $this->dom->addChild(
4803
            $ferroEnv,
4804
            'cInt',
4805
            $std->cInt,
4806
            false,
4807
            $identificador . 'Código interno da Ferrovia envolvida'
4808
        );
4809
        $this->dom->addChild(
4810
            $ferroEnv,
4811
            'IE',
4812
            $std->IE,
4813
            false,
4814
            $identificador . 'Inscrição Estadual'
4815
        );
4816
        $this->dom->addChild(
4817
            $ferroEnv,
4818
            'xNome',
4819
            $std->xNome,
4820
            false,
4821
            $identificador . 'Razão Social ou Nome'
4822
        );
4823
        $identificador = '#1 <ferroEnv> - <enderFerro> - ';
4824
        $enderFerro = $this->dom->createElement('enderFerro');
4825
        $this->dom->addChild(
4826
            $enderFerro,
4827
            'xLgr',
4828
            $std->xLgr,
4829
            true,
4830
            $identificador . 'Logradouro'
4831
        );
4832
        $this->dom->addChild(
4833
            $enderFerro,
4834
            'nro',
4835
            $std->nro,
4836
            false,
4837
            $identificador . 'Número'
4838
        );
4839
        $this->dom->addChild(
4840
            $enderFerro,
4841
            'xCpl',
4842
            $std->xCpl,
4843
            false,
4844
            $identificador . 'Complemento'
4845
        );
4846
        $this->dom->addChild(
4847
            $enderFerro,
4848
            'xBairro',
4849
            $std->xBairro,
4850
            false,
4851
            $identificador . 'Bairro'
4852
        );
4853
        $this->dom->addChild(
4854
            $enderFerro,
4855
            'cMun',
4856
            $std->cMun,
4857
            true,
4858
            $identificador . 'Código do município'
4859
        );
4860
        $this->dom->addChild(
4861
            $enderFerro,
4862
            'xMun',
4863
            $std->xMun,
4864
            true,
4865
            $identificador . 'Nome do município'
4866
        );
4867
        $this->dom->addChild(
4868
            $enderFerro,
4869
            'CEP',
4870
            $std->CEP,
4871
            true,
4872
            $identificador . 'CEP'
4873
        );
4874
        $this->dom->addChild(
4875
            $enderFerro,
4876
            'UF',
4877
            $std->UF,
4878
            true,
4879
            $identificador . 'Sigla da UF'
4880
        );
4881
        $ferroEnv->appendChild($enderFerro);
4882
        $this->ferroEnv[] = $ferroEnv;
4883
        return $ferroEnv;
4884
    }
4885
4886
    /**
4887
     * CT-e de substituição
4888
     * @return type
4889
     */
4890
    public function taginfCteSub($std)
4891
    {
4892
4893
        $possible = [
4894
            'chCte',
4895
            'refCteAnu'
4896
        ];
4897
4898
        $std = $this->equilizeParameters($std, $possible);
4899
4900
        $identificador = '#149 <infCteSub> - ';
4901
        $this->infCteSub = $this->dom->createElement('infCteSub');
4902
        $this->dom->addChild(
4903
            $this->infCteSub,
4904
            'chCte',
4905
            $std->chCte,
4906
            false,
4907
            "$identificador  Chave de acesso do CTe a ser substituído (original)"
4908
        );
4909
        $this->dom->addChild(
4910
            $this->infCteSub,
4911
            'refCteAnu',
4912
            $std->refCteAnu,
4913
            false,
4914
            "$identificador  Chave de acesso do CT-e de Anulação"
4915
        );
4916
        return $this->infCteSub;
4917
    }
4918
4919
    /**
4920
     * Informações do Serviço Vinculado a Multimodal
4921
     * @return type
4922
     */
4923
    public function infCTeMultimodal($std)
4924
    {
4925
        $possible = [
4926
            'chCTeMultimodal',
4927
        ];
4928
4929
        $std = $this->equilizeParameters($std, $possible);
4930
4931
        if (empty($this->infServVinc)) $this->infServVinc = $this->dom->createElement('infServVinc');
4932
4933
        $identificador = '#388 <infCTeMultimodal> - ';
4934
        $infCTeMultimodal = $this->dom->createElement('infCTeMultimodal');
4935
        $this->dom->addChild(
4936
            $infCTeMultimodal,
4937
            'chCTeMultimodal',
4938
            $std->chCTeMultimodal,
4939
            true,
4940
            $identificador . 'Chave de acesso do CT-e Multimodal '
4941
        );
4942
4943
        $this->infCTeMultimodal[] = $infCTeMultimodal;
4944
        return $infCTeMultimodal;
4945
    }
4946
4947
    /**
4948
     * CT-e de substituição - tomaICMS
4949
     * @param type $std
0 ignored issues
show
Bug introduced by
There is no parameter named $std. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
4950
     * @return type
4951
     */
4952
    public function tagtomaICMS()
4953
    {
4954
        $this->tomaICMS = $this->dom->createElement('tomaICMS');
4955
        return $this->tomaICMS;
4956
    }
4957
4958
    /**
4959
     * CT-e de substituição - NF-e
4960
     * @param type $std
4961
     * @return type
4962
     */
4963
    public function tagrefNFe($std)
4964
    {
4965
4966
        $possible = [
4967
            'refNFe'
4968
        ];
4969
4970
        $std = $this->equilizeParameters($std, $possible);
4971
4972
        if (empty($this->tomICMS)) {
0 ignored issues
show
Bug introduced by
The property tomICMS does not seem to exist. Did you mean tomaICMS?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
4973
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
4974
        }
4975
        $identificador = '#153 <refNFe> - ';
4976
        $this->dom->addChild(
4977
            $this->tomaICMS,
4978
            'refNFe',
4979
            $std->refNFe,
4980
            false,
4981
            "$identificador  Chave de acesso da NF-e emitida pelo tomador"
4982
        );
4983
4984
        return $this->tomaICMS;
4985
    }
4986
4987
    /**
4988
     * CT-e de substituição - NF
4989
     * @param type $std
4990
     * @return type
4991
     */
4992
    public function tagrefNF($std)
4993
    {
4994
4995
        $possible = [
4996
            'CNPJ',
4997
            'CPF',
4998
            'mod',
4999
            'serie',
5000
            'subserie',
5001
            'nro',
5002
            'valor',
5003
            'dEmi'
5004
        ];
5005
5006
        $std = $this->equilizeParameters($std, $possible);
5007
5008
        $identificador = '#154 <refNFe> - ';
5009
        if (empty($this->tomICMS)) {
0 ignored issues
show
Bug introduced by
The property tomICMS does not seem to exist. Did you mean tomaICMS?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
5010
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
5011
        }
5012
        $this->refNF = $this->dom->createElement('refNF');
5013
        if ($std->CNPJ != '') {
5014
            $this->dom->addChild(
5015
                $this->refNF,
5016
                'CNPJ',
5017
                $std->CNPJ,
5018
                true,
5019
                $identificador . 'CNPJ do emitente'
5020
            );
5021
        } elseif ($std->CPF != '') {
5022
            $this->dom->addChild(
5023
                $this->refNF,
5024
                'CPF',
5025
                $std->CPF,
5026
                true,
5027
                $identificador . 'CPF do emitente'
5028
            );
5029
        }
5030
        $this->dom->addChild(
5031
            $this->refNF,
5032
            'mod',
5033
            $std->mod,
5034
            false,
5035
            $identificador . 'Modelo'
5036
        );
5037
        $this->dom->addChild(
5038
            $this->refNF,
5039
            'serie',
5040
            $std->serie,
5041
            false,
5042
            $identificador . 'Série do documento'
5043
        );
5044
        $this->dom->addChild(
5045
            $this->refNF,
5046
            'subserie',
5047
            $std->subserie,
5048
            false,
5049
            $identificador . 'Subserie do documento'
5050
        );
5051
        $this->dom->addChild(
5052
            $this->refNF,
5053
            'nro',
5054
            $std->nro,
5055
            false,
5056
            $identificador . 'Número'
5057
        );
5058
        $this->dom->addChild(
5059
            $this->refNF,
5060
            'valor',
5061
            $std->valor,
5062
            false,
5063
            $identificador . 'Valor'
5064
        );
5065
        $this->dom->addChild(
5066
            $this->refNF,
5067
            'dEmi',
5068
            $std->dEmi,
5069
            false,
5070
            $identificador . 'Emissão'
5071
        );
5072
        $this->tomaICMS->appendChild($this->refNF);
5073
        return $this->tomaICMS;
5074
    }
5075
5076
    /**
5077
     * CT-e de substituição - CT-e
5078
     * @param type $std
5079
     * @return type
5080
     */
5081
    public function tagrefCTe($std)
5082
    {
5083
5084
        $possible = [
5085
            'refCte'
5086
        ];
5087
5088
        $std = $this->equilizeParameters($std, $possible);
5089
5090
        if (empty($this->tomICMS)) {
0 ignored issues
show
Bug introduced by
The property tomICMS does not seem to exist. Did you mean tomaICMS?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
5091
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
5092
        }
5093
        $identificador = '#163 <refCte> - ';
5094
        $this->dom->addChild(
5095
            $this->tomaICMS,
5096
            'refCte',
5097
            $std->refCte,
5098
            false,
5099
            "$identificador  Chave de acesso do CT-e emitida pelo tomador"
5100
        );
5101
5102
        return $this->tomaICMS;
5103
    }
5104
5105
    /**
5106
     * Leiaute - Rodoviário
5107
     * Gera as tags para o elemento: "veic" (Dados dos Veículos)
5108
     * #21
5109
     * Nível: 1
5110
     * @return mixed
5111
     */
5112
    public function tagveicCTeOS($std)
5113
    {
5114
5115
        $possible = [
5116
            'placa',
5117
            'RENAVAM',
5118
            'CNPJ',
5119
            'CPF',
5120
            'TAF',
5121
            'NroRegEstadual',
5122
            'xNome',
5123
            'IE',
5124
            'ufProp',
5125
            'tpProp',
5126
            'uf'
5127
        ];
5128
5129
        $std = $this->equilizeParameters($std, $possible);
5130
5131
        $identificador = '#21 <veic> - ';
5132
        $this->veic = $this->dom->createElement('veic');
5133
        $this->dom->addChild(
5134
            $this->veic,
5135
            'placa',
5136
            $std->placa,
5137
            false,
5138
            $identificador . 'Placa do veículo'
5139
        );
5140
        $this->dom->addChild(
5141
            $this->veic,
5142
            'RENAVAM',
5143
            $std->RENAVAM,
5144
            false,
5145
            $identificador . 'RENAVAM do veículo'
5146
        );
5147
        if ($std->xNome != '') { // CASO FOR VEICULO DE TERCEIRO
5148
            $this->prop = $this->dom->createElement('prop');
5149
            if ($std->CNPJ != '') {
5150
                $this->dom->addChild(
5151
                    $this->prop,
5152
                    'CNPJ',
5153
                    $std->CNPJ,
5154
                    true,
5155
                    $identificador . 'CNPJ do proprietario'
5156
                );
5157
            } elseif ($std->CPF != '') {
5158
                $this->dom->addChild(
5159
                    $this->prop,
5160
                    'CPF',
5161
                    $std->CPF,
5162
                    true,
5163
                    $identificador . 'CPF do proprietario'
5164
                );
5165
            }
5166
            if ($std->taf != '') {
5167
                $this->dom->addChild(
5168
                    $this->prop,
5169
                    'TAF',
5170
                    $std->taf,
5171
                    false,
5172
                    $identificador . 'TAF'
5173
                );
5174
            } else {
5175
                $this->dom->addChild(
5176
                    $this->prop,
5177
                    'NroRegEstadual',
5178
                    $std->nroRegEstadual,
5179
                    false,
5180
                    $identificador . 'Número do Registro Estadual'
5181
                );
5182
            }
5183
            $this->dom->addChild(
5184
                $this->prop,
5185
                'xNome',
5186
                $std->xNome,
5187
                true,
5188
                $identificador . 'Nome do proprietario'
5189
            );
5190
            $this->dom->addChild(
5191
                $this->prop,
5192
                'IE',
5193
                Strings::onlyNumbers($std->IE),
5194
                false,
5195
                $identificador . 'IE do proprietario'
5196
            );
5197
            $this->dom->addChild(
5198
                $this->prop,
5199
                'UF',
5200
                $std->ufProp,
5201
                true,
5202
                $identificador . 'UF do proprietario'
5203
            );
5204
            $this->dom->addChild(
5205
                $this->prop,
5206
                'tpProp',
5207
                $std->tpProp,
5208
                true,
5209
                $identificador . 'Tipo Proprietário'
5210
            );
5211
            $this->dom->appChild($this->veic, $this->prop, 'Falta tag "prop"');
5212
        }
5213
        $this->dom->addChild(
5214
            $this->veic,
5215
            'UF',
5216
            $std->uf,
5217
            true,
5218
            $identificador . 'UF em que veículo está licenciado'
5219
        );
5220
        return $this->veic;
5221
    }
5222
5223
    public function infFretamento($std)
5224
    {
5225
5226
        $possible = [
5227
            'tpFretamento',
5228
            'dhViagem'
5229
        ];
5230
5231
        $std = $this->equilizeParameters($std, $possible);
5232
5233
        $identificador = '#21 <infFretamento> - ';
5234
        $this->infFretamento = $this->dom->createElement('infFretamento');
5235
        $this->dom->addChild(
5236
            $this->infFretamento,
5237
            'tpFretamento',
5238
            $std->tpFretamento,
5239
            true,
5240
            $identificador . 'Tipo do Fretamento de Pessoas'
5241
        );
5242
        $this->dom->addChild(
5243
            $this->infFretamento,
5244
            'dhViagem',
5245
            $std->dhViagem,
5246
            false,
5247
            $identificador . 'Data e hora da viagem'
5248
        );
5249
        return $this->infFretamento;
5250
    }
5251
5252
    /**
5253
     * Gera as tags para o elemento: "infCteComp" (Detalhamento do CT-e complementado)
5254
     * #410
5255
     * Nível: 1
5256
     * @return DOMElement|\DOMNode
5257
     */
5258
    public function taginfCTeComp($std)
5259
    {
5260
5261
        $possible = [
5262
            'chCTe'
5263
        ];
5264
5265
        $std = $this->equilizeParameters($std, $possible);
5266
5267
        $identificador = '#410 <infCteComp> - ';
5268
        $this->infCteComp = $this->dom->createElement('infCteComp');
5269
        $this->dom->addChild(
5270
            $this->infCteComp,
5271
            'chCTe',
5272
            $std->chCTe,
5273
            true,
5274
            $identificador . ' Chave do CT-e complementado'
5275
        );
5276
        return $this->infCteComp;
5277
    }
5278
5279
    /**
5280
     * Gera as tags para o elemento: "infCteAnu" (Detalhamento do CT-e de Anulação)
5281
     * #411
5282
     * Nível: 1
5283
     * @return DOMElement|\DOMNode
5284
     */
5285
    public function taginfCteAnu($std)
5286
    {
5287
5288
        $possible = [
5289
            'chave',
5290
            'dEmi'
5291
        ];
5292
5293
        $std = $this->equilizeParameters($std, $possible);
5294
5295
        $identificador = '#411 <infCteAnu> - ';
5296
        $this->infCteAnu = $this->dom->createElement('infCteAnu');
5297
        $this->dom->addChild(
5298
            $this->infCteAnu,
5299
            'chCte',
5300
            $std->chave,
5301
            true,
5302
            $identificador . ' Chave do CT-e anulado'
5303
        );
5304
        $this->dom->addChild(
5305
            $this->infCteAnu,
5306
            'dEmi',
5307
            $std->data,
5308
            true,
5309
            $identificador . ' Data de Emissão do CT-e anulado'
5310
        );
5311
        return $this->infCteAnu;
5312
    }
5313
5314
    /**
5315
     * Gera as tags para o elemento: "autXML" (Autorizados para download do XML)
5316
     * #396
5317
     * Nível: 1
5318
     * Os parâmetros para esta função são todos os elementos da tag "autXML"
5319
     *
5320
     * @return boolean
5321
     */
5322
    public function tagveicNovos($std)
5323
    {
5324
5325
        $possible = [
5326
            'chassi',
5327
            'cCor',
5328
            'xCor',
5329
            'cMod',
5330
            'vUnit',
5331
            'vFrete'
5332
        ];
5333
5334
        $std = $this->equilizeParameters($std, $possible);
5335
5336
        $identificador = '#396 <veicNovos> - ';
5337
        $veicNovos = $this->dom->createElement('veicNovos');
5338
        $this->dom->addChild(
5339
            $veicNovos,
5340
            'chassi',
5341
            $std->chassi,
5342
            true,
5343
            $identificador . 'Chassi do veículo '
5344
        );
5345
        $this->dom->addChild(
5346
            $veicNovos,
5347
            'cCor',
5348
            $std->cCor,
5349
            true,
5350
            $identificador . 'Cor do veículo '
5351
        );
5352
        $this->dom->addChild(
5353
            $veicNovos,
5354
            'xCor',
5355
            $std->xCor,
5356
            true,
5357
            $identificador . 'Descrição da cor '
5358
        );
5359
        $this->dom->addChild(
5360
            $veicNovos,
5361
            'cMod',
5362
            $std->cMod,
5363
            true,
5364
            $identificador . 'Código Marca Modelo '
5365
        );
5366
        $this->dom->addChild(
5367
            $veicNovos,
5368
            'vUnit',
5369
            $std->vUnit,
5370
            true,
5371
            $identificador . 'Valor Unitário do Veículo '
5372
        );
5373
        $this->dom->addChild(
5374
            $veicNovos,
5375
            'vFrete',
5376
            $std->vFrete,
5377
            true,
5378
            $identificador . 'Frete Unitário '
5379
        );
5380
        $this->veicNovos[] = $veicNovos;
5381
        return $veicNovos;
5382
    }
5383
5384
    /**
5385
     * Gera as tags para o elemento: "autXML" (Autorizados para download do XML)
5386
     * #396
5387
     * Nível: 1
5388
     * Os parâmetros para esta função são todos os elementos da tag "autXML"
5389
     *
5390
     * @return boolean
5391
     */
5392
    public function tagautXML($std)
5393
    {
5394
5395
        $possible = [
5396
            'CNPJ',
5397
            'CPF'
5398
        ];
5399
5400
        $std = $this->equilizeParameters($std, $possible);
5401
5402
        $identificador = '#396 <autXML> - ';
5403
        $autXML = $this->dom->createElement('autXML');
5404
        if (isset($std->CNPJ) && $std->CNPJ != '') {
5405
            $this->dom->addChild(
5406
                $autXML,
5407
                'CNPJ',
5408
                $std->CNPJ,
5409
                true,
5410
                $identificador . 'CNPJ do Cliente Autorizado'
5411
            );
5412
        } elseif (isset($std->CPF) && $std->CPF != '') {
5413
            $this->dom->addChild(
5414
                $autXML,
5415
                'CPF',
5416
                $std->CPF,
5417
                true,
5418
                $identificador . 'CPF do Cliente Autorizado'
5419
            );
5420
        }
5421
        $this->autXML[] = $autXML;
5422
        return $autXML;
5423
    }
5424
5425
    /**
5426
     * #359
5427
     * tag CTe/infCTe/cobr (opcional)
5428
     * Depende de fat
5429
     */
5430
    protected function buildCobr()
5431
    {
5432
        if (empty($this->cobr)) {
5433
            $this->cobr = $this->dom->createElement("cobr");
5434
        }
5435
    }
5436
5437
    /**
5438
     * #360
5439
     * tag CTe/infCTe/cobr/fat (opcional)
5440
     * @param stdClass $std
5441
     * @return DOMElement
5442
     */
5443
    public function tagfat(stdClass $std)
5444
    {
5445
5446
        $possible = [
5447
            'nFat',
5448
            'vOrig',
5449
            'vDesc',
5450
            'vLiq'
5451
        ];
5452
5453
        $std = $this->equilizeParameters($std, $possible);
5454
5455
        $this->buildCobr();
5456
        $fat = $this->dom->createElement("fat");
5457
        $this->dom->addChild(
5458
            $fat,
5459
            "nFat",
5460
            $std->nFat,
5461
            false,
5462
            "Número da Fatura"
5463
        );
5464
        $this->dom->addChild(
5465
            $fat,
5466
            "vOrig",
5467
            $std->vOrig,
5468
            false,
5469
            "Valor Original da Fatura"
5470
        );
5471
        if ($std->vDesc > 0) {
5472
            $this->dom->addChild(
5473
                $fat,
5474
                "vDesc",
5475
                $std->vDesc,
5476
                false,
5477
                "Valor do desconto"
5478
            );
5479
        }
5480
        $this->dom->addChild(
5481
            $fat,
5482
            "vLiq",
5483
            $std->vLiq,
5484
            false,
5485
            "Valor Líquido da Fatura"
5486
        );
5487
        $this->dom->appChild($this->cobr, $fat);
5488
        return $fat;
5489
    }
5490
5491
    /**
5492
     * #365
5493
     * tag CTe/infCTe/cobr/fat/dup (opcional)
5494
     * É necessário criar a tag fat antes de criar as duplicatas
5495
     * @param stdClass $std
5496
     * @return DOMElement
5497
     */
5498
    public function tagdup(stdClass $std)
5499
    {
5500
5501
        $possible = [
5502
            'nDup',
5503
            'dVenc',
5504
            'vDup'
5505
        ];
5506
5507
        $std = $this->equilizeParameters($std, $possible);
5508
5509
        $this->buildCobr();
5510
        $dup = $this->dom->createElement("dup");
5511
        $this->dom->addChild(
5512
            $dup,
5513
            "nDup",
5514
            $std->nDup,
5515
            false,
5516
            "Número da Duplicata"
5517
        );
5518
        $this->dom->addChild(
5519
            $dup,
5520
            "dVenc",
5521
            $std->dVenc,
5522
            false,
5523
            "Data de vencimento"
5524
        );
5525
        $this->dom->addChild(
5526
            $dup,
5527
            "vDup",
5528
            $std->vDup,
5529
            true,
5530
            "Valor da duplicata"
5531
        );
5532
        $this->dom->appChild($this->cobr, $dup, 'Inclui duplicata na tag cobr');
5533
        return $dup;
5534
    }
5535
5536
    /**
5537
     * Informações do Responsável técnico
5538
     * tag CTe/infCte/infRespTec (opcional)
5539
     * @return DOMElement
5540
     * @throws RuntimeException
5541
     */
5542
    public function taginfRespTec(stdClass $std)
5543
    {
5544
5545
        $possible = [
5546
            'CNPJ',
5547
            'xContato',
5548
            'email',
5549
            'fone',
5550
            'idCSRT',
5551
            'CSRT'
5552
        ];
5553
5554
        $std = $this->equilizeParameters($std, $possible);
5555
5556
        $infRespTec = $this->dom->createElement("infRespTec");
5557
        $this->dom->addChild(
5558
            $infRespTec,
5559
            "CNPJ",
5560
            $std->CNPJ,
5561
            true,
5562
            "Informar o CNPJ da pessoa jurídica responsável pelo sistema "
5563
            . "utilizado na emissão do documento fiscal eletrônico"
5564
        );
5565
        $this->dom->addChild(
5566
            $infRespTec,
5567
            "xContato",
5568
            $std->xContato,
5569
            true,
5570
            "Informar o nome da pessoa a ser contatada na empresa desenvolvedora "
5571
            . "do sistema utilizado na emissão do documento fiscal eletrônico"
5572
        );
5573
        $this->dom->addChild(
5574
            $infRespTec,
5575
            "email",
5576
            $std->email,
5577
            true,
5578
            "Informar o e-mail da pessoa a ser contatada na empresa "
5579
            . "desenvolvedora do sistema."
5580
        );
5581
        $this->dom->addChild(
5582
            $infRespTec,
5583
            "fone",
5584
            $std->fone,
5585
            true,
5586
            "Informar o telefone da pessoa a ser contatada na empresa "
5587
            . "desenvolvedora do sistema."
5588
        );
5589
        if (!empty($std->CSRT) && !empty($std->idCSRT)) {
5590
            $this->csrt = $std->CSRT;
0 ignored issues
show
Bug introduced by
The property csrt does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
5591
            $this->dom->addChild(
5592
                $infRespTec,
5593
                "idCSRT",
5594
                $std->idCSRT,
5595
                true,
5596
                "Identificador do CSRT utilizado para montar o hash do CSRT"
5597
            );
5598
            $this->dom->addChild(
5599
                $infRespTec,
5600
                "hashCSRT",
5601
                $this->hashCSRT($std->CSRT),
0 ignored issues
show
Bug introduced by
The method hashCSRT() does not seem to exist on object<NFePHP\CTe\Make>.

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

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

Loading history...
5602
                true,
5603
                "hash do CSRT"
5604
            );
5605
        }
5606
        $this->infRespTec = $infRespTec;
5607
        return $infRespTec;
5608
    }
5609
5610
    protected function checkCTeKey(Dom $dom)
5611
    {
5612
        $infCTe = $dom->getElementsByTagName("infCte")->item(0);
5613
        $ide = $dom->getElementsByTagName("ide")->item(0);
5614
        $emit = $dom->getElementsByTagName("emit")->item(0);
5615
        $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue;
5616
        $dhEmi = $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue;
5617
        $cnpj = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
5618
        $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue;
5619
        $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
5620
        $nNF = $ide->getElementsByTagName('nCT')->item(0)->nodeValue;
5621
        $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue;
5622
        $cCT = $ide->getElementsByTagName('cCT')->item(0)->nodeValue;
5623
        $chave = str_replace('CTe', '', $infCTe->getAttribute("Id"));
5624
5625
        $dt = new \DateTime($dhEmi);
5626
5627
        $chaveMontada = Keys::build(
5628
            $cUF,
5629
            $dt->format('y'),
5630
            $dt->format('m'),
5631
            $cnpj,
5632
            $mod,
5633
            $serie,
5634
            $nNF,
5635
            $tpEmis,
5636
            $cCT
5637
        );
5638
        //caso a chave contida no CTe esteja errada
5639
        //substituir a chave
5640
        if ($chaveMontada != $chave) {
5641
            $ide->getElementsByTagName('cDV')->item(0)->nodeValue = substr($chaveMontada, -1);
5642
            $infCTe = $dom->getElementsByTagName("infCte")->item(0);
5643
            $infCTe->setAttribute("Id", "CTe" . $chaveMontada);
5644
            $this->chCTe = $chaveMontada;
5645
        }
5646
    }
5647
    
5648
    /**
5649
     * Retorna os erros detectados
5650
     * @return array
5651
     */
5652
    public function getErrors()
5653
    {
5654
        return $this->errors;
5655
    }
5656
5657
    /**
5658
     * Includes missing or unsupported properties in stdClass
5659
     * Replace all unsuported chars
5660
     *
5661
     * @param stdClass $std
5662
     * @param array $possible
5663
     * @return stdClass
5664
     */
5665
    private function equilizeParameters(stdClass $std, $possible)
5666
    {
5667
        return Strings::equilizeParameters($std, $possible, $this->replaceAccentedChars);
5668
    }
5669
}
5670