|
|
|
@ -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,8 +36,12 @@ 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;
|
|
|
|
@ -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
|
|
|
|
@ -141,4 +157,89 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
|
|
|
|
|
List<PuntoVenta> 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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|