mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-24 09:40:21 +00:00
terminado. trabajando en el carrito. falta mensaje de ya añadido
This commit is contained in:
@ -0,0 +1,67 @@
|
||||
import { formateaMoneda } from '../../imprimelibros/utils.js';
|
||||
|
||||
$(() => {
|
||||
|
||||
updateTotal();
|
||||
|
||||
function updateTotal() {
|
||||
const items = $(".product");
|
||||
let iva4 = 0;
|
||||
let iva21 = 0;
|
||||
let base = 0;
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const item = $(items[i]);
|
||||
const b = item.data("base");
|
||||
const i4 = item.data("iva-4");
|
||||
const i21 = item.data("iva-21");
|
||||
base += parseFloat(b) || 0;
|
||||
iva4 += parseFloat(i4) || 0;
|
||||
iva21 += parseFloat(i21) || 0;
|
||||
}
|
||||
$("#base-cesta").text(formateaMoneda(base));
|
||||
if (iva4 > 0) {
|
||||
$("#iva-4-cesta").text(formateaMoneda(iva4));
|
||||
$("#tr-iva-4").show();
|
||||
} else {
|
||||
$("#tr-iva-4").hide();
|
||||
}
|
||||
if (iva21 > 0) {
|
||||
$("#iva-21-cesta").text(formateaMoneda(iva21));
|
||||
$("#tr-iva-21").show();
|
||||
} else {
|
||||
$("#tr-iva-21").hide();
|
||||
}
|
||||
const total = base + iva4 + iva21;
|
||||
$("#total-cesta").text(formateaMoneda(total));
|
||||
}
|
||||
|
||||
$(document).on("click", ".delete-item", async function (event) {
|
||||
|
||||
event.preventDefault();
|
||||
const cartItemId = $(this).data("cart-item-id");
|
||||
const card = $(this).closest('.card.product');
|
||||
|
||||
// CSRF (Spring Security)
|
||||
const csrfToken = document.querySelector('meta[name="_csrf"]')?.content || '';
|
||||
const csrfHeader = document.querySelector('meta[name="_csrf_header"]')?.content || 'X-CSRF-TOKEN';
|
||||
|
||||
try {
|
||||
const res = await fetch(`/cart/delete/item/${cartItemId}`, {
|
||||
method: 'DELETE',
|
||||
headers: { [csrfHeader]: csrfToken }
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
console.error('Error al eliminar. Status:', res.status);
|
||||
return;
|
||||
}
|
||||
else{
|
||||
card?.remove();
|
||||
updateTotal();
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.error('Error en la solicitud:', err);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -1700,6 +1700,7 @@ export default class PresupuestoWizard {
|
||||
window.PRESUPUESTO_ID = data.presupuesto_id;
|
||||
}
|
||||
body.presupuesto.id = window.PRESUPUESTO_ID || body.presupuesto.id || null;
|
||||
this.opts.presupuestoId = window.PRESUPUESTO_ID;
|
||||
|
||||
this.#updateResumenTable(data);
|
||||
}).catch((error) => {
|
||||
|
||||
Reference in New Issue
Block a user