falta el update carrito del backend

This commit is contained in:
2025-10-29 13:31:25 +01:00
parent c272fd7b9b
commit 5e9631073e
17 changed files with 516 additions and 162 deletions

View File

@ -23,7 +23,6 @@ public class CartService {
private final CartRepository cartRepo;
private final CartItemRepository itemRepo;
private final MessageSource messageSource;
private final PresupuestoFormatter presupuestoFormatter;
private final PresupuestoRepository presupuestoRepo;
private final Utils utils;
@ -33,7 +32,6 @@ public class CartService {
this.cartRepo = cartRepo;
this.itemRepo = itemRepo;
this.messageSource = messageSource;
this.presupuestoFormatter = presupuestoFormatter;
this.presupuestoRepo = presupuestoRepo;
this.utils = utils;
}
@ -152,4 +150,29 @@ public class CartService {
return resumen;
}
public Map<String, Object> getCartSummary(List<Map<String, Object>> cartItems, Locale locale) {
double base = 0.0;
double iva4 = 0.0;
double iva21 = 0.0;
for (Map<String, Object> item : cartItems) {
Presupuesto p = presupuestoRepo.findById((Long) item.get("presupuestoId"))
.orElseThrow(() -> new IllegalStateException("Presupuesto no encontrado: " + item.get("presupuestoId")));
base += p.getBaseImponible().doubleValue();
iva4 += p.getIvaImporte4().doubleValue();
iva21 += p.getIvaImporte21().doubleValue();
}
double total = base + iva4 + iva21;
Map<String, Object> summary = new HashMap<>();
summary.put("base", Utils.formatCurrency(base, locale));
summary.put("iva4", Utils.formatCurrency(iva4, locale));
summary.put("iva21", Utils.formatCurrency(iva21, locale));
summary.put("total", Utils.formatCurrency(total, locale));
return summary;
}
}