primera version final del presupuesto

This commit is contained in:
2025-10-17 09:21:31 +02:00
parent ea8a005cde
commit 46715d1017
11 changed files with 323 additions and 73 deletions

View File

@ -3,7 +3,6 @@ package com.imprimelibros.erp.pdf;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@ -16,12 +15,15 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.imprimelibros.erp.presupuesto.PresupuestoRepository;
import com.imprimelibros.erp.presupuesto.dto.Presupuesto;
import com.imprimelibros.erp.common.Utils;
@Service
public class PdfService {
private final TemplateRegistry registry;
private final PdfTemplateEngine engine;
private final PdfRenderer renderer;
private final PresupuestoRepository presupuestoRepository;
private final Utils utils;
private final Map<String, String> empresa = Map.of(
"nombre", "ImprimeLibros ERP",
@ -86,11 +88,12 @@ public class PdfService {
}
public PdfService(TemplateRegistry registry, PdfTemplateEngine engine, PdfRenderer renderer,
PresupuestoRepository presupuestoRepository) {
PresupuestoRepository presupuestoRepository, Utils utils) {
this.registry = registry;
this.engine = engine;
this.renderer = renderer;
this.presupuestoRepository = presupuestoRepository;
this.utils = utils;
}
private byte[] generate(DocumentSpec spec) {
@ -140,6 +143,9 @@ public class PdfService {
model.put("servicios", List.of(
Map.of("descripcion", "Transporte península", "unidades", 1, "precio", 90.00)));
Map<String, Object> specs = utils.getTextoPresupuesto(presupuesto, locale);
model.put("specs", specs);
Map<String, Object> pricing = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
@ -150,22 +156,22 @@ public class PdfService {
List<Integer> tiradas = snapshot.keySet().stream().toList();
pricing.put("tiradas", tiradas);
pricing.put("impresion", snapshot.values().stream()
.map(p -> formatCurrency(p.getPrecioTotalTirada(), locale))
.map(p -> Utils.formatCurrency(p.getPrecioTotalTirada(), locale))
.toList());
pricing.put("servicios", snapshot.values().stream()
.map(p -> formatCurrency(p.getServiciosTotal(), locale))
.map(p -> Utils.formatCurrency(p.getServiciosTotal(), locale))
.toList());
pricing.put("peso", snapshot.values().stream()
.map(p -> formatCurrency(p.getPeso(), locale))
.map(p -> Utils.formatCurrency(p.getPeso(), locale))
.toList());
pricing.put("iva_4", snapshot.values().stream()
.map(p -> formatCurrency(p.getIvaImporte4(), locale))
.map(p -> Utils.formatCurrency(p.getIvaImporte4(), locale))
.toList());
pricing.put("iva_21", snapshot.values().stream()
.map(p -> formatCurrency(p.getIvaImporte21(), locale))
.map(p -> Utils.formatCurrency(p.getIvaImporte21(), locale))
.toList());
pricing.put("total", snapshot.values().stream()
.map(p -> formatCurrency(p.getTotalConIva(), locale))
.map(p -> Utils.formatCurrency(p.getTotalConIva(), locale))
.toList());
pricing.put("show_iva_4", presupuesto.getIvaImporte4().floatValue() > 0);
pricing.put("show_iva_21", presupuesto.getIvaImporte21().floatValue() > 0);
@ -196,9 +202,4 @@ public class PdfService {
throw new RuntimeException("Error generando presupuesto PDF", e);
}
}
private static String formatCurrency(double value, Locale locale) {
NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale);
return currencyFormatter.format(value);
}
}