Passed
Pull Request — master (#921)
by
unknown
08:01
created

Make   F

Complexity

Total Complexity 462

Size/Duplication

Total Lines 7783
Duplicated Lines 0 %

Test Coverage

Coverage 34%

Importance

Changes 50
Bugs 4 Features 0
Metric Value
wmc 462
eloc 5626
dl 0
loc 7783
ccs 1747
cts 5138
cp 0.34
rs 0.8
c 50
b 4
f 0

97 Methods

Rating   Name   Duplication   Size   Complexity  
A getModelo() 0 3 1
A tagvagao() 0 12 1
B tagcomb() 0 121 2
B tagICMSUFDest() 0 84 1
A tagCEST() 0 32 1
A tagveicTransp() 0 36 1
B checkNFeKey() 0 49 5
A tagimposto() 0 17 1
A tagNVE() 0 11 2
A hashCSRT() 0 4 1
B tagdetPag() 0 84 8
A getErrors() 0 3 1
F buildDet() 0 157 35
A buildISSQNTot() 0 34 5
A getNodeValue() 0 7 1
A tagtransp() 0 11 1
B tagenderDest() 0 105 3
A tagautXML() 0 24 3
A tagcompra() 0 27 1
B tagDI() 0 100 1
A tagRECOPI() 0 7 1
A tagrefNF() 0 52 1
A tagadi() 0 55 1
F tagICMSTot() 0 241 29
B tagICMSPart() 0 140 6
A tagarma() 0 45 1
A taginfAdProd() 0 10 1
A tagdup() 0 33 1
A taginfAdic() 0 20 1
B tagenderEmit() 0 99 1
A tagvol() 0 57 1
A tagexporta() 0 27 1
A tagII() 0 43 1
A buildCobr() 0 4 2
A buildInfAdic() 0 6 2
F tagPIS() 0 177 44
A tagretTrib() 0 65 1
B tagrefNFP() 0 75 1
A tagrefCTe() 0 9 1
B tagveicProd() 0 202 1
A tagfat() 0 41 1
B tagretirada() 0 136 1
A tagrefNFe() 0 9 1
A tagRastro() 0 50 1
A tagpag() 0 16 1
A tagprocRef() 0 22 1
A tagbalsa() 0 12 1
A tagretTransp() 0 60 1
F tagICMS() 0 1058 37
A tagdetExportInd() 0 42 2
A buildNFref() 0 4 1
C tagide() 0 219 12
B tagemit() 0 88 6
A buildTotal() 0 41 1
A montaNFe() 0 3 1
C tagISSQN() 0 159 9
D tagCOFINS() 0 95 35
A tagforDia() 0 14 1
F tagICMSSN() 0 523 52
B tagcana() 0 71 1
A tagimpostoDevol() 0 29 1
A __construct() 0 47 1
A buildNFe() 0 7 2
B tagentrega() 0 136 1
A buildTagPag() 0 3 1
A tagdetExport() 0 18 1
A setOnlyAscii() 0 3 1
A getXML() 0 6 2
A tagrefECF() 0 31 1
B tagIPI() 0 115 5
B tagtransporta() 0 69 1
A taginfRespTec() 0 64 3
A tagCOFINSST() 0 63 4
C tagprod() 0 245 9
A tagobsFisco() 0 16 1
F tagdest() 0 106 14
A getChave() 0 3 1
B monta() 0 76 7
A tagdeduc() 0 22 1
F tagISSQNTot() 0 138 25
A tagobsCont() 0 16 1
A taginfNFeSupl() 0 19 2
A tagIntermed() 0 24 1
A buildCOFINSNT() 0 11 1
A tagencerrante() 0 50 1
A tagreboque() 0 36 1
F buildImp() 0 31 11
A taglacres() 0 12 1
A buildVol() 0 4 2
B tagICMSST() 0 137 3
A conditionalNumberFormatting() 0 6 2
A buildCOFINSAliq() 0 32 1
A taginfNFe() 0 17 2
A equilizeParameters() 0 6 1
A tagmed() 0 34 1
B buildCOFINSoutr() 0 49 6
A tagPISST() 0 63 4

How to fix   Complexity   

Complex Class

Complex classes like Make often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Make, and based on these observations, apply Extract Interface, too.

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

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

7810
            return number_format(/** @scrutinizer ignore-type */ $value, $decimal, '.', '');
Loading history...
7811
        }
7812 1
        return null;
7813
    }
7814
}
7815