trabajando en el paso de parametros

This commit is contained in:
Jaime Jiménez
2025-09-22 09:37:54 +02:00
parent 62d67012be
commit 479cecf52b
4 changed files with 51 additions and 17 deletions

View File

@ -375,10 +375,15 @@ public class PresupuestoController {
return ResponseEntity.ok(resultado); return ResponseEntity.ok(resultado);
} }
@GetMapping("/public/getresumen") // Se hace un post para no tener problemas con la longitud de la URL
public ResponseEntity<?> getResumen(Presupuesto presupuesto, @RequestParam HashMap<String, Object> summary, Locale locale) { @PostMapping("/public/getresumen")
return ResponseEntity.ok(presupuestoService.getResumen(presupuesto, summary, locale)); public ResponseEntity<?> getResumen(@ModelAttribute("presupuesto") Presupuesto presupuesto,
@RequestParam String summary, Locale locale) throws JsonProcessingException {
Map<String, Object> summaryMap = new ObjectMapper().readValue(summary,
new TypeReference<Map<String, Object>>() {
});
return ResponseEntity.ok(presupuestoService.getResumen(presupuesto, summaryMap, locale));
} }
} }

View File

@ -781,7 +781,7 @@ public class PresupuestoService {
return out; return out;
} }
public Map<String, Object> getResumen(Presupuesto presupuesto, HashMap<String, Object> servicios, Locale locale) { public Map<String, Object> getResumen(Presupuesto presupuesto, Map<String, Object> summary, Locale locale) {
Map<String, Object> resumen = new HashMap<>(); Map<String, Object> resumen = new HashMap<>();
resumen.put("titulo", presupuesto.getTitulo()); resumen.put("titulo", presupuesto.getTitulo());
@ -795,6 +795,7 @@ public class PresupuestoService {
*/ */
String textoResumen = messageSource.getMessage("presupuesto.resumen-texto", null, locale); String textoResumen = messageSource.getMessage("presupuesto.resumen-texto", null, locale);
textoResumen = textoResumen.replace("{tipoEncuadernacion}", summary.get("encuadernacion").toString());
resumen.put("resumen", textoResumen); resumen.put("resumen", textoResumen);
return resumen; return resumen;
} }

View File

@ -2,6 +2,7 @@ import imagen_presupuesto from "./imagen-presupuesto.js";
import ServiceOptionCard from "./service-option-card.js"; import ServiceOptionCard from "./service-option-card.js";
import TiradaCard from "./tirada-price-card.js"; import TiradaCard from "./tirada-price-card.js";
import * as Summary from "./summary.js"; import * as Summary from "./summary.js";
import { bracketPrefix, dotify } from "../utils.js";
class PresupuestoCliente { class PresupuestoCliente {
@ -1388,14 +1389,18 @@ class PresupuestoCliente {
this.#changeTab('pills-seleccion-tirada'); this.#changeTab('pills-seleccion-tirada');
this.summaryTableExtras.addClass('d-none'); this.summaryTableExtras.addClass('d-none');
} else { } else {
const data = Summary.getSummaryData(); const summaryData = Summary.getSummaryData();
const presupuestoData = this.#getPresupuestoData();
const payload = {
...dotify(this.#getPresupuestoData(), 'presupuesto'),
summary: JSON.stringify(Summary.getSummaryData()),
};
$.ajax({ $.ajax({
url: '/presupuesto/public/getresumen', url: '/presupuesto/public/getresumen',
type: 'GET', type: 'POST',
data: { data: payload,
presupuesto: this.#getPresupuestoData(),
summary: data,
}
}).then((data) => { }).then((data) => {
console.log("Extras validados correctamente", data); console.log("Extras validados correctamente", data);
}).catch((error) => { }).catch((error) => {

View File

@ -1,14 +1,13 @@
function formateaMoneda(valor, digits = 2, locale = 'es-ES', currency = 'EUR') { export function formateaMoneda(valor, digits = 2, locale = 'es-ES', currency = 'EUR') {
try { try {
return new Intl.NumberFormat(locale, { style: 'currency', currency, minimumFractionDigits: digits, useGrouping: true }).format(valor); return new Intl.NumberFormat(locale, { style: 'currency', currency, minimumFractionDigits: digits, useGrouping: true }).format(valor);
} catch { } catch {
return valor; return valor;
} }
} }
export { formateaMoneda };
function formateaNumero({ export function formateaNumero({
valor, valor,
digits = 2, digits = 2,
style = 'decimal', style = 'decimal',
@ -31,10 +30,34 @@ function formateaNumero({
return new Intl.NumberFormat(locale, opts).format(n); return new Intl.NumberFormat(locale, opts).format(n);
} }
export { formateaNumero };
function isNumber(value) { export function isNumber(value) {
return !isNaN(Number(value)) && value.trim() !== ''; return !isNaN(Number(value)) && value.trim() !== '';
} }
export { isNumber };
// Aplana un objeto a "prefijo.clave" (sin arrays)
export function dotify(obj, prefix = '') {
const out = {};
const walk = (o, path) => {
Object.entries(o).forEach(([k, v]) => {
const key = path ? `${path}.${k}` : k;
if (v !== null && typeof v === 'object' && !Array.isArray(v)) {
walk(v, key);
} else {
out[key] = v;
}
});
};
walk(obj, prefix);
return out;
}
// Convierte {a:1, b:2} en {"summary[a]":1, "summary[b]":2}
export function bracketPrefix(obj, prefix) {
const out = {};
Object.entries(obj).forEach(([k, v]) => {
out[`${prefix}[${k}]`] = v;
});
return out;
}