Passed
Push — master ( 56e103...301f45 )
by
unknown
01:58
created

Make::checkCTeKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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