node-sped-nfe 1.2.41 → 1.2.43
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.
- package/dist/utils/eventos.js +346 -555
- package/dist/utils/make.js +12 -4
- package/dist/utils/tools.js +28 -28
- package/package.json +3 -2
package/dist/utils/make.js
CHANGED
|
@@ -21,6 +21,9 @@ class Make {
|
|
|
21
21
|
vBC: 0,
|
|
22
22
|
vICMS: 0,
|
|
23
23
|
vICMSDeson: 0,
|
|
24
|
+
vFCPUFDest: 0,
|
|
25
|
+
vICMSUFDest: 0,
|
|
26
|
+
vICMSUFRemet: 0,
|
|
24
27
|
vFCP: 0,
|
|
25
28
|
vBCST: 0,
|
|
26
29
|
vST: 0,
|
|
@@ -36,7 +39,8 @@ class Make {
|
|
|
36
39
|
vPIS: 0,
|
|
37
40
|
vCOFINS: 0,
|
|
38
41
|
vOutro: 0,
|
|
39
|
-
vNF: 0
|
|
42
|
+
vNF: 0,
|
|
43
|
+
vTotTrib: 0
|
|
40
44
|
});
|
|
41
45
|
}
|
|
42
46
|
formatData(dataUsr = new Date()) {
|
|
@@ -165,7 +169,12 @@ class Make {
|
|
|
165
169
|
obj[cont].prod.qTrib = (obj[cont].prod.qTrib * 1).toFixed(4);
|
|
166
170
|
obj[cont].prod.vUnTrib = (obj[cont].prod.vUnTrib * 1).toFixed(10);
|
|
167
171
|
//Calcular ICMSTot
|
|
168
|
-
__classPrivateFieldGet(this, _Make_instances, "m", _Make_calICMSTot).call(this,
|
|
172
|
+
__classPrivateFieldGet(this, _Make_instances, "m", _Make_calICMSTot).call(this, {
|
|
173
|
+
...obj[cont].prod,
|
|
174
|
+
...{
|
|
175
|
+
vNF: ((obj[cont].prod.vUnCom - (obj[cont].prod?.vDesc || 0)) * obj[cont].prod.qTrib).toFixed(2)
|
|
176
|
+
}
|
|
177
|
+
});
|
|
169
178
|
}
|
|
170
179
|
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.det = obj;
|
|
171
180
|
}
|
|
@@ -345,7 +354,6 @@ class Make {
|
|
|
345
354
|
__classPrivateFieldGet(this, _Make_instances, "m", _Make_calICMSTot).call(this, obj);
|
|
346
355
|
}
|
|
347
356
|
tagProdICMSUFDest(index, obj) {
|
|
348
|
-
console.log(__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.total);
|
|
349
357
|
if (__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.det[index].imposto.ICMSUFDest === undefined)
|
|
350
358
|
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.det[index].imposto.ICMSUFDest = {};
|
|
351
359
|
Object.keys(obj).forEach(key => {
|
|
@@ -670,7 +678,7 @@ class Make {
|
|
|
670
678
|
//Como ja temos cUF, vamos usar o extras.cUF2UF
|
|
671
679
|
let tempUF = urlEventos(cUF2UF[__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.cUF], __classPrivateFieldGet(this, _Make_NFe, "f").infNFe['@versao']);
|
|
672
680
|
__classPrivateFieldGet(this, _Make_NFe, "f").infNFeSupl = {
|
|
673
|
-
qrCode: tempUF.mod65[__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.tpAmb == 1 ? 'producao' : 'homologacao'].
|
|
681
|
+
qrCode: tempUF.mod65[__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.tpAmb == 1 ? 'producao' : 'homologacao'].NfeConsultaQR, //Este não e o valor final, vamos utilizar apenas para carregar os dados que vão ser utlizados no make
|
|
674
682
|
urlChave: tempUF.mod65[__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.tpAmb == 1 ? 'producao' : 'homologacao'].urlChave
|
|
675
683
|
};
|
|
676
684
|
}
|
package/dist/utils/tools.js
CHANGED
|
@@ -22,8 +22,6 @@ import { fileURLToPath } from 'url';
|
|
|
22
22
|
import pem from 'pem';
|
|
23
23
|
import { cUF2UF, json2xml, xml2json, formatData, UF2cUF } from "./extras.js";
|
|
24
24
|
import { SignedXml } from 'xml-crypto';
|
|
25
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
26
|
-
const __dirname = path.dirname(__filename);
|
|
27
25
|
class Tools {
|
|
28
26
|
constructor(config = { mod: "", xmllint: 'xmllint', UF: '', tpAmb: 2, CSC: "", CSCid: "", versao: "4.00", timeout: 30, openssl: null, CPF: "", CNPJ: "" }, certificado = { pfx: "", senha: "" }) {
|
|
29
27
|
_Tools_instances.add(this);
|
|
@@ -178,8 +176,10 @@ class Tools {
|
|
|
178
176
|
let UF = cUF2UF[cUF];
|
|
179
177
|
let mod = `${chNFe}`.substring(20, 22);
|
|
180
178
|
//https://www.nfe.fazenda.gov.br/portal/webservices.aspx?AspxAutoDetectCookieSupport=1
|
|
181
|
-
if ([
|
|
179
|
+
if (["AC", "AL", "AP", "CE", "DF", "ES", "PA", "PB", "PI", "RJ", "RN", "RO", "RR", "SC", "SE", "TO"].includes(UF))
|
|
182
180
|
UF = 'SVRS';
|
|
181
|
+
if (["MA"].includes(UF))
|
|
182
|
+
UF = 'SVAN';
|
|
183
183
|
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").tpAmb === "undefined")
|
|
184
184
|
throw "consultarNFe({...tpAmb}) -> não definido!";
|
|
185
185
|
let consSitNFe = {
|
|
@@ -256,22 +256,6 @@ class Tools {
|
|
|
256
256
|
throw "sefazEvento({tpEvento}) -> não definido!";
|
|
257
257
|
if (!__classPrivateFieldGet(this, _Tools_config, "f").CNPJ && !__classPrivateFieldGet(this, _Tools_config, "f").CPF)
|
|
258
258
|
throw "new Tools({CNPJ|CPF}) -> não definido!";
|
|
259
|
-
const geradorLote = function () {
|
|
260
|
-
const agora = new Date();
|
|
261
|
-
const ano = agora.getFullYear().toString().slice(2); // Só os 2 últimos dígitos do ano
|
|
262
|
-
const mes = String(agora.getMonth() + 1).padStart(2, '0');
|
|
263
|
-
const dia = String(agora.getDate()).padStart(2, '0');
|
|
264
|
-
const hora = String(agora.getHours()).padStart(2, '0');
|
|
265
|
-
const minuto = String(agora.getMinutes()).padStart(2, '0');
|
|
266
|
-
const segundo = String(agora.getSeconds()).padStart(2, '0');
|
|
267
|
-
// Junta tudo
|
|
268
|
-
let idLote = `${ano}${mes}${dia}${hora}${minuto}${segundo}`;
|
|
269
|
-
// Se ainda tiver menos de 15 dígitos, adiciona um número aleatório no final
|
|
270
|
-
while (idLote.length < 15) {
|
|
271
|
-
idLote += Math.floor(Math.random() * 10); // Adiciona dígitos aleatórios
|
|
272
|
-
}
|
|
273
|
-
return idLote;
|
|
274
|
-
};
|
|
275
259
|
let detEvento = {
|
|
276
260
|
"@versao": "1.00",
|
|
277
261
|
"descEvento": __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_descEvento).call(this, `${tpEvento}`)
|
|
@@ -389,10 +373,16 @@ class Tools {
|
|
|
389
373
|
try {
|
|
390
374
|
if (!chNFe && !ultNSU)
|
|
391
375
|
throw "sefazDistDFe({chNFe|ultNSU})";
|
|
392
|
-
if (!__classPrivateFieldGet(this, _Tools_config, "f").CNPJ)
|
|
393
|
-
throw "CNPJ
|
|
394
|
-
if (__classPrivateFieldGet(this, _Tools_config, "f").
|
|
395
|
-
|
|
376
|
+
if (!__classPrivateFieldGet(this, _Tools_config, "f").CNPJ && !__classPrivateFieldGet(this, _Tools_config, "f").CPF)
|
|
377
|
+
throw "Tools({CNPJ|CPF})";
|
|
378
|
+
if (__classPrivateFieldGet(this, _Tools_config, "f").CPF != undefined) {
|
|
379
|
+
if (__classPrivateFieldGet(this, _Tools_config, "f").CPF.length !== 11)
|
|
380
|
+
throw "Tools({CPF}) inválido!";
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
if (__classPrivateFieldGet(this, _Tools_config, "f").CNPJ.length !== 14)
|
|
384
|
+
throw "Tools({CNPJ}) inválido!";
|
|
385
|
+
}
|
|
396
386
|
// Gera o XML da consulta
|
|
397
387
|
// Prepara o SOAP
|
|
398
388
|
var xmlSing = await json2xml({
|
|
@@ -428,8 +418,8 @@ class Tools {
|
|
|
428
418
|
}
|
|
429
419
|
}
|
|
430
420
|
});
|
|
431
|
-
// HTTPS Request
|
|
432
|
-
const req = https.request(tempUF[`
|
|
421
|
+
// HTTPS Request, trava modelo 55
|
|
422
|
+
const req = https.request(tempUF[`mod55`][(__classPrivateFieldGet(this, _Tools_config, "f").tpAmb == 1 ? "producao" : "homologacao")].NFeDistribuicaoDFe, {
|
|
433
423
|
...{
|
|
434
424
|
method: 'POST',
|
|
435
425
|
headers: {
|
|
@@ -480,13 +470,12 @@ class Tools {
|
|
|
480
470
|
throw "sefazStatus({...tpAmb}) -> não definido!";
|
|
481
471
|
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").mod == "undefined")
|
|
482
472
|
throw "sefazStatus({...mod}) -> não definido!";
|
|
483
|
-
let tempUF = urlEventos(__classPrivateFieldGet(this, _Tools_config, "f").UF, __classPrivateFieldGet(this, _Tools_config, "f").versao);
|
|
484
473
|
//Separado para validar o corpo da consulta
|
|
485
474
|
let consStatServ = {
|
|
486
475
|
"@versao": "4.00",
|
|
487
476
|
"@xmlns": "http://www.portalfiscal.inf.br/nfe",
|
|
488
477
|
"tpAmb": __classPrivateFieldGet(this, _Tools_config, "f").tpAmb,
|
|
489
|
-
"cUF":
|
|
478
|
+
"cUF": UF2cUF[__classPrivateFieldGet(this, _Tools_config, "f").UF],
|
|
490
479
|
"xServ": "STATUS"
|
|
491
480
|
};
|
|
492
481
|
let xmlObj = {
|
|
@@ -515,6 +504,7 @@ class Tools {
|
|
|
515
504
|
headers: {
|
|
516
505
|
'Content-Type': 'application/soap+xml; charset=utf-8',
|
|
517
506
|
'Content-Length': xml.length,
|
|
507
|
+
'SOAPAction': 'http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico4/nfeStatusServicoNF'
|
|
518
508
|
},
|
|
519
509
|
rejectUnauthorized: false
|
|
520
510
|
},
|
|
@@ -619,7 +609,17 @@ async function _Tools_xmlValido(xml, xsd) {
|
|
|
619
609
|
return new Promise((resolve, reject) => {
|
|
620
610
|
const xmlFile = tmp.fileSync({ mode: 0o644, prefix: 'xml-', postfix: '.xml' });
|
|
621
611
|
fs.writeFileSync(xmlFile.name, xml, { encoding: 'utf8' });
|
|
622
|
-
|
|
612
|
+
//Obter caminho, dos schemas
|
|
613
|
+
var schemaPath = "";
|
|
614
|
+
try { //NW.js + ElectronJS
|
|
615
|
+
schemaPath = path.dirname(require.resolve("node-sped-nfe"));
|
|
616
|
+
schemaPath = path.resolve(`${path.join(schemaPath, "..", "schemas")}/PL_010_V1/${xsd}.xsd`);
|
|
617
|
+
}
|
|
618
|
+
catch (error) { //Caso o require seja desativo
|
|
619
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
620
|
+
const __dirname = path.dirname(__filename);
|
|
621
|
+
schemaPath = path.resolve(__dirname, `../../schemas/PL_010_V1/${xsd}.xsd`);
|
|
622
|
+
}
|
|
623
623
|
const verif = spawnSync(__classPrivateFieldGet(this, _Tools_config, "f").xmllint, ['--noout', '--schema', schemaPath, xmlFile.name], { encoding: 'utf8' });
|
|
624
624
|
xmlFile.removeCallback();
|
|
625
625
|
// Aqui, usamos o operador de encadeamento opcional (?.)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-sped-nfe",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.43",
|
|
4
4
|
"author": "Kalmon V. Tavares",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"import": "./dist/index.js",
|
|
22
22
|
"require": "./dist/index.js",
|
|
23
23
|
"types": "./dist/index.d.ts"
|
|
24
|
-
}
|
|
24
|
+
},
|
|
25
|
+
"./schemas/*": "./schemas/*"
|
|
25
26
|
},
|
|
26
27
|
"scripts": {
|
|
27
28
|
"build": "tsc > saida.txt",
|