|
|
|
@ -71,6 +71,13 @@ public class OrdenHelper { |
|
|
|
|
|
|
|
|
|
|
|
Optional<Orden> orden = ordenDAO.findById(vo.getOrden()); |
|
|
|
Optional<Orden> orden = ordenDAO.findById(vo.getOrden()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (orden.isPresent()) { |
|
|
|
|
|
|
|
if (EstadoOrdenEnum.PAGADO.equals(orden.get().getEstado())) { |
|
|
|
|
|
|
|
throw new NegocioException("No se puede agregar productos a una orden pagada", 2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (orden.isEmpty()) { |
|
|
|
if (orden.isEmpty()) { |
|
|
|
throw new NegocioException("Orden no encontrada", 2); |
|
|
|
throw new NegocioException("Orden no encontrada", 2); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -113,9 +120,36 @@ public class OrdenHelper { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
detalle.get().setDescuento(vo.getDescuento()); |
|
|
|
detalle.get().setDescuento(vo.getDescuento()); |
|
|
|
|
|
|
|
detalle.get().setEntregado(vo.getEntregado()); |
|
|
|
|
|
|
|
|
|
|
|
detalleDAO.save(detalle.get()); |
|
|
|
detalleDAO.save(detalle.get()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
evaluarProductosEntregados(detalle.get().getOrden().getId()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void evaluarProductosEntregados(Long idOrden) throws NegocioException { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Optional<Orden> orden = ordenDAO.findById(idOrden); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (orden.isEmpty()) { |
|
|
|
|
|
|
|
throw new NegocioException("Orden no encontrada", 2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean detallesPagados = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Detalle detalle: orden.get().getDetalle()) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Boolean.FALSE.equals(detalle.getEntregado())) { |
|
|
|
|
|
|
|
detallesPagados = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (detallesPagados) { |
|
|
|
|
|
|
|
orden.get().setEntregado(Boolean.TRUE); |
|
|
|
|
|
|
|
ordenDAO.save(orden.get()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<OrdenVO> mapperOrden(List<Orden> ordenes) { |
|
|
|
private List<OrdenVO> mapperOrden(List<Orden> ordenes) { |
|
|
|
@ -138,6 +172,7 @@ public class OrdenHelper { |
|
|
|
ordenVO.setFecha(orden.getFechaCreacion()); |
|
|
|
ordenVO.setFecha(orden.getFechaCreacion()); |
|
|
|
ordenVO.setEstado(orden.getEstado()); |
|
|
|
ordenVO.setEstado(orden.getEstado()); |
|
|
|
ordenVO.setMedio(orden.getMedioPago()); |
|
|
|
ordenVO.setMedio(orden.getMedioPago()); |
|
|
|
|
|
|
|
ordenVO.setEntregado(orden.getEntregado()); |
|
|
|
|
|
|
|
|
|
|
|
Integer total = 0; |
|
|
|
Integer total = 0; |
|
|
|
|
|
|
|
|
|
|
|
@ -177,6 +212,8 @@ public class OrdenHelper { |
|
|
|
detalleVO.setId(detalle.getId()); |
|
|
|
detalleVO.setId(detalle.getId()); |
|
|
|
detalleVO.setPrecio(detalle.getPrecio().getPrecio()); |
|
|
|
detalleVO.setPrecio(detalle.getPrecio().getPrecio()); |
|
|
|
detalleVO.setDescuento(detalle.getDescuento()); |
|
|
|
detalleVO.setDescuento(detalle.getDescuento()); |
|
|
|
|
|
|
|
detalleVO.setEntregado(detalle.getEntregado()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return detalleVO; |
|
|
|
return detalleVO; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -203,4 +240,11 @@ public class OrdenHelper { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<OrdenVO> obtenerPedidos() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Orden> ordenes = ordenDAO.getAllPedidos(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return mapperOrden(ordenes); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|