237 lines
7.8 KiB
Java
237 lines
7.8 KiB
Java
/*
|
|
* To change this template, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
package com.rjconsultores.ventaboletos.service.impl;
|
|
|
|
import java.util.Calendar;
|
|
import java.util.List;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.zkoss.util.resource.Labels;
|
|
|
|
import com.rjconsultores.ventaboletos.dao.EstacionDAO;
|
|
import com.rjconsultores.ventaboletos.entidad.Estacion;
|
|
import com.rjconsultores.ventaboletos.entidad.EstacionImpresora;
|
|
import com.rjconsultores.ventaboletos.entidad.EstacionSitef;
|
|
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
|
|
import com.rjconsultores.ventaboletos.enums.TipoImpressora;
|
|
import com.rjconsultores.ventaboletos.exception.BusinessException;
|
|
import com.rjconsultores.ventaboletos.service.AutorizaFolioService;
|
|
import com.rjconsultores.ventaboletos.service.EstacionService;
|
|
import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
|
|
import com.rjconsultores.ventaboletos.utilerias.CustomEnum;
|
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
|
|
|
/**
|
|
*
|
|
* @author Administrador
|
|
*/
|
|
@Service("estacionService")
|
|
public class EstacionServiceImpl implements EstacionService {
|
|
|
|
@Autowired
|
|
private EstacionDAO estacionDAO;
|
|
|
|
@Autowired
|
|
private AutorizaFolioService autorizaFolioService;
|
|
|
|
public List<Estacion> obtenerTodos() {
|
|
return estacionDAO.obtenerTodos();
|
|
}
|
|
|
|
public Estacion obtenerID(Integer id) {
|
|
return estacionDAO.obtenerID(id);
|
|
}
|
|
|
|
@Transactional(rollbackFor = BusinessException.class)
|
|
public Estacion suscribirActualizar(Estacion estacion) throws BusinessException {
|
|
validarEstoqueUpdate(estacion);
|
|
|
|
if (estacion.getDescmac() != null && !estacion.getDescmac().isEmpty())
|
|
validarDuplicidade(estacionDAO.buscarEstacionDuplicadaPorMAC(estacion.getDescmac(), estacion.getEstacionId()));
|
|
|
|
if (estacion.getImei() != null && !estacion.getImei().isEmpty())
|
|
validarDuplicidade(estacionDAO.buscarEstacionDuplicadaPorIMEI(estacion.getImei(), estacion.getEstacionId()));
|
|
|
|
boolean esCajaDuplicado = false;
|
|
List<Estacion> lsEstacion = estacionDAO.buscar(estacion.getNumcaja(), estacion.getPuntoVenta());
|
|
|
|
if (!lsEstacion.isEmpty()) {
|
|
if (estacion.getEstacionId() == null) {
|
|
esCajaDuplicado = true;
|
|
} else {
|
|
esCajaDuplicado = !lsEstacion.get(0).getEstacionId().equals(estacion.getEstacionId());
|
|
}
|
|
}
|
|
|
|
if (esCajaDuplicado) {
|
|
throw new BusinessException("estacionServiceImpl.msg.cajaDuplicado");
|
|
}
|
|
|
|
estacion.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
|
estacion.setFecmodif(Calendar.getInstance().getTime());
|
|
estacion.setActivo(Boolean.TRUE);
|
|
|
|
boolean isNuevaFiscal = validacionNuevaImpressoraFiscal(estacion);
|
|
|
|
if (estacion.getEstacionId() == null) {
|
|
estacion = estacionDAO.suscribir(estacion);
|
|
} else {
|
|
estacion = estacionDAO.actualizacion(estacion);
|
|
}
|
|
|
|
String errorNoChequeFolio = null;
|
|
for (EstacionImpresora ei : estacion.getLsEstacionImpresora()) {
|
|
boolean isImpressoraFiscal = validacionImpressoraFiscal(ei);
|
|
if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.GENERAR_ROTINA_FOLIOS.getDescricao())) {
|
|
errorNoChequeFolio = autorizaFolioService.noChequeFolioPreimpresos(ei, false);
|
|
} else if ((isImpressoraFiscal && isNuevaFiscal) ||
|
|
(estacion.getIndStockCentral() != null && estacion.getIndStockCentral() && isImpressoraFiscal)) {
|
|
errorNoChequeFolio = autorizaFolioService.noChequeFolioPreimpresos(ei, true);
|
|
}
|
|
}
|
|
|
|
if (StringUtils.isNotBlank(errorNoChequeFolio)) {
|
|
throw new BusinessException(errorNoChequeFolio);
|
|
}
|
|
|
|
return estacion;
|
|
}
|
|
|
|
private void validarDuplicidade(Estacion estacionValidacao) throws BusinessException {
|
|
Boolean esMacDuplicado = Boolean.FALSE;
|
|
|
|
String nomeEstacao = "";
|
|
Long numeroCaixa = 0l;
|
|
|
|
if (estacionValidacao != null) {
|
|
nomeEstacao = estacionValidacao.getDescestacion();
|
|
numeroCaixa = estacionValidacao.getNumcaja();
|
|
esMacDuplicado = Boolean.TRUE;
|
|
}
|
|
|
|
if (esMacDuplicado) {
|
|
StringBuilder msg = new StringBuilder();
|
|
msg.append( Labels.getLabel("estacionServiceImpl.msg.macDuplicado") );
|
|
msg.append( "\n" );
|
|
msg.append( Labels.getLabel("estacionServiceImpl.msg.macDuplicado.descricaoEstacao") );
|
|
msg.append( nomeEstacao );
|
|
msg.append( "\n" );
|
|
msg.append( Labels.getLabel("estacionServiceImpl.msg.macDuplicado.numeroCaixa") );
|
|
msg.append( numeroCaixa.toString() );
|
|
|
|
throw new BusinessException( msg.toString());
|
|
}
|
|
}
|
|
|
|
private boolean validacionNuevaImpressoraFiscal(final Estacion e) {
|
|
for (EstacionImpresora ei : e.getLsEstacionImpresora()) {
|
|
if(TipoImpressora.getTipoImpressoraFiscal(ei.getTipoImpressora())!=null && ei.getEstacionImpresoraId() == null){
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private boolean validacionImpressoraFiscal(final EstacionImpresora ei) {
|
|
if(TipoImpressora.getTipoImpressoraFiscal(ei.getTipoImpressora())!=null){
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void devolverFoliosAutomaticosImpressoraFiscal(final EstacionImpresora ei) {
|
|
|
|
if(TipoImpressora.getTipoImpressoraFiscal(ei.getTipoImpressora())!=null){
|
|
autorizaFolioService.devolverFoliosAutomaticosImpressoraFiscal(ei);
|
|
}
|
|
}
|
|
|
|
private void validarEstoqueUpdate(Estacion estacion) throws BusinessException {
|
|
|
|
if (estacion.getEstacionId() == null) {
|
|
return;
|
|
}
|
|
|
|
if (!ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.GENERAR_ROTINA_FOLIOS.getDescricao())) {
|
|
Estacion estacionPuntoVentaAnterior = estacionDAO.obtenerID(estacion.getEstacionId());
|
|
if (estacionPuntoVentaAnterior.getPuntoVenta() != null)
|
|
if (!estacionPuntoVentaAnterior.getPuntoVenta().equals(estacion.getPuntoVenta())) {
|
|
if (estacionDAO.temEstoque(estacionPuntoVentaAnterior.getPuntoVenta(), estacion)) {
|
|
throw new BusinessException("estacionServiceImpl.msg.hayStock");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void validarEstoqueBorrar(Estacion estacion) throws BusinessException {
|
|
if (!ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.GENERAR_ROTINA_FOLIOS.getDescricao())) {
|
|
if (estacionDAO.temEstoque(estacion.getPuntoVenta(), estacion)) {
|
|
throw new BusinessException("estacionServiceImpl.msg.hayStock.borrar");
|
|
}
|
|
}
|
|
}
|
|
|
|
@Transactional
|
|
public void borrar(Estacion entidad) throws BusinessException {
|
|
|
|
validarEstoqueBorrar(entidad);
|
|
|
|
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
|
entidad.setActivo(Boolean.FALSE);
|
|
|
|
if (entidad.getEstacionSitefList() != null) {
|
|
for (EstacionSitef es : entidad.getEstacionSitefList()) {
|
|
es.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
|
es.setFecmodif(Calendar.getInstance().getTime());
|
|
es.setActivo(Boolean.FALSE);
|
|
}
|
|
}
|
|
|
|
estacionDAO.actualizacion(entidad);
|
|
}
|
|
|
|
public List<Estacion> buscar(String descEstacion, String descMac, Long nunCaja, PuntoVenta pv) {
|
|
return estacionDAO.buscar(descEstacion, descMac, nunCaja, pv);
|
|
}
|
|
|
|
public List<Estacion> buscar(String descMac) {
|
|
return estacionDAO.buscar(descMac);
|
|
}
|
|
|
|
public Estacion buscarPorIMEI(String imei) {
|
|
return estacionDAO.buscarPorIMEI(imei);
|
|
}
|
|
|
|
@Override
|
|
public Long getDecimalMAC(String mac) {
|
|
mac = mac.trim();
|
|
mac = mac.replace("-", "");
|
|
return Long.parseLong(mac, 16);
|
|
}
|
|
|
|
@Override
|
|
public List<Estacion> buscarEstaciones(PuntoVenta puntoVenta) {
|
|
List<Estacion> estaciones = estacionDAO.buscarEstaciones(puntoVenta);
|
|
return estaciones;
|
|
}
|
|
|
|
@Override
|
|
public List<Estacion> buscarEstaciones(List<PuntoVenta> lsPuntoVenta) {
|
|
return estacionDAO.buscarEstaciones(lsPuntoVenta);
|
|
}
|
|
|
|
@Override
|
|
public List<Estacion> buscarEstacionesStockCentral(PuntoVenta puntoVenta) {
|
|
List<Estacion> estaciones = estacionDAO.buscarEstacionesStockCentral(puntoVenta);
|
|
return estaciones;
|
|
}
|
|
}
|