NUEVO:
- Empezada nueva vista y modelo gastos.
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user