diff --git a/.classpath b/.classpath
index f9e548381..6fb5d90e8 100644
--- a/.classpath
+++ b/.classpath
@@ -104,5 +104,6 @@
+
diff --git a/src/com/rjconsultores/ventaboletos/exception/IntegracionException.java b/src/com/rjconsultores/ventaboletos/exception/IntegracionException.java
new file mode 100644
index 000000000..ca00e3f64
--- /dev/null
+++ b/src/com/rjconsultores/ventaboletos/exception/IntegracionException.java
@@ -0,0 +1,34 @@
+package com.rjconsultores.ventaboletos.exception;
+
+import java.text.MessageFormat;
+
+import org.zkoss.util.resource.Labels;
+
+public class IntegracionException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ *
+ * @param message
+ * - La clave del archivo de traducción
+ */
+ public IntegracionException(String message) {
+ super(Labels.getLabel(message));
+ }
+
+ /**
+ *
+ * @param message
+ * - La clave del archivo de traducción
+ * @param oMsg
+ * - Los parametros de la mensage
+ */
+ public IntegracionException(String message, Object oMsg) {
+ super(new MessageFormat(Labels.getLabel(message)).format(oMsg));
+ }
+
+}
diff --git a/src/com/rjconsultores/ventaboletos/service/PuntoVentaService.java b/src/com/rjconsultores/ventaboletos/service/PuntoVentaService.java
index 868f9c120..9abc2958b 100644
--- a/src/com/rjconsultores/ventaboletos/service/PuntoVentaService.java
+++ b/src/com/rjconsultores/ventaboletos/service/PuntoVentaService.java
@@ -10,22 +10,23 @@ import com.rjconsultores.ventaboletos.entidad.Empresa;
import com.rjconsultores.ventaboletos.entidad.Parada;
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
import com.rjconsultores.ventaboletos.entidad.Usuario;
+import com.rjconsultores.ventaboletos.exception.IntegracionException;
/**
*
* @author Administrador
*/
public interface PuntoVentaService {
-
+
public List obtenerTodos();
- public PuntoVenta obtenerID(Integer id);
+ public PuntoVenta obtenerID(Integer id);
- public PuntoVenta suscribir(PuntoVenta entidad);
+ public PuntoVenta suscribir(PuntoVenta entidad) throws IntegracionException;
- public PuntoVenta actualizacion(PuntoVenta entidad);
+ public PuntoVenta actualizacion(PuntoVenta entidad) throws IntegracionException;
- public void borrar(PuntoVenta entidad);
+ public void borrar(PuntoVenta entidad);
public List buscaLike(String strEstacion);
@@ -36,8 +37,8 @@ public interface PuntoVentaService {
public List buscaPuntoVentaParada(Parada paradaId);
public List buscarPuntoVentaSubordinados(PuntoVenta puntoVenta);
-
+
public List buscarPuntosVentaMovimentacionBilhetes(List empresas);
-
+
public List buscarPuntosVentaPorUsuario(Usuario usuario);
}
diff --git a/src/com/rjconsultores/ventaboletos/service/impl/PuntoVentaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/PuntoVentaServiceImpl.java
index cebbd9d5a..e7d543118 100644
--- a/src/com/rjconsultores/ventaboletos/service/impl/PuntoVentaServiceImpl.java
+++ b/src/com/rjconsultores/ventaboletos/service/impl/PuntoVentaServiceImpl.java
@@ -7,19 +7,27 @@ package com.rjconsultores.ventaboletos.service.impl;
import java.util.Calendar;
import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.rjconsultores.ventaboletos.dao.PuntoVentaDAO;
import com.rjconsultores.ventaboletos.dao.UsuarioUbicacionDAO;
+import com.rjconsultores.ventaboletos.entidad.Constante;
import com.rjconsultores.ventaboletos.entidad.Empresa;
import com.rjconsultores.ventaboletos.entidad.FormaPagoDet;
import com.rjconsultores.ventaboletos.entidad.Parada;
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
import com.rjconsultores.ventaboletos.entidad.Usuario;
+import com.rjconsultores.ventaboletos.exception.IntegracionException;
+import com.rjconsultores.ventaboletos.service.ConstanteService;
import com.rjconsultores.ventaboletos.service.PuntoVentaService;
+import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
+import com.rjconsultores.ws.totvs.fornecedor.Tipo;
+import com.rjconsultores.ws.totvs.service.TotvsService;
/**
*
@@ -28,13 +36,17 @@ import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
@Service("puntoVentaService")
public class PuntoVentaServiceImpl implements PuntoVentaService {
+ private static Logger log = LoggerFactory.getLogger(PuntoVentaServiceImpl.class);
+
@Autowired
private PuntoVentaDAO puntoVentaDAO;
-
+ @Autowired
+ private ConstanteService constanteService;
+
@Autowired
private UsuarioUbicacionDAO usuarioUbicacionDAO;
- //FIXME : Remover esse método de quem está usando. Esse método carrega muitos dados
+ // FIXME : Remover esse método de quem está usando. Esse método carrega muitos dados
@Deprecated
public List obtenerTodos() {
return puntoVentaDAO.obtenerTodos();
@@ -44,22 +56,26 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
return puntoVentaDAO.obtenerID(id);
}
- @Transactional
- public PuntoVenta suscribir(PuntoVenta entidad) {
+ @Transactional(noRollbackFor = { IntegracionException.class })
+ public PuntoVenta suscribir(PuntoVenta entidad) throws IntegracionException {
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
entidad.setFecmodif(Calendar.getInstance().getTime());
entidad.setActivo(Boolean.TRUE);
+ entidad = puntoVentaDAO.suscribir(entidad);
- return puntoVentaDAO.suscribir(entidad);
+ integracionTotvs(entidad);
+ return entidad;
}
- @Transactional
- public PuntoVenta actualizacion(PuntoVenta entidad) {
+ @Transactional(noRollbackFor = { IntegracionException.class })
+ public PuntoVenta actualizacion(PuntoVenta entidad) throws IntegracionException {
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
entidad.setFecmodif(Calendar.getInstance().getTime());
entidad.setActivo(Boolean.TRUE);
+ entidad = puntoVentaDAO.actualizacion(entidad);
- return puntoVentaDAO.actualizacion(entidad);
+ integracionTotvs(entidad);
+ return entidad;
}
@Transactional
@@ -138,7 +154,92 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
}
public List buscarPuntosVentaPorUsuario(Usuario usuario) {
- List puntosVenta = usuarioUbicacionDAO.buscarPuntoVentaPorUsuario(usuario);
+ List puntosVenta = usuarioUbicacionDAO.buscarPuntoVentaPorUsuario(usuario);
return puntosVenta;
}
+
+ private void integracionTotvs(PuntoVenta puntoVenta) throws IntegracionException {
+ if (ApplicationProperties.getInstance().integracionTotvs()) {
+
+ String nomeEmpresa = puntoVenta.getRazonSocial();
+ String nomeFilial = puntoVenta.getNumDoCPuntoVenta();
+
+ String endpointFornecedor = getEndpointFornecedor();
+ String endpointCliente = getEndpointCliente();
+
+ String nome = puntoVenta.getNombpuntoventa();
+ String cgc = puntoVenta.getNumDoCPuntoVenta();
+
+ String endereco = puntoVenta.getDireccioncalle() + "," + puntoVenta.getDireccionnumero() == null ? "" : puntoVenta.getDireccionnumero();
+ String complemen = puntoVenta.getCompl() == null ? "" : puntoVenta.getCompl();
+ String bairro = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getDesccolonia();
+ String codmun = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getCiudad().getCiudadId().toString();
+ String est = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getCiudad().getEstado().getCveestado();
+ String codpais = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getCiudad().getEstado().getPais().getPaisId().toString();
+ String cep = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getCodpostal();
+ String pais = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getCiudad().getEstado().getPais().getNombpais();
+
+ String tel = puntoVenta.getNumtelefonouno();
+ String ddd = null;
+ try {
+ String[] telefone = puntoVenta.getNumtelefonouno() == null ? null : puntoVenta.getNumtelefonouno().split("\\)");
+ ddd = puntoVenta.getNumtelefonouno() == null ? null : telefone[0].replaceAll("\\(", "");
+ tel = puntoVenta.getNumtelefonouno() == null ? null : telefone[1].replaceAll("\\(", "");
+ } catch (Exception e) {
+ tel = puntoVenta.getNumtelefonouno();
+ }
+
+ String email = puntoVenta.getDescCorreo();
+ String fax = puntoVenta.getNumfax();
+ String inscr = puntoVenta.getNumIEPuntoVenta();
+ String nreduz = puntoVenta.getNombpuntoventa();
+ String tipo = Tipo.F.name();
+ String tpessoa = puntoVenta.getNumDoCPuntoVenta();
+ String obs = puntoVenta.getComentarios();
+
+ String conta = puntoVenta.getAgenciaId() == null ? null : puntoVenta.getAgenciaId().getNumconta() + "-" + puntoVenta.getAgenciaId().getDigito();
+ String cnae = "";
+ String inscrm = "";
+ String naturez = "";
+ String simpnac = "";
+ String contrib = "";
+ String entid = "";
+ String fator = "";
+
+ try {
+ TotvsService.cadastrarFornecedor(endpointFornecedor, nomeEmpresa, nomeFilial, bairro, cep,
+ cgc, cnae, codmun, codpais, complemen, conta, ddd, email, endereco, est, inscr,
+ inscrm, naturez, nome, nreduz, simpnac, tel, tipo, tpessoa);
+ } catch (Exception e) {
+ log.error("", e);
+ throw new IntegracionException("integracion.totvs");
+ }
+
+ try {
+ TotvsService.cadastrarCliente(endpointCliente, bairro, cep, cgc, codmun, codpais, complemen, conta,
+ contrib, ddd, email, nomeEmpresa, endereco, entid, fator, fax, inscr, inscrm, naturez, nome,
+ nreduz, obs, pais, tpessoa, tel, tipo, est);
+ } catch (Exception e) {
+ log.error("", e);
+ throw new IntegracionException("integracion.totvs");
+ }
+
+ }
+ }
+
+ private String getEndpointFornecedor() {
+ Constante constante = constanteService.buscarPorNomeConstante("WS_TOTVS_FORNECEDOR_ENDPOINT");
+ if (constante == null) {
+ return "";
+ }
+ return constante.getValorconstante();
+ }
+
+ private String getEndpointCliente() {
+ Constante constante = constanteService.buscarPorNomeConstante("WS_TOTVS_CLIENTE_ENDPOINT");
+ if (constante == null) {
+ return "";
+ }
+ return constante.getValorconstante();
+ }
}
diff --git a/src/com/rjconsultores/ventaboletos/utilerias/ApplicationProperties.java b/src/com/rjconsultores/ventaboletos/utilerias/ApplicationProperties.java
index e52d320b5..1c238d7e8 100644
--- a/src/com/rjconsultores/ventaboletos/utilerias/ApplicationProperties.java
+++ b/src/com/rjconsultores/ventaboletos/utilerias/ApplicationProperties.java
@@ -109,32 +109,40 @@ public class ApplicationProperties {
String property = p.getProperty("no.cheque.folio", "0");
return property.equals("1");
}
-
+
public boolean habilitarPricingCategoria() {
String property = p.getProperty("pricing.categoria.habilitar", "0");
return property.equals("1");
}
-
+
public boolean rutaConMasDeUnaClase() {
String property = p.getProperty("ruta.masdeunaclase", "0");
return property.equals("1");
}
+
public boolean diagramaAutobusDosPestana() {
String property = p.getProperty("diagramaautobus.dospestana", "0");
return property.equals("1");
}
+
public boolean contrasenaValidaComplejidad() {
String property = p.getProperty("contrasena.validaComplejidad", "0");
return property.equals("1");
}
+
public boolean pafActivo() {
String property = p.getProperty("paf.activo", "0");
return property.equals("1");
}
-
+
public boolean habilitarCustomSequence() {
String property = p.getProperty("custom.sequence", "0");
return property.equals("1");
}
-
+
+ public boolean integracionTotvs() {
+ String property = p.getProperty("integracion.totvs", "0");
+ return property.equals("1");
+ }
+
}