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);
}
@GetMapping("/public/getresumen")
public ResponseEntity<?> getResumen(Presupuesto presupuesto, @RequestParam HashMap<String, Object> summary, Locale locale) {
return ResponseEntity.ok(presupuestoService.getResumen(presupuesto, summary, locale));
// Se hace un post para no tener problemas con la longitud de la URL
@PostMapping("/public/getresumen")
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;
}
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<>();
resumen.put("titulo", presupuesto.getTitulo());
@ -795,6 +795,7 @@ public class PresupuestoService {
*/
String textoResumen = messageSource.getMessage("presupuesto.resumen-texto", null, locale);
textoResumen = textoResumen.replace("{tipoEncuadernacion}", summary.get("encuadernacion").toString());
resumen.put("resumen", textoResumen);
return resumen;
}

View File

@ -2,6 +2,7 @@ import imagen_presupuesto from "./imagen-presupuesto.js";
import ServiceOptionCard from "./service-option-card.js";
import TiradaCard from "./tirada-price-card.js";
import * as Summary from "./summary.js";
import { bracketPrefix, dotify } from "../utils.js";
class PresupuestoCliente {
@ -1388,14 +1389,18 @@ class PresupuestoCliente {
this.#changeTab('pills-seleccion-tirada');
this.summaryTableExtras.addClass('d-none');
} 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({
url: '/presupuesto/public/getresumen',
type: 'GET',
data: {
presupuesto: this.#getPresupuestoData(),
summary: data,
}
type: 'POST',
data: payload,
}).then((data) => {
console.log("Extras validados correctamente", data);
}).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 {
return new Intl.NumberFormat(locale, { style: 'currency', currency, minimumFractionDigits: digits, useGrouping: true }).format(valor);
} catch {
return valor;
}
}
export { formateaMoneda };
function formateaNumero({
export function formateaNumero({
valor,
digits = 2,
style = 'decimal',
@ -31,10 +30,34 @@ function formateaNumero({
return new Intl.NumberFormat(locale, opts).format(n);
}
export { formateaNumero };
function isNumber(value) {
export function isNumber(value) {
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;
}