|
| 1 | +package br.com.swconsultoria.nfe.exemplos; |
| 2 | + |
| 3 | +import br.com.swconsultoria.nfe.Nfe; |
| 4 | +import br.com.swconsultoria.nfe.dom.ConfiguracoesNfe; |
| 5 | +import br.com.swconsultoria.nfe.dom.enuns.AmbienteEnum; |
| 6 | +import br.com.swconsultoria.nfe.dom.enuns.EstadosEnum; |
| 7 | +import br.com.swconsultoria.nfe.exception.NfeException; |
| 8 | +import br.com.swconsultoria.nfe.schema.envEventoEConf.DetEvento; |
| 9 | +import br.com.swconsultoria.nfe.schema.envEventoEConf.TEvento; |
| 10 | +import br.com.swconsultoria.nfe.schema.envEventoEConf.TUfEmi; |
| 11 | +import br.com.swconsultoria.nfe.schema.eventoEConf.TRetEnvEvento; |
| 12 | +import br.com.swconsultoria.nfe.util.XmlNfeUtil; |
| 13 | + |
| 14 | +import java.time.LocalDateTime; |
| 15 | + |
| 16 | +/** |
| 17 | + * @author Samuel Oliveira |
| 18 | + * |
| 19 | + */ |
| 20 | +public class EConfTeste { |
| 21 | + |
| 22 | + public static void main(String[] args) { |
| 23 | + |
| 24 | + try { |
| 25 | + |
| 26 | + // Inicia As Configurações |
| 27 | + ConfiguracoesNfe config = ConfiguracaoTeste.iniciaConfiguracoes(EstadosEnum.GO, AmbienteEnum.HOMOLOGACAO); |
| 28 | + |
| 29 | + // Monta o Evento |
| 30 | + br.com.swconsultoria.nfe.schema.envEventoEConf.TEnvEvento envEvento = new br.com.swconsultoria.nfe.schema.envEventoEConf.TEnvEvento(); |
| 31 | + envEvento.setVersao("1.00"); |
| 32 | + envEvento.setIdLote("1"); |
| 33 | + |
| 34 | + TEvento evento = new TEvento(); |
| 35 | + evento.setVersao("1.00"); |
| 36 | + TEvento.InfEvento infEvento = new TEvento.InfEvento(); |
| 37 | + infEvento.setId("ID" + "110750" + "52250810732644000128550010000927501960446967" + "01"); |
| 38 | + infEvento.setCOrgao("92"); |
| 39 | + infEvento.setTpAmb("2"); |
| 40 | + infEvento.setCNPJ("10732644000128"); |
| 41 | + infEvento.setChNFe("52250810732644000128550010000927501960446967"); |
| 42 | + infEvento.setDhEvento(XmlNfeUtil.dataNfe(LocalDateTime.now())); |
| 43 | + infEvento.setTpEvento("110750"); |
| 44 | + infEvento.setNSeqEvento("1"); |
| 45 | + infEvento.setVerEvento("1.00"); |
| 46 | + |
| 47 | + DetEvento detEvento = new DetEvento(); |
| 48 | + detEvento.setVersao("1.00"); |
| 49 | + detEvento.setDescEvento("ECONF"); |
| 50 | + detEvento.setVerAplic("1.00"); |
| 51 | + infEvento.setDetEvento(detEvento); |
| 52 | + evento.setInfEvento(infEvento); |
| 53 | + envEvento.getEvento().add(evento); |
| 54 | + |
| 55 | + DetEvento.DetPag detPag = new DetEvento.DetPag(); |
| 56 | + detPag.setIndPag("1"); |
| 57 | + detPag.setTPag("04"); |
| 58 | + detPag.setVPag("500.00"); |
| 59 | + detPag.setDPag("2025-10-21"); |
| 60 | + detPag.setCNPJPag("10440482000154"); |
| 61 | + detPag.setUFPag(TUfEmi.GO); |
| 62 | + detPag.setTBand("02"); |
| 63 | + detPag.setCNPJIF("10440482000154"); |
| 64 | + detPag.setCAut("JFMfVe"); |
| 65 | + envEvento.getEvento().get(0).getInfEvento().getDetEvento().getDetPag().add(detPag); |
| 66 | + |
| 67 | + System.out.println(XmlNfeUtil.objectToXml(envEvento)); |
| 68 | + |
| 69 | + //Envia a ECONF |
| 70 | + TRetEnvEvento retorno = Nfe.econf(config, envEvento, true); |
| 71 | + |
| 72 | + if (!retorno.getCStat().equals("128")) { |
| 73 | + throw new NfeException(retorno.getCStat() + " - " + retorno.getXMotivo()); |
| 74 | + } |
| 75 | + |
| 76 | + if (!retorno.getRetEvento().get(0).getInfEvento().getCStat().equals("135")) { |
| 77 | + throw new NfeException(retorno.getRetEvento().get(0).getInfEvento().getCStat() + " - " + retorno.getRetEvento().get(0).getInfEvento().getXMotivo()); |
| 78 | + } |
| 79 | + |
| 80 | + //Resultado |
| 81 | + System.out.println(); |
| 82 | + retorno.getRetEvento().forEach(resultado -> { |
| 83 | + System.out.println("# Chave: " + resultado.getInfEvento().getChNFe()); |
| 84 | + System.out.println("# Status: " + resultado.getInfEvento().getCStat() + " - " + resultado.getInfEvento().getXMotivo()); |
| 85 | + System.out.println("# Protocolo: " + resultado.getInfEvento().getNProt()); |
| 86 | + }); |
| 87 | + |
| 88 | + } catch (Exception e) { |
| 89 | + System.err.println(); |
| 90 | + System.err.println(e.getMessage()); |
| 91 | + } |
| 92 | + |
| 93 | + } |
| 94 | + |
| 95 | +} |
0 commit comments