ghinfe 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/.env.example +24 -15
  2. package/LICENSE +21 -21
  3. package/README.md +491 -413
  4. package/docs/developer-guide.html +421 -421
  5. package/docs/openapi.yaml +428 -428
  6. package/examples/dce-homologacao.js +141 -0
  7. package/examples/emitir-nfce.js +51 -51
  8. package/examples/emitir-nfe.js +83 -83
  9. package/examples/emitir-nfse.js +46 -46
  10. package/examples/endpoints-sefaz.js +14 -14
  11. package/examples/eventos-nfe.js +49 -49
  12. package/examples/gerar-chave.js +25 -25
  13. package/examples/gerar-dace.js +59 -0
  14. package/examples/gerar-danfe.js +75 -75
  15. package/examples/gerar-dce.js +58 -0
  16. package/examples/layouts-nfse.js +51 -51
  17. package/examples/mock-sefaz.js +52 -52
  18. package/examples/nfse-eventos.js +57 -57
  19. package/examples/reforma-ibscbs.js +27 -27
  20. package/examples/reforma-nfe-xml.js +52 -52
  21. package/examples/status-sefaz.js +12 -12
  22. package/examples/validar-xsd.js +48 -48
  23. package/package.json +59 -68
  24. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/consSitDCeTiposBasico_v1.00.xsd +123 -0
  25. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/consSitDCe_v1.00.xsd +10 -0
  26. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/consStatServDCeTiposBasico_v1.00.xsd +110 -0
  27. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/consStatServDCe_v1.00.xsd +10 -0
  28. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/dceTiposBasico_v1.00.xsd +1388 -0
  29. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/retConsSitDCe_v1.00.xsd +10 -0
  30. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/retConsStatServDCe_v1.00.xsd +10 -0
  31. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/tiposGeralDCe_v1.00.xsd +712 -0
  32. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/xmldsig-core-schema_v1.01.xsd +98 -0
  33. package/schemas/dce/PL_DCe_100a_NT2024.001/dceTiposBasico_v1.00.xsd +1410 -0
  34. package/schemas/dce/PL_DCe_100a_NT2024.001/dce_v1.00.xsd +10 -0
  35. package/schemas/dce/PL_DCe_100a_NT2024.001/evento/evCancDCe_v1.00.xsd +36 -0
  36. package/schemas/dce/PL_DCe_100a_NT2024.001/evento/eventoDCeTiposBasico_v1.00.xsd +283 -0
  37. package/schemas/dce/PL_DCe_100a_NT2024.001/evento/eventoDCe_v1.00.xsd +9 -0
  38. package/schemas/dce/PL_DCe_100a_NT2024.001/evento/procEventoDCe_v1.00.xsd +10 -0
  39. package/schemas/dce/PL_DCe_100a_NT2024.001/evento/retEventoDCe_v1.00.xsd +9 -0
  40. package/schemas/dce/PL_DCe_100a_NT2024.001/evento/tiposGeralDCe_v1.00.xsd +712 -0
  41. package/schemas/dce/PL_DCe_100a_NT2024.001/evento/xmldsig-core-schema_v1.01.xsd +98 -0
  42. package/schemas/dce/PL_DCe_100a_NT2024.001/procDCe_v1.00.xsd +37 -0
  43. package/schemas/dce/PL_DCe_100a_NT2024.001/retDCe_v1.00.xsd +9 -0
  44. package/schemas/dce/PL_DCe_100a_NT2024.001/tiposGeralDCe_v1.00.xsd +712 -0
  45. package/schemas/dce/PL_DCe_100a_NT2024.001/xmldsig-core-schema_v1.01.xsd +98 -0
  46. package/schemas/nfe/PL_009_V4/enviNFe_v3.10.xsd +8 -8
  47. package/schemas/nfe/PL_009_V4/xmldsig-core-schema_v1.01.xsd +97 -97
  48. package/scripts/download-schemas.js +39 -39
  49. package/scripts/test-xsd.js +34 -34
  50. package/src/api/server.js +316 -316
  51. package/src/constants/sefaz.js +69 -69
  52. package/src/danfe/DanfeService.js +205 -205
  53. package/src/danfe/xml-extract.js +69 -69
  54. package/src/dce/builders/DCeEventoXmlBuilder.js +86 -0
  55. package/src/dce/builders/DCeXmlBuilder.js +345 -0
  56. package/src/dce/constants/dce.js +87 -0
  57. package/src/dce/dace/DaceService.js +356 -0
  58. package/src/dce/dace/dace-extract.js +114 -0
  59. package/src/dce/services/DCeService.js +263 -0
  60. package/src/dce/services/DCeSoapService.js +235 -0
  61. package/src/dce/services/DCeXmlService.js +67 -0
  62. package/src/dce/types/DCeDocument.js +106 -0
  63. package/src/dce/utils/qrcode.utils.js +59 -0
  64. package/src/errors/GhinfeError.js +13 -13
  65. package/src/errors/SefazError.js +25 -25
  66. package/src/errors/XsdValidationError.js +15 -15
  67. package/src/index.js +84 -60
  68. package/src/nfce/builders/NFCeXmlBuilder.js +178 -178
  69. package/src/nfce/constants/qrcode.js +26 -26
  70. package/src/nfce/services/NFCeService.js +188 -188
  71. package/src/nfce/services/NFCeXmlService.js +38 -38
  72. package/src/nfce/types/NFCeDocument.js +42 -42
  73. package/src/nfce/utils/qrcode.utils.js +92 -92
  74. package/src/nfe/builders/NFeEventoXmlBuilder.js +110 -110
  75. package/src/nfe/builders/NFeXmlBuilder.js +215 -215
  76. package/src/nfe/mocks/sefaz-responses.js +195 -195
  77. package/src/nfe/services/NFeEventoService.js +95 -95
  78. package/src/nfe/services/NFeService.js +196 -196
  79. package/src/nfe/services/NFeSignService.js +127 -111
  80. package/src/nfe/services/NFeSoapService.js +437 -437
  81. package/src/nfe/services/NFeXmlService.js +41 -41
  82. package/src/nfe/services/NFeXsdService.js +56 -56
  83. package/src/nfe/types/NFeDocument.js +92 -92
  84. package/src/nfe/types/NFeEvento.js +44 -44
  85. package/src/nfse/NFSeMunicipioResolver.js +42 -42
  86. package/src/nfse/builders/NFSeEventoXmlBuilder.js +92 -92
  87. package/src/nfse/builders/NFSeXmlBuilder.js +16 -16
  88. package/src/nfse/constants/municipios.js +82 -82
  89. package/src/nfse/layouts/adapters.js +202 -202
  90. package/src/nfse/mocks/nfse-responses.js +142 -142
  91. package/src/nfse/services/NFSeService.js +191 -191
  92. package/src/nfse/services/NFSeSoapService.js +232 -232
  93. package/src/nfse/services/NFSeXmlService.js +12 -12
  94. package/src/nfse/types/NFSeDocument.js +54 -54
  95. package/src/queue/NFCeQueue.js +63 -63
  96. package/src/queue/NFSeQueue.js +59 -59
  97. package/src/queue/NFeQueue.js +76 -76
  98. package/src/reforma/ibscbs.js +175 -175
  99. package/src/sefaz/SefazEndpointResolver.js +95 -95
  100. package/src/sefaz/ca/icp-brasil-raiz-v10.pem +38 -0
  101. package/src/sefaz/endpoints.registry.js +205 -205
  102. package/src/sefaz/httpsAgent.js +33 -0
  103. package/src/shared/fiscal.helpers.js +53 -53
  104. package/src/utils/certificate.utils.js +69 -47
  105. package/src/utils/chave.utils.js +205 -117
  106. package/src/utils/code128.utils.js +67 -0
  107. package/src/utils/date.utils.js +26 -26
  108. package/src/utils/xml.utils.js +44 -44
  109. package/src/validation/XsdValidator.js +133 -114
  110. package/src/validation/schemas.js +18 -14
@@ -1,178 +1,178 @@
1
- import { create } from 'xmlbuilder2';
2
- import { NFE_VERSAO } from '../../constants/sefaz.js';
3
- import { formatSefazDateTime } from '../../utils/date.utils.js';
4
- import { GhinfeError } from '../../errors/GhinfeError.js';
5
- import { codigoUf, formatDecimal, appendEndereco, appendImpostosItem } from '../../shared/fiscal.helpers.js';
6
-
7
- /**
8
- * Monta XML da NFC-e (modelo 65, layout 4.00).
9
- */
10
- export class NFCeXmlBuilder {
11
- /**
12
- * @param {import('../types/NFCeDocument.js').NFCeDocumento} documento
13
- * @returns {string}
14
- */
15
- build(documento) {
16
- this.#validar(documento);
17
-
18
- const dhEmi = formatSefazDateTime();
19
- const idInfNFe = `NFe${documento.chaveAcesso}`;
20
- const ambiente = documento.ambiente ?? 2;
21
-
22
- const totalProdutos = documento.itens.reduce((s, i) => s + i.valorTotal, 0);
23
- const valorIcms = documento.itens.reduce((s, i) => s + (i.valorIcms ?? 0), 0);
24
- const valorDesc = documento.itens.reduce((s, i) => s + (i.valorDesconto ?? 0), 0);
25
- const valorNf = totalProdutos - valorDesc;
26
-
27
- const root = create({ version: '1.0', encoding: 'UTF-8' })
28
- .ele('NFe', { xmlns: 'http://www.portalfiscal.inf.br/nfe' })
29
- .ele('infNFe', { versao: NFE_VERSAO, Id: idInfNFe });
30
-
31
- const inf = root;
32
-
33
- // ide — NFC-e modelo 65
34
- inf
35
- .ele('ide')
36
- .ele('cUF').txt(codigoUf(documento.ide.uf)).up()
37
- .ele('cNF').txt(documento.chaveAcesso.substring(35, 43)).up()
38
- .ele('natOp').txt(documento.ide.naturezaOperacao ?? 'VENDA').up()
39
- .ele('mod').txt('65').up()
40
- .ele('serie').txt(String(documento.ide.serie ?? 1)).up()
41
- .ele('nNF').txt(String(documento.ide.numero)).up()
42
- .ele('dhEmi').txt(dhEmi).up()
43
- .ele('tpNF').txt('1').up()
44
- .ele('idDest').txt('1').up()
45
- .ele('cMunFG').txt(documento.ide.codigoMunicipio).up()
46
- .ele('tpImp').txt('4').up()
47
- .ele('tpEmis').txt('1').up()
48
- .ele('cDV').txt(documento.chaveAcesso.slice(-1)).up()
49
- .ele('tpAmb').txt(String(ambiente)).up()
50
- .ele('finNFe').txt('1').up()
51
- .ele('indFinal').txt('1').up()
52
- .ele('indPres').txt(String(documento.ide.presenca ?? 1)).up()
53
- .ele('procEmi').txt('0').up()
54
- .ele('verProc').txt('ghinfe-0.3.0').up()
55
- .up();
56
-
57
- // emit
58
- const emit = inf.ele('emit');
59
- emit.ele('CNPJ').txt(documento.emitente.cnpj.replace(/\D/g, '')).up();
60
- emit.ele('xNome').txt(documento.emitente.razaoSocial).up();
61
- if (documento.emitente.nomeFantasia) {
62
- emit.ele('xFant').txt(documento.emitente.nomeFantasia).up();
63
- }
64
- appendEndereco(emit, 'enderEmit', documento.emitente.endereco);
65
- emit.ele('IE').txt(documento.emitente.ie).up();
66
- emit.ele('CRT').txt(documento.emitente.crt).up();
67
- emit.up();
68
-
69
- // dest — opcional na NFC-e (se informado CPF/CNPJ, exige indIEDest ou enderDest)
70
- if (documento.destinatario?.cpf || documento.destinatario?.cnpj) {
71
- const dest = inf.ele('dest');
72
- const docDest = (documento.destinatario.cnpj ?? documento.destinatario.cpf ?? '').replace(/\D/g, '');
73
- if (docDest.length === 14) dest.ele('CNPJ').txt(docDest).up();
74
- else if (docDest.length === 11) dest.ele('CPF').txt(docDest).up();
75
- if (documento.destinatario.razaoSocial) {
76
- dest.ele('xNome').txt(documento.destinatario.razaoSocial).up();
77
- }
78
- if (documento.destinatario.endereco) {
79
- appendEndereco(dest, 'enderDest', documento.destinatario.endereco);
80
- } else {
81
- dest.ele('indIEDest').txt('9').up();
82
- }
83
- dest.up();
84
- }
85
-
86
- // det — itens
87
- documento.itens.forEach((item, index) => {
88
- const det = inf.ele('det', { nItem: String(index + 1) });
89
- const prod = det.ele('prod');
90
- prod.ele('cProd').txt(item.codigo).up();
91
- prod.ele('cEAN').txt(item.ean ?? 'SEM GTIN').up();
92
- prod.ele('xProd').txt(item.descricao).up();
93
- prod.ele('NCM').txt(item.ncm).up();
94
- prod.ele('CFOP').txt(item.cfop).up();
95
- prod.ele('uCom').txt(item.unidade).up();
96
- prod.ele('qCom').txt(formatDecimal(item.quantidade, 4)).up();
97
- prod.ele('vUnCom').txt(formatDecimal(item.valorUnitario, 10)).up();
98
- prod.ele('vProd').txt(formatDecimal(item.valorTotal, 2)).up();
99
- prod.ele('cEANTrib').txt(item.ean ?? 'SEM GTIN').up();
100
- prod.ele('uTrib').txt(item.unidade).up();
101
- prod.ele('qTrib').txt(formatDecimal(item.quantidade, 4)).up();
102
- prod.ele('vUnTrib').txt(formatDecimal(item.valorUnitario, 10)).up();
103
- prod.ele('indTot').txt('1').up();
104
- prod.up();
105
-
106
- appendImpostosItem(det.ele('imposto'), item);
107
- det.up();
108
- });
109
-
110
- // total
111
- const total = inf.ele('total').ele('ICMSTot');
112
- total
113
- .ele('vBC').txt(formatDecimal(totalProdutos, 2)).up()
114
- .ele('vICMS').txt(formatDecimal(valorIcms, 2)).up()
115
- .ele('vICMSDeson').txt('0.00').up()
116
- .ele('vFCP').txt('0.00').up()
117
- .ele('vBCST').txt('0.00').up()
118
- .ele('vST').txt('0.00').up()
119
- .ele('vFCPST').txt('0.00').up()
120
- .ele('vFCPSTRet').txt('0.00').up()
121
- .ele('vProd').txt(formatDecimal(totalProdutos, 2)).up()
122
- .ele('vFrete').txt('0.00').up()
123
- .ele('vSeg').txt('0.00').up()
124
- .ele('vDesc').txt(formatDecimal(valorDesc, 2)).up()
125
- .ele('vII').txt('0.00').up()
126
- .ele('vIPI').txt('0.00').up()
127
- .ele('vIPIDevol').txt('0.00').up()
128
- .ele('vPIS').txt('0.00').up()
129
- .ele('vCOFINS').txt('0.00').up()
130
- .ele('vOutro').txt('0.00').up()
131
- .ele('vNF').txt(formatDecimal(valorNf, 2)).up();
132
- total.up().up();
133
-
134
- // transp — NFC-e sem frete
135
- inf.ele('transp').ele('modFrete').txt('9').up().up();
136
-
137
- // pag
138
- const pag = inf.ele('pag');
139
- const pagamentos = documento.pagamentos ?? [{ forma: '01', valor: valorNf }];
140
- pagamentos.forEach((p) => {
141
- const detPag = pag.ele('detPag');
142
- detPag.ele('tPag').txt(p.forma).up();
143
- detPag.ele('vPag').txt(formatDecimal(p.valor, 2)).up();
144
- detPag.up();
145
- });
146
- pag.up();
147
-
148
- // infAdic
149
- if (documento.informacoesComplementares || documento.informacoesFisco) {
150
- const infAdic = inf.ele('infAdic');
151
- if (documento.informacoesFisco) {
152
- infAdic.ele('infAdFisco').txt(documento.informacoesFisco).up();
153
- }
154
- if (documento.informacoesComplementares) {
155
- infAdic.ele('infCpl').txt(documento.informacoesComplementares).up();
156
- }
157
- infAdic.up();
158
- }
159
-
160
- return root.end({ prettyPrint: false, headless: false });
161
- }
162
-
163
- /** @param {import('../types/NFCeDocument.js').NFCeDocumento} documento */
164
- #validar(documento) {
165
- if (!documento.chaveAcesso || documento.chaveAcesso.length !== 44) {
166
- throw new GhinfeError('chaveAcesso deve conter 44 dígitos', 'INVALID_CHAVE');
167
- }
168
- if (!documento.emitente?.cnpj) {
169
- throw new GhinfeError('emitente.cnpj é obrigatório', 'INVALID_EMITENTE');
170
- }
171
- if (!documento.itens?.length) {
172
- throw new GhinfeError('A NFC-e deve conter ao menos um item', 'INVALID_ITENS');
173
- }
174
- if (!documento.csc?.idCSC || !documento.csc?.codigo) {
175
- throw new GhinfeError('csc.idCSC e csc.codigo são obrigatórios para QR Code', 'INVALID_CSC');
176
- }
177
- }
178
- }
1
+ import { create } from 'xmlbuilder2';
2
+ import { NFE_VERSAO } from '../../constants/sefaz.js';
3
+ import { formatSefazDateTime } from '../../utils/date.utils.js';
4
+ import { GhinfeError } from '../../errors/GhinfeError.js';
5
+ import { codigoUf, formatDecimal, appendEndereco, appendImpostosItem } from '../../shared/fiscal.helpers.js';
6
+
7
+ /**
8
+ * Monta XML da NFC-e (modelo 65, layout 4.00).
9
+ */
10
+ export class NFCeXmlBuilder {
11
+ /**
12
+ * @param {import('../types/NFCeDocument.js').NFCeDocumento} documento
13
+ * @returns {string}
14
+ */
15
+ build(documento) {
16
+ this.#validar(documento);
17
+
18
+ const dhEmi = formatSefazDateTime();
19
+ const idInfNFe = `NFe${documento.chaveAcesso}`;
20
+ const ambiente = documento.ambiente ?? 2;
21
+
22
+ const totalProdutos = documento.itens.reduce((s, i) => s + i.valorTotal, 0);
23
+ const valorIcms = documento.itens.reduce((s, i) => s + (i.valorIcms ?? 0), 0);
24
+ const valorDesc = documento.itens.reduce((s, i) => s + (i.valorDesconto ?? 0), 0);
25
+ const valorNf = totalProdutos - valorDesc;
26
+
27
+ const root = create({ version: '1.0', encoding: 'UTF-8' })
28
+ .ele('NFe', { xmlns: 'http://www.portalfiscal.inf.br/nfe' })
29
+ .ele('infNFe', { versao: NFE_VERSAO, Id: idInfNFe });
30
+
31
+ const inf = root;
32
+
33
+ // ide — NFC-e modelo 65
34
+ inf
35
+ .ele('ide')
36
+ .ele('cUF').txt(codigoUf(documento.ide.uf)).up()
37
+ .ele('cNF').txt(documento.chaveAcesso.substring(35, 43)).up()
38
+ .ele('natOp').txt(documento.ide.naturezaOperacao ?? 'VENDA').up()
39
+ .ele('mod').txt('65').up()
40
+ .ele('serie').txt(String(documento.ide.serie ?? 1)).up()
41
+ .ele('nNF').txt(String(documento.ide.numero)).up()
42
+ .ele('dhEmi').txt(dhEmi).up()
43
+ .ele('tpNF').txt('1').up()
44
+ .ele('idDest').txt('1').up()
45
+ .ele('cMunFG').txt(documento.ide.codigoMunicipio).up()
46
+ .ele('tpImp').txt('4').up()
47
+ .ele('tpEmis').txt('1').up()
48
+ .ele('cDV').txt(documento.chaveAcesso.slice(-1)).up()
49
+ .ele('tpAmb').txt(String(ambiente)).up()
50
+ .ele('finNFe').txt('1').up()
51
+ .ele('indFinal').txt('1').up()
52
+ .ele('indPres').txt(String(documento.ide.presenca ?? 1)).up()
53
+ .ele('procEmi').txt('0').up()
54
+ .ele('verProc').txt('ghinfe-0.3.0').up()
55
+ .up();
56
+
57
+ // emit
58
+ const emit = inf.ele('emit');
59
+ emit.ele('CNPJ').txt(documento.emitente.cnpj.replace(/\D/g, '')).up();
60
+ emit.ele('xNome').txt(documento.emitente.razaoSocial).up();
61
+ if (documento.emitente.nomeFantasia) {
62
+ emit.ele('xFant').txt(documento.emitente.nomeFantasia).up();
63
+ }
64
+ appendEndereco(emit, 'enderEmit', documento.emitente.endereco);
65
+ emit.ele('IE').txt(documento.emitente.ie).up();
66
+ emit.ele('CRT').txt(documento.emitente.crt).up();
67
+ emit.up();
68
+
69
+ // dest — opcional na NFC-e (se informado CPF/CNPJ, exige indIEDest ou enderDest)
70
+ if (documento.destinatario?.cpf || documento.destinatario?.cnpj) {
71
+ const dest = inf.ele('dest');
72
+ const docDest = (documento.destinatario.cnpj ?? documento.destinatario.cpf ?? '').replace(/\D/g, '');
73
+ if (docDest.length === 14) dest.ele('CNPJ').txt(docDest).up();
74
+ else if (docDest.length === 11) dest.ele('CPF').txt(docDest).up();
75
+ if (documento.destinatario.razaoSocial) {
76
+ dest.ele('xNome').txt(documento.destinatario.razaoSocial).up();
77
+ }
78
+ if (documento.destinatario.endereco) {
79
+ appendEndereco(dest, 'enderDest', documento.destinatario.endereco);
80
+ } else {
81
+ dest.ele('indIEDest').txt('9').up();
82
+ }
83
+ dest.up();
84
+ }
85
+
86
+ // det — itens
87
+ documento.itens.forEach((item, index) => {
88
+ const det = inf.ele('det', { nItem: String(index + 1) });
89
+ const prod = det.ele('prod');
90
+ prod.ele('cProd').txt(item.codigo).up();
91
+ prod.ele('cEAN').txt(item.ean ?? 'SEM GTIN').up();
92
+ prod.ele('xProd').txt(item.descricao).up();
93
+ prod.ele('NCM').txt(item.ncm).up();
94
+ prod.ele('CFOP').txt(item.cfop).up();
95
+ prod.ele('uCom').txt(item.unidade).up();
96
+ prod.ele('qCom').txt(formatDecimal(item.quantidade, 4)).up();
97
+ prod.ele('vUnCom').txt(formatDecimal(item.valorUnitario, 10)).up();
98
+ prod.ele('vProd').txt(formatDecimal(item.valorTotal, 2)).up();
99
+ prod.ele('cEANTrib').txt(item.ean ?? 'SEM GTIN').up();
100
+ prod.ele('uTrib').txt(item.unidade).up();
101
+ prod.ele('qTrib').txt(formatDecimal(item.quantidade, 4)).up();
102
+ prod.ele('vUnTrib').txt(formatDecimal(item.valorUnitario, 10)).up();
103
+ prod.ele('indTot').txt('1').up();
104
+ prod.up();
105
+
106
+ appendImpostosItem(det.ele('imposto'), item);
107
+ det.up();
108
+ });
109
+
110
+ // total
111
+ const total = inf.ele('total').ele('ICMSTot');
112
+ total
113
+ .ele('vBC').txt(formatDecimal(totalProdutos, 2)).up()
114
+ .ele('vICMS').txt(formatDecimal(valorIcms, 2)).up()
115
+ .ele('vICMSDeson').txt('0.00').up()
116
+ .ele('vFCP').txt('0.00').up()
117
+ .ele('vBCST').txt('0.00').up()
118
+ .ele('vST').txt('0.00').up()
119
+ .ele('vFCPST').txt('0.00').up()
120
+ .ele('vFCPSTRet').txt('0.00').up()
121
+ .ele('vProd').txt(formatDecimal(totalProdutos, 2)).up()
122
+ .ele('vFrete').txt('0.00').up()
123
+ .ele('vSeg').txt('0.00').up()
124
+ .ele('vDesc').txt(formatDecimal(valorDesc, 2)).up()
125
+ .ele('vII').txt('0.00').up()
126
+ .ele('vIPI').txt('0.00').up()
127
+ .ele('vIPIDevol').txt('0.00').up()
128
+ .ele('vPIS').txt('0.00').up()
129
+ .ele('vCOFINS').txt('0.00').up()
130
+ .ele('vOutro').txt('0.00').up()
131
+ .ele('vNF').txt(formatDecimal(valorNf, 2)).up();
132
+ total.up().up();
133
+
134
+ // transp — NFC-e sem frete
135
+ inf.ele('transp').ele('modFrete').txt('9').up().up();
136
+
137
+ // pag
138
+ const pag = inf.ele('pag');
139
+ const pagamentos = documento.pagamentos ?? [{ forma: '01', valor: valorNf }];
140
+ pagamentos.forEach((p) => {
141
+ const detPag = pag.ele('detPag');
142
+ detPag.ele('tPag').txt(p.forma).up();
143
+ detPag.ele('vPag').txt(formatDecimal(p.valor, 2)).up();
144
+ detPag.up();
145
+ });
146
+ pag.up();
147
+
148
+ // infAdic
149
+ if (documento.informacoesComplementares || documento.informacoesFisco) {
150
+ const infAdic = inf.ele('infAdic');
151
+ if (documento.informacoesFisco) {
152
+ infAdic.ele('infAdFisco').txt(documento.informacoesFisco).up();
153
+ }
154
+ if (documento.informacoesComplementares) {
155
+ infAdic.ele('infCpl').txt(documento.informacoesComplementares).up();
156
+ }
157
+ infAdic.up();
158
+ }
159
+
160
+ return root.end({ prettyPrint: false, headless: false });
161
+ }
162
+
163
+ /** @param {import('../types/NFCeDocument.js').NFCeDocumento} documento */
164
+ #validar(documento) {
165
+ if (!documento.chaveAcesso || documento.chaveAcesso.length !== 44) {
166
+ throw new GhinfeError('chaveAcesso deve conter 44 dígitos', 'INVALID_CHAVE');
167
+ }
168
+ if (!documento.emitente?.cnpj) {
169
+ throw new GhinfeError('emitente.cnpj é obrigatório', 'INVALID_EMITENTE');
170
+ }
171
+ if (!documento.itens?.length) {
172
+ throw new GhinfeError('A NFC-e deve conter ao menos um item', 'INVALID_ITENS');
173
+ }
174
+ if (!documento.csc?.idCSC || !documento.csc?.codigo) {
175
+ throw new GhinfeError('csc.idCSC e csc.codigo são obrigatórios para QR Code', 'INVALID_CSC');
176
+ }
177
+ }
178
+ }
@@ -1,26 +1,26 @@
1
- /** URLs de consulta QR Code NFC-e por UF e ambiente. */
2
- export const NFCE_QRCODE_URLS = {
3
- SP: {
4
- 1: 'https://www.nfce.fazenda.sp.gov.br/NFCeConsultaPublica/Paginas/ConsultaQRCode.aspx',
5
- 2: 'https://www.homologacao.nfce.fazenda.sp.gov.br/NFCeConsultaPublica/Paginas/ConsultaQRCode.aspx',
6
- },
7
- PR: {
8
- 1: 'http://www.fazenda.pr.gov.br/nfce/qrcode',
9
- 2: 'http://www.fazenda.pr.gov.br/nfce/qrcode',
10
- },
11
- RS: {
12
- 1: 'https://www.sefaz.rs.gov.br/NFCE/NFCE-COM-QRCode',
13
- 2: 'https://www.sefaz.rs.gov.br/NFCE/NFCE-COM-QRCode',
14
- },
15
- };
16
-
17
- /** URLs de consulta por chave (portal SEFAZ). */
18
- export const NFCE_URL_CHAVE = {
19
- SP: {
20
- 1: 'https://www.nfce.fazenda.sp.gov.br/consulta',
21
- 2: 'https://www.homologacao.nfce.fazenda.sp.gov.br/consulta',
22
- },
23
- };
24
-
25
- /** Versão do QR Code NFC-e (2 = atual). */
26
- export const NFCE_QRCODE_VERSAO = '2';
1
+ /** URLs de consulta QR Code NFC-e por UF e ambiente. */
2
+ export const NFCE_QRCODE_URLS = {
3
+ SP: {
4
+ 1: 'https://www.nfce.fazenda.sp.gov.br/NFCeConsultaPublica/Paginas/ConsultaQRCode.aspx',
5
+ 2: 'https://www.homologacao.nfce.fazenda.sp.gov.br/NFCeConsultaPublica/Paginas/ConsultaQRCode.aspx',
6
+ },
7
+ PR: {
8
+ 1: 'http://www.fazenda.pr.gov.br/nfce/qrcode',
9
+ 2: 'http://www.fazenda.pr.gov.br/nfce/qrcode',
10
+ },
11
+ RS: {
12
+ 1: 'https://www.sefaz.rs.gov.br/NFCE/NFCE-COM-QRCode',
13
+ 2: 'https://www.sefaz.rs.gov.br/NFCE/NFCE-COM-QRCode',
14
+ },
15
+ };
16
+
17
+ /** URLs de consulta por chave (portal SEFAZ). */
18
+ export const NFCE_URL_CHAVE = {
19
+ SP: {
20
+ 1: 'https://www.nfce.fazenda.sp.gov.br/consulta',
21
+ 2: 'https://www.homologacao.nfce.fazenda.sp.gov.br/consulta',
22
+ },
23
+ };
24
+
25
+ /** Versão do QR Code NFC-e (2 = atual). */
26
+ export const NFCE_QRCODE_VERSAO = '2';