acabando presupuesto

This commit is contained in:
2025-10-16 21:46:02 +02:00
parent ff9c04afb6
commit ea8a005cde
11 changed files with 349 additions and 139 deletions

View File

@ -3,7 +3,6 @@ import { formateaMoneda } from "../utils.js";
$(document).on('change', '#maquetacion', function (e) {
e.preventDefault();
if ($('#maquetacion').is(':checked')) {
$.get("/presupuesto/public/maquetacion/form", function (data) {

View File

@ -211,6 +211,7 @@ export default class PresupuestoWizard {
this.#initDatosGenerales();
if (presupuestoId && mode !== 'public') {
await fetch(`/presupuesto/api/get?id=${encodeURIComponent(presupuestoId)}`, {
headers: {
'Accept': 'application/json',
@ -218,12 +219,16 @@ export default class PresupuestoWizard {
})
.then(r => r.json())
.then(dto => {
sessionStorage.removeItem("formData");
this.formData = dto;
this.#cacheFormData();
this.#loadDatosGeneralesData();
});
} else {
if (stored) {
sessionStorage.removeItem("formData");
this.formData = JSON.parse(stored);
this.#cacheFormData();
this.#loadDatosGeneralesData();
}
}
@ -290,8 +295,29 @@ export default class PresupuestoWizard {
}
}
});
}
// Usa function() para que `this` sea el botón
$('.btn-imprimir').on('click', (e) => {
e.preventDefault();
// obtén el id de donde lo tengas (data-attr o variable global)
const id = this.opts.presupuestoId;
const url = `/api/pdf/presupuesto/${id}?mode=download`;
// Truco: crear <a> y hacer click
const a = document.createElement('a');
a.href = url;
a.target = '_self'; // descarga en la misma pestaña
// a.download = `presupuesto-${id}.pdf`; // opcional, tu server ya pone filename
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
});
}
async #guardarPresupuesto() {
@ -1742,7 +1768,7 @@ export default class PresupuestoWizard {
this.divExtras.append(item.render());
}
if (!this.formData.servicios.servicios.includes(s => s.id === "ferro-digital")) {
if (!this.formData.servicios.servicios.some(s => s.id === "ferro-digital")) {
this.formData.servicios.servicios.push({
id: "ferro-digital",
label: "Ferro Digital",
@ -1776,6 +1802,15 @@ export default class PresupuestoWizard {
...result,
};
if (!this.formData.servicios.servicios.some(s => s.id === "maquetacion") && result.precio > 0) {
this.formData.servicios.servicios.push({
id: "maquetacion",
label: $(`label[for="maquetacion"] .service-title`).text().trim(),
units: 1,
price: result.precio,
});
}
this.#cacheFormData();
});
}