mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-22 00:30:23 +00:00
trabajando en la vista del pedido
This commit is contained in:
@ -52,6 +52,9 @@ public class PedidoLinea {
|
||||
@Column(name = "estado_manual", nullable = false)
|
||||
private Boolean estadoManual;
|
||||
|
||||
@Column(name = "fecha_entrega")
|
||||
private LocalDateTime fechaEntrega;
|
||||
|
||||
@Column(name = "created_at")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@ -100,6 +103,14 @@ public class PedidoLinea {
|
||||
this.estadoManual = estadoManual;
|
||||
}
|
||||
|
||||
public LocalDateTime getFechaEntrega() {
|
||||
return fechaEntrega;
|
||||
}
|
||||
|
||||
public void setFechaEntrega(LocalDateTime fechaEntrega) {
|
||||
this.fechaEntrega = fechaEntrega;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import java.util.List;
|
||||
public interface PedidoLineaRepository extends JpaRepository<PedidoLinea, Long> {
|
||||
|
||||
List<PedidoLinea> findByPedidoId(Long pedidoId);
|
||||
List<PedidoLinea> findByPedidoIdOrderByIdAsc(Long pedidoId);
|
||||
|
||||
List<PedidoLinea> findByPresupuestoId(Long presupuestoId);
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package com.imprimelibros.erp.pedidos;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Instant;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
@ -19,5 +19,5 @@ public interface PedidoRepository extends JpaRepository<Pedido, Long>, JpaSpecif
|
||||
AND p.createdAt >= :afterDate
|
||||
""")
|
||||
Double sumTotalByCreatedByAndCreatedAtAfter(@Param("userId") Long userId,
|
||||
@Param("afterDate") LocalDateTime afterDate);
|
||||
@Param("afterDate") Instant afterDate);
|
||||
}
|
||||
|
||||
@ -2,8 +2,10 @@ package com.imprimelibros.erp.pedidos;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -44,7 +46,7 @@ public class PedidoService {
|
||||
public int getDescuentoFidelizacion(Long userId) {
|
||||
// descuento entre el 1% y el 6% para clientes fidelidad (mas de 1500€ en el
|
||||
// ultimo año)
|
||||
LocalDateTime haceUnAno = LocalDateTime.now().minusYears(1);
|
||||
Instant haceUnAno = Instant.now().minusSeconds(365 * 24 * 60 * 60);
|
||||
double totalGastado = pedidoRepository.sumTotalByCreatedByAndCreatedAtAfter(userId, haceUnAno);
|
||||
if (totalGastado < 1200) {
|
||||
return 0;
|
||||
@ -127,6 +129,32 @@ public class PedidoService {
|
||||
return saved;
|
||||
}
|
||||
|
||||
/** Lista de los items del pedido preparados para la vista*/
|
||||
@Transactional
|
||||
public List<Map<String, Object>> getLineas(Long pedidoId, Locale locale) {
|
||||
Pedido p = pedidoRepository.findById(pedidoId).orElse(null);
|
||||
if (p == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<Map<String, Object>> resultados = new ArrayList<>();
|
||||
List<PedidoLinea> items = pedidoLineaRepository.findByPedidoIdOrderByIdAsc(p.getId());
|
||||
for (PedidoLinea item : items) {
|
||||
|
||||
Presupuesto presupuesto = item.getPresupuesto();
|
||||
Map<String, Object> elemento = presupuestoService.getPresupuestoInfoForCard(presupuesto, locale);
|
||||
elemento.put("estado", item.getEstado());
|
||||
elemento.put("fechaEntrega", item.getFechaEntrega() != null ?
|
||||
Utils.formatDate(item.getFechaEntrega(), locale) : "");
|
||||
elemento.put("lineaId", item.getId());
|
||||
resultados.add(elemento);
|
||||
}
|
||||
return resultados;
|
||||
}
|
||||
|
||||
/***************************
|
||||
* MÉTODOS PRIVADOS
|
||||
***************************/
|
||||
@Transactional
|
||||
private void saveDireccionesPedidoLinea(
|
||||
Map<String, Map<String, Object>> direcciones,
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.imprimelibros.erp.pedidos;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.security.Principal;
|
||||
@ -12,6 +13,7 @@ import java.util.Map;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
|
||||
import com.imprimelibros.erp.common.Utils;
|
||||
import com.imprimelibros.erp.datatables.DataTable;
|
||||
@ -31,13 +33,15 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
public class PedidosController {
|
||||
|
||||
private final PedidoRepository repoPedido;
|
||||
private final PedidoService pedidoService;
|
||||
private final UserDao repoUser;
|
||||
private final MessageSource messageSource;
|
||||
private final PedidoLineaRepository repoPedidoLinea;
|
||||
|
||||
public PedidosController(PedidoRepository repoPedido, UserDao repoUser, MessageSource messageSource,
|
||||
public PedidosController(PedidoRepository repoPedido, PedidoService pedidoService, UserDao repoUser, MessageSource messageSource,
|
||||
PedidoLineaRepository repoPedidoLinea) {
|
||||
this.repoPedido = repoPedido;
|
||||
this.pedidoService = pedidoService;
|
||||
this.repoUser = repoUser;
|
||||
this.messageSource = messageSource;
|
||||
this.repoPedidoLinea = repoPedidoLinea;
|
||||
@ -162,4 +166,21 @@ public class PedidosController {
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/view/{id}")
|
||||
public String verPedido(
|
||||
@PathVariable(name = "id", required = true) Long id,
|
||||
Model model, Locale locale) {
|
||||
|
||||
Boolean isAdmin = Utils.isCurrentUserAdmin();
|
||||
if (isAdmin) {
|
||||
model.addAttribute("isAdmin", true);
|
||||
} else {
|
||||
model.addAttribute("isAdmin", false);
|
||||
}
|
||||
List<Map<String, Object>> lineas = pedidoService.getLineas(id, locale);
|
||||
model.addAttribute("lineas", lineas);
|
||||
model.addAttribute("id", id);
|
||||
return "imprimelibros/pedidos/pedidos-view";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user