diff --git a/src/com/rjconsultores/ventaboletos/dao/EstacionDAO.java b/src/com/rjconsultores/ventaboletos/dao/EstacionDAO.java index fca70766a..0108ca7ba 100644 --- a/src/com/rjconsultores/ventaboletos/dao/EstacionDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/EstacionDAO.java @@ -33,4 +33,6 @@ public interface EstacionDAO extends GenericDAO { public List buscarEstaciones(PuntoVenta puntoVenta); public List buscarPuntosVentaEstacionPorUsuario(Usuario usuario); + + public Boolean temEstoque(PuntoVenta puntoVenta, Estacion estacion); } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/EstacionHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/EstacionHibernateDAO.java index 50df5a082..04e28247b 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/EstacionHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/EstacionHibernateDAO.java @@ -6,9 +6,11 @@ package com.rjconsultores.ventaboletos.dao.hibernate; import com.rjconsultores.ventaboletos.entidad.Usuario; +import java.math.BigDecimal; import java.util.List; import org.hibernate.Criteria; +import org.hibernate.SQLQuery; import org.hibernate.SessionFactory; import org.hibernate.criterion.DetachedCriteria; import org.hibernate.criterion.Order; @@ -94,5 +96,21 @@ public List buscarEstaciones(PuntoVenta puntoVenta) { return buscaPuntoVentasUsuario.list(); } + + public Boolean temEstoque(PuntoVenta puntoVenta, Estacion estacion){ + StringBuilder qryStr = new StringBuilder(); + qryStr.append("Select count(*) from ABASTO_BOLETO B, DET_ABASTO_BOLETO D "); + qryStr.append("where d.abastoboleto_id = b.abastoboleto_id and (d.statusfirma = 0 "); + qryStr.append("or d.statusfirma = 1) and d.activo = 1 and b.activo = 1 and "); + qryStr.append("b.puntoventa_id = :puntoventa_id and b.estacion_id = :estacion_id"); + + SQLQuery query = getSession().createSQLQuery(qryStr.toString()); + query.setParameter("puntoventa_id", puntoVenta.getPuntoventaId()); + query.setParameter("estacion_id", estacion.getEstacionId()); + + List list = query.list(); + BigDecimal result = list.get(0); + return (result.intValue() > 0); + } } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java index 8a19b7a9e..5317b769d 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java @@ -46,6 +46,14 @@ public class EstacionServiceImpl implements EstacionService { @Transactional(rollbackFor = BusinessException.class) public Estacion suscribirActualizar(Estacion estacion) throws BusinessException { + if (!ApplicationProperties.getInstance().generarRotinaFolios()){ + Estacion estacionPuntoVentaAnterior = estacionDAO.obtenerID(estacion.getEstacionId()); + if (!estacionPuntoVentaAnterior.getPuntoVenta().equals(estacion.getPuntoVenta())){ + if (estacionDAO.temEstoque(estacionPuntoVentaAnterior.getPuntoVenta(), estacion)){ + throw new BusinessException("estacionServiceImpl.msg.hayStock"); + } + } + } Boolean esMacDuplicado = Boolean.FALSE; List lsEstacionMac = estacionDAO.buscar(estacion.getDescmac()); if (!lsEstacionMac.isEmpty()) {