mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-23 09:10:22 +00:00
terminado resumen
This commit is contained in:
@ -2,7 +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";
|
||||
import { formateaMoneda } from "../utils.js";
|
||||
|
||||
class PresupuestoCliente {
|
||||
|
||||
@ -157,6 +157,9 @@ class PresupuestoCliente {
|
||||
// pestaña extras
|
||||
this.divExtras = $('#div-extras');
|
||||
|
||||
// pestaña resumen
|
||||
this.tablaResumen = $('#resumen-tabla-final');
|
||||
|
||||
// resumen
|
||||
this.summaryTableInterior = $('#summary-interior');
|
||||
this.summaryTableCubierta = $('#summary-cubierta');
|
||||
@ -1394,16 +1397,17 @@ class PresupuestoCliente {
|
||||
|
||||
const servicios = [];
|
||||
$('.service-checkbox:checked').each(function () {
|
||||
const $servicio = $(this);
|
||||
const $servicio = $(this);
|
||||
servicios.push({
|
||||
id: $servicio.attr('id') ?? $(`label[for="${$servicio.attr('id')}"] .service-title`).text().trim(),
|
||||
label: $(`label[for="${$servicio.attr('id')}"] .service-title`).text().trim(),
|
||||
price: $servicio.data('price') ?? $(`label[for="${$servicio.attr('id')}"] .service-price`).text().trim().replace(" " + self.divExtras.data('currency'), ''),
|
||||
});
|
||||
});
|
||||
|
||||
const body = {
|
||||
presupuesto: this.#getPresupuestoData(),
|
||||
servicios: servicios
|
||||
presupuesto: this.#getPresupuestoData(),
|
||||
servicios: servicios
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
@ -1413,7 +1417,7 @@ class PresupuestoCliente {
|
||||
data: JSON.stringify(body)
|
||||
}).then((data) => {
|
||||
$('#resumen-titulo').text(data.titulo);
|
||||
$('#resumen-texto').html(data.texto);
|
||||
this.#updateResumenTable(data);
|
||||
}).catch((error) => {
|
||||
console.error("Error obtener resumen: ", error);
|
||||
});
|
||||
@ -1505,6 +1509,52 @@ class PresupuestoCliente {
|
||||
});
|
||||
}
|
||||
|
||||
#updateResumenTable(data) {
|
||||
this.tablaResumen.find('tbody').empty();
|
||||
|
||||
const lineas = Object.keys(data).filter(k => k.startsWith("linea")).sort((a, b) => {
|
||||
const numA = parseInt(a.replace("linea", ""), 10);
|
||||
const numB = parseInt(b.replace("linea", ""), 10);
|
||||
return numA - numB;
|
||||
});
|
||||
const servicios = data.servicios || [];
|
||||
|
||||
let total = 0;
|
||||
|
||||
const locale = document.documentElement.lang || 'es-ES';
|
||||
|
||||
for (const l of lineas) {
|
||||
const row = `
|
||||
<tr>
|
||||
<td>${l=="linea0" ? `<img style="max-width: 60px; height: auto;" src="${data.imagen}" alt="${data.imagen_alt}" class="img-fluid" />` : ''}</td>
|
||||
<td>${data[l].descripcion}</td>
|
||||
<td class="text-center">${data[l].cantidad}</td>
|
||||
<td class="text-center">${formateaMoneda(data[l].precio_unitario, 4, locale)}</td>
|
||||
<td class="text-end">${formateaMoneda(data[l].precio_total, 2, locale)}</td>
|
||||
</tr>
|
||||
`;
|
||||
total += data[l].precio_total;
|
||||
this.tablaResumen.find('tbody').append(row);
|
||||
}
|
||||
for (const s of servicios) {
|
||||
const row = `
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>${s.descripcion}</td>
|
||||
<td class="text-center">1</td>
|
||||
<td class="text-center">${formateaMoneda(s.precio, 2, locale)}</td>
|
||||
<td class="text-end">${formateaMoneda(s.precio, 2, locale)}</td>
|
||||
</tr>
|
||||
`;
|
||||
total += s.precio;
|
||||
this.tablaResumen.find('tbody').append(row);
|
||||
}
|
||||
|
||||
$('#resumen-base').text(formateaMoneda(total, 2, locale));
|
||||
$('#resumen-iva').text(formateaMoneda(total * 0.04, 2, locale));
|
||||
$('#resumen-total').text(formateaMoneda(total * 1.04, 2, locale));
|
||||
}
|
||||
|
||||
/******************************
|
||||
* END RESUMEN
|
||||
******************************/
|
||||
|
||||
Reference in New Issue
Block a user