VENDEDOR EN PEDIDO Y EN ADMINISTRADOR

This commit is contained in:
2026-06-11 14:08:03 -05:00
parent ad3911d3c3
commit e4588b75db
14 changed files with 758 additions and 187 deletions
+22 -3
View File
@@ -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
})
});