Skip to content

Commit 7a99de4

Browse files
committed
adicionado arquivo de teste para NFe
1 parent d1cf2a8 commit 7a99de4

File tree

1 file changed

+308
-0
lines changed

1 file changed

+308
-0
lines changed

nfetest.js

+308
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
2+
const fs = require('fs');
3+
const lib = require('./lib');
4+
const signUtils = require('./lib/factory/signature');
5+
const XmlHelper = require('./lib/factory/xmlHelper');
6+
7+
let cert = {
8+
key: fs.readFileSync('C:\\cert\\newKey.key'),
9+
pem: fs.readFileSync('C:\\cert\\test.pem'),
10+
pfx: fs.readFileSync('C:\\cert\\certificado.pfx'),
11+
password: fs.readFileSync('C:\\cert\\senha.txt')
12+
};
13+
14+
let empresa = {
15+
razaoSocial: 'TESTE',
16+
nomeFantasia: 'TESTE',
17+
cnpj: 'OBRIGATORIO',
18+
inscricaoEstadual: 'OBRIGATORIO',
19+
inscricaoMunicipal: '',
20+
codRegimeTributario: '1',//2
21+
endereco: {
22+
logradouro: 'Rua Teste',
23+
numero: 123,
24+
complemento: '',
25+
bairro: 'Bairro Teste',
26+
municipio: 'Cachoeirinha',
27+
codMunicipio: '3550308',
28+
uf: 'SP',
29+
cUf: '35',
30+
cep: '99999999',
31+
telefone: '999999999'
32+
},
33+
certificado: cert,
34+
idCSC: '1',
35+
CSC: ''
36+
};
37+
38+
let responsavelTecnico = {
39+
cnpj: 'empresa teste',
40+
contato: 'teste',
41+
email: 'teste@teste.com',
42+
fone: '999999999',
43+
idCSRT: '01',
44+
CSRT: 'G8063VRTNDMO886SFNK5LDUDEI24XJ22YIPO'
45+
};
46+
47+
let moment = require('moment');
48+
49+
function randomInt(min, max) {
50+
return Math.floor(Math.random() * (max - min + 1)) + min;
51+
}
52+
53+
let documento = {
54+
dhEmissao: moment().format(),
55+
ambiente: '2',
56+
modelo: '55',
57+
numeroNota: randomInt(2, 9999),
58+
serie: '20',
59+
naturezaOperacao: 'VENDA',
60+
tipoDocumentoFiscal: '1',
61+
identificadorDestinoOperacao: '1',
62+
codUF: '35',
63+
codIbgeFatoGerador: '3550308',
64+
processoEmissao: '0',
65+
finalidadeEmissao: '1',
66+
indConsumidorFinal: '1',
67+
indPresenca: '1',
68+
tipoEmissao: '1',
69+
tipoImpressao: '0',
70+
// 0=Sem geração de DANFE;
71+
// 1=DANFE normal, Retrato;
72+
// 2=DANFE normal, Paisagem;
73+
// 3=DANFE Simplificado;
74+
// 4=DANFE NFC-e;
75+
// 5=DANFE NFC-e em mensagem eletrônica (o envio de
76+
// mensagem eletrônica pode ser feita de forma simultânea com a
77+
// impressão do DANFE; usar o tpImp=5 quando esta for a única
78+
// forma de disponibilização do DANFE).
79+
80+
versaoAplicativoEmissao: 'NODE-NFE TEST 1.0',
81+
};
82+
83+
let dest = {
84+
indicadorIEDestinario: '9',
85+
documento: '34493536837',
86+
nome: 'THIAGO FIGLIANO ROSA',
87+
isEstrangeiro: false,
88+
email: '',
89+
endereco: {
90+
logradouro: 'RUA A',
91+
numero: 1,
92+
complemento: '',
93+
bairro: 'CENTRO',
94+
municipio: 'SÃO PAULO',
95+
codMunicipio: '3550308',
96+
cUf: '35',
97+
uf: 'SP',
98+
cep: '03071000',
99+
telefone: ''
100+
}
101+
};
102+
103+
let transp = {
104+
modalidateFrete: '9'
105+
};
106+
107+
let infoAdic = {
108+
infoComplementar: 'TESTE NFE 55'
109+
};
110+
111+
let produtos = [];
112+
let valorProduto = 31.80;
113+
let valorTotalProdutos = 0;
114+
for (let i = 1; i <= 1; i++) {
115+
valorTotalProdutos += valorProduto;
116+
produtos.push({
117+
prod: {
118+
codigo: '84233',
119+
cEAN: '7898221456293',
120+
descricao: 'PRODUTO TESTE',
121+
cest: '2104400',
122+
NCM: '85164000',
123+
CFOP: '5102',
124+
unidadeComercial: 'SAC',
125+
quantidadeComercial: '1.0000',
126+
valorUnitarioComercial: valorProduto.toFixed(2),
127+
valorTotal: valorProduto.toFixed(2),
128+
cEANTrib: '7898221456293',
129+
unidadeTributavel: 'SAC',
130+
quantidadeTributavel: '1.0000',
131+
valorUnitarioTributavel: valorProduto.toFixed(2),
132+
indicadorTotal: '1',
133+
valorFrete: '',
134+
valorSeguro: '',
135+
valorDesconto: '',
136+
valorOutro: '',
137+
numeroPedido: '123',
138+
numeroItemPedido: '1',
139+
},
140+
imposto: {
141+
valorAproximadoTributos: 0,
142+
icms: {
143+
orig: '0',
144+
CSOSN: '400'
145+
},
146+
pis: {
147+
CST: '01',
148+
vBC: 0,
149+
pPIS: 0.17,
150+
vPIS: 0
151+
},
152+
cofins: {
153+
CST: '01',
154+
pCOFINS: 0.81,
155+
vBC: 0,
156+
vCOFINS: 0
157+
}
158+
},
159+
//infoAdicional: 'TEST',
160+
numeroItem: i,
161+
});
162+
}
163+
164+
let pagamento = {
165+
//valorTroco: '',
166+
pagamentos: [{
167+
indicadorFormaPagamento: '',
168+
formaPagamento: '01',
169+
valor: valorTotalProdutos.toFixed(2),
170+
dadosCartao: {
171+
tipoIntegracao: '1',
172+
cnpj: '99999999999999',
173+
bandeira: '01',
174+
codAutorizacao: '1321231231'
175+
}
176+
}]
177+
};
178+
179+
let icmsTot = {
180+
vBC: 0,
181+
vICMS: 0,
182+
vICMSDeson: '0.00',
183+
//vFCPUFDest: '0.00',
184+
//vICMSUFDest:'0.00',
185+
//vICMSUFRemet: '0.00',
186+
vFCP: '0.00',
187+
vBCST: '0.00',
188+
vST: '0.00',
189+
vFCPST: '0.00',
190+
vFCPSTRet: '0.00',
191+
vProd: valorTotalProdutos.toFixed(2),
192+
vFrete: '0.00',
193+
vSeg: '0.00',
194+
vDesc: '0.00',
195+
vII: '0.00',
196+
vIPI: '0.00',
197+
vIPIDevol: '0.00',
198+
vPIS: '0.00',
199+
vCOFINS: '0.00',
200+
vOutro: '0.00',
201+
vNF: valorTotalProdutos.toFixed(2),
202+
//vTotTrib: '0.00',
203+
};
204+
205+
let nfce = {
206+
docFiscal: documento,
207+
destinatario: dest,
208+
produtos: produtos,
209+
total: {icmsTot: icmsTot},
210+
transporte: transp,
211+
pagamento: pagamento,
212+
infoAdicional: infoAdic
213+
};
214+
215+
async function testeEmissaoNFe() {
216+
const nfeProc = new lib.NFeProcessor(empresa, null);
217+
218+
const ini = new Date();
219+
let result = await nfeProc.processarDocumento(nfce);
220+
const fin = new Date();
221+
console.log(`${(fin.getTime() - ini.getTime())/1000}s`)
222+
223+
result = require('util').inspect(result, false, null);
224+
console.log('Resultado Emissão NF-e: \n\n' + result);
225+
}
226+
227+
async function testeEmissaoNFCe() {
228+
const nfeProc = new lib.NFeProcessor(empresa, null);
229+
230+
const ini = new Date();
231+
let result = await nfeProc.processarDocumento(nfce);
232+
const fin = new Date();
233+
console.log(`${(fin.getTime() - ini.getTime())/1000}s`)
234+
235+
result = require('util').inspect(result, false, null);
236+
console.log('Resultado Emissão NFC-e: \n\n' + result);
237+
}
238+
239+
async function testeEmissaoNFCeAsync(empresa) {
240+
const nfeProc = new lib.NFeProcessor(empresa);
241+
242+
const ini = new Date();
243+
let result = await nfeProc.processarDocumentoAsync(nfce);
244+
const fin = new Date();
245+
console.log(`${(fin.getTime() - ini.getTime())/1000}s`)
246+
247+
//result = require('util').inspect(result, false, null);
248+
//console.log('Resultado Emissão NFC-e: \n\n' + result);
249+
}
250+
251+
async function testeEmissaoNFCeContingenciaOffline(empresa) {
252+
const nfeProc = new lib.NFeProcessor(empresa);
253+
254+
nfce.docFiscal.isContingenciaOffline = true;
255+
nfce.docFiscal.dhContingencia = moment().format();
256+
nfce.docFiscal.justificativaContingencia = 'TESTE CONTINGENCIA';
257+
258+
let result = await nfeProc.processarDocumento(nfce);
259+
//console.log('Resultado Geração XML NFC-e Contingencia: \n\n' + require('util').inspect(result, false, null) + '\n\n');
260+
261+
let result_emissao = await nfeProc.transmitirXml(Object(result.retornoContingenciaOffline).xml_gerado,'2', null);
262+
console.log('Resultado Transmissão XML Contingencia: \n\n' + require('util').inspect(result_emissao, false, null));
263+
264+
}
265+
266+
function testeAssinaturaXML() {
267+
//Test assinatura
268+
let xml_test = '<consStatServ id="test" versao="4.00" xmlns="http://www.portalfiscal.inf.br/nfe"><tpAmb>2</tpAmb><cUF>43</cUF><xServ>STATUS</xServ></consStatServ>';
269+
let xmlAssinado = signUtils.Signature.signXmlX509(xml_test, 'consStatServ', cert);
270+
console.log(xmlAssinado)
271+
}
272+
273+
function testeQRcodeNFCe(){
274+
//urls qrcode: http://nfce.encat.org/consulte-sua-nota-qr-code-versao-2-0/
275+
const nfeProc = new lib.NFeProcessor(empresa);
276+
console.log(nfeProc.gerarQRCodeNFCeOnline('https://www.sefaz.rs.gov.br/NFCE/NFCE-COM.aspx?', '43181296418264011920650200000086101048053960', '2', '2', empresa.idCSC, empresa.CSC));
277+
}
278+
279+
// TESTES STATUS SERVICO:
280+
async function testeConsultaStatusServico(empresa, ambiente, modelo) {
281+
const statusProc = new lib.StatusServicoProcessor(empresa, ambiente, modelo);
282+
let result = await statusProc.processarDocumento();
283+
console.log(result.data);
284+
285+
console.log(result.data.retConsStatServ.xMotivo);
286+
}
287+
288+
function testeDesereliaze() {
289+
let xml = `<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><nfeResultMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeStatusServico4"><retConsStatServ versao="4.00" xmlns="http://www.portalfiscal.inf.br/nfe"><tpAmb>2</tpAmb><verAplic>RSnfce201805211008</verAplic><cStat>107</cStat><xMotivo>Servico em Operacao</xMotivo><cUF>43</cUF><dhRecbto>2019-03-21T22:37:44-03:00</dhRecbto><tMed>1</tMed></retConsStatServ></nfeResultMsg></soap:Body></soap:Envelope>
290+
<consStatServ versao="4.00" xmlns="http://www.portalfiscal.inf.br/nfe"><tpAmb>2</tpAmb><cUF>43</cUF><xServ>STATUS</xServ></consStatServ>`;
291+
292+
let obj = XmlHelper.XmlHelper.deserializeXml(xml);
293+
console.log(require('util').inspect(obj, false, null))
294+
}
295+
296+
function testHashRespTec(){
297+
const nfeProc = new lib.NFeProcessor(empresa);
298+
console.log(nfeProc.gerarHashCSRT('41180678393592000146558900000006041028190697', 'G8063VRTNDMO886SFNK5LDUDEI24XJ22YIPO'));
299+
}
300+
301+
// testeAssinaturaXML();
302+
// testeConsultaStatusServico(empresa, '2', '65');
303+
//testeDesereliaze();
304+
// testeEmissaoNFCe();
305+
// testeEmissaoNFCeContingenciaOffline(empresa);
306+
//testeQRcodeNFCe();
307+
//testHashRespTec();
308+
testeEmissaoNFe();

0 commit comments

Comments
 (0)