diff --git a/src/com/rjconsultores/ventaboletos/entidad/Ciudad.java b/src/com/rjconsultores/ventaboletos/entidad/Ciudad.java index 3ef539834..4d86f8005 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/Ciudad.java +++ b/src/com/rjconsultores/ventaboletos/entidad/Ciudad.java @@ -196,4 +196,9 @@ public class Ciudad implements Serializable { public void setCodibge(Integer codibge) { this.codibge = codibge; } + + public String getUF(){ + return estado != null ? estado.getCveestado() : ""; + } + } diff --git a/src/com/rjconsultores/ventaboletos/entidad/Colonia.java b/src/com/rjconsultores/ventaboletos/entidad/Colonia.java index 738508969..8d6a7139e 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/Colonia.java +++ b/src/com/rjconsultores/ventaboletos/entidad/Colonia.java @@ -148,4 +148,16 @@ public class Colonia implements Serializable { public String toString() { return this.desccolonia; } + + public String getBairro(){ + return desccolonia; + } + + public String getUF(){ + return ciudad != null ? ciudad.getUF() : ""; + } + + public String getCidade(){ + return ciudad != null ? ciudad.getNombciudad() : ""; + } } diff --git a/src/com/rjconsultores/ventaboletos/entidad/InscricaoEstadual.java b/src/com/rjconsultores/ventaboletos/entidad/InscricaoEstadual.java index 6088346a4..8e6a279c5 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/InscricaoEstadual.java +++ b/src/com/rjconsultores/ventaboletos/entidad/InscricaoEstadual.java @@ -34,6 +34,7 @@ public class InscricaoEstadual { private String bairro; private Ciudad cidade; private String cnpj; + private String equivalenciaAG; public InscricaoEstadual() { // TODO Auto-generated constructor stub @@ -189,6 +190,15 @@ public class InscricaoEstadual { this.cnpj = cnpj; } + @Column(name = "EQUIVALENCIAAG") + public String getEquivalenciaAG() { + return equivalenciaAG; + } + + public void setEquivalenciaAG(String equivalenciaAG) { + this.equivalenciaAG = equivalenciaAG; + } + @Override public boolean equals(Object object) { if (!(object instanceof EmpresaImposto)) { diff --git a/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java b/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java index bbe3b953c..e0de4719b 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java +++ b/src/com/rjconsultores/ventaboletos/entidad/PuntoVenta.java @@ -168,6 +168,12 @@ public class PuntoVenta implements Serializable { @Column(name = "INDINTEGRACION") private Integer indIntegracion; + + @Column(name = "INDINTEGRADOAG") + private Boolean indIntegradoAG; + + @Column(name = "MOTIVONAOINTEGRADOAG") + private String motivoNaoIntegradoAG; @OneToMany(cascade = CascadeType.ALL, mappedBy = "puntoventaId") @LazyCollection(LazyCollectionOption.FALSE) @@ -879,6 +885,22 @@ public class PuntoVenta implements Serializable { this.equivalenciaId = equivalenciaId; } + public Boolean getIndIntegradoAG() { + return indIntegradoAG; + } + + public void setIndIntegradoAG(Boolean indIntegradoAG) { + this.indIntegradoAG = indIntegradoAG; + } + + public String getMotivoNaoIntegradoAG() { + return motivoNaoIntegradoAG; + } + + public void setMotivoNaoIntegradoAG(String motivoNaoIntegradoAG) { + this.motivoNaoIntegradoAG = motivoNaoIntegradoAG; + } + public Date getDateFechamento() { return dateFechamento; } @@ -894,5 +916,32 @@ public class PuntoVenta implements Serializable { public void setDateAbertura(Date dateAbertura) { this.dateAbertura = dateAbertura; } - + + public String getCep(){ + return codpostal != null ? codpostal.toString() : ""; + } + + public String getLogradouro(){ + return direccioncalle; + } + + public String getBairro(){ + return colonia != null ? colonia.getBairro() : ""; + } + + public String getNumero(){ + return direccionnumero; + } + + public String getComplemento(){ + return compl; + } + + public String getUF(){ + return colonia != null ? colonia.getUF() : ""; + } + + public String getCidade(){ + return colonia != null ? colonia.getCidade() : ""; + } } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/PuntoVentaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/PuntoVentaServiceImpl.java index 7f1bbc1cb..dcdd24b76 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/PuntoVentaServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/PuntoVentaServiceImpl.java @@ -4,10 +4,15 @@ */ package com.rjconsultores.ventaboletos.service.impl; +import java.net.MalformedURLException; +import java.net.URL; +import java.rmi.RemoteException; import java.text.Normalizer; import java.util.Calendar; import java.util.List; +import javax.xml.rpc.ServiceException; + import org.apache.commons.lang.StringUtils; import org.brazilutils.br.cpfcnpj.CpfCnpj; import org.slf4j.Logger; @@ -15,6 +20,13 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.tempuri.IAG; +import org.tempuri.IAGservice; +import org.tempuri.IAGserviceLocator; + +import AGIntf.TCliente; +import AGIntf.TFornecedor; +import AGIntf.TServicosCliente; import com.rjconsultores.ventaboletos.dao.PuntoVentaDAO; import com.rjconsultores.ventaboletos.dao.UsuarioUbicacionDAO; @@ -119,7 +131,9 @@ public class PuntoVentaServiceImpl implements PuntoVentaService { log.error(Atributos.MSG_ERRO_GENERICA, e); respEx = new IntegracionException(Atributos.MSG_ERRO_GENERICA + e.getMessage()); } + } + if (respEx != null) { if (respEx instanceof ValidacionCampoException) { throw (ValidacionCampoException) respEx; @@ -129,10 +143,169 @@ public class PuntoVentaServiceImpl implements PuntoVentaService { } } entidad = puntoVentaDAO.suscribir(entidad); - + + integrarClienteAG(entidad); + integrarFornecedorAG(entidad); + return entidad; } + private void integrarFornecedorAG(PuntoVenta entidad) { + if (ApplicationProperties.getInstance().integracionAGWS()) { + try{ + IAGservice service = new IAGserviceLocator(); + IAG iag = service.getIAGPort(new URL("http://localhost:8089/cgi-bin/AGWS.exe/soap/IAG")); + TFornecedor fornecedor = null; + try{ + fornecedor = iag.getObjetoFornecedorPorCNPJCPF(entidad.getNumDoCPuntoVenta()); + } catch (RemoteException e) { + log.error("", e.toString()); + } + if (fornecedor != null){ + // retornar msg a informação de registro já cadastrado + entidad.setIndIntegradoAG(false); + entidad.setMotivoNaoIntegradoAG("Fornecedor já cadastrado"); + } else { + fornecedor = new TFornecedor(); + fornecedor.setNome(entidad.getRazonSocial()); + fornecedor.setNomeFantasia(entidad.getNombpuntoventa()); + fornecedor.setCNPJCPF(entidad.getNumDoCPuntoVenta()); + fornecedor.setGrupo(""); + fornecedor.setReceita(""); + fornecedor.setCodigo(""); + fornecedor.setCEP(entidad.getCep()); + fornecedor.setLogradouro(""+entidad.getLogradouro()); + fornecedor.setBairro(entidad.getBairro()); + fornecedor.setNumero(""+entidad.getNumero()); + fornecedor.setComplemento(""+entidad.getComplemento()); + fornecedor.setUF(entidad.getUF()); + fornecedor.setCidade(entidad.getCidade()); + fornecedor.setDDD(""); + fornecedor.setFone(""); + fornecedor.setFax(""); + fornecedor.setEmail(""); + fornecedor.setContato(""); + fornecedor.setSite(""); + fornecedor.setRG(""); + fornecedor.setIE(""); + fornecedor.setIM(""); + fornecedor.setReferencia(""); + fornecedor.setFinalidadeTED(""); + fornecedor.setFinalidadeDOC(""); + fornecedor.setCelular(""); + fornecedor.setLeiaute(""); + fornecedor.setBanco(""); + fornecedor.setBancoNumero(""); + fornecedor.setAgencia(""); + fornecedor.setCC(""); + fornecedor.setDVAg(""); + fornecedor.setDVCC(""); + fornecedor.setIDWS(entidad.getPuntoventaId().toString()); + try{ + String retornoAG = iag.incluiFornecedor(fornecedor); + System.out.println(retornoAG); + } catch (RemoteException e) { + entidad.setIndIntegradoAG(false); + entidad.setMotivoNaoIntegradoAG(e.getMessage()); + } + } + } catch (ServiceException se){ + log.error("", se.toString()); + } catch (MalformedURLException me){ + log.error("", me.toString()); + } + } + } + + private void integrarClienteAG(PuntoVenta entidad) { + if (ApplicationProperties.getInstance().integracionAGWS()) { + try{ + IAGservice service = new IAGserviceLocator(); + IAG iag = service.getIAGPort(new URL("http://localhost:8089/cgi-bin/AGWS.exe/soap/IAG")); + TCliente cli = null; + try{ + cli = iag.getObjetoClienteCPFCNPJ(entidad.getNumDoCPuntoVenta()); + } catch (RemoteException e) { + log.error("", e.toString()); + } + if (cli != null){ + // retornar msg a informação de registro já cadastrado + entidad.setIndIntegradoAG(false); + entidad.setMotivoNaoIntegradoAG("Cliente já cadastrado"); + } else { + cli = new TCliente(); + cli.setCodigo(""); + cli.setNome(entidad.getRazonSocial()); + cli.setNomeFantasia(entidad.getNombpuntoventa()); + cli.setCnpjcpf(entidad.getNumDoCPuntoVenta()); + cli.setGrupo(""); + cli.setAgenteCobrador(""); + cli.setVencimento(0); + cli.setContaContabil(""); + cli.setCep(entidad.getCep()); + cli.setLogradouro(""+entidad.getLogradouro()); + cli.setBairro(entidad.getBairro()); + cli.setNumero(""+entidad.getNumero()); + cli.setComplemento(""+entidad.getComplemento()); + cli.setUf(entidad.getUF()); + cli.setCidade(entidad.getCidade()); + cli.setDdd(""); + cli.setFone(""); + cli.setDddFax(""); + cli.setFax(""); + cli.setIdentificador(""); + cli.setDddCelular(""); + cli.setCelular(""); + cli.setEmail(""); + cli.setContato(""); + cli.setSite(""); + cli.setRg(""); + cli.setIe(""); + cli.setReceita(""); + cli.setRepresentante(""); + cli.setIM(""); + cli.setCampoExtra1(""); + cli.setCampoExtra10(""); + cli.setCampoExtra2(""); + cli.setCampoExtra3(""); + cli.setCampoExtra4(""); + cli.setCampoExtra5(""); + cli.setCampoExtra6(""); + cli.setCampoExtra7(""); + cli.setCampoExtra8(""); + cli.setCampoExtra9(""); + cli.setServicosCliente(new TServicosCliente()); + cli.setIDWS(entidad.getPuntoventaId().toString()); + cli.getServicosCliente().setServico(""); + cli.getServicosCliente().setEstabelecimento(""); + cli.getServicosCliente().setModalidade(""); + cli.getServicosCliente().setIndexador(""); + cli.getServicosCliente().setAnoMesPrimeiraCobranca(""); + cli.getServicosCliente().setAquisicao(Calendar.getInstance()); + cli.getServicosCliente().setAnoMesReajuste(""); + cli.getServicosCliente().setObservacao(""); + cli.getServicosCliente().setDescricaoNota(""); + cli.getServicosCliente().setComplementoDescricaoNota(""); + cli.getServicosCliente().setContrato(""); + cli.getServicosCliente().setDtCancelamento(Calendar.getInstance()); + cli.getServicosCliente().setObsCancelamento(""); + cli.getServicosCliente().setCRS_Codigo(""); + try{ + String retornoAG = iag.incluiCliente(cli); + System.out.println(retornoAG); + } catch (RemoteException e) { + entidad.setIndIntegradoAG(false); + entidad.setMotivoNaoIntegradoAG(e.getMessage()); + } + } + } catch (ServiceException se){ + log.error("", se.toString()); + } catch (MalformedURLException me){ + log.error("", me.toString()); + } + } + } + @Transactional(noRollbackFor = { IntegracionException.class, ValidacionCampoException.class }) public PuntoVenta actualizacion(PuntoVenta entidad) throws IntegracionException, ValidacionCampoException { entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); @@ -184,6 +357,9 @@ public class PuntoVentaServiceImpl implements PuntoVentaService { entidad = puntoVentaDAO.actualizacion(entidad); + integrarClienteAG(entidad); + integrarFornecedorAG(entidad); + if (respEx != null) { if (respEx instanceof IntegracionException) { throw (IntegracionException) respEx; diff --git a/src/com/rjconsultores/ventaboletos/utilerias/ApplicationProperties.java b/src/com/rjconsultores/ventaboletos/utilerias/ApplicationProperties.java index 66e5bd7af..a6e7083b5 100644 --- a/src/com/rjconsultores/ventaboletos/utilerias/ApplicationProperties.java +++ b/src/com/rjconsultores/ventaboletos/utilerias/ApplicationProperties.java @@ -139,6 +139,16 @@ public class ApplicationProperties { return property.equals("1"); } + public boolean integracionAG() { + String property = p.getProperty("integracion.AG", "0"); + return property.equals("1"); + } + + public boolean integracionAGWS() { + String property = p.getProperty("integracion.agws", "0"); + return property.equals("1"); + } + public boolean integracionRioCard() { String property = p.getProperty("integracion.riocard", "0"); return property.equals("1");