Passed
Push — master ( b3ed40...4f350f )
by Roberto
05:08 queued 02:39
created

Make::buildNFe()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
namespace NFePHP\NFe;
4
5
/**
6
 * Classe a construção do xml da NFe modelo 55 e modelo 65
7
 * Esta classe basica está estruturada para montar XML da NFe para o
8
 * layout versão 4.00, os demais modelos serão derivados deste
9
 *
10
 * @category  API
11
 * @package   NFePHP\NFe\
12
 * @copyright Copyright (c) 2008-2020
13
 * @license   http://www.gnu.org/licenses/lgpl.txt LGPLv3+
14
 * @license   https://opensource.org/licenses/MIT MIT
15
 * @license   http://www.gnu.org/licenses/gpl.txt GPLv3+
16
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
17
 * @link      http://github.com/nfephp-org/sped-nfe for the canonical source repository
18
 */
19
use NFePHP\Common\Keys;
20
use NFePHP\Common\DOMImproved as Dom;
21
use NFePHP\Common\Strings;
22
use NFePHP\NFe\Common\Gtin;
23
use stdClass;
24
use RuntimeException;
25
use InvalidArgumentException;
26
use DOMElement;
27
use DateTime;
28
29
class Make
30
{
31
    /**
32
     * @var array
33
     */
34
    public $errors = [];
35
    /**
36
     * @var string
37
     */
38
    public $chNFe;
39
    /**
40
     * @var string
41
     */
42
    public $xml;
43
    /**
44
     * @var string
45
     */
46
    protected $version;
47
    /**
48
     * @var integer
49
     */
50
    protected $mod = 55;
51
    /**
52
     * @var \NFePHP\Common\DOMImproved
53
     */
54
    public $dom;
55
    /**
56
     * @var integer
57
     */
58
    protected $tpAmb = 2;
59
    /**
60
     * @var DOMElement
61
     */
62
    protected $NFe;
63
    /**
64
     * @var DOMElement
65
     */
66
    protected $infNFe;
67
    /**
68
     * @var DOMElement
69
     */
70
    protected $ide;
71
    /**
72
     * @var DOMElement
73
     */
74
    protected $emit;
75
    /**
76
     * @var DOMElement
77
     */
78
    protected $enderEmit;
79
    /**
80
     * @var DOMElement
81
     */
82
    protected $dest;
83
    /**
84
     * @var DOMElement
85
     */
86
    protected $enderDest;
87
    /**
88
     * @var DOMElement
89
     */
90
    protected $retirada;
91
    /**
92
     * @var DOMElement
93
     */
94
    protected $entrega;
95
    /**
96
     * @var DOMElement
97
     */
98
    protected $total;
99
    /**
100
     * @var DOMElement
101
     */
102
    protected $cobr;
103
    /**
104
     * @var DOMElement
105
     */
106
    protected $transp;
107
    /**
108
     * @var DOMElement
109
     */
110
    protected $infAdic;
111
    /**
112
     * @var DOMElement
113
     */
114
    protected $exporta;
115
    /**
116
     * @var DOMElement
117
     */
118
    protected $compra;
119
    /**
120
     * @var DOMElement
121
     */
122
    protected $cana;
123
    /**
124
     * @var DOMElement
125
     */
126
    protected $infNFeSupl;
127
    /**
128
     * @var array of DOMElements
129
     */
130
    protected $aNFref = [];
131
    /**
132
     * @var array of DOMElements
133
     */
134
    protected $aDup = [];
135
    /**
136
     * @var DOMElement
137
     */
138
    protected $pag;
139
    /**
140
     * @var array of DOMElements
141
     */
142
    protected $aDetPag = [];
143
    /**
144
     * @var DOMElement
145
     */
146
    protected $intermed;
147
    /**
148
     * @var array of DOMElements
149
     */
150
    protected $aReboque = [];
151
    /**
152
     * @var array of DOMElements
153
     */
154
    protected $aVol = [];
155
    /**
156
     * @var array of DOMElements
157
     */
158
    protected $aAutXML = [];
159
    /**
160
     * @var array of DOMElements
161
     */
162
    protected $aDet = [];
163
    /**
164
     * @var array of DOMElements
165
     */
166
    protected $aProd = [];
167
    /**
168
     * @var array of DOMElements
169
     */
170
    protected $aRastro = [];
171
    /**
172
     * @var array of DOMElements
173
     */
174
    protected $aNVE = [];
175
    /**
176
     * @var array of DOMElements
177
     */
178
    protected $aCest = [];
179
    /**
180
     * @var array of DOMElements
181
     */
182
    protected $aRECOPI = [];
183
    /**
184
     * @var array of DOMElements
185
     */
186
    protected $aDetExport = [];
187
    /**
188
     * @var array of DOMElements
189
     */
190
    protected $aDI = [];
191
    /**
192
     * @var array of DOMElements
193
     */
194
    protected $aAdi = [];
195
    /**
196
     * @var array of DOMElements
197
     */
198
    protected $aVeicProd = [];
199
    /**
200
     * @var array of DOMElements
201
     */
202
    protected $aMed = [];
203
    /**
204
     * @var array of DOMElements
205
     */
206
    protected $aArma = [];
207
    /**
208
     * @var array of DOMElements
209
     */
210
    protected $aComb = [];
211
    /**
212
     * @var array of DOMElements
213
     */
214
    protected $aEncerrante = [];
215
    /**
216
     * @var array of DOMElements
217
     */
218
    protected $aImposto = [];
219
    /**
220
     * @var array of DOMElements
221
     */
222
    protected $aICMS = [];
223
    /**
224
     * @var array of DOMElements
225
     */
226
    protected $aICMSUFDest = [];
227
    /**
228
     * @var array of DOMElements
229
     */
230
    protected $aIPI = [];
231
    /**
232
     * @var array of DOMElements
233
     */
234
    protected $aII = [];
235
    /**
236
     * @var array of DOMElements
237
     */
238
    protected $aISSQN = [];
239
    /**
240
     * @var array
241
     */
242
    protected $aPIS = [];
243
    /**
244
     * @var array of DOMElements
245
     */
246
    protected $aPISST = [];
247
    /**
248
     * @var array of DOMElements
249
     */
250
    protected $aCOFINS = [];
251
    /**
252
     * @var array of DOMElements
253
     */
254
    protected $aCOFINSST = [];
255
    /**
256
     * @var array of DOMElements
257
     */
258
    protected $aImpostoDevol = [];
259
    /**
260
     * @var array of DOMElements
261
     */
262
    protected $aInfAdProd = [];
263
    /**
264
     * @var array of DOMElements
265
     */
266
    protected $aObsCont = [];
267
    /**
268
     * @var array of DOMElements
269
     */
270
    protected $aObsFisco = [];
271
    /**
272
     * @var array of DOMElements
273
     */
274
    protected $aProcRef = [];
275
    /**
276
     * @var stdClass
277
     */
278
    protected $stdTot;
279
    /**
280
     * @var DOMElement
281
     */
282
    protected $infRespTec;
283
    /**
284
     * @var string
285
     */
286
    protected $csrt;
287
    /**
288
     * @var boolean
289
     */
290
    protected $replaceAccentedChars = false;
291
292
    /**
293
     * Função construtora cria um objeto DOMDocument
294
     * que será carregado com o documento fiscal
295
     */
296 7
    public function __construct()
297
    {
298 7
        $this->dom = new Dom('1.0', 'UTF-8');
299 7
        $this->dom->preserveWhiteSpace = false;
300 7
        $this->dom->formatOutput = false;
301
        //elemento totalizador
302 7
        $this->stdTot = new \stdClass();
303 7
        $this->stdTot->vBC = 0;
304 7
        $this->stdTot->vICMS = 0;
305 7
        $this->stdTot->vICMSDeson = 0;
306 7
        $this->stdTot->vFCP = 0;
307 7
        $this->stdTot->vFCPUFDest = 0;
308 7
        $this->stdTot->vICMSUFDest = 0;
309 7
        $this->stdTot->vICMSUFRemet = 0;
310 7
        $this->stdTot->vBCST = 0;
311 7
        $this->stdTot->vST = 0;
312 7
        $this->stdTot->vFCPST = 0;
313 7
        $this->stdTot->vFCPSTRet = 0;
314 7
        $this->stdTot->vProd = 0;
315 7
        $this->stdTot->vFrete = 0;
316 7
        $this->stdTot->vSeg = 0;
317 7
        $this->stdTot->vDesc = 0;
318 7
        $this->stdTot->vII = 0;
319 7
        $this->stdTot->vIPI = 0;
320 7
        $this->stdTot->vIPIDevol = 0;
321 7
        $this->stdTot->vPIS = 0;
322 7
        $this->stdTot->vCOFINS = 0;
323 7
        $this->stdTot->vOutro = 0;
324 7
        $this->stdTot->vNF = 0;
325 7
        $this->stdTot->vTotTrib = 0;
326 7
    }
327
328
    /**
329
     * Set character convertion to ASCII only ou not
330
     * @param bool $option
331
     */
332
    public function setOnlyAscii($option = false)
333
    {
334
        $this->replaceAccentedChars = $option;
335
    }
336
337
    /**
338
     * Returns xml string and assembly it is necessary
339
     * @return string
340
     */
341
    public function getXML()
342
    {
343
        if (empty($this->xml)) {
344
            $this->montaNFe();
345
        }
346
        return $this->xml;
347
    }
348
349
    /**
350
     * Retorns the key number of NFe (44 digits)
351
     * @return string
352
     */
353 1
    public function getChave()
354
    {
355 1
        return $this->chNFe;
356
    }
357
358
    /**
359
     * Returns the model of NFe 55 or 65
360
     * @return int
361
     */
362
    public function getModelo()
363
    {
364
        return $this->mod;
365
    }
366
367
    /**
368
     * Call method of xml assembly. For compatibility only.
369
     * @return string
370
     */
371
    public function montaNFe()
372
    {
373
        return $this->monta();
374
    }
375
376
    /**
377
     * NFe xml mount method
378
     * this function returns TRUE on success or FALSE on error
379
     * The xml of the NFe must be retrieved by the getXML() function or
380
     * directly by the public property $xml
381
     *
382
     * @return string
383
     * @throws RuntimeException
384
     */
385
    public function monta()
386
    {
387
        if (!empty($this->errors)) {
388
            $this->errors = array_merge($this->errors, $this->dom->errors);
389
        } else {
390
            $this->errors = $this->dom->errors;
391
        }
392
        //cria a tag raiz da Nfe
393
        $this->buildNFe();
394
        //processa nfeRef e coloca as tags na tag ide
395
        foreach ($this->aNFref as $nfeRef) {
396
            $this->dom->appChild($this->ide, $nfeRef, 'Falta tag "ide"');
397
        }
398
        //monta as tags det e coloca no array $this->aDet com os detalhes dos produtos
399
        $this->buildDet();
400
        //[2] tag ide (5 B01)
401
        $this->dom->appChild($this->infNFe, $this->ide, 'Falta tag "infNFe"');
402
        //[8] tag emit (30 C01)
403
        $this->dom->appChild($this->infNFe, $this->emit, 'Falta tag "infNFe"');
404
        //[10] tag dest (62 E01)
405
        $this->dom->appChild($this->infNFe, $this->dest, 'Falta tag "infNFe"');
406
        //[12] tag retirada (80 F01)
407
        $this->dom->appChild($this->infNFe, $this->retirada, 'Falta tag "infNFe"');
408
        //[13] tag entrega (89 G01)
409
        $this->dom->appChild($this->infNFe, $this->entrega, 'Falta tag "infNFe"');
410
        //[14] tag autXML (97a.1 G50)
411
        foreach ($this->aAutXML as $aut) {
412
            $this->dom->appChild($this->infNFe, $aut, 'Falta tag "infNFe"');
413
        }
414
        //[14a] tag det (98 H01)
415
        foreach ($this->aDet as $det) {
416
            $this->dom->appChild($this->infNFe, $det, 'Falta tag "infNFe"');
417
        }
418
        //força a construção do total caso não sejam chamado metodo tagICMSTot()
419
        if (empty($this->total)) {
420
            $std = new \stdClass();
421
            $this->tagICMSTot($std);
422
        }
423
        //[28a] tag total (326 W01)
424
        $this->dom->appChild($this->infNFe, $this->total, 'Falta tag "infNFe"');
425
        //mota a tag vol
426
        $this->buildVol();
427
        //[32] tag transp (356 X01)
428
        $this->dom->appChild($this->infNFe, $this->transp, 'Falta tag "infNFe"');
429
        //[39a] tag cobr (389 Y01)
430
        $this->dom->appChild($this->infNFe, $this->cobr, 'Falta tag "infNFe"');
431
        //[42] tag pag (398a YA01)
432
        //processa Pag e coloca as tags na tag pag
433
        $this->buildTagPag();
434
        //[43] tag infIntermed (398.26 YB01) NT 2020.006_1.00
435
        $this->dom->appChild($this->infNFe, $this->intermed, 'Falta tag "infNFe"');
436
        //[44] tag infAdic (399 Z01)
437
        $this->dom->appChild($this->infNFe, $this->infAdic, 'Falta tag "infNFe"');
438
        //[48] tag exporta (402 ZA01)
439
        $this->dom->appChild($this->infNFe, $this->exporta, 'Falta tag "infNFe"');
440
        //[49] tag compra (405 ZB01)
441
        $this->dom->appChild($this->infNFe, $this->compra, 'Falta tag "infNFe"');
442
        //[50] tag cana (409 ZC01)
443
        $this->dom->appChild($this->infNFe, $this->cana, 'Falta tag "infNFe"');
444
        //Responsável Técnico
445
        $this->dom->appChild($this->infNFe, $this->infRespTec, 'Falta tag "infNFe"');
446
        //[1] tag infNFe (1 A01)
447
        $this->dom->appChild($this->NFe, $this->infNFe, 'Falta tag "NFe"');
448
        //[0] tag NFe
449
        $this->dom->appendChild($this->NFe);
450
        // testa da chave
451
        $this->checkNFeKey($this->dom);
452
        $this->xml = $this->dom->saveXML();
453
        if (count($this->errors) > 0) {
454
            throw new RuntimeException('Existem erros nas tags. Obtenha os erros com getErrors().');
455
        }
456
        return $this->xml;
457
    }
458
459
    /**
460
     * Informações da NF-e A01 pai NFe
461
     * tag NFe/infNFe
462
     * @param  stdClass $std
463
     * @return DOMElement
464
     */
465 7
    public function taginfNFe(stdClass $std)
466
    {
467 7
        $possible = ['Id', 'versao', 'pk_nItem'];
468 7
        $std = $this->equilizeParameters($std, $possible);
469 7
        $chave = preg_replace('/[^0-9]/', '', $std->Id);
470 7
        $this->infNFe = $this->dom->createElement("infNFe");
471 7
        $this->infNFe->setAttribute("Id", 'NFe' . $chave);
472 7
        $this->infNFe->setAttribute(
473 7
            "versao",
474 7
            $std->versao
475
        );
476 7
        $this->version = $std->versao;
477 7
        if (!empty($std->pk_nItem)) {
478 1
            $this->infNFe->setAttribute("pk_nItem", $std->pk_nItem);
479
        }
480 7
        $this->chNFe = $chave;
481 7
        return $this->infNFe;
482
    }
483
484
    /**
485
     * Informações de identificação da NF-e B01 pai A01
486
     * NOTA: Ajustado para NT2020_006_v1.00
487
     * tag NFe/infNFe/ide
488
     * @param  stdClass $std
489
     * @return DOMElement
490
     */
491 4
    public function tagide(stdClass $std)
492
    {
493
        $possible = [
494 4
            'cUF',
495
            'cNF',
496
            'natOp',
497
            'indPag',
498
            'mod',
499
            'serie',
500
            'nNF',
501
            'dhEmi',
502
            'dhSaiEnt',
503
            'tpNF',
504
            'idDest',
505
            'cMunFG',
506
            'tpImp',
507
            'tpEmis',
508
            'cDV',
509
            'tpAmb',
510
            'finNFe',
511
            'indFinal',
512
            'indPres',
513
            'indIntermed',
514
            'procEmi',
515
            'verProc',
516
            'dhCont',
517
            'xJust'
518
        ];
519 4
        $std = $this->equilizeParameters($std, $possible);
520
521 4
        if (empty($std->cNF)) {
522 1
            $std->cNF = Keys::random($std->nNF);
523
        }
524 4
        if (empty($std->cDV)) {
525 2
            $std->cDV = 0;
526
        }
527
        //validação conforme NT 2019.001
528 4
        $std->cNF = str_pad($std->cNF, 8, '0', STR_PAD_LEFT);
529 4
        if (intval($std->cNF) == intval($std->nNF)) {
530
            throw new InvalidArgumentException("O valor [{$std->cNF}] não é "
531
            . "aceitável para cNF, não pode ser igual ao de nNF, vide NT2019.001");
532
        }
533 4
        if (method_exists(Keys::class, 'cNFIsValid')) {
534 4
            if (!Keys::cNFIsValid($std->cNF)) {
535
                throw new InvalidArgumentException("O valor [{$std->cNF}] para cNF "
536
                . "é invalido, deve respeitar a NT2019.001");
537
            }
538
        }
539 4
        $this->tpAmb = $std->tpAmb;
540 4
        $this->mod = $std->mod;
541 4
        $identificador = 'B01 <ide> - ';
542 4
        $ide = $this->dom->createElement("ide");
543 4
        $this->dom->addChild(
544 4
            $ide,
545 4
            "cUF",
546 4
            $std->cUF,
547 4
            true,
548 4
            $identificador . "Código da UF do emitente do Documento Fiscal"
549
        );
550 4
        $this->dom->addChild(
551 4
            $ide,
552 4
            "cNF",
553 4
            $std->cNF,
554 4
            true,
555 4
            $identificador . "Código Numérico que compõe a Chave de Acesso"
556
        );
557 4
        $this->dom->addChild(
558 4
            $ide,
559 4
            "natOp",
560 4
            substr(trim($std->natOp), 0, 60),
561 4
            true,
562 4
            $identificador . "Descrição da Natureza da Operação"
563
        );
564 4
        $this->dom->addChild(
565 4
            $ide,
566 4
            "mod",
567 4
            $std->mod,
568 4
            true,
569 4
            $identificador . "Código do Modelo do Documento Fiscal"
570
        );
571 4
        $this->dom->addChild(
572 4
            $ide,
573 4
            "serie",
574 4
            $std->serie,
575 4
            true,
576 4
            $identificador . "Série do Documento Fiscal"
577
        );
578 4
        $this->dom->addChild(
579 4
            $ide,
580 4
            "nNF",
581 4
            $std->nNF,
582 4
            true,
583 4
            $identificador . "Número do Documento Fiscal"
584
        );
585 4
        $this->dom->addChild(
586 4
            $ide,
587 4
            "dhEmi",
588 4
            $std->dhEmi,
589 4
            true,
590 4
            $identificador . "Data e hora de emissão do Documento Fiscal"
591
        );
592 4
        if ($std->mod == '55' && !empty($std->dhSaiEnt)) {
593 1
            $this->dom->addChild(
594 1
                $ide,
595 1
                "dhSaiEnt",
596 1
                $std->dhSaiEnt,
597 1
                false,
598 1
                $identificador . "Data e hora de Saída ou da Entrada da Mercadoria/Produto"
599
            );
600
        }
601 4
        $this->dom->addChild(
602 4
            $ide,
603 4
            "tpNF",
604 4
            $std->tpNF,
605 4
            true,
606 4
            $identificador . "Tipo de Operação"
607
        );
608 4
        $this->dom->addChild(
609 4
            $ide,
610 4
            "idDest",
611 4
            $std->idDest,
612 4
            true,
613 4
            $identificador . "Identificador de local de destino da operação"
614
        );
615 4
        $this->dom->addChild(
616 4
            $ide,
617 4
            "cMunFG",
618 4
            $std->cMunFG,
619 4
            true,
620 4
            $identificador . "Código do Município de Ocorrência do Fato Gerador"
621
        );
622 4
        $this->dom->addChild(
623 4
            $ide,
624 4
            "tpImp",
625 4
            $std->tpImp,
626 4
            true,
627 4
            $identificador . "Formato de Impressão do DANFE"
628
        );
629 4
        $this->dom->addChild(
630 4
            $ide,
631 4
            "tpEmis",
632 4
            $std->tpEmis,
633 4
            true,
634 4
            $identificador . "Tipo de Emissão da NF-e"
635
        );
636 4
        $this->dom->addChild(
637 4
            $ide,
638 4
            "cDV",
639 4
            !empty($std->cDV) ? $std->cDV : '0',
640 4
            true,
641 4
            $identificador . "Dígito Verificador da Chave de Acesso da NF-e"
642
        );
643 4
        $this->dom->addChild(
644 4
            $ide,
645 4
            "tpAmb",
646 4
            $std->tpAmb,
647 4
            true,
648 4
            $identificador . "Identificação do Ambiente"
649
        );
650 4
        $this->dom->addChild(
651 4
            $ide,
652 4
            "finNFe",
653 4
            $std->finNFe,
654 4
            true,
655 4
            $identificador . "Finalidade de emissão da NF-e"
656
        );
657 4
        $this->dom->addChild(
658 4
            $ide,
659 4
            "indFinal",
660 4
            $std->indFinal,
661 4
            true,
662 4
            $identificador . "Indica operação com Consumidor final"
663
        );
664 4
        $this->dom->addChild(
665 4
            $ide,
666 4
            "indPres",
667 4
            $std->indPres,
668 4
            true,
669 4
            $identificador . "Indicador de presença do comprador no estabelecimento comercial no momento da operação"
670
        );
671 4
        $this->dom->addChild(
672 4
            $ide,
673 4
            "indIntermed",
674 4
            isset($std->indIntermed) ? $std->indIntermed : null,
675 4
            false,
676 4
            $identificador . "Indicador de intermediador/marketplace"
677
        );
678 4
        $this->dom->addChild(
679 4
            $ide,
680 4
            "procEmi",
681 4
            $std->procEmi,
682 4
            true,
683 4
            $identificador . "Processo de emissão da NF-e"
684
        );
685 4
        $this->dom->addChild(
686 4
            $ide,
687 4
            "verProc",
688 4
            $std->verProc,
689 4
            true,
690 4
            $identificador . "Versão do Processo de emissão da NF-e"
691
        );
692 4
        if (!empty($std->dhCont) && !empty($std->xJust)) {
693 1
            $this->dom->addChild(
694 1
                $ide,
695 1
                "dhCont",
696 1
                $std->dhCont,
697 1
                true,
698 1
                $identificador . "Data e Hora da entrada em contingência"
699
            );
700 1
            $this->dom->addChild(
701 1
                $ide,
702 1
                "xJust",
703 1
                substr(trim($std->xJust), 0, 256),
704 1
                true,
705 1
                $identificador . "Justificativa da entrada em contingência"
706
            );
707
        }
708 4
        $this->ide = $ide;
709 4
        return $ide;
710
    }
711
712
    /**
713
     * Chave de acesso da NF-e referenciada BA02 pai BA01
714
     * tag NFe/infNFe/ide/NFref/refNFe
715
     * @param  stdClass $std
716
     * @return DOMElement
717
     */
718
    public function tagrefNFe(stdClass $std)
719
    {
720
        $possible = ['refNFe'];
721
        $std = $this->equilizeParameters($std, $possible);
722
723
        $num = $this->buildNFref();
724
        $refNFe = $this->dom->createElement("refNFe", $std->refNFe);
725
        $this->dom->appChild($this->aNFref[$num - 1], $refNFe);
726
        return $refNFe;
727
    }
728
729
    /**
730
     * Informação da NF modelo 1/1A referenciada BA03 pai BA01
731
     * tag NFe/infNFe/ide/NFref/NF DOMNode
732
     * @param  stdClass $std
733
     * @return DOMElement
734
     */
735
    public function tagrefNF(stdClass $std)
736
    {
737
        $possible = ['cUF', 'AAMM', 'CNPJ', 'mod', 'serie', 'nNF'];
738
        $std = $this->equilizeParameters($std, $possible);
739
740
        $identificador = 'BA03 <refNF> - ';
741
        $num = $this->buildNFref();
742
        $refNF = $this->dom->createElement("refNF");
743
        $this->dom->addChild(
744
            $refNF,
745
            "cUF",
746
            $std->cUF,
747
            true,
748
            $identificador . "Código da UF do emitente"
749
        );
750
        $this->dom->addChild(
751
            $refNF,
752
            "AAMM",
753
            $std->AAMM,
754
            true,
755
            $identificador . "Ano e Mês de emissão da NF-e"
756
        );
757
        $this->dom->addChild(
758
            $refNF,
759
            "CNPJ",
760
            $std->CNPJ,
761
            true,
762
            $identificador . "CNPJ do emitente"
763
        );
764
        $this->dom->addChild(
765
            $refNF,
766
            "mod",
767
            $std->mod,
768
            true,
769
            $identificador . "Modelo do Documento Fiscal"
770
        );
771
        $this->dom->addChild(
772
            $refNF,
773
            "serie",
774
            $std->serie,
775
            true,
776
            $identificador . "Série do Documento Fiscal"
777
        );
778
        $this->dom->addChild(
779
            $refNF,
780
            "nNF",
781
            $std->nNF,
782
            true,
783
            $identificador . "Número do Documento Fiscal"
784
        );
785
        $this->dom->appChild($this->aNFref[$num - 1], $refNF);
786
        return $refNF;
787
    }
788
789
    /**
790
     * Informações da NF de produtor rural referenciada BA10 pai BA01
791
     * tag NFe/infNFe/ide/NFref/refNFP
792
     * @param  stdClass $std
793
     * @return DOMElement
794
     */
795
    public function tagrefNFP(stdClass $std)
796
    {
797
        $possible = [
798
            'cUF',
799
            'AAMM',
800
            'CNPJ',
801
            'CPF',
802
            'IE',
803
            'mod',
804
            'serie',
805
            'nNF'
806
        ];
807
        $std = $this->equilizeParameters($std, $possible);
808
809
        $identificador = 'BA10 <refNFP> - ';
810
        $num = $this->buildNFref();
811
        $refNFP = $this->dom->createElement("refNFP");
812
        $this->dom->addChild(
813
            $refNFP,
814
            "cUF",
815
            $std->cUF,
816
            true,
817
            $identificador . "Código da UF do emitente"
818
        );
819
        $this->dom->addChild(
820
            $refNFP,
821
            "AAMM",
822
            $std->AAMM,
823
            true,
824
            $identificador . "AAMM da emissão da NF de produtor"
825
        );
826
        $this->dom->addChild(
827
            $refNFP,
828
            "CNPJ",
829
            $std->CNPJ,
830
            false,
831
            $identificador . "Informar o CNPJ do emitente da NF de produtor"
832
        );
833
        $this->dom->addChild(
834
            $refNFP,
835
            "CPF",
836
            $std->CPF,
837
            false,
838
            $identificador . "Informar o CPF do emitente da NF de produtor"
839
        );
840
        $this->dom->addChild(
841
            $refNFP,
842
            "IE",
843
            $std->IE,
844
            true,
845
            $identificador . "Informar a IE do emitente da NF de Produtor ou o literal 'ISENTO'"
846
        );
847
        $this->dom->addChild(
848
            $refNFP,
849
            "mod",
850
            str_pad($std->mod, 2, '0', STR_PAD_LEFT),
851
            true,
852
            $identificador . "Modelo do Documento Fiscal"
853
        );
854
        $this->dom->addChild(
855
            $refNFP,
856
            "serie",
857
            $std->serie,
858
            true,
859
            $identificador . "Série do Documento Fiscal"
860
        );
861
        $this->dom->addChild(
862
            $refNFP,
863
            "nNF",
864
            $std->nNF,
865
            true,
866
            $identificador . "Número do Documento Fiscal"
867
        );
868
        $this->dom->appChild($this->aNFref[$num - 1], $refNFP);
869
        return $refNFP;
870
    }
871
872
    /**
873
     * Chave de acesso do CT-e referenciada BA19 pai BA01
874
     * tag NFe/infNFe/ide/NFref/refCTe
875
     * @param  stdClass $std
876
     * @return DOMElement
877
     */
878
    public function tagrefCTe(stdClass $std)
879
    {
880
        $possible = ['refCTe'];
881
        $std = $this->equilizeParameters($std, $possible);
882
883
        $num = $this->buildNFref();
884
        $refCTe = $this->dom->createElement("refCTe", $std->refCTe);
885
        $this->dom->appChild($this->aNFref[$num - 1], $refCTe);
886
        return $refCTe;
887
    }
888
889
    /**
890
     * Informações do Cupom Fiscal referenciado BA20 pai BA01
891
     * tag NFe/infNFe/ide/NFref/refECF
892
     * @param stdClass $std
893
     * @return DOMElement
894
     */
895
    public function tagrefECF(stdClass $std)
896
    {
897
        $possible = ['mod', 'nECF', 'nCOO'];
898
        $std = $this->equilizeParameters($std, $possible);
899
900
        $identificador = 'BA20 <refECF> - ';
901
        $num = $this->buildNFref();
902
        $refECF = $this->dom->createElement("refECF");
903
        $this->dom->addChild(
904
            $refECF,
905
            "mod",
906
            $std->mod,
907
            true,
908
            $identificador . "Modelo do Documento Fiscal"
909
        );
910
        $this->dom->addChild(
911
            $refECF,
912
            "nECF",
913
            str_pad($std->nECF, 3, '0', STR_PAD_LEFT),
914
            true,
915
            $identificador . "Número de ordem sequencial do ECF"
916
        );
917
        $this->dom->addChild(
918
            $refECF,
919
            "nCOO",
920
            str_pad($std->nCOO, 6, '0', STR_PAD_LEFT),
921
            true,
922
            $identificador . "Número do Contador de Ordem de Operação - COO"
923
        );
924
        $this->dom->appChild($this->aNFref[$num - 1], $refECF);
925
        return $refECF;
926
    }
927
928
    /**
929
     * Identificação do emitente da NF-e C01 pai A01
930
     * tag NFe/infNFe/emit
931
     * @param  stdClass $std
932
     * @return DOMElement
933
     */
934
    public function tagemit(stdClass $std)
935
    {
936
        $possible = [
937
            'xNome',
938
            'xFant',
939
            'IE',
940
            'IEST',
941
            'IM',
942
            'CNAE',
943
            'CRT',
944
            'CNPJ',
945
            'CPF'
946
        ];
947
        $std = $this->equilizeParameters($std, $possible);
948
        $identificador = 'C01 <emit> - ';
949
        $this->emit = $this->dom->createElement("emit");
950
        if (!empty($std->CNPJ)) {
951
            $this->dom->addChild(
952
                $this->emit,
953
                "CNPJ",
954
                Strings::onlyNumbers($std->CNPJ),
955
                false,
956
                $identificador . "CNPJ do emitente"
957
            );
958
        } elseif (!empty($std->CPF)) {
959
            $this->dom->addChild(
960
                $this->emit,
961
                "CPF",
962
                Strings::onlyNumbers($std->CPF),
963
                false,
964
                $identificador . "CPF do remetente"
965
            );
966
        }
967
        $this->dom->addChild(
968
            $this->emit,
969
            "xNome",
970
            substr(trim($std->xNome), 0, 60),
971
            true,
972
            $identificador . "Razão Social ou Nome do emitente"
973
        );
974
        $this->dom->addChild(
975
            $this->emit,
976
            "xFant",
977
            substr(trim($std->xFant), 0, 60),
978
            false,
979
            $identificador . "Nome fantasia do emitente"
980
        );
981
        if ($std->IE != 'ISENTO') {
982
            $std->IE = Strings::onlyNumbers($std->IE);
983
        }
984
        $this->dom->addChild(
985
            $this->emit,
986
            "IE",
987
            $std->IE,
988
            true,
989
            $identificador . "Inscrição Estadual do emitente"
990
        );
991
        $this->dom->addChild(
992
            $this->emit,
993
            "IEST",
994
            Strings::onlyNumbers($std->IEST),
995
            false,
996
            $identificador . "IE do Substituto Tributário do emitente"
997
        );
998
        $this->dom->addChild(
999
            $this->emit,
1000
            "IM",
1001
            Strings::onlyNumbers($std->IM),
1002
            false,
1003
            $identificador . "Inscrição Municipal do Prestador de Serviço do emitente"
1004
        );
1005
        if (!empty($std->IM) && !empty($std->CNAE)) {
1006
            $this->dom->addChild(
1007
                $this->emit,
1008
                "CNAE",
1009
                Strings::onlyNumbers($std->CNAE),
1010
                false,
1011
                $identificador . "CNAE fiscal do emitente"
1012
            );
1013
        }
1014
        $this->dom->addChild(
1015
            $this->emit,
1016
            "CRT",
1017
            $std->CRT,
1018
            true,
1019
            $identificador . "Código de Regime Tributário do emitente"
1020
        );
1021
        return $this->emit;
1022
    }
1023
1024
    /**
1025
     * Endereço do emitente C05 pai C01
1026
     * tag NFe/infNFe/emit/endEmit
1027
     * @param stdClass $std
1028
     * @return DOMElement
1029
     */
1030
    public function tagenderEmit(stdClass $std)
1031
    {
1032
        $possible = [
1033
            'xLgr',
1034
            'nro',
1035
            'xCpl',
1036
            'xBairro',
1037
            'cMun',
1038
            'xMun',
1039
            'UF',
1040
            'CEP',
1041
            'cPais',
1042
            'xPais',
1043
            'fone'
1044
        ];
1045
        $std = $this->equilizeParameters($std, $possible);
1046
1047
        $identificador = 'C05 <enderEmit> - ';
1048
        $this->enderEmit = $this->dom->createElement("enderEmit");
1049
        $this->dom->addChild(
1050
            $this->enderEmit,
1051
            "xLgr",
1052
            substr(trim($std->xLgr), 0, 60),
1053
            true,
1054
            $identificador . "Logradouro do Endereço do emitente"
1055
        );
1056
        $this->dom->addChild(
1057
            $this->enderEmit,
1058
            "nro",
1059
            substr(trim($std->nro), 0, 60),
1060
            true,
1061
            $identificador . "Número do Endereço do emitente"
1062
        );
1063
        $this->dom->addChild(
1064
            $this->enderEmit,
1065
            "xCpl",
1066
            substr(trim($std->xCpl), 0, 60),
1067
            false,
1068
            $identificador . "Complemento do Endereço do emitente"
1069
        );
1070
        $this->dom->addChild(
1071
            $this->enderEmit,
1072
            "xBairro",
1073
            substr(trim($std->xBairro), 0, 60),
1074
            true,
1075
            $identificador . "Bairro do Endereço do emitente"
1076
        );
1077
        $this->dom->addChild(
1078
            $this->enderEmit,
1079
            "cMun",
1080
            Strings::onlyNumbers($std->cMun),
1081
            true,
1082
            $identificador . "Código do município do Endereço do emitente"
1083
        );
1084
        $this->dom->addChild(
1085
            $this->enderEmit,
1086
            "xMun",
1087
            substr(trim($std->xMun), 0, 60),
1088
            true,
1089
            $identificador . "Nome do município do Endereço do emitente"
1090
        );
1091
        $this->dom->addChild(
1092
            $this->enderEmit,
1093
            "UF",
1094
            strtoupper(trim($std->UF)),
1095
            true,
1096
            $identificador . "Sigla da UF do Endereço do emitente"
1097
        );
1098
        $this->dom->addChild(
1099
            $this->enderEmit,
1100
            "CEP",
1101
            Strings::onlyNumbers($std->CEP),
1102
            true,
1103
            $identificador . "Código do CEP do Endereço do emitente"
1104
        );
1105
        $this->dom->addChild(
1106
            $this->enderEmit,
1107
            "cPais",
1108
            Strings::onlyNumbers($std->cPais),
1109
            false,
1110
            $identificador . "Código do País do Endereço do emitente"
1111
        );
1112
        $this->dom->addChild(
1113
            $this->enderEmit,
1114
            "xPais",
1115
            substr(trim($std->xPais), 0, 60),
1116
            false,
1117
            $identificador . "Nome do País do Endereço do emitente"
1118
        );
1119
        $this->dom->addChild(
1120
            $this->enderEmit,
1121
            "fone",
1122
            trim($std->fone),
1123
            false,
1124
            $identificador . "Telefone do Endereço do emitente"
1125
        );
1126
        $node = $this->emit->getElementsByTagName("IE")->item(0);
1127
        $this->emit->insertBefore($this->enderEmit, $node);
1128
        return $this->enderEmit;
1129
    }
1130
1131
    /**
1132
     * Identificação do Destinatário da NF-e E01 pai A01
1133
     * tag NFe/infNFe/dest (opcional para modelo 65)
1134
     * @param stdClass $std
1135
     * @return DOMElement
1136
     */
1137
    public function tagdest(stdClass $std)
1138
    {
1139
        $possible = [
1140
            'xNome',
1141
            'indIEDest',
1142
            'IE',
1143
            'ISUF',
1144
            'IM',
1145
            'email',
1146
            'CNPJ',
1147
            'CPF',
1148
            'idEstrangeiro'
1149
        ];
1150
        $std = $this->equilizeParameters($std, $possible);
1151
        $identificador = 'E01 <dest> - ';
1152
        $flagNome = true; //marca se xNome é ou não obrigatório
1153
        $temIE = $std->IE != '' && $std->IE != 'ISENTO'; // Tem inscrição municipal
1154
        $this->dest = $this->dom->createElement("dest");
1155
        if (!$temIE && $std->indIEDest == 1) {
1156
            $std->indIEDest = 2;
1157
        }
1158
        if ($this->mod == '65') {
1159
            $std->indIEDest = 9;
1160
            if ($std->xNome == '') {
1161
                $flagNome = false; //marca se xNome é ou não obrigatório
1162
            }
1163
        }
1164
        $xNome = $std->xNome;
1165
        if ($this->tpAmb == '2') {
1166
            $xNome = 'NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
1167
            //a exigência do CNPJ 99999999000191 não existe mais
1168
        }
1169
        if (!empty($std->CNPJ)) {
1170
            $this->dom->addChild(
1171
                $this->dest,
1172
                "CNPJ",
1173
                Strings::onlyNumbers($std->CNPJ),
1174
                true,
1175
                $identificador . "CNPJ do destinatário"
1176
            );
1177
        } elseif (!empty($std->CPF)) {
1178
            $this->dom->addChild(
1179
                $this->dest,
1180
                "CPF",
1181
                Strings::onlyNumbers($std->CPF),
1182
                true,
1183
                $identificador . "CPF do destinatário"
1184
            );
1185
        } elseif ($std->idEstrangeiro !== null) {
1186
            $this->dom->addChild(
1187
                $this->dest,
1188
                "idEstrangeiro",
1189
                $std->idEstrangeiro,
1190
                true,
1191
                $identificador . "Identificação do destinatário no caso de comprador estrangeiro",
1192
                true
1193
            );
1194
            $std->indIEDest = '9';
1195
        }
1196
        $this->dom->addChild(
1197
            $this->dest,
1198
            "xNome",
1199
            substr(trim($xNome), 0, 60),
1200
            $flagNome, //se mod 55 true ou mod 65 false
1201
            $identificador . "Razão Social ou nome do destinatário"
1202
        );
1203
        $this->dom->addChild(
1204
            $this->dest,
1205
            "indIEDest",
1206
            Strings::onlyNumbers($std->indIEDest),
1207
            true,
1208
            $identificador . "Indicador da IE do Destinatário"
1209
        );
1210
        if ($temIE) {
1211
            $this->dom->addChild(
1212
                $this->dest,
1213
                "IE",
1214
                $std->IE,
1215
                true,
1216
                $identificador . "Inscrição Estadual do Destinatário"
1217
            );
1218
        }
1219
        $this->dom->addChild(
1220
            $this->dest,
1221
            "ISUF",
1222
            Strings::onlyNumbers($std->ISUF),
1223
            false,
1224
            $identificador . "Inscrição na SUFRAMA do destinatário"
1225
        );
1226
        $this->dom->addChild(
1227
            $this->dest,
1228
            "IM",
1229
            Strings::onlyNumbers($std->IM),
1230
            false,
1231
            $identificador . "Inscrição Municipal do Tomador do Serviço do destinatário"
1232
        );
1233
        $this->dom->addChild(
1234
            $this->dest,
1235
            "email",
1236
            substr(trim($std->email), 0, 60),
1237
            false,
1238
            $identificador . "Email do destinatário"
1239
        );
1240
        return $this->dest;
1241
    }
1242
1243
    /**
1244
     * Endereço do Destinatário da NF-e E05 pai E01
1245
     * tag NFe/infNFe/dest/enderDest  (opcional para modelo 65)
1246
     * Os dados do destinatário devem ser inseridos antes deste método
1247
     * @param stdClass $std
1248
     * @return DOMElement
1249
     */
1250
    public function tagenderDest(stdClass $std)
1251
    {
1252
        $possible = [
1253
            'xLgr',
1254
            'nro',
1255
            'xCpl',
1256
            'xBairro',
1257
            'cMun',
1258
            'xMun',
1259
            'UF',
1260
            'CEP',
1261
            'cPais',
1262
            'xPais',
1263
            'fone'
1264
        ];
1265
        $std = $this->equilizeParameters($std, $possible);
1266
1267
        $identificador = 'E05 <enderDest> - ';
1268
        if (empty($this->dest)) {
1269
            throw new RuntimeException('A TAG dest deve ser criada antes do endereço do mesmo.');
1270
        }
1271
        $this->enderDest = $this->dom->createElement("enderDest");
1272
        $this->dom->addChild(
1273
            $this->enderDest,
1274
            "xLgr",
1275
            $std->xLgr,
1276
            true,
1277
            $identificador . "Logradouro do Endereço do Destinatário"
1278
        );
1279
        $this->dom->addChild(
1280
            $this->enderDest,
1281
            "nro",
1282
            $std->nro,
1283
            true,
1284
            $identificador . "Número do Endereço do Destinatário"
1285
        );
1286
        $this->dom->addChild(
1287
            $this->enderDest,
1288
            "xCpl",
1289
            $std->xCpl,
1290
            false,
1291
            $identificador . "Complemento do Endereço do Destinatário"
1292
        );
1293
        $this->dom->addChild(
1294
            $this->enderDest,
1295
            "xBairro",
1296
            $std->xBairro,
1297
            true,
1298
            $identificador . "Bairro do Endereço do Destinatário"
1299
        );
1300
        $this->dom->addChild(
1301
            $this->enderDest,
1302
            "cMun",
1303
            $std->cMun,
1304
            true,
1305
            $identificador . "Código do município do Endereço do Destinatário"
1306
        );
1307
        $this->dom->addChild(
1308
            $this->enderDest,
1309
            "xMun",
1310
            $std->xMun,
1311
            true,
1312
            $identificador . "Nome do município do Endereço do Destinatário"
1313
        );
1314
        $this->dom->addChild(
1315
            $this->enderDest,
1316
            "UF",
1317
            $std->UF,
1318
            true,
1319
            $identificador . "Sigla da UF do Endereço do Destinatário"
1320
        );
1321
        $this->dom->addChild(
1322
            $this->enderDest,
1323
            "CEP",
1324
            $std->CEP,
1325
            false,
1326
            $identificador . "Código do CEP do Endereço do Destinatário"
1327
        );
1328
        $this->dom->addChild(
1329
            $this->enderDest,
1330
            "cPais",
1331
            $std->cPais,
1332
            false,
1333
            $identificador . "Código do País do Endereço do Destinatário"
1334
        );
1335
        $this->dom->addChild(
1336
            $this->enderDest,
1337
            "xPais",
1338
            $std->xPais,
1339
            false,
1340
            $identificador . "Nome do País do Endereço do Destinatário"
1341
        );
1342
        $this->dom->addChild(
1343
            $this->enderDest,
1344
            "fone",
1345
            $std->fone,
1346
            false,
1347
            $identificador . "Telefone do Endereço do Destinatário"
1348
        );
1349
        $node = $this->dest->getElementsByTagName("indIEDest")->item(0);
1350
        if (!isset($node)) {
1351
            $node = $this->dest->getElementsByTagName("IE")->item(0);
1352
        }
1353
        $this->dest->insertBefore($this->enderDest, $node);
1354
        return $this->enderDest;
1355
    }
1356
1357
    /**
1358
     * Identificação do Local de retirada F01 pai A01
1359
     * tag NFe/infNFe/retirada (opcional)
1360
     * NOTA: ajustado para NT 2018.005
1361
     * @param stdClass $std
1362
     * @return DOMElement
1363
     */
1364
    public function tagretirada(stdClass $std)
1365
    {
1366
        $possible = [
1367
            'xLgr',
1368
            'nro',
1369
            'xCpl',
1370
            'xBairro',
1371
            'cMun',
1372
            'xMun',
1373
            'UF',
1374
            'CNPJ',
1375
            'CPF',
1376
            'xNome',
1377
            'CEP',
1378
            'cPais',
1379
            'xPais',
1380
            'fone',
1381
            'email',
1382
            'IE'
1383
        ];
1384
        $std = $this->equilizeParameters($std, $possible);
1385
        $identificador = 'F01 <retirada> - ';
1386
        $this->retirada = $this->dom->createElement("retirada");
1387
        $this->dom->addChild(
1388
            $this->retirada,
1389
            "CNPJ",
1390
            $std->CNPJ,
1391
            false,
1392
            $identificador . "CNPJ do Cliente da Retirada"
1393
        );
1394
        $this->dom->addChild(
1395
            $this->retirada,
1396
            "CPF",
1397
            $std->CPF,
1398
            false,
1399
            $identificador . "CPF do Cliente da Retirada"
1400
        );
1401
        $this->dom->addChild(
1402
            $this->retirada,
1403
            "xNome",
1404
            $std->xNome,
1405
            false,
1406
            $identificador . "Nome do Cliente da Retirada"
1407
        );
1408
        $this->dom->addChild(
1409
            $this->retirada,
1410
            "xLgr",
1411
            $std->xLgr,
1412
            true,
1413
            $identificador . "Logradouro do Endereco do Cliente da Retirada"
1414
        );
1415
        $this->dom->addChild(
1416
            $this->retirada,
1417
            "nro",
1418
            $std->nro,
1419
            true,
1420
            $identificador . "Número do Endereco do Cliente da Retirada"
1421
        );
1422
        $this->dom->addChild(
1423
            $this->retirada,
1424
            "xCpl",
1425
            $std->xCpl,
1426
            false,
1427
            $identificador . "Complemento do Endereco do Cliente da Retirada"
1428
        );
1429
        $this->dom->addChild(
1430
            $this->retirada,
1431
            "xBairro",
1432
            $std->xBairro,
1433
            true,
1434
            $identificador . "Bairro do Endereco do Cliente da Retirada"
1435
        );
1436
        $this->dom->addChild(
1437
            $this->retirada,
1438
            "cMun",
1439
            $std->cMun,
1440
            true,
1441
            $identificador . "Código do município do Endereco do Cliente da Retirada"
1442
        );
1443
        $this->dom->addChild(
1444
            $this->retirada,
1445
            "xMun",
1446
            $std->xMun,
1447
            true,
1448
            $identificador . "Nome do município do Endereco do Cliente da Retirada"
1449
        );
1450
        $this->dom->addChild(
1451
            $this->retirada,
1452
            "UF",
1453
            $std->UF,
1454
            true,
1455
            $identificador . "Sigla da UF do Endereco do Cliente da Retirada"
1456
        );
1457
        $this->dom->addChild(
1458
            $this->retirada,
1459
            "CEP",
1460
            $std->CEP,
1461
            false,
1462
            $identificador . "CEP do Endereco do Cliente da Retirada"
1463
        );
1464
        $this->dom->addChild(
1465
            $this->retirada,
1466
            "cPais",
1467
            $std->cPais,
1468
            false,
1469
            $identificador . "Codigo do Pais do Endereco do Cliente da Retirada"
1470
        );
1471
        $this->dom->addChild(
1472
            $this->retirada,
1473
            "xPais",
1474
            $std->xPais,
1475
            false,
1476
            $identificador . "Pais do Endereco do Cliente da Retirada"
1477
        );
1478
        $this->dom->addChild(
1479
            $this->retirada,
1480
            "fone",
1481
            $std->fone,
1482
            false,
1483
            $identificador . "Fone do Endereco do Cliente da Retirada"
1484
        );
1485
        $this->dom->addChild(
1486
            $this->retirada,
1487
            "email",
1488
            $std->email,
1489
            false,
1490
            $identificador . "Email do Endereco do Cliente da Retirada"
1491
        );
1492
        $this->dom->addChild(
1493
            $this->retirada,
1494
            "IE",
1495
            $std->IE,
1496
            false,
1497
            $identificador . "IE do Cliente da Retirada"
1498
        );
1499
        return $this->retirada;
1500
    }
1501
1502
    /**
1503
     * Identificação do Local de entrega G01 pai A01
1504
     * tag NFe/infNFe/entrega (opcional)
1505
     * NOTA: ajustado para NT 2018.005
1506
     * @param stdClass $std
1507
     * @return DOMElement
1508
     */
1509
    public function tagentrega(stdClass $std)
1510
    {
1511
        $possible = [
1512
            'xLgr',
1513
            'nro',
1514
            'xCpl',
1515
            'xBairro',
1516
            'cMun',
1517
            'xMun',
1518
            'UF',
1519
            'CNPJ',
1520
            'CPF',
1521
            'xNome',
1522
            'CEP',
1523
            'cPais',
1524
            'xPais',
1525
            'fone',
1526
            'email',
1527
            'IE'
1528
        ];
1529
        $std = $this->equilizeParameters($std, $possible);
1530
        $identificador = 'G01 <entrega> - ';
1531
        $this->entrega = $this->dom->createElement("entrega");
1532
        $this->dom->addChild(
1533
            $this->entrega,
1534
            "CNPJ",
1535
            $std->CNPJ,
1536
            false,
1537
            $identificador . "CNPJ do Cliente da Entrega"
1538
        );
1539
        $this->dom->addChild(
1540
            $this->entrega,
1541
            "CPF",
1542
            $std->CPF,
1543
            false,
1544
            $identificador . "CPF do Cliente da Entrega"
1545
        );
1546
        $this->dom->addChild(
1547
            $this->entrega,
1548
            "xNome",
1549
            $std->xNome,
1550
            false,
1551
            $identificador . "Nome do Cliente da Entrega"
1552
        );
1553
        $this->dom->addChild(
1554
            $this->entrega,
1555
            "xLgr",
1556
            $std->xLgr,
1557
            true,
1558
            $identificador . "Logradouro do Endereco do Cliente da Entrega"
1559
        );
1560
        $this->dom->addChild(
1561
            $this->entrega,
1562
            "nro",
1563
            $std->nro,
1564
            true,
1565
            $identificador . "Número do Endereco do Cliente da Entrega"
1566
        );
1567
        $this->dom->addChild(
1568
            $this->entrega,
1569
            "xCpl",
1570
            $std->xCpl,
1571
            false,
1572
            $identificador . "Complemento do Endereco do Cliente da Entrega"
1573
        );
1574
        $this->dom->addChild(
1575
            $this->entrega,
1576
            "xBairro",
1577
            $std->xBairro,
1578
            true,
1579
            $identificador . "Bairro do Endereco do Cliente da Entrega"
1580
        );
1581
        $this->dom->addChild(
1582
            $this->entrega,
1583
            "cMun",
1584
            $std->cMun,
1585
            true,
1586
            $identificador . "Código do município do Endereco do Cliente da Entrega"
1587
        );
1588
        $this->dom->addChild(
1589
            $this->entrega,
1590
            "xMun",
1591
            $std->xMun,
1592
            true,
1593
            $identificador . "Nome do município do Endereco do Cliente da Entrega"
1594
        );
1595
        $this->dom->addChild(
1596
            $this->entrega,
1597
            "UF",
1598
            $std->UF,
1599
            true,
1600
            $identificador . "Sigla da UF do Endereco do Cliente da Entrega"
1601
        );
1602
        $this->dom->addChild(
1603
            $this->entrega,
1604
            "CEP",
1605
            $std->CEP,
1606
            false,
1607
            $identificador . "CEP do Endereco do Cliente da Entrega"
1608
        );
1609
        $this->dom->addChild(
1610
            $this->entrega,
1611
            "cPais",
1612
            $std->cPais,
1613
            false,
1614
            $identificador . "Codigo do Pais do Endereco do Cliente da Entrega"
1615
        );
1616
        $this->dom->addChild(
1617
            $this->entrega,
1618
            "xPais",
1619
            $std->xPais,
1620
            false,
1621
            $identificador . "Pais do Endereco do Cliente da Entrega"
1622
        );
1623
        $this->dom->addChild(
1624
            $this->entrega,
1625
            "fone",
1626
            $std->fone,
1627
            false,
1628
            $identificador . "Fone do Endereco do Cliente da Entrega"
1629
        );
1630
        $this->dom->addChild(
1631
            $this->entrega,
1632
            "email",
1633
            $std->email,
1634
            false,
1635
            $identificador . "Email do Endereco do Cliente da Entrega"
1636
        );
1637
        $this->dom->addChild(
1638
            $this->entrega,
1639
            "IE",
1640
            $std->IE,
1641
            false,
1642
            $identificador . "IE do Cliente da Entrega"
1643
        );
1644
        return $this->entrega;
1645
    }
1646
1647
    /**
1648
     * Pessoas autorizadas para o download do XML da NF-e G50 pai A01
1649
     * tag NFe/infNFe/autXML
1650
     * @param stdClass $std
1651
     * @return DOMElement
1652
     */
1653
    public function tagautXML(stdClass $std)
1654
    {
1655
        $possible = ['CNPJ', 'CPF'];
1656
        $std = $this->equilizeParameters($std, $possible);
1657
        $identificador = 'G50 <autXML> - ';
1658
        $std->CNPJ = !empty($std->CNPJ) ? $std->CNPJ : null;
1659
        $std->CPF = !empty($std->CPF) ? $std->CPF : null;
1660
        $autXML = $this->dom->createElement("autXML");
1661
        $this->dom->addChild(
1662
            $autXML,
1663
            "CNPJ",
1664
            $std->CNPJ,
1665
            false,
1666
            $identificador . "CNPJ do Cliente Autorizado"
1667
        );
1668
        $this->dom->addChild(
1669
            $autXML,
1670
            "CPF",
1671
            $std->CPF,
1672
            false,
1673
            $identificador . "CPF do Cliente Autorizado"
1674
        );
1675
        $this->aAutXML[] = $autXML;
1676
        return $autXML;
1677
    }
1678
1679
    /**
1680
     * Informações adicionais do produto V01 pai H01
1681
     * tag NFe/infNFe/det[]/infAdProd
1682
     * @param stdClass $std
1683
     * @return DOMElement
1684
     */
1685
    public function taginfAdProd(stdClass $std)
1686
    {
1687
        $possible = ['item', 'infAdProd'];
1688
        $std = $this->equilizeParameters($std, $possible);
1689
        $infAdProd = $this->dom->createElement(
1690
            "infAdProd",
1691
            substr(trim($std->infAdProd), 0, 500)
1692
        );
1693
        $this->aInfAdProd[$std->item] = $infAdProd;
1694
        return $infAdProd;
1695
    }
1696
1697
    /**
1698
     * Detalhamento de Produtos e Serviços I01 pai H01
1699
     * tag NFe/infNFe/det[]/prod
1700
     * NOTA: Ajustado para NT2016_002_v1.30
1701
     * @param stdClass $std
1702
     * @return DOMElement
1703
     */
1704
    public function tagprod(stdClass $std)
1705
    {
1706
        $possible = [
1707
            'item',
1708
            'cProd',
1709
            'cEAN',
1710
            'xProd',
1711
            'NCM',
1712
            'cBenef',
1713
            'EXTIPI',
1714
            'CFOP',
1715
            'uCom',
1716
            'qCom',
1717
            'vUnCom',
1718
            'vProd',
1719
            'cEANTrib',
1720
            'uTrib',
1721
            'qTrib',
1722
            'vUnTrib',
1723
            'vFrete',
1724
            'vSeg',
1725
            'vDesc',
1726
            'vOutro',
1727
            'indTot',
1728
            'xPed',
1729
            'nItemPed',
1730
            'nFCI'
1731
        ];
1732
        $std = $this->equilizeParameters($std, $possible);
1733
        //totalizador
1734
        if ($std->indTot == 1) {
1735
            $this->stdTot->vProd += (float) $std->vProd;
1736
        }
1737
        $this->stdTot->vFrete += (float) $std->vFrete;
1738
        $this->stdTot->vSeg += (float) $std->vSeg;
1739
        $this->stdTot->vDesc += (float) $std->vDesc;
1740
        $this->stdTot->vOutro += (float) $std->vOutro;
1741
1742
        $cean = !empty($std->cEAN) ? trim(strtoupper($std->cEAN)) : '';
1743
        $ceantrib = !empty($std->cEANTrib) ? trim(strtoupper($std->cEANTrib)) : '';
1744
        //throw exception if not is Valid
1745
        try {
1746
            Gtin::isValid($cean);
1747
        } catch (\InvalidArgumentException $e) {
1748
            $this->errors[] = "cEANT {$cean} " . $e->getMessage();
1749
        }
1750
1751
        try {
1752
            Gtin::isValid($ceantrib);
1753
        } catch (\InvalidArgumentException $e) {
1754
            $this->errors[] = "cEANTrib {$ceantrib} " . $e->getMessage();
1755
        }
1756
1757
        $identificador = 'I01 <prod> - ';
1758
        $prod = $this->dom->createElement("prod");
1759
        $this->dom->addChild(
1760
            $prod,
1761
            "cProd",
1762
            $std->cProd,
1763
            true,
1764
            $identificador . "[item $std->item] Código do produto ou serviço"
1765
        );
1766
        $this->dom->addChild(
1767
            $prod,
1768
            "cEAN",
1769
            $cean,
1770
            true,
1771
            $identificador . "[item $std->item] GTIN (Global Trade Item Number) do produto, antigo "
1772
            . "código EAN ou código de barras",
1773
            true
1774
        );
1775
        $xProd = $std->xProd;
1776
        if ($this->tpAmb == '2' && $this->mod == '65' && $std->item === 1) {
1777
            $xProd = 'NOTA FISCAL EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
1778
        }
1779
        $this->dom->addChild(
1780
            $prod,
1781
            "xProd",
1782
            $xProd,
1783
            true,
1784
            $identificador . "[item $std->item] Descrição do produto ou serviço"
1785
        );
1786
        $this->dom->addChild(
1787
            $prod,
1788
            "NCM",
1789
            $std->NCM,
1790
            true,
1791
            $identificador . "[item $std->item] Código NCM com 8 dígitos ou 2 dígitos (gênero)"
1792
        );
1793
        //incluido no layout 4.00
1794
        $this->dom->addChild(
1795
            $prod,
1796
            "cBenef",
1797
            $std->cBenef,
1798
            false,
1799
            $identificador . "[item $std->item] Código de Benefício Fiscal utilizado pela UF"
1800
        );
1801
        $this->dom->addChild(
1802
            $prod,
1803
            "EXTIPI",
1804
            $std->EXTIPI,
1805
            false,
1806
            $identificador . "[item $std->item] Preencher de acordo com o código EX da TIPI"
1807
        );
1808
        $this->dom->addChild(
1809
            $prod,
1810
            "CFOP",
1811
            $std->CFOP,
1812
            true,
1813
            $identificador . "[item $std->item] Código Fiscal de Operações e Prestações"
1814
        );
1815
        $this->dom->addChild(
1816
            $prod,
1817
            "uCom",
1818
            $std->uCom,
1819
            true,
1820
            $identificador . "[item $std->item] Unidade Comercial do produto"
1821
        );
1822
        $this->dom->addChild(
1823
            $prod,
1824
            "qCom",
1825
            $this->conditionalNumberFormatting($std->qCom, 4),
1826
            true,
1827
            $identificador . "[item $std->item] Quantidade Comercial do produto"
1828
        );
1829
        $this->dom->addChild(
1830
            $prod,
1831
            "vUnCom",
1832
            $this->conditionalNumberFormatting($std->vUnCom, 10),
1833
            true,
1834
            $identificador . "[item $std->item] Valor Unitário de Comercialização do produto"
1835
        );
1836
        $this->dom->addChild(
1837
            $prod,
1838
            "vProd",
1839
            $this->conditionalNumberFormatting($std->vProd),
1840
            true,
1841
            $identificador . "[item $std->item] Valor Total Bruto dos Produtos ou Serviços"
1842
        );
1843
        $this->dom->addChild(
1844
            $prod,
1845
            "cEANTrib",
1846
            $ceantrib,
1847
            true,
1848
            $identificador . "[item $std->item] GTIN (Global Trade Item Number) da unidade tributável, antigo "
1849
            . "código EAN ou código de barras",
1850
            true
1851
        );
1852
        $this->dom->addChild(
1853
            $prod,
1854
            "uTrib",
1855
            $std->uTrib,
1856
            true,
1857
            $identificador . "[item $std->item] Unidade Tributável do produto"
1858
        );
1859
        $this->dom->addChild(
1860
            $prod,
1861
            "qTrib",
1862
            $this->conditionalNumberFormatting($std->qTrib, 4),
1863
            true,
1864
            $identificador . "[item $std->item] Quantidade Tributável do produto"
1865
        );
1866
        $this->dom->addChild(
1867
            $prod,
1868
            "vUnTrib",
1869
            $this->conditionalNumberFormatting($std->vUnTrib, 10),
1870
            true,
1871
            $identificador . "[item $std->item] Valor Unitário de tributação do produto"
1872
        );
1873
        $this->dom->addChild(
1874
            $prod,
1875
            "vFrete",
1876
            $this->conditionalNumberFormatting($std->vFrete),
1877
            false,
1878
            $identificador . "[item $std->item] Valor Total do Frete"
1879
        );
1880
        $this->dom->addChild(
1881
            $prod,
1882
            "vSeg",
1883
            $this->conditionalNumberFormatting($std->vSeg),
1884
            false,
1885
            $identificador . "[item $std->item] Valor Total do Seguro"
1886
        );
1887
        $this->dom->addChild(
1888
            $prod,
1889
            "vDesc",
1890
            $this->conditionalNumberFormatting($std->vDesc),
1891
            false,
1892
            $identificador . "[item $std->item] Valor do Desconto"
1893
        );
1894
        $this->dom->addChild(
1895
            $prod,
1896
            "vOutro",
1897
            $this->conditionalNumberFormatting($std->vOutro),
1898
            false,
1899
            $identificador . "[item $std->item] Outras despesas acessórias"
1900
        );
1901
        $this->dom->addChild(
1902
            $prod,
1903
            "indTot",
1904
            $std->indTot,
1905
            true,
1906
            $identificador . "[item $std->item] Indica se valor do Item (vProd) entra no valor total da NF-e (vProd)"
1907
        );
1908
        $this->dom->addChild(
1909
            $prod,
1910
            "xPed",
1911
            $std->xPed,
1912
            false,
1913
            $identificador . "[item $std->item] Número do Pedido de Compra"
1914
        );
1915
        $this->dom->addChild(
1916
            $prod,
1917
            "nItemPed",
1918
            $std->nItemPed,
1919
            false,
1920
            $identificador . "[item $std->item] Item do Pedido de Compra"
1921
        );
1922
        $this->dom->addChild(
1923
            $prod,
1924
            "nFCI",
1925
            $std->nFCI,
1926
            false,
1927
            $identificador . "[item $std->item] Número de controle da FCI "
1928
                . "Ficha de Conteúdo de Importação"
1929
        );
1930
        $this->aProd[$std->item] = $prod;
1931
        return $prod;
1932
    }
1933
1934
    /**
1935
     * NVE NOMENCLATURA DE VALOR ADUANEIRO E ESTATÍSTICA
1936
     * Podem ser até 8 NVE's por item
1937
     *
1938
     * @param stdClass $std
1939
     * @return DOMElement|null
1940
     */
1941
    public function tagNVE(stdClass $std)
1942
    {
1943
        $possible = ['item', 'NVE'];
1944
        $std = $this->equilizeParameters($std, $possible);
1945
1946
        if ($std->NVE == '') {
1947
            return null;
1948
        }
1949
        $nve = $this->dom->createElement("NVE", $std->NVE);
1950
        $this->aNVE[$std->item][] = $nve;
1951
        return $nve;
1952
    }
1953
1954
    /**
1955
     * Código Especificador da Substituição Tributária – CEST,
1956
     * que identifica a mercadoria sujeita aos regimes de substituição
1957
     * tributária e de antecipação do recolhimento do imposto.
1958
     * vide NT2015.003  I05C pai
1959
     * tag NFe/infNFe/det[item]/prod/CEST (opcional)
1960
     * NOTA: Ajustado para NT2016_002_v1.30
1961
     * @param  stdClass $std
1962
     * @return DOMElement
1963
     */
1964
    public function tagCEST(stdClass $std)
1965
    {
1966
        $possible = ['item', 'CEST', 'indEscala', 'CNPJFab'];
1967
        $std = $this->equilizeParameters($std, $possible);
1968
        $identificador = 'I05b <ctrltST> - ';
1969
        $ctrltST = $this->dom->createElement("ctrltST");
1970
        $this->dom->addChild(
1971
            $ctrltST,
1972
            "CEST",
1973
            Strings::onlyNumbers($std->CEST),
1974
            true,
1975
            "$identificador [item $std->item] Numero CEST"
1976
        );
1977
        //incluido no layout 4.00
1978
        $this->dom->addChild(
1979
            $ctrltST,
1980
            "indEscala",
1981
            trim($std->indEscala),
1982
            false,
1983
            "$identificador [item $std->item] Indicador de Produção em escala relevante"
1984
        );
1985
        //incluido no layout 4.00
1986
        $this->dom->addChild(
1987
            $ctrltST,
1988
            "CNPJFab",
1989
            Strings::onlyNumbers($std->CNPJFab),
1990
            false,
1991
            "$identificador [item $std->item] CNPJ do Fabricante da Mercadoria,"
1992
                . "obrigatório para produto em escala NÃO relevante."
1993
        );
1994
        $this->aCest[$std->item][] = $ctrltST;
1995
        return $ctrltST;
1996
    }
1997
1998
    /**
1999
     * tag NFe/infNFe/det[item]/prod/nRECOPI
2000
     * @param  stdClass $std
2001
     * @return DOMElement
2002
     */
2003
    public function tagRECOPI(stdClass $std)
2004
    {
2005
        $possible = ['item', 'nRECOPI'];
2006
        $std = $this->equilizeParameters($std, $possible);
2007
        $recopi = $this->dom->createElement("nRECOPI", $std->nRECOPI);
2008
        $this->aRECOPI[$std->item] = $recopi;
2009
        return $recopi;
2010
    }
2011
2012
    /**
2013
     * Declaração de Importação I8 pai I01
2014
     * tag NFe/infNFe/det[]/prod/DI
2015
     * @param stdClass $std
2016
     * @return DOMElement
2017
     */
2018
    public function tagDI(stdClass $std)
2019
    {
2020
        $possible = [
2021
            'item',
2022
            'nDI',
2023
            'dDI',
2024
            'xLocDesemb',
2025
            'UFDesemb',
2026
            'dDesemb',
2027
            'tpViaTransp',
2028
            'vAFRMM',
2029
            'tpIntermedio',
2030
            'CNPJ',
2031
            'UFTerceiro',
2032
            'cExportador'
2033
        ];
2034
        $std = $this->equilizeParameters($std, $possible);
2035
        $identificador = 'I8 <DI> - ';
2036
        $tDI = $this->dom->createElement("DI");
2037
        $this->dom->addChild(
2038
            $tDI,
2039
            "nDI",
2040
            $std->nDI,
2041
            true,
2042
            $identificador . "[item $std->item] Número do Documento de Importação (DI, DSI, DIRE, ...)"
2043
        );
2044
        $this->dom->addChild(
2045
            $tDI,
2046
            "dDI",
2047
            $std->dDI,
2048
            true,
2049
            $identificador . "[item $std->item] Data de Registro do documento"
2050
        );
2051
        $this->dom->addChild(
2052
            $tDI,
2053
            "xLocDesemb",
2054
            $std->xLocDesemb,
2055
            true,
2056
            $identificador . "[item $std->item] Local de desembaraço"
2057
        );
2058
        $this->dom->addChild(
2059
            $tDI,
2060
            "UFDesemb",
2061
            $std->UFDesemb,
2062
            true,
2063
            $identificador . "[item $std->item] Sigla da UF onde ocorreu o Desembaraço Aduaneiro"
2064
        );
2065
        $this->dom->addChild(
2066
            $tDI,
2067
            "dDesemb",
2068
            $std->dDesemb,
2069
            true,
2070
            $identificador . "[item $std->item] Data do Desembaraço Aduaneiro"
2071
        );
2072
        $this->dom->addChild(
2073
            $tDI,
2074
            "tpViaTransp",
2075
            $std->tpViaTransp,
2076
            true,
2077
            $identificador . "[item $std->item] Via de transporte internacional "
2078
                . "informada na Declaração de Importação (DI)"
2079
        );
2080
        $this->dom->addChild(
2081
            $tDI,
2082
            "vAFRMM",
2083
            $this->conditionalNumberFormatting($std->vAFRMM),
2084
            false,
2085
            $identificador . "[item $std->item] Valor da AFRMM "
2086
                . "- Adicional ao Frete para Renovação da Marinha Mercante"
2087
        );
2088
        $this->dom->addChild(
2089
            $tDI,
2090
            "tpIntermedio",
2091
            $std->tpIntermedio,
2092
            true,
2093
            $identificador . "[item $std->item] Forma de importação quanto a intermediação"
2094
        );
2095
        $this->dom->addChild(
2096
            $tDI,
2097
            "CNPJ",
2098
            $std->CNPJ,
2099
            false,
2100
            $identificador . "[item $std->item] CNPJ do adquirente ou do encomendante"
2101
        );
2102
        $this->dom->addChild(
2103
            $tDI,
2104
            "UFTerceiro",
2105
            $std->UFTerceiro,
2106
            false,
2107
            $identificador . "[item $std->item] Sigla da UF do adquirente ou do encomendante"
2108
        );
2109
        $this->dom->addChild(
2110
            $tDI,
2111
            "cExportador",
2112
            $std->cExportador,
2113
            true,
2114
            $identificador . "[item $std->item] Código do Exportador"
2115
        );
2116
        $this->aDI[$std->item][$std->nDI] = $tDI;
2117
        return $tDI;
2118
    }
2119
2120
    /**
2121
     * Adições I25 pai I18
2122
     * tag NFe/infNFe/det[]/prod/DI/adi
2123
     * @param stdClass $std
2124
     * @return DOMElement
2125
     */
2126
    public function tagadi(stdClass $std)
2127
    {
2128
        $possible = [
2129
            'item',
2130
            'nDI',
2131
            'nAdicao',
2132
            'nSeqAdic',
2133
            'cFabricante',
2134
            'vDescDI',
2135
            'nDraw'
2136
        ];
2137
        $std = $this->equilizeParameters($std, $possible);
2138
        $identificador = 'I25 <adi> - ';
2139
        $adi = $this->dom->createElement("adi");
2140
        $this->dom->addChild(
2141
            $adi,
2142
            "nAdicao",
2143
            $std->nAdicao,
2144
            true,
2145
            $identificador . "[item $std->item] Número da Adição"
2146
        );
2147
        $this->dom->addChild(
2148
            $adi,
2149
            "nSeqAdic",
2150
            $std->nSeqAdic,
2151
            true,
2152
            $identificador . "[item $std->item] Número sequencial do item dentro da Adição"
2153
        );
2154
        $this->dom->addChild(
2155
            $adi,
2156
            "cFabricante",
2157
            $std->cFabricante,
2158
            true,
2159
            $identificador . "[item $std->item] Código do fabricante estrangeiro"
2160
        );
2161
        $this->dom->addChild(
2162
            $adi,
2163
            "vDescDI",
2164
            $this->conditionalNumberFormatting($std->vDescDI),
2165
            false,
2166
            $identificador . "[item $std->item] Valor do desconto do item da DI Adição"
2167
        );
2168
        $this->dom->addChild(
2169
            $adi,
2170
            "nDraw",
2171
            $std->nDraw,
2172
            false,
2173
            $identificador . "[item $std->item] Número do ato concessório de Drawback"
2174
        );
2175
        $this->aAdi[$std->item][$std->nDI][] = $adi;
2176
        //colocar a adi em seu DI respectivo
2177
        $nodeDI = $this->aDI[$std->item][$std->nDI];
2178
        $this->dom->appChild($nodeDI, $adi);
2179
        $this->aDI[$std->item][$std->nDI] = $nodeDI;
2180
        return $adi;
2181
    }
2182
2183
    /**
2184
     * Grupo de informações de exportação para o item I50 pai I01
2185
     * tag NFe/infNFe/det[]/prod/detExport
2186
     * @param stdClass $std
2187
     * @return DOMElement
2188
     */
2189
    public function tagdetExport(stdClass $std)
2190
    {
2191
        $possible = [
2192
            'item',
2193
            'nDraw'
2194
        ];
2195
        $std = $this->equilizeParameters($std, $possible);
2196
        $identificador = 'I50 <detExport> - ';
2197
        $detExport = $this->dom->createElement("detExport");
2198
        $this->dom->addChild(
2199
            $detExport,
2200
            "nDraw",
2201
            Strings::onlyNumbers($std->nDraw),
2202
            false,
2203
            $identificador . "[item $std->item] Número do ato concessório de Drawback"
2204
        );
2205
        $this->aDetExport[$std->item][] = $detExport;
2206
        return $detExport;
2207
    }
2208
2209
    /**
2210
     * Grupo de informações de exportação para o item I52 pai I52
2211
     * tag NFe/infNFe/det[]/prod/detExport
2212
     * @param stdClass $std
2213
     * @return DOMElement
2214
     */
2215
    public function tagdetExportInd(stdClass $std)
2216
    {
2217
        $possible = [
2218
            'item',
2219
            'nRE',
2220
            'chNFe',
2221
            'qExport'
2222
        ];
2223
        $std = $this->equilizeParameters($std, $possible);
2224
        $identificador = 'I52 <exportInd> - ';
2225
        $exportInd = $this->dom->createElement("exportInd");
2226
        $this->dom->addChild(
2227
            $exportInd,
2228
            "nRE",
2229
            Strings::onlyNumbers($std->nRE),
2230
            true,
2231
            $identificador . "[item $std->item] Número do Registro de Exportação"
2232
        );
2233
        $this->dom->addChild(
2234
            $exportInd,
2235
            "chNFe",
2236
            Strings::onlyNumbers($std->chNFe),
2237
            true,
2238
            $identificador . "[item $std->item] Chave de Acesso da NF-e recebida para exportação"
2239
        );
2240
        $this->dom->addChild(
2241
            $exportInd,
2242
            "qExport",
2243
            $this->conditionalNumberFormatting($std->qExport, 4),
2244
            true,
2245
            $identificador . "[item $std->item] Quantidade do item realmente exportado"
2246
        );
2247
        //obtem o ultimo detExport
2248
        $nDE = count($this->aDetExport[$std->item]) - 1;
2249
        if ($nDE < 0) {
2250
            throw new RuntimeException('A TAG detExportInd deve ser criada depois da detExport, pois pertence a ela.');
2251
        }
2252
        //colocar a exportInd em seu DetExport respectivo
2253
        $nodeDetExport = $this->aDetExport[$std->item][$nDE];
2254
        $this->dom->appChild($nodeDetExport, $exportInd);
2255
        $this->aDetExport[$std->item][$nDE] = $nodeDetExport;
2256
        return $exportInd;
2257
    }
2258
2259
    /**
2260
     * Rastreabilidade do produto podem ser até 500 por item TAG I80 pai I01
2261
     * NOTA: Ajustado para NT2016_002_v1.00
2262
     * tag NFe/infNFe/det[]/prod/rastro
2263
     * @param stdClass $std
2264
     * @return DOMElement
2265
     */
2266
    public function tagRastro(stdClass $std)
2267
    {
2268
        $possible = [
2269
            'item',
2270
            'nLote',
2271
            'qLote',
2272
            'dFab',
2273
            'dVal',
2274
            'cAgreg'
2275
        ];
2276
        $std = $this->equilizeParameters($std, $possible);
2277
        $identificador = 'I80 <rastro> - ';
2278
        $rastro = $this->dom->createElement("rastro");
2279
        $this->dom->addChild(
2280
            $rastro,
2281
            "nLote",
2282
            substr(trim($std->nLote), 0, 20),
2283
            true,
2284
            $identificador . "[item $std->item] Número do lote"
2285
        );
2286
        $this->dom->addChild(
2287
            $rastro,
2288
            "qLote",
2289
            $this->conditionalNumberFormatting($std->qLote, 3),
2290
            true,
2291
            $identificador . "[item $std->item] Quantidade do lote"
2292
        );
2293
        $this->dom->addChild(
2294
            $rastro,
2295
            "dFab",
2296
            trim($std->dFab),
2297
            true,
2298
            $identificador . "[item $std->item] Data de fabricação"
2299
        );
2300
        $this->dom->addChild(
2301
            $rastro,
2302
            "dVal",
2303
            trim($std->dVal),
2304
            true,
2305
            $identificador . "[item $std->item] Data da validade"
2306
        );
2307
        $this->dom->addChild(
2308
            $rastro,
2309
            "cAgreg",
2310
            Strings::onlyNumbers($std->cAgreg),
2311
            false,
2312
            $identificador . "[item $std->item] Código de Agregação"
2313
        );
2314
        $this->aRastro[$std->item][] = $rastro;
2315
        return $rastro;
2316
    }
2317
2318
    /**
2319
     * Detalhamento de Veículos novos J01 pai I90
2320
     * tag NFe/infNFe/det[]/prod/veicProd (opcional)
2321
     * @param stdClass $std
2322
     * @return DOMElement
2323
     */
2324
    public function tagveicProd(stdClass $std)
2325
    {
2326
        $possible = [
2327
            'item',
2328
            'tpOp',
2329
            'chassi',
2330
            'cCor',
2331
            'xCor',
2332
            'pot',
2333
            'cilin',
2334
            'pesoL',
2335
            'pesoB',
2336
            'nSerie',
2337
            'tpComb',
2338
            'nMotor',
2339
            'CMT',
2340
            'dist',
2341
            'anoMod',
2342
            'anoFab',
2343
            'tpPint',
2344
            'tpVeic',
2345
            'espVeic',
2346
            'VIN',
2347
            'condVeic',
2348
            'cMod',
2349
            'cCorDENATRAN',
2350
            'lota',
2351
            'tpRest'
2352
        ];
2353
        $std = $this->equilizeParameters($std, $possible);
2354
        $identificador = 'J01 <veicProd> - ';
2355
        $veicProd = $this->dom->createElement("veicProd");
2356
        $this->dom->addChild(
2357
            $veicProd,
2358
            "tpOp",
2359
            $std->tpOp,
2360
            true,
2361
            "$identificador [item $std->item] Tipo da operação do veículo"
2362
        );
2363
        $this->dom->addChild(
2364
            $veicProd,
2365
            "chassi",
2366
            $std->chassi,
2367
            true,
2368
            "$identificador [item $std->item] Chassi do veículo"
2369
        );
2370
        $this->dom->addChild(
2371
            $veicProd,
2372
            "cCor",
2373
            $std->cCor,
2374
            true,
2375
            "$identificador [item $std->item] Cor do veículo"
2376
        );
2377
        $this->dom->addChild(
2378
            $veicProd,
2379
            "xCor",
2380
            $std->xCor,
2381
            true,
2382
            "$identificador [item $std->item] Descrição da Cor do veículo"
2383
        );
2384
        $this->dom->addChild(
2385
            $veicProd,
2386
            "pot",
2387
            $std->pot,
2388
            true,
2389
            "$identificador [item $std->item] Potência Motor (CV) do veículo"
2390
        );
2391
        $this->dom->addChild(
2392
            $veicProd,
2393
            "cilin",
2394
            $std->cilin,
2395
            true,
2396
            "$identificador [item $std->item] Cilindradas do veículo"
2397
        );
2398
        $this->dom->addChild(
2399
            $veicProd,
2400
            "pesoL",
2401
            $this->conditionalNumberFormatting($std->pesoL, 3),
2402
            true,
2403
            "$identificador [item $std->item] Peso Líquido do veículo"
2404
        );
2405
        $this->dom->addChild(
2406
            $veicProd,
2407
            "pesoB",
2408
            $this->conditionalNumberFormatting($std->pesoB, 3),
2409
            true,
2410
            "$identificador [item $std->item] Peso Bruto do veículo"
2411
        );
2412
        $this->dom->addChild(
2413
            $veicProd,
2414
            "nSerie",
2415
            $std->nSerie,
2416
            true,
2417
            "$identificador [item $std->item] Serial (série) do veículo"
2418
        );
2419
        $this->dom->addChild(
2420
            $veicProd,
2421
            "tpComb",
2422
            $std->tpComb,
2423
            true,
2424
            "$identificador [item $std->item] Tipo de combustível do veículo"
2425
        );
2426
        $this->dom->addChild(
2427
            $veicProd,
2428
            "nMotor",
2429
            $std->nMotor,
2430
            true,
2431
            "$identificador [item $std->item] Número de Motor do veículo"
2432
        );
2433
        $this->dom->addChild(
2434
            $veicProd,
2435
            "CMT",
2436
            $this->conditionalNumberFormatting($std->CMT, 4),
2437
            true,
2438
            "$identificador [item $std->item] Capacidade Máxima de Tração do veículo"
2439
        );
2440
        $this->dom->addChild(
2441
            $veicProd,
2442
            "dist",
2443
            $std->dist,
2444
            true,
2445
            "$identificador [item $std->item] Distância entre eixos do veículo"
2446
        );
2447
        $this->dom->addChild(
2448
            $veicProd,
2449
            "anoMod",
2450
            $std->anoMod,
2451
            true,
2452
            "$identificador [item $std->item] Ano Modelo de Fabricação do veículo"
2453
        );
2454
        $this->dom->addChild(
2455
            $veicProd,
2456
            "anoFab",
2457
            $std->anoFab,
2458
            true,
2459
            "$identificador [item $std->item] Ano de Fabricação do veículo"
2460
        );
2461
        $this->dom->addChild(
2462
            $veicProd,
2463
            "tpPint",
2464
            $std->tpPint,
2465
            true,
2466
            "$identificador [item $std->item] Tipo de Pintura do veículo"
2467
        );
2468
        $this->dom->addChild(
2469
            $veicProd,
2470
            "tpVeic",
2471
            $std->tpVeic,
2472
            true,
2473
            "$identificador [item $std->item] Tipo de Veículo"
2474
        );
2475
        $this->dom->addChild(
2476
            $veicProd,
2477
            "espVeic",
2478
            $std->espVeic,
2479
            true,
2480
            "$identificador [item $std->item] Espécie de Veículo"
2481
        );
2482
        $this->dom->addChild(
2483
            $veicProd,
2484
            "VIN",
2485
            $std->VIN,
2486
            true,
2487
            "$identificador [item $std->item] Condição do VIN do veículo"
2488
        );
2489
        $this->dom->addChild(
2490
            $veicProd,
2491
            "condVeic",
2492
            $std->condVeic,
2493
            true,
2494
            "$identificador [item $std->item] Condição do Veículo"
2495
        );
2496
        $this->dom->addChild(
2497
            $veicProd,
2498
            "cMod",
2499
            $std->cMod,
2500
            true,
2501
            "$identificador [item $std->item] Código Marca Modelo do veículo"
2502
        );
2503
        $this->dom->addChild(
2504
            $veicProd,
2505
            "cCorDENATRAN",
2506
            $std->cCorDENATRAN,
2507
            true,
2508
            "$identificador [item $std->item] Código da Cor do veículo"
2509
        );
2510
        $this->dom->addChild(
2511
            $veicProd,
2512
            "lota",
2513
            $std->lota,
2514
            true,
2515
            "$identificador [item $std->item] Capacidade máxima de lotação do veículo"
2516
        );
2517
        $this->dom->addChild(
2518
            $veicProd,
2519
            "tpRest",
2520
            $std->tpRest,
2521
            true,
2522
            "$identificador [item $std->item] Restrição do veículo"
2523
        );
2524
        $this->aVeicProd[$std->item] = $veicProd;
2525
        return $veicProd;
2526
    }
2527
2528
    /**
2529
     * Detalhamento de medicamentos K01 pai I90
2530
     * NOTA: Ajustado para NT2018.005
2531
     * tag NFe/infNFe/det[]/prod/med (opcional)
2532
     * @param stdClass $std
2533
     * @return DOMElement
2534
     */
2535
    public function tagmed(stdClass $std)
2536
    {
2537
        $possible = [
2538
            'item',
2539
            'vPMC',
2540
            'cProdANVISA',
2541
            'xMotivoIsencao'
2542
        ];
2543
        $std = $this->equilizeParameters($std, $possible);
2544
        $identificador = 'K01 <med> - ';
2545
        $med = $this->dom->createElement("med");
2546
        $this->dom->addChild(
2547
            $med,
2548
            "cProdANVISA",
2549
            $std->cProdANVISA,
2550
            false,
2551
            "$identificador [item $std->item] Numero ANVISA"
2552
        );
2553
        $this->dom->addChild(
2554
            $med,
2555
            "xMotivoIsencao",
2556
            $std->xMotivoIsencao,
2557
            false,
2558
            "$identificador [item $std->item] Motivo da isenção da ANVISA"
2559
        );
2560
        $this->dom->addChild(
2561
            $med,
2562
            "vPMC",
2563
            $this->conditionalNumberFormatting($std->vPMC),
2564
            true,
2565
            "$identificador [item $std->item] Preço máximo consumidor"
2566
        );
2567
        $this->aMed[$std->item] = $med;
2568
        return $med;
2569
    }
2570
2571
    /**
2572
     * Detalhamento de armas L01 pai I90
2573
     * tag NFe/infNFe/det[]/prod/arma (opcional)
2574
     * @param stdClass $std
2575
     * @return DOMElement
2576
     */
2577
    public function tagarma(stdClass $std)
2578
    {
2579
        $possible = [
2580
            'item',
2581
            'nAR',
2582
            'tpArma',
2583
            'nSerie',
2584
            'nCano',
2585
            'descr'
2586
        ];
2587
        $std = $this->equilizeParameters($std, $possible);
2588
        $identificador = 'L01 <arma> - ';
2589
        $arma = $this->dom->createElement("arma");
2590
        $this->dom->addChild(
2591
            $arma,
2592
            "tpArma",
2593
            $std->tpArma,
2594
            true,
2595
            "$identificador [item $std->item] Indicador do tipo de arma de fogo"
2596
        );
2597
        $this->dom->addChild(
2598
            $arma,
2599
            "nSerie",
2600
            $std->nSerie,
2601
            true,
2602
            "$identificador [item $std->item] Número de série da arma"
2603
        );
2604
        $this->dom->addChild(
2605
            $arma,
2606
            "nCano",
2607
            $std->nCano,
2608
            true,
2609
            "$identificador [item $std->item] Número de série do cano"
2610
        );
2611
        $this->dom->addChild(
2612
            $arma,
2613
            "descr",
2614
            $std->descr,
2615
            true,
2616
            "$identificador [item $std->item] Descrição completa da arma, compreendendo: calibre, marca, capacidade, "
2617
                . "tipo de funcionamento, comprimento e demais elementos que "
2618
                . "permitam a sua perfeita identificação."
2619
        );
2620
        $this->aArma[$std->item][$std->nAR] = $arma;
2621
        return $arma;
2622
    }
2623
2624
    /**
2625
     * Detalhamento de combustiveis L101 pai I90
2626
     * tag NFe/infNFe/det[]/prod/comb (opcional)
2627
     * LA|cProdANP|pMixGN|CODIF|qTemp|UFCons|
2628
     *
2629
     * NOTA: Ajustado para NT2016_002_v1.30
2630
     * LA|cProdANP|descANP|pGLP|pGNn|pGNi|vPart|CODIF|qTemp|UFCons|
2631
     * @param stdClass $std
2632
     * @return DOMElement
2633
     */
2634
    public function tagcomb(stdClass $std)
2635
    {
2636
        $possible = [
2637
            'item',
2638
            'cProdANP',
2639
            'descANP',
2640
            'pGLP',
2641
            'pGNn',
2642
            'pGNi',
2643
            'vPart',
2644
            'CODIF',
2645
            'qTemp',
2646
            'UFCons',
2647
            'qBCProd',
2648
            'vAliqProd',
2649
            'vCIDE'
2650
        ];
2651
        $std = $this->equilizeParameters($std, $possible);
2652
2653
        $identificador = 'L101 <comb> - ';
2654
        $comb = $this->dom->createElement("comb");
2655
        $this->dom->addChild(
2656
            $comb,
2657
            "cProdANP",
2658
            $std->cProdANP,
2659
            true,
2660
            "$identificador [item $std->item] Código de produto da ANP"
2661
        );
2662
        //incluso no layout 4.00
2663
        $this->dom->addChild(
2664
            $comb,
2665
            "descANP",
2666
            $std->descANP,
2667
            false,
2668
            "$identificador [item $std->item] Utilizar a descrição de produtos do "
2669
                . "Sistema de Informações de Movimentação de Produtos - "
2670
                . "SIMP (http://www.anp.gov.br/simp/"
2671
        );
2672
        //incluso no layout 4.00
2673
        $this->dom->addChild(
2674
            $comb,
2675
            "pGLP",
2676
            $this->conditionalNumberFormatting($std->pGLP, 4),
2677
            false,
2678
            "$identificador [item $std->item] Percentual do GLP derivado do "
2679
                . "petróleo no produto GLP (cProdANP=210203001) 1v4"
2680
        );
2681
        //incluso no layout 4.00
2682
        $this->dom->addChild(
2683
            $comb,
2684
            "pGNn",
2685
            $this->conditionalNumberFormatting($std->pGNn, 4),
2686
            false,
2687
            "$identificador [item $std->item] Percentual de Gás Natural Nacional"
2688
                . " – GLGNn para o produto GLP (cProdANP=210203001) 1v4"
2689
        );
2690
        //incluso no layout 4.00
2691
        $this->dom->addChild(
2692
            $comb,
2693
            "pGNi",
2694
            $this->conditionalNumberFormatting($std->pGNi, 4),
2695
            false,
2696
            "$identificador [item $std->item] Percentual de Gás Natural Importado"
2697
                . " – GLGNi para o produto GLP (cProdANP=210203001) 1v4"
2698
        );
2699
        //incluso no layout 4.00
2700
        $this->dom->addChild(
2701
            $comb,
2702
            "vPart",
2703
            $this->conditionalNumberFormatting($std->vPart),
2704
            false,
2705
            "$identificador [item $std->item] Valor de partida (cProdANP=210203001) "
2706
        );
2707
        $this->dom->addChild(
2708
            $comb,
2709
            "CODIF",
2710
            $std->CODIF,
2711
            false,
2712
            "[item $std->item] Código de autorização / registro do CODIF"
2713
        );
2714
        $this->dom->addChild(
2715
            $comb,
2716
            "qTemp",
2717
            $this->conditionalNumberFormatting($std->qTemp, 4),
2718
            false,
2719
            "$identificador [item $std->item] Quantidade de combustível faturada à temperatura ambiente."
2720
        );
2721
        $this->dom->addChild(
2722
            $comb,
2723
            "UFCons",
2724
            $std->UFCons,
2725
            true,
2726
            "[item $std->item] Sigla da UF de consumo"
2727
        );
2728
        if ($std->qBCProd != "") {
2729
            $tagCIDE = $this->dom->createElement("CIDE");
2730
            $this->dom->addChild(
2731
                $tagCIDE,
2732
                "qBCProd",
2733
                $this->conditionalNumberFormatting($std->qBCProd, 4),
2734
                true,
2735
                "$identificador [item $std->item] BC da CIDE"
2736
            );
2737
            $this->dom->addChild(
2738
                $tagCIDE,
2739
                "vAliqProd",
2740
                $this->conditionalNumberFormatting($std->vAliqProd, 4),
2741
                true,
2742
                "$identificador [item $std->item] Valor da alíquota da CIDE"
2743
            );
2744
            $this->dom->addChild(
2745
                $tagCIDE,
2746
                "vCIDE",
2747
                $this->conditionalNumberFormatting($std->vCIDE),
2748
                true,
2749
                "$identificador [item $std->item] Valor da CIDE"
2750
            );
2751
            $this->dom->appChild($comb, $tagCIDE);
2752
        }
2753
        $this->aComb[$std->item] = $comb;
2754
        return $comb;
2755
    }
2756
2757
    /**
2758
     * informações relacionadas com as operações de combustíveis, subgrupo de
2759
     * encerrante que permite o controle sobre as operações de venda de combustíveis
2760
     * LA11 pai LA01
2761
     * tag NFe/infNFe/det[]/prod/comb/encerrante (opcional)
2762
     * @param stdClass $std
2763
     * @return DOMElement
2764
     */
2765
    public function tagencerrante(stdClass $std)
2766
    {
2767
        $possible = [
2768
            'item',
2769
            'nBico',
2770
            'nBomba',
2771
            'nTanque',
2772
            'vEncIni',
2773
            'vEncFin'
2774
        ];
2775
        $std = $this->equilizeParameters($std, $possible);
2776
        $identificador = 'LA11 <encerrante> - ';
2777
        $encerrante = $this->dom->createElement("encerrante");
2778
        $this->dom->addChild(
2779
            $encerrante,
2780
            "nBico",
2781
            $std->nBico,
2782
            true,
2783
            "$identificador [item $std->item] Número de identificação do bico utilizado no abastecimento"
2784
        );
2785
        $this->dom->addChild(
2786
            $encerrante,
2787
            "nBomba",
2788
            $std->nBomba,
2789
            false,
2790
            "$identificador [item $std->item] Número de identificação da bomba ao qual o bico está interligado"
2791
        );
2792
        $this->dom->addChild(
2793
            $encerrante,
2794
            "nTanque",
2795
            $std->nTanque,
2796
            true,
2797
            "$identificador [item $std->item] Número de identificação do tanque ao qual o bico está interligado"
2798
        );
2799
        $this->dom->addChild(
2800
            $encerrante,
2801
            "vEncIni",
2802
            $this->conditionalNumberFormatting($std->vEncIni),
2803
            true,
2804
            "$identificador [item $std->item] Valor do Encerrante no início do abastecimento"
2805
        );
2806
        $this->dom->addChild(
2807
            $encerrante,
2808
            "vEncFin",
2809
            $this->conditionalNumberFormatting($std->vEncFin),
2810
            true,
2811
            "$identificador [item $std->item] Valor do Encerrante no final do abastecimento"
2812
        );
2813
        $this->aEncerrante[$std->item] = $encerrante;
2814
        return $encerrante;
2815
    }
2816
2817
    /**
2818
     * Impostos com o valor total tributado M01 pai H01
2819
     * tag NFe/infNFe/det[]/imposto
2820
     * @param stdClass $std
2821
     * @return DOMElement
2822
     */
2823
    public function tagimposto(stdClass $std)
2824
    {
2825
        $possible = ['item', 'vTotTrib'];
2826
        $std = $this->equilizeParameters($std, $possible);
2827
        //totalizador dos valores dos itens
2828
        $this->stdTot->vTotTrib += (float) $std->vTotTrib;
2829
        $identificador = 'M01 <imposto> - ';
2830
        $imposto = $this->dom->createElement("imposto");
2831
        $this->dom->addChild(
2832
            $imposto,
2833
            "vTotTrib",
2834
            $this->conditionalNumberFormatting($std->vTotTrib),
2835
            false,
2836
            "$identificador [item $std->item] Valor aproximado total de tributos federais, estaduais e municipais."
2837
        );
2838
        $this->aImposto[$std->item] = $imposto;
2839
        return $imposto;
2840
    }
2841
2842
    /**
2843
     * Informações do ICMS da Operação própria e ST N01 pai M01
2844
     * tag NFe/infNFe/det[]/imposto/ICMS
2845
     * @param stdClass $std
2846
     * @return DOMElement
2847
     */
2848
    public function tagICMS(stdClass $std)
2849
    {
2850
        $possible = [
2851
            'item',
2852
            'orig',
2853
            'CST',
2854
            'modBC',
2855
            'vBC',
2856
            'pICMS',
2857
            'vICMS',
2858
            'pFCP',
2859
            'vFCP',
2860
            'vBCFCP',
2861
            'modBCST',
2862
            'pMVAST',
2863
            'pRedBCST',
2864
            'vBCST',
2865
            'pICMSST',
2866
            'vICMSST',
2867
            'vBCFCPST',
2868
            'pFCPST',
2869
            'vFCPST',
2870
            'vICMSDeson',
2871
            'motDesICMS',
2872
            'pRedBC',
2873
            'vICMSOp',
2874
            'pDif',
2875
            'vICMSDif',
2876
            'vBCSTRet',
2877
            'pST',
2878
            'vICMSSTRet',
2879
            'vBCFCPSTRet',
2880
            'pFCPSTRet',
2881
            'vFCPSTRet',
2882
            'pRedBCEfet',
2883
            'vBCEfet',
2884
            'pICMSEfet',
2885
            'vICMSEfet',
2886
            'vICMSSubstituto'
2887
        ];
2888
        $std = $this->equilizeParameters($std, $possible);
2889
        //totalização generica
2890
        $this->stdTot->vICMSDeson += (float) !empty($std->vICMSDeson) ? $std->vICMSDeson : 0;
2891
        $this->stdTot->vFCP += (float) !empty($std->vFCP) ? $std->vFCP : 0;
2892
        $this->stdTot->vFCPST += (float) !empty($std->vFCPST) ? $std->vFCPST : 0;
2893
        $this->stdTot->vFCPSTRet += (float) !empty($std->vFCPSTRet) ? $std->vFCPSTRet : 0;
2894
        $identificador = 'N01 <ICMSxx> - ';
2895
        switch ($std->CST) {
2896
            case '00':
2897
                $this->stdTot->vBC += (float) !empty($std->vBC) ? $std->vBC : 0;
2898
                $this->stdTot->vICMS += (float) !empty($std->vICMS) ? $std->vICMS : 0;
2899
2900
                $icms = $this->dom->createElement("ICMS00");
2901
                $this->dom->addChild(
2902
                    $icms,
2903
                    'orig',
2904
                    $std->orig,
2905
                    true,
2906
                    "$identificador [item $std->item] Origem da mercadoria"
2907
                );
2908
                $this->dom->addChild(
2909
                    $icms,
2910
                    'CST',
2911
                    $std->CST,
2912
                    true,
2913
                    "$identificador [item $std->item] Tributação do ICMS = 00"
2914
                );
2915
                $this->dom->addChild(
2916
                    $icms,
2917
                    'modBC',
2918
                    $std->modBC,
2919
                    true,
2920
                    "$identificador [item $std->item] Modalidade de determinação da BC do ICMS"
2921
                );
2922
                $this->dom->addChild(
2923
                    $icms,
2924
                    'vBC',
2925
                    $this->conditionalNumberFormatting($std->vBC),
2926
                    true,
2927
                    "$identificador [item $std->item] Valor da BC do ICMS"
2928
                );
2929
                $this->dom->addChild(
2930
                    $icms,
2931
                    'pICMS',
2932
                    $this->conditionalNumberFormatting($std->pICMS, 4),
2933
                    true,
2934
                    "$identificador [item $std->item] Alíquota do imposto"
2935
                );
2936
                $this->dom->addChild(
2937
                    $icms,
2938
                    'vICMS',
2939
                    $this->conditionalNumberFormatting($std->vICMS),
2940
                    true,
2941
                    "$identificador [item $std->item] Valor do ICMS"
2942
                );
2943
                $this->dom->addChild(
2944
                    $icms,
2945
                    'pFCP',
2946
                    $this->conditionalNumberFormatting($std->pFCP, 4),
2947
                    false,
2948
                    "$identificador [item $std->item] Percentual do Fundo de "
2949
                    . "Combate à Pobreza (FCP)"
2950
                );
2951
                $this->dom->addChild(
2952
                    $icms,
2953
                    'vFCP',
2954
                    $this->conditionalNumberFormatting($std->vFCP),
2955
                    false,
2956
                    "$identificador [item $std->item] Valor do Fundo de Combate "
2957
                    . "à Pobreza (FCP)"
2958
                );
2959
                break;
2960
            case '10':
2961
                $this->stdTot->vBC += (float) !empty($std->vBC) ? $std->vBC : 0;
2962
                $this->stdTot->vICMS += (float) !empty($std->vICMS) ? $std->vICMS : 0;
2963
                $this->stdTot->vBCST += (float) !empty($std->vBCST) ? $std->vBCST : 0;
2964
                $this->stdTot->vST += (float) !empty($std->vICMSST) ? $std->vICMSST : 0;
2965
2966
                $icms = $this->dom->createElement("ICMS10");
2967
                $this->dom->addChild(
2968
                    $icms,
2969
                    'orig',
2970
                    $std->orig,
2971
                    true,
2972
                    "$identificador [item $std->item] Origem da mercadoria"
2973
                );
2974
                $this->dom->addChild(
2975
                    $icms,
2976
                    'CST',
2977
                    $std->CST,
2978
                    true,
2979
                    "$identificador [item $std->item] Tributação do ICMS = 10"
2980
                );
2981
                $this->dom->addChild(
2982
                    $icms,
2983
                    'modBC',
2984
                    $std->modBC,
2985
                    true,
2986
                    "$identificador [item $std->item] Modalidade de determinação da BC do ICMS"
2987
                );
2988
                $this->dom->addChild(
2989
                    $icms,
2990
                    'vBC',
2991
                    $this->conditionalNumberFormatting($std->vBC),
2992
                    true,
2993
                    "$identificador [item $std->item] Valor da BC do ICMS"
2994
                );
2995
                $this->dom->addChild(
2996
                    $icms,
2997
                    'pICMS',
2998
                    $this->conditionalNumberFormatting($std->pICMS, 4),
2999
                    true,
3000
                    "$identificador [item $std->item] Alíquota do imposto"
3001
                );
3002
                $this->dom->addChild(
3003
                    $icms,
3004
                    'vICMS',
3005
                    $this->conditionalNumberFormatting($std->vICMS),
3006
                    true,
3007
                    "$identificador [item $std->item] Valor do ICMS"
3008
                );
3009
                $this->dom->addChild(
3010
                    $icms,
3011
                    'vBCFCP',
3012
                    $this->conditionalNumberFormatting($std->vBCFCP),
3013
                    false,
3014
                    "$identificador [item $std->item] Valor da Base de Cálculo do FCP"
3015
                );
3016
                $this->dom->addChild(
3017
                    $icms,
3018
                    'pFCP',
3019
                    $this->conditionalNumberFormatting($std->pFCP, 4),
3020
                    false,
3021
                    "$identificador [item $std->item] Percentual do Fundo de "
3022
                    . "Combate à Pobreza (FCP)"
3023
                );
3024
                $this->dom->addChild(
3025
                    $icms,
3026
                    'vFCP',
3027
                    $this->conditionalNumberFormatting($std->vFCP),
3028
                    false,
3029
                    "$identificador [item $std->item] Valor do FCP"
3030
                );
3031
                $this->dom->addChild(
3032
                    $icms,
3033
                    'modBCST',
3034
                    $std->modBCST,
3035
                    true,
3036
                    "$identificador [item $std->item] Modalidade de determinação da BC do ICMS ST"
3037
                );
3038
                $this->dom->addChild(
3039
                    $icms,
3040
                    'pMVAST',
3041
                    $this->conditionalNumberFormatting($std->pMVAST, 4),
3042
                    false,
3043
                    "$identificador [item $std->item] Percentual da margem de valor Adicionado do ICMS ST"
3044
                );
3045
                $this->dom->addChild(
3046
                    $icms,
3047
                    'pRedBCST',
3048
                    $this->conditionalNumberFormatting($std->pRedBCST, 4),
3049
                    false,
3050
                    "$identificador [item $std->item] Percentual da Redução de BC do ICMS ST"
3051
                );
3052
                $this->dom->addChild(
3053
                    $icms,
3054
                    'vBCST',
3055
                    $this->conditionalNumberFormatting($std->vBCST),
3056
                    true,
3057
                    "$identificador [item $std->item] Valor da BC do ICMS ST"
3058
                );
3059
                $this->dom->addChild(
3060
                    $icms,
3061
                    'pICMSST',
3062
                    $this->conditionalNumberFormatting($std->pICMSST, 4),
3063
                    true,
3064
                    "$identificador [item $std->item] Alíquota do imposto do ICMS ST"
3065
                );
3066
                $this->dom->addChild(
3067
                    $icms,
3068
                    'vICMSST',
3069
                    $this->conditionalNumberFormatting($std->vICMSST),
3070
                    true,
3071
                    "$identificador [item $std->item] Valor do ICMS ST"
3072
                );
3073
                $this->dom->addChild(
3074
                    $icms,
3075
                    'vBCFCPST',
3076
                    $this->conditionalNumberFormatting($std->vBCFCPST),
3077
                    false,
3078
                    "$identificador [item $std->item] Valor da Base de Cálculo do FCP ST"
3079
                );
3080
                $this->dom->addChild(
3081
                    $icms,
3082
                    'pFCPST',
3083
                    $this->conditionalNumberFormatting($std->pFCPST, 4),
3084
                    false,
3085
                    "$identificador [item $std->item] Percentual do Fundo de "
3086
                    . "Combate à Pobreza (FCP) ST"
3087
                );
3088
                $this->dom->addChild(
3089
                    $icms,
3090
                    'vFCPST',
3091
                    $this->conditionalNumberFormatting($std->vFCPST),
3092
                    false,
3093
                    "$identificador [item $std->item] Valor do FCP ST"
3094
                );
3095
                break;
3096
            case '20':
3097
                $this->stdTot->vBC += (float) !empty($std->vBC) ? $std->vBC : 0;
3098
                $this->stdTot->vICMS += (float) !empty($std->vICMS) ? $std->vICMS : 0;
3099
3100
                $icms = $this->dom->createElement("ICMS20");
3101
                $this->dom->addChild(
3102
                    $icms,
3103
                    'orig',
3104
                    $std->orig,
3105
                    true,
3106
                    "$identificador [item $std->item] Origem da mercadoria"
3107
                );
3108
                $this->dom->addChild(
3109
                    $icms,
3110
                    'CST',
3111
                    $std->CST,
3112
                    true,
3113
                    "$identificador [item $std->item] Tributação do ICMS = 20"
3114
                );
3115
                $this->dom->addChild(
3116
                    $icms,
3117
                    'modBC',
3118
                    $std->modBC,
3119
                    true,
3120
                    "$identificador [item $std->item] Modalidade de determinação da BC do ICMS"
3121
                );
3122
                $this->dom->addChild(
3123
                    $icms,
3124
                    'pRedBC',
3125
                    $this->conditionalNumberFormatting($std->pRedBC, 4),
3126
                    true,
3127
                    "$identificador [item $std->item] Percentual da Redução de BC"
3128
                );
3129
                $this->dom->addChild(
3130
                    $icms,
3131
                    'vBC',
3132
                    $this->conditionalNumberFormatting($std->vBC),
3133
                    true,
3134
                    "$identificador [item $std->item] Valor da BC do ICMS"
3135
                );
3136
                $this->dom->addChild(
3137
                    $icms,
3138
                    'pICMS',
3139
                    $this->conditionalNumberFormatting($std->pICMS, 4),
3140
                    true,
3141
                    "$identificador [item $std->item] Alíquota do imposto"
3142
                );
3143
                $this->dom->addChild(
3144
                    $icms,
3145
                    'vICMS',
3146
                    $this->conditionalNumberFormatting($std->vICMS),
3147
                    true,
3148
                    "$identificador [item $std->item] Valor do ICMS"
3149
                );
3150
                $this->dom->addChild(
3151
                    $icms,
3152
                    'vBCFCP',
3153
                    $this->conditionalNumberFormatting($std->vBCFCP),
3154
                    false,
3155
                    "$identificador [item $std->item] Valor da Base de Cálculo do FCP"
3156
                );
3157
                $this->dom->addChild(
3158
                    $icms,
3159
                    'pFCP',
3160
                    $this->conditionalNumberFormatting($std->pFCP, 4),
3161
                    false,
3162
                    "$identificador [item $std->item] Percentual do Fundo de "
3163
                    . "Combate à Pobreza (FCP)"
3164
                );
3165
                $this->dom->addChild(
3166
                    $icms,
3167
                    'vFCP',
3168
                    $this->conditionalNumberFormatting($std->vFCP),
3169
                    false,
3170
                    "$identificador [item $std->item] Valor do FCP"
3171
                );
3172
                $this->dom->addChild(
3173
                    $icms,
3174
                    'vICMSDeson',
3175
                    $this->conditionalNumberFormatting($std->vICMSDeson),
3176
                    false,
3177
                    "$identificador [item $std->item] Valor do ICMS desonerado"
3178
                );
3179
                $this->dom->addChild(
3180
                    $icms,
3181
                    'motDesICMS',
3182
                    $std->motDesICMS,
3183
                    false,
3184
                    "$identificador [item $std->item] Motivo da desoneração do ICMS"
3185
                );
3186
                break;
3187
            case '30':
3188
                $this->stdTot->vBCST += (float) !empty($std->vBCST) ? $std->vBCST : 0;
3189
                $this->stdTot->vST += (float) !empty($std->vICMSST) ? $std->vICMSST : 0;
3190
3191
                $icms = $this->dom->createElement("ICMS30");
3192
                $this->dom->addChild(
3193
                    $icms,
3194
                    'orig',
3195
                    $std->orig,
3196
                    true,
3197
                    "$identificador [item $std->item] Origem da mercadoria"
3198
                );
3199
                $this->dom->addChild(
3200
                    $icms,
3201
                    'CST',
3202
                    $std->CST,
3203
                    true,
3204
                    "$identificador [item $std->item] Tributação do ICMS = 30"
3205
                );
3206
                $this->dom->addChild(
3207
                    $icms,
3208
                    'modBCST',
3209
                    $std->modBCST,
3210
                    true,
3211
                    "$identificador [item $std->item] Modalidade de determinação da BC do ICMS ST"
3212
                );
3213
                $this->dom->addChild(
3214
                    $icms,
3215
                    'pMVAST',
3216
                    $this->conditionalNumberFormatting($std->pMVAST, 4),
3217
                    false,
3218
                    "$identificador [item $std->item] Percentual da margem de valor Adicionado do ICMS ST"
3219
                );
3220
                $this->dom->addChild(
3221
                    $icms,
3222
                    'pRedBCST',
3223
                    $this->conditionalNumberFormatting($std->pRedBCST, 4),
3224
                    false,
3225
                    "$identificador [item $std->item] Percentual da Redução de BC do ICMS ST"
3226
                );
3227
                $this->dom->addChild(
3228
                    $icms,
3229
                    'vBCST',
3230
                    $this->conditionalNumberFormatting($std->vBCST),
3231
                    true,
3232
                    "$identificador [item $std->item] Valor da BC do ICMS ST"
3233
                );
3234
                $this->dom->addChild(
3235
                    $icms,
3236
                    'pICMSST',
3237
                    $this->conditionalNumberFormatting($std->pICMSST, 4),
3238
                    true,
3239
                    "$identificador [item $std->item] Alíquota do imposto do ICMS ST"
3240
                );
3241
                $this->dom->addChild(
3242
                    $icms,
3243
                    'vICMSST',
3244
                    $this->conditionalNumberFormatting($std->vICMSST),
3245
                    true,
3246
                    "$identificador [item $std->item] Valor do ICMS ST"
3247
                );
3248
                $this->dom->addChild(
3249
                    $icms,
3250
                    'vBCFCPST',
3251
                    $this->conditionalNumberFormatting($std->vBCFCPST),
3252
                    false,
3253
                    "$identificador [item $std->item] Valor da Base de Cálculo do FCP ST"
3254
                );
3255
                $this->dom->addChild(
3256
                    $icms,
3257
                    'pFCPST',
3258
                    $this->conditionalNumberFormatting($std->pFCPST, 4),
3259
                    false,
3260
                    "$identificador [item $std->item] Percentual do Fundo de "
3261
                    . "Combate à Pobreza (FCP) ST"
3262
                );
3263
                $this->dom->addChild(
3264
                    $icms,
3265
                    'vFCPST',
3266
                    $this->conditionalNumberFormatting($std->vFCPST),
3267
                    false,
3268
                    "$identificador [item $std->item] Valor do FCP ST"
3269
                );
3270
                $this->dom->addChild(
3271
                    $icms,
3272
                    'vICMSDeson',
3273
                    $this->conditionalNumberFormatting($std->vICMSDeson),
3274
                    false,
3275
                    "$identificador [item $std->item] Valor do ICMS desonerado"
3276
                );
3277
                $this->dom->addChild(
3278
                    $icms,
3279
                    'motDesICMS',
3280
                    $std->motDesICMS,
3281
                    false,
3282
                    "$identificador [item $std->item] Motivo da desoneração do ICMS"
3283
                );
3284
                break;
3285
            case '40':
3286
            case '41':
3287
            case '50':
3288
                $icms = $this->dom->createElement("ICMS40");
3289
                $this->dom->addChild(
3290
                    $icms,
3291
                    'orig',
3292
                    $std->orig,
3293
                    true,
3294
                    "$identificador [item $std->item] Origem da mercadoria"
3295
                );
3296
                $this->dom->addChild(
3297
                    $icms,
3298
                    'CST',
3299
                    $std->CST,
3300
                    true,
3301
                    "$identificador [item $std->item] Tributação do ICMS $std->CST"
3302
                );
3303
                $this->dom->addChild(
3304
                    $icms,
3305
                    'vICMSDeson',
3306
                    $this->conditionalNumberFormatting($std->vICMSDeson),
3307
                    false,
3308
                    "$identificador [item $std->item] Valor do ICMS desonerado"
3309
                );
3310
                $this->dom->addChild(
3311
                    $icms,
3312
                    'motDesICMS',
3313
                    $std->motDesICMS,
3314
                    false,
3315
                    "$identificador [item $std->item] Motivo da desoneração do ICMS"
3316
                );
3317
                break;
3318
            case '51':
3319
                $icms = $this->dom->createElement("ICMS51");
3320
                $this->dom->addChild(
3321
                    $icms,
3322
                    'orig',
3323
                    $std->orig,
3324
                    true,
3325
                    "$identificador [item $std->item] Origem da mercadoria"
3326
                );
3327
                $this->dom->addChild(
3328
                    $icms,
3329
                    'CST',
3330
                    $std->CST,
3331
                    true,
3332
                    "$identificador [item $std->item] Tributação do ICMS = 51"
3333
                );
3334
                $this->dom->addChild(
3335
                    $icms,
3336
                    'modBC',
3337
                    $std->modBC,
3338
                    false,
3339
                    "$identificador [item $std->item] Modalidade de determinação da BC do ICMS"
3340
                );
3341
                $this->dom->addChild(
3342
                    $icms,
3343
                    'pRedBC',
3344
                    $this->conditionalNumberFormatting($std->pRedBC, 4),
3345
                    false,
3346
                    "$identificador [item $std->item] Percentual da Redução de BC"
3347
                );
3348
                $this->dom->addChild(
3349
                    $icms,
3350
                    'vBC',
3351
                    $this->conditionalNumberFormatting($std->vBC),
3352
                    false,
3353
                    "$identificador [item $std->item] Valor da BC do ICMS"
3354
                );
3355
                $this->dom->addChild(
3356
                    $icms,
3357
                    'pICMS',
3358
                    $this->conditionalNumberFormatting($std->pICMS, 4),
3359
                    false,
3360
                    "$identificador [item $std->item] Alíquota do imposto"
3361
                );
3362
                $this->dom->addChild(
3363
                    $icms,
3364
                    'vICMSOp',
3365
                    $this->conditionalNumberFormatting($std->vICMSOp),
3366
                    false,
3367
                    "$identificador [item $std->item] Valor do ICMS da Operação"
3368
                );
3369
                $this->dom->addChild(
3370
                    $icms,
3371
                    'pDif',
3372
                    $this->conditionalNumberFormatting($std->pDif, 4),
3373
                    false,
3374
                    "$identificador [item $std->item] Percentual do diferimento"
3375
                );
3376
                $this->dom->addChild(
3377
                    $icms,
3378
                    'vICMSDif',
3379
                    $this->conditionalNumberFormatting($std->vICMSDif),
3380
                    false,
3381
                    "$identificador [item $std->item] Valor do ICMS diferido"
3382
                );
3383
                $this->dom->addChild(
3384
                    $icms,
3385
                    'vICMS',
3386
                    $this->conditionalNumberFormatting($std->vICMS),
3387
                    false,
3388
                    "$identificador [item $std->item] Valor do ICMS realmente devido"
3389
                );
3390
                $this->dom->addChild(
3391
                    $icms,
3392
                    'vBCFCP',
3393
                    $this->conditionalNumberFormatting($std->vBCFCP),
3394
                    false,
3395
                    "$identificador [item $std->item] Valor da Base de Cálculo do FCP"
3396
                );
3397
                $this->dom->addChild(
3398
                    $icms,
3399
                    'pFCP',
3400
                    $this->conditionalNumberFormatting($std->pFCP, 4),
3401
                    false,
3402
                    "$identificador [item $std->item] Percentual do Fundo de "
3403
                    . "Combate à Pobreza (FCP)"
3404
                );
3405
                $this->dom->addChild(
3406
                    $icms,
3407
                    'vFCP',
3408
                    $this->conditionalNumberFormatting($std->vFCP),
3409
                    false,
3410
                    "$identificador [item $std->item] Valor do FCP"
3411
                );
3412
                break;
3413
            case '60':
3414
                $icms = $this->dom->createElement("ICMS60");
3415
                $this->dom->addChild(
3416
                    $icms,
3417
                    'orig',
3418
                    $std->orig,
3419
                    true,
3420
                    "$identificador [item $std->item] Origem da mercadoria"
3421
                );
3422
                $this->dom->addChild(
3423
                    $icms,
3424
                    'CST',
3425
                    $std->CST,
3426
                    true,
3427
                    "$identificador [item $std->item] Tributação do ICMS = 60"
3428
                );
3429
                $this->dom->addChild(
3430
                    $icms,
3431
                    'vBCSTRet',
3432
                    $this->conditionalNumberFormatting($std->vBCSTRet),
3433
                    false,
3434
                    "$identificador [item $std->item] Valor da BC do ICMS ST retido"
3435
                );
3436
                $this->dom->addChild(
3437
                    $icms,
3438
                    'pST',
3439
                    $this->conditionalNumberFormatting($std->pST, 4),
3440
                    false,
3441
                    "$identificador [item $std->item] Valor do ICMS ST retido"
3442
                );
3443
                $this->dom->addChild(
3444
                    $icms,
3445
                    'vICMSSubstituto',
3446
                    $this->conditionalNumberFormatting($std->vICMSSubstituto),
3447
                    false,
3448
                    "$identificador [item $std->item] Valor do ICMS próprio do Substituto"
3449
                );
3450
                $this->dom->addChild(
3451
                    $icms,
3452
                    'vICMSSTRet',
3453
                    $this->conditionalNumberFormatting($std->vICMSSTRet),
3454
                    false,
3455
                    "$identificador [item $std->item] Valor do ICMS ST retido"
3456
                );
3457
                $this->dom->addChild(
3458
                    $icms,
3459
                    'vBCFCPSTRet',
3460
                    $this->conditionalNumberFormatting($std->vBCFCPSTRet),
3461
                    false,
3462
                    "$identificador [item $std->item] Valor da Base de Cálculo "
3463
                    . "do FCP retido anteriormente por ST"
3464
                );
3465
                $this->dom->addChild(
3466
                    $icms,
3467
                    'pFCPSTRet',
3468
                    $this->conditionalNumberFormatting($std->pFCPSTRet, 4),
3469
                    false,
3470
                    "$identificador [item $std->item] Percentual do FCP retido "
3471
                    . "anteriormente por Substituição Tributária"
3472
                );
3473
                $this->dom->addChild(
3474
                    $icms,
3475
                    'vFCPSTRet',
3476
                    $this->conditionalNumberFormatting($std->vFCPSTRet),
3477
                    false,
3478
                    "$identificador [item $std->item] Valor do FCP retido por "
3479
                    . "Substituição Tributária"
3480
                );
3481
                $this->dom->addChild(
3482
                    $icms,
3483
                    'pRedBCEfet',
3484
                    $this->conditionalNumberFormatting($std->pRedBCEfet, 4),
3485
                    false,
3486
                    "$identificador [item $std->item] Percentual de redução "
3487
                    . "para obtenção da base de cálculo efetiva (vBCEfet)"
3488
                );
3489
                $this->dom->addChild(
3490
                    $icms,
3491
                    'vBCEfet',
3492
                    $this->conditionalNumberFormatting($std->vBCEfet),
3493
                    false,
3494
                    "$identificador [item $std->item] base de calculo efetiva"
3495
                );
3496
                $this->dom->addChild(
3497
                    $icms,
3498
                    'pICMSEfet',
3499
                    $this->conditionalNumberFormatting($std->pICMSEfet, 4),
3500
                    false,
3501
                    "$identificador [item $std->item] Alíquota do ICMS na operação a consumidor final"
3502
                );
3503
                $this->dom->addChild(
3504
                    $icms,
3505
                    'vICMSEfet',
3506
                    $this->conditionalNumberFormatting($std->vICMSEfet),
3507
                    false,
3508
                    "$identificador [item $std->item] Valor do ICMS efetivo"
3509
                );
3510
                break;
3511
            case '70':
3512
                $this->stdTot->vBC += (float) !empty($std->vBC) ? $std->vBC : 0;
3513
                $this->stdTot->vICMS += (float) !empty($std->vICMS) ? $std->vICMS : 0;
3514
                $this->stdTot->vBCST += (float) !empty($std->vBCST) ? $std->vBCST : 0;
3515
                $this->stdTot->vST += (float) !empty($std->vICMSST) ? $std->vICMSST : 0;
3516
3517
                $icms = $this->dom->createElement("ICMS70");
3518
                $this->dom->addChild(
3519
                    $icms,
3520
                    'orig',
3521
                    $std->orig,
3522
                    true,
3523
                    "$identificador [item $std->item] Origem da mercadoria"
3524
                );
3525
                $this->dom->addChild(
3526
                    $icms,
3527
                    'CST',
3528
                    $std->CST,
3529
                    true,
3530
                    "$identificador [item $std->item] Tributação do ICMS = 70"
3531
                );
3532
                $this->dom->addChild(
3533
                    $icms,
3534
                    'modBC',
3535
                    $std->modBC,
3536
                    true,
3537
                    "$identificador [item $std->item] Modalidade de determinação da BC do ICMS"
3538
                );
3539
                $this->dom->addChild(
3540
                    $icms,
3541
                    'pRedBC',
3542
                    $this->conditionalNumberFormatting($std->pRedBC, 4),
3543
                    true,
3544
                    "$identificador [item $std->item] Percentual da Redução de BC"
3545
                );
3546
                $this->dom->addChild(
3547
                    $icms,
3548
                    'vBC',
3549
                    $this->conditionalNumberFormatting($std->vBC),
3550
                    true,
3551
                    "$identificador [item $std->item] Valor da BC do ICMS"
3552
                );
3553
                $this->dom->addChild(
3554
                    $icms,
3555
                    'pICMS',
3556
                    $this->conditionalNumberFormatting($std->pICMS, 4),
3557
                    true,
3558
                    "$identificador [item $std->item] Alíquota do imposto"
3559
                );
3560
                $this->dom->addChild(
3561
                    $icms,
3562
                    'vICMS',
3563
                    $this->conditionalNumberFormatting($std->vICMS),
3564
                    true,
3565
                    "$identificador [item $std->item] Valor do ICMS"
3566
                );
3567
                $this->dom->addChild(
3568
                    $icms,
3569
                    'vBCFCP',
3570
                    $this->conditionalNumberFormatting($std->vBCFCP),
3571
                    false,
3572
                    "$identificador [item $std->item] Valor da Base de Cálculo do FCP"
3573
                );
3574
                $this->dom->addChild(
3575
                    $icms,
3576
                    'pFCP',
3577
                    $this->conditionalNumberFormatting($std->pFCP, 4),
3578
                    false,
3579
                    "$identificador [item $std->item] Percentual do Fundo de "
3580
                    . "Combate à Pobreza (FCP)"
3581
                );
3582
                $this->dom->addChild(
3583
                    $icms,
3584
                    'vFCP',
3585
                    $std->vFCP,
3586
                    false,
3587
                    "$identificador [item $std->item] Valor do FCP"
3588
                );
3589
                $this->dom->addChild(
3590
                    $icms,
3591
                    'modBCST',
3592
                    $std->modBCST,
3593
                    true,
3594
                    "$identificador [item $std->item] Modalidade de determinação da BC do ICMS ST"
3595
                );
3596
                $this->dom->addChild(
3597
                    $icms,
3598
                    'pMVAST',
3599
                    $this->conditionalNumberFormatting($std->pMVAST, 4),
3600
                    false,
3601
                    "$identificador [item $std->item] Percentual da margem de valor Adicionado do ICMS ST"
3602
                );
3603
                $this->dom->addChild(
3604
                    $icms,
3605
                    'pRedBCST',
3606
                    $this->conditionalNumberFormatting($std->pRedBCST, 4),
3607
                    false,
3608
                    "$identificador [item $std->item] Percentual da Redução de BC do ICMS ST"
3609
                );
3610
                $this->dom->addChild(
3611
                    $icms,
3612
                    'vBCST',
3613
                    $this->conditionalNumberFormatting($std->vBCST),
3614
                    true,
3615
                    "$identificador [item $std->item] Valor da BC do ICMS ST"
3616
                );
3617
                $this->dom->addChild(
3618
                    $icms,
3619
                    'pICMSST',
3620
                    $this->conditionalNumberFormatting($std->pICMSST, 4),
3621
                    true,
3622
                    "$identificador [item $std->item] Alíquota do imposto do ICMS ST"
3623
                );
3624
                $this->dom->addChild(
3625
                    $icms,
3626
                    'vICMSST',
3627
                    $this->conditionalNumberFormatting($std->vICMSST),
3628
                    true,
3629
                    "$identificador [item $std->item] Valor do ICMS ST"
3630
                );
3631
                $this->dom->addChild(
3632
                    $icms,
3633
                    'vBCFCPST',
3634
                    $this->conditionalNumberFormatting($std->vBCFCPST),
3635
                    false,
3636
                    "$identificador [item $std->item] Valor da Base de Cálculo do FCP ST"
3637
                );
3638
                $this->dom->addChild(
3639
                    $icms,
3640
                    'pFCPST',
3641
                    $this->conditionalNumberFormatting($std->pFCPST, 4),
3642
                    false,
3643
                    "$identificador [item $std->item] Percentual do Fundo de "
3644
                    . "Combate à Pobreza (FCP) ST"
3645
                );
3646
                $this->dom->addChild(
3647
                    $icms,
3648
                    'vFCPST',
3649
                    $this->conditionalNumberFormatting($std->vFCPST),
3650
                    false,
3651
                    "$identificador [item $std->item] Valor do FCP ST"
3652
                );
3653
                $this->dom->addChild(
3654
                    $icms,
3655
                    'vICMSDeson',
3656
                    $this->conditionalNumberFormatting($std->vICMSDeson),
3657
                    false,
3658
                    "$identificador [item $std->item] Valor do ICMS desonerado"
3659
                );
3660
                $this->dom->addChild(
3661
                    $icms,
3662
                    'motDesICMS',
3663
                    $std->motDesICMS,
3664
                    false,
3665
                    "$identificador [item $std->item] Motivo da desoneração do ICMS"
3666
                );
3667
                break;
3668
            case '90':
3669
                $this->stdTot->vBC += (float) !empty($std->vBC) ? $std->vBC : 0;
3670
                $this->stdTot->vICMS += (float) !empty($std->vICMS) ? $std->vICMS : 0;
3671
                $this->stdTot->vBCST += (float) !empty($std->vBCST) ? $std->vBCST : 0;
3672
                $this->stdTot->vST += (float) !empty($std->vICMSST) ? $std->vICMSST : 0;
3673
3674
                $icms = $this->dom->createElement("ICMS90");
3675
                $this->dom->addChild(
3676
                    $icms,
3677
                    'orig',
3678
                    $std->orig,
3679
                    true,
3680
                    "$identificador [item $std->item] Origem da mercadoria"
3681
                );
3682
                $this->dom->addChild(
3683
                    $icms,
3684
                    'CST',
3685
                    $std->CST,
3686
                    true,
3687
                    "$identificador [item $std->item] Tributação do ICMS = 90"
3688
                );
3689
                $this->dom->addChild(
3690
                    $icms,
3691
                    'modBC',
3692
                    $std->modBC,
3693
                    false,
3694
                    "$identificador [item $std->item] Modalidade de determinação da BC do ICMS"
3695
                );
3696
                $this->dom->addChild(
3697
                    $icms,
3698
                    'vBC',
3699
                    $this->conditionalNumberFormatting($std->vBC),
3700
                    false,
3701
                    "$identificador [item $std->item] Valor da BC do ICMS"
3702
                );
3703
                $this->dom->addChild(
3704
                    $icms,
3705
                    'pRedBC',
3706
                    $this->conditionalNumberFormatting($std->pRedBC, 4),
3707
                    false,
3708
                    "$identificador [item $std->item] Percentual da Redução de BC"
3709
                );
3710
                $this->dom->addChild(
3711
                    $icms,
3712
                    'pICMS',
3713
                    $this->conditionalNumberFormatting($std->pICMS, 4),
3714
                    false,
3715
                    "$identificador [item $std->item] Alíquota do imposto"
3716
                );
3717
                $this->dom->addChild(
3718
                    $icms,
3719
                    'vICMS',
3720
                    $this->conditionalNumberFormatting($std->vICMS),
3721
                    false,
3722
                    "$identificador [item $std->item] Valor do ICMS"
3723
                );
3724
                $this->dom->addChild(
3725
                    $icms,
3726
                    'vBCFCP',
3727
                    $this->conditionalNumberFormatting($std->vBCFCP),
3728
                    false,
3729
                    "$identificador [item $std->item] Valor da Base de Cálculo do FCP"
3730
                );
3731
                $this->dom->addChild(
3732
                    $icms,
3733
                    'pFCP',
3734
                    $this->conditionalNumberFormatting($std->pFCP, 4),
3735
                    false,
3736
                    "$identificador [item $std->item] Percentual do Fundo de "
3737
                    . "Combate à Pobreza (FCP)"
3738
                );
3739
                $this->dom->addChild(
3740
                    $icms,
3741
                    'vFCP',
3742
                    $this->conditionalNumberFormatting($std->vFCP),
3743
                    false,
3744
                    "$identificador [item $std->item] Valor do FCP"
3745
                );
3746
                $this->dom->addChild(
3747
                    $icms,
3748
                    'modBCST',
3749
                    $std->modBCST,
3750
                    false,
3751
                    "$identificador [item $std->item] Modalidade de determinação da BC do ICMS ST"
3752
                );
3753
                $this->dom->addChild(
3754
                    $icms,
3755
                    'pMVAST',
3756
                    $this->conditionalNumberFormatting($std->pMVAST, 4),
3757
                    false,
3758
                    "$identificador [item $std->item] Percentual da margem de valor Adicionado do ICMS ST"
3759
                );
3760
                $this->dom->addChild(
3761
                    $icms,
3762
                    'pRedBCST',
3763
                    $this->conditionalNumberFormatting($std->pRedBCST, 4),
3764
                    false,
3765
                    "$identificador [item $std->item] Percentual da Redução de BC do ICMS ST"
3766
                );
3767
                $this->dom->addChild(
3768
                    $icms,
3769
                    'vBCST',
3770
                    $this->conditionalNumberFormatting($std->vBCST),
3771
                    false,
3772
                    "$identificador [item $std->item] Valor da BC do ICMS ST"
3773
                );
3774
                $this->dom->addChild(
3775
                    $icms,
3776
                    'pICMSST',
3777
                    $this->conditionalNumberFormatting($std->pICMSST, 4),
3778
                    false,
3779
                    "$identificador [item $std->item] Alíquota do imposto do ICMS ST"
3780
                );
3781
                $this->dom->addChild(
3782
                    $icms,
3783
                    'vICMSST',
3784
                    $this->conditionalNumberFormatting($std->vICMSST),
3785
                    false,
3786
                    "$identificador [item $std->item] Valor do ICMS ST"
3787
                );
3788
                $this->dom->addChild(
3789
                    $icms,
3790
                    'vBCFCPST',
3791
                    $this->conditionalNumberFormatting($std->vBCFCPST),
3792
                    false,
3793
                    "$identificador [item $std->item] Valor da Base de Cálculo do FCP ST"
3794
                );
3795
                $this->dom->addChild(
3796
                    $icms,
3797
                    'pFCPST',
3798
                    $this->conditionalNumberFormatting($std->pFCPST, 4),
3799
                    false,
3800
                    "$identificador [item $std->item] Percentual do Fundo de "
3801
                    . "Combate à Pobreza (FCP) ST"
3802
                );
3803
                $this->dom->addChild(
3804
                    $icms,
3805
                    'vFCPST',
3806
                    $this->conditionalNumberFormatting($std->vFCPST),
3807
                    false,
3808
                    "$identificador [item $std->item] Valor do FCP ST"
3809
                );
3810
                $this->dom->addChild(
3811
                    $icms,
3812
                    'vICMSDeson',
3813
                    $this->conditionalNumberFormatting($std->vICMSDeson),
3814
                    false,
3815
                    "$identificador [item $std->item] Valor do ICMS desonerado"
3816
                );
3817
                $this->dom->addChild(
3818
                    $icms,
3819
                    'motDesICMS',
3820
                    $std->motDesICMS,
3821
                    false,
3822
                    "$identificador [item $std->item] Motivo da desoneração do ICMS"
3823
                );
3824
                break;
3825
        }
3826
        $tagIcms = $this->dom->createElement('ICMS');
3827
        if (isset($icms)) {
3828
            $tagIcms->appendChild($icms);
3829
        }
3830
        $this->aICMS[$std->item] = $tagIcms;
3831
        return $tagIcms;
3832
    }
3833
3834
    /**
3835
     * Grupo de Partilha do ICMS entre a UF de origem e UF de destino ou
3836
     * a UF definida na legislação. N10a pai N01
3837
     * tag NFe/infNFe/det[]/imposto/ICMS/ICMSPart
3838
     * @param stdClass $std
3839
     * @return DOMElement
3840
     */
3841
    public function tagICMSPart(stdClass $std)
3842
    {
3843
        $possible = [
3844
            'item',
3845
            'orig',
3846
            'CST',
3847
            'modBC',
3848
            'vBC',
3849
            'pRedBC',
3850
            'pICMS',
3851
            'vICMS',
3852
            'modBCST',
3853
            'pMVAST',
3854
            'pRedBCST',
3855
            'vBCST',
3856
            'pICMSST',
3857
            'vICMSST',
3858
            'pBCOp',
3859
            'UFST'
3860
        ];
3861
        $std = $this->equilizeParameters($std, $possible);
3862
        $this->stdTot->vBC += (float) !empty($std->vBC) ? $std->vBC : 0;
3863
        $this->stdTot->vICMS += (float) !empty($std->vICMS) ? $std->vICMS : 0;
3864
        $this->stdTot->vBCST += (float) !empty($std->vBCST) ? $std->vBCST : 0;
3865
        $this->stdTot->vST += (float) !empty($std->vICMSST) ? $std->vICMSST : 0;
3866
        $icmsPart = $this->dom->createElement("ICMSPart");
3867
        $this->dom->addChild(
3868
            $icmsPart,
3869
            'orig',
3870
            $std->orig,
3871
            true,
3872
            "[item $std->item] Origem da mercadoria"
3873
        );
3874
        $this->dom->addChild(
3875
            $icmsPart,
3876
            'CST',
3877
            $std->CST,
3878
            true,
3879
            "[item $std->item] Tributação do ICMS 10 ou 90"
3880
        );
3881
        $this->dom->addChild(
3882
            $icmsPart,
3883
            'modBC',
3884
            $std->modBC,
3885
            true,
3886
            "[item $std->item] Modalidade de determinação da BC do ICMS"
3887
        );
3888
        $this->dom->addChild(
3889
            $icmsPart,
3890
            'vBC',
3891
            $this->conditionalNumberFormatting($std->vBC),
3892
            true,
3893
            "[item $std->item] Valor da BC do ICMS"
3894
        );
3895
        $this->dom->addChild(
3896
            $icmsPart,
3897
            'pRedBC',
3898
            $this->conditionalNumberFormatting($std->pRedBC, 4),
3899
            false,
3900
            "[item $std->item] Percentual da Redução de BC"
3901
        );
3902
        $this->dom->addChild(
3903
            $icmsPart,
3904
            'pICMS',
3905
            $this->conditionalNumberFormatting($std->pICMS, 4),
3906
            true,
3907
            "[item $std->item] Alíquota do imposto"
3908
        );
3909
        $this->dom->addChild(
3910
            $icmsPart,
3911
            'vICMS',
3912
            $this->conditionalNumberFormatting($std->vICMS),
3913
            true,
3914
            "[item $std->item] Valor do ICMS"
3915
        );
3916
        $this->dom->addChild(
3917
            $icmsPart,
3918
            'modBCST',
3919
            $std->modBCST,
3920
            true,
3921
            "[item $std->item] Modalidade de determinação da BC do ICMS ST"
3922
        );
3923
        $this->dom->addChild(
3924
            $icmsPart,
3925
            'pMVAST',
3926
            $this->conditionalNumberFormatting($std->pMVAST, 4),
3927
            false,
3928
            "[item $std->item] Percentual da margem de valor Adicionado do ICMS ST"
3929
        );
3930
        $this->dom->addChild(
3931
            $icmsPart,
3932
            'pRedBCST',
3933
            $this->conditionalNumberFormatting($std->pRedBCST, 4),
3934
            false,
3935
            "[item $std->item] Percentual da Redução de BC do ICMS ST"
3936
        );
3937
        $this->dom->addChild(
3938
            $icmsPart,
3939
            'vBCST',
3940
            $this->conditionalNumberFormatting($std->vBCST),
3941
            true,
3942
            "[item $std->item] Valor da BC do ICMS ST"
3943
        );
3944
        $this->dom->addChild(
3945
            $icmsPart,
3946
            'pICMSST',
3947
            $this->conditionalNumberFormatting($std->pICMSST, 4),
3948
            true,
3949
            "[item $std->item] Alíquota do imposto do ICMS ST"
3950
        );
3951
        $this->dom->addChild(
3952
            $icmsPart,
3953
            'vICMSST',
3954
            $this->conditionalNumberFormatting($std->vICMSST),
3955
            true,
3956
            "[item $std->item] Valor do ICMS ST"
3957
        );
3958
        $this->dom->addChild(
3959
            $icmsPart,
3960
            'pBCOp',
3961
            $this->conditionalNumberFormatting($std->pBCOp, 4),
3962
            true,
3963
            "[item $std->item] Percentual da BC operação própria"
3964
        );
3965
        $this->dom->addChild(
3966
            $icmsPart,
3967
            'UFST',
3968
            $std->UFST,
3969
            true,
3970
            "[item $std->item] UF para qual é devido o ICMS ST"
3971
        );
3972
        //caso exista a tag aICMS[$std->item] inserir nela caso contrario criar
3973
        if (!empty($this->aICMS[$std->item])) {
3974
            $tagIcms = $this->aICMS[$std->item];
3975
        } else {
3976
            $tagIcms = $this->dom->createElement('ICMS');
3977
        }
3978
        $this->dom->appChild($tagIcms, $icmsPart, "Inserindo ICMSPart em ICMS[$std->item]");
3979
        $this->aICMS[$std->item] = $tagIcms;
3980
        return $tagIcms;
3981
    }
3982
3983
    /**
3984
     * Grupo de Repasse de ICMSST retido anteriormente em operações
3985
     * interestaduais com repasses através do Substituto Tributário
3986
     * NOTA: ajustado NT 2018.005
3987
     * tag NFe/infNFe/det[]/imposto/ICMS/ICMSST N10b pai N01
3988
     * @param stdClass $std
3989
     * @return DOMElement
3990
     */
3991
    public function tagICMSST(stdClass $std)
3992
    {
3993
        $possible = [
3994
            'item',
3995
            'orig',
3996
            'CST',
3997
            'vBCSTRet',
3998
            'vICMSSTRet',
3999
            'vBCSTDest',
4000
            'vICMSSTDest',
4001
            'vBCFCPSTRet',
4002
            'pFCPSTRet',
4003
            'vFCPSTRet',
4004
            'pST',
4005
            'vICMSSubstituto',
4006
            'pRedBCEfet',
4007
            'vBCEfet',
4008
            'pICMSEfet',
4009
            'vICMSEfet'
4010
        ];
4011
        $std = $this->equilizeParameters($std, $possible);
4012
        $icmsST = $this->dom->createElement("ICMSST");
4013
        $this->dom->addChild(
4014
            $icmsST,
4015
            'orig',
4016
            $std->orig,
4017
            true,
4018
            "[item $std->item] Origem da mercadoria"
4019
        );
4020
        $this->dom->addChild(
4021
            $icmsST,
4022
            'CST',
4023
            $std->CST,
4024
            true,
4025
            "[item $std->item] Tributação do ICMS 41 ou 60"
4026
        );
4027
        $this->dom->addChild(
4028
            $icmsST,
4029
            'vBCSTRet',
4030
            $this->conditionalNumberFormatting($std->vBCSTRet),
4031
            true,
4032
            "[item $std->item] Valor do BC do ICMS ST retido na UF remetente"
4033
        );
4034
        $this->dom->addChild(
4035
            $icmsST,
4036
            'pST',
4037
            $this->conditionalNumberFormatting($std->pST, 4),
4038
            false,
4039
            "[item $std->item] Alíquota suportada pelo Consumidor Final"
4040
        );
4041
        $this->dom->addChild(
4042
            $icmsST,
4043
            'vICMSSubstituto',
4044
            $this->conditionalNumberFormatting($std->vICMSSubstituto),
4045
            false,
4046
            "[item $std->item] Valor do ICMS próprio do Substituto"
4047
        );
4048
        $this->dom->addChild(
4049
            $icmsST,
4050
            'vICMSSTRet',
4051
            $this->conditionalNumberFormatting($std->vICMSSTRet),
4052
            true,
4053
            "[item $std->item] Valor do ICMS ST retido na UF remetente"
4054
        );
4055
        $this->dom->addChild(
4056
            $icmsST,
4057
            'vBCFCPSTRet',
4058
            $this->conditionalNumberFormatting($std->vBCFCPSTRet),
4059
            false,
4060
            "[item $std->item] Valor da Base de Cálculo do FCP"
4061
        );
4062
        $this->dom->addChild(
4063
            $icmsST,
4064
            'pFCPSTRet',
4065
            $this->conditionalNumberFormatting($std->pFCPSTRet, 4),
4066
            false,
4067
            "[item $std->item] Percentual do FCP retido"
4068
        );
4069
        $this->dom->addChild(
4070
            $icmsST,
4071
            'vFCPSTRet',
4072
            $this->conditionalNumberFormatting($std->vFCPSTRet),
4073
            false,
4074
            "[item $std->item] Valor do FCP retido"
4075
        );
4076
        $this->dom->addChild(
4077
            $icmsST,
4078
            'vBCSTDest',
4079
            $this->conditionalNumberFormatting($std->vBCSTDest),
4080
            true,
4081
            "[item $std->item] Valor da BC do ICMS ST da UF destino"
4082
        );
4083
        $this->dom->addChild(
4084
            $icmsST,
4085
            'vICMSSTDest',
4086
            $this->conditionalNumberFormatting($std->vICMSSTDest),
4087
            true,
4088
            "[item $std->item] Valor do ICMS ST da UF destino"
4089
        );
4090
        $this->dom->addChild(
4091
            $icmsST,
4092
            'pRedBCEfet',
4093
            $this->conditionalNumberFormatting($std->pRedBCEfet, 4),
4094
            false,
4095
            "[item $std->item] Percentual de redução da base de cálculo efetiva"
4096
        );
4097
        $this->dom->addChild(
4098
            $icmsST,
4099
            'vBCEfet',
4100
            $this->conditionalNumberFormatting($std->vBCEfet),
4101
            false,
4102
            "[item $std->item] Valor da base de cálculo efetiva"
4103
        );
4104
        $this->dom->addChild(
4105
            $icmsST,
4106
            'pICMSEfet',
4107
            $this->conditionalNumberFormatting($std->pICMSEfet, 4),
4108
            false,
4109
            "[item $std->item] Alíquota do ICMS efetiva"
4110
        );
4111
        $this->dom->addChild(
4112
            $icmsST,
4113
            'vICMSEfet',
4114
            $this->conditionalNumberFormatting($std->vICMSEfet),
4115
            false,
4116
            "[item $std->item] Valor do ICMS efetivo"
4117
        );
4118
        //caso exista a tag aICMS[$std->item] inserir nela caso contrario criar
4119
        if (!empty($this->aICMS[$std->item])) {
4120
            $tagIcms = $this->aICMS[$std->item];
4121
        } else {
4122
            $tagIcms = $this->dom->createElement('ICMS');
4123
        }
4124
        $this->dom->appChild($tagIcms, $icmsST, "Inserindo ICMSST em ICMS[$std->item]");
4125
        $this->aICMS[$std->item] = $tagIcms;
4126
        return $tagIcms;
4127
    }
4128
4129
    /**
4130
     * Tributação ICMS pelo Simples Nacional N10c pai N01
4131
     * tag NFe/infNFe/det[]/imposto/ICMS/ICMSSN N10c pai N01
4132
     * @param stdClass $std
4133
     * @return DOMElement
4134
     */
4135
    public function tagICMSSN(stdClass $std)
4136
    {
4137
        $possible = [
4138
            'item',
4139
            'orig',
4140
            'CSOSN',
4141
            'pCredSN',
4142
            'vCredICMSSN',
4143
            'modBCST',
4144
            'pMVAST',
4145
            'pRedBCST',
4146
            'vBCST',
4147
            'pICMSST',
4148
            'vICMSST',
4149
            'vBCFCPST',
4150
            'pFCPST',
4151
            'vFCPST',
4152
            'vBCSTRet',
4153
            'pST',
4154
            'vICMSSTRet',
4155
            'vBCFCPSTRet',
4156
            'pFCPSTRet',
4157
            'vFCPSTRet',
4158
            'modBC',
4159
            'vBC',
4160
            'pRedBC',
4161
            'pICMS',
4162
            'vICMS',
4163
            'pRedBCEfet',
4164
            'vBCEfet',
4165
            'pICMSEfet',
4166
            'vICMSEfet',
4167
            'vICMSSubstituto'
4168
        ];
4169
        $std = $this->equilizeParameters($std, $possible);
4170
        //totalizador generico
4171
        $this->stdTot->vFCPST += (float) !empty($std->vFCPST) ? $std->vFCPST : 0;
4172
        $this->stdTot->vFCPSTRet += (float) !empty($std->vFCPSTRet) ? $std->vFCPSTRet : 0;
4173
        switch ($std->CSOSN) {
4174
            case '101':
4175
                $icmsSN = $this->dom->createElement("ICMSSN101");
4176
                $this->dom->addChild(
4177
                    $icmsSN,
4178
                    'orig',
4179
                    $std->orig,
4180
                    true,
4181
                    "[item $std->item] Origem da mercadoria"
4182
                );
4183
                $this->dom->addChild(
4184
                    $icmsSN,
4185
                    'CSOSN',
4186
                    $std->CSOSN,
4187
                    true,
4188
                    "[item $std->item] Código de Situação da Operação Simples Nacional"
4189
                );
4190
                $this->dom->addChild(
4191
                    $icmsSN,
4192
                    'pCredSN',
4193
                    $this->conditionalNumberFormatting($std->pCredSN, 2),
4194
                    true,
4195
                    "[item $std->item] Alíquota aplicável de cálculo do crédito (Simples Nacional)."
4196
                );
4197
                $this->dom->addChild(
4198
                    $icmsSN,
4199
                    'vCredICMSSN',
4200
                    $this->conditionalNumberFormatting($std->vCredICMSSN),
4201
                    true,
4202
                    "[item $std->item] Valor crédito do ICMS que pode ser aproveitado nos termos do"
4203
                    . " art. 23 da LC 123 (Simples Nacional)"
4204
                );
4205
                break;
4206
            case '102':
4207
            case '103':
4208
            case '300':
4209
            case '400':
4210
                $icmsSN = $this->dom->createElement("ICMSSN102");
4211
                $this->dom->addChild(
4212
                    $icmsSN,
4213
                    'orig',
4214
                    $std->orig,
4215
                    true,
4216
                    "[item $std->item] Origem da mercadoria"
4217
                );
4218
                $this->dom->addChild(
4219
                    $icmsSN,
4220
                    'CSOSN',
4221
                    $std->CSOSN,
4222
                    true,
4223
                    "[item $std->item] Código de Situação da Operação Simples Nacional"
4224
                );
4225
                break;
4226
            case '201':
4227
                $this->stdTot->vBCST += (float) !empty($std->vBCST) ? $std->vBCST : 0;
4228
                $this->stdTot->vST += (float) !empty($std->vICMSST) ? $std->vICMSST : 0;
4229
4230
                $icmsSN = $this->dom->createElement("ICMSSN201");
4231
                $this->dom->addChild(
4232
                    $icmsSN,
4233
                    'orig',
4234
                    $std->orig,
4235
                    true,
4236
                    "[item $std->item] Origem da mercadoria"
4237
                );
4238
                $this->dom->addChild(
4239
                    $icmsSN,
4240
                    'CSOSN',
4241
                    $std->CSOSN,
4242
                    true,
4243
                    "[item $std->item] Código de Situação da Operação Simples Nacional"
4244
                );
4245
                $this->dom->addChild(
4246
                    $icmsSN,
4247
                    'modBCST',
4248
                    $std->modBCST,
4249
                    true,
4250
                    "[item $std->item] Alíquota aplicável de cálculo do crédito (Simples Nacional)."
4251
                );
4252
                $this->dom->addChild(
4253
                    $icmsSN,
4254
                    'pMVAST',
4255
                    $this->conditionalNumberFormatting($std->pMVAST, 4),
4256
                    false,
4257
                    "[item $std->item] Percentual da margem de valor Adicionado do ICMS ST"
4258
                );
4259
                $this->dom->addChild(
4260
                    $icmsSN,
4261
                    'pRedBCST',
4262
                    $this->conditionalNumberFormatting($std->pRedBCST, 4),
4263
                    false,
4264
                    "[item $std->item] Percentual da Redução de BC do ICMS ST"
4265
                );
4266
                $this->dom->addChild(
4267
                    $icmsSN,
4268
                    'vBCST',
4269
                    $this->conditionalNumberFormatting($std->vBCST),
4270
                    true,
4271
                    "[item $std->item] Valor da BC do ICMS ST"
4272
                );
4273
                $this->dom->addChild(
4274
                    $icmsSN,
4275
                    'pICMSST',
4276
                    $this->conditionalNumberFormatting($std->pICMSST, 4),
4277
                    true,
4278
                    "[item $std->item] Alíquota do imposto do ICMS ST"
4279
                );
4280
                $this->dom->addChild(
4281
                    $icmsSN,
4282
                    'vICMSST',
4283
                    $this->conditionalNumberFormatting($std->vICMSST),
4284
                    true,
4285
                    "[item $std->item] Valor do ICMS ST"
4286
                );
4287
                $this->dom->addChild(
4288
                    $icmsSN,
4289
                    'vBCFCPST',
4290
                    $this->conditionalNumberFormatting($std->vBCFCPST),
4291
                    isset($std->vBCFCPST) ? true : false,
4292
                    "[item $std->item] Valor da Base de Cálculo do FCP "
4293
                    . "retido por Substituição Tributária"
4294
                );
4295
                $this->dom->addChild(
4296
                    $icmsSN,
4297
                    'pFCPST',
4298
                    $this->conditionalNumberFormatting($std->pFCPST, 4),
4299
                    isset($std->pFCPST) ? true : false,
4300
                    "[item $std->item] Percentual do FCP retido por "
4301
                    . "Substituição Tributária"
4302
                );
4303
                $this->dom->addChild(
4304
                    $icmsSN,
4305
                    'vFCPST',
4306
                    $this->conditionalNumberFormatting($std->vFCPST),
4307
                    isset($std->vFCPST) ? true : false,
4308
                    "[item $std->item] Valor do FCP retido por Substituição Tributária"
4309
                );
4310
                $this->dom->addChild(
4311
                    $icmsSN,
4312
                    'pCredSN',
4313
                    $this->conditionalNumberFormatting($std->pCredSN, 4),
4314
                    false,
4315
                    "[item $std->item] Alíquota aplicável de cálculo do crédito (Simples Nacional)."
4316
                );
4317
                $this->dom->addChild(
4318
                    $icmsSN,
4319
                    'vCredICMSSN',
4320
                    $this->conditionalNumberFormatting($std->vCredICMSSN),
4321
                    false,
4322
                    "[item $std->item] Valor crédito do ICMS que pode ser aproveitado nos "
4323
                    . "termos do art. 23 da LC 123 (Simples Nacional)"
4324
                );
4325
                break;
4326
            case '202':
4327
            case '203':
4328
                $this->stdTot->vBCST += (float) !empty($std->vBCST) ? $std->vBCST : 0;
4329
                $this->stdTot->vST += (float) !empty($std->vICMSST) ? $std->vICMSST : 0;
4330
4331
                $icmsSN = $this->dom->createElement("ICMSSN202");
4332
                $this->dom->addChild(
4333
                    $icmsSN,
4334
                    'orig',
4335
                    $std->orig,
4336
                    true,
4337
                    "[item $std->item] Origem da mercadoria"
4338
                );
4339
                $this->dom->addChild(
4340
                    $icmsSN,
4341
                    'CSOSN',
4342
                    $std->CSOSN,
4343
                    true,
4344
                    "[item $std->item] Código de Situação da Operação Simples Nacional"
4345
                );
4346
                $this->dom->addChild(
4347
                    $icmsSN,
4348
                    'modBCST',
4349
                    $std->modBCST,
4350
                    true,
4351
                    "[item $std->item] Alíquota aplicável de cálculo do crédito (Simples Nacional)."
4352
                );
4353
                $this->dom->addChild(
4354
                    $icmsSN,
4355
                    'pMVAST',
4356
                    $this->conditionalNumberFormatting($std->pMVAST, 4),
4357
                    false,
4358
                    "[item $std->item] Percentual da margem de valor Adicionado do ICMS ST"
4359
                );
4360
                $this->dom->addChild(
4361
                    $icmsSN,
4362
                    'pRedBCST',
4363
                    $this->conditionalNumberFormatting($std->pRedBCST, 4),
4364
                    false,
4365
                    "[item $std->item] Percentual da Redução de BC do ICMS ST"
4366
                );
4367
                $this->dom->addChild(
4368
                    $icmsSN,
4369
                    'vBCST',
4370
                    $this->conditionalNumberFormatting($std->vBCST),
4371
                    true,
4372
                    "[item $std->item] Valor da BC do ICMS ST"
4373
                );
4374
                $this->dom->addChild(
4375
                    $icmsSN,
4376
                    'pICMSST',
4377
                    $this->conditionalNumberFormatting($std->pICMSST, 4),
4378
                    true,
4379
                    "[item $std->item] Alíquota do imposto do ICMS ST"
4380
                );
4381
                $this->dom->addChild(
4382
                    $icmsSN,
4383
                    'vICMSST',
4384
                    $this->conditionalNumberFormatting($std->vICMSST),
4385
                    true,
4386
                    "[item $std->item] Valor do ICMS ST"
4387
                );
4388
                $this->dom->addChild(
4389
                    $icmsSN,
4390
                    'vBCFCPST',
4391
                    $this->conditionalNumberFormatting($std->vBCFCPST),
4392
                    isset($std->vBCFCPST) ? true : false,
4393
                    "[item $std->item] Valor da Base de Cálculo do FCP "
4394
                    . "retido por Substituição Tributária"
4395
                );
4396
                $this->dom->addChild(
4397
                    $icmsSN,
4398
                    'pFCPST',
4399
                    $this->conditionalNumberFormatting($std->pFCPST, 4),
4400
                    isset($std->pFCPST) ? true : false,
4401
                    "[item $std->item] Percentual do FCP retido por "
4402
                    . "Substituição Tributária"
4403
                );
4404
                $this->dom->addChild(
4405
                    $icmsSN,
4406
                    'vFCPST',
4407
                    $this->conditionalNumberFormatting($std->vFCPST),
4408
                    isset($std->vFCPST) ? true : false,
4409
                    "[item $std->item] Valor do FCP retido por Substituição Tributária"
4410
                );
4411
                break;
4412
            case '500':
4413
                $icmsSN = $this->dom->createElement("ICMSSN500");
4414
                $this->dom->addChild(
4415
                    $icmsSN,
4416
                    'orig',
4417
                    $std->orig,
4418
                    true,
4419
                    "[item $std->item] Origem da mercadoria"
4420
                );
4421
                $this->dom->addChild(
4422
                    $icmsSN,
4423
                    'CSOSN',
4424
                    $std->CSOSN,
4425
                    true,
4426
                    "[item $std->item] Código de Situação da Operação Simples Nacional"
4427
                );
4428
                $this->dom->addChild(
4429
                    $icmsSN,
4430
                    'vBCSTRet',
4431
                    $this->conditionalNumberFormatting($std->vBCSTRet),
4432
                    isset($std->vBCSTRet) ? true : false,
4433
                    "[item $std->item] Valor da BC do ICMS ST retido"
4434
                );
4435
                $this->dom->addChild(
4436
                    $icmsSN,
4437
                    'pST',
4438
                    $this->conditionalNumberFormatting($std->pST, 4),
4439
                    isset($std->pST) ? true : false,
4440
                    "[item $std->item] Alíquota suportada pelo Consumidor Final"
4441
                );
4442
                $this->dom->addChild(
4443
                    $icmsSN,
4444
                    'vICMSSubstituto',
4445
                    $this->conditionalNumberFormatting($std->vICMSSubstituto),
4446
                    false,
4447
                    "[item $std->item] Valor do ICMS próprio do Substituto"
4448
                );
4449
                $this->dom->addChild(
4450
                    $icmsSN,
4451
                    'vICMSSTRet',
4452
                    $this->conditionalNumberFormatting($std->vICMSSTRet),
4453
                    isset($std->vICMSSTRet) ? true : false,
4454
                    "[item $std->item] Valor do ICMS ST retido"
4455
                );
4456
                $this->dom->addChild(
4457
                    $icmsSN,
4458
                    'vBCFCPSTRet',
4459
                    $this->conditionalNumberFormatting($std->vBCFCPSTRet, 2),
4460
                    isset($std->vBCFCPSTRet) ? true : false,
4461
                    "[item $std->item] Valor da Base de Cálculo do FCP "
4462
                    . "retido anteriormente por Substituição Tributária"
4463
                );
4464
                $this->dom->addChild(
4465
                    $icmsSN,
4466
                    'pFCPSTRet',
4467
                    $this->conditionalNumberFormatting($std->pFCPSTRet, 4),
4468
                    isset($std->pFCPSTRet) ? true : false,
4469
                    "[item $std->item] Percentual do FCP retido anteriormente por "
4470
                    . "Substituição Tributária"
4471
                );
4472
                $this->dom->addChild(
4473
                    $icmsSN,
4474
                    'vFCPSTRet',
4475
                    $this->conditionalNumberFormatting($std->vFCPSTRet),
4476
                    isset($std->vFCPSTRet) ? true : false,
4477
                    "[item $std->item] Valor do FCP retido anteiormente por "
4478
                    . "Substituição Tributária"
4479
                );
4480
                $this->dom->addChild(
4481
                    $icmsSN,
4482
                    'pRedBCEfet',
4483
                    $this->conditionalNumberFormatting($std->pRedBCEfet, 4),
4484
                    isset($std->pRedBCEfet) ? true : false,
4485
                    "[item $std->item] Percentual de redução da base "
4486
                    . "de cálculo efetiva"
4487
                );
4488
                $this->dom->addChild(
4489
                    $icmsSN,
4490
                    'vBCEfet',
4491
                    $this->conditionalNumberFormatting($std->vBCEfet),
4492
                    isset($std->vBCEfet) ? true : false,
4493
                    "[item $std->item] Valor da base de cálculo efetiva"
4494
                );
4495
                $this->dom->addChild(
4496
                    $icmsSN,
4497
                    'pICMSEfet',
4498
                    $this->conditionalNumberFormatting($std->pICMSEfet, 4),
4499
                    isset($std->pICMSEfet) ? true : false,
4500
                    "[item $std->item] Alíquota do ICMS efetiva"
4501
                );
4502
                $this->dom->addChild(
4503
                    $icmsSN,
4504
                    'vICMSEfet',
4505
                    $this->conditionalNumberFormatting($std->vICMSEfet),
4506
                    isset($std->vICMSEfet) ? true : false,
4507
                    "[item $std->item] Valor do ICMS efetivo"
4508
                );
4509
                break;
4510
            case '900':
4511
                $this->stdTot->vBC += (float) !empty($std->vBC) ? $std->vBC : 0;
4512
                $this->stdTot->vICMS += (float) !empty($std->vICMS) ? $std->vICMS : 0;
4513
                $this->stdTot->vBCST += (float) !empty($std->vBCST) ? $std->vBCST : 0;
4514
                $this->stdTot->vST += (float) !empty($std->vICMSST) ? $std->vICMSST : 0;
4515
                $icmsSN = $this->dom->createElement("ICMSSN900");
4516
                $this->dom->addChild(
4517
                    $icmsSN,
4518
                    'orig',
4519
                    $std->orig,
4520
                    true,
4521
                    "[item $std->item] Origem da mercadoria"
4522
                );
4523
                $this->dom->addChild(
4524
                    $icmsSN,
4525
                    'CSOSN',
4526
                    $std->CSOSN,
4527
                    true,
4528
                    "[item $std->item] Código de Situação da Operação Simples Nacional"
4529
                );
4530
                $this->dom->addChild(
4531
                    $icmsSN,
4532
                    'modBC',
4533
                    $std->modBC,
4534
                    isset($std->modBC) ? true : false,
4535
                    "[item $std->item] Modalidade de determinação da BC do ICMS"
4536
                );
4537
                $this->dom->addChild(
4538
                    $icmsSN,
4539
                    'vBC',
4540
                    $this->conditionalNumberFormatting($std->vBC),
4541
                    isset($std->vBC) ? true : false,
4542
                    "[item $std->item] Valor da BC do ICMS"
4543
                );
4544
                $this->dom->addChild(
4545
                    $icmsSN,
4546
                    'pRedBC',
4547
                    $this->conditionalNumberFormatting($std->pRedBC, 4),
4548
                    false,
4549
                    "[item $std->item] Percentual da Redução de BC"
4550
                );
4551
                $this->dom->addChild(
4552
                    $icmsSN,
4553
                    'pICMS',
4554
                    $this->conditionalNumberFormatting($std->pICMS, 4),
4555
                    isset($std->pICMS) ? true : false,
4556
                    "[item $std->item] Alíquota do imposto"
4557
                );
4558
                $this->dom->addChild(
4559
                    $icmsSN,
4560
                    'vICMS',
4561
                    $this->conditionalNumberFormatting($std->vICMS),
4562
                    isset($std->pICMS) ? true : false,
4563
                    "[item $std->item] Valor do ICMS"
4564
                );
4565
                $this->dom->addChild(
4566
                    $icmsSN,
4567
                    'modBCST',
4568
                    $std->modBCST,
4569
                    isset($std->modBCST) ? true : false,
4570
                    "[item $std->item] Alíquota aplicável de cálculo do crédito (Simples Nacional)."
4571
                );
4572
                $this->dom->addChild(
4573
                    $icmsSN,
4574
                    'pMVAST',
4575
                    $this->conditionalNumberFormatting($std->pMVAST, 4),
4576
                    false,
4577
                    "[item $std->item] Percentual da margem de valor Adicionado do ICMS ST"
4578
                );
4579
                $this->dom->addChild(
4580
                    $icmsSN,
4581
                    'pRedBCST',
4582
                    $this->conditionalNumberFormatting($std->pRedBCST, 4),
4583
                    false,
4584
                    "[item $std->item] Percentual da Redução de BC do ICMS ST"
4585
                );
4586
                $this->dom->addChild(
4587
                    $icmsSN,
4588
                    'vBCST',
4589
                    $this->conditionalNumberFormatting($std->vBCST),
4590
                    isset($std->vBCST) ? true : false,
4591
                    "[item $std->item] Valor da BC do ICMS ST"
4592
                );
4593
                $this->dom->addChild(
4594
                    $icmsSN,
4595
                    'pICMSST',
4596
                    $this->conditionalNumberFormatting($std->pICMSST, 4),
4597
                    isset($std->pICMSST) ? true : false,
4598
                    "[item $std->item] Alíquota do imposto do ICMS ST"
4599
                );
4600
                $this->dom->addChild(
4601
                    $icmsSN,
4602
                    'vICMSST',
4603
                    $this->conditionalNumberFormatting($std->vICMSST),
4604
                    isset($std->vICMSST) ? true : false,
4605
                    "[item $std->item] Valor do ICMS ST"
4606
                );
4607
                $this->dom->addChild(
4608
                    $icmsSN,
4609
                    'vBCFCPST',
4610
                    $this->conditionalNumberFormatting($std->vBCFCPST),
4611
                    isset($std->vBCFCPST) ? true : false,
4612
                    "[item $std->item] Valor da Base de Cálculo do FCP "
4613
                    . "retido por Substituição Tributária"
4614
                );
4615
                $this->dom->addChild(
4616
                    $icmsSN,
4617
                    'pFCPST',
4618
                    $this->conditionalNumberFormatting($std->pFCPST, 4),
4619
                    isset($std->pFCPST) ? true : false,
4620
                    "[item $std->item] Percentual do FCP retido por "
4621
                    . "Substituição Tributária"
4622
                );
4623
                $this->dom->addChild(
4624
                    $icmsSN,
4625
                    'vFCPST',
4626
                    $this->conditionalNumberFormatting($std->vFCPST),
4627
                    isset($std->vFCPST) ? true : false,
4628
                    "[item $std->item] Valor do FCP retido por Substituição Tributária"
4629
                );
4630
                $this->dom->addChild(
4631
                    $icmsSN,
4632
                    'pCredSN',
4633
                    $this->conditionalNumberFormatting($std->pCredSN, 4),
4634
                    isset($std->pCredSN) ? true : false,
4635
                    "[item $std->item] Alíquota aplicável de cálculo do crédito (Simples Nacional)."
4636
                );
4637
                $this->dom->addChild(
4638
                    $icmsSN,
4639
                    'vCredICMSSN',
4640
                    $this->conditionalNumberFormatting($std->vCredICMSSN),
4641
                    isset($std->vCredICMSSN) ? true : false,
4642
                    "[item $std->item] Valor crédito do ICMS que pode ser aproveitado nos termos do"
4643
                    . " art. 23 da LC 123 (Simples Nacional)"
4644
                );
4645
                break;
4646
        }
4647
        //caso exista a tag aICMS[$std-item] inserir nela caso contrario criar
4648
        if (!empty($this->aICMS[$std->item])) {
4649
            $tagIcms = $this->aICMS[$std->item];
4650
        } else {
4651
            $tagIcms = $this->dom->createElement('ICMS');
4652
        }
4653
        if (isset($icmsSN)) {
4654
            $this->dom->appChild($tagIcms, $icmsSN, "Inserindo ICMSST em ICMS[$std->item]");
4655
        }
4656
        $this->aICMS[$std->item] = $tagIcms;
4657
        return $tagIcms;
4658
    }
4659
4660
    /**
4661
     * Grupo ICMSUFDest NA01 pai M01
4662
     * tag NFe/infNFe/det[]/imposto/ICMSUFDest (opcional)
4663
     * Grupo a ser informado nas vendas interestaduais para consumidor final,
4664
     * não contribuinte do ICMS
4665
     * @param stdClass $std
4666
     * @return DOMElement
4667
     */
4668
    public function tagICMSUFDest(stdClass $std)
4669
    {
4670
        $possible = [
4671
            'item',
4672
            'vBCUFDest',
4673
            'vBCFCPUFDest',
4674
            'pFCPUFDest',
4675
            'pICMSUFDest',
4676
            'pICMSInter',
4677
            'pICMSInterPart',
4678
            'vFCPUFDest',
4679
            'vICMSUFDest',
4680
            'vICMSUFRemet'
4681
        ];
4682
        $std = $this->equilizeParameters($std, $possible);
4683
        $this->stdTot->vICMSUFDest += (float) $std->vICMSUFDest;
4684
        $this->stdTot->vFCPUFDest += (float) $std->vFCPUFDest;
4685
        $this->stdTot->vICMSUFRemet += (float) $std->vICMSUFRemet;
4686
        $icmsUFDest = $this->dom->createElement('ICMSUFDest');
4687
        $this->dom->addChild(
4688
            $icmsUFDest,
4689
            "vBCUFDest",
4690
            $this->conditionalNumberFormatting($std->vBCUFDest),
4691
            true,
4692
            "[item $std->item] Valor da BC do ICMS na UF do destinatário"
4693
        );
4694
        $this->dom->addChild(
4695
            $icmsUFDest,
4696
            "vBCFCPUFDest",
4697
            $this->conditionalNumberFormatting($std->vBCFCPUFDest),
4698
            false,
4699
            "[item $std->item] Valor da BC do ICMS na UF do destinatário"
4700
        );
4701
        $this->dom->addChild(
4702
            $icmsUFDest,
4703
            "pFCPUFDest",
4704
            $this->conditionalNumberFormatting($std->pFCPUFDest, 4),
4705
            false,
4706
            "[item $std->item] Percentual do ICMS relativo ao Fundo de Combate à Pobreza (FCP) na UF de destino"
4707
        );
4708
        $this->dom->addChild(
4709
            $icmsUFDest,
4710
            "pICMSUFDest",
4711
            $this->conditionalNumberFormatting($std->pICMSUFDest, 4),
4712
            true,
4713
            "[item $std->item] Alíquota interna da UF do destinatário"
4714
        );
4715
        $this->dom->addChild(
4716
            $icmsUFDest,
4717
            "pICMSInter",
4718
            $this->conditionalNumberFormatting($std->pICMSInter, 2),
4719
            true,
4720
            "[item $std->item] Alíquota interestadual das UF envolvidas"
4721
        );
4722
        $this->dom->addChild(
4723
            $icmsUFDest,
4724
            "pICMSInterPart",
4725
            $this->conditionalNumberFormatting($std->pICMSInterPart, 4),
4726
            true,
4727
            "[item $std->item] Percentual provisório de partilha entre os Estados"
4728
        );
4729
        $this->dom->addChild(
4730
            $icmsUFDest,
4731
            "vFCPUFDest",
4732
            $this->conditionalNumberFormatting($std->vFCPUFDest),
4733
            false,
4734
            "[item $std->item] Valor do ICMS relativo ao Fundo de Combate à Pobreza (FCP) da UF de destino"
4735
        );
4736
        $this->dom->addChild(
4737
            $icmsUFDest,
4738
            "vICMSUFDest",
4739
            $this->conditionalNumberFormatting($std->vICMSUFDest),
4740
            true,
4741
            "[item $std->item] Valor do ICMS de partilha para a UF do destinatário"
4742
        );
4743
        $this->dom->addChild(
4744
            $icmsUFDest,
4745
            "vICMSUFRemet",
4746
            $this->conditionalNumberFormatting($std->vICMSUFRemet),
4747
            true,
4748
            "[item $std->item] Valor do ICMS de partilha para a UF do remetente"
4749
        );
4750
        $this->aICMSUFDest[$std->item] = $icmsUFDest;
4751
        return $icmsUFDest;
4752
    }
4753
4754
    /**
4755
     * Grupo IPI O01 pai M01
4756
     * tag NFe/infNFe/det[]/imposto/IPI (opcional)
4757
     * @param stdClass $std
4758
     * @return DOMElement
4759
     */
4760
    public function tagIPI(stdClass $std)
4761
    {
4762
        $possible = [
4763
            'item',
4764
            'clEnq',
4765
            'CNPJProd',
4766
            'cSelo',
4767
            'qSelo',
4768
            'cEnq',
4769
            'CST',
4770
            'vIPI',
4771
            'vBC',
4772
            'pIPI',
4773
            'qUnid',
4774
            'vUnid'
4775
        ];
4776
        $std = $this->equilizeParameters($std, $possible);
4777
        $ipi = $this->dom->createElement('IPI');
4778
        $this->dom->addChild(
4779
            $ipi,
4780
            "clEnq",
4781
            $std->clEnq,
4782
            false,
4783
            "[item $std->item] Classe de enquadramento do IPI para Cigarros e Bebidas"
4784
        );
4785
        $this->dom->addChild(
4786
            $ipi,
4787
            "CNPJProd",
4788
            $std->CNPJProd,
4789
            false,
4790
            "[item $std->item] CNPJ do produtor da mercadoria, quando diferente do emitente. "
4791
            . "Somente para os casos de exportação direta ou indireta."
4792
        );
4793
        $this->dom->addChild(
4794
            $ipi,
4795
            "cSelo",
4796
            $std->cSelo,
4797
            false,
4798
            "[item $std->item] Código do selo de controle IPI"
4799
        );
4800
        $this->dom->addChild(
4801
            $ipi,
4802
            "qSelo",
4803
            $std->qSelo,
4804
            false,
4805
            "[item $std->item] Quantidade de selo de controle"
4806
        );
4807
        $this->dom->addChild(
4808
            $ipi,
4809
            "cEnq",
4810
            $std->cEnq,
4811
            true,
4812
            "[item $std->item] Código de Enquadramento Legal do IPI"
4813
        );
4814
        if ($std->CST == '00' || $std->CST == '49' || $std->CST == '50' || $std->CST == '99') {
4815
            //totalizador
4816
            $this->stdTot->vIPI += (float) $std->vIPI;
4817
            $ipiTrib = $this->dom->createElement('IPITrib');
4818
            $this->dom->addChild(
4819
                $ipiTrib,
4820
                "CST",
4821
                $std->CST,
4822
                true,
4823
                "[item $std->item] Código da situação tributária do IPI"
4824
            );
4825
            $this->dom->addChild(
4826
                $ipiTrib,
4827
                "vBC",
4828
                $this->conditionalNumberFormatting($std->vBC),
4829
                false,
4830
                "[item $std->item] Valor da BC do IPI"
4831
            );
4832
            $this->dom->addChild(
4833
                $ipiTrib,
4834
                "pIPI",
4835
                $this->conditionalNumberFormatting($std->pIPI, 4),
4836
                false,
4837
                "[item $std->item] Alíquota do IPI"
4838
            );
4839
            $this->dom->addChild(
4840
                $ipiTrib,
4841
                "qUnid",
4842
                $this->conditionalNumberFormatting($std->qUnid, 4),
4843
                false,
4844
                "[item $std->item] Quantidade total na unidade padrão para tributação (somente para os "
4845
                . "produtos tributados por unidade)"
4846
            );
4847
            $this->dom->addChild(
4848
                $ipiTrib,
4849
                "vUnid",
4850
                $this->conditionalNumberFormatting($std->vUnid, 4),
4851
                false,
4852
                "[item $std->item] Valor por Unidade Tributável"
4853
            );
4854
            $this->dom->addChild(
4855
                $ipiTrib,
4856
                "vIPI",
4857
                $this->conditionalNumberFormatting($std->vIPI),
4858
                true,
4859
                "[item $std->item] Valor do IPI"
4860
            );
4861
            $ipi->appendChild($ipiTrib);
4862
        } else {
4863
            $ipINT = $this->dom->createElement('IPINT');
4864
            $this->dom->addChild(
4865
                $ipINT,
4866
                "CST",
4867
                $std->CST,
4868
                true,
4869
                "[item $std->item] Código da situação tributária do IPINT"
4870
            );
4871
            $ipi->appendChild($ipINT);
4872
        }
4873
        $this->aIPI[$std->item] = $ipi;
4874
        return $ipi;
4875
    }
4876
4877
    /**
4878
     * Grupo Imposto de Importação P01 pai M01
4879
     * tag NFe/infNFe/det[]/imposto/II
4880
     * @param stdClass $std
4881
     * @return DOMElement
4882
     */
4883
    public function tagII(stdClass $std)
4884
    {
4885
        $possible = [
4886
            'item',
4887
            'vBC',
4888
            'vDespAdu',
4889
            'vII',
4890
            'vIOF'
4891
        ];
4892
        $std = $this->equilizeParameters($std, $possible);
4893
        //totalizador
4894
        $this->stdTot->vII += (float) $std->vII;
4895
        $tii = $this->dom->createElement('II');
4896
        $this->dom->addChild(
4897
            $tii,
4898
            "vBC",
4899
            $this->conditionalNumberFormatting($std->vBC),
4900
            true,
4901
            "[item $std->item] Valor BC do Imposto de Importação"
4902
        );
4903
        $this->dom->addChild(
4904
            $tii,
4905
            "vDespAdu",
4906
            $this->conditionalNumberFormatting($std->vDespAdu),
4907
            true,
4908
            "[item $std->item] Valor despesas aduaneiras"
4909
        );
4910
        $this->dom->addChild(
4911
            $tii,
4912
            "vII",
4913
            $this->conditionalNumberFormatting($std->vII),
4914
            true,
4915
            "[item $std->item] Valor Imposto de Importação"
4916
        );
4917
        $this->dom->addChild(
4918
            $tii,
4919
            "vIOF",
4920
            $this->conditionalNumberFormatting($std->vIOF),
4921
            true,
4922
            "[item $std->item] Valor Imposto sobre Operações Financeiras"
4923
        );
4924
        $this->aII[$std->item] = $tii;
4925
        return $tii;
4926
    }
4927
4928
    /**
4929
     * Grupo PIS Q01 pai M01
4930
     * tag NFe/infNFe/det[]/imposto/PIS
4931
     * @param stdClass $std
4932
     * @return DOMElement
4933
     */
4934
    public function tagPIS(stdClass $std)
4935
    {
4936
        $possible = [
4937
            'item',
4938
            'CST',
4939
            'vBC',
4940
            'pPIS',
4941
            'vPIS',
4942
            'qBCProd',
4943
            'vAliqProd'
4944
        ];
4945
        $std = $this->equilizeParameters($std, $possible);
4946
        
4947
        switch ($std->CST) {
4948
            case '01':
4949
            case '02':
4950
                $pisItem = $this->dom->createElement('PISAliq');
4951
                $this->dom->addChild(
4952
                    $pisItem,
4953
                    'CST',
4954
                    $std->CST,
4955
                    true,
4956
                    "[item $std->item] Código de Situação Tributária do PIS"
4957
                );
4958
                $this->dom->addChild(
4959
                    $pisItem,
4960
                    'vBC',
4961
                    $this->conditionalNumberFormatting($std->vBC),
4962
                    true,
4963
                    "[item $std->item] Valor da Base de Cálculo do PIS"
4964
                );
4965
                $this->dom->addChild(
4966
                    $pisItem,
4967
                    'pPIS',
4968
                    $this->conditionalNumberFormatting($std->pPIS, 4),
4969
                    true,
4970
                    "[item $std->item] Alíquota do PIS (em percentual)"
4971
                );
4972
                $this->dom->addChild(
4973
                    $pisItem,
4974
                    'vPIS',
4975
                    $this->conditionalNumberFormatting($std->vPIS),
4976
                    true,
4977
                    "[item $std->item] Valor do PIS"
4978
                );
4979
                //totalizador
4980
                $this->stdTot->vPIS += (float) !empty($std->vPIS) ? $std->vPIS : 0;
4981
                break;
4982
            case '03':
4983
                $pisItem = $this->dom->createElement('PISQtde');
4984
                $this->dom->addChild(
4985
                    $pisItem,
4986
                    'CST',
4987
                    $std->CST,
4988
                    true,
4989
                    "[item $std->item] Código de Situação Tributária do PIS"
4990
                );
4991
                $this->dom->addChild(
4992
                    $pisItem,
4993
                    'qBCProd',
4994
                    $this->conditionalNumberFormatting($std->qBCProd, 4),
4995
                    true,
4996
                    "[item $std->item] Quantidade Vendida"
4997
                );
4998
                $this->dom->addChild(
4999
                    $pisItem,
5000
                    'vAliqProd',
5001
                    $this->conditionalNumberFormatting($std->vAliqProd, 4),
5002
                    true,
5003
                    "[item $std->item] Alíquota do PIS (em reais)"
5004
                );
5005
                $this->dom->addChild(
5006
                    $pisItem,
5007
                    'vPIS',
5008
                    $this->conditionalNumberFormatting($std->vPIS),
5009
                    true,
5010
                    "[item $std->item] Valor do PIS"
5011
                );
5012
                //totalizador
5013
                $this->stdTot->vPIS += (float) !empty($std->vPIS) ? $std->vPIS : 0;
5014
                break;
5015
            case '04':
5016
            case '05':
5017
            case '06':
5018
            case '07':
5019
            case '08':
5020
            case '09':
5021
                $pisItem = $this->dom->createElement('PISNT');
5022
                $this->dom->addChild(
5023
                    $pisItem,
5024
                    'CST',
5025
                    $std->CST,
5026
                    true,
5027
                    "[item $std->item] Código de Situação Tributária do PIS"
5028
                );
5029
                break;
5030
            case '49':
5031
            case '50':
5032
            case '51':
5033
            case '52':
5034
            case '53':
5035
            case '54':
5036
            case '55':
5037
            case '56':
5038
            case '60':
5039
            case '61':
5040
            case '62':
5041
            case '63':
5042
            case '64':
5043
            case '65':
5044
            case '66':
5045
            case '67':
5046
            case '70':
5047
            case '71':
5048
            case '72':
5049
            case '73':
5050
            case '74':
5051
            case '75':
5052
            case '98':
5053
            case '99':
5054
                $pisItem = $this->dom->createElement('PISOutr');
5055
                $this->dom->addChild(
5056
                    $pisItem,
5057
                    'CST',
5058
                    $std->CST,
5059
                    true,
5060
                    "[item $std->item] Código de Situação Tributária do PIS"
5061
                );
5062
                $this->dom->addChild(
5063
                    $pisItem,
5064
                    'vBC',
5065
                    $this->conditionalNumberFormatting($std->vBC),
5066
                    ($std->vBC !== null) ? true : false,
5067
                    "[item $std->item] Valor da Base de Cálculo do PIS"
5068
                );
5069
                $this->dom->addChild(
5070
                    $pisItem,
5071
                    'pPIS',
5072
                    $this->conditionalNumberFormatting($std->pPIS, 4),
5073
                    ($std->pPIS !== null) ? true : false,
5074
                    "[item $std->item] Alíquota do PIS (em percentual)"
5075
                );
5076
                $this->dom->addChild(
5077
                    $pisItem,
5078
                    'qBCProd',
5079
                    $this->conditionalNumberFormatting($std->qBCProd, 4),
5080
                    ($std->qBCProd !== null) ? true : false,
5081
                    "[item $std->item] Quantidade Vendida"
5082
                );
5083
                $this->dom->addChild(
5084
                    $pisItem,
5085
                    'vAliqProd',
5086
                    $this->conditionalNumberFormatting($std->vAliqProd, 4),
5087
                    ($std->vAliqProd !== null) ? true : false,
5088
                    "[item $std->item] Alíquota do PIS (em reais)"
5089
                );
5090
                $this->dom->addChild(
5091
                    $pisItem,
5092
                    'vPIS',
5093
                    $this->conditionalNumberFormatting($std->vPIS),
5094
                    ($std->vPIS !== null) ? true : false,
5095
                    "[item $std->item] Valor do PIS"
5096
                );
5097
                //totalizador
5098
                $this->stdTot->vPIS += (float) !empty($std->vPIS) ? $std->vPIS : 0;
5099
                break;
5100
        }
5101
        $pis = $this->dom->createElement('PIS');
5102
        if (isset($pisItem)) {
5103
            $pis->appendChild($pisItem);
5104
        }
5105
        $this->aPIS[$std->item] = $pis;
5106
        return $pis;
5107
    }
5108
5109
    /**
5110
     * Grupo PIS Substituição Tributária R01 pai M01
5111
     * tag NFe/infNFe/det[]/imposto/PISST (opcional)
5112
     * @param stdClass $std
5113
     * @return DOMElement
5114
     */
5115
    public function tagPISST(stdClass $std)
5116
    {
5117
        $possible = [
5118
            'item',
5119
            'vPIS',
5120
            'vBC',
5121
            'pPIS',
5122
            'qBCProd',
5123
            'vAliqProd'
5124
        ];
5125
        $std = $this->equilizeParameters($std, $possible);
5126
        $pisst = $this->dom->createElement('PISST');
5127
        if (!isset($std->qBCProd)) {
5128
            $this->dom->addChild(
5129
                $pisst,
5130
                'vBC',
5131
                $this->conditionalNumberFormatting($std->vBC),
5132
                true,
5133
                "[item $std->item] Valor da Base de Cálculo do PIS"
5134
            );
5135
            $this->dom->addChild(
5136
                $pisst,
5137
                'pPIS',
5138
                $this->conditionalNumberFormatting($std->pPIS, 4),
5139
                true,
5140
                "[item $std->item] Alíquota do PIS (em percentual)"
5141
            );
5142
        } else {
5143
            $this->dom->addChild(
5144
                $pisst,
5145
                'qBCProd',
5146
                $this->conditionalNumberFormatting($std->qBCProd, 4),
5147
                true,
5148
                "[item $std->item] Quantidade Vendida"
5149
            );
5150
            $this->dom->addChild(
5151
                $pisst,
5152
                'vAliqProd',
5153
                $this->conditionalNumberFormatting($std->vAliqProd, 4),
5154
                true,
5155
                "[item $std->item] Alíquota do PIS (em reais)"
5156
            );
5157
        }
5158
        $this->dom->addChild(
5159
            $pisst,
5160
            'vPIS',
5161
            $this->conditionalNumberFormatting($std->vPIS),
5162
            true,
5163
            "[item $std->item] Valor do PIS"
5164
        );
5165
        $this->aPISST[$std->item] = $pisst;
5166
        return $pisst;
5167
    }
5168
5169
    /**
5170
     * Grupo COFINS S01 pai M01
5171
     * tag det[item]/imposto/COFINS (opcional)
5172
     * @param  stdClass $std
5173
     * @return DOMElement
5174
     */
5175
    public function tagCOFINS(stdClass $std)
5176
    {
5177
        $possible = [
5178
            'item',
5179
            'CST',
5180
            'vBC',
5181
            'pCOFINS',
5182
            'vCOFINS',
5183
            'qBCProd',
5184
            'vAliqProd'
5185
        ];
5186
        $std = $this->equilizeParameters($std, $possible);
5187
        switch ($std->CST) {
5188
            case '01':
5189
            case '02':
5190
                $confinsItem = $this->buildCOFINSAliq($std);
5191
                //totalizador
5192
                $this->stdTot->vCOFINS += (float) $std->vCOFINS;
5193
                break;
5194
            case '03':
5195
                $confinsItem = $this->dom->createElement('COFINSQtde');
5196
                $this->dom->addChild(
5197
                    $confinsItem,
5198
                    'CST',
5199
                    $std->CST,
5200
                    true,
5201
                    "[item $std->item] Código de Situação Tributária da COFINS"
5202
                );
5203
                $this->dom->addChild(
5204
                    $confinsItem,
5205
                    'qBCProd',
5206
                    $this->conditionalNumberFormatting($std->qBCProd, 4),
5207
                    true,
5208
                    "[item $std->item] Quantidade Vendida"
5209
                );
5210
                $this->dom->addChild(
5211
                    $confinsItem,
5212
                    'vAliqProd',
5213
                    $this->conditionalNumberFormatting($std->vAliqProd, 4),
5214
                    true,
5215
                    "[item $std->item] Alíquota do COFINS (em reais)"
5216
                );
5217
                $this->dom->addChild(
5218
                    $confinsItem,
5219
                    'vCOFINS',
5220
                    $this->conditionalNumberFormatting($std->vCOFINS),
5221
                    true,
5222
                    "[item $std->item] Valor do COFINS"
5223
                );
5224
                //totalizador
5225
                $this->stdTot->vCOFINS += (float) $std->vCOFINS;
5226
                break;
5227
            case '04':
5228
            case '05':
5229
            case '06':
5230
            case '07':
5231
            case '08':
5232
            case '09':
5233
                $confinsItem = $this->buildCOFINSNT($std);
5234
                break;
5235
            case '49':
5236
            case '50':
5237
            case '51':
5238
            case '52':
5239
            case '53':
5240
            case '54':
5241
            case '55':
5242
            case '56':
5243
            case '60':
5244
            case '61':
5245
            case '62':
5246
            case '63':
5247
            case '64':
5248
            case '65':
5249
            case '66':
5250
            case '67':
5251
            case '70':
5252
            case '71':
5253
            case '72':
5254
            case '73':
5255
            case '74':
5256
            case '75':
5257
            case '98':
5258
            case '99':
5259
                $confinsItem = $this->buildCOFINSoutr($std);
5260
                //totalizador
5261
                $this->stdTot->vCOFINS += (float) $std->vCOFINS;
5262
                break;
5263
        }
5264
        $confins = $this->dom->createElement('COFINS');
5265
        if (isset($confinsItem)) {
5266
            $confins->appendChild($confinsItem);
5267
        }
5268
        $this->aCOFINS[$std->item] = $confins;
5269
        return $confins;
5270
    }
5271
5272
    /**
5273
     * Grupo COFINS Substituição Tributária T01 pai M01
5274
     * tag NFe/infNFe/det[]/imposto/COFINSST (opcional)
5275
     * @param stdClass $std
5276
     * @return DOMElement
5277
     */
5278
    public function tagCOFINSST(stdClass $std)
5279
    {
5280
        $possible = [
5281
            'item',
5282
            'vCOFINS',
5283
            'vBC',
5284
            'pCOFINS',
5285
            'qBCProd',
5286
            'vAliqProd'
5287
        ];
5288
        $std = $this->equilizeParameters($std, $possible);
5289
        $cofinsst = $this->dom->createElement("COFINSST");
5290
        if (!isset($std->qBCProd)) {
5291
            $this->dom->addChild(
5292
                $cofinsst,
5293
                "vBC",
5294
                $this->conditionalNumberFormatting($std->vBC),
5295
                true,
5296
                "[item $std->item] Valor da Base de Cálculo da COFINS"
5297
            );
5298
            $this->dom->addChild(
5299
                $cofinsst,
5300
                "pCOFINS",
5301
                $this->conditionalNumberFormatting($std->pCOFINS, 4),
5302
                true,
5303
                "[item $std->item] Alíquota da COFINS (em percentual)"
5304
            );
5305
        } else {
5306
            $this->dom->addChild(
5307
                $cofinsst,
5308
                "qBCProd",
5309
                $this->conditionalNumberFormatting($std->qBCProd, 4),
5310
                true,
5311
                "[item $std->item] Quantidade Vendida"
5312
            );
5313
            $this->dom->addChild(
5314
                $cofinsst,
5315
                "vAliqProd",
5316
                $this->conditionalNumberFormatting($std->vAliqProd, 4),
5317
                true,
5318
                "[item $std->item] Alíquota da COFINS (em reais)"
5319
            );
5320
        }
5321
        $this->dom->addChild(
5322
            $cofinsst,
5323
            "vCOFINS",
5324
            $this->conditionalNumberFormatting($std->vCOFINS),
5325
            true,
5326
            "[item $std->item] Valor da COFINS"
5327
        );
5328
        $this->aCOFINSST[$std->item] = $cofinsst;
5329
        return $cofinsst;
5330
    }
5331
5332
    /**
5333
     * Grupo ISSQN U01 pai M01
5334
     * tag NFe/infNFe/det[]/imposto/ISSQN (opcional)
5335
     * @param stdClass $std
5336
     * @return DOMElement
5337
     */
5338
    public function tagISSQN(stdClass $std)
5339
    {
5340
        $possible = [
5341
            'item',
5342
            'vBC',
5343
            'vAliq',
5344
            'vISSQN',
5345
            'cMunFG',
5346
            'cListServ',
5347
            'vDeducao',
5348
            'vOutro',
5349
            'vDescIncond',
5350
            'vDescCond',
5351
            'vISSRet',
5352
            'indISS',
5353
            'cServico',
5354
            'cMun',
5355
            'cPais',
5356
            'nProcesso',
5357
            'indIncentivo'
5358
        ];
5359
        $std = $this->equilizeParameters($std, $possible);
5360
        $issqn = $this->dom->createElement("ISSQN");
5361
        $this->dom->addChild(
5362
            $issqn,
5363
            "vBC",
5364
            $this->conditionalNumberFormatting($std->vBC),
5365
            true,
5366
            "[item $std->item] Valor da Base de Cálculo do ISSQN"
5367
        );
5368
        $this->dom->addChild(
5369
            $issqn,
5370
            "vAliq",
5371
            $this->conditionalNumberFormatting($std->vAliq, 4),
5372
            true,
5373
            "[item $std->item] Alíquota do ISSQN"
5374
        );
5375
        $this->dom->addChild(
5376
            $issqn,
5377
            "vISSQN",
5378
            $this->conditionalNumberFormatting($std->vISSQN),
5379
            true,
5380
            "[item $std->item] Valor do ISSQN"
5381
        );
5382
        $this->dom->addChild(
5383
            $issqn,
5384
            "cMunFG",
5385
            $std->cMunFG,
5386
            true,
5387
            "[item $std->item] Código do município de ocorrência do fato gerador do ISSQN"
5388
        );
5389
        $this->dom->addChild(
5390
            $issqn,
5391
            "cListServ",
5392
            $std->cListServ,
5393
            true,
5394
            "[item $std->item] Item da Lista de Serviços"
5395
        );
5396
        $this->dom->addChild(
5397
            $issqn,
5398
            "vDeducao",
5399
            $this->conditionalNumberFormatting($std->vDeducao),
5400
            false,
5401
            "[item $std->item] Valor dedução para redução da Base de Cálculo"
5402
        );
5403
        $this->dom->addChild(
5404
            $issqn,
5405
            "vOutro",
5406
            $this->conditionalNumberFormatting($std->vOutro),
5407
            false,
5408
            "[item $std->item] Valor outras retenções"
5409
        );
5410
        $this->dom->addChild(
5411
            $issqn,
5412
            "vDescIncond",
5413
            $this->conditionalNumberFormatting($std->vDescIncond),
5414
            false,
5415
            "[item $std->item] Valor desconto incondicionado"
5416
        );
5417
        $this->dom->addChild(
5418
            $issqn,
5419
            "vDescCond",
5420
            $this->conditionalNumberFormatting($std->vDescCond),
5421
            false,
5422
            "[item $std->item] Valor desconto condicionado"
5423
        );
5424
        $this->dom->addChild(
5425
            $issqn,
5426
            "vISSRet",
5427
            $this->conditionalNumberFormatting($std->vISSRet),
5428
            false,
5429
            "[item $std->item] Valor retenção ISS"
5430
        );
5431
        $this->dom->addChild(
5432
            $issqn,
5433
            "indISS",
5434
            $std->indISS,
5435
            true,
5436
            "[item $std->item] Indicador da exigibilidade do ISS"
5437
        );
5438
        $this->dom->addChild(
5439
            $issqn,
5440
            "cServico",
5441
            $std->cServico,
5442
            false,
5443
            "[item $std->item] Código do serviço prestado dentro do município"
5444
        );
5445
        $this->dom->addChild(
5446
            $issqn,
5447
            "cMun",
5448
            $std->cMun,
5449
            false,
5450
            "[item $std->item] Código do Município de incidência do imposto"
5451
        );
5452
        $this->dom->addChild(
5453
            $issqn,
5454
            "cPais",
5455
            $std->cPais,
5456
            false,
5457
            "[item $std->item] Código do País onde o serviço foi prestado"
5458
        );
5459
        $this->dom->addChild(
5460
            $issqn,
5461
            "nProcesso",
5462
            $std->nProcesso,
5463
            false,
5464
            "[item $std->item] Número do processo judicial ou administrativo de suspensão da exigibilidade"
5465
        );
5466
        $this->dom->addChild(
5467
            $issqn,
5468
            "indIncentivo",
5469
            $std->indIncentivo,
5470
            true,
5471
            "[item $std->item] Indicador de incentivo Fiscal"
5472
        );
5473
        $this->aISSQN[$std->item] = $issqn;
5474
        return $issqn;
5475
    }
5476
5477
    /**
5478
     * Informação do Imposto devolvido U50 pai H01
5479
     * tag NFe/infNFe/det[]/impostoDevol (opcional)
5480
     * @param stdClass $std
5481
     * @return DOMElement
5482
     */
5483
    public function tagimpostoDevol(stdClass $std)
5484
    {
5485
        $possible = [
5486
            'item',
5487
            'pDevol',
5488
            'vIPIDevol'
5489
        ];
5490
        $std = $this->equilizeParameters($std, $possible);
5491
        //totalizador
5492
        $this->stdTot->vIPIDevol += (float) $std->vIPIDevol;
5493
        $impostoDevol = $this->dom->createElement("impostoDevol");
5494
        $this->dom->addChild(
5495
            $impostoDevol,
5496
            "pDevol",
5497
            $this->conditionalNumberFormatting($std->pDevol, 2),
5498
            true,
5499
            "[item $std->item] Percentual da mercadoria devolvida"
5500
        );
5501
        $parent = $this->dom->createElement("IPI");
5502
        $this->dom->addChild(
5503
            $parent,
5504
            "vIPIDevol",
5505
            $this->conditionalNumberFormatting($std->vIPIDevol),
5506
            true,
5507
            "[item $std->item] Valor do IPI devolvido"
5508
        );
5509
        $impostoDevol->appendChild($parent);
5510
        $this->aImpostoDevol[$std->item] = $impostoDevol;
5511
        return $impostoDevol;
5512
    }
5513
5514
    /**
5515
     * Grupo Totais referentes ao ICMS W02 pai W01
5516
     * tag NFe/infNFe/total/ICMSTot
5517
     * @param stdClass $std
5518
     * @return DOMElement
5519
     */
5520
    public function tagICMSTot(stdClass $std)
5521
    {
5522
        $this->buildTotal();
5523
        $vBC = isset($std->vBC) ? $std->vBC : $this->stdTot->vBC;
5524
        $vICMS = isset($std->vICMS) ? $std->vICMS : $this->stdTot->vICMS;
5525
        $vICMSDeson = !empty($std->vICMSDeson) ? $std->vICMSDeson : $this->stdTot->vICMSDeson;
5526
        $vBCST = !empty($std->vBCST) ? $std->vBCST : $this->stdTot->vBCST;
5527
        $vST = !empty($std->vST) ? $std->vST : $this->stdTot->vST;
5528
        $vProd = !empty($std->vProd) ? $std->vProd : $this->stdTot->vProd;
5529
        $vFrete = !empty($std->vFrete) ? $std->vFrete : $this->stdTot->vFrete;
5530
        $vSeg = !empty($std->vSeg) ? $std->vSeg : $this->stdTot->vSeg;
5531
        $vDesc = !empty($std->vDesc) ? $std->vDesc : $this->stdTot->vDesc;
5532
        $vII = !empty($std->vII) ? $std->vII : $this->stdTot->vII;
5533
        $vIPI = !empty($std->vIPI) ? $std->vIPI : $this->stdTot->vIPI;
5534
        $vPIS = !empty($std->vPIS) ? $std->vPIS : $this->stdTot->vPIS;
5535
        $vCOFINS = !empty($std->vCOFINS) ? $std->vCOFINS : $this->stdTot->vCOFINS;
5536
        $vOutro = !empty($std->vOutro) ? $std->vOutro : $this->stdTot->vOutro;
5537
        $vNF = !empty($std->vNF) ? $std->vNF : $this->stdTot->vNF;
5538
        $vIPIDevol = !empty($std->vIPIDevol) ? $std->vIPIDevol : $this->stdTot->vIPIDevol;
5539
        $vTotTrib = !empty($std->vTotTrib) ? $std->vTotTrib : $this->stdTot->vTotTrib;
5540
        $vFCP = !empty($std->vFCP) ? $std->vFCP : $this->stdTot->vFCP;
5541
        $vFCPST = !empty($std->vFCPST) ? $std->vFCPST : $this->stdTot->vFCPST;
5542
        $vFCPSTRet = !empty($std->vFCPSTRet) ? $std->vFCPSTRet : $this->stdTot->vFCPSTRet;
5543
        $vFCPUFDest = !empty($std->vFCPUFDest) ? $std->vFCPUFDest : $this->stdTot->vFCPUFDest;
5544
        $vICMSUFDest = !empty($std->vICMSUFDest) ? $std->vICMSUFDest : $this->stdTot->vICMSUFDest;
5545
        $vICMSUFRemet = !empty($std->vICMSUFRemet) ? $std->vICMSUFRemet : $this->stdTot->vICMSUFRemet;
5546
5547
        //campos opcionais incluir se maior que zero
5548
        $vFCPUFDest = ($vFCPUFDest > 0) ? number_format($vFCPUFDest, 2, '.', '') : null;
5549
        $vICMSUFDest = ($vICMSUFDest > 0) ? number_format($vICMSUFDest, 2, '.', '') : null;
5550
        $vICMSUFRemet = ($vICMSUFRemet > 0) ? number_format($vICMSUFRemet, 2, '.', '') : null;
5551
        $vTotTrib = ($vTotTrib > 0) ? number_format($vTotTrib, 2, '.', '') : null;
5552
5553
        //campos obrigatórios para 4.00
5554
        $vFCP = number_format($vFCP, 2, '.', '');
5555
        $vFCPST = number_format($vFCPST, 2, '.', '');
5556
        $vFCPSTRet = number_format($vFCPSTRet, 2, '.', '');
5557
        $vIPIDevol = number_format($vIPIDevol, 2, '.', '');
5558
5559
        $ICMSTot = $this->dom->createElement("ICMSTot");
5560
        $this->dom->addChild(
5561
            $ICMSTot,
5562
            "vBC",
5563
            $this->conditionalNumberFormatting($vBC),
5564
            true,
5565
            "Base de Cálculo do ICMS"
5566
        );
5567
        $this->dom->addChild(
5568
            $ICMSTot,
5569
            "vICMS",
5570
            $this->conditionalNumberFormatting($vICMS),
5571
            true,
5572
            "Valor Total do ICMS"
5573
        );
5574
        $this->dom->addChild(
5575
            $ICMSTot,
5576
            "vICMSDeson",
5577
            $this->conditionalNumberFormatting($vICMSDeson),
5578
            true,
5579
            "Valor Total do ICMS desonerado"
5580
        );
5581
        $this->dom->addChild(
5582
            $ICMSTot,
5583
            "vFCPUFDest",
5584
            $this->conditionalNumberFormatting($vFCPUFDest),
5585
            false,
5586
            "Valor total do ICMS relativo ao Fundo de Combate à Pobreza(FCP) "
5587
            . "para a UF de destino"
5588
        );
5589
        $this->dom->addChild(
5590
            $ICMSTot,
5591
            "vICMSUFDest",
5592
            $this->conditionalNumberFormatting($vICMSUFDest),
5593
            false,
5594
            "Valor total do ICMS de partilha para a UF do destinatário"
5595
        );
5596
        $this->dom->addChild(
5597
            $ICMSTot,
5598
            "vICMSUFRemet",
5599
            $this->conditionalNumberFormatting($vICMSUFRemet),
5600
            false,
5601
            "Valor total do ICMS de partilha para a UF do remetente"
5602
        );
5603
        //incluso no layout 4.00
5604
        $this->dom->addChild(
5605
            $ICMSTot,
5606
            "vFCP",
5607
            $this->conditionalNumberFormatting($vFCP),
5608
            false,
5609
            "Valor total do ICMS relativo ao Fundo de Combate à Pobreza(FCP) "
5610
            . "para a UF de destino"
5611
        );
5612
        $this->dom->addChild(
5613
            $ICMSTot,
5614
            "vBCST",
5615
            $this->conditionalNumberFormatting($vBCST),
5616
            true,
5617
            "Base de Cálculo do ICMS ST"
5618
        );
5619
        $this->dom->addChild(
5620
            $ICMSTot,
5621
            "vST",
5622
            $this->conditionalNumberFormatting($vST),
5623
            true,
5624
            "Valor Total do ICMS ST"
5625
        );
5626
        //incluso na 4.00
5627
        $this->dom->addChild(
5628
            $ICMSTot,
5629
            "vFCPST",
5630
            $this->conditionalNumberFormatting($vFCPST),
5631
            false, //true para 4.00
5632
            "Valor Total do FCP (Fundo de Combate à Pobreza) "
5633
            . "retido por substituição tributária"
5634
        );
5635
        //incluso na 4.00
5636
        $this->dom->addChild(
5637
            $ICMSTot,
5638
            "vFCPSTRet",
5639
            $this->conditionalNumberFormatting($vFCPSTRet),
5640
            false, //true para 4.00
5641
            "Valor Total do FCP retido anteriormente por "
5642
            . "Substituição Tributária"
5643
        );
5644
        $this->dom->addChild(
5645
            $ICMSTot,
5646
            "vProd",
5647
            $this->conditionalNumberFormatting($vProd),
5648
            true,
5649
            "Valor Total dos produtos e serviços"
5650
        );
5651
        $this->dom->addChild(
5652
            $ICMSTot,
5653
            "vFrete",
5654
            $this->conditionalNumberFormatting($vFrete),
5655
            true,
5656
            "Valor Total do Frete"
5657
        );
5658
        $this->dom->addChild(
5659
            $ICMSTot,
5660
            "vSeg",
5661
            $this->conditionalNumberFormatting($vSeg),
5662
            true,
5663
            "Valor Total do Seguro"
5664
        );
5665
        $this->dom->addChild(
5666
            $ICMSTot,
5667
            "vDesc",
5668
            $this->conditionalNumberFormatting($vDesc),
5669
            true,
5670
            "Valor Total do Desconto"
5671
        );
5672
        $this->dom->addChild(
5673
            $ICMSTot,
5674
            "vII",
5675
            $this->conditionalNumberFormatting($vII),
5676
            true,
5677
            "Valor Total do II"
5678
        );
5679
        $this->dom->addChild(
5680
            $ICMSTot,
5681
            "vIPI",
5682
            $this->conditionalNumberFormatting($vIPI),
5683
            true,
5684
            "Valor Total do IPI"
5685
        );
5686
        //incluso 4.00
5687
        $this->dom->addChild(
5688
            $ICMSTot,
5689
            "vIPIDevol",
5690
            $this->conditionalNumberFormatting($vIPIDevol),
5691
            false,
5692
            "Valor Total do IPI"
5693
        );
5694
        $this->dom->addChild(
5695
            $ICMSTot,
5696
            "vPIS",
5697
            $this->conditionalNumberFormatting($vPIS),
5698
            true,
5699
            "Valor do PIS"
5700
        );
5701
        $this->dom->addChild(
5702
            $ICMSTot,
5703
            "vCOFINS",
5704
            $this->conditionalNumberFormatting($vCOFINS),
5705
            true,
5706
            "Valor da COFINS"
5707
        );
5708
        $this->dom->addChild(
5709
            $ICMSTot,
5710
            "vOutro",
5711
            $this->conditionalNumberFormatting($vOutro),
5712
            true,
5713
            "Outras Despesas acessórias"
5714
        );
5715
        $this->dom->addChild(
5716
            $ICMSTot,
5717
            "vNF",
5718
            $this->conditionalNumberFormatting($vNF),
5719
            true,
5720
            "Valor Total da NF-e"
5721
        );
5722
        $this->dom->addChild(
5723
            $ICMSTot,
5724
            "vTotTrib",
5725
            $this->conditionalNumberFormatting($vTotTrib),
5726
            false,
5727
            "Valor aproximado total de tributos federais, estaduais e municipais."
5728
        );
5729
        $this->dom->appChild($this->total, $ICMSTot, '');
5730
        return $ICMSTot;
5731
    }
5732
5733
    /**
5734
     * Grupo Totais referentes ao ISSQN W17 pai W01
5735
     * tag NFe/infNFe/total/ISSQNTot (opcional)
5736
     * @param stdClass $std
5737
     * @return DOMElement
5738
     */
5739
    public function tagISSQNTot(stdClass $std)
5740
    {
5741
        $possible = [
5742
            'vServ',
5743
            'vBC',
5744
            'vISS',
5745
            'vPIS',
5746
            'vCOFINS',
5747
            'dCompet',
5748
            'vDeducao',
5749
            'vOutro',
5750
            'vDescIncond',
5751
            'vDescCond',
5752
            'vISSRet',
5753
            'cRegTrib'
5754
        ];
5755
        $std = $this->equilizeParameters($std, $possible);
5756
        $this->buildTotal();
5757
        $ISSQNTot = $this->dom->createElement("ISSQNtot");
5758
        $this->dom->addChild(
5759
            $ISSQNTot,
5760
            "vServ",
5761
            $this->conditionalNumberFormatting($std->vServ),
5762
            false,
5763
            "Valor total dos Serviços sob não incidência ou não tributados pelo ICMS"
5764
        );
5765
        $this->dom->addChild(
5766
            $ISSQNTot,
5767
            "vBC",
5768
            $this->conditionalNumberFormatting($std->vBC),
5769
            false,
5770
            "Valor total Base de Cálculo do ISS"
5771
        );
5772
        $this->dom->addChild(
5773
            $ISSQNTot,
5774
            "vISS",
5775
            $this->conditionalNumberFormatting($std->vISS),
5776
            false,
5777
            "Valor total do ISS"
5778
        );
5779
        $this->dom->addChild(
5780
            $ISSQNTot,
5781
            "vPIS",
5782
            $this->conditionalNumberFormatting($std->vPIS),
5783
            false,
5784
            "Valor total do PIS sobre serviços"
5785
        );
5786
        $this->dom->addChild(
5787
            $ISSQNTot,
5788
            "vCOFINS",
5789
            $this->conditionalNumberFormatting($std->vCOFINS),
5790
            false,
5791
            "Valor total da COFINS sobre serviços"
5792
        );
5793
        $this->dom->addChild(
5794
            $ISSQNTot,
5795
            "dCompet",
5796
            $std->dCompet,
5797
            true,
5798
            "Data da prestação do serviço"
5799
        );
5800
        $this->dom->addChild(
5801
            $ISSQNTot,
5802
            "vDeducao",
5803
            $this->conditionalNumberFormatting($std->vDeducao),
5804
            false,
5805
            "Valor total dedução para redução da Base de Cálculo"
5806
        );
5807
        $this->dom->addChild(
5808
            $ISSQNTot,
5809
            "vOutro",
5810
            $this->conditionalNumberFormatting($std->vOutro),
5811
            false,
5812
            "Valor total outras retenções"
5813
        );
5814
        $this->dom->addChild(
5815
            $ISSQNTot,
5816
            "vDescIncond",
5817
            $this->conditionalNumberFormatting($std->vDescIncond),
5818
            false,
5819
            "Valor total desconto incondicionado"
5820
        );
5821
        $this->dom->addChild(
5822
            $ISSQNTot,
5823
            "vDescCond",
5824
            $this->conditionalNumberFormatting($std->vDescCond),
5825
            false,
5826
            "Valor total desconto condicionado"
5827
        );
5828
        $this->dom->addChild(
5829
            $ISSQNTot,
5830
            "vISSRet",
5831
            $this->conditionalNumberFormatting($std->vISSRet),
5832
            false,
5833
            "Valor total retenção ISS"
5834
        );
5835
        $this->dom->addChild(
5836
            $ISSQNTot,
5837
            "cRegTrib",
5838
            $std->cRegTrib,
5839
            false,
5840
            "Código do Regime Especial de Tributação"
5841
        );
5842
        $this->dom->appChild($this->total, $ISSQNTot, '');
5843
        return $ISSQNTot;
5844
    }
5845
5846
    /**
5847
     * Grupo Retenções de Tributos W23 pai W01
5848
     * tag NFe/infNFe/total/reTrib (opcional)
5849
     * @param stdClass $std
5850
     * @return DOMElement
5851
     */
5852
    public function tagretTrib(stdClass $std)
5853
    {
5854
        $possible = [
5855
            'vRetPIS',
5856
            'vRetCOFINS',
5857
            'vRetCSLL',
5858
            'vBCIRRF',
5859
            'vIRRF',
5860
            'vBCRetPrev',
5861
            'vRetPrev'
5862
        ];
5863
        $std = $this->equilizeParameters($std, $possible);
5864
        $retTrib = $this->dom->createElement("retTrib");
5865
        $this->dom->addChild(
5866
            $retTrib,
5867
            "vRetPIS",
5868
            $this->conditionalNumberFormatting($std->vRetPIS),
5869
            false,
5870
            "Valor Retido de PIS"
5871
        );
5872
        $this->dom->addChild(
5873
            $retTrib,
5874
            "vRetCOFINS",
5875
            $this->conditionalNumberFormatting($std->vRetCOFINS),
5876
            false,
5877
            "Valor Retido de COFINS"
5878
        );
5879
        $this->dom->addChild(
5880
            $retTrib,
5881
            "vRetCSLL",
5882
            $this->conditionalNumberFormatting($std->vRetCSLL),
5883
            false,
5884
            "Valor Retido de CSLL"
5885
        );
5886
        $this->dom->addChild(
5887
            $retTrib,
5888
            "vBCIRRF",
5889
            $this->conditionalNumberFormatting($std->vBCIRRF),
5890
            false,
5891
            "Base de Cálculo do IRRF"
5892
        );
5893
        $this->dom->addChild(
5894
            $retTrib,
5895
            "vIRRF",
5896
            $this->conditionalNumberFormatting($std->vIRRF),
5897
            false,
5898
            "Valor Retido do IRRF"
5899
        );
5900
        $this->dom->addChild(
5901
            $retTrib,
5902
            "vBCRetPrev",
5903
            $this->conditionalNumberFormatting($std->vBCRetPrev),
5904
            false,
5905
            "Base de Cálculo da Retenção da Previdência Social"
5906
        );
5907
        $this->dom->addChild(
5908
            $retTrib,
5909
            "vRetPrev",
5910
            $this->conditionalNumberFormatting($std->vRetPrev),
5911
            false,
5912
            "Valor da Retenção da Previdência Social"
5913
        );
5914
        $this->dom->appChild($this->total, $retTrib, '');
5915
        return $retTrib;
5916
    }
5917
5918
    /**
5919
     * Grupo Informações do Transporte X01 pai A01
5920
     * tag NFe/infNFe/transp (obrigatório)
5921
     * @param stdClass $std
5922
     * @return DOMElement
5923
     */
5924
    public function tagtransp(stdClass $std)
5925
    {
5926
        $this->transp = $this->dom->createElement("transp");
5927
        $this->dom->addChild(
5928
            $this->transp,
5929
            "modFrete",
5930
            $std->modFrete,
5931
            true,
5932
            "Modalidade do frete"
5933
        );
5934
        return $this->transp;
5935
    }
5936
5937
    /**
5938
     * Grupo Transportador X03 pai X01
5939
     * tag NFe/infNFe/transp/tranporta (opcional)
5940
     * @param stdClass $std
5941
     * @return DOMElement
5942
     */
5943
    public function tagtransporta(stdClass $std)
5944
    {
5945
        $possible = [
5946
            'xNome',
5947
            'IE',
5948
            'xEnder',
5949
            'xMun',
5950
            'UF',
5951
            'CNPJ',
5952
            'CPF'
5953
        ];
5954
        $std = $this->equilizeParameters($std, $possible);
5955
        $transporta = $this->dom->createElement("transporta");
5956
        $this->dom->addChild(
5957
            $transporta,
5958
            "CNPJ",
5959
            $std->CNPJ,
5960
            false,
5961
            "CNPJ do Transportador"
5962
        );
5963
        $this->dom->addChild(
5964
            $transporta,
5965
            "CPF",
5966
            $std->CPF,
5967
            false,
5968
            "CPF do Transportador"
5969
        );
5970
        $this->dom->addChild(
5971
            $transporta,
5972
            "xNome",
5973
            $std->xNome,
5974
            false,
5975
            "Razão Social ou nome do Transportador"
5976
        );
5977
        $this->dom->addChild(
5978
            $transporta,
5979
            "IE",
5980
            $std->IE,
5981
            false,
5982
            "Inscrição Estadual do Transportador"
5983
        );
5984
        $this->dom->addChild(
5985
            $transporta,
5986
            "xEnder",
5987
            $std->xEnder,
5988
            false,
5989
            "Endereço Completo do Transportador"
5990
        );
5991
        $this->dom->addChild(
5992
            $transporta,
5993
            "xMun",
5994
            $std->xMun,
5995
            false,
5996
            "Nome do município do Transportador"
5997
        );
5998
        $this->dom->addChild(
5999
            $transporta,
6000
            "UF",
6001
            $std->UF,
6002
            false,
6003
            "Sigla da UF do Transportador"
6004
        );
6005
        $this->dom->appChild(
6006
            $this->transp,
6007
            $transporta,
6008
            'A tag transp deveria ter sido carregada primeiro.'
6009
        );
6010
        $this->dom->appChild($this->transp, $transporta, "Inclusão do node vol");
6011
        return $transporta;
6012
    }
6013
6014
    /**
6015
     * Grupo Retenção ICMS transporte X11 pai X01
6016
     * tag NFe/infNFe/transp/retTransp (opcional)
6017
     * @param stdClass $std
6018
     * @return DOMElement
6019
     */
6020
    public function tagretTransp(stdClass $std)
6021
    {
6022
        $possible = [
6023
            'vServ',
6024
            'vBCRet',
6025
            'pICMSRet',
6026
            'vICMSRet',
6027
            'CFOP',
6028
            'cMunFG'
6029
        ];
6030
        $std = $this->equilizeParameters($std, $possible);
6031
        $retTransp = $this->dom->createElement("retTransp");
6032
        $this->dom->addChild(
6033
            $retTransp,
6034
            "vServ",
6035
            $this->conditionalNumberFormatting($std->vServ),
6036
            true,
6037
            "Valor do Serviço"
6038
        );
6039
        $this->dom->addChild(
6040
            $retTransp,
6041
            "vBCRet",
6042
            $this->conditionalNumberFormatting($std->vBCRet),
6043
            true,
6044
            "BC da Retenção do ICMS"
6045
        );
6046
        $this->dom->addChild(
6047
            $retTransp,
6048
            "pICMSRet",
6049
            $this->conditionalNumberFormatting($std->pICMSRet, 4),
6050
            true,
6051
            "Alíquota da Retenção"
6052
        );
6053
        $this->dom->addChild(
6054
            $retTransp,
6055
            "vICMSRet",
6056
            $this->conditionalNumberFormatting($std->vICMSRet),
6057
            true,
6058
            "Valor do ICMS Retido"
6059
        );
6060
        $this->dom->addChild(
6061
            $retTransp,
6062
            "CFOP",
6063
            $std->CFOP,
6064
            true,
6065
            "CFOP"
6066
        );
6067
        $this->dom->addChild(
6068
            $retTransp,
6069
            "cMunFG",
6070
            $std->cMunFG,
6071
            true,
6072
            "Código do município de ocorrência do fato gerador do ICMS do transporte"
6073
        );
6074
        $this->dom->appChild(
6075
            $this->transp,
6076
            $retTransp,
6077
            'A tag transp deveria ter sido carregada primeiro.'
6078
        );
6079
        return $retTransp;
6080
    }
6081
6082
    /**
6083
     * Grupo Veículo Transporte X18 pai X17.1
6084
     * tag NFe/infNFe/transp/veicTransp (opcional)
6085
     * @param stdClass $std
6086
     * @return DOMElement
6087
     */
6088
    public function tagveicTransp(stdClass $std)
6089
    {
6090
        $possible = [
6091
            'placa',
6092
            'UF',
6093
            'RNTC'
6094
        ];
6095
        $std = $this->equilizeParameters($std, $possible);
6096
        $veicTransp = $this->dom->createElement("veicTransp");
6097
        $this->dom->addChild(
6098
            $veicTransp,
6099
            "placa",
6100
            $std->placa,
6101
            true,
6102
            "Placa do Veículo"
6103
        );
6104
        $this->dom->addChild(
6105
            $veicTransp,
6106
            "UF",
6107
            $std->UF,
6108
            true,
6109
            "Sigla da UF do Veículo"
6110
        );
6111
        $this->dom->addChild(
6112
            $veicTransp,
6113
            "RNTC",
6114
            $std->RNTC,
6115
            false,
6116
            "Registro Nacional de Transportador de Carga (ANTT) do Veículo"
6117
        );
6118
        $this->dom->appChild(
6119
            $this->transp,
6120
            $veicTransp,
6121
            'A tag transp deveria ter sido carregada primeiro.'
6122
        );
6123
        return $veicTransp;
6124
    }
6125
6126
    /**
6127
     * Grupo Reboque X22 pai X17.1
6128
     * tag NFe/infNFe/transp/reboque (opcional)
6129
     * @param stdClass $std
6130
     * @return DOMElement
6131
     */
6132
    public function tagreboque(stdClass $std)
6133
    {
6134
        $possible = [
6135
            'placa',
6136
            'UF',
6137
            'RNTC'
6138
        ];
6139
        $std = $this->equilizeParameters($std, $possible);
6140
        $reboque = $this->dom->createElement("reboque");
6141
        $this->dom->addChild(
6142
            $reboque,
6143
            "placa",
6144
            $std->placa,
6145
            true,
6146
            "Placa do Veículo Reboque"
6147
        );
6148
        $this->dom->addChild(
6149
            $reboque,
6150
            "UF",
6151
            $std->UF,
6152
            true,
6153
            "Sigla da UF do Veículo Reboque"
6154
        );
6155
        $this->dom->addChild(
6156
            $reboque,
6157
            "RNTC",
6158
            $std->RNTC,
6159
            false,
6160
            "Registro Nacional de Transportador de Carga (ANTT) do Veículo Reboque"
6161
        );
6162
        $this->dom->appChild(
6163
            $this->transp,
6164
            $reboque,
6165
            'A tag transp deveria ter sido carregada primeiro.'
6166
        );
6167
        return $reboque;
6168
    }
6169
6170
    /**
6171
     * Campo Vagao X25a pai X01
6172
     * tag NFe/infNFe/transp/vagao (opcional)
6173
     * @param stdClass $std
6174
     */
6175
    public function tagvagao(stdClass $std)
6176
    {
6177
        $possible = [
6178
            'vagao'
6179
        ];
6180
        $std = $this->equilizeParameters($std, $possible);
6181
        $this->dom->addChild(
6182
            $this->transp,
6183
            "vagao",
6184
            $std->vagao,
6185
            false,
6186
            "Identificação do vagão do Veículo Reboque"
6187
        );
6188
    }
6189
6190
    /**
6191
     * Campo Balsa X25b pai X01
6192
     * tag NFe/infNFe/transp/balsa (opcional)
6193
     * @param stdClass $std
6194
     */
6195
    public function tagbalsa(stdClass $std)
6196
    {
6197
        $possible = [
6198
            'balsa'
6199
        ];
6200
        $std = $this->equilizeParameters($std, $possible);
6201
        $this->dom->addChild(
6202
            $this->transp,
6203
            "balsa",
6204
            $std->balsa,
6205
            false,
6206
            "Identificação da balsa do Veículo Reboque"
6207
        );
6208
    }
6209
6210
    /**
6211
     * Grupo Volumes X26 pai X01
6212
     * tag NFe/infNFe/transp/vol (opcional)
6213
     * @param  stdClass $std
6214
     * @return DOMElement
6215
     */
6216
    public function tagvol(stdClass $std)
6217
    {
6218
        $possible = [
6219
            'item',
6220
            'qVol',
6221
            'esp',
6222
            'marca',
6223
            'nVol',
6224
            'pesoL',
6225
            'pesoB'
6226
        ];
6227
        $std = $this->equilizeParameters($std, $possible);
6228
        $vol = $this->dom->createElement("vol");
6229
        $this->dom->addChild(
6230
            $vol,
6231
            "qVol",
6232
            $this->conditionalNumberFormatting($std->qVol, 0),
6233
            false,
6234
            "Quantidade de volumes transportados"
6235
        );
6236
        $this->dom->addChild(
6237
            $vol,
6238
            "esp",
6239
            $std->esp,
6240
            false,
6241
            "Espécie dos volumes transportados"
6242
        );
6243
        $this->dom->addChild(
6244
            $vol,
6245
            "marca",
6246
            $std->marca,
6247
            false,
6248
            "Marca dos volumes transportados"
6249
        );
6250
        $this->dom->addChild(
6251
            $vol,
6252
            "nVol",
6253
            $std->nVol,
6254
            false,
6255
            "Numeração dos volumes transportados"
6256
        );
6257
        $this->dom->addChild(
6258
            $vol,
6259
            "pesoL",
6260
            $this->conditionalNumberFormatting($std->pesoL, 3),
6261
            false,
6262
            "Peso Líquido (em kg) dos volumes transportados"
6263
        );
6264
        $this->dom->addChild(
6265
            $vol,
6266
            "pesoB",
6267
            $this->conditionalNumberFormatting($std->pesoB, 3),
6268
            false,
6269
            "Peso Bruto (em kg) dos volumes transportados"
6270
        );
6271
        $this->aVol[$std->item] = $vol;
6272
        return $vol;
6273
    }
6274
6275
    /**
6276
     * Grupo Lacres X33 pai X26
6277
     * tag NFe/infNFe/transp/vol/lacres (opcional)
6278
     * @param stdClass $std
6279
     * @return DOMElement
6280
     */
6281
    public function taglacres(stdClass $std)
6282
    {
6283
        $lacre = $this->dom->createElement("lacres");
6284
        $this->dom->addChild(
6285
            $lacre,
6286
            "nLacre",
6287
            $std->nLacre,
6288
            true,
6289
            "Número dos Lacres"
6290
        );
6291
        $this->dom->appChild($this->aVol[$std->item], $lacre, "Inclusão do node lacres");
6292
        return $lacre;
6293
    }
6294
6295
    /**
6296
     * Node vol
6297
     */
6298
    protected function buildVol()
6299
    {
6300
        foreach ($this->aVol as $num => $vol) {
6301
            $this->dom->appChild($this->transp, $vol, "Inclusão do node vol");
6302
        }
6303
    }
6304
6305
    /**
6306
     * Grupo Pagamento Y pai A01
6307
     * NOTA: Ajustado para NT2016_002_v1.30
6308
     * tag NFe/infNFe/pag (obrigatorio na NT2016_002_v1.30)
6309
     * Obrigatório para 55 e 65
6310
     * @param stdClass $std
6311
     * @return DOMElement
6312
     */
6313
    public function tagpag($std)
6314
    {
6315
        $possible = [
6316
            'vTroco'
6317
        ];
6318
        $std = $this->equilizeParameters($std, $possible);
6319
        $pag = $this->dom->createElement("pag");
6320
        //incluso no layout 4.00
6321
        $this->dom->addChild(
6322
            $pag,
6323
            "vTroco",
6324
            $this->conditionalNumberFormatting($std->vTroco),
6325
            false,
6326
            "Valor do troco"
6327
        );
6328
        return $this->pag = $pag;
6329
    }
6330
6331
    /**
6332
     * Grupo de Formas de Pagamento YA01a pai YA01
6333
     * NOTA: Ajuste NT_2016_002_v1.30
6334
     * NOTA: Ajuste NT_2016_002_v1 51
6335
     * NOTA: Ajuste NT_2020_006
6336
     * tag NFe/infNFe/pag/detPag
6337
     * @param stdClass $std
6338
     * @return DOMElement
6339
     */
6340
    public function tagdetPag($std)
6341
    {
6342
        $possible = [
6343
            'indPag',
6344
            'tPag',
6345
            'xPag',
6346
            'vPag',
6347
            'CNPJ',
6348
            'tBand',
6349
            'cAut',
6350
            'tpIntegra'
6351
        ];
6352
        $std = $this->equilizeParameters($std, $possible);
6353
        //padrão para layout 4.00
6354
        $detPag = $this->dom->createElement("detPag");
6355
        $this->dom->addChild(
6356
            $detPag,
6357
            "indPag",
6358
            $std->indPag,
6359
            false,
6360
            "Indicador da Forma de Pagamento"
6361
        );
6362
        $this->dom->addChild(
6363
            $detPag,
6364
            "tPag",
6365
            $std->tPag,
6366
            true,
6367
            "Forma de pagamento"
6368
        );
6369
        $this->dom->addChild(
6370
            $detPag,
6371
            "xPag",
6372
            !empty($std->xPag) ? $std->xPag : null,
6373
            false,
6374
            "Descricao da Forma de pagamento"
6375
        );
6376
        $this->dom->addChild(
6377
            $detPag,
6378
            "vPag",
6379
            $this->conditionalNumberFormatting($std->vPag),
6380
            true,
6381
            "Valor do Pagamento"
6382
        );
6383
        if (!empty($std->tpIntegra)) {
6384
            $card = $this->dom->createElement("card");
6385
            $this->dom->addChild(
6386
                $card,
6387
                "tpIntegra",
6388
                $std->tpIntegra,
6389
                true,
6390
                "Tipo de Integração para pagamento"
6391
            );
6392
            $this->dom->addChild(
6393
                $card,
6394
                "CNPJ",
6395
                !empty($std->CNPJ) ? $std->CNPJ : null,
6396
                false,
6397
                "CNPJ da Credenciadora de cartão de crédito e/ou débito"
6398
            );
6399
            $this->dom->addChild(
6400
                $card,
6401
                "tBand",
6402
                !empty($std->tBand) ? $std->tBand : null,
6403
                false,
6404
                "Bandeira da operadora de cartão de crédito e/ou débito"
6405
            );
6406
            $this->dom->addChild(
6407
                $card,
6408
                "cAut",
6409
                !empty($std->cAut) ? $std->cAut : null,
6410
                false,
6411
                "Número de autorização da operação cartão de crédito e/ou débito"
6412
            );
6413
            $this->dom->appChild($detPag, $card, "Inclusão do node Card");
6414
        }
6415
        $node = !empty($this->pag->getElementsByTagName("vTroco")->item(0))
6416
            ? $this->pag->getElementsByTagName("vTroco")->item(0)
6417
            : null;
6418
        if (!empty($node)) {
6419
            $this->pag->insertBefore($detPag, $node);
6420
        } else {
6421
            $this->dom->appChild($this->pag, $detPag, 'Falta tag "Pag"');
6422
        }
6423
        return $detPag;
6424
    }
6425
    
6426
    /**
6427
     * Dados do intermediador
6428
     *
6429
     * @param stdClass $std
6430
     * @return \DomElement
6431
     */
6432
    public function tagIntermed(stdClass $std)
6433
    {
6434
        $possible = [
6435
            'CNPJ',
6436
            'idCadIntTran'
6437
        ];
6438
        $std = $this->equilizeParameters($std, $possible);
6439
        $tag = $this->dom->createElement("infIntermed");
6440
        $this->dom->addChild(
6441
            $tag,
6442
            "CNPJ",
6443
            $std->CNPJ,
6444
            true,
6445
            "CNPJ do Intermediador da Transação (agenciador, plataforma de "
6446
            . "delivery, marketplace e similar) de serviços e de negócios"
6447
        );
6448
        $this->dom->addChild(
6449
            $tag,
6450
            "idCadIntTran",
6451
            $std->idCadIntTran,
6452
            true,
6453
            "Identificador cadastrado no intermediador"
6454
        );
6455
        return $this->intermed = $tag;
6456
    }
6457
6458
    /**
6459
     * Grupo Fatura Y02 pai Y01
6460
     * tag NFe/infNFe/cobr/fat (opcional)
6461
     * @param stdClass $std
6462
     * @return DOMElement
6463
     */
6464
    public function tagfat(stdClass $std)
6465
    {
6466
        $possible = [
6467
            'nFat',
6468
            'vOrig',
6469
            'vDesc',
6470
            'vLiq'
6471
        ];
6472
        $std = $this->equilizeParameters($std, $possible);
6473
        $this->buildCobr();
6474
        $fat = $this->dom->createElement("fat");
6475
        $this->dom->addChild(
6476
            $fat,
6477
            "nFat",
6478
            $std->nFat,
6479
            false,
6480
            "Número da Fatura"
6481
        );
6482
        $this->dom->addChild(
6483
            $fat,
6484
            "vOrig",
6485
            $this->conditionalNumberFormatting($std->vOrig),
6486
            false,
6487
            "Valor Original da Fatura"
6488
        );
6489
        $this->dom->addChild(
6490
            $fat,
6491
            "vDesc",
6492
            $this->conditionalNumberFormatting($std->vDesc),
6493
            false,
6494
            "Valor do desconto"
6495
        );
6496
        $this->dom->addChild(
6497
            $fat,
6498
            "vLiq",
6499
            $this->conditionalNumberFormatting($std->vLiq),
6500
            false,
6501
            "Valor Líquido da Fatura"
6502
        );
6503
        $this->dom->appChild($this->cobr, $fat);
6504
        return $fat;
6505
    }
6506
6507
    /**
6508
     * Grupo Duplicata Y07 pai Y02
6509
     * tag NFe/infNFe/cobr/fat/dup (opcional)
6510
     * É necessário criar a tag fat antes de criar as duplicatas
6511
     * @param stdClass $std
6512
     * @return DOMElement
6513
     */
6514
    public function tagdup(stdClass $std)
6515
    {
6516
        $possible = [
6517
            'nDup',
6518
            'dVenc',
6519
            'vDup'
6520
        ];
6521
        $std = $this->equilizeParameters($std, $possible);
6522
        $this->buildCobr();
6523
        $dup = $this->dom->createElement("dup");
6524
        $this->dom->addChild(
6525
            $dup,
6526
            "nDup",
6527
            $std->nDup,
6528
            false,
6529
            "Número da Duplicata"
6530
        );
6531
        $this->dom->addChild(
6532
            $dup,
6533
            "dVenc",
6534
            $std->dVenc,
6535
            false,
6536
            "Data de vencimento"
6537
        );
6538
        $this->dom->addChild(
6539
            $dup,
6540
            "vDup",
6541
            $this->conditionalNumberFormatting($std->vDup),
6542
            true,
6543
            "Valor da duplicata"
6544
        );
6545
        $this->dom->appChild($this->cobr, $dup, 'Inclui duplicata na tag cobr');
6546
        return $dup;
6547
    }
6548
6549
    /**
6550
     * Grupo de Informações Adicionais Z01 pai A01
6551
     * tag NFe/infNFe/infAdic (opcional)
6552
     * @param stdClass $std
6553
     * @return DOMElement
6554
     */
6555
    public function taginfAdic(stdClass $std)
6556
    {
6557
        $possible = ['infAdFisco', 'infCpl'];
6558
        $std = $this->equilizeParameters($std, $possible);
6559
        $this->buildInfAdic();
6560
        $this->dom->addChild(
6561
            $this->infAdic,
6562
            "infAdFisco",
6563
            $std->infAdFisco,
6564
            false,
6565
            "Informações Adicionais de Interesse do Fisco"
6566
        );
6567
        $this->dom->addChild(
6568
            $this->infAdic,
6569
            "infCpl",
6570
            $std->infCpl,
6571
            false,
6572
            "Informações Complementares de interesse do Contribuinte"
6573
        );
6574
        return $this->infAdic;
6575
    }
6576
6577
    /**
6578
     * Grupo Campo de uso livre do contribuinte Z04 pai Z01
6579
     * tag NFe/infNFe/infAdic/obsCont (opcional)
6580
     * O método taginfAdic deve ter sido carregado antes
6581
     * @param stdClass $std
6582
     * @return DOMElement
6583
     */
6584
    public function tagobsCont(stdClass $std)
6585
    {
6586
        $possible = ['xCampo', 'xTexto'];
6587
        $std = $this->equilizeParameters($std, $possible);
6588
        $this->buildInfAdic();
6589
        $obsCont = $this->dom->createElement("obsCont");
6590
        $obsCont->setAttribute("xCampo", $std->xCampo);
6591
        $this->dom->addChild(
6592
            $obsCont,
6593
            "xTexto",
6594
            $std->xTexto,
6595
            true,
6596
            "Conteúdo do campo"
6597
        );
6598
        $this->dom->appChild($this->infAdic, $obsCont, '');
6599
        return $obsCont;
6600
    }
6601
6602
    /**
6603
     * Grupo Campo de uso livre do Fisco Z07 pai Z01
6604
     * tag NFe/infNFe/infAdic/obsFisco (opcional)
6605
     * O método taginfAdic deve ter sido carregado antes
6606
     * @param stdClass $std
6607
     * @return DOMElement
6608
     */
6609
    public function tagobsFisco(stdClass $std)
6610
    {
6611
        $possible = ['xCampo', 'xTexto'];
6612
        $std = $this->equilizeParameters($std, $possible);
6613
        $this->buildInfAdic();
6614
        $obsFisco = $this->dom->createElement("obsFisco");
6615
        $obsFisco->setAttribute("xCampo", $std->xCampo);
6616
        $this->dom->addChild(
6617
            $obsFisco,
6618
            "xTexto",
6619
            $std->xTexto,
6620
            true,
6621
            "Conteúdo do campo"
6622
        );
6623
        $this->dom->appChild($this->infAdic, $obsFisco, '');
6624
        return $obsFisco;
6625
    }
6626
6627
    /**
6628
     * Grupo Processo referenciado Z10 pai Z01 (NT2012.003)
6629
     * tag NFe/infNFe/procRef (opcional)
6630
     * O método taginfAdic deve ter sido carregado antes
6631
     * @param stdClass $std
6632
     * @return DOMElement
6633
     */
6634
    public function tagprocRef($std)
6635
    {
6636
        $possible = ['nProc', 'indProc'];
6637
        $std = $this->equilizeParameters($std, $possible);
6638
        $this->buildInfAdic();
6639
        $procRef = $this->dom->createElement("procRef");
6640
        $this->dom->addChild(
6641
            $procRef,
6642
            "nProc",
6643
            $std->nProc,
6644
            true,
6645
            "Identificador do processo ou ato concessório"
6646
        );
6647
        $this->dom->addChild(
6648
            $procRef,
6649
            "indProc",
6650
            $std->indProc,
6651
            true,
6652
            "Indicador da origem do processo"
6653
        );
6654
        $this->dom->appChild($this->infAdic, $procRef, '');
6655
        return $procRef;
6656
    }
6657
6658
    /**
6659
     * Grupo Exportação ZA01 pai A01
6660
     * tag NFe/infNFe/exporta (opcional)
6661
     * @param stdClass $std
6662
     * @return DOMElement
6663
     */
6664
    public function tagexporta(stdClass $std)
6665
    {
6666
        $possible = ['UFSaidaPais', 'xLocExporta', 'xLocDespacho'];
6667
        $std = $this->equilizeParameters($std, $possible);
6668
        $this->exporta = $this->dom->createElement("exporta");
6669
        $this->dom->addChild(
6670
            $this->exporta,
6671
            "UFSaidaPais",
6672
            $std->UFSaidaPais,
6673
            true,
6674
            "Sigla da UF de Embarque ou de transposição de fronteira"
6675
        );
6676
        $this->dom->addChild(
6677
            $this->exporta,
6678
            "xLocExporta",
6679
            $std->xLocExporta,
6680
            true,
6681
            "Descrição do Local de Embarque ou de transposição de fronteira"
6682
        );
6683
        $this->dom->addChild(
6684
            $this->exporta,
6685
            "xLocDespacho",
6686
            $std->xLocDespacho,
6687
            false,
6688
            "Descrição do local de despacho"
6689
        );
6690
        return $this->exporta;
6691
    }
6692
6693
    /**
6694
     * Grupo Compra ZB01 pai A01
6695
     * tag NFe/infNFe/compra (opcional)
6696
     * @param stdClass $std
6697
     * @return DOMElement
6698
     */
6699
    public function tagcompra(stdClass $std)
6700
    {
6701
        $possible = ['xNEmp', 'xPed', 'xCont'];
6702
        $std = $this->equilizeParameters($std, $possible);
6703
        $this->compra = $this->dom->createElement("compra");
6704
        $this->dom->addChild(
6705
            $this->compra,
6706
            "xNEmp",
6707
            $std->xNEmp,
6708
            false,
6709
            "Nota de Empenho"
6710
        );
6711
        $this->dom->addChild(
6712
            $this->compra,
6713
            "xPed",
6714
            $std->xPed,
6715
            false,
6716
            "Pedido"
6717
        );
6718
        $this->dom->addChild(
6719
            $this->compra,
6720
            "xCont",
6721
            $std->xCont,
6722
            false,
6723
            "Contrato"
6724
        );
6725
        return $this->compra;
6726
    }
6727
6728
    /**
6729
     * Grupo Cana ZC01 pai A01
6730
     * tag NFe/infNFe/cana (opcional)
6731
     * @param stdClass $std
6732
     * @return DOMElement
6733
     */
6734
    public function tagcana(stdClass $std)
6735
    {
6736
        $possible = [
6737
            'safra',
6738
            'ref',
6739
            'qTotMes',
6740
            'qTotAnt',
6741
            'qTotGer',
6742
            'vFor',
6743
            'vTotDed',
6744
            'vLiqFor'
6745
        ];
6746
        $std = $this->equilizeParameters($std, $possible);
6747
        $this->cana = $this->dom->createElement("cana");
6748
        $this->dom->addChild(
6749
            $this->cana,
6750
            "safra",
6751
            $std->safra,
6752
            true,
6753
            "Identificação da safra"
6754
        );
6755
        $this->dom->addChild(
6756
            $this->cana,
6757
            "ref",
6758
            $std->ref,
6759
            true,
6760
            "Mês e ano de referência"
6761
        );
6762
        $this->dom->addChild(
6763
            $this->cana,
6764
            "qTotMes",
6765
            $std->qTotMes,
6766
            true,
6767
            "Quantidade Total do Mês"
6768
        );
6769
        $this->dom->addChild(
6770
            $this->cana,
6771
            "qTotAnt",
6772
            $std->qTotAnt,
6773
            true,
6774
            "Quantidade Total Anterior"
6775
        );
6776
        $this->dom->addChild(
6777
            $this->cana,
6778
            "qTotGer",
6779
            $std->qTotGer,
6780
            true,
6781
            "Quantidade Total Geral"
6782
        );
6783
        $this->dom->addChild(
6784
            $this->cana,
6785
            "vFor",
6786
            $this->conditionalNumberFormatting($std->vFor),
6787
            true,
6788
            "Valor dos Fornecimentos"
6789
        );
6790
        $this->dom->addChild(
6791
            $this->cana,
6792
            "vTotDed",
6793
            $this->conditionalNumberFormatting($std->vTotDed),
6794
            true,
6795
            "Valor Total da Dedução"
6796
        );
6797
        $this->dom->addChild(
6798
            $this->cana,
6799
            "vLiqFor",
6800
            $this->conditionalNumberFormatting($std->vLiqFor),
6801
            true,
6802
            "Valor Líquido dos Fornecimentos"
6803
        );
6804
        return $this->cana;
6805
    }
6806
6807
    /**
6808
     * Grupo Fornecimento diário de cana ZC04 pai ZC01
6809
     * tag NFe/infNFe/cana/forDia
6810
     * @param stdClass $std
6811
     * @return DOMElement
6812
     */
6813
    public function tagforDia(stdClass $std)
6814
    {
6815
        $forDia = $this->dom->createElement("forDia");
6816
        $forDia->setAttribute("dia", $std->dia);
6817
        $this->dom->addChild(
6818
            $forDia,
6819
            "qtde",
6820
            $this->conditionalNumberFormatting($std->qtde, 10),
6821
            true,
6822
            "Quantidade"
6823
        );
6824
        $qTotMes = $this->cana->getElementsByTagName('qTotMes')->item(0);
6825
        $this->cana->insertBefore($forDia, $qTotMes);
6826
        return $forDia;
6827
    }
6828
6829
    /**
6830
     * Grupo Deduções – Taxas e Contribuições ZC10 pai ZC01
6831
     * tag NFe/infNFe/cana/deduc (opcional)
6832
     * @param stdClass $std
6833
     * @return DOMElement
6834
     */
6835
    public function tagdeduc(stdClass $std)
6836
    {
6837
        $possible = ['xDed', 'vDed'];
6838
        $std = $this->equilizeParameters($std, $possible);
6839
        $deduc = $this->dom->createElement("deduc");
6840
        $this->dom->addChild(
6841
            $deduc,
6842
            "xDed",
6843
            $std->xDed,
6844
            true,
6845
            "Descrição da Dedução"
6846
        );
6847
        $this->dom->addChild(
6848
            $deduc,
6849
            "vDed",
6850
            $this->conditionalNumberFormatting($std->vDed),
6851
            true,
6852
            "Valor da Dedução"
6853
        );
6854
        $vFor = $this->cana->getElementsByTagName('vFor')->item(0);
6855
        $this->cana->insertBefore($deduc, $vFor);
6856
        return $deduc;
6857
    }
6858
6859
    /**
6860
     * Informações suplementares da Nota Fiscal
6861
     * @param stdClass $std
6862
     * @return DOMElement
6863
     */
6864
    public function taginfNFeSupl(stdClass $std)
6865
    {
6866
        $possible = ['qrcode', 'urlChave'];
6867
        $std = $this->equilizeParameters($std, $possible);
6868
6869
        $infNFeSupl = $this->dom->createElement("infNFeSupl");
6870
        $nodeqr = $infNFeSupl->appendChild($this->dom->createElement('qrCode'));
6871
        $nodeqr->appendChild($this->dom->createCDATASection($std->qrcode));
6872
        //incluido no layout 4.00
6873
        $std->urlChave = !empty($std->urlChave) ? $std->urlChave : null;
6874
        $this->dom->addChild(
6875
            $infNFeSupl,
6876
            "urlChave",
6877
            $std->urlChave,
6878
            false,
6879
            "URL de consulta por chave de acesso a ser impressa no DANFE NFC-e"
6880
        );
6881
        $this->infNFeSupl = $infNFeSupl;
6882
        return $infNFeSupl;
6883
    }
6884
6885
    /**
6886
     * Informações do Responsável técnico ZD01 pai A01
6887
     * tag NFe/infNFe/infRespTec (opcional)
6888
     * @param stdClass $std
6889
     * @return DOMElement
6890
     * @throws RuntimeException
6891
     */
6892
    public function taginfRespTec(stdClass $std)
6893
    {
6894
        $possible = [
6895
            'CNPJ',
6896
            'xContato',
6897
            'email',
6898
            'fone',
6899
            'CSRT',
6900
            'idCSRT'
6901
        ];
6902
6903
        $std = $this->equilizeParameters($std, $possible);
6904
        $infRespTec = $this->dom->createElement("infRespTec");
6905
        $this->dom->addChild(
6906
            $infRespTec,
6907
            "CNPJ",
6908
            $std->CNPJ,
6909
            true,
6910
            "Informar o CNPJ da pessoa jurídica responsável pelo sistema "
6911
            . "utilizado na emissão do documento fiscal eletrônico"
6912
        );
6913
        $this->dom->addChild(
6914
            $infRespTec,
6915
            "xContato",
6916
            $std->xContato,
6917
            true,
6918
            "Informar o nome da pessoa a ser contatada na empresa desenvolvedora "
6919
            . "do sistema utilizado na emissão do documento fiscal eletrônico"
6920
        );
6921
        $this->dom->addChild(
6922
            $infRespTec,
6923
            "email",
6924
            $std->email,
6925
            true,
6926
            "Informar o e-mail da pessoa a ser contatada na empresa "
6927
            . "desenvolvedora do sistema."
6928
        );
6929
        $this->dom->addChild(
6930
            $infRespTec,
6931
            "fone",
6932
            $std->fone,
6933
            true,
6934
            "Informar o telefone da pessoa a ser contatada na empresa "
6935
            . "desenvolvedora do sistema."
6936
        );
6937
        if (!empty($std->CSRT) && !empty($std->idCSRT)) {
6938
            $this->csrt = $std->CSRT;
6939
            $this->dom->addChild(
6940
                $infRespTec,
6941
                "idCSRT",
6942
                $std->idCSRT,
6943
                true,
6944
                "Identificador do CSRT utilizado para montar o hash do CSRT"
6945
            );
6946
            $this->dom->addChild(
6947
                $infRespTec,
6948
                "hashCSRT",
6949
                $this->hashCSRT($std->CSRT),
6950
                true,
6951
                "hash do CSRT"
6952
            );
6953
        }
6954
        $this->infRespTec = $infRespTec;
6955
        return $infRespTec;
6956
    }
6957
6958
    /**
6959
     * Tag raiz da NFe
6960
     * tag NFe DOMNode
6961
     * Função chamada pelo método [ monta ]
6962
     *
6963
     * @return DOMElement
6964
     */
6965
    protected function buildNFe()
6966
    {
6967
        if (empty($this->NFe)) {
6968
            $this->NFe = $this->dom->createElement("NFe");
6969
            $this->NFe->setAttribute("xmlns", "http://www.portalfiscal.inf.br/nfe");
6970
        }
6971
        return $this->NFe;
6972
    }
6973
6974
    /**
6975
     * Informação de Documentos Fiscais referenciados BA01 pai B01
6976
     * tag NFe/infNFe/ide/NFref
6977
     * Podem ser criados até 500 desses Nodes por NFe
6978
     * Função chamada pelos métodos
6979
     * [tagrefNFe] [tagrefNF] [tagrefNFP]  [tagCTeref] [tagrefECF]
6980
     */
6981
    protected function buildNFref()
6982
    {
6983
        $this->aNFref[] = $this->dom->createElement("NFref");
6984
        return count($this->aNFref);
6985
    }
6986
6987
    /**
6988
     * Insere dentro dentro das tags imposto o ICMS IPI II PIS COFINS ISSQN
6989
     * tag NFe/infNFe/det[]/imposto
6990
     * @return void
6991
     */
6992
    protected function buildImp()
6993
    {
6994
        foreach ($this->aImposto as $nItem => $imposto) {
6995
            if (!empty($this->aICMS[$nItem])) {
6996
                $this->dom->appChild($imposto, $this->aICMS[$nItem], "Inclusão do node ICMS");
6997
            }
6998
            if (!empty($this->aIPI[$nItem])) {
6999
                $this->dom->appChild($imposto, $this->aIPI[$nItem], "Inclusão do node IPI");
7000
            }
7001
            if (!empty($this->aII[$nItem])) {
7002
                $this->dom->appChild($imposto, $this->aII[$nItem], "Inclusão do node II");
7003
            }
7004
            if (!empty($this->aISSQN[$nItem])) {
7005
                $this->dom->appChild($imposto, $this->aISSQN[$nItem], "Inclusão do node ISSQN");
7006
            }
7007
            if (!empty($this->aPIS[$nItem])) {
7008
                $this->dom->appChild($imposto, $this->aPIS[$nItem], "Inclusão do node PIS");
7009
            }
7010
            if (!empty($this->aPISST[$nItem])) {
7011
                $this->dom->appChild($imposto, $this->aPISST[$nItem], "Inclusão do node PISST");
7012
            }
7013
            if (!empty($this->aCOFINS[$nItem])) {
7014
                $this->dom->appChild($imposto, $this->aCOFINS[$nItem], "Inclusão do node COFINS");
7015
            }
7016
            if (!empty($this->aCOFINSST[$nItem])) {
7017
                $this->dom->appChild($imposto, $this->aCOFINSST[$nItem], "Inclusão do node COFINSST");
7018
            }
7019
            if (!empty($this->aICMSUFDest[$nItem])) {
7020
                $this->dom->appChild($imposto, $this->aICMSUFDest[$nItem], "Inclusão do node ICMSUFDest");
7021
            }
7022
            $this->aImposto[$nItem] = $imposto;
7023
        }
7024
    }
7025
7026
    /**
7027
     * Grupo COFINS tributado pela alíquota S02 pai S01
7028
     * tag det/imposto/COFINS/COFINSAliq (opcional)
7029
     * Função chamada pelo método [ tagCOFINS ]
7030
     * @param stdClass $std
7031
     * @return DOMElement
7032
     */
7033
    protected function buildCOFINSAliq($std)
7034
    {
7035
        $confinsAliq = $this->dom->createElement('COFINSAliq');
7036
        $this->dom->addChild(
7037
            $confinsAliq,
7038
            'CST',
7039
            $std->CST,
7040
            true,
7041
            "Código de Situação Tributária da COFINS"
7042
        );
7043
        $this->dom->addChild(
7044
            $confinsAliq,
7045
            'vBC',
7046
            $this->conditionalNumberFormatting($std->vBC),
7047
            true,
7048
            "Valor da Base de Cálculo da COFINS"
7049
        );
7050
        $this->dom->addChild(
7051
            $confinsAliq,
7052
            'pCOFINS',
7053
            $this->conditionalNumberFormatting($std->pCOFINS, 4),
7054
            true,
7055
            "Alíquota da COFINS (em percentual)"
7056
        );
7057
        $this->dom->addChild(
7058
            $confinsAliq,
7059
            'vCOFINS',
7060
            $this->conditionalNumberFormatting($std->vCOFINS),
7061
            true,
7062
            "Valor da COFINS"
7063
        );
7064
        return $confinsAliq;
7065
    }
7066
7067
    /**
7068
     * Grupo COFINS não tributado S04 pai S01
7069
     * tag NFe/infNFe/det[]/imposto/COFINS/COFINSNT (opcional)
7070
     * Função chamada pelo método [ tagCOFINS ]
7071
     * @param stdClass $std
7072
     * @return DOMElement
7073
     */
7074
    protected function buildCOFINSNT(stdClass $std)
7075
    {
7076
        $confinsnt = $this->dom->createElement('COFINSNT');
7077
        $this->dom->addChild(
7078
            $confinsnt,
7079
            "CST",
7080
            $std->CST,
7081
            true,
7082
            "Código de Situação Tributária da COFINS"
7083
        );
7084
        return $confinsnt;
7085
    }
7086
7087
    /**
7088
     * Grupo COFINS Outras Operações S05 pai S01
7089
     * tag NFe/infNFe/det[]/imposto/COFINS/COFINSoutr (opcional)
7090
     * Função chamada pelo método [ tagCOFINS ]
7091
     * @param stdClass $std
7092
     * @return DOMElement
7093
     */
7094
    protected function buildCOFINSoutr(stdClass $std)
7095
    {
7096
        $confinsoutr = $this->dom->createElement('COFINSOutr');
7097
        $this->dom->addChild(
7098
            $confinsoutr,
7099
            "CST",
7100
            $std->CST,
7101
            true,
7102
            "Código de Situação Tributária da COFINS"
7103
        );
7104
        $this->dom->addChild(
7105
            $confinsoutr,
7106
            "vBC",
7107
            $this->conditionalNumberFormatting($std->vBC),
7108
            ($std->vBC !== null) ? true : false,
7109
            "Valor da Base de Cálculo da COFINS"
7110
        );
7111
        $this->dom->addChild(
7112
            $confinsoutr,
7113
            "pCOFINS",
7114
            $this->conditionalNumberFormatting($std->pCOFINS, 4),
7115
            ($std->pCOFINS !== null) ? true : false,
7116
            "Alíquota da COFINS (em percentual)"
7117
        );
7118
        $this->dom->addChild(
7119
            $confinsoutr,
7120
            "qBCProd",
7121
            $this->conditionalNumberFormatting($std->qBCProd, 4),
7122
            ($std->qBCProd !== null) ? true : false,
7123
            "Quantidade Vendida"
7124
        );
7125
        $this->dom->addChild(
7126
            $confinsoutr,
7127
            "vAliqProd",
7128
            $this->conditionalNumberFormatting($std->vAliqProd, 4),
7129
            ($std->vAliqProd !== null) ? true : false,
7130
            "Alíquota da COFINS (em reais)"
7131
        );
7132
        $this->dom->addChild(
7133
            $confinsoutr,
7134
            "vCOFINS",
7135
            $this->conditionalNumberFormatting($std->vCOFINS),
7136
            true,
7137
            "Valor da COFINS"
7138
        );
7139
        return $confinsoutr;
7140
    }
7141
7142
    /**
7143
     * Insere dentro da tag det os produtos
7144
     * tag NFe/infNFe/det[]
7145
     * @return array|string
7146
     */
7147
    protected function buildDet()
7148
    {
7149
        if (empty($this->aProd)) {
7150
            return '';
7151
        }
7152
        //insere NVE
7153
        foreach ($this->aNVE as $nItem => $nve) {
7154
            $prod = $this->aProd[$nItem];
7155
            foreach ($nve as $child) {
7156
                $node = $prod->getElementsByTagName("cBenef")->item(0);
7157
                if (empty($node)) {
7158
                    $node = $prod->getElementsByTagName("EXTIPI")->item(0);
7159
                    if (empty($node)) {
7160
                        $node = $prod->getElementsByTagName("CFOP")->item(0);
7161
                    }
7162
                }
7163
                $prod->insertBefore($child, $node);
7164
            }
7165
        }
7166
        //insere CEST
7167
        foreach ($this->aCest as $nItem => $cest) {
7168
            $prod = $this->aProd[$nItem];
7169
            /** @var \DOMElement $child */
7170
            foreach ($cest as $child) {
7171
                $node = $prod->getElementsByTagName("cBenef")->item(0);
7172
                if (empty($node)) {
7173
                    $node = $prod->getElementsByTagName("EXTIPI")->item(0);
7174
                    if (empty($node)) {
7175
                        $node = $prod->getElementsByTagName("CFOP")->item(0);
7176
                    }
7177
                }
7178
                $cchild = $child->getElementsByTagName("CEST")->item(0);
7179
                $prod->insertBefore($cchild, $node);
7180
                $cchild = $child->getElementsByTagName("indEscala")->item(0);
7181
                if (!empty($cchild)) {
7182
                    $prod->insertBefore($cchild, $node);
7183
                }
7184
                $cchild = $child->getElementsByTagName("CNPJFab")->item(0);
7185
                if (!empty($cchild)) {
7186
                    $prod->insertBefore($cchild, $node);
7187
                    $this->aProd[$nItem] = $prod;
7188
                }
7189
            }
7190
        }
7191
        //insere DI
7192
        foreach ($this->aDI as $nItem => $aDI) {
7193
            $prod = $this->aProd[$nItem];
7194
            foreach ($aDI as $child) {
7195
                $node = $prod->getElementsByTagName("xPed")->item(0);
7196
                if (!empty($node)) {
7197
                    $prod->insertBefore($child, $node);
7198
                } else {
7199
                    $node = $prod->getElementsByTagName("FCI")->item(0);
7200
                    if (!empty($node)) {
7201
                        $prod->insertBefore($child, $node);
7202
                    } else {
7203
                        $this->dom->appChild($prod, $child, "Inclusão do node DI");
7204
                    }
7205
                }
7206
            }
7207
            $this->aProd[$nItem] = $prod;
7208
        }
7209
        //insere detExport
7210
        foreach ($this->aDetExport as $nItem => $detexport) {
7211
            $prod = $this->aProd[$nItem];
7212
            foreach ($detexport as $child) {
7213
                $node = $prod->getElementsByTagName("xPed")->item(0);
7214
                if (!empty($node)) {
7215
                    $prod->insertBefore($child, $node);
7216
                } else {
7217
                    $this->dom->appChild($prod, $child, "Inclusão do node DetExport");
7218
                }
7219
            }
7220
            $this->aProd[$nItem] = $prod;
7221
        }
7222
        //insere Rastro
7223
        foreach ($this->aRastro as $nItem => $child) {
7224
            $prod = $this->aProd[$nItem];
7225
            foreach ($child as $rastro) {
7226
                $this->dom->appChild($prod, $rastro, "Inclusão do node Rastro");
7227
            }
7228
            $this->aProd[$nItem] = $prod;
7229
        }
7230
        //insere veiculo
7231
        foreach ($this->aVeicProd as $nItem => $child) {
7232
            $prod = $this->aProd[$nItem];
7233
            $this->dom->appChild($prod, $child, "Inclusão do node veiculo");
7234
            $this->aProd[$nItem] = $prod;
7235
        }
7236
        //insere medicamentos
7237
        foreach ($this->aMed as $nItem => $child) {
7238
            $prod = $this->aProd[$nItem];
7239
            $this->dom->appChild($prod, $child, "Inclusão do node medicamento");
7240
            $this->aProd[$nItem] = $prod;
7241
        }
7242
        //insere armas
7243
        foreach ($this->aArma as $nItem => $arma) {
7244
            $prod = $this->aProd[$nItem];
7245
            foreach ($arma as $child) {
7246
                $node = $prod->getElementsByTagName("imposto")->item(0);
7247
                if (!empty($node)) {
7248
                    $prod->insertBefore($child, $node);
7249
                } else {
7250
                    $this->dom->appChild($prod, $child, "Inclusão do node arma");
7251
                }
7252
            }
7253
            $this->aProd[$nItem] = $prod;
7254
        }
7255
        //insere combustivel
7256
        foreach ($this->aComb as $nItem => $child) {
7257
            $prod = $this->aProd[$nItem];
7258
            if (!empty($this->aEncerrante)) {
7259
                $encerrante = $this->aEncerrante[$nItem];
7260
                if (!empty($encerrante)) {
7261
                    $this->dom->appChild($child, $encerrante, "inclusão do node encerrante na tag comb");
7262
                }
7263
            }
7264
            $this->dom->appChild($prod, $child, "Inclusão do node combustivel");
7265
            $this->aProd[$nItem] = $prod;
7266
        }
7267
        //insere RECOPI
7268
        foreach ($this->aRECOPI as $nItem => $child) {
7269
            $prod = $this->aProd[$nItem];
7270
            $this->dom->appChild($prod, $child, "Inclusão do node RECOPI");
7271
            $this->aProd[$nItem] = $prod;
7272
        }
7273
        //montagem da tag imposto[]
7274
        $this->buildImp();
7275
        //montagem da tag det[]
7276
        foreach ($this->aProd as $nItem => $prod) {
7277
            $det = $this->dom->createElement("det");
7278
            $det->setAttribute("nItem", $nItem);
7279
            $det->appendChild($prod);
7280
            //insere imposto
7281
            if (!empty($this->aImposto[$nItem])) {
7282
                $child = $this->aImposto[$nItem];
7283
                $this->dom->appChild($det, $child, "Inclusão do node imposto");
7284
            }
7285
            //insere impostoDevol
7286
            if (!empty($this->aImpostoDevol[$nItem])) {
7287
                $child = $this->aImpostoDevol[$nItem];
7288
                $this->dom->appChild($det, $child, "Inclusão do node impostoDevol");
7289
            }
7290
            //insere infAdProd
7291
            if (!empty($this->aInfAdProd[$nItem])) {
7292
                $child = $this->aInfAdProd[$nItem];
7293
                $this->dom->appChild($det, $child, "Inclusão do node infAdProd");
7294
            }
7295
            $this->aDet[] = $det;
7296
            $det = null;
0 ignored issues
show
Unused Code introduced by
$det is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
7297
        }
7298
        return $this->aProd;
7299
    }
7300
7301
    /**
7302
     * Insere a tag pag, os detalhamentos dos pagamentos e cartoes
7303
     * NOTA: Ajustado para NT2016_002_v1.30
7304
     * tag NFe/infNFe/pag/
7305
     * tag NFe/infNFe/pag/detPag[]
7306
     * tag NFe/infNFe/pag/detPag[]/Card
7307
     */
7308
    protected function buildTagPag()
7309
    {
7310
        $this->dom->appChild($this->infNFe, $this->pag, 'Falta tag "infNFe"');
7311
    }
7312
7313
    /**
7314
     * Grupo Totais da NF-e W01 pai A01
7315
     * tag NFe/infNFe/total
7316
     */
7317
    protected function buildTotal()
7318
    {
7319
        if (empty($this->total)) {
7320
            $this->total = $this->dom->createElement("total");
7321
        }
7322
7323
        $this->stdTot->vNF = $this->stdTot->vProd
7324
            - $this->stdTot->vDesc
7325
            + $this->stdTot->vST
7326
            + $this->stdTot->vFrete
7327
            + $this->stdTot->vSeg
7328
            + $this->stdTot->vOutro
7329
            + $this->stdTot->vII
7330
            + $this->stdTot->vIPI
7331
            + $this->stdTot->vIPIDevol;
7332
        //round all values
7333
        $this->stdTot->vBC = round($this->stdTot->vBC, 2);
7334
        $this->stdTot->vICMS = round($this->stdTot->vICMS, 2);
7335
        $this->stdTot->vICMSDeson = round($this->stdTot->vICMSDeson, 2);
7336
        $this->stdTot->vFCP = round($this->stdTot->vFCP, 2);
7337
        $this->stdTot->vFCPUFDest = round($this->stdTot->vFCPUFDest, 2);
7338
        $this->stdTot->vICMSUFDest = round($this->stdTot->vICMSUFDest, 2);
7339
        $this->stdTot->vICMSUFRemet = round($this->stdTot->vICMSUFRemet, 2);
7340
        $this->stdTot->vBCST = round($this->stdTot->vBCST, 2);
7341
        $this->stdTot->vST = round($this->stdTot->vST, 2);
7342
        $this->stdTot->vFCPST = round($this->stdTot->vFCPST, 2);
7343
        $this->stdTot->vFCPSTRet = round($this->stdTot->vFCPSTRet, 2);
7344
        $this->stdTot->vProd = round($this->stdTot->vProd, 2);
7345
        $this->stdTot->vFrete = round($this->stdTot->vFrete, 2);
7346
        $this->stdTot->vSeg = round($this->stdTot->vSeg, 2);
7347
        $this->stdTot->vDesc = round($this->stdTot->vDesc, 2);
7348
        $this->stdTot->vII = round($this->stdTot->vII, 2);
7349
        $this->stdTot->vIPI = round($this->stdTot->vIPI, 2);
7350
        $this->stdTot->vIPIDevol = round($this->stdTot->vIPIDevol, 2);
7351
        $this->stdTot->vPIS = round($this->stdTot->vPIS, 2);
7352
        $this->stdTot->vCOFINS = round($this->stdTot->vCOFINS, 2);
7353
        $this->stdTot->vOutro = round($this->stdTot->vOutro, 2);
7354
        $this->stdTot->vNF = round($this->stdTot->vNF, 2);
7355
        $this->stdTot->vTotTrib = round($this->stdTot->vTotTrib, 2);
7356
    }
7357
7358
    /**
7359
     * Grupo Cobrança Y01 pai A01
7360
     * tag NFe/infNFe/cobr (opcional)
7361
     * Depende de fat
7362
     */
7363
    protected function buildCobr()
7364
    {
7365
        if (empty($this->cobr)) {
7366
            $this->cobr = $this->dom->createElement("cobr");
7367
        }
7368
    }
7369
7370
    /**
7371
     * Grupo de Informações Adicionais Z01 pai A01
7372
     * tag NFe/infNFe/infAdic (opcional)
7373
     * Função chamada pelos metodos
7374
     * [taginfAdic] [tagobsCont] [tagobsFisco] [tagprocRef]
7375
     * @return DOMElement
7376
     */
7377
    protected function buildInfAdic()
7378
    {
7379
        if (empty($this->infAdic)) {
7380
            $this->infAdic = $this->dom->createElement("infAdic");
7381
        }
7382
        return $this->infAdic;
7383
    }
7384
7385
    /**
7386
     * Remonta a chave da NFe de 44 digitos com base em seus dados
7387
     * já contidos na NFE.
7388
     * Isso é útil no caso da chave informada estar errada
7389
     * se a chave estiver errada a mesma é substituida
7390
     * @param Dom $dom
7391
     * @return void
7392
     */
7393
    protected function checkNFeKey(Dom $dom)
7394
    {
7395
        $infNFe = $dom->getElementsByTagName("infNFe")->item(0);
7396
        $ide = $dom->getElementsByTagName("ide")->item(0);
7397
        $emit = $dom->getElementsByTagName("emit")->item(0);
7398
        $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue;
7399
        $dhEmi = $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue;
7400
        if (!empty($emit->getElementsByTagName('CNPJ')->item(0)->nodeValue)) {
7401
            $doc = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
7402
        } else {
7403
            $doc = $emit->getElementsByTagName('CPF')->item(0)->nodeValue;
7404
        }
7405
        $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue;
7406
        $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
7407
        $nNF = $ide->getElementsByTagName('nNF')->item(0)->nodeValue;
7408
        $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue;
7409
        $cNF = $ide->getElementsByTagName('cNF')->item(0)->nodeValue;
7410
        $chave = str_replace('NFe', '', $infNFe->getAttribute("Id"));
7411
        $dt = new DateTime($dhEmi);
7412
        $infRespTec = $dom->getElementsByTagName("infRespTec")->item(0);
7413
        $chaveMontada = Keys::build(
7414
            $cUF,
7415
            $dt->format('y'),
7416
            $dt->format('m'),
7417
            $doc,
7418
            $mod,
7419
            $serie,
7420
            $nNF,
7421
            $tpEmis,
7422
            $cNF
7423
        );
7424
        if (empty($chave)) {
7425
            //chave não foi passada por parâmetro então colocar a chavemontada
7426
            $infNFe->setAttribute('Id', "NFe$chaveMontada");
7427
            $chave = $chaveMontada;
7428
            $this->chNFe = $chaveMontada;
7429
            $ide->getElementsByTagName('cDV')->item(0)->nodeValue = substr($chave, -1);
7430
            //trocar também o hash se o CSRT for passado
7431
            if (!empty($this->csrt)) {
7432
                $hashCSRT = $this->hashCSRT($this->csrt);
7433
                $infRespTec->getElementsByTagName("hashCSRT")
7434
                    ->item(0)->nodeValue = $hashCSRT;
7435
            }
7436
        }
7437
        //caso a chave contida na NFe esteja errada
7438
        //substituir a chave
7439
        if ($chaveMontada != $chave) {
7440
            $this->chNFe = $chaveMontada;
7441
            $this->errors[] = "A chave informada está incorreta [$chave] => [correto: $chaveMontada].";
7442
        }
7443
    }
7444
7445
    /**
7446
     * Retorna os erros detectados
7447
     * @return array
7448
     */
7449
    public function getErrors()
7450
    {
7451
        return $this->errors;
7452
    }
7453
7454
    /**
7455
     * Includes missing or unsupported properties in stdClass
7456
     * Replace all unsuported chars
7457
     * @param stdClass $std
7458
     * @param array $possible
7459
     * @return stdClass
7460
     */
7461 7
    protected function equilizeParameters(stdClass $std, $possible)
7462
    {
7463 7
        $arr = get_object_vars($std);
7464 7
        foreach ($possible as $key) {
7465 7
            if (!array_key_exists($key, $arr)) {
7466 6
                $std->$key = null;
7467
            } else {
7468 7
                if (is_string($std->$key)) {
7469 7
                    $std->$key = trim(Strings::replaceUnacceptableCharacters($std->$key));
7470 7
                    if ($this->replaceAccentedChars) {
7471 7
                        $std->$key = Strings::toASCII($std->$key);
7472
                    }
7473
                }
7474
            }
7475
        }
7476 7
        return $std;
7477
    }
7478
7479
    /**
7480
     * Calcula hash sha1 retornando Base64Binary
7481
     * @param string $CSRT
7482
     * @return string
7483
     */
7484
    protected function hashCSRT($CSRT)
7485
    {
7486
        $comb = $CSRT . $this->chNFe;
7487
        return base64_encode(sha1($comb, true));
7488
    }
7489
    
7490
    /**
7491
     * Formatação numerica condicional
7492
     * @param string|float|int|null $value
7493
     * @param int $decimal
7494
     * @return string
7495
     */
7496
    protected function conditionalNumberFormatting($value = null, $decimal = 2)
7497
    {
7498
        if (is_numeric($value)) {
7499
            return number_format($value, $decimal, '.', '');
7500
        }
7501
        return null;
7502
    }
7503
7504
    /*
7505
    protected function conditionalNumberFormatting($value = null, array $decimal): string
7506
    {
7507
        if (!is_numeric($value)) {
7508
            return null;
7509
        }
7510
        $num = (float) $value;
7511
        $l = explode('.', $num);
7512
        $declen = 0;
7513
        if (!empty($l[1])) {
7514
            $declen = strlen($l[1]);
7515
        }
7516
        if ($declen < $decimal[0]) {
7517
            return number_format($num, $decimal[0], '.', '');
7518
        } elseif ($declen > $decimal[1]) {
7519
            return number_format($num, $decimal[1], '.', '');
7520
        }
7521
        return $num;
7522
    }*/
7523
}
7524