node-sped-nfe 1.2.1 → 1.2.3

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.
@@ -442,17 +442,15 @@ class Make {
442
442
  __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.total = {
443
443
  ICMSTot: {}
444
444
  };
445
- if (obj != null) {
445
+ Object.keys(__classPrivateFieldGet(this, _Make_ICMSTot, "f")).forEach(key => {
446
+ __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.total.ICMSTot[key] = (__classPrivateFieldGet(this, _Make_ICMSTot, "f")[key] * 1).toFixed(2);
447
+ });
448
+ __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.total.ICMSTot.vNF = (__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.total.ICMSTot.vProd - __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.total.ICMSTot.vDesc).toFixed(2);
449
+ if (obj != null) { // Substituir campos que deseja
446
450
  Object.keys(obj).forEach(key => {
447
451
  __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.total.ICMSTot[key] = obj[key];
448
452
  });
449
453
  }
450
- else {
451
- Object.keys(__classPrivateFieldGet(this, _Make_ICMSTot, "f")).forEach(key => {
452
- __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.total.ICMSTot[key] = (__classPrivateFieldGet(this, _Make_ICMSTot, "f")[key] * 1).toFixed(2);
453
- });
454
- __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.total.ICMSTot.vNF = (__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.total.ICMSTot.vProd - __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.total.ICMSTot.vDesc).toFixed(2);
455
- }
456
454
  }
457
455
  tagISSQNTot(obj) {
458
456
  throw "Não implementado!";
@@ -22,13 +22,13 @@ declare class Tools {
22
22
  json2xml(obj: object): Promise<string>;
23
23
  getCertificado(): Promise<object>;
24
24
  consultarNFe(chNFe: string): Promise<string>;
25
- sefazEvento({ chNFe, tpEvento, nProt, justificativa, textoCorrecao, sequencial }: {
25
+ sefazEvento({ chNFe, tpEvento, nProt, xJust, nSeqEvento, dhEvento }: {
26
26
  chNFe?: string | undefined;
27
27
  tpEvento?: string | undefined;
28
28
  nProt?: string | undefined;
29
- justificativa?: string | undefined;
30
- textoCorrecao?: string | undefined;
31
- sequencial?: number | undefined;
29
+ xJust?: string | undefined;
30
+ nSeqEvento?: number | undefined;
31
+ dhEvento?: string | undefined;
32
32
  }): Promise<string>;
33
33
  sefazDistDFe({ ultNSU, chNFe }: {
34
34
  ultNSU?: string;
@@ -20,7 +20,7 @@ import fs from "fs";
20
20
  import path from 'path';
21
21
  import { fileURLToPath } from 'url';
22
22
  import pem from 'pem';
23
- import { cUF2UF, json2xml, xml2json, UF2cUF } from "./extras.js";
23
+ import { cUF2UF, json2xml, xml2json, formatData, UF2cUF } from "./extras.js";
24
24
  import { SignedXml } from 'xml-crypto';
25
25
  const __filename = fileURLToPath(import.meta.url);
26
26
  const __dirname = path.dirname(__filename);
@@ -103,7 +103,7 @@ class Tools {
103
103
  });
104
104
  res.on('end', () => {
105
105
  xml2json(data).then((jRes) => {
106
- json2xml(jRes['soap:Envelope']['soap:Body']).then(resolve).catch(reject);
106
+ json2xml(jRes['soapenv:Envelope']?.['soapenv:Body']?.['nfeResultMsg'] || jRes['soap:Envelope']?.['soap:Body']?.['nfeResultMsg']).then(resolve).catch(reject);
107
107
  });
108
108
  });
109
109
  });
@@ -217,7 +217,7 @@ class Tools {
217
217
  res.on('data', (chunk) => data += chunk);
218
218
  res.on('end', () => {
219
219
  xml2json(data).then((jRes) => {
220
- json2xml(jRes['soap:Envelope']['soap:Body']).then(resolve).catch(reject);
220
+ json2xml(jRes['soapenv:Envelope']?.['soapenv:Body']?.['nfeResultMsg'] || jRes['soap:Envelope']?.['soap:Body']?.['nfeResultMsg']).then(resolve).catch(reject);
221
221
  });
222
222
  });
223
223
  });
@@ -237,7 +237,7 @@ class Tools {
237
237
  }
238
238
  });
239
239
  }
240
- async sefazEvento({ chNFe = "", tpEvento = "", nProt = "", justificativa = "", textoCorrecao = "", sequencial = 1 }) {
240
+ async sefazEvento({ chNFe = "", tpEvento = "", nProt = "", xJust = "", nSeqEvento = 1, dhEvento = formatData() }) {
241
241
  return new Promise(async (resolve, reject) => {
242
242
  try {
243
243
  if (!chNFe)
@@ -262,32 +262,33 @@ class Tools {
262
262
  }
263
263
  return idLote;
264
264
  };
265
- const tempUF = urlEventos(`AN`, __classPrivateFieldGet(this, _Tools_config, "f").versao);
266
265
  let detEvento = {
267
266
  "@versao": "1.00",
268
267
  "descEvento": __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_descEvento).call(this, `${tpEvento}`)
269
268
  };
269
+ const cOrgao = !['210200', '210210', '210220', '210240'].includes(tpEvento) ? chNFe.substring(0, 2) : '91';
270
270
  // Adicionar campos específicos por tipo de evento
271
271
  if (tpEvento === "110111") { // Cancelamento
272
272
  if (!nProt)
273
273
  throw "sefazEvento({nProt}) obrigatório para Cancelamento!";
274
- if (!justificativa)
275
- throw "sefazEvento({justificativa}) obrigatório para Cancelamento!";
274
+ if (!xJust)
275
+ throw "sefazEvento({xJust}) obrigatório para Cancelamento!";
276
276
  detEvento["nProt"] = nProt;
277
- detEvento["xJust"] = justificativa;
277
+ detEvento["xJust"] = xJust;
278
278
  }
279
279
  else if (tpEvento === "110110") { // Carta de Correção
280
- if (!textoCorrecao)
281
- throw "sefazEvento({textoCorrecao}) obrigatório para Carta de Correção!";
282
- detEvento["xCorrecao"] = textoCorrecao;
283
- detEvento["xCondUso"] = "A carta de correção é disciplinada pelo § 1º-A do art. do Convênio S/N, de 15 de dezembro de 1970...";
280
+ if (!xJust)
281
+ throw "sefazEvento({xJust}) obrigatório para Carta de Correção!";
282
+ detEvento["xCorrecao"] = xJust;
283
+ detEvento["xCondUso"] = "A Carta de Correcao e disciplinada pelo paragrafo 1o-A do art. 7o do Convenio S/N, de 15 de dezembro de 1970 e pode ser utilizada para regularizacao de erro ocorrido na emissao de documento fiscal, desde que o erro nao esteja relacionado com: I - as variaveis que determinam o valor do imposto tais como: base de calculo, aliquota, diferenca de preco, quantidade, valor da operacao ou da prestacao; II - a correcao de dados cadastrais que implique mudanca do remetente ou do destinatario; III - a data de emissao ou de saida.";
284
284
  }
285
285
  else if (tpEvento === "210240") { // Operação não realizada
286
- if (!justificativa)
287
- throw "sefazEvento({justificativa}) obrigatório para Operação não realizada!";
288
- detEvento["xJust"] = justificativa;
286
+ if (!xJust)
287
+ throw "sefazEvento({xJust}) obrigatório para Operação não realizada!";
288
+ detEvento["xJust"] = xJust;
289
289
  }
290
290
  // Ciência (210210), Confirmação (210200), Desconhecimento (210220) não precisam de campos extras
291
+ const tempUF = urlEventos(cUF2UF[cOrgao], __classPrivateFieldGet(this, _Tools_config, "f").versao);
291
292
  const evento = {
292
293
  "envEvento": {
293
294
  "@xmlns": "http://www.portalfiscal.inf.br/nfe",
@@ -297,14 +298,14 @@ class Tools {
297
298
  "@xmlns": "http://www.portalfiscal.inf.br/nfe",
298
299
  "@versao": "1.00",
299
300
  "infEvento": {
300
- "@Id": `ID${tpEvento}${chNFe}${sequencial.toString().padStart(2, '0')}`,
301
- "cOrgao": "91",
301
+ "@Id": `ID${tpEvento}${chNFe}${nSeqEvento.toString().padStart(2, '0')}`,
302
+ cOrgao,
302
303
  "tpAmb": __classPrivateFieldGet(this, _Tools_config, "f").tpAmb,
303
304
  "CNPJ": __classPrivateFieldGet(this, _Tools_config, "f").CNPJ,
304
305
  "chNFe": chNFe,
305
- "dhEvento": "2025-04-29T14:16:21-03:00",
306
+ dhEvento,
306
307
  "tpEvento": tpEvento,
307
- "nSeqEvento": sequencial,
308
+ "nSeqEvento": nSeqEvento,
308
309
  "verEvento": "1.00",
309
310
  "detEvento": detEvento
310
311
  }
@@ -319,7 +320,10 @@ class Tools {
319
320
  "@xmlns:soap": "http://www.w3.org/2003/05/soap-envelope",
320
321
  "@xmlns:nfe": "http://www.portalfiscal.inf.br/nfe/wsdl/NFeRecepcaoEvento4",
321
322
  "soap:Body": {
322
- "nfe:nfeDadosMsg": await xml2json(xmlSing)
323
+ "nfe:nfeDadosMsg": {
324
+ ...await xml2json(xmlSing),
325
+ "@xmlns": "http://www.portalfiscal.inf.br/nfe/wsdl/NFeRecepcaoEvento4"
326
+ }
323
327
  }
324
328
  }
325
329
  });
@@ -341,7 +345,7 @@ class Tools {
341
345
  });
342
346
  res.on('end', () => {
343
347
  xml2json(data).then((jRes) => {
344
- json2xml(jRes['soap:Envelope']['soap:Body']).then(resolve).catch(reject);
348
+ json2xml(jRes['soapenv:Envelope']?.['soapenv:Body']?.['nfeResultMsg'] || jRes['soap:Envelope']?.['soap:Body']?.['nfeResultMsg']).then(resolve).catch(reject);
345
349
  });
346
350
  });
347
351
  });
@@ -429,7 +433,7 @@ class Tools {
429
433
  });
430
434
  res.on('end', () => {
431
435
  xml2json(data).then((jRes) => {
432
- json2xml(jRes['soap:Envelope']['soap:Body']).then(resolve).catch(reject);
436
+ json2xml(jRes['soapenv:Envelope']?.['soapenv:Body']?.['nfeResultMsg'] || jRes['soap:Envelope']?.['soap:Body']?.['nfeResultMsg']).then(resolve).catch(reject);
433
437
  });
434
438
  });
435
439
  });
@@ -506,7 +510,7 @@ class Tools {
506
510
  });
507
511
  res.on('end', () => {
508
512
  xml2json(data).then((jRes) => {
509
- json2xml(jRes['soap:Envelope']['soap:Body']).then(resolve).catch(reject);
513
+ json2xml(jRes['soapenv:Envelope']?.['soapenv:Body']?.['nfeResultMsg'] || jRes['soap:Envelope']?.['soap:Body']?.['nfeResultMsg']).then(resolve).catch(reject);
510
514
  });
511
515
  });
512
516
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-sped-nfe",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "author": "Kalmon V. Tavares",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",