diff --git a/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java b/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java index c60fd55d7..ba3e47d70 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java +++ b/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java @@ -157,13 +157,16 @@ public class PuntoVenta implements Serializable { @Column(name = "RAZONSOCIAL") private String razonSocial; - + @Column(name = "INCPROGCONCESSAOCREDITO") private Boolean incProgConcessaoCredito; - + @Column(name = "NUMIEPUNTOVENTA") private String numIEPuntoVenta; + @Column(name = "INDINTEGRACION") + private Integer indIntegracion; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "puntoventaId") @LazyCollection(LazyCollectionOption.FALSE) private List ptovtaEmpresaBloqueadaList; @@ -760,12 +763,12 @@ public class PuntoVenta implements Serializable { public void setPtovtaCatIndList(List ptovtaCatIndList) { this.ptovtaCatIndList = ptovtaCatIndList; } - + public PtovtaCatInd addPtovtaCatInd(PtovtaCatInd pto) { pto.setActivo(Boolean.TRUE); pto.setFecmodif(Calendar.getInstance().getTime()); pto.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); - + this.ptovtaCatIndList.add(pto); return pto; } @@ -789,4 +792,12 @@ public class PuntoVenta implements Serializable { public void setIncProgConcessaoCredito(Boolean incProgConcessaoCredito) { this.incProgConcessaoCredito = incProgConcessaoCredito; } + + public Integer getIndIntegracion() { + return indIntegracion; + } + + public void setIndIntegracion(Integer indIntegracion) { + this.indIntegracion = indIntegracion; + } } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/PuntoVentaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/PuntoVentaServiceImpl.java index 487624a20..dd8cc274d 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/PuntoVentaServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/PuntoVentaServiceImpl.java @@ -32,6 +32,8 @@ import com.rjconsultores.ws.utileria.Atributos; import com.rjconsultores.ws.utileria.Atributos.CodPaisBanco; import com.rjconsultores.ws.utileria.Atributos.ContribuinteICMS; import com.rjconsultores.ws.utileria.Atributos.ContribuinteSimplesNacional; +import com.rjconsultores.ws.utileria.Atributos.InscricaoMunicipal; +import com.rjconsultores.ws.utileria.Atributos.RetornoTotvs; import com.rjconsultores.ws.utileria.Atributos.TipoCliente; import com.rjconsultores.ws.utileria.Atributos.TipoEntidade; import com.rjconsultores.ws.utileria.Atributos.TipoFornecedor; @@ -75,9 +77,31 @@ public class PuntoVentaServiceImpl implements PuntoVentaService { entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); entidad.setFecmodif(Calendar.getInstance().getTime()); entidad.setActivo(Boolean.TRUE); + + IntegracionException respEx = null; + try { + if (entidad.getIndIntegracion() == TipoRetornoTotvs.CONCLUIDA.getValor()) { + String resp = integracionTotvs(entidad); + entidad.setIndIntegracion(TipoRetornoTotvs.CONCLUIDA.getValor()); + + if (resp.equals(RetornoTotvs.CNPJ_JA_CADASTRADO.getValor())) { + entidad.setIndIntegracion(TipoRetornoTotvs.JA_CADASTRADA.getValor()); + respEx = new IntegracionException("integracion.totvs.ja.cadastrado"); + } + + } + } catch (Exception e) { + entidad.setIndIntegracion(TipoRetornoTotvs.ERRO.getValor()); + log.error("", e); + respEx = new IntegracionException("integracion.totvs"); + } + entidad = puntoVentaDAO.suscribir(entidad); - integracionTotvs(entidad); + if (respEx != null) { + throw respEx; + } + return entidad; } @@ -86,9 +110,30 @@ public class PuntoVentaServiceImpl implements PuntoVentaService { entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); entidad.setFecmodif(Calendar.getInstance().getTime()); entidad.setActivo(Boolean.TRUE); + + IntegracionException respEx = null; + try { + if (entidad.getIndIntegracion() != TipoRetornoTotvs.CONCLUIDA.getValor()) { + String resp = integracionTotvs(entidad); + entidad.setIndIntegracion(TipoRetornoTotvs.CONCLUIDA.getValor()); + + if (resp.equals(RetornoTotvs.CNPJ_JA_CADASTRADO.getValor())) { + respEx = new IntegracionException("integracion.totvs.ja.cadastrado"); + } + + } + } catch (Exception e) { + entidad.setIndIntegracion(TipoRetornoTotvs.ERRO.getValor()); + log.error("", e); + respEx = new IntegracionException("integracion.totvs"); + } + entidad = puntoVentaDAO.actualizacion(entidad); - integracionTotvs(entidad); + if (respEx != null) { + throw respEx; + } + return entidad; } @@ -189,7 +234,7 @@ public class PuntoVentaServiceImpl implements PuntoVentaService { return resp; } - private void integracionTotvs(PuntoVenta puntoVenta) throws IntegracionException { + private String integracionTotvs(PuntoVenta puntoVenta) throws Exception { if (ApplicationProperties.getInstance().integracionTotvs()) { boolean clienteValido = validaCanalVenta(puntoVenta.getTipoPuntoVenta().getTipoptovtaId().intValue()); @@ -233,6 +278,7 @@ public class PuntoVentaServiceImpl implements PuntoVentaService { String email = puntoVenta.getDescCorreo(); String fax = puntoVenta.getNumfax(); String inscr = puntoVenta.getNumIEPuntoVenta(); + String inscrm = InscricaoMunicipal.ISENTO.name(); String nreduz = puntoVenta.getRazonSocial() != null ? puntoVenta.getRazonSocial() : puntoVenta.getNombpuntoventa(); @@ -251,7 +297,6 @@ public class PuntoVentaServiceImpl implements PuntoVentaService { obs = StringUtils.isBlank(obs) ? "sem obs." : obs; String conta = "1110101001001"; // DEVE SER REVISADO COM A GUANABARA - String inscrm = "ISENTO"; // DEVE SER REVISADO COM A GUANABARA String naturez = ""; String cnae = ""; @@ -271,11 +316,12 @@ public class PuntoVentaServiceImpl implements PuntoVentaService { String ctacorr = puntoVenta.getAgenciaId() == null ? "" : puntoVenta.getAgenciaId().getNumconta(); String dgverct = puntoVenta.getAgenciaId() == null ? "" : puntoVenta.getAgenciaId().getDigito(); + String resp = null; Exception respEx = null; if (fornecedorValido) { try { - TotvsService.cadastrarFornecedor(endpointFornecedor, bairro, cep, cgc, cnae, codmun, codpais, complemen, conta, ddd, email, endereco, + resp = TotvsService.cadastrarFornecedor(endpointFornecedor, bairro, cep, cgc, cnae, codmun, codpais, complemen, conta, ddd, email, endereco, est, inscr, inscrm, naturez, nome, nreduz, simpnac, tel, tipoPessoa, tppessoa, cnpjEmpresaProtheus, xidsvp, agencia, banco, dgverag, ctacorr, dgverct); } catch (Exception e) { @@ -292,7 +338,7 @@ public class PuntoVentaServiceImpl implements PuntoVentaService { if (clienteValido) { try { - TotvsService.cadastrarCliente(endpointCliente, bairro, cep, cgc, codmun, codpais, complemen, conta, contrib, ddd, email, cnpjEmpresaProtheus, + resp = TotvsService.cadastrarCliente(endpointCliente, bairro, cep, cgc, codmun, codpais, complemen, conta, contrib, ddd, email, cnpjEmpresaProtheus, endereco, entid, fator, fax, inscr, inscrm, naturez, nome, nreduz, obs, pais, tppessoaCliente, tel, tipoPessoa, est, xidsvp); } catch (Exception e) { log.error("", e); @@ -300,10 +346,13 @@ public class PuntoVentaServiceImpl implements PuntoVentaService { } if (respEx != null) { - throw new IntegracionException("integracion.totvs"); + throw respEx; } } + + return resp; } + return null; } private String getEndpointFornecedor() { @@ -336,4 +385,22 @@ public class PuntoVentaServiceImpl implements PuntoVentaService { vlr = somenteNumeros(vlr); return vlr.length() > 11; } + + public enum TipoRetornoTotvs { + CONCLUIDA(1), ERRO(-1), JA_CADASTRADA(2), PENDENTE(0); + + private Integer valor; + + private TipoRetornoTotvs(Integer valor) { + this.setValor(valor); + } + + public Integer getValor() { + return valor; + } + + public void setValor(Integer valor) { + this.valor = valor; + } + } }