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;
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;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Property;
@ -24,6 +21,7 @@ import org.springframework.stereotype.Repository;
import com.rjconsultores.ventaboletos.dao.EstacionDAO;
import com.rjconsultores.ventaboletos.entidad.Estacion;
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
import com.rjconsultores.ventaboletos.entidad.Usuario;
/**
*

View File

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