- Empezada nueva vista y modelo gastos.
This commit is contained in:
Bryam105
2026-05-29 11:42:05 -03:00
parent 1f07d1b53f
commit 74a38420d8
13 changed files with 699 additions and 4 deletions
+27 -3
View File
@@ -161,8 +161,8 @@
});
});
// enviar a wsp
function enviarPedido() {
// enviar a wsp y guardar gasto
async function enviarPedido() {
let telefonoRaw = "{{ $supplier->phone }}";
let telefono = telefonoRaw.replace(/\D/g, '');
@@ -177,14 +177,16 @@
let mensaje = `Hola *{{ $supplier->name }}*, me comunico de Bicicletería Lauck para realizar el siguiente pedido:\n\n`;
let hayProductos = false;
let productsToSave = [];
document.querySelectorAll('.product-row').forEach(row => {
const isChecked = row.querySelector('.product-check').checked;
const qty = row.querySelector('.product-qty').value;
const qty = parseInt(row.querySelector('.product-qty').value);
const name = row.querySelector('.product-name').innerText.trim();
if (isChecked && qty > 0) {
mensaje += `- ${qty}x ${name}\n`;
productsToSave.push({ name: name, qty: qty });
hayProductos = true;
}
});
@@ -196,6 +198,28 @@
mensaje += `\n¡Muchas gracias!`;
try {
// Guardar el Gasto en el backend
const response = await fetch("{{ route('suppliers.storeOrder', $supplier) }}", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': '{{ csrf_token() }}'
},
body: JSON.stringify({ products: productsToSave })
});
const data = await response.json();
if(!data.success) {
alert('Hubo un error al registrar el pedido en el sistema.');
return;
}
} catch (error) {
alert('Hubo un error de conexión al intentar guardar el pedido.');
console.error(error);
return;
}
const url = `https://wa.me/${telefono}?text=${encodeURIComponent(mensaje)}`;
window.open(url, '_blank');
}