VENDEDOR EN PEDIDO Y EN ADMINISTRADOR
This commit is contained in:
+22
-3
@@ -457,10 +457,27 @@ function setupCartModals() {
|
||||
});
|
||||
|
||||
// Generar PDF → abrir formulario
|
||||
document.getElementById('cartPdfBtn').addEventListener('click', () => {
|
||||
document.getElementById('cartPdfBtn').addEventListener('click', async () => {
|
||||
cerrarModal('cartModal');
|
||||
document.getElementById('orderForm').reset();
|
||||
document.getElementById('orderError').classList.remove('show');
|
||||
|
||||
// Cargar vendedores en el select
|
||||
const sel = document.getElementById('orderVendedor');
|
||||
sel.innerHTML = '<option value="">Selecciona un vendedor</option>';
|
||||
try {
|
||||
const res = await fetch('/api/vendedores');
|
||||
if (res.ok) {
|
||||
const vendedores = await res.json();
|
||||
vendedores.forEach(v => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = v.nombre;
|
||||
opt.textContent = v.nombre;
|
||||
sel.appendChild(opt);
|
||||
});
|
||||
}
|
||||
} catch {}
|
||||
|
||||
abrirModal('orderModal');
|
||||
});
|
||||
|
||||
@@ -479,9 +496,10 @@ async function enviarPedido() {
|
||||
const ciudad = document.getElementById('orderCiudad').value.trim();
|
||||
const telefono = document.getElementById('orderTelefono').value.trim();
|
||||
const direccion = document.getElementById('orderDireccion').value.trim();
|
||||
const vendedor = document.getElementById('orderVendedor').value;
|
||||
const errEl = document.getElementById('orderError');
|
||||
|
||||
if (!nombre || !ciudad || !telefono || !direccion) {
|
||||
if (!nombre || !ciudad || !telefono || !direccion || !vendedor) {
|
||||
errEl.textContent = 'Todos los campos son obligatorios';
|
||||
errEl.classList.add('show');
|
||||
return;
|
||||
@@ -502,7 +520,8 @@ async function enviarPedido() {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
items: carrito.map(i => ({ ref: i.ref, nombre: i.nombre, precio: i.precio, cantidad: i.cantidad })),
|
||||
cliente: { nombre, ciudad, telefono, direccion }
|
||||
cliente: { nombre, ciudad, telefono, direccion },
|
||||
vendedor
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user