Passed
Push — master ( ab6fce...a68b26 )
by
unknown
02:00 queued 15s
created

Make::montaCTe()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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
     * Tomador é contribuinte do ICMS
378
     * @var \DOMNode
379
     */
380
    private $tomaICMS = '';
381
    /**
382
     * Informação da NFe emitida pelo Tomador
383
     * @var \DOMNode
384
     */
385
    private $refNFe = '';
386
    /**
387
     * Informação da NF ou CT emitido pelo Tomador
388
     * @var \DOMNode
389
     */
390
    private $refNF = '';
391
    /**
392
     * Informação da NF ou CT emitido pelo Tomador
393
     * @var \DOMNode
394
     */
395
    private $infCteComp = '';
396
    /**
397
     * Detalhamento do CT-e do tipo Anulação
398
     * @var \DOMNode
399
     */
400
    private $infCteAnu = '';
401
    /**
402
     * Informações do modal Rodoviário
403
     * @var \DOMNode
404
     */
405
    private $rodo = '';
406
    /**
407
     * Informações do modal Aéreo
408
     * @var \DOMNode
409
     */
410
    private $aereo = '';
411
    /**
412
     * Informações do modal Ferroviario
413
     * @var \DOMNode
414
     */
415
    private $ferrov = '';
416
417
    private $ferroEnv = '';
418
    /**
419
     * Informações do modal Aquaviario
420
     * @var \DOMNode
421
     */
422
    private $aquav = '';
423
    /**
424
     * Informações do modal Dutoviário
425
     * @var \DOMNode
426
     */
427
    private $duto = '';
428
    /**
429
     * Ordens de Coleta associados
430
     * @var array
431
     */
432
    private $occ = array();
433
    /**
434
     * @var \DOMNode
435
     */
436
    private $emiOcc = array();
437
    /**
438
     * Informações de Vale Pedágio
439
     * @var array
440
     */
441
    private $valePed = array();
442
    /**
443
     * Dados dos Veículos
444
     * @var array
445
     */
446
    private $veic = array();
447
    /**
448
     * Proprietários do Veículo. Só preenchido quando o veículo não pertencer à empresa emitente do CT-e
449
     * @var array
450
     */
451
    private $prop = array();
452
    /**
453
     * Autorizados para download do XML do DF-e
454
     * @var array
455
     */
456
    private $autXML = array();
457
    /**
458
     * Dados do Fretamento - CTe-OS
459
     * @var
460
     */
461
    private $infFretamento;
462
    /**
463
     * @var DOMElement
464
     */
465
    protected $infRespTec;
466
    /**
467
     * @var boolean
468
     */
469
    protected $replaceAccentedChars = false;
470
471
    public function __construct()
472
    {
473
        $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...
474
        $this->dom->preserveWhiteSpace = false;
475
        $this->dom->formatOutput = false;
476
    }
477
478
    /**
479
     * Returns xml string and assembly it is necessary
480
     * @return string
481
     */
482
    public function getXML()
483
    {
484
        if (empty($this->xml)) {
485
            $this->montaCTe();
486
        }
487
        return $this->xml;
488
    }
489
490
    /**
491
     * Retorns the key number of NFe (44 digits)
492
     * @return string
493
     */
494
    public function getChave()
495
    {
496
        return $this->chCTe;
497
    }
498
499
    /**
500
     * Returns the model of CTe 57 or 67
501
     * @return int
502
     */
503
    public function getModelo()
504
    {
505
        return $this->mod;
506
    }
507
508
    /**
509
     * Set character convertion to ASCII only ou not
510
     * @param bool $option
511
     */
512
    public function setOnlyAscii($option = false)
513
    {
514
        $this->replaceAccentedChars = $option;
515
    }
516
517
    /**
518
     * Call method of xml assembly. For compatibility only.
519
     * @return boolean
520
     */
521
    public function montaCTe()
522
    {
523
        return $this->monta();
524
    }
525
526
    /**
527
     * Monta o arquivo XML usando as tag's já preenchidas
528
     *
529
     * @return bool
530
     */
531
    public function monta()
532
    {
533
        $this->errors = $this->dom->errors;
534
        if (count($this->errors) > 0) {
535
            return false;
536
        }
537
        if ($this->mod == 57) {
538
            $this->buildCTe();
539
        } else {
540
            return $this->montaCTeOS();
541
        }
542
        if ($this->toma3 != '') {
543
            $this->dom->appChild($this->ide, $this->toma3, 'Falta tag "ide"');
544
        } else {
545
            $this->dom->appChild($this->ide, $this->toma4, 'Falta tag "ide"');
546
        }
547
        $this->dom->appChild($this->infCte, $this->ide, 'Falta tag "infCte"');
548
        if ($this->compl != '') {
549
            if ($this->fluxo != '') {
550
                foreach ($this->pass as $pass) {
551
                    $this->dom->appChild($this->fluxo, $pass, 'Falta tag "fluxo"');
552
                }
553
                $this->dom->appChild($this->compl, $this->fluxo, 'Falta tag "infCte"');
554
            }
555
            if ($this->semData != '') {
556
                $this->tagEntrega();
557
                $this->dom->appChild($this->entrega, $this->semData, 'Falta tag "Entrega"');
558
            }
559
            if ($this->comData != '') {
560
                $this->tagEntrega();
561
                $this->dom->appChild($this->entrega, $this->comData, 'Falta tag "Entrega"');
562
            }
563
            if ($this->noPeriodo != '') {
564
                $this->tagEntrega();
565
                $this->dom->appChild($this->entrega, $this->noPeriodo, 'Falta tag "Entrega"');
566
            }
567
            if ($this->semHora != '') {
568
                $this->tagEntrega();
569
                $this->dom->appChild($this->entrega, $this->semHora, 'Falta tag "Entrega"');
570
            }
571
            if ($this->comHora != '') {
572
                $this->tagEntrega();
573
                $this->dom->appChild($this->entrega, $this->comHora, 'Falta tag "Entrega"');
574
            }
575
            if ($this->noInter != '') {
576
                $this->tagEntrega();
577
                $this->dom->appChild($this->entrega, $this->noInter, 'Falta tag "Entrega"');
578
            }
579
            foreach ($this->obsCont as $obsCont) {
580
                $this->dom->appChild($this->compl, $obsCont, 'Falta tag "compl"');
581
            }
582
            foreach ($this->obsFisco as $obsFisco) {
583
                $this->dom->appChild($this->compl, $obsFisco, 'Falta tag "compl"');
584
            }
585
            $this->dom->appChild($this->infCte, $this->compl, 'Falta tag "infCte"');
586
        }
587
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "emit"');
588
        $this->dom->appChild($this->infCte, $this->emit, 'Falta tag "infCte"');
589
        if ($this->rem != '') {
590
            $this->dom->appChild($this->infCte, $this->rem, 'Falta tag "infCte"');
591
        }
592
        if ($this->exped != '') {
593
            $this->dom->appChild($this->infCte, $this->exped, 'Falta tag "infCte"');
594
        }
595
        if ($this->receb != '') {
596
            $this->dom->appChild($this->infCte, $this->receb, 'Falta tag "infCte"');
597
        }
598
        if ($this->dest != '') {
599
            $this->dom->appChild($this->infCte, $this->dest, 'Falta tag "infCte"');
600
        }
601
        foreach ($this->comp as $comp) {
602
            $this->dom->appChild($this->vPrest, $comp, 'Falta tag "vPrest"');
603
        }
604
        $this->dom->appChild($this->infCte, $this->vPrest, 'Falta tag "infCte"');
605
        $this->dom->appChild($this->infCte, $this->imp, 'Falta tag "imp"');
606
        if ($this->infCteComp != '') { // Caso seja um CTe tipo complemento de valores
607
            $this->dom->appChild($this->infCte, $this->infCteComp, 'Falta tag "infCteComp"');
608
        }
609
        if ($this->infCteAnu != '') { // Caso seja um CTe tipo anulação
610
            $this->dom->appChild($this->infCte, $this->infCteAnu, 'Falta tag "infCteAnu"');
611
        }
612
        if ($this->infCTeNorm != '') { // Caso seja um CTe tipo normal
613
            $this->dom->appChild($this->infCte, $this->infCTeNorm, 'Falta tag "infCTeNorm"');
614
            $this->dom->appChild($this->infCTeNorm, $this->infCarga, 'Falta tag "infCarga"');
615
            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...
616
                $this->dom->appChild($this->infCarga, $infQ, 'Falta tag "infQ"');
617
            }
618
            foreach ($this->infNF as $infNF) {
619
                $this->dom->appChild($this->infDoc, $infNF, 'Falta tag "infNF"');
620
            }
621
            foreach ($this->infNFe as $infNFe) {
622
                $this->dom->appChild($this->infDoc, $infNFe, 'Falta tag "infNFe"');
623
            }
624
            foreach ($this->infOutros as $infOutros) {
625
                $this->dom->appChild($this->infDoc, $infOutros, 'Falta tag "infOutros"');
626
            }
627
            $this->dom->appChild($this->infCTeNorm, $this->infDoc, 'Falta tag "infCTeNorm"');
628
            if ($this->idDocAntEle != [] || $this->idDocAntPap != []) { //Caso tenha CT-es Anteriores viculados
629
                $this->dom->appChild($this->infCTeNorm, $this->docAnt, 'Falta tag "docAnt"');
630
                foreach ($this->emiDocAnt as $indice => $emiDocAnt) {
631
                    $this->dom->appChild($this->docAnt, $emiDocAnt, 'Falta tag "emiDocAnt"');
632
                    $this->dom->appChild($emiDocAnt, $this->idDocAnt[$indice], 'Falta tag "idDocAnt"');
633
                    if (array_key_exists($indice, $this->idDocAntEle)) {
634
                        foreach ($this->idDocAntEle[$indice] as $idDocAntEle) {
635
                            $this->dom->appChild($this->idDocAnt[$indice], $idDocAntEle, 'Falta tag "emiDocAnt"');
636
                        }
637
                    }
638
                    if (array_key_exists($indice, $this->idDocAntPap)) {
639
                        foreach ($this->idDocAntPap[$indice] as $idDocAntPap) {
640
                            $this->dom->appChild($this->idDocAnt[$indice], $idDocAntPap, 'Falta tag "idDocAntEle"');
641
                        }
642
                    }
643
                }
644
            }
645
            foreach ($this->seg as $seg) {
646
                $this->dom->appChild($this->infCTeNorm, $seg, 'Falta tag "seg"');
647
            }
648
            $this->dom->appChild($this->infCTeNorm, $this->infModal, 'Falta tag "infModal"');
649
            if ($this->modal == '01') {
650
                if ($this->rodo) {
651
                    foreach ($this->occ as $occ) {
652
                        $this->dom->appChild($this->rodo, $occ, 'Falta tag "occ"');
653
                    }
654
                    $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "rodo"');
655
                }
656
            } elseif ($this->modal == '02') {
657
                foreach ($this->peri as $peri) {
658
                    $this->dom->appChild($this->aereo, $peri, 'Falta tag "aereo"');
659
                }
660
                $this->dom->appChild($this->infModal, $this->aereo, 'Falta tag "aereo"');
661
            } elseif ($this->modal == '04') {
662
                foreach ($this->ferroEnv as $ferroEnv) {
0 ignored issues
show
Bug introduced by
The expression $this->ferroEnv of type string is not traversable.
Loading history...
663
                    $this->ferrov->insertBefore($ferroEnv, $this->ferrov->getElementsByTagName('fluxo')->item(0));
664
                }
665
                $this->dom->appChild($this->infModal, $this->ferrov, 'Falta tag "ferrov"');
666
            } elseif ($this->modal == '03') {
667
                $this->dom->appChild($this->infModal, $this->aquav, 'Falta tag "aquav"');
668
            } elseif ($this->modal == '05') {
669
                $this->dom->appChild($this->infModal, $this->duto, 'Falta tag "duto"');
670
            } else {
671
                throw new Exception('Modal não informado ou não suportado.');
672
            }
673
            foreach ($this->veicNovos as $veicNovos) {
674
                $this->dom->appChild($this->infCTeNorm, $veicNovos, 'Falta tag "infCte"');
675
            }
676
            if ($this->infCteSub != '') {
677
                $this->dom->appChild($this->infCTeNorm, $this->infCteSub, 'Falta tag "infCteSub"');
678
679
                if ($this->tomaICMS != '') {
680
                    $this->dom->appChild($this->infCteSub, $this->tomaICMS, 'Falta tag "infCteSub"');
681
                }
682
            }
683
        }
684
        if ($this->cobr != '') {
685
            $this->dom->appChild($this->infCte, $this->cobr, 'Falta tag "infCte"');
686
        }
687
        foreach ($this->autXML as $autXML) {
688
            $this->dom->appChild($this->infCte, $autXML, 'Falta tag "infCte"');
689
        }
690
        $this->dom->appChild($this->infCte, $this->infRespTec, 'Falta tag "infCte"');
691
        //[1] tag infCTe
692
        $this->dom->appChild($this->CTe, $this->infCte, 'Falta tag "CTe"');
693
        //[0] tag CTe
694
        $this->dom->appendChild($this->CTe);
695
        // testa da chave
696
        $this->checkCTeKey($this->dom);
697
        $this->xml = $this->dom->saveXML();
698
        return true;
699
    }
700
701
    /**
702
     * Gera as tags para o elemento: "occ" (ordem de coletas)
703
     * #3
704
     * Nível:1
705
     * Os parâmetros para esta função são todos os elementos da tag "occ" do
706
     * tipo elemento (Ele = E|CE|A) e nível 1
707
     *
708
     * @return \DOMElement
709
     */
710
711
    public function tagocc($std)
712
    {
713
714
        $possible = [
715
            'serie',
716
            'nOcc',
717
            'dEmi',
718
            'CNPJ',
719
            'cInt',
720
            'IE',
721
            'UF',
722
            'fone'
723
        ];
724
725
        $std = $this->equilizeParameters($std, $possible);
726
727
        $identificador = '#3 <occ> - ';
728
        $occ = $this->dom->createElement('occ');
729
        $this->dom->addChild(
730
            $occ,
731
            'serie',
732
            $std->serie,
733
            false,
734
            $identificador . 'Série da OCC'
735
        );
736
        $this->dom->addChild(
737
            $occ,
738
            'nOcc',
739
            $std->nOcc,
740
            true,
741
            $identificador . 'Número da Ordem de coleta'
742
        );
743
        $this->dom->addChild(
744
            $occ,
745
            'dEmi',
746
            $std->dEmi,
747
            true,
748
            $identificador . 'Data de emissão da ordem de coleta'
749
        );
750
        //emitente
751
        $identificador = '#7 <emiOcc> - ';
752
        $emiOcc = $this->dom->createElement('emiOcc');
753
        $this->dom->addChild(
754
            $emiOcc,
755
            'CNPJ',
756
            $std->CNPJ,
757
            true,
758
            $identificador . 'Número do CNPJ'
759
        );
760
        $this->dom->addChild(
761
            $emiOcc,
762
            'cInt',
763
            $std->cInt,
764
            false,
765
            $identificador . 'Código interno de uso da transportadora'
766
        );
767
        $this->dom->addChild(
768
            $emiOcc,
769
            'IE',
770
            $std->IE,
771
            true,
772
            $identificador . 'Inscrição Estadual'
773
        );
774
        $this->dom->addChild(
775
            $emiOcc,
776
            'UF',
777
            $std->UF,
778
            true,
779
            $identificador . 'Sigla da UF'
780
        );
781
        $this->dom->addChild(
782
            $emiOcc,
783
            'fone',
784
            $std->fone,
785
            false,
786
            $identificador . 'Telefone'
787
        );
788
        $this->dom->appChild($occ, $emiOcc, 'Falta tag "emiOcc"');
789
        $this->occ[] = $occ;
790
        return $occ;
791
    }
792
793
794
    /**
795
     * Monta o arquivo XML usando as tag's já preenchidas
796
     *
797
     * @return bool
798
     */
799
    public function montaCTeOS()
800
    {
801
        $this->errors = $this->dom->errors;
802
        if (count($this->errors) > 0) {
803
            return false;
804
        }
805
        $this->buildCTeOS();
806
        if ($this->infPercurso != '') {
807
            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...
808
                $this->dom->appChild($this->ide, $perc, 'Falta tag "infPercurso"');
809
            }
810
        }
811
        $this->dom->appChild($this->infCte, $this->ide, 'Falta tag "infCte"');
812
        if ($this->compl != '') {
813
            $this->dom->appChild($this->infCte, $this->compl, 'Falta tag "infCte"');
814
        }
815
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "emit"');
816
        $this->dom->appChild($this->infCte, $this->emit, 'Falta tag "infCte"');
817
        if ($this->toma != '') {
818
            $this->dom->appChild($this->infCte, $this->toma, 'Falta tag "infCte"');
819
        }
820
        foreach ($this->comp as $comp) {
821
            $this->dom->appChild($this->vPrest, $comp, 'Falta tag "vPrest"');
822
        }
823
        $this->dom->appChild($this->infCte, $this->vPrest, 'Falta tag "infCte"');
824
        $this->dom->appChild($this->infCte, $this->imp, 'Falta tag "imp"');
825
        if ($this->infCteComp != '') { // Caso seja um CTe tipo complemento de valores
826
            $this->dom->appChild($this->infCte, $this->infCteComp, 'Falta tag "infCteComp"');
827
        } elseif ($this->infCteAnu != '') { // Caso seja um CTe tipo anulação
828
            $this->dom->appChild($this->infCte, $this->infCteAnu, 'Falta tag "infCteAnu"');
829
        } elseif ($this->infCTeNorm != '') { // Caso seja um CTe tipo normal
830
            $this->dom->appChild($this->infCte, $this->infCTeNorm, 'Falta tag "infCTeNorm"');
831
            $this->dom->appChild($this->infCTeNorm, $this->infServico, 'Falta tag "infServico"');
832
            foreach ($this->infDocRef as $infDocRef) {
833
                $this->dom->appChild($this->infCTeNorm, $infDocRef, 'Falta tag "infDocRef"');
834
            }
835
            foreach ($this->seg as $seg) {
836
                $this->dom->appChild($this->infCTeNorm, $seg, 'Falta tag "seg"');
837
            }
838
            if ($this->infModal != '') {
839
                $this->dom->appChild($this->infCTeNorm, $this->infModal, 'Falta tag "infModal"');
840
                if (!empty($this->veic)) {
841
                    $this->dom->appChild($this->rodo, $this->veic, 'Falta tag "veic"');
842
                }
843
                $this->dom->appChild($this->rodo, $this->infFretamento, 'Falta tag "infFretamento"');
844
                $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "rodo"');
845
            }
846
        }
847
        if ($this->cobr != '') {
848
            $this->dom->appChild($this->infCte, $this->cobr, 'Falta tag "infCte"');
849
        }
850
        foreach ($this->autXML as $autXML) {
851
            $this->dom->appChild($this->infCte, $autXML, 'Falta tag "infCte"');
852
        }
853
        $this->dom->appChild($this->infCte, $this->infRespTec, 'Falta tag "infCte"');
854
        $this->dom->appChild($this->CTe, $this->infCte, 'Falta tag "CTe"');
855
        $this->dom->appendChild($this->CTe);
856
        // testa da chave
857
        $this->checkCTeKey($this->dom);
858
        $this->xml = $this->dom->saveXML();
859
        return true;
860
    }
861
862
    /**
863
     * Gera o grupo básico: Informações do CT-e
864
     * #1
865
     * Nível: 0
866
     * @param stdClass $std
867
     * @return \DOMElement
868
     */
869
    public function taginfCTe($std)
870
    {
871
        $chave = preg_replace('/[^0-9]/', '', $std->Id);
872
        $this->infCte = $this->dom->createElement('infCte');
873
        $this->infCte->setAttribute('Id', 'CTe' . $chave);
874
        $this->infCte->setAttribute('versao', $std->versao);
875
        return $this->infCte;
876
    }
877
878
    /**
879
     * Gera as tags para o elemento: Identificação do CT-e
880
     * #4
881
     * Nível: 1
882
     * @param stdClass $std
883
     * @return DOMElement|\DOMNode
884
     */
885
    public function tagide($std)
886
    {
887
888
        $possible = [
889
            'cUF',
890
            'cCT',
891
            'CFOP',
892
            'natOp',
893
            'mod',
894
            'serie',
895
            'nCT',
896
            'dhEmi',
897
            'tpImp',
898
            'tpEmis',
899
            'cDV',
900
            'tpEmis',
901
            'tpAmb',
902
            'tpCTe',
903
            'procEmi',
904
            'verProc',
905
            'indGlobalizado',
906
            'cMunEnv',
907
            'xMunEnv',
908
            'UFEnv',
909
            'modal',
910
            'tpServ',
911
            'indIEToma',
912
            'cMunIni',
913
            'xMunIni',
914
            'UFIni',
915
            'cMunFim',
916
            'xMunFim',
917
            'UFFim',
918
            'retira',
919
            'xDetRetira',
920
            'indIEToma',
921
            'dhCont',
922
            'xJust'
923
        ];
924
925
        $std = $this->equilizeParameters($std, $possible);
926
927
        $this->tpAmb = $std->tpAmb;
928
        $this->mod = $std->mod;
929
        $identificador = '#4 <ide> - ';
930
        $this->ide = $this->dom->createElement('ide');
931
        $this->dom->addChild(
932
            $this->ide,
933
            'cUF',
934
            $std->cUF,
935
            true,
936
            $identificador . 'Código da UF do emitente do CT-e'
937
        );
938
        $this->dom->addChild(
939
            $this->ide,
940
            'cCT',
941
            str_pad($std->cCT, 8, '0', STR_PAD_LEFT),
942
            true,
943
            $identificador . 'Código numérico que compõe a Chave de Acesso'
944
        );
945
        $this->dom->addChild(
946
            $this->ide,
947
            'CFOP',
948
            $std->CFOP,
949
            true,
950
            $identificador . 'Código Fiscal de Operações e Prestações'
951
        );
952
        $this->dom->addChild(
953
            $this->ide,
954
            'natOp',
955
            Strings::replaceSpecialsChars(substr(trim($std->natOp), 0, 60)),
956
            true,
957
            $identificador . 'Natureza da Operação'
958
        );
959
        $this->dom->addChild(
960
            $this->ide,
961
            'mod',
962
            $std->mod,
963
            true,
964
            $identificador . 'Modelo do documento fiscal'
965
        );
966
        $this->dom->addChild(
967
            $this->ide,
968
            'serie',
969
            $std->serie,
970
            true,
971
            $identificador . 'Série do CT-e'
972
        );
973
        $this->dom->addChild(
974
            $this->ide,
975
            'nCT',
976
            $std->nCT,
977
            true,
978
            $identificador . 'Número do CT-e'
979
        );
980
        $this->dom->addChild(
981
            $this->ide,
982
            'dhEmi',
983
            $std->dhEmi,
984
            true,
985
            $identificador . 'Data e hora de emissão do CT-e'
986
        );
987
        $this->dom->addChild(
988
            $this->ide,
989
            'tpImp',
990
            $std->tpImp,
991
            true,
992
            $identificador . 'Formato de impressão do DACTE'
993
        );
994
        $this->dom->addChild(
995
            $this->ide,
996
            'tpEmis',
997
            $std->tpEmis,
998
            true,
999
            $identificador . 'Forma de emissão do CT-e'
1000
        );
1001
        $this->dom->addChild(
1002
            $this->ide,
1003
            'cDV',
1004
            $std->cDV,
1005
            false,
1006
            $identificador . 'Digito Verificador da chave de acesso do CT-e'
1007
        );
1008
        $this->dom->addChild(
1009
            $this->ide,
1010
            'tpAmb',
1011
            $std->tpAmb,
1012
            true,
1013
            $identificador . 'Tipo do Ambiente'
1014
        );
1015
        $this->dom->addChild(
1016
            $this->ide,
1017
            'tpCTe',
1018
            $std->tpCTe,
1019
            true,
1020
            $identificador . 'Tipo do CT-e'
1021
        );
1022
        $this->dom->addChild(
1023
            $this->ide,
1024
            'procEmi',
1025
            $std->procEmi,
1026
            true,
1027
            $identificador . 'Identificador do processo de emissão do CT-e'
1028
        );
1029
        $this->dom->addChild(
1030
            $this->ide,
1031
            'verProc',
1032
            $std->verProc,
1033
            true,
1034
            $identificador . 'Versão do processo de emissão'
1035
        );
1036
        if ($this->mod == 57) {
1037
            $this->dom->addChild(
1038
                $this->ide,
1039
                'indGlobalizado',
1040
                $std->indGlobalizado,
1041
                false,
1042
                $identificador . 'Indicador de CT-e Globalizado'
1043
            );
1044
        }
1045
        $this->dom->addChild(
1046
            $this->ide,
1047
            'cMunEnv',
1048
            $std->cMunEnv,
1049
            true,
1050
            $identificador . 'Código do Município de envio do CT-e (de onde o documento foi transmitido)'
1051
        );
1052
        $this->dom->addChild(
1053
            $this->ide,
1054
            'xMunEnv',
1055
            $std->xMunEnv,
1056
            true,
1057
            $identificador . 'Nome do Município de envio do CT-e (de onde o documento foi transmitido)'
1058
        );
1059
        $this->dom->addChild(
1060
            $this->ide,
1061
            'UFEnv',
1062
            $std->UFEnv,
1063
            true,
1064
            $identificador . 'Sigla da UF de envio do CT-e (de onde o documento foi transmitido)'
1065
        );
1066
        $this->dom->addChild(
1067
            $this->ide,
1068
            'modal',
1069
            $std->modal,
1070
            true,
1071
            $identificador . 'Modal'
1072
        );
1073
        $this->modal = $std->modal;
1074
        $this->dom->addChild(
1075
            $this->ide,
1076
            'tpServ',
1077
            $std->tpServ,
1078
            true,
1079
            $identificador . 'Tipo do Serviço'
1080
        );
1081
        if ($this->mod == 67) {
1082
            $this->dom->addChild(
1083
                $this->ide,
1084
                'indIEToma',
1085
                $std->indIEToma,
1086
                true,
1087
                $identificador . 'Indicador do papel do tomador na prestação do serviço'
1088
            );
1089
        }
1090
        $this->dom->addChild(
1091
            $this->ide,
1092
            'cMunIni',
1093
            $std->cMunIni,
1094
            true,
1095
            $identificador . 'Nome do Município do início da prestação'
1096
        );
1097
        $this->dom->addChild(
1098
            $this->ide,
1099
            'xMunIni',
1100
            $std->xMunIni,
1101
            true,
1102
            $identificador . 'Nome do Município do início da prestação'
1103
        );
1104
        $this->dom->addChild(
1105
            $this->ide,
1106
            'UFIni',
1107
            $std->UFIni,
1108
            true,
1109
            $identificador . 'UF do início da prestação'
1110
        );
1111
        $this->dom->addChild(
1112
            $this->ide,
1113
            'cMunFim',
1114
            $std->cMunFim,
1115
            true,
1116
            $identificador . 'Código do Município de término da prestação'
1117
        );
1118
        $this->dom->addChild(
1119
            $this->ide,
1120
            'xMunFim',
1121
            $std->xMunFim,
1122
            true,
1123
            $identificador . 'Nome do Município do término da prestação'
1124
        );
1125
        $this->dom->addChild(
1126
            $this->ide,
1127
            'UFFim',
1128
            $std->UFFim,
1129
            true,
1130
            $identificador . 'UF do término da prestação'
1131
        );
1132
        if ($this->mod == 57) {
1133
            $this->dom->addChild(
1134
                $this->ide,
1135
                'retira',
1136
                $std->retira,
1137
                true,
1138
                $identificador . 'Indicador se o Recebedor retira no Aeroporto, Filial, Porto ou Estação de Destino'
1139
            );
1140
            $this->dom->addChild(
1141
                $this->ide,
1142
                'xDetRetira',
1143
                $std->xDetRetira,
1144
                false,
1145
                $identificador . 'Detalhes do retira'
1146
            );
1147
            $this->dom->addChild(
1148
                $this->ide,
1149
                'indIEToma',
1150
                $std->indIEToma,
1151
                true,
1152
                $identificador . 'Indicador do papel do tomador na prestação do serviço'
1153
            );
1154
        }
1155
        $this->dom->addChild(
1156
            $this->ide,
1157
            'dhCont',
1158
            $std->dhCont,
1159
            false,
1160
            $identificador . 'Data e Hora da entrada em contingência'
1161
        );
1162
        $this->dom->addChild(
1163
            $this->ide,
1164
            'xJust',
1165
            Strings::replaceSpecialsChars(substr(trim($std->xJust), 0, 256)),
1166
            false,
1167
            $identificador . 'Justificativa da entrada em contingência'
1168
        );
1169
        $this->tpServ = $std->tpServ;
1170
        return $this->ide;
1171
    }
1172
1173
    public function taginfPercurso($std)
1174
    {
1175
1176
        $possible = [
1177
            'UFPer'
1178
        ];
1179
1180
        $std = $this->equilizeParameters($std, $possible);
1181
1182
        $identificador = '#4 <infPercurso> - ';
1183
        $this->infPercurso[] = $this->dom->createElement('infPercurso');
1184
        $posicao = (int)count($this->infPercurso) - 1;
1185
        $this->dom->addChild(
1186
            $this->infPercurso[$posicao],
1187
            'UFPer',
1188
            $std->uf,
1189
            true,
1190
            $identificador . 'Código da UF do percurso'
1191
        );
1192
1193
        return $this->infPercurso[$posicao];
1194
    }
1195
1196
    /**
1197
     * Gera as tags para o elemento: toma3 (Indicador do "papel" do tomador do serviço no CT-e)
1198
     * e adiciona ao grupo ide
1199
     * #35
1200
     * Nível: 2
1201
     * @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...
1202
     * @param stdClass $std
1203
     * @return \DOMElement
1204
     */
1205
    public function tagtoma3($std)
1206
    {
1207
1208
        $possible = [
1209
            'toma'
1210
        ];
1211
1212
        $std = $this->equilizeParameters($std, $possible);
1213
1214
        $identificador = '#35 <toma3> - ';
1215
        $this->toma3 = $this->dom->createElement('toma3');
1216
        $this->dom->addChild(
1217
            $this->toma3,
1218
            'toma',
1219
            $std->toma,
1220
            true,
1221
            $identificador . 'Tomador do Serviço'
1222
        );
1223
        return $this->toma3;
1224
    }
1225
1226
    /**
1227
     * Gera as tags para o elemento: toma4 (Indicador do "papel" do tomador
1228
     * do serviço no CT-e) e adiciona ao grupo ide
1229
     * #37
1230
     * Nível: 2
1231
     * @param stdClass $std
1232
     * @return \DOMElement
1233
     */
1234
    public function tagtoma4($std)
1235
    {
1236
1237
        $possible = [
1238
            'toma',
1239
            'CNPJ',
1240
            'CPF',
1241
            'IE',
1242
            'xNome',
1243
            'xFant',
1244
            'fone',
1245
            'email'
1246
        ];
1247
1248
        $std = $this->equilizeParameters($std, $possible);
1249
1250
        $identificador = '#37 <toma4> - ';
1251
        $this->toma4 = $this->dom->createElement('toma4');
1252
        $this->dom->addChild(
1253
            $this->toma4,
1254
            'toma',
1255
            $std->toma,
1256
            true,
1257
            $identificador . 'Tomador do Serviço'
1258
        );
1259
        if ($std->CNPJ != '') {
1260
            $this->dom->addChild(
1261
                $this->toma4,
1262
                'CNPJ',
1263
                $std->CNPJ,
1264
                true,
1265
                $identificador . 'Número do CNPJ'
1266
            );
1267
        } elseif ($std->CPF != '') {
1268
            $this->dom->addChild(
1269
                $this->toma4,
1270
                'CPF',
1271
                $std->CPF,
1272
                true,
1273
                $identificador . 'Número do CPF'
1274
            );
1275
        } else {
1276
            $this->dom->addChild(
1277
                $this->toma4,
1278
                'CNPJ',
1279
                $std->CNPJ,
1280
                true,
1281
                $identificador . 'Número do CNPJ'
1282
            );
1283
            $this->dom->addChild(
1284
                $this->toma4,
1285
                'CPF',
1286
                $std->CPF,
1287
                true,
1288
                $identificador . 'Número do CPF'
1289
            );
1290
        }
1291
        $this->dom->addChild(
1292
            $this->toma4,
1293
            'IE',
1294
            $std->IE,
1295
            false,
1296
            $identificador . 'Inscrição Estadual'
1297
        );
1298
        $this->dom->addChild(
1299
            $this->toma4,
1300
            'xNome',
1301
            $std->xNome,
1302
            true,
1303
            $identificador . 'Razão Social ou Nome'
1304
        );
1305
        $this->dom->addChild(
1306
            $this->toma4,
1307
            'xFant',
1308
            $std->xFant,
1309
            false,
1310
            $identificador . 'Nome Fantasia'
1311
        );
1312
        $this->dom->addChild(
1313
            $this->toma4,
1314
            'fone',
1315
            $std->fone,
1316
            false,
1317
            $identificador . 'Telefone'
1318
        );
1319
        $this->dom->addChild(
1320
            $this->toma4,
1321
            'email',
1322
            $std->email,
1323
            false,
1324
            $identificador . 'Endereço de email'
1325
        );
1326
        return $this->toma4;
1327
    }
1328
1329
    /**
1330
     * Gera as tags para o elemento: toma4 (Indicador do "papel" do tomador
1331
     * do serviço no CT-e OS) e adiciona ao grupo ide
1332
     * #37
1333
     * Nível: 2
1334
     *
1335
     * @return \DOMElement
1336
     */
1337
    public function tagtomador($std)
1338
    {
1339
1340
        $possible = [
1341
            'CNPJ',
1342
            'CPF',
1343
            'IE',
1344
            'xNome',
1345
            'xFant',
1346
            'fone',
1347
            'xLgr',
1348
            'nro',
1349
            'xCpl',
1350
            'xBairro',
1351
            'cMun',
1352
            'xMun',
1353
            'CEP',
1354
            'UF',
1355
            'cPais',
1356
            'xPais',
1357
            'email'
1358
        ];
1359
1360
        $std = $this->equilizeParameters($std, $possible);
1361
1362
        $identificador = '#37 <toma> - ';
1363
        $this->toma = $this->dom->createElement('toma');
1364
        if ($std->CNPJ != '') {
1365
            $this->dom->addChild(
1366
                $this->toma,
1367
                'CNPJ',
1368
                $std->CNPJ,
1369
                true,
1370
                $identificador . 'Número do CNPJ'
1371
            );
1372
        } elseif ($std->CPF != '') {
1373
            $this->dom->addChild(
1374
                $this->toma,
1375
                'CPF',
1376
                $std->CPF,
1377
                true,
1378
                $identificador . 'Número do CPF'
1379
            );
1380
        } else {
1381
            $this->dom->addChild(
1382
                $this->toma,
1383
                'CNPJ',
1384
                $std->CNPJ,
1385
                true,
1386
                $identificador . 'Número do CNPJ'
1387
            );
1388
            $this->dom->addChild(
1389
                $this->toma,
1390
                'CPF',
1391
                $std->CPF,
1392
                true,
1393
                $identificador . 'Número do CPF'
1394
            );
1395
        }
1396
        $this->dom->addChild(
1397
            $this->toma,
1398
            'IE',
1399
            $std->IE,
1400
            false,
1401
            $identificador . 'Inscrição Estadual'
1402
        );
1403
        $this->dom->addChild(
1404
            $this->toma,
1405
            'xNome',
1406
            $std->xNome,
1407
            true,
1408
            $identificador . 'Razão Social ou Nome'
1409
        );
1410
        $this->dom->addChild(
1411
            $this->toma,
1412
            'xFant',
1413
            $std->xFant,
1414
            false,
1415
            $identificador . 'Nome Fantasia'
1416
        );
1417
        $this->dom->addChild(
1418
            $this->toma,
1419
            'fone',
1420
            $std->fone,
1421
            false,
1422
            $identificador . 'Telefone'
1423
        );
1424
        //Endereço Tomador
1425
        $this->enderToma = $this->dom->createElement('enderToma');
1426
        $this->dom->addChild(
1427
            $this->enderToma,
1428
            'xLgr',
1429
            $std->xLgr,
1430
            true,
1431
            $identificador . 'Logradouro'
1432
        );
1433
        $this->dom->addChild(
1434
            $this->enderToma,
1435
            'nro',
1436
            $std->nro,
1437
            true,
1438
            $identificador . 'Número'
1439
        );
1440
        $this->dom->addChild(
1441
            $this->enderToma,
1442
            'xCpl',
1443
            $std->xCpl,
1444
            false,
1445
            $identificador . 'Complemento'
1446
        );
1447
        $this->dom->addChild(
1448
            $this->enderToma,
1449
            'xBairro',
1450
            $std->xBairro,
1451
            true,
1452
            $identificador . 'Bairro'
1453
        );
1454
        $this->dom->addChild(
1455
            $this->enderToma,
1456
            'cMun',
1457
            $std->cMun,
1458
            true,
1459
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
1460
        );
1461
        $this->dom->addChild(
1462
            $this->enderToma,
1463
            'xMun',
1464
            $std->xMun,
1465
            true,
1466
            $identificador . 'Nome do município'
1467
        );
1468
        $this->dom->addChild(
1469
            $this->enderToma,
1470
            'CEP',
1471
            $std->CEP,
1472
            false,
1473
            $identificador . 'CEP'
1474
        );
1475
        $this->dom->addChild(
1476
            $this->enderToma,
1477
            'UF',
1478
            $std->UF,
1479
            true,
1480
            $identificador . 'Sigla da UF'
1481
        );
1482
        $this->dom->addChild(
1483
            $this->enderToma,
1484
            'cPais',
1485
            $std->cPais,
1486
            false,
1487
            $identificador . 'Código do país'
1488
        );
1489
        $this->dom->addChild(
1490
            $this->enderToma,
1491
            'xPais',
1492
            $std->xPais,
1493
            false,
1494
            $identificador . 'Nome do país'
1495
        );
1496
        $this->dom->appChild($this->toma, $this->enderToma, 'Falta tag "enderToma"');
1497
        $this->dom->addChild(
1498
            $this->toma,
1499
            'email',
1500
            $std->email,
1501
            false,
1502
            $identificador . 'Endereço de email'
1503
        );
1504
        return $this->toma;
1505
    }
1506
1507
    /**
1508
     * Gera as tags para o elemento: "enderToma" (Dados do endereço) e adiciona ao grupo "toma4"
1509
     * #45
1510
     * Nível: 3
1511
     *
1512
     * @return \DOMElement
1513
     */
1514
    public function tagenderToma($std)
1515
    {
1516
1517
        $possible = [
1518
            'xLgr',
1519
            'nro',
1520
            'xCpl',
1521
            'xBairro',
1522
            'cMun',
1523
            'xMun',
1524
            'CEP',
1525
            'UF',
1526
            'cPais',
1527
            'xPais'
1528
        ];
1529
1530
        $std = $this->equilizeParameters($std, $possible);
1531
1532
        $identificador = '#45 <enderToma> - ';
1533
        $this->enderToma = $this->dom->createElement('enderToma');
1534
        $this->dom->addChild(
1535
            $this->enderToma,
1536
            'xLgr',
1537
            $std->xLgr,
1538
            true,
1539
            $identificador . 'Logradouro'
1540
        );
1541
        $this->dom->addChild(
1542
            $this->enderToma,
1543
            'nro',
1544
            $std->nro,
1545
            true,
1546
            $identificador . 'Número'
1547
        );
1548
        $this->dom->addChild(
1549
            $this->enderToma,
1550
            'xCpl',
1551
            $std->xCpl,
1552
            false,
1553
            $identificador . 'Complemento'
1554
        );
1555
        $this->dom->addChild(
1556
            $this->enderToma,
1557
            'xBairro',
1558
            $std->xBairro,
1559
            true,
1560
            $identificador . 'Bairro'
1561
        );
1562
        $this->dom->addChild(
1563
            $this->enderToma,
1564
            'cMun',
1565
            $std->cMun,
1566
            true,
1567
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
1568
        );
1569
        $this->dom->addChild(
1570
            $this->enderToma,
1571
            'xMun',
1572
            $std->xMun,
1573
            true,
1574
            $identificador . 'Nome do município'
1575
        );
1576
        $this->dom->addChild(
1577
            $this->enderToma,
1578
            'CEP',
1579
            $std->CEP,
1580
            false,
1581
            $identificador . 'CEP'
1582
        );
1583
        $this->dom->addChild(
1584
            $this->enderToma,
1585
            'UF',
1586
            $std->UF,
1587
            true,
1588
            $identificador . 'Sigla da UF'
1589
        );
1590
        $this->dom->addChild(
1591
            $this->enderToma,
1592
            'cPais',
1593
            $std->cPais,
1594
            false,
1595
            $identificador . 'Código do país'
1596
        );
1597
        $this->dom->addChild(
1598
            $this->enderToma,
1599
            'xPais',
1600
            $std->xPais,
1601
            false,
1602
            $identificador . 'Nome do país'
1603
        );
1604
1605
        if (!empty($this->toma4)) {
1606
            $this->toma4->insertBefore($this->enderToma, $this->toma4->getElementsByTagName("email")->item(0));
1607
        }
1608
        return $this->enderToma;
1609
    }
1610
1611
    /**
1612
     * Gera as tags para o elemento: "compl" (Dados complementares do CT-e para fins operacionais ou comerciais)
1613
     * #59
1614
     * Nível: 1
1615
     *
1616
     * @return \DOMElement
1617
     */
1618
    public function tagcompl($std)
1619
    {
1620
1621
        $possible = [
1622
            'xCaracAd',
1623
            'xCaracSer',
1624
            'xEmi',
1625
            'origCalc',
1626
            'destCalc',
1627
            'xObs'
1628
        ];
1629
1630
        $std = $this->equilizeParameters($std, $possible);
1631
1632
        $identificador = '#59 <compl> - ';
1633
        if ($this->compl == '') {
1634
            $this->compl = $this->dom->createElement('compl');
1635
        }
1636
        $this->dom->addChild(
1637
            $this->compl,
1638
            'xCaracAd',
1639
            $std->xCaracAd,
1640
            false,
1641
            $identificador . 'Característica adicional do transporte'
1642
        );
1643
        $this->dom->addChild(
1644
            $this->compl,
1645
            'xCaracSer',
1646
            $std->xCaracSer,
1647
            false,
1648
            $identificador . 'Característica adicional do serviço'
1649
        );
1650
        $this->dom->addChild(
1651
            $this->compl,
1652
            'xEmi',
1653
            $std->xEmi,
1654
            false,
1655
            $identificador . 'Funcionário emissor do CTe'
1656
        );
1657
        if ($this->mod == 57) {
1658
            $this->dom->addChild(
1659
                $this->compl,
1660
                'origCalc',
1661
                $std->origCalc,
1662
                false,
1663
                $identificador . 'Município de origem para efeito de cálculo do frete'
1664
            );
1665
            $this->dom->addChild(
1666
                $this->compl,
1667
                'destCalc',
1668
                $std->destCalc,
1669
                false,
1670
                $identificador . 'Município de destino para efeito de cálculo do frete'
1671
            );
1672
        }
1673
        $this->dom->addChild(
1674
            $this->compl,
1675
            'xObs',
1676
            $std->xObs,
1677
            false,
1678
            $identificador . 'Observações Gerais'
1679
        );
1680
        return $this->compl;
1681
    }
1682
1683
    /**
1684
     * Gera as tags para o elemento: "compl" (Dados complementares do CT-e OS para fins operacionais ou comerciais)
1685
     * #59
1686
     * Nível: 1
1687
     *
1688
     * @return \DOMElement
1689
     */
1690
    public function tagcomplCTeOs($std)
1691
    {
1692
1693
        $possible = [
1694
            'xCaracAd',
1695
            'xCaracSer',
1696
            'xEmi',
1697
            'xObs'
1698
        ];
1699
1700
        $std = $this->equilizeParameters($std, $possible);
1701
1702
        $identificador = '#59 <compl> - ';
1703
        $this->compl = $this->dom->createElement('compl');
1704
        $this->dom->addChild(
1705
            $this->compl,
1706
            'xCaracAd',
1707
            $std->xCaracAd,
1708
            false,
1709
            $identificador . 'Característica adicional do transporte'
1710
        );
1711
        $this->dom->addChild(
1712
            $this->compl,
1713
            'xCaracSer',
1714
            $std->xCaracSer,
1715
            false,
1716
            $identificador . 'Característica adicional do serviço'
1717
        );
1718
        $this->dom->addChild(
1719
            $this->compl,
1720
            'xEmi',
1721
            $std->xEmi,
1722
            false,
1723
            $identificador . 'Funcionário emissor do CTe'
1724
        );
1725
        $this->dom->addChild(
1726
            $this->compl,
1727
            'xObs',
1728
            $std->xObs,
1729
            false,
1730
            $identificador . 'Observações Gerais'
1731
        );
1732
        return $this->compl;
1733
    }
1734
1735
    /**
1736
     * Gera as tags para o elemento: "fluxo" (Previsão do fluxo da carga)
1737
     * #63
1738
     * Nível: 2
1739
     * Os parâmetros para esta função são todos os elementos da tag "fluxo" do
1740
     * tipo elemento (Ele = E|CE|A) e nível 3
1741
     *
1742
     * @return \DOMElement
1743
     */
1744
    public function tagfluxo($std)
1745
    {
1746
1747
        $possible = [
1748
            'xOrig',
1749
            'xDest',
1750
            'xRota'
1751
        ];
1752
1753
        $std = $this->equilizeParameters($std, $possible);
1754
1755
        $identificador = '#63 <fluxo> - ';
1756
        $this->fluxo = $this->dom->createElement('fluxo');
1757
        $this->dom->addChild(
1758
            $this->fluxo,
1759
            'xOrig',
1760
            $std->xOrig,
1761
            false,
1762
            $identificador . 'Sigla ou código interno da Filial/Porto/Estação/ Aeroporto de Origem'
1763
        );
1764
        $this->dom->addChild(
1765
            $this->fluxo,
1766
            'xDest',
1767
            $std->xDest,
1768
            false,
1769
            $identificador . 'Sigla ou código interno da Filial/Porto/Estação/Aeroporto de Destino'
1770
        );
1771
        $this->dom->addChild(
1772
            $this->fluxo,
1773
            'xRota',
1774
            $std->xRota,
1775
            false,
1776
            $identificador . 'Código da Rota de Entrega'
1777
        );
1778
        return $this->fluxo;
1779
    }
1780
1781
    /**
1782
     * Gera as tags para o elemento: "pass"
1783
     * #65
1784
     * Nível: 3
1785
     *
1786
     * @return \DOMElement
1787
     */
1788
    public function tagpass($std)
1789
    {
1790
1791
        $possible = [
1792
            'xPass'
1793
        ];
1794
1795
        $std = $this->equilizeParameters($std, $possible);
1796
1797
        $identificador = '#65 <pass> - ';
1798
        $this->pass[] = $this->dom->createElement('pass');
1799
        $posicao = (int)count($this->pass) - 1;
1800
        $this->dom->addChild(
1801
            $this->pass[$posicao],
1802
            'xPass',
1803
            $std->xPass,
1804
            false,
1805
            $identificador . 'Sigla ou código interno da Filial/Porto/Estação/Aeroporto de Passagem'
1806
        );
1807
        return $this->pass[$posicao];
1808
    }
1809
1810
    /**
1811
     * Gera as tags para o elemento: "semData" (Entrega sem data definida)
1812
     * #70
1813
     * Nível: 3
1814
     *
1815
     * @return \DOMElement
1816
     */
1817
    public function tagsemData($std)
1818
    {
1819
1820
        $possible = [
1821
            'tpPer'
1822
        ];
1823
1824
        $std = $this->equilizeParameters($std, $possible);
1825
1826
        $identificador = '#70 <semData> - ';
1827
        $this->semData = $this->dom->createElement('semData');
1828
        $this->dom->addChild(
1829
            $this->semData,
1830
            'tpPer',
1831
            $std->tpPer,
1832
            true,
1833
            $identificador . 'Tipo de data/período programado para entrega'
1834
        );
1835
        return $this->semData;
1836
    }
1837
1838
    /**
1839
     * Gera as tags para o elemento: "comData" (Entrega com data definida)
1840
     * #72
1841
     * Nível: 3
1842
     *
1843
     * @return \DOMElement
1844
     */
1845
    public function tagcomData($std)
1846
    {
1847
1848
        $possible = [
1849
            'tpPer',
1850
            'dProg'
1851
        ];
1852
1853
        $std = $this->equilizeParameters($std, $possible);
1854
1855
        $identificador = '#72 <comData> - ';
1856
        $this->comData = $this->dom->createElement('comData');
1857
        $this->dom->addChild(
1858
            $this->comData,
1859
            'tpPer',
1860
            $std->tpPer,
1861
            true,
1862
            $identificador . 'Tipo de data/período programado para entrega'
1863
        );
1864
        $this->dom->addChild(
1865
            $this->comData,
1866
            'dProg',
1867
            $std->dProg,
1868
            true,
1869
            $identificador . 'Data programada'
1870
        );
1871
        return $this->comData;
1872
    }
1873
1874
    /**
1875
     * Gera as tags para o elemento: "noPeriodo" (Entrega no período definido)
1876
     * #75
1877
     * Nível: 3
1878
     *
1879
     * @return \DOMElement
1880
     */
1881
    public function tagnoPeriodo($std)
1882
    {
1883
1884
        $possible = [
1885
            'tpPer',
1886
            'dIni',
1887
            'dFim'
1888
        ];
1889
1890
        $std = $this->equilizeParameters($std, $possible);
1891
1892
        $identificador = '#75 <noPeriodo> - ';
1893
        $this->noPeriodo = $this->dom->createElement('noPeriodo');
1894
        $this->dom->addChild(
1895
            $this->noPeriodo,
1896
            'tpPer',
1897
            $std->tpPer,
1898
            true,
1899
            $identificador . 'Tipo de data/período programado para entrega'
1900
        );
1901
        $this->dom->addChild(
1902
            $this->noPeriodo,
1903
            'dIni',
1904
            $std->dIni,
1905
            true,
1906
            $identificador . 'Data inicial'
1907
        );
1908
        $this->dom->addChild(
1909
            $this->noPeriodo,
1910
            'dFim',
1911
            $std->dFim,
1912
            true,
1913
            $identificador . 'Data final'
1914
        );
1915
        return $this->noPeriodo;
1916
    }
1917
1918
    /**
1919
     * Gera as tags para o elemento: "semHora" (Entrega sem hora definida)
1920
     * #79
1921
     * Nível: 3
1922
     * Os parâmetros para esta função são todos os elementos da tag "semHora" do
1923
     * tipo elemento (Ele = E|CE|A) e nível 4
1924
     *
1925
     * @return \DOMElement
1926
     */
1927
    public function tagsemHora($std)
1928
    {
1929
1930
        $possible = [
1931
            'tpHor'
1932
        ];
1933
1934
        $std = $this->equilizeParameters($std, $possible);
1935
1936
        $identificador = '#79 <semHora> - ';
1937
        $this->semHora = $this->dom->createElement('semHora');
1938
        $this->dom->addChild(
1939
            $this->semHora,
1940
            'tpHor',
1941
            $std->tpHor,
1942
            true,
1943
            $identificador . 'Tipo de hora'
1944
        );
1945
        return $this->semHora;
1946
    }
1947
1948
    /**
1949
     * Gera as tags para o elemento: "comHora" (Entrega sem hora definida)
1950
     * # = 81
1951
     * Nível = 3
1952
     * Os parâmetros para esta função são todos os elementos da tag "comHora" do
1953
     * tipo elemento (Ele = E|CE|A) e nível 4
1954
     *
1955
     * @return \DOMElement
1956
     */
1957
    public function tagcomHora($std)
1958
    {
1959
1960
        $possible = [
1961
            'tpHor',
1962
            'hProg'
1963
        ];
1964
1965
        $std = $this->equilizeParameters($std, $possible);
1966
1967
        $identificador = '#81 <comHora> - ';
1968
        $this->comHora = $this->dom->createElement('comHora');
1969
        $this->dom->addChild(
1970
            $this->comHora,
1971
            'tpHor',
1972
            $std->tpHor,
1973
            true,
1974
            $identificador . 'Tipo de hora'
1975
        );
1976
        $this->dom->addChild(
1977
            $this->comHora,
1978
            'hProg',
1979
            $std->hProg,
1980
            true,
1981
            $identificador . 'Hora programada'
1982
        );
1983
        return $this->comHora;
1984
    }
1985
1986
    /**
1987
     * Gera as tags para o elemento: "noInter" (Entrega no intervalo de horário definido)
1988
     * #84
1989
     * Nível: 3
1990
     * Os parâmetros para esta função são todos os elementos da tag "noInter" do
1991
     * tipo elemento (Ele = E|CE|A) e nível 4
1992
     *
1993
     * @return \DOMElement
1994
     */
1995
    public function tagnoInter($std)
1996
    {
1997
1998
        $possible = [
1999
            'tpHor',
2000
            'hIni',
2001
            'hFim'
2002
        ];
2003
2004
        $std = $this->equilizeParameters($std, $possible);
2005
2006
        $identificador = '#84 <noInter> - ';
2007
        $this->noInter = $this->dom->createElement('noInter');
2008
        $this->dom->addChild(
2009
            $this->noInter,
2010
            'tpHor',
2011
            $std->tpHor,
2012
            true,
2013
            $identificador . 'Tipo de hora'
2014
        );
2015
        $this->dom->addChild(
2016
            $this->noInter,
2017
            'hIni',
2018
            $std->hIni,
2019
            true,
2020
            $identificador . 'Hora inicial'
2021
        );
2022
        $this->dom->addChild(
2023
            $this->noInter,
2024
            'hFim',
2025
            $std->hFim,
2026
            true,
2027
            $identificador . 'Hora final'
2028
        );
2029
        return $this->noInter;
2030
    }
2031
2032
    /**
2033
     * Gera as tags para o elemento: "ObsCont" (Campo de uso livre do contribuinte)
2034
     * #91
2035
     * Nível: 2
2036
     * Os parâmetros para esta função são todos os elementos da tag "ObsCont" do
2037
     * tipo elemento (Ele = E|CE|A) e nível 3
2038
     *
2039
     * @return boolean
2040
     */
2041
    public function tagobsCont($std)
2042
    {
2043
2044
        $possible = [
2045
            'xCampo',
2046
            'xTexto'
2047
        ];
2048
2049
        $std = $this->equilizeParameters($std, $possible);
2050
2051
        $identificador = '#91 <ObsCont> - ';
2052
        if (count($this->obsCont) <= 10) {
2053
            $this->obsCont[] = $this->dom->createElement('ObsCont');
2054
            $posicao = (int)count($this->obsCont) - 1;
2055
            $this->obsCont[$posicao]->setAttribute('xCampo', $std->xCampo);
2056
            $this->dom->addChild(
2057
                $this->obsCont[$posicao],
2058
                'xTexto',
2059
                $std->xTexto,
2060
                true,
2061
                $identificador . 'Conteúdo do campo'
2062
            );
2063
            return true;
2064
        }
2065
        $this->errors[] = array(
2066
            'tag' => (string)'<ObsCont>',
2067
            'desc' => (string)'Campo de uso livre do contribuinte',
2068
            'erro' => (string)'Tag deve aparecer de 0 a 10 vezes'
2069
        );
2070
        return false;
2071
    }
2072
2073
    /**
2074
     * Gera as tags para o elemento: "ObsFisco" (Campo de uso livre do contribuinte)
2075
     * #94
2076
     * Nível: 2
2077
     * Os parâmetros para esta função são todos os elementos da tag "ObsFisco" do tipo
2078
     * elemento (Ele = E|CE|A) e nível 3
2079
     *
2080
     * @return boolean
2081
     */
2082
    public function tagobsFisco($std)
2083
    {
2084
2085
        $possible = [
2086
            'xCampo',
2087
            'xTexto'
2088
        ];
2089
2090
        $std = $this->equilizeParameters($std, $possible);
2091
2092
        $identificador = '#94 <ObsFisco> - ';
2093
        if (count($this->obsFisco) <= 10) {
2094
            $this->obsFisco[] = $this->dom->createElement('ObsFisco');
2095
            $posicao = (int)count($this->obsFisco) - 1;
2096
            $this->obsFisco[$posicao]->setAttribute('xCampo', $std->xCampo);
2097
            $this->dom->addChild(
2098
                $this->obsFisco[$posicao],
2099
                'xTexto',
2100
                $std->xTexto,
2101
                true,
2102
                $identificador . 'Conteúdo do campo'
2103
            );
2104
            return true;
2105
        }
2106
        $this->errors[] = array(
2107
            'tag' => (string)'<ObsFisco>',
2108
            'desc' => (string)'Campo de uso livre do contribuinte',
2109
            'erro' => (string)'Tag deve aparecer de 0 a 10 vezes'
2110
        );
2111
        return false;
2112
    }
2113
2114
    /**
2115
     * Gera as tags para o elemento: "emit" (Identificação do Emitente do CT-e)
2116
     * #97
2117
     * Nível: 1
2118
     * Os parâmetros para esta função são todos os elementos da tag "emit" do
2119
     * tipo elemento (Ele = E|CE|A) e nível 2
2120
     *
2121
     * @return \DOMElement
2122
     */
2123
    public function tagemit($std)
2124
    {
2125
2126
        $possible = [
2127
            'CNPJ',
2128
            'IE',
2129
            'IEST',
2130
            'xNome',
2131
            'xFant'
2132
        ];
2133
2134
        $std = $this->equilizeParameters($std, $possible);
2135
2136
        $identificador = '#97 <emit> - ';
2137
        $this->emit = $this->dom->createElement('emit');
2138
        $this->dom->addChild(
2139
            $this->emit,
2140
            'CNPJ',
2141
            $std->CNPJ,
2142
            true,
2143
            $identificador . 'CNPJ do emitente'
2144
        );
2145
        $this->dom->addChild(
2146
            $this->emit,
2147
            'IE',
2148
            Strings::onlyNumbers($std->IE),
2149
            false,
2150
            $identificador . 'Inscrição Estadual do Emitente'
2151
        );
2152
        $this->dom->addChild(
2153
            $this->emit,
2154
            'IEST',
2155
            Strings::onlyNumbers($std->IEST),
2156
            false,
2157
            $identificador . 'Inscrição Estadual do Substituto Tributário'
2158
        );
2159
        $this->dom->addChild(
2160
            $this->emit,
2161
            'xNome',
2162
            $std->xNome,
2163
            true,
2164
            $identificador . 'Razão social ou Nome do emitente'
2165
        );
2166
        $this->dom->addChild(
2167
            $this->emit,
2168
            'xFant',
2169
            $std->xFant,
2170
            false,
2171
            $identificador . 'Nome fantasia'
2172
        );
2173
        return $this->emit;
2174
    }
2175
2176
    /**
2177
     * Gera as tags para o elemento: "enderEmit" (Endereço do emitente)
2178
     * #102
2179
     * Nível: 2
2180
     * Os parâmetros para esta função são todos os elementos da tag "enderEmit" do
2181
     * tipo elemento (Ele = E|CE|A) e nível 3
2182
     *
2183
     * @return \DOMElement
2184
     */
2185
    public function tagenderEmit($std)
2186
    {
2187
2188
        $possible = [
2189
            'xLgr',
2190
            'nro',
2191
            'xCpl',
2192
            'xBairro',
2193
            'cMun',
2194
            'xMun',
2195
            'CEP',
2196
            'UF',
2197
            'fone'
2198
        ];
2199
2200
        $std = $this->equilizeParameters($std, $possible);
2201
2202
        $identificador = '#102 <enderEmit> - ';
2203
        $this->enderEmit = $this->dom->createElement('enderEmit');
2204
        $this->dom->addChild(
2205
            $this->enderEmit,
2206
            'xLgr',
2207
            $std->xLgr,
2208
            true,
2209
            $identificador . 'Logradouro'
2210
        );
2211
        $this->dom->addChild(
2212
            $this->enderEmit,
2213
            'nro',
2214
            $std->nro,
2215
            true,
2216
            $identificador . 'Número'
2217
        );
2218
        $this->dom->addChild(
2219
            $this->enderEmit,
2220
            'xCpl',
2221
            $std->xCpl,
2222
            false,
2223
            $identificador . 'Complemento'
2224
        );
2225
        $this->dom->addChild(
2226
            $this->enderEmit,
2227
            'xBairro',
2228
            $std->xBairro,
2229
            true,
2230
            $identificador . 'Bairro'
2231
        );
2232
        $this->dom->addChild(
2233
            $this->enderEmit,
2234
            'cMun',
2235
            $std->cMun,
2236
            true,
2237
            $identificador . 'Código do município'
2238
        );
2239
        $this->dom->addChild(
2240
            $this->enderEmit,
2241
            'xMun',
2242
            $std->xMun,
2243
            true,
2244
            $identificador . 'Nome do município'
2245
        );
2246
        $this->dom->addChild(
2247
            $this->enderEmit,
2248
            'CEP',
2249
            $std->CEP,
2250
            false,
2251
            $identificador . 'CEP'
2252
        );
2253
        $this->dom->addChild(
2254
            $this->enderEmit,
2255
            'UF',
2256
            $std->UF,
2257
            true,
2258
            $identificador . 'Sigla da UF'
2259
        );
2260
        $this->dom->addChild(
2261
            $this->enderEmit,
2262
            'fone',
2263
            $std->fone,
2264
            false,
2265
            $identificador . 'Telefone'
2266
        );
2267
        return $this->enderEmit;
2268
    }
2269
2270
    /**
2271
     * Gera as tags para o elemento: "rem" (Informações do Remetente das mercadorias
2272
     * transportadas pelo CT-e)
2273
     * #112
2274
     * Nível = 1
2275
     * Os parâmetros para esta função são todos os elementos da tag "rem" do
2276
     * tipo elemento (Ele = E|CE|A) e nível 2
2277
     *
2278
     * @return \DOMElement
2279
     */
2280
    public function tagrem($std)
2281
    {
2282
2283
        $possible = [
2284
            'CNPJ',
2285
            'CPF',
2286
            'IE',
2287
            'xNome',
2288
            'xFant',
2289
            'fone',
2290
            'email'
2291
        ];
2292
2293
        $std = $this->equilizeParameters($std, $possible);
2294
2295
        $identificador = '#97 <rem> - ';
2296
        $this->rem = $this->dom->createElement('rem');
2297
        if ($std->CNPJ != '') {
2298
            $this->dom->addChild(
2299
                $this->rem,
2300
                'CNPJ',
2301
                $std->CNPJ,
2302
                true,
2303
                $identificador . 'CNPJ do Remente'
2304
            );
2305
        } elseif ($std->CPF != '') {
2306
            $this->dom->addChild(
2307
                $this->rem,
2308
                'CPF',
2309
                $std->CPF,
2310
                true,
2311
                $identificador . 'CPF do Remente'
2312
            );
2313
        } else {
2314
            $this->dom->addChild(
2315
                $this->rem,
2316
                'CNPJ',
2317
                $std->CNPJ,
2318
                true,
2319
                $identificador . 'CNPJ do Remente'
2320
            );
2321
            $this->dom->addChild(
2322
                $this->rem,
2323
                'CPF',
2324
                $std->CPF,
2325
                true,
2326
                $identificador . 'CPF do remente'
2327
            );
2328
        }
2329
        $this->dom->addChild(
2330
            $this->rem,
2331
            'IE',
2332
            $std->IE,
2333
            false,
2334
            $identificador . 'Inscrição Estadual do remente'
2335
        );
2336
        $xNome = $std->xNome;
2337
        if ($this->tpAmb == '2') {
2338
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2339
        }
2340
        $this->dom->addChild(
2341
            $this->rem,
2342
            'xNome',
2343
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2344
            true,
2345
            $identificador . 'Razão social ou Nome do remente'
2346
        );
2347
        $this->dom->addChild(
2348
            $this->rem,
2349
            'xFant',
2350
            $std->xFant,
2351
            false,
2352
            $identificador . 'Nome fantasia'
2353
        );
2354
        $this->dom->addChild(
2355
            $this->rem,
2356
            'fone',
2357
            $std->fone,
2358
            false,
2359
            $identificador . 'Telefone'
2360
        );
2361
        $this->dom->addChild(
2362
            $this->rem,
2363
            'email',
2364
            $std->email,
2365
            false,
2366
            $identificador . 'Endereço de email'
2367
        );
2368
        return $this->rem;
2369
    }
2370
2371
    /**
2372
     * Gera as tags para o elemento: "enderReme" (Dados do endereço)
2373
     * #120
2374
     * Nível: 2
2375
     * Os parâmetros para esta função são todos os elementos da tag "enderReme" do
2376
     * tipo elemento (Ele = E|CE|A) e nível 3
2377
     *
2378
     * @return \DOMElement
2379
     */
2380
    public function tagenderReme($std)
2381
    {
2382
2383
        $possible = [
2384
            'xLgr',
2385
            'nro',
2386
            'xCpl',
2387
            'xBairro',
2388
            'cMun',
2389
            'xMun',
2390
            'CEP',
2391
            'UF',
2392
            'cPais',
2393
            'xPais'
2394
        ];
2395
2396
        $std = $this->equilizeParameters($std, $possible);
2397
2398
        $identificador = '#119 <enderReme> - ';
2399
        $this->enderReme = $this->dom->createElement('enderReme');
2400
        $this->dom->addChild(
2401
            $this->enderReme,
2402
            'xLgr',
2403
            $std->xLgr,
2404
            true,
2405
            $identificador . 'Logradouro'
2406
        );
2407
        $this->dom->addChild(
2408
            $this->enderReme,
2409
            'nro',
2410
            $std->nro,
2411
            true,
2412
            $identificador . 'Número'
2413
        );
2414
        $this->dom->addChild(
2415
            $this->enderReme,
2416
            'xCpl',
2417
            $std->xCpl,
2418
            false,
2419
            $identificador . 'Complemento'
2420
        );
2421
        $this->dom->addChild(
2422
            $this->enderReme,
2423
            'xBairro',
2424
            $std->xBairro,
2425
            true,
2426
            $identificador . 'Bairro'
2427
        );
2428
        $this->dom->addChild(
2429
            $this->enderReme,
2430
            'cMun',
2431
            $std->cMun,
2432
            true,
2433
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2434
        );
2435
        $this->dom->addChild(
2436
            $this->enderReme,
2437
            'xMun',
2438
            $std->xMun,
2439
            true,
2440
            $identificador . 'Nome do município'
2441
        );
2442
        $this->dom->addChild(
2443
            $this->enderReme,
2444
            'CEP',
2445
            $std->CEP,
2446
            false,
2447
            $identificador . 'CEP'
2448
        );
2449
        $this->dom->addChild(
2450
            $this->enderReme,
2451
            'UF',
2452
            $std->UF,
2453
            true,
2454
            $identificador . 'Sigla da UF'
2455
        );
2456
        $this->dom->addChild(
2457
            $this->enderReme,
2458
            'cPais',
2459
            $std->cPais,
2460
            false,
2461
            $identificador . 'Código do país'
2462
        );
2463
        $this->dom->addChild(
2464
            $this->enderReme,
2465
            'xPais',
2466
            $std->xPais,
2467
            false,
2468
            $identificador . 'Nome do país'
2469
        );
2470
2471
        $node = $this->rem->getElementsByTagName("email")->item(0);
2472
        $this->rem->insertBefore($this->enderReme, $node);
2473
        return $this->enderReme;
2474
    }
2475
2476
    /**
2477
     * Gera as tags para o elemento: "exped" (Informações do Expedidor da Carga)
2478
     * #132
2479
     * Nível: 1
2480
     * Os parâmetros para esta função são todos os elementos da tag "exped" do
2481
     * tipo elemento (Ele = E|CE|A) e nível 2
2482
     *
2483
     * @return \DOMElement
2484
     */
2485
    public function tagexped($std)
2486
    {
2487
2488
        $possible = [
2489
            'CNPJ',
2490
            'CPF',
2491
            'IE',
2492
            'xNome',
2493
            'fone',
2494
            'email'
2495
        ];
2496
2497
        $std = $this->equilizeParameters($std, $possible);
2498
2499
        $identificador = '#142 <exped> - ';
2500
        $this->exped = $this->dom->createElement('exped');
2501
        if ($std->CNPJ != '') {
2502
            $this->dom->addChild(
2503
                $this->exped,
2504
                'CNPJ',
2505
                $std->CNPJ,
2506
                true,
2507
                $identificador . 'Número do CNPJ'
2508
            );
2509
        } elseif ($std->CPF != '') {
2510
            $this->dom->addChild(
2511
                $this->exped,
2512
                'CPF',
2513
                $std->CPF,
2514
                true,
2515
                $identificador . 'Número do CPF'
2516
            );
2517
        } else {
2518
            $this->dom->addChild(
2519
                $this->exped,
2520
                'CNPJ',
2521
                $std->CNPJ,
2522
                true,
2523
                $identificador . 'Número do CNPJ'
2524
            );
2525
            $this->dom->addChild(
2526
                $this->exped,
2527
                'CPF',
2528
                $std->CPF,
2529
                true,
2530
                $identificador . 'Número do CPF'
2531
            );
2532
        }
2533
        if (!empty($std->IE)) {
2534
            $this->dom->addChild(
2535
                $this->exped,
2536
                'IE',
2537
                $std->IE,
2538
                true,
2539
                $identificador . 'Inscrição Estadual'
2540
            );
2541
        }
2542
        $xNome = $std->xNome;
2543
        if ($this->tpAmb == '2') {
2544
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2545
        }
2546
        $this->dom->addChild(
2547
            $this->exped,
2548
            'xNome',
2549
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2550
            true,
2551
            $identificador . 'Razão social ou Nome'
2552
        );
2553
        $this->dom->addChild(
2554
            $this->exped,
2555
            'fone',
2556
            $std->fone,
2557
            false,
2558
            $identificador . 'Telefone'
2559
        );
2560
        $this->dom->addChild(
2561
            $this->exped,
2562
            'email',
2563
            $std->email,
2564
            false,
2565
            $identificador . 'Endereço de email'
2566
        );
2567
        return $this->exped;
2568
    }
2569
2570
    /**
2571
     * Gera as tags para o elemento: "enderExped" (Dados do endereço)
2572
     * #138
2573
     * Nível: 2
2574
     * Os parâmetros para esta função são todos os elementos da tag "enderExped" do
2575
     * tipo elemento (Ele = E|CE|A) e nível 3
2576
     *
2577
     * @return \DOMElement
2578
     */
2579
    public function tagenderExped($std)
2580
    {
2581
2582
        $possible = [
2583
            'xLgr',
2584
            'nro',
2585
            'xCpl',
2586
            'xBairro',
2587
            'cMun',
2588
            'xMun',
2589
            'CEP',
2590
            'UF',
2591
            'cPais',
2592
            'xPais'
2593
        ];
2594
2595
        $std = $this->equilizeParameters($std, $possible);
2596
2597
        $identificador = '#148 <enderExped> - ';
2598
        $this->enderExped = $this->dom->createElement('enderExped');
2599
        $this->dom->addChild(
2600
            $this->enderExped,
2601
            'xLgr',
2602
            $std->xLgr,
2603
            true,
2604
            $identificador . 'Logradouro'
2605
        );
2606
        $this->dom->addChild(
2607
            $this->enderExped,
2608
            'nro',
2609
            $std->nro,
2610
            true,
2611
            $identificador . 'Número'
2612
        );
2613
        $this->dom->addChild(
2614
            $this->enderExped,
2615
            'xCpl',
2616
            $std->xCpl,
2617
            false,
2618
            $identificador . 'Complemento'
2619
        );
2620
        $this->dom->addChild(
2621
            $this->enderExped,
2622
            'xBairro',
2623
            $std->xBairro,
2624
            true,
2625
            $identificador . 'Bairro'
2626
        );
2627
        $this->dom->addChild(
2628
            $this->enderExped,
2629
            'cMun',
2630
            $std->cMun,
2631
            true,
2632
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2633
        );
2634
        $this->dom->addChild(
2635
            $this->enderExped,
2636
            'xMun',
2637
            $std->xMun,
2638
            true,
2639
            $identificador . 'Nome do município'
2640
        );
2641
        $this->dom->addChild(
2642
            $this->enderExped,
2643
            'CEP',
2644
            $std->CEP,
2645
            false,
2646
            $identificador . 'CEP'
2647
        );
2648
        $this->dom->addChild(
2649
            $this->enderExped,
2650
            'UF',
2651
            $std->UF,
2652
            true,
2653
            $identificador . 'Sigla da UF'
2654
        );
2655
        $this->dom->addChild(
2656
            $this->enderExped,
2657
            'cPais',
2658
            $std->cPais,
2659
            false,
2660
            $identificador . 'Código do país'
2661
        );
2662
        $this->dom->addChild(
2663
            $this->enderExped,
2664
            'xPais',
2665
            $std->xPais,
2666
            false,
2667
            $identificador . 'Nome do país'
2668
        );
2669
        $node = $this->exped->getElementsByTagName("email")->item(0);
2670
        $this->exped->insertBefore($this->enderExped, $node);
2671
        return $this->enderExped;
2672
    }
2673
2674
    /**
2675
     * Gera as tags para o elemento: "receb" (Informações do Recebedor da Carga)
2676
     * #150
2677
     * Nível: 1
2678
     * Os parâmetros para esta função são todos os elementos da tag "receb" do
2679
     * tipo elemento (Ele = E|CE|A) e nível 2
2680
     *
2681
     * @return \DOMElement
2682
     */
2683
    public function tagreceb($std)
2684
    {
2685
2686
        $possible = [
2687
            'CNPJ',
2688
            'CPF',
2689
            'IE',
2690
            'xNome',
2691
            'fone',
2692
            'email'
2693
        ];
2694
2695
        $std = $this->equilizeParameters($std, $possible);
2696
2697
        $identificador = '#160 <receb> - ';
2698
        $this->receb = $this->dom->createElement('receb');
2699
        if ($std->CNPJ != '') {
2700
            $this->dom->addChild(
2701
                $this->receb,
2702
                'CNPJ',
2703
                $std->CNPJ,
2704
                true,
2705
                $identificador . 'Número do CNPJ'
2706
            );
2707
        } elseif ($std->CPF != '') {
2708
            $this->dom->addChild(
2709
                $this->receb,
2710
                'CPF',
2711
                $std->CPF,
2712
                true,
2713
                $identificador . 'Número do CPF'
2714
            );
2715
        } else {
2716
            $this->dom->addChild(
2717
                $this->receb,
2718
                'CNPJ',
2719
                $std->CNPJ,
2720
                true,
2721
                $identificador . 'Número do CNPJ'
2722
            );
2723
            $this->dom->addChild(
2724
                $this->receb,
2725
                'CPF',
2726
                $std->CPF,
2727
                true,
2728
                $identificador . 'Número do CPF'
2729
            );
2730
        }
2731
        if (!empty($std->IE)) {
2732
            $this->dom->addChild(
2733
                $this->receb,
2734
                'IE',
2735
                $std->IE,
2736
                true,
2737
                $identificador . 'Inscrição Estadual'
2738
            );
2739
        }
2740
        $xNome = $std->xNome;
2741
        if ($this->tpAmb == '2') {
2742
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2743
        }
2744
        $this->dom->addChild(
2745
            $this->receb,
2746
            'xNome',
2747
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2748
            true,
2749
            $identificador . 'Razão social ou Nome'
2750
        );
2751
        $this->dom->addChild(
2752
            $this->receb,
2753
            'fone',
2754
            $std->fone,
2755
            false,
2756
            $identificador . 'Telefone'
2757
        );
2758
        $this->dom->addChild(
2759
            $this->receb,
2760
            'email',
2761
            $std->email,
2762
            false,
2763
            $identificador . 'Endereço de email'
2764
        );
2765
        return $this->receb;
2766
    }
2767
2768
    /**
2769
     * Gera as tags para o elemento: "enderReceb" (Informações do Recebedor da Carga)
2770
     * #156
2771
     * Nível: 2
2772
     * Os parâmetros para esta função são todos os elementos da tag "enderReceb" do
2773
     * tipo elemento (Ele = E|CE|A) e nível 3
2774
     *
2775
     * @return \DOMElement
2776
     */
2777
    public function tagenderReceb($std)
2778
    {
2779
2780
        $possible = [
2781
            'xLgr',
2782
            'nro',
2783
            'xCpl',
2784
            'xBairro',
2785
            'cMun',
2786
            'xMun',
2787
            'CEP',
2788
            'UF',
2789
            'cPais',
2790
            'xPais'
2791
        ];
2792
2793
        $std = $this->equilizeParameters($std, $possible);
2794
2795
        $identificador = '#160 <enderReceb> - ';
2796
        $this->enderReceb = $this->dom->createElement('enderReceb');
2797
        $this->dom->addChild(
2798
            $this->enderReceb,
2799
            'xLgr',
2800
            $std->xLgr,
2801
            true,
2802
            $identificador . 'Logradouro'
2803
        );
2804
        $this->dom->addChild(
2805
            $this->enderReceb,
2806
            'nro',
2807
            $std->nro,
2808
            true,
2809
            $identificador . 'Número'
2810
        );
2811
        $this->dom->addChild(
2812
            $this->enderReceb,
2813
            'xCpl',
2814
            $std->xCpl,
2815
            false,
2816
            $identificador . 'Complemento'
2817
        );
2818
        $this->dom->addChild(
2819
            $this->enderReceb,
2820
            'xBairro',
2821
            $std->xBairro,
2822
            true,
2823
            $identificador . 'Bairro'
2824
        );
2825
        $this->dom->addChild(
2826
            $this->enderReceb,
2827
            'cMun',
2828
            $std->cMun,
2829
            true,
2830
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
2831
        );
2832
        $this->dom->addChild(
2833
            $this->enderReceb,
2834
            'xMun',
2835
            $std->xMun,
2836
            true,
2837
            $identificador . 'Nome do município'
2838
        );
2839
        $this->dom->addChild(
2840
            $this->enderReceb,
2841
            'CEP',
2842
            $std->CEP,
2843
            false,
2844
            $identificador . 'CEP'
2845
        );
2846
        $this->dom->addChild(
2847
            $this->enderReceb,
2848
            'UF',
2849
            $std->UF,
2850
            true,
2851
            $identificador . 'Sigla da UF'
2852
        );
2853
        $this->dom->addChild(
2854
            $this->enderReceb,
2855
            'cPais',
2856
            $std->cPais,
2857
            false,
2858
            $identificador . 'Código do país'
2859
        );
2860
        $this->dom->addChild(
2861
            $this->enderReceb,
2862
            'xPais',
2863
            $std->xPais,
2864
            false,
2865
            $identificador . 'Nome do país'
2866
        );
2867
        $node = $this->receb->getElementsByTagName("email")->item(0);
2868
        $this->receb->insertBefore($this->enderReceb, $node);
2869
        return $this->enderReceb;
2870
    }
2871
2872
    /**
2873
     * Gera as tags para o elemento: "dest" (Informações do Destinatário do CT-e)
2874
     * #168
2875
     * Nível: 1
2876
     * Os parâmetros para esta função são todos os elementos da tag "dest" do
2877
     * tipo elemento (Ele = E|CE|A) e nível 2
2878
     *
2879
     * @return \DOMElement
2880
     */
2881
    public function tagdest($std)
2882
    {
2883
2884
        $possible = [
2885
            'CNPJ',
2886
            'CPF',
2887
            'IE',
2888
            'xNome',
2889
            'fone',
2890
            'ISUF',
2891
            'email'
2892
        ];
2893
2894
        $std = $this->equilizeParameters($std, $possible);
2895
2896
        $identificador = '#178 <dest> - ';
2897
        $this->dest = $this->dom->createElement('dest');
2898
        if ($std->CNPJ != '') {
2899
            $this->dom->addChild(
2900
                $this->dest,
2901
                'CNPJ',
2902
                $std->CNPJ,
2903
                true,
2904
                $identificador . 'Número do CNPJ'
2905
            );
2906
        } elseif ($std->CPF != '') {
2907
            $this->dom->addChild(
2908
                $this->dest,
2909
                'CPF',
2910
                $std->CPF,
2911
                true,
2912
                $identificador . 'Número do CPF'
2913
            );
2914
        } else {
2915
            $this->dom->addChild(
2916
                $this->dest,
2917
                'CNPJ',
2918
                $std->CNPJ,
2919
                true,
2920
                $identificador . 'Número do CNPJ'
2921
            );
2922
            $this->dom->addChild(
2923
                $this->dest,
2924
                'CPF',
2925
                $std->CPF,
2926
                true,
2927
                $identificador . 'Número do CPF'
2928
            );
2929
        }
2930
        if (!empty($std->IE)) {
2931
            $this->dom->addChild(
2932
                $this->dest,
2933
                'IE',
2934
                $std->IE,
2935
                true,
2936
                $identificador . 'Inscrição Estadual'
2937
            );
2938
        }
2939
        $xNome = $std->xNome;
2940
        if ($this->tpAmb == '2') {
2941
            $xNome = 'CT-E EMITIDO EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
2942
        }
2943
        $this->dom->addChild(
2944
            $this->dest,
2945
            'xNome',
2946
            Strings::replaceSpecialsChars(substr(trim($xNome), 0, 60)),
2947
            true,
2948
            $identificador . 'Razão social ou Nome'
2949
        );
2950
        $this->dom->addChild(
2951
            $this->dest,
2952
            'fone',
2953
            $std->fone,
2954
            false,
2955
            $identificador . 'Telefone'
2956
        );
2957
        $this->dom->addChild(
2958
            $this->dest,
2959
            'ISUF',
2960
            $std->ISUF,
2961
            false,
2962
            $identificador . 'Inscrição na SUFRAMA'
2963
        );
2964
        $this->dom->addChild(
2965
            $this->dest,
2966
            'email',
2967
            $std->email,
2968
            false,
2969
            $identificador . 'Endereço de email'
2970
        );
2971
        return $this->dest;
2972
    }
2973
2974
    /**
2975
     * Gera as tags para o elemento: "enderDest" (Informações do Recebedor da Carga)
2976
     * # = 175
2977
     * Nível = 2
2978
     * Os parâmetros para esta função são todos os elementos da tag "enderDest" do
2979
     * tipo elemento (Ele = E|CE|A) e nível 3
2980
     *
2981
     * @return \DOMElement
2982
     */
2983
    public function tagenderDest($std)
2984
    {
2985
2986
        $possible = [
2987
            'xLgr',
2988
            'nro',
2989
            'xCpl',
2990
            'xBairro',
2991
            'cMun',
2992
            'xMun',
2993
            'CEP',
2994
            'UF',
2995
            'cPais',
2996
            'xPais'
2997
        ];
2998
2999
        $std = $this->equilizeParameters($std, $possible);
3000
3001
        $identificador = '#185 <enderDest> - ';
3002
        $this->enderDest = $this->dom->createElement('enderDest');
3003
        $this->dom->addChild(
3004
            $this->enderDest,
3005
            'xLgr',
3006
            $std->xLgr,
3007
            true,
3008
            $identificador . 'Logradouro'
3009
        );
3010
        $this->dom->addChild(
3011
            $this->enderDest,
3012
            'nro',
3013
            $std->nro,
3014
            true,
3015
            $identificador . 'Número'
3016
        );
3017
        $this->dom->addChild(
3018
            $this->enderDest,
3019
            'xCpl',
3020
            $std->xCpl,
3021
            false,
3022
            $identificador . 'Complemento'
3023
        );
3024
        $this->dom->addChild(
3025
            $this->enderDest,
3026
            'xBairro',
3027
            $std->xBairro,
3028
            true,
3029
            $identificador . 'Bairro'
3030
        );
3031
        $this->dom->addChild(
3032
            $this->enderDest,
3033
            'cMun',
3034
            $std->cMun,
3035
            true,
3036
            $identificador . 'Código do município (utilizar a tabela do IBGE)'
3037
        );
3038
        $this->dom->addChild(
3039
            $this->enderDest,
3040
            'xMun',
3041
            $std->xMun,
3042
            true,
3043
            $identificador . 'Nome do município'
3044
        );
3045
        $this->dom->addChild(
3046
            $this->enderDest,
3047
            'CEP',
3048
            $std->CEP,
3049
            false,
3050
            $identificador . 'CEP'
3051
        );
3052
        $this->dom->addChild(
3053
            $this->enderDest,
3054
            'UF',
3055
            $std->UF,
3056
            true,
3057
            $identificador . 'Sigla da UF'
3058
        );
3059
        $this->dom->addChild(
3060
            $this->enderDest,
3061
            'cPais',
3062
            $std->cPais,
3063
            false,
3064
            $identificador . 'Código do país'
3065
        );
3066
        $this->dom->addChild(
3067
            $this->enderDest,
3068
            'xPais',
3069
            $std->xPais,
3070
            false,
3071
            $identificador . 'Nome do país'
3072
        );
3073
        $node = $this->dest->getElementsByTagName("email")->item(0);
3074
        $this->dest->insertBefore($this->enderDest, $node);
3075
        return $this->enderDest;
3076
    }
3077
3078
    /**
3079
     * Gera as tags para o elemento: "vPrest" (Valores da Prestação de Serviço)
3080
     * #187
3081
     * Nível: 1
3082
     * Os parâmetros para esta função são todos os elementos da tag "vPrest" do
3083
     * tipo elemento (Ele = E|CE|A) e nível 2
3084
     *
3085
     * @return \DOMElement
3086
     */
3087
    public function tagvPrest($std)
3088
    {
3089
3090
        $possible = [
3091
            'vTPrest',
3092
            'vRec'
3093
        ];
3094
3095
        $std = $this->equilizeParameters($std, $possible);
3096
3097
        $identificador = '#208 <vPrest> - ';
3098
        $this->vPrest = $this->dom->createElement('vPrest');
3099
        $this->dom->addChild(
3100
            $this->vPrest,
3101
            'vTPrest',
3102
            $std->vTPrest,
3103
            true,
3104
            $identificador . 'Valor Total da Prestação do Serviço'
3105
        );
3106
        $this->dom->addChild(
3107
            $this->vPrest,
3108
            'vRec',
3109
            $std->vRec,
3110
            true,
3111
            $identificador . 'Valor a Receber'
3112
        );
3113
        return $this->vPrest;
3114
    }
3115
3116
    /**
3117
     * Gera as tags para o elemento: "Comp" (Componentes do Valor da Prestação)
3118
     * #211
3119
     * Nível: 2
3120
     * Os parâmetros para esta função são todos os elementos da tag "Comp" do
3121
     * tipo elemento (Ele = E|CE|A) e nível 3
3122
     *
3123
     * @return \DOMElement
3124
     */
3125
    public function tagComp($std)
3126
    {
3127
3128
        $possible = [
3129
            'xNome',
3130
            'vComp'
3131
        ];
3132
3133
        $std = $this->equilizeParameters($std, $possible);
3134
3135
        $identificador = '#65 <pass> - ';
3136
        $this->comp[] = $this->dom->createElement('Comp');
3137
        $posicao = (int)count($this->comp) - 1;
3138
        $this->dom->addChild(
3139
            $this->comp[$posicao],
3140
            'xNome',
3141
            $std->xNome,
3142
            false,
3143
            $identificador . 'Nome do componente'
3144
        );
3145
        $this->dom->addChild(
3146
            $this->comp[$posicao],
3147
            'vComp',
3148
            $std->vComp,
3149
            false,
3150
            $identificador . 'Valor do componente'
3151
        );
3152
        return $this->comp[$posicao];
3153
    }
3154
3155
    /**
3156
     * tagICMS
3157
     * Informações relativas ao ICMS
3158
     * #194
3159
     *
3160
     * @return DOMElement
3161
     */
3162
    public function tagicms($std)
3163
    {
3164
3165
        $possible = [
3166
            'CST',
3167
            'vBC',
3168
            'pICMS',
3169
            'vICMS',
3170
            'pRedBC',
3171
            'vBCSTRet',
3172
            'vICMSSTRet',
3173
            'pICMSSTRet',
3174
            'vCred',
3175
            'pRedBCOutraUF',
3176
            'vBCOutraUF',
3177
            'pICMSOutraUF',
3178
            'vICMSOutraUF',
3179
            'pRedBC',
3180
            'vTotTrib',
3181
            'infAdFisco',
3182
            'vBCUFFim',
3183
            'pFCPUFFim',
3184
            'pICMSUFFim',
3185
            'pICMSInter',
3186
            'vFCPUFFim',
3187
            'vICMSUFFim',
3188
            'vICMSUFIni'
3189
        ];
3190
3191
        $std = $this->equilizeParameters($std, $possible);
3192
3193
        $identificador = 'N01 <ICMSxx> - ';
3194
        switch ($std->cst) {
3195
            case '00':
3196
                $icms = $this->dom->createElement("ICMS00");
3197
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 00");
3198
                $this->dom->addChild($icms, 'vBC', $std->vBC, true, "$identificador  Valor da BC do ICMS");
3199
                $this->dom->addChild($icms, 'pICMS', $std->pICMS, true, "$identificador  Alíquota do imposto");
3200
                $this->dom->addChild($icms, 'vICMS', $std->vICMS, true, "$identificador  Valor do ICMS");
3201
                break;
3202
            case '20':
3203
                $icms = $this->dom->createElement("ICMS20");
3204
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 20");
3205
                $this->dom->addChild(
3206
                    $icms,
3207
                    'pRedBC',
3208
                    $std->pRedBC,
3209
                    true,
3210
                    "$identificador  Percentual da Redução de BC"
3211
                );
3212
                $this->dom->addChild($icms, 'vBC', $std->vBC, true, "$identificador  Valor da BC do ICMS");
3213
                $this->dom->addChild($icms, 'pICMS', $std->pICMS, true, "$identificador  Alíquota do imposto");
3214
                $this->dom->addChild($icms, 'vICMS', $std->vICMS, true, "$identificador  Valor do ICMS");
3215
                break;
3216
            case '40':
3217
                $icms = $this->dom->createElement("ICMS45");
3218
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 40");
3219
                break;
3220
            case '41':
3221
                $icms = $this->dom->createElement("ICMS45");
3222
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 41");
3223
                break;
3224
            case '51':
3225
                $icms = $this->dom->createElement("ICMS45");
3226
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 51");
3227
                break;
3228
            case '60':
3229
                $icms = $this->dom->createElement("ICMS60");
3230
                $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 60");
3231
                $this->dom->addChild(
3232
                    $icms,
3233
                    'vBCSTRet',
3234
                    $std->vBCSTRet,
3235
                    true,
3236
                    "$identificador  Valor BC do ICMS ST retido"
3237
                );
3238
                $this->dom->addChild(
3239
                    $icms,
3240
                    'vICMSSTRet',
3241
                    $std->vICMSSTRet,
3242
                    true,
3243
                    "$identificador  Valor do ICMS ST retido"
3244
                );
3245
                $this->dom->addChild(
3246
                    $icms,
3247
                    'pICMSSTRet',
3248
                    $std->pICMSSTRet,
3249
                    true,
3250
                    "$identificador  Valor do ICMS ST retido"
3251
                );
3252
                if ($std->vCred > 0) {
3253
                    $this->dom->addChild($icms, 'vCred', $std->vCred, false, "$identificador  Valor do Crédito");
3254
                }
3255
                break;
3256
            case '90':
3257
                if ($std->outraUF == true) {
3258
                    $icms = $this->dom->createElement("ICMSOutraUF");
3259
                    $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador  Tributação do ICMS = 90");
3260
                    if ($std->pRedBC > 0) {
3261
                        $this->dom->addChild(
3262
                            $icms,
3263
                            'pRedBCOutraUF',
3264
                            $std->pRedBCOutraUF,
3265
                            false,
3266
                            "$identificador Percentual Red "
3267
                            . "BC Outra UF"
3268
                        );
3269
                    }
3270
                    $this->dom->addChild($icms, 'vBCOutraUF', $std->vBC, true, "$identificador Valor BC ICMS Outra UF");
3271
                    $this->dom->addChild($icms, 'pICMSOutraUF', $std->pICMS, true, "$identificador Alíquota do "
3272
                        . "imposto Outra UF");
3273
                    $this->dom->addChild(
3274
                        $icms,
3275
                        'vICMSOutraUF',
3276
                        $std->vICMS,
3277
                        true,
3278
                        "$identificador Valor ICMS Outra UF"
3279
                    );
3280
                } else {
3281
                    $icms = $this->dom->createElement("ICMS90");
3282
                    $this->dom->addChild($icms, 'CST', $std->cst, true, "$identificador Tributação do ICMS = 90");
3283
                    if ($std->pRedBC > 0) {
3284
                        $this->dom->addChild(
3285
                            $icms,
3286
                            'pRedBC',
3287
                            $std->pRedBC,
3288
                            false,
3289
                            "$identificador Percentual Redução BC"
3290
                        );
3291
                    }
3292
                    $this->dom->addChild($icms, 'vBC', $std->vBC, true, "$identificador  Valor da BC do ICMS");
3293
                    $this->dom->addChild($icms, 'pICMS', $std->pICMS, true, "$identificador  Alíquota do imposto");
3294
                    $this->dom->addChild($icms, 'vICMS', $std->vICMS, true, "$identificador  Valor do ICMS");
3295
                    if ($std->vCred > 0) {
3296
                        $this->dom->addChild($icms, 'vCred', $std->vCred, false, "$identificador  Valor do Crédido");
3297
                    }
3298
                }
3299
                break;
3300
            case 'SN':
3301
                $icms = $this->dom->createElement("ICMSSN");
3302
                $this->dom->addChild($icms, 'CST', 90, true, "$identificador Tributação do ICMS = 90");
3303
                $this->dom->addChild($icms, 'indSN', '1', true, "$identificador  Indica se contribuinte é SN");
3304
                break;
3305
        }
3306
        $this->imp = $this->dom->createElement('imp');
3307
        $tagIcms = $this->dom->createElement('ICMS');
3308
        if (isset($icms)) {
3309
            $this->imp->appendChild($tagIcms);
3310
        }
3311
        if (isset($icms)) {
3312
            $tagIcms->appendChild($icms);
3313
        }
3314
        if ($std->vTotTrib > 0) {
3315
            $this->dom->addChild(
3316
                $this->imp,
3317
                'vTotTrib',
3318
                $std->vTotTrib,
3319
                false,
3320
                "$identificador Valor Total dos Tributos"
3321
            );
3322
        }
3323
        if (isset($std->infAdFisco)) {
3324
            $this->dom->addChild(
3325
                $this->imp,
3326
                'infAdFisco',
3327
                $std->infAdFisco,
3328
                false,
3329
                "$identificador Informações adicionais de interesse do Fisco"
3330
            );
3331
        }
3332
3333
        if ($std->vICMSUFFim != '' || $std->vICMSUFIni != '') {
3334
            $icmsDifal = $this->dom->createElement("ICMSUFFim");
3335
            $this->dom->addChild(
3336
                $icmsDifal,
3337
                'vBCUFFim',
3338
                $std->vBCUFFim,
3339
                true,
3340
                "$identificador Valor da BC do ICMS na UF
3341
                de término da prestação do serviço de transporte"
3342
            );
3343
            $this->dom->addChild(
3344
                $icmsDifal,
3345
                'pFCPUFFim',
3346
                $std->pFCPUFFim,
3347
                true,
3348
                "$identificador Percentual do ICMS
3349
                relativo ao Fundo de Combate à pobreza (FCP) na UF de término da prestação do serviço de
3350
                transporte"
3351
            );
3352
            $this->dom->addChild(
3353
                $icmsDifal,
3354
                'pICMSUFFim',
3355
                $std->pICMSUFFim,
3356
                true,
3357
                "$identificador Alíquota interna da UF
3358
                de término da prestação do serviço de transporte"
3359
            );
3360
            $this->dom->addChild(
3361
                $icmsDifal,
3362
                'pICMSInter',
3363
                $std->pICMSInter,
3364
                true,
3365
                "$identificador Alíquota interestadual
3366
                das UF envolvidas"
3367
            );
3368
            $this->dom->addChild(
3369
                $icmsDifal,
3370
                'vFCPUFFim',
3371
                $std->vFCPUFFim,
3372
                true,
3373
                "$identificador Valor do ICMS relativo
3374
                ao Fundo de Combate á Pobreza (FCP) da UF de término da prestação"
3375
            );
3376
            $this->dom->addChild(
3377
                $icmsDifal,
3378
                'vICMSUFFim',
3379
                $std->vICMSUFFim,
3380
                true,
3381
                "$identificador Valor do ICMS de
3382
                partilha para a UF de término da prestação do serviço de transporte"
3383
            );
3384
            $this->dom->addChild(
3385
                $icmsDifal,
3386
                'vICMSUFIni',
3387
                $std->vICMSUFIni,
3388
                true,
3389
                "$identificador Valor do ICMS de
3390
                partilha para a UF de início da prestação do serviço de transporte"
3391
            );
3392
3393
            $this->imp->appendChild($icmsDifal);
3394
        }
3395
3396
        return $tagIcms;
3397
    }
3398
3399
    /**
3400
     * tagInfTribFed
3401
     * Informações do Impostos Federais
3402
     * CTe OS
3403
     * @return DOMElement
3404
     */
3405
    public function taginfTribFed($std)
3406
    {
3407
3408
        $possible = [
3409
            'vPIS',
3410
            'vCOFINS',
3411
            'vIR',
3412
            'vINSS',
3413
            'vCSLL'
3414
        ];
3415
3416
        $std = $this->equilizeParameters($std, $possible);
3417
3418
        $identificador = 'N02 <imp> - ';
3419
        $tagInfTribFed = $this->dom->createElement('infTribFed');
3420
        $this->dom->addChild($tagInfTribFed, 'vPIS', $std->vPIS, false, "$identificador  Valor de PIS");
3421
        $this->dom->addChild($tagInfTribFed, 'vCOFINS', $std->vCOFINS, false, "$identificador  Valor de COFINS");
3422
        $this->dom->addChild($tagInfTribFed, 'vIR', $std->vIR, false, "$identificador  Valor de IR");
3423
        $this->dom->addChild($tagInfTribFed, 'vINSS', $std->vINSS, false, "$identificador  Valor de INSS");
3424
        $this->dom->addChild($tagInfTribFed, 'vCSLL', $std->vCSLL, false, "$identificador  Valor de CSLL");
3425
        $this->imp->appendChild($tagInfTribFed);
3426
    }
3427
3428
3429
    /**
3430
     * Tag raiz do documento xml
3431
     * Função chamada pelo método [ monta ]
3432
     * @return \DOMElement
3433
     */
3434
    private function buildCTe()
3435
    {
3436
        if (empty($this->CTe)) {
3437
            $this->CTe = $this->dom->createElement('CTe');
3438
            $this->CTe->setAttribute('xmlns', 'http://www.portalfiscal.inf.br/cte');
3439
        }
3440
        return $this->CTe;
3441
    }
3442
3443
    /**
3444
     * Tag raiz do documento xml
3445
     * Função chamada pelo método [ monta ]
3446
     * @return \DOMElement
3447
     */
3448
    private function buildCTeOS()
3449
    {
3450
        if (empty($this->CTe)) {
3451
            $this->CTe = $this->dom->createElement('CTeOS');
3452
            $this->CTe->setAttribute('versao', '3.00');
3453
            $this->CTe->setAttribute('xmlns', 'http://www.portalfiscal.inf.br/cte');
3454
        }
3455
        return $this->CTe;
3456
    }
3457
3458
    /**
3459
     * Gera as tags para o elemento: "Entrega" (Informações ref. a previsão de entrega)
3460
     * #69
3461
     * Nível: 2
3462
     * Os parâmetros para esta função são todos os elementos da tag "Entrega" do
3463
     * tipo elemento (Ele = E|CE|A) e nível 3
3464
     *
3465
     * @return \DOMElement
3466
     */
3467
    private function tagEntrega()
3468
    {
3469
        if ($this->compl == '') {
3470
            $this->compl = $this->dom->createElement('compl');
3471
        }
3472
        if ($this->entrega == '') {
3473
            $this->entrega = $this->dom->createElement('Entrega');
3474
            $this->dom->appChild($this->compl, $this->entrega, 'Falta tag "compl"');
3475
        }
3476
        return $this->entrega;
3477
    }
3478
3479
    /**
3480
     * #241
3481
     * @return type
3482
     */
3483
    public function taginfCTeNorm()
3484
    {
3485
        $this->infCTeNorm = $this->dom->createElement('infCTeNorm');
3486
        return $this->infCTeNorm;
3487
    }
3488
3489
    /**
3490
     * Gera as tags para o elemento: "infCarga" (Informações da Carga do CT-e)
3491
     * #242
3492
     * Nível: 2
3493
     *
3494
     * @return \DOMElement
3495
     */
3496
    public function taginfCarga($std)
3497
    {
3498
3499
        $possible = [
3500
            'vCarga',
3501
            'proPred',
3502
            'xOutCat'
3503
        ];
3504
3505
        $std = $this->equilizeParameters($std, $possible);
3506
3507
        $identificador = '#242 <infCarga> - ';
3508
        $this->infCarga = $this->dom->createElement('infCarga');
3509
        $this->dom->addChild(
3510
            $this->infCarga,
3511
            'vCarga',
3512
            $std->vCarga,
3513
            false,
3514
            $identificador . 'Valor Total da Carga'
3515
        );
3516
        $this->dom->addChild(
3517
            $this->infCarga,
3518
            'proPred',
3519
            $std->proPred,
3520
            true,
3521
            $identificador . 'Produto Predominante'
3522
        );
3523
        $this->dom->addChild(
3524
            $this->infCarga,
3525
            'xOutCat',
3526
            $std->xOutCat,
3527
            false,
3528
            $identificador . 'Outras Caract. da Carga'
3529
        );
3530
        return $this->infCarga;
3531
    }
3532
3533
    /**
3534
     * Gera as tags para o elemento: "infCTeNorm" (Informações da Carga do CT-e OS)
3535
     * #253
3536
     * Nível: 2
3537
     * Os parâmetros para esta função são todos os elementos da tag "infServico"
3538
     *
3539
     * @return \DOMElement
3540
     */
3541
    public function taginfServico($std)
3542
    {
3543
3544
        $possible = [
3545
            'xDescServ'
3546
        ];
3547
3548
        $std = $this->equilizeParameters($std, $possible);
3549
3550
        $identificador = '#253 <infServico> - ';
3551
        $this->infServico = $this->dom->createElement('infServico');
3552
        $this->dom->addChild(
3553
            $this->infServico,
3554
            'xDescServ',
3555
            $std->xDescServ,
3556
            true,
3557
            $identificador . 'Descrição do Serviço Prestado'
3558
        );
3559
        $infQ = $this->dom->createElement('infQ');
3560
        $this->dom->addChild($infQ, 'qCarga', $std->qCarga, false, $identificador . 'Quantidade');
3561
        $this->infServico->appendChild($infQ);
3562
        return $this->infServico;
3563
    }
3564
3565
    /**
3566
     * Gera as tags para o elemento: "infQ" (Informações de quantidades da Carga do CT-e)
3567
     * #246
3568
     * Nível: 3
3569
     * Os parâmetros para esta função são todos os elementos da tag "infQ"
3570
     *
3571
     * @return mixed
3572
     */
3573
    public function taginfQ($std)
3574
    {
3575
3576
        $possible = [
3577
            'cUnid',
3578
            'tpMed',
3579
            'qCarga',
3580
            'vCargaAverb'
3581
        ];
3582
3583
        $std = $this->equilizeParameters($std, $possible);
3584
3585
        $identificador = '#257 <infQ> - ';
3586
        $this->infQ[] = $this->dom->createElement('infQ');
3587
        $posicao = (int)count($this->infQ) - 1;
3588
        $this->dom->addChild(
3589
            $this->infQ[$posicao],
3590
            'cUnid',
3591
            $std->cUnid,
3592
            true,
3593
            $identificador . 'Código da Unidade de Medida'
3594
        );
3595
        $this->dom->addChild(
3596
            $this->infQ[$posicao],
3597
            'tpMed',
3598
            $std->tpMed,
3599
            true,
3600
            $identificador . 'Tipo da Medida'
3601
        );
3602
        $this->dom->addChild(
3603
            $this->infQ[$posicao],
3604
            'qCarga',
3605
            $std->qCarga,
3606
            true,
3607
            $identificador . 'Quantidade'
3608
        );
3609
        $this->dom->addChild(
3610
            $this->infQ[$posicao],
3611
            'vCargaAverb',
3612
            $std->vCargaAverb,
3613
            false,
3614
            $identificador . 'Valor da Carga para efeito de averbação'
3615
        );
3616
        return $this->infQ[$posicao];
3617
    }
3618
3619
    private function taginfDoc()
3620
    {
3621
        if (empty($this->infDoc)) {
3622
            $this->infDoc = $this->dom->createElement('infDoc');
3623
        }
3624
        return $this->infDoc;
3625
    }
3626
3627
    /**
3628
     * Documentos de Transporte Anterior
3629
     * @return DOMElement|\DOMNode
3630
     */
3631
    public function tagdocAnt()
3632
    {
3633
        $this->docAnt = $this->dom->createElement('docAnt');
3634
        return $this->docAnt;
3635
    }
3636
3637
    /**
3638
     * Informações de identificação dos documentos de Transporte Anterior
3639
     * @return array|DOMElement
3640
     */
3641
    public function tagidDocAnt()
3642
    {
3643
        $this->idDocAnt[count($this->emiDocAnt) - 1] = $this->dom->createElement('idDocAnt');
3644
        return $this->idDocAnt;
3645
    }
3646
3647
    /**
3648
     * Gera as tags para o elemento: "infNF" (Informações das NF)
3649
     * #262
3650
     * Nível: 3
3651
     * @return mixed
3652
     */
3653
    public function taginfNF($std)
3654
    {
3655
3656
        $possible = [
3657
            'nRoma',
3658
            'nPed',
3659
            'mod',
3660
            'serie',
3661
            'nDoc',
3662
            'dEmi',
3663
            'vBC',
3664
            'vICMS',
3665
            'vBCST',
3666
            'vST',
3667
            'vProd',
3668
            'vNF',
3669
            'nCFOP',
3670
            'nPeso',
3671
            'PIN',
3672
            'dPrev',
3673
            'infUnidCarga',
3674
            'infUnidTransp'
3675
        ];
3676
        $this->taginfDoc();
3677
        $std = $this->equilizeParameters($std, $possible);
3678
3679
        $identificador = '#262 <infNF> - ';
3680
        $infNF = $this->dom->createElement('infNF');
3681
        $this->dom->addChild(
3682
            $infNF,
3683
            'nRoma',
3684
            $std->nRoma,
3685
            false,
3686
            $identificador . 'Número do Romaneio da NF'
3687
        );
3688
        $this->dom->addChild(
3689
            $infNF,
3690
            'nPed',
3691
            $std->nPed,
3692
            false,
3693
            $identificador . 'Número do Pedido da NF'
3694
        );
3695
        $this->dom->addChild(
3696
            $infNF,
3697
            'mod',
3698
            $std->mod,
3699
            true,
3700
            $identificador . 'Modelo da Nota Fiscal'
3701
        );
3702
        $this->dom->addChild(
3703
            $infNF,
3704
            'serie',
3705
            $std->serie,
3706
            true,
3707
            $identificador . 'Série'
3708
        );
3709
        $this->dom->addChild(
3710
            $infNF,
3711
            'nDoc',
3712
            $std->nDoc,
3713
            true,
3714
            $identificador . 'Número'
3715
        );
3716
        $this->dom->addChild(
3717
            $infNF,
3718
            'dEmi',
3719
            $std->dEmi,
3720
            true,
3721
            $identificador . 'Data de Emissão'
3722
        );
3723
        $this->dom->addChild(
3724
            $infNF,
3725
            'vBC',
3726
            $std->vBC,
3727
            true,
3728
            $identificador . 'Valor da Base de Cálculo do ICMS'
3729
        );
3730
        $this->dom->addChild(
3731
            $infNF,
3732
            'vICMS',
3733
            $std->vICMS,
3734
            true,
3735
            $identificador . 'Valor Totaldo ICMS'
3736
        );
3737
        $this->dom->addChild(
3738
            $infNF,
3739
            'vBCST',
3740
            $std->vBCST,
3741
            true,
3742
            $identificador . 'Valor da Base de Cálculo do ICMS ST'
3743
        );
3744
        $this->dom->addChild(
3745
            $infNF,
3746
            'vST',
3747
            $std->vST,
3748
            true,
3749
            $identificador . 'Valor Total do ICMS ST'
3750
        );
3751
        $this->dom->addChild(
3752
            $infNF,
3753
            'vProd',
3754
            $std->vProd,
3755
            true,
3756
            $identificador . 'Valor Total dos Produtos'
3757
        );
3758
        $this->dom->addChild(
3759
            $infNF,
3760
            'vNF',
3761
            $std->vNF,
3762
            true,
3763
            $identificador . 'Valor Total da NF'
3764
        );
3765
        $this->dom->addChild(
3766
            $infNF,
3767
            'nCFOP',
3768
            $std->nCFOP,
3769
            true,
3770
            $identificador . 'CFOP Predominante'
3771
        );
3772
        $this->dom->addChild(
3773
            $infNF,
3774
            'nPeso',
3775
            $std->nPeso,
3776
            false,
3777
            $identificador . 'Peso total em Kg'
3778
        );
3779
        $this->dom->addChild(
3780
            $infNF,
3781
            'PIN',
3782
            $std->PIN,
3783
            false,
3784
            $identificador . 'PIN SUFRAMA'
3785
        );
3786
        $this->dom->addChild(
3787
            $infNF,
3788
            'dPrev',
3789
            $std->dPrev,
3790
            false,
3791
            $identificador . 'Data prevista de entrega'
3792
        );
3793
        if ($std->infUnidCarga) {
3794
            foreach ($std->infUnidCarga as $value) {
3795
                $this->dom->appChild($infNF, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
3796
            }
3797
        }
3798
        if ($std->infUnidTransp) {
3799
            foreach ($std->infUnidTransp as $value) {
3800
                $this->dom->appChild($infNF, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
3801
            }
3802
        }
3803
        $this->infNF[] = $infNF;
3804
        return $infNF;
3805
    }
3806
3807
    /**
3808
     * Gera as tags para o elemento: "infNFe" (Informações das NF-e)
3809
     * #297
3810
     * Nível: 3
3811
     * @return mixed
3812
     */
3813
    public function taginfNFe($std)
3814
    {
3815
3816
        $possible = [
3817
            'chave',
3818
            'PIN',
3819
            'dPrev',
3820
            'infUnidCarga',
3821
            'infUnidTransp'
3822
        ];
3823
        $this->taginfDoc();
3824
        $std = $this->equilizeParameters($std, $possible);
3825
3826
        $identificador = '#297 <infNFe> - ';
3827
        $infNFe = $this->dom->createElement('infNFe');
3828
        $this->dom->addChild(
3829
            $infNFe,
3830
            'chave',
3831
            $std->chave,
3832
            true,
3833
            $identificador . 'Chave de acesso da NF-e'
3834
        );
3835
        $this->dom->addChild(
3836
            $infNFe,
3837
            'PIN',
3838
            $std->PIN,
3839
            false,
3840
            $identificador . 'PIN SUFRAMA'
3841
        );
3842
        $this->dom->addChild(
3843
            $infNFe,
3844
            'dPrev',
3845
            $std->dPrev,
3846
            false,
3847
            $identificador . 'Data prevista de entrega'
3848
        );
3849
        if ($std->infUnidCarga) {
3850
            foreach ($std->infUnidCarga as $value) {
3851
                $this->dom->appChild($infNFe, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
3852
            }
3853
        }
3854
        if ($std->infUnidTransp) {
3855
            foreach ($std->infUnidTransp as $value) {
3856
                $this->dom->appChild($infNFe, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
3857
            }
3858
        }
3859
        $this->infNFe[] = $infNFe;
3860
        return $infNFe;
3861
    }
3862
3863
    /**
3864
     * Gera as tags para o elemento: "infOutros" (Informações dos demais documentos)
3865
     * #319
3866
     * Nível: 3
3867
     * @return mixed
3868
     */
3869
    public function taginfOutros($std)
3870
    {
3871
3872
        $possible = [
3873
            'tpDoc',
3874
            'descOutros',
3875
            'nDoc',
3876
            'dEmi',
3877
            'vDocFisc',
3878
            'dPrev',
3879
            'infUnidCarga',
3880
            'infUnidTransp'
3881
        ];
3882
        $this->taginfDoc();
3883
        $std = $this->equilizeParameters($std, $possible);
3884
3885
        $ident = '#319 <infOutros> - ';
3886
        $infOutros = $this->dom->createElement('infOutros');
3887
        $this->dom->addChild(
3888
            $infOutros,
3889
            'tpDoc',
3890
            $std->tpDoc,
3891
            true,
3892
            $ident . 'Tipo de documento originário'
3893
        );
3894
        $this->dom->addChild(
3895
            $infOutros,
3896
            'descOutros',
3897
            $std->descOutros,
3898
            false,
3899
            $ident . 'Descrição do documento'
3900
        );
3901
        $this->dom->addChild(
3902
            $infOutros,
3903
            'nDoc',
3904
            $std->nDoc,
3905
            false,
3906
            $ident . 'Número do documento'
3907
        );
3908
        $this->dom->addChild(
3909
            $infOutros,
3910
            'dEmi',
3911
            $std->dEmi,
3912
            false,
3913
            $ident . 'Data de Emissão'
3914
        );
3915
        $this->dom->addChild(
3916
            $infOutros,
3917
            'vDocFisc',
3918
            $std->vDocFisc,
3919
            false,
3920
            $ident . 'Valor do documento'
3921
        );
3922
        $this->dom->addChild(
3923
            $infOutros,
3924
            'dPrev',
3925
            $std->dPrev,
3926
            false,
3927
            $ident . 'Data ista de entrega'
3928
        );
3929
        if ($std->infUnidCarga) {
3930
            foreach ($std->infUnidCarga as $value) {
3931
                $this->dom->appChild($infOutros, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
3932
            }
3933
        }
3934
        if ($std->infUnidTransp) {
3935
            foreach ($std->infUnidTransp as $value) {
3936
                $this->dom->appChild($infOutros, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
3937
            }
3938
        }
3939
        $this->infOutros[] = $infOutros;
3940
        return $infOutros;
3941
    }
3942
3943
    /**
3944
     * taginfUnidCarga
3945
     * tag CTe/infCte/infDoc/(infNF/infNFe/infOutros)/infUnidCarga
3946
     *
3947
     * @param  stdClass $std
3948
     * @return DOMElement
3949
     */
3950
    private function taginfUnidCarga(stdClass $std)
3951
    {
3952
        $possible = [
3953
            'tpUnidCarga',
3954
            'idUnidCarga',
3955
            'lacUnidCarga',
3956
            'qtdRat'
3957
        ];
3958
        $std = $this->equilizeParameters($std, $possible);
3959
        $infUnidCarga = $this->dom->createElement("infUnidCarga");
3960
        $this->dom->addChild(
3961
            $infUnidCarga,
3962
            "tpUnidCarga",
3963
            $std->tpUnidCarga,
3964
            false,
3965
            "Tipo da Unidade de Carga"
3966
        );
3967
        $this->dom->addChild(
3968
            $infUnidCarga,
3969
            "idUnidCarga",
3970
            $std->idUnidCarga,
3971
            false,
3972
            "Identificação da Unidade de Carga "
3973
        );
3974
        if ($std->lacUnidCarga != null) {
3975
            $possible = [
3976
                'nLacre'
3977
            ];
3978
            $stdlacUnidCarga = $this->equilizeParameters($std->lacUnidCarga, $possible);
3979
            foreach ($stdlacUnidCarga->nLacre as $nLacre) {
3980
                $lacUnidCarga = $this->dom->createElement("lacUnidCarga");
3981
                $this->dom->addChild(
3982
                    $lacUnidCarga,
3983
                    "nLacre",
3984
                    $nLacre,
3985
                    true,
3986
                    "Número do lacre"
3987
                );
3988
                $this->dom->appChild($infUnidCarga, $lacUnidCarga, 'Falta tag "infUnidCarga"');
3989
            }
3990
        }
3991
        $this->dom->addChild(
3992
            $infUnidCarga,
3993
            "qtdRat",
3994
            $std->qtdRat,
3995
            false,
3996
            "Quantidade rateada (Peso,Volume)"
3997
        );
3998
        return $infUnidCarga;
3999
    }
4000
4001
    /**
4002
     * taginfUnidTransp
4003
     * tag CTe/infCte/infDoc/(infNF/infNFe/infOutros)/infUnidTransp
4004
     *
4005
     * @param  stdClass $std
4006
     * @return DOMElement
4007
     */
4008
    private function taginfUnidTransp(stdClass $std)
4009
    {
4010
        $possible = [
4011
            'tpUnidTransp',
4012
            'idUnidTransp',
4013
            'qtdRat',
4014
            'lacUnidTransp',
4015
            'infUnidCarga'
4016
        ];
4017
        $std = $this->equilizeParameters($std, $possible);
4018
        $infUnidTransp = $this->dom->createElement("infUnidTransp");
4019
        $this->dom->addChild(
4020
            $infUnidTransp,
4021
            "tpUnidTransp",
4022
            $std->tpUnidTransp,
4023
            true,
4024
            "Tipo da Unidade de Transporte"
4025
        );
4026
        $this->dom->addChild(
4027
            $infUnidTransp,
4028
            "idUnidTransp",
4029
            $std->idUnidTransp,
4030
            false,
4031
            "Identificação da Unidade de Transporte"
4032
        );
4033
        if ($std->lacUnidTransp != null) {
4034
            $possible = [
4035
                'nLacre'
4036
            ];
4037
            $stdlacUnidTransp = $this->equilizeParameters($std->lacUnidTransp, $possible);
4038
            foreach ($stdlacUnidTransp->nLacre as $nLacre) {
4039
                $lacUnidTransp = $this->dom->createElement("lacUnidTransp");
4040
                $this->dom->addChild(
4041
                    $lacUnidTransp,
4042
                    "nLacre",
4043
                    $nLacre,
4044
                    true,
4045
                    "Número do lacre"
4046
                );
4047
                $this->dom->appChild($infUnidTransp, $lacUnidTransp, 'Falta tag "infUnidTransp"');
4048
            }
4049
        }
4050
        if ($std->infUnidCarga) {
4051
            foreach ($std->infUnidCarga as $value) {
4052
                $this->dom->appChild($infUnidTransp, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
4053
            }
4054
        }
4055
        $this->dom->addChild(
4056
            $infUnidTransp,
4057
            "qtdRat",
4058
            $std->qtdRat,
4059
            false,
4060
            "Quantidade rateada (Peso,Volume) "
4061
        );
4062
        return $infUnidTransp;
4063
    }
4064
4065
    /**
4066
     * Gera as tags para o elemento: "infDocRef" (Informações dos demais documentos)
4067
     * #319
4068
     * Nível: 3
4069
     * @return mixed
4070
     */
4071
    public function taginfDocRef($std)
4072
    {
4073
4074
        $possible = [
4075
            'nDoc',
4076
            'serie',
4077
            'subserie',
4078
            'dEmi',
4079
            'vDoc'
4080
        ];
4081
4082
        $std = $this->equilizeParameters($std, $possible);
4083
4084
        $ident = '#319 <infDocRef> - ';
4085
        $this->infDocRef[] = $this->dom->createElement('infDocRef');
4086
        $posicao = (int)count($this->infDocRef) - 1;
4087
        $this->dom->addChild(
4088
            $this->infDocRef[$posicao],
4089
            'nDoc',
4090
            $std->nDoc,
4091
            false,
4092
            $ident . 'Número do documento'
4093
        );
4094
        $this->dom->addChild(
4095
            $this->infDocRef[$posicao],
4096
            'serie',
4097
            $std->serie,
4098
            false,
4099
            $ident . 'Série do documento'
4100
        );
4101
        $this->dom->addChild(
4102
            $this->infDocRef[$posicao],
4103
            'subserie',
4104
            $std->subserie,
4105
            false,
4106
            $ident . 'Subserie do documento'
4107
        );
4108
        $this->dom->addChild(
4109
            $this->infDocRef[$posicao],
4110
            'dEmi',
4111
            $std->dEmi,
4112
            false,
4113
            $ident . 'Data de Emissão'
4114
        );
4115
        $this->dom->addChild(
4116
            $this->infDocRef[$posicao],
4117
            'vDoc',
4118
            $std->vDoc,
4119
            false,
4120
            $ident . 'Valor do documento'
4121
        );
4122
        return $this->infDocRef[$posicao];
4123
    }
4124
4125
    /**
4126
     * Gera as tags para o elemento: "emiDocAnt" (Informações dos CT-es Anteriores)
4127
     * #345
4128
     * Nível: 3
4129
     * @return mixed
4130
     */
4131
    public function tagemiDocAnt($std)
4132
    {
4133
4134
        $possible = [
4135
            'CNPJ',
4136
            'IE',
4137
            'UF',
4138
            'CPF',
4139
            'xNome'
4140
        ];
4141
4142
        $std = $this->equilizeParameters($std, $possible);
4143
4144
        $identificador = '#345 <emiDocAnt> - ';
4145
        $this->emiDocAnt[] = $this->dom->createElement('emiDocAnt');
4146
        $posicao = (int)count($this->emiDocAnt) - 1;
4147
        if ($std->CNPJ != '') {
4148
            $this->dom->addChild(
4149
                $this->emiDocAnt[$posicao],
4150
                'CNPJ',
4151
                $std->CNPJ,
4152
                true,
4153
                $identificador . 'Número do CNPJ'
4154
            );
4155
            $this->dom->addChild(
4156
                $this->emiDocAnt[$posicao],
4157
                'IE',
4158
                Strings::onlyNumbers($std->IE),
4159
                true,
4160
                $identificador . 'Inscrição Estadual'
4161
            );
4162
            $this->dom->addChild(
4163
                $this->emiDocAnt[$posicao],
4164
                'UF',
4165
                $std->UF,
4166
                true,
4167
                $identificador . 'Sigla da UF'
4168
            );
4169
        } else {
4170
            $this->dom->addChild(
4171
                $this->emiDocAnt[$posicao],
4172
                'CPF',
4173
                $std->CPF,
4174
                true,
4175
                $identificador . 'Número do CPF'
4176
            );
4177
        }
4178
        $this->dom->addChild(
4179
            $this->emiDocAnt[$posicao],
4180
            'xNome',
4181
            $std->xNome,
4182
            true,
4183
            $identificador . 'Razão Social ou Nome do Expedidor'
4184
        );
4185
        return $this->emiDocAnt[$posicao];
4186
    }
4187
4188
    /**
4189
     * Gera as tags para o elemento: "idDocAntEle" (Informações dos CT-es Anteriores)
4190
     * #348
4191
     * Nível: 4
4192
     * @return mixed
4193
     */
4194
    public function tagidDocAntEle($std)
4195
    {
4196
4197
        $possible = [
4198
            'chCTe'
4199
        ];
4200
4201
        $std = $this->equilizeParameters($std, $possible);
4202
4203
        $identificador = '#358 <idDocAntEle> - ';
4204
        $this->idDocAntEle[count($this->emiDocAnt) - 1][] = $this->dom->createElement('idDocAntEle');
4205
        $posicao = (int)count($this->idDocAntEle[count($this->emiDocAnt) - 1]) - 1;
4206
        $this->dom->addChild(
4207
            $this->idDocAntEle[count($this->emiDocAnt) - 1][$posicao],
4208
            'chCTe',
4209
            $std->chCTe,
4210
            true,
4211
            $identificador . 'Chave de Acesso do CT-e'
4212
        );
4213
        return $this->idDocAntEle[count($this->emiDocAnt) - 1][$posicao];
4214
    }
4215
4216
4217
    /**
4218
     * Gera as tags para o elemento: "seg" (Informações de Seguro da Carga)
4219
     * #360
4220
     * Nível: 2
4221
     * @return mixed
4222
     */
4223
    public function tagseg($std)
4224
    {
4225
4226
        $possible = [
4227
            'respSeg',
4228
            'xSeg',
4229
            'nApol'
4230
        ];
4231
4232
        $std = $this->equilizeParameters($std, $possible);
4233
4234
        $identificador = '#360 <seg> - ';
4235
        $this->seg[] = $this->dom->createElement('seg');
4236
        $posicao = (int)count($this->seg) - 1;
4237
        $this->dom->addChild(
4238
            $this->seg[$posicao],
4239
            'respSeg',
4240
            $std->respSeg,
4241
            true,
4242
            $identificador . 'Responsável pelo Seguro'
4243
        );
4244
        $this->dom->addChild(
4245
            $this->seg[$posicao],
4246
            'xSeg',
4247
            $std->xSeg,
4248
            false,
4249
            $identificador . 'Nome da Seguradora'
4250
        );
4251
        $this->dom->addChild(
4252
            $this->seg[$posicao],
4253
            'nApol',
4254
            $std->nApol,
4255
            false,
4256
            $identificador . 'Número da Apólice'
4257
        );
4258
        return $this->seg[$posicao];
4259
    }
4260
4261
    /**
4262
     * Gera as tags para o elemento: "idDocAntEle" (Informações dos CT-es Anteriores)
4263
     * #348
4264
     * Nível: 4
4265
     * @return mixed
4266
     */
4267
    public function tagidDocAntPap($std)
4268
    {
4269
4270
        $possible = [
4271
            'tpDoc',
4272
            'serie',
4273
            'subser',
4274
            'nDoc',
4275
            'dEmi'
4276
        ];
4277
4278
        $std = $this->equilizeParameters($std, $possible);
4279
4280
        $identificador = '#358 <idDocAntPap> - ';
4281
        $this->idDocAntPap[count($this->emiDocAnt) - 1][] = $this->dom->createElement('idDocAntPap');
4282
        $posicao = (int)count($this->idDocAntPap[count($this->emiDocAnt) - 1]) - 1;
4283
        $this->dom->addChild(
4284
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4285
            'tpDoc',
4286
            $std->tpDoc,
4287
            true,
4288
            $identificador . 'Tipo do Documento de Transporte Anterior'
4289
        );
4290
        $this->dom->addChild(
4291
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4292
            'serie',
4293
            $std->serie,
4294
            true,
4295
            $identificador . 'Série do Documento Fiscal'
4296
        );
4297
        $this->dom->addChild(
4298
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4299
            'subser',
4300
            $std->subser,
4301
            false,
4302
            $identificador . 'Série do Documento Fiscal'
4303
        );
4304
        $this->dom->addChild(
4305
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4306
            'nDoc',
4307
            $std->nDoc,
4308
            true,
4309
            $identificador . 'Número do Documento Fiscal'
4310
        );
4311
        $this->dom->addChild(
4312
            $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao],
4313
            'dEmi',
4314
            $std->dEmi,
4315
            true,
4316
            $identificador . 'Data de emissão (AAAA-MM-DD)'
4317
        );
4318
        return $this->idDocAntPap[count($this->emiDocAnt) - 1][$posicao];
4319
    }
4320
4321
4322
    /**
4323
     * Gera as tags para o elemento: "infModal" (Informações do modal)
4324
     * #366
4325
     * Nível: 2
4326
     * @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...
4327
     * @return DOMElement|\DOMNode
4328
     */
4329
    public function taginfModal($std)
4330
    {
4331
        $this->infModal = $this->dom->createElement('infModal');
4332
        $this->infModal->setAttribute('versaoModal', $std->versaoModal);
4333
        return $this->infModal;
4334
    }
4335
4336
    /**
4337
     * Leiaute - Rodoviário
4338
     * Gera as tags para o elemento: "rodo" (Informações do modal Rodoviário)
4339
     * #1
4340
     * Nível: 0
4341
     * @return DOMElement|\DOMNode
4342
     */
4343
    public function tagrodo($std)
4344
    {
4345
4346
        $possible = [
4347
            'RNTRC'
4348
        ];
4349
4350
        $std = $this->equilizeParameters($std, $possible);
4351
4352
        $identificador = '#1 <rodo> - ';
4353
        $this->rodo = $this->dom->createElement('rodo');
4354
        $this->dom->addChild(
4355
            $this->rodo,
4356
            'RNTRC',
4357
            $std->RNTRC,
4358
            true,
4359
            $identificador . 'Registro nacional de transportadores
4360
            rodoviários de carga'
4361
        );
4362
        return $this->rodo;
4363
    }
4364
4365
    /**
4366
     * Leiaute - Dutoviário
4367
     * Gera as tags para o elemento: "duto" (informações do modal Dutoviário)
4368
     * @author Uilasmar Guedes
4369
     * #1
4370
     * Nivel: 0
4371
     * @return DOMElement|\DOMNode
4372
     */
4373
    public function tagduto($std)
4374
    {
4375
4376
        $possible = [
4377
            'vTar',
4378
            'dIni',
4379
            'dFim'
4380
        ];
4381
4382
        $std = $this->equilizeParameters($std, $possible);
4383
4384
        $identificador = '#1 <duto> - ';
4385
        $this->duto = $this->dom->createElement('duto');
4386
        $this->dom->addChild(
4387
            $this->duto,
4388
            'vTar',
4389
            $std->vTar,
4390
            false,
4391
            $identificador . 'Valor da tarifa '
4392
        );
4393
        $this->dom->addChild(
4394
            $this->duto,
4395
            'dIni',
4396
            $std->dIni,
4397
            true,
4398
            $identificador . 'Data de Início da prestação do serviço'
4399
        );
4400
        $this->dom->addChild(
4401
            $this->duto,
4402
            'dFim',
4403
            $std->dFim,
4404
            true,
4405
            $identificador . 'Data de Fim da prestação do serviço'
4406
        );
4407
        return $this->duto;
4408
    }
4409
4410
    /**
4411
     * Leiaute - Aquaviario
4412
     * Gera as tags para o elemento: "aquav" (informações do modal Aquaviario)
4413
     * @author Anderson Minuto Consoni Vaz
4414
     * #1
4415
     * Nivel: 0
4416
     * @return DOMElement|\DOMNode
4417
     */
4418
    public function tagaquav($std)
4419
    {
4420
4421
        $possible = [
4422
            'vPrest',
4423
            'vAFRMM',
4424
            'xNavio',
4425
            'nViag',
4426
            'direc',
4427
            'irin',
4428
            'tpNav'
4429
        ];
4430
4431
        $std = $this->equilizeParameters($std, $possible);
4432
4433
        $identificador = '#1 <aquav> - ';
4434
        $this->aquav = $this->dom->createElement('aquav');
4435
        $this->dom->addChild(
4436
            $this->aquav,
4437
            'vPrest',
4438
            $std->vPrest,
4439
            true,
4440
            $identificador . 'vPrest'
4441
        );
4442
        $this->dom->addChild(
4443
            $this->aquav,
4444
            'vAFRMM',
4445
            $std->vAFRMM,
4446
            true,
4447
            $identificador . 'vAFRMM'
4448
        );
4449
        $this->dom->addChild(
4450
            $this->aquav,
4451
            'xNavio',
4452
            $std->xNavio,
4453
            true,
4454
            $identificador . 'xNavio'
4455
        );
4456
        $this->dom->addChild(
4457
            $this->aquav,
4458
            'nViag',
4459
            $std->nViag,
4460
            true,
4461
            $identificador . 'nViag'
4462
        );
4463
        $this->dom->addChild(
4464
            $this->aquav,
4465
            'direc',
4466
            $std->direc,
4467
            true,
4468
            $identificador . 'direc'
4469
        );
4470
        $this->dom->addChild(
4471
            $this->aquav,
4472
            'irin',
4473
            $std->irin,
4474
            true,
4475
            $identificador . 'irin'
4476
        );
4477
        $this->dom->addChild(
4478
            $this->aquav,
4479
            'tpNav',
4480
            $std->tpNav,
4481
            false,
4482
            $identificador . 'tpNav'
4483
        );
4484
        return $this->aquav;
4485
    }
4486
4487
    /**
4488
     * Leiaute - Rodoviário
4489
     * Gera as tags para o elemento: "rodo" (Informações do modal Rodoviário) CT-e OS
4490
     * #1
4491
     * Nível: 0
4492
     * @return DOMElement|\DOMNode
4493
     */
4494
    public function tagrodoOS($std)
4495
    {
4496
4497
        $possible = [
4498
            'vPrest',
4499
            'vAFRMM',
4500
            'xNavio',
4501
            'nViag',
4502
            'direc',
4503
            'irin',
4504
            'tpNav'
4505
        ];
4506
4507
        $std = $this->equilizeParameters($std, $possible);
4508
4509
        $identificador = '#1 <rodoOS> - ';
4510
        $this->rodo = $this->dom->createElement('rodoOS');
4511
        $this->dom->addChild(
4512
            $this->rodo,
4513
            'TAF',
4514
            $std->TAF,
4515
            false,
4516
            $identificador . 'Termo de Autorização de Fretamento - TAF'
4517
        );
4518
        $this->dom->addChild(
4519
            $this->rodo,
4520
            'NroRegEstadual',
4521
            $std->nroRegEstadual,
4522
            false,
4523
            $identificador . 'Número do Registro Estadual'
4524
        );
4525
        return $this->rodo;
4526
    }
4527
4528
    /**
4529
     * Leiaute - Aéreo
4530
     * Gera as tags para o elemento: "aereo" (Informações do modal Aéreo)
4531
     * @author Newton Pasqualini Filho
4532
     * #1
4533
     * Nível: 0
4534
     * @return DOMElement|\DOMNode
4535
     */
4536
    public function tagaereo($std)
4537
    {
4538
4539
        $possible = [
4540
            'nMinu',
4541
            'nOCA',
4542
            'dPrevAereo',
4543
            'natCarga_xDime',
4544
            'natCarga_cInfManu',
4545
            'tarifa_CL',
4546
            'tarifa_cTar',
4547
            'tarifa_vTar'
4548
        ];
4549
4550
        $std = $this->equilizeParameters($std, $possible);
4551
4552
        $identificador = '#1 <aereo> - ';
4553
        $this->aereo = $this->dom->createElement('aereo');
4554
        $this->dom->addChild(
4555
            $this->aereo,
4556
            'nMinu',
4557
            $std->nMinu,
4558
            false,
4559
            $identificador . 'Número da Minuta'
4560
        );
4561
        $this->dom->addChild(
4562
            $this->aereo,
4563
            'nOCA',
4564
            $std->nOCA,
4565
            false,
4566
            $identificador . 'Número Operacional do Conhecimento Aéreo'
4567
        );
4568
        $this->dom->addChild(
4569
            $this->aereo,
4570
            'dPrevAereo',
4571
            $std->dPrevAereo,
4572
            true,
4573
            $identificador . 'Data prevista da entrega'
4574
        );
4575
        if (isset($std->natCarga_xDime) || isset($std->natCarga_cInfManu)) {
4576
            $identificador = '#1 <aereo> - <natCarga> - ';
4577
            $natCarga = $this->dom->createElement('natCarga');
4578
            $this->dom->addChild(
4579
                $natCarga,
4580
                'xDime',
4581
                $std->natCarga_xDime,
4582
                false,
4583
                $identificador . 'Dimensões da carga, formato: 1234x1234x1234 (cm)'
4584
            );
4585
            if (isset($std->natCarga_cInfManu) && !is_array($std->natCarga_cInfManu)) {
4586
                $std->natCarga_cInfManu = [$std->natCarga_cInfManu];
4587
            }
4588
            $cInfManuX = 0;
4589
            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...
4590
                $cInfManuX++;
4591
                $this->dom->addChild(
4592
                    $natCarga,
4593
                    'cInfManu',
4594
                    $cInfManu,
4595
                    false,
4596
                    $identificador . 'Informação de manuseio, com dois dígitos, pode ter mais de uma ocorrência.'
4597
                );
4598
            }
4599
            $this->aereo->appendChild($natCarga);
4600
        }
4601
        $identificador = '#1 <aereo> - <tarifa> - ';
4602
        $tarifa = $this->dom->createElement('tarifa');
4603
        $this->dom->addChild(
4604
            $tarifa,
4605
            'CL',
4606
            $std->tarifa_CL,
4607
            true,
4608
            $identificador . 'Classe da tarifa: M - Tarifa Mínima / G - Tarifa Geral / E - Tarifa Específica'
4609
        );
4610
        $this->dom->addChild(
4611
            $tarifa,
4612
            'cTar',
4613
            $std->tarifa_cTar,
4614
            false,
4615
            $identificador . 'Código de três digítos correspondentes à tarifa.'
4616
        );
4617
        $this->dom->addChild(
4618
            $tarifa,
4619
            'vTar',
4620
            $std->tarifa_vTar,
4621
            true,
4622
            $identificador . 'Valor da tarifa. 15 posições, sendo 13 inteiras e 2 decimais.'
4623
        );
4624
        $this->aereo->appendChild($tarifa);
4625
        return $this->aereo;
4626
    }
4627
4628
    /**
4629
     * Leiaute - Aéreo
4630
     * Gera as tags para o elemento: "aereo" (Informações do modal Aéreo)
4631
     * #1
4632
     * Nível: 0
4633
     * @return DOMElement|\DOMNode
4634
     */
4635
    public function tagperi($std)
4636
    {
4637
4638
        $possible = [
4639
            'nONU',
4640
            'qTotEmb',
4641
            'qTotProd',
4642
            'uniAP'
4643
        ];
4644
4645
        $std = $this->equilizeParameters($std, $possible);
4646
4647
        $identificador = '#1 <aereo> - <peri> - ';
4648
        $peri = $this->dom->createElement('peri');
4649
        $this->dom->addChild(
4650
            $peri,
4651
            'nONU',
4652
            $std->nONU,
4653
            true,
4654
            $identificador . 'Número ONU/UN'
4655
        );
4656
        $this->dom->addChild(
4657
            $peri,
4658
            'qTotEmb',
4659
            $std->qTotEmb,
4660
            true,
4661
            $identificador . 'Quantidade total de volumes contendo artigos perigosos'
4662
        );
4663
        $identificador = '#1 <peri> - <infTotAP> - ';
4664
        $infTotAP = $this->dom->createElement('infTotAP');
4665
        $this->dom->addChild(
4666
            $infTotAP,
4667
            'qTotProd',
4668
            $std->qTotProd,
4669
            false,
4670
            $identificador . 'Quantidade total de artigos perigosos'
4671
        );
4672
        $this->dom->addChild(
4673
            $infTotAP,
4674
            'uniAP',
4675
            $std->uniAP,
4676
            true,
4677
            $identificador . 'Unidade de medida'
4678
        );
4679
        $peri->appendChild($infTotAP);
4680
        $this->peri[] = $peri;
4681
        return $peri;
4682
    }
4683
4684
    public function tagferrov($std)
4685
    {
4686
4687
        $possible = [
4688
            'tpTraf',
4689
            'respFat',
4690
            'ferrEmi',
4691
            'vFrete',
4692
            'chCTeFerroOrigem ',
4693
            'fluxo'
4694
        ];
4695
4696
        $std = $this->equilizeParameters($std, $possible);
4697
4698
        $identificador = '#1 <ferrov> - ';
4699
        $this->ferrov = $this->dom->createElement('ferrov');
4700
        $this->dom->addChild(
4701
            $this->ferrov,
4702
            'tpTraf',
4703
            $std->tpTraf,
4704
            true,
4705
            $identificador . 'Tipo de Tráfego'
4706
        );
4707
        $identificador = '#1 <ferrov> - <trafMut> - ';
4708
        $trafMut = $this->dom->createElement('trafMut');
4709
        $this->dom->addChild(
4710
            $trafMut,
4711
            'respFat',
4712
            $std->respFat,
4713
            true,
4714
            $identificador . 'Responsável pelo Faturamento'
4715
        );
4716
        $this->dom->addChild(
4717
            $trafMut,
4718
            'ferrEmi',
4719
            $std->ferrEmi,
4720
            true,
4721
            $identificador . 'Ferrovia Emitente do CTe'
4722
        );
4723
        $this->dom->addChild(
4724
            $trafMut,
4725
            'vFrete',
4726
            $std->vFrete,
4727
            true,
4728
            $identificador . 'Valor do Frete do Tráfego Mútuo '
4729
        );
4730
        $this->dom->addChild(
4731
            $trafMut,
4732
            'chCTeFerroOrigem',
4733
            $std->chCTeFerroOrigem,
4734
            false,
4735
            $identificador . 'Chave de acesso do CT-e emitido pelo ferrovia de origem'
4736
        );
4737
        $this->ferrov->appendChild($trafMut);
4738
        $this->dom->addChild(
4739
            $this->ferrov,
4740
            'fluxo',
4741
            $std->fluxo,
4742
            true,
4743
            $identificador . 'Fluxo Ferroviário '
4744
        );
4745
    }
4746
4747
    public function tagferroEnv($std)
4748
    {
4749
4750
        $possible = [
4751
            'CNPJ',
4752
            'cInt',
4753
            'IE',
4754
            'xNome',
4755
            'xLgr',
4756
            'nro',
4757
            'xCpl',
4758
            'xBairro',
4759
            'cMun',
4760
            'xMun',
4761
            'CEP',
4762
            'UF',
4763
            'fluxo'
4764
        ];
4765
4766
        $std = $this->equilizeParameters($std, $possible);
4767
4768
        $identificador = '#1 <trafMut> - <ferroEnv> - ';
4769
        $ferroEnv = $this->dom->createElement('ferroEnv');
4770
        $this->dom->addChild(
4771
            $ferroEnv,
4772
            'CNPJ',
4773
            $std->CNPJ,
4774
            true,
4775
            $identificador . 'Número do CNPJ'
4776
        );
4777
        $this->dom->addChild(
4778
            $ferroEnv,
4779
            'cInt',
4780
            $std->cInt,
4781
            false,
4782
            $identificador . 'Código interno da Ferrovia envolvida'
4783
        );
4784
        $this->dom->addChild(
4785
            $ferroEnv,
4786
            'IE',
4787
            $std->IE,
4788
            false,
4789
            $identificador . 'Inscrição Estadual'
4790
        );
4791
        $this->dom->addChild(
4792
            $ferroEnv,
4793
            'xNome',
4794
            $std->xNome,
4795
            false,
4796
            $identificador . 'Razão Social ou Nome'
4797
        );
4798
        $identificador = '#1 <ferroEnv> - <enderFerro> - ';
4799
        $enderFerro = $this->dom->createElement('enderFerro');
4800
        $this->dom->addChild(
4801
            $enderFerro,
4802
            'xLgr',
4803
            $std->xLgr,
4804
            true,
4805
            $identificador . 'Logradouro'
4806
        );
4807
        $this->dom->addChild(
4808
            $enderFerro,
4809
            'nro',
4810
            $std->nro,
4811
            false,
4812
            $identificador . 'Número'
4813
        );
4814
        $this->dom->addChild(
4815
            $enderFerro,
4816
            'xCpl',
4817
            $std->xCpl,
4818
            false,
4819
            $identificador . 'Complemento'
4820
        );
4821
        $this->dom->addChild(
4822
            $enderFerro,
4823
            'xBairro',
4824
            $std->xBairro,
4825
            false,
4826
            $identificador . 'Bairro'
4827
        );
4828
        $this->dom->addChild(
4829
            $enderFerro,
4830
            'cMun',
4831
            $std->cMun,
4832
            true,
4833
            $identificador . 'Código do município'
4834
        );
4835
        $this->dom->addChild(
4836
            $enderFerro,
4837
            'xMun',
4838
            $std->xMun,
4839
            true,
4840
            $identificador . 'Nome do município'
4841
        );
4842
        $this->dom->addChild(
4843
            $enderFerro,
4844
            'CEP',
4845
            $std->CEP,
4846
            true,
4847
            $identificador . 'CEP'
4848
        );
4849
        $this->dom->addChild(
4850
            $enderFerro,
4851
            'UF',
4852
            $std->UF,
4853
            true,
4854
            $identificador . 'Sigla da UF'
4855
        );
4856
        $ferroEnv->appendChild($enderFerro);
4857
        $this->ferroEnv[] = $ferroEnv;
4858
        return $ferroEnv;
4859
    }
4860
4861
    /**
4862
     * CT-e de substituição
4863
     * @return type
4864
     */
4865
    public function taginfCteSub($std)
4866
    {
4867
4868
        $possible = [
4869
            'chCte',
4870
            'refCteAnu'
4871
        ];
4872
4873
        $std = $this->equilizeParameters($std, $possible);
4874
4875
        $identificador = '#149 <infCteSub> - ';
4876
        $this->infCteSub = $this->dom->createElement('infCteSub');
4877
        $this->dom->addChild(
4878
            $this->infCteSub,
4879
            'chCte',
4880
            $std->chCte,
4881
            false,
4882
            "$identificador  Chave de acesso do CTe a ser substituído (original)"
4883
        );
4884
        $this->dom->addChild(
4885
            $this->infCteSub,
4886
            'refCteAnu',
4887
            $std->refCteAnu,
4888
            false,
4889
            "$identificador  Chave de acesso do CT-e de Anulação"
4890
        );
4891
        return $this->infCteSub;
4892
    }
4893
4894
4895
    /**
4896
     * CT-e de substituição - tomaICMS
4897
     * @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...
4898
     * @return type
4899
     */
4900
    public function tagtomaICMS()
4901
    {
4902
        $this->tomaICMS = $this->dom->createElement('tomaICMS');
4903
        return $this->tomaICMS;
4904
    }
4905
4906
    /**
4907
     * CT-e de substituição - NF-e
4908
     * @param type $std
4909
     * @return type
4910
     */
4911
    public function tagrefNFe($std)
4912
    {
4913
4914
        $possible = [
4915
            'refNFe'
4916
        ];
4917
4918
        $std = $this->equilizeParameters($std, $possible);
4919
4920
        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...
4921
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
4922
        }
4923
        $identificador = '#153 <refNFe> - ';
4924
        $this->dom->addChild(
4925
            $this->tomaICMS,
4926
            'refNFe',
4927
            $std->refNFe,
4928
            false,
4929
            "$identificador  Chave de acesso da NF-e emitida pelo tomador"
4930
        );
4931
4932
        return $this->tomaICMS;
4933
    }
4934
4935
    /**
4936
     * CT-e de substituição - NF
4937
     * @param type $std
4938
     * @return type
4939
     */
4940
    public function tagrefNF($std)
4941
    {
4942
4943
        $possible = [
4944
            'CNPJ',
4945
            'CPF',
4946
            'mod',
4947
            'serie',
4948
            'subserie',
4949
            'nro',
4950
            'valor',
4951
            'dEmi'
4952
        ];
4953
4954
        $std = $this->equilizeParameters($std, $possible);
4955
4956
        $identificador = '#154 <refNFe> - ';
4957
        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...
4958
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
4959
        }
4960
        $this->refNF = $this->dom->createElement('refNF');
4961
        if ($std->CNPJ != '') {
4962
            $this->dom->addChild(
4963
                $this->refNF,
4964
                'CNPJ',
4965
                $std->CNPJ,
4966
                true,
4967
                $identificador . 'CNPJ do emitente'
4968
            );
4969
        } elseif ($std->CPF != '') {
4970
            $this->dom->addChild(
4971
                $this->refNF,
4972
                'CPF',
4973
                $std->CPF,
4974
                true,
4975
                $identificador . 'CPF do emitente'
4976
            );
4977
        }
4978
        $this->dom->addChild(
4979
            $this->refNF,
4980
            'mod',
4981
            $std->mod,
4982
            false,
4983
            $identificador . 'Modelo'
4984
        );
4985
        $this->dom->addChild(
4986
            $this->refNF,
4987
            'serie',
4988
            $std->serie,
4989
            false,
4990
            $identificador . 'Série do documento'
4991
        );
4992
        $this->dom->addChild(
4993
            $this->refNF,
4994
            'subserie',
4995
            $std->subserie,
4996
            false,
4997
            $identificador . 'Subserie do documento'
4998
        );
4999
        $this->dom->addChild(
5000
            $this->refNF,
5001
            'nro',
5002
            $std->nro,
5003
            false,
5004
            $identificador . 'Número'
5005
        );
5006
        $this->dom->addChild(
5007
            $this->refNF,
5008
            'valor',
5009
            $std->valor,
5010
            false,
5011
            $identificador . 'Valor'
5012
        );
5013
        $this->dom->addChild(
5014
            $this->refNF,
5015
            'dEmi',
5016
            $std->dEmi,
5017
            false,
5018
            $identificador . 'Emissão'
5019
        );
5020
        $this->tomaICMS->appendChild($this->refNF);
5021
        return $this->tomaICMS;
5022
    }
5023
5024
    /**
5025
     * CT-e de substituição - CT-e
5026
     * @param type $std
5027
     * @return type
5028
     */
5029
    public function tagrefCTe($std)
5030
    {
5031
5032
        $possible = [
5033
            'refCTe'
5034
        ];
5035
5036
        $std = $this->equilizeParameters($std, $possible);
5037
5038
        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...
5039
            $this->tomaICMS = $this->dom->createElement('tomaICMS');
5040
        }
5041
        $identificador = '#163 <refCTe> - ';
5042
        $this->dom->addChild(
5043
            $this->tomaICMS,
5044
            'refCTe',
5045
            $std->refCTe,
5046
            false,
5047
            "$identificador  Chave de acesso do CT-e emitida pelo tomador"
5048
        );
5049
5050
        return $this->tomaICMS;
5051
    }
5052
5053
    /**
5054
     * Leiaute - Rodoviário
5055
     * Gera as tags para o elemento: "veic" (Dados dos Veículos)
5056
     * #21
5057
     * Nível: 1
5058
     * @return mixed
5059
     */
5060
    public function tagveicCTeOS($std)
5061
    {
5062
5063
        $possible = [
5064
            'placa',
5065
            'RENAVAM',
5066
            'CNPJ',
5067
            'CPF',
5068
            'TAF',
5069
            'NroRegEstadual',
5070
            'xNome',
5071
            'IE',
5072
            'ufProp',
5073
            'tpProp',
5074
            'uf'
5075
        ];
5076
5077
        $std = $this->equilizeParameters($std, $possible);
5078
5079
        $identificador = '#21 <veic> - ';
5080
        $this->veic = $this->dom->createElement('veic');
5081
        $this->dom->addChild(
5082
            $this->veic,
5083
            'placa',
5084
            $std->placa,
5085
            false,
5086
            $identificador . 'Placa do veículo'
5087
        );
5088
        $this->dom->addChild(
5089
            $this->veic,
5090
            'RENAVAM',
5091
            $std->RENAVAM,
5092
            false,
5093
            $identificador . 'RENAVAM do veículo'
5094
        );
5095
        if ($std->xNome != '') { // CASO FOR VEICULO DE TERCEIRO
5096
            $this->prop = $this->dom->createElement('prop');
5097
            if ($std->CNPJ != '') {
5098
                $this->dom->addChild(
5099
                    $this->prop,
5100
                    'CNPJ',
5101
                    $std->CNPJ,
5102
                    true,
5103
                    $identificador . 'CNPJ do proprietario'
5104
                );
5105
            } elseif ($std->CPF != '') {
5106
                $this->dom->addChild(
5107
                    $this->prop,
5108
                    'CPF',
5109
                    $std->CPF,
5110
                    true,
5111
                    $identificador . 'CPF do proprietario'
5112
                );
5113
            }
5114
            if ($std->taf != '') {
5115
                $this->dom->addChild(
5116
                    $this->prop,
5117
                    'TAF',
5118
                    $std->taf,
5119
                    false,
5120
                    $identificador . 'TAF'
5121
                );
5122
            } else {
5123
                $this->dom->addChild(
5124
                    $this->prop,
5125
                    'NroRegEstadual',
5126
                    $std->nroRegEstadual,
5127
                    false,
5128
                    $identificador . 'Número do Registro Estadual'
5129
                );
5130
            }
5131
            $this->dom->addChild(
5132
                $this->prop,
5133
                'xNome',
5134
                $std->xNome,
5135
                true,
5136
                $identificador . 'Nome do proprietario'
5137
            );
5138
            $this->dom->addChild(
5139
                $this->prop,
5140
                'IE',
5141
                Strings::onlyNumbers($std->IE),
5142
                false,
5143
                $identificador . 'IE do proprietario'
5144
            );
5145
            $this->dom->addChild(
5146
                $this->prop,
5147
                'UF',
5148
                $std->ufProp,
5149
                true,
5150
                $identificador . 'UF do proprietario'
5151
            );
5152
            $this->dom->addChild(
5153
                $this->prop,
5154
                'tpProp',
5155
                $std->tpProp,
5156
                true,
5157
                $identificador . 'Tipo Proprietário'
5158
            );
5159
            $this->dom->appChild($this->veic, $this->prop, 'Falta tag "prop"');
5160
        }
5161
        $this->dom->addChild(
5162
            $this->veic,
5163
            'UF',
5164
            $std->uf,
5165
            true,
5166
            $identificador . 'UF em que veículo está licenciado'
5167
        );
5168
        return $this->veic;
5169
    }
5170
5171
    public function infFretamento($std)
5172
    {
5173
5174
        $possible = [
5175
            'tpFretamento',
5176
            'dhViagem'
5177
        ];
5178
5179
        $std = $this->equilizeParameters($std, $possible);
5180
5181
        $identificador = '#21 <infFretamento> - ';
5182
        $this->infFretamento = $this->dom->createElement('infFretamento');
5183
        $this->dom->addChild(
5184
            $this->infFretamento,
5185
            'tpFretamento',
5186
            $std->tpFretamento,
5187
            true,
5188
            $identificador . 'Tipo do Fretamento de Pessoas'
5189
        );
5190
        $this->dom->addChild(
5191
            $this->infFretamento,
5192
            'dhViagem',
5193
            $std->dhViagem,
5194
            false,
5195
            $identificador . 'Data e hora da viagem'
5196
        );
5197
        return $this->infFretamento;
5198
    }
5199
5200
    /**
5201
     * Gera as tags para o elemento: "infCteComp" (Detalhamento do CT-e complementado)
5202
     * #410
5203
     * Nível: 1
5204
     * @return DOMElement|\DOMNode
5205
     */
5206
    public function taginfCTeComp($std)
5207
    {
5208
5209
        $possible = [
5210
            'chCTe'
5211
        ];
5212
5213
        $std = $this->equilizeParameters($std, $possible);
5214
5215
        $identificador = '#410 <infCteComp> - ';
5216
        $this->infCteComp = $this->dom->createElement('infCteComp');
5217
        $this->dom->addChild(
5218
            $this->infCteComp,
5219
            'chCTe',
5220
            $std->chCTe,
5221
            true,
5222
            $identificador . ' Chave do CT-e complementado'
5223
        );
5224
        return $this->infCteComp;
5225
    }
5226
5227
    /**
5228
     * Gera as tags para o elemento: "infCteAnu" (Detalhamento do CT-e de Anulação)
5229
     * #411
5230
     * Nível: 1
5231
     * @return DOMElement|\DOMNode
5232
     */
5233
    public function taginfCteAnu($std)
5234
    {
5235
5236
        $possible = [
5237
            'chave',
5238
            'dEmi'
5239
        ];
5240
5241
        $std = $this->equilizeParameters($std, $possible);
5242
5243
        $identificador = '#411 <infCteAnu> - ';
5244
        $this->infCteAnu = $this->dom->createElement('infCteAnu');
5245
        $this->dom->addChild(
5246
            $this->infCteAnu,
5247
            'chCte',
5248
            $std->chave,
5249
            true,
5250
            $identificador . ' Chave do CT-e anulado'
5251
        );
5252
        $this->dom->addChild(
5253
            $this->infCteAnu,
5254
            'dEmi',
5255
            $std->data,
5256
            true,
5257
            $identificador . ' Data de Emissão do CT-e anulado'
5258
        );
5259
        return $this->infCteAnu;
5260
    }
5261
5262
    /**
5263
     * Gera as tags para o elemento: "autXML" (Autorizados para download do XML)
5264
     * #396
5265
     * Nível: 1
5266
     * Os parâmetros para esta função são todos os elementos da tag "autXML"
5267
     *
5268
     * @return boolean
5269
     */
5270
    public function tagveicNovos($std)
5271
    {
5272
5273
        $possible = [
5274
            'chassi',
5275
            'cCor',
5276
            'xCor',
5277
            'cMod',
5278
            'vUnit',
5279
            'vFrete'
5280
        ];
5281
5282
        $std = $this->equilizeParameters($std, $possible);
5283
5284
        $identificador = '#396 <veicNovos> - ';
5285
        $veicNovos = $this->dom->createElement('veicNovos');
5286
        $this->dom->addChild(
5287
            $veicNovos,
5288
            'chassi',
5289
            $std->chassi,
5290
            true,
5291
            $identificador . 'Chassi do veículo '
5292
        );
5293
        $this->dom->addChild(
5294
            $veicNovos,
5295
            'cCor',
5296
            $std->cCor,
5297
            true,
5298
            $identificador . 'Cor do veículo '
5299
        );
5300
        $this->dom->addChild(
5301
            $veicNovos,
5302
            'xCor',
5303
            $std->xCor,
5304
            true,
5305
            $identificador . 'Descrição da cor '
5306
        );
5307
        $this->dom->addChild(
5308
            $veicNovos,
5309
            'cMod',
5310
            $std->cMod,
5311
            true,
5312
            $identificador . 'Código Marca Modelo '
5313
        );
5314
        $this->dom->addChild(
5315
            $veicNovos,
5316
            'vUnit',
5317
            $std->vUnit,
5318
            true,
5319
            $identificador . 'Valor Unitário do Veículo '
5320
        );
5321
        $this->dom->addChild(
5322
            $veicNovos,
5323
            'vFrete',
5324
            $std->vFrete,
5325
            true,
5326
            $identificador . 'Frete Unitário '
5327
        );
5328
        $this->veicNovos[] = $veicNovos;
5329
        return $veicNovos;
5330
    }
5331
5332
    /**
5333
     * Gera as tags para o elemento: "autXML" (Autorizados para download do XML)
5334
     * #396
5335
     * Nível: 1
5336
     * Os parâmetros para esta função são todos os elementos da tag "autXML"
5337
     *
5338
     * @return boolean
5339
     */
5340
    public function tagautXML($std)
5341
    {
5342
5343
        $possible = [
5344
            'CNPJ',
5345
            'CPF'
5346
        ];
5347
5348
        $std = $this->equilizeParameters($std, $possible);
5349
5350
        $identificador = '#396 <autXML> - ';
5351
        $autXML = $this->dom->createElement('autXML');
5352
        if (isset($std->CNPJ) && $std->CNPJ != '') {
5353
            $this->dom->addChild(
5354
                $autXML,
5355
                'CNPJ',
5356
                $std->CNPJ,
5357
                true,
5358
                $identificador . 'CNPJ do Cliente Autorizado'
5359
            );
5360
        } elseif (isset($std->CPF) && $std->CPF != '') {
5361
            $this->dom->addChild(
5362
                $autXML,
5363
                'CPF',
5364
                $std->CPF,
5365
                true,
5366
                $identificador . 'CPF do Cliente Autorizado'
5367
            );
5368
        }
5369
        $this->autXML[] = $autXML;
5370
        return $autXML;
5371
    }
5372
5373
    /**
5374
     * #359
5375
     * tag CTe/infCTe/cobr (opcional)
5376
     * Depende de fat
5377
     */
5378
    protected function buildCobr()
5379
    {
5380
        if (empty($this->cobr)) {
5381
            $this->cobr = $this->dom->createElement("cobr");
5382
        }
5383
    }
5384
5385
    /**
5386
     * #360
5387
     * tag CTe/infCTe/cobr/fat (opcional)
5388
     * @param stdClass $std
5389
     * @return DOMElement
5390
     */
5391
    public function tagfat(stdClass $std)
5392
    {
5393
5394
        $possible = [
5395
            'nFat',
5396
            'vOrig',
5397
            'vDesc',
5398
            'vLiq'
5399
        ];
5400
5401
        $std = $this->equilizeParameters($std, $possible);
5402
5403
        $this->buildCobr();
5404
        $fat = $this->dom->createElement("fat");
5405
        $this->dom->addChild(
5406
            $fat,
5407
            "nFat",
5408
            $std->nFat,
5409
            false,
5410
            "Número da Fatura"
5411
        );
5412
        $this->dom->addChild(
5413
            $fat,
5414
            "vOrig",
5415
            $std->vOrig,
5416
            false,
5417
            "Valor Original da Fatura"
5418
        );
5419
        $this->dom->addChild(
5420
            $fat,
5421
            "vDesc",
5422
            $std->vDesc,
5423
            false,
5424
            "Valor do desconto"
5425
        );
5426
        $this->dom->addChild(
5427
            $fat,
5428
            "vLiq",
5429
            $std->vLiq,
5430
            false,
5431
            "Valor Líquido da Fatura"
5432
        );
5433
        $this->dom->appChild($this->cobr, $fat);
5434
        return $fat;
5435
    }
5436
5437
    /**
5438
     * #365
5439
     * tag CTe/infCTe/cobr/fat/dup (opcional)
5440
     * É necessário criar a tag fat antes de criar as duplicatas
5441
     * @param stdClass $std
5442
     * @return DOMElement
5443
     */
5444
    public function tagdup(stdClass $std)
5445
    {
5446
5447
        $possible = [
5448
            'nDup',
5449
            'dVenc',
5450
            'vDup'
5451
        ];
5452
5453
        $std = $this->equilizeParameters($std, $possible);
5454
5455
        $this->buildCobr();
5456
        $dup = $this->dom->createElement("dup");
5457
        $this->dom->addChild(
5458
            $dup,
5459
            "nDup",
5460
            $std->nDup,
5461
            false,
5462
            "Número da Duplicata"
5463
        );
5464
        $this->dom->addChild(
5465
            $dup,
5466
            "dVenc",
5467
            $std->dVenc,
5468
            false,
5469
            "Data de vencimento"
5470
        );
5471
        $this->dom->addChild(
5472
            $dup,
5473
            "vDup",
5474
            $std->vDup,
5475
            true,
5476
            "Valor da duplicata"
5477
        );
5478
        $this->dom->appChild($this->cobr, $dup, 'Inclui duplicata na tag cobr');
5479
        return $dup;
5480
    }
5481
5482
    /**
5483
     * Informações do Responsável técnico
5484
     * tag CTe/infCte/infRespTec (opcional)
5485
     * @return DOMElement
5486
     * @throws RuntimeException
5487
     */
5488
    public function taginfRespTec(stdClass $std)
5489
    {
5490
5491
        $possible = [
5492
            'CNPJ',
5493
            'xContato',
5494
            'email',
5495
            'fone',
5496
            'idCSRT',
5497
            'CSRT'
5498
        ];
5499
5500
        $std = $this->equilizeParameters($std, $possible);
5501
5502
        $infRespTec = $this->dom->createElement("infRespTec");
5503
        $this->dom->addChild(
5504
            $infRespTec,
5505
            "CNPJ",
5506
            $std->CNPJ,
5507
            true,
5508
            "Informar o CNPJ da pessoa jurídica responsável pelo sistema "
5509
            . "utilizado na emissão do documento fiscal eletrônico"
5510
        );
5511
        $this->dom->addChild(
5512
            $infRespTec,
5513
            "xContato",
5514
            $std->xContato,
5515
            true,
5516
            "Informar o nome da pessoa a ser contatada na empresa desenvolvedora "
5517
            . "do sistema utilizado na emissão do documento fiscal eletrônico"
5518
        );
5519
        $this->dom->addChild(
5520
            $infRespTec,
5521
            "email",
5522
            $std->email,
5523
            true,
5524
            "Informar o e-mail da pessoa a ser contatada na empresa "
5525
            . "desenvolvedora do sistema."
5526
        );
5527
        $this->dom->addChild(
5528
            $infRespTec,
5529
            "fone",
5530
            $std->fone,
5531
            true,
5532
            "Informar o telefone da pessoa a ser contatada na empresa "
5533
            . "desenvolvedora do sistema."
5534
        );
5535
        if (!empty($std->CSRT) && !empty($std->idCSRT)) {
5536
            $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...
5537
            $this->dom->addChild(
5538
                $infRespTec,
5539
                "idCSRT",
5540
                $std->idCSRT,
5541
                true,
5542
                "Identificador do CSRT utilizado para montar o hash do CSRT"
5543
            );
5544
            $this->dom->addChild(
5545
                $infRespTec,
5546
                "hashCSRT",
5547
                $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...
5548
                true,
5549
                "hash do CSRT"
5550
            );
5551
        }
5552
        $this->infRespTec = $infRespTec;
5553
        return $infRespTec;
5554
    }
5555
5556
    protected function checkCTeKey(Dom $dom)
5557
    {
5558
        $infCTe = $dom->getElementsByTagName("infCte")->item(0);
5559
        $ide = $dom->getElementsByTagName("ide")->item(0);
5560
        $emit = $dom->getElementsByTagName("emit")->item(0);
5561
        $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue;
5562
        $dhEmi = $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue;
5563
        $cnpj = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
5564
        $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue;
5565
        $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
5566
        $nNF = $ide->getElementsByTagName('nCT')->item(0)->nodeValue;
5567
        $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue;
5568
        $cCT = $ide->getElementsByTagName('cCT')->item(0)->nodeValue;
5569
        $chave = str_replace('CTe', '', $infCTe->getAttribute("Id"));
5570
5571
        $dt = new \DateTime($dhEmi);
5572
5573
        $chaveMontada = Keys::build(
5574
            $cUF,
5575
            $dt->format('y'),
5576
            $dt->format('m'),
5577
            $cnpj,
5578
            $mod,
5579
            $serie,
5580
            $nNF,
5581
            $tpEmis,
5582
            $cCT
5583
        );
5584
        //caso a chave contida no CTe esteja errada
5585
        //substituir a chave
5586
        if ($chaveMontada != $chave) {
5587
            $ide->getElementsByTagName('cDV')->item(0)->nodeValue = substr($chaveMontada, -1);
5588
            $infCTe = $dom->getElementsByTagName("infCte")->item(0);
5589
            $infCTe->setAttribute("Id", "CTe" . $chaveMontada);
5590
            $this->chCTe = $chaveMontada;
5591
        }
5592
    }
5593
    
5594
    /**
5595
     * Retorna os erros detectados
5596
     * @return array
5597
     */
5598
    public function getErrors()
5599
    {
5600
        return $this->errors;
5601
    }
5602
5603
    /**
5604
     * Includes missing or unsupported properties in stdClass
5605
     * Replace all unsuported chars
5606
     *
5607
     * @param  stdClass $std
5608
     * @param  array $possible
5609
     * @return stdClass
5610
     */
5611
    private function equilizeParameters(stdClass $std, $possible)
5612
    {
5613
        return Strings::equilizeParameters($std, $possible, $this->replaceAccentedChars);
5614
    }
5615
}
5616