gleimar 2014-01-16 14:18:11 +00:00
parent 8bb81378e7
commit 08b66ff46e
2 changed files with 23 additions and 12 deletions

View File

@ -4,15 +4,12 @@
*/ */
package com.rjconsultores.ventaboletos.dao.hibernate; package com.rjconsultores.ventaboletos.dao.hibernate;
import com.rjconsultores.ventaboletos.entidad.Usuario;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
import org.hibernate.Criteria; import org.hibernate.Criteria;
import org.hibernate.SQLQuery; import org.hibernate.SQLQuery;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order; import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections; import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Property; import org.hibernate.criterion.Property;
@ -24,6 +21,7 @@ import org.springframework.stereotype.Repository;
import com.rjconsultores.ventaboletos.dao.EstacionDAO; import com.rjconsultores.ventaboletos.dao.EstacionDAO;
import com.rjconsultores.ventaboletos.entidad.Estacion; import com.rjconsultores.ventaboletos.entidad.Estacion;
import com.rjconsultores.ventaboletos.entidad.PuntoVenta; import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
import com.rjconsultores.ventaboletos.entidad.Usuario;
/** /**
* *

View File

@ -45,7 +45,7 @@ public class EstacionServiceImpl implements EstacionService {
@Transactional(rollbackFor = BusinessException.class) @Transactional(rollbackFor = BusinessException.class)
public Estacion suscribirActualizar(Estacion estacion) throws BusinessException { public Estacion suscribirActualizar(Estacion estacion) throws BusinessException {
validarEstoque(estacion); validarEstoqueUpdate(estacion);
Boolean esMacDuplicado = Boolean.FALSE; Boolean esMacDuplicado = Boolean.FALSE;
List<Estacion> lsEstacionMac = estacionDAO.buscar(estacion.getDescmac()); List<Estacion> lsEstacionMac = estacionDAO.buscar(estacion.getDescmac());
@ -93,7 +93,12 @@ public class EstacionServiceImpl implements EstacionService {
} }
private void validarEstoque(Estacion estacion) throws BusinessException { private void validarEstoqueUpdate(Estacion estacion) throws BusinessException {
if (estacion.getEstacionId() == null) {
return;
}
if (!ApplicationProperties.getInstance().generarRotinaFolios()) { if (!ApplicationProperties.getInstance().generarRotinaFolios()) {
Estacion estacionPuntoVentaAnterior = estacionDAO.obtenerID(estacion.getEstacionId()); Estacion estacionPuntoVentaAnterior = estacionDAO.obtenerID(estacion.getEstacionId());
if (!estacionPuntoVentaAnterior.getPuntoVenta().equals(estacion.getPuntoVenta())) { if (!estacionPuntoVentaAnterior.getPuntoVenta().equals(estacion.getPuntoVenta())) {
@ -104,10 +109,18 @@ public class EstacionServiceImpl implements EstacionService {
} }
} }
private void validarEstoqueBorrar(Estacion estacion) throws BusinessException {
if (!ApplicationProperties.getInstance().generarRotinaFolios()) {
if (estacionDAO.temEstoque(estacion.getPuntoVenta(), estacion)) {
throw new BusinessException("estacionServiceImpl.msg.hayStock");
}
}
}
@Transactional @Transactional
public void borrar(Estacion entidad) throws BusinessException { public void borrar(Estacion entidad) throws BusinessException {
validarEstoque(entidad); validarEstoqueBorrar(entidad);
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
entidad.setFecmodif(Calendar.getInstance().getTime()); entidad.setFecmodif(Calendar.getInstance().getTime());