mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 00:48:49 +00:00
trabajando en el paso de parametros
This commit is contained in:
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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) => {
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user