diff --git a/proveedores.html b/proveedores.html index 415b092..5f93d62 100644 --- a/proveedores.html +++ b/proveedores.html @@ -399,6 +399,7 @@ const addr = raw['Dirección'] || raw['DOMICILIO'] || ""; const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || ""; const fullAddr = `${addr} ${pop}`.trim(); + const cp = raw['Código Postal'] || raw['C.P.'] || ""; const phone = (raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "").match(/[6789]\d{8}/)?.[0] || ""; let guildName = null; @@ -415,6 +416,7 @@ let bgClass = 'bg-white'; let isLocked = false; let lockedMsg = ''; + let showQuickQueueBtn = false; // Variable para saber si mostrar el botón rápido const autoStatus = (svc.automation_status || '').toLowerCase(); const sysStatus = (svc.status || '').toLowerCase(); @@ -441,6 +443,8 @@ } else if (autoStatus === 'failed') { bgClass = 'bg-red-50/40 border-red-200 hover:border-red-400'; isLocked = false; + // Si ha fallado, pero tiene gremio detectado, le damos la opción de reenviar a la bolsa rápidamente + if (rawGuildId) showQuickQueueBtn = true; badgeEstado = `
@@ -452,8 +456,14 @@ // AQUÍ USAMOS EL COLOR Y NOMBRE DEL ESTADO DE LA BASE DE DATOS const cMap = colorMap[dbStatusObj.color] || colorMap['gray']; bgClass = `${cMap.bg.replace('100', '50')}/40 ${cMap.border} hover:border-${dbStatusObj.color}-400`; - isLocked = true; - lockedMsg = `Este servicio ya está en estado: ${dbStatusObj.name}. Ve al Panel Operativo.`; + + // Si está en un estado que no sea "Pendiente" o "Sin Asignar", se bloquea la edición por aquí + if(!dbStatusObj.name.toLowerCase().includes('pendiente') && !dbStatusObj.name.toLowerCase().includes('desasignado')) { + isLocked = true; + lockedMsg = `Este servicio ya está en estado: ${dbStatusObj.name}. Ve al Panel Operativo.`; + } else if(rawGuildId && !opName) { + showQuickQueueBtn = true; // Si está pendiente, sin técnico y tiene gremio -> Botón rápido + } badgeEstado = `
@@ -486,6 +496,7 @@
`; } else { bgClass = isUrgent ? 'bg-red-50/20 border-red-300 hover:border-red-50 shadow-[0_0_15px_rgba(239,68,68,0.15)]' : 'bg-white border-slate-200'; + if(rawGuildId) showQuickQueueBtn = true; // Si está virgen y tiene gremio -> Botón rápido badgeEstado = `
@@ -521,6 +532,15 @@ } }; + let quickQueueHtml = ''; + if (showQuickQueueBtn) { + quickQueueHtml = ` + + `; + } + card.innerHTML = `
@@ -536,9 +556,10 @@ ${urgentBadge}

${fullAddr}

-
+
#${svc.service_ref} ${guildName ? `${guildName}` : ''} + ${quickQueueHtml}
@@ -748,6 +769,30 @@ finally { btn.disabled = false; } } + // Nueva función para el botón rápido + async function quickSendToQueue(event, id, guildId, cp) { + event.stopPropagation(); // Evita que se abra el modal + + if(!guildId) { + showToast("⚠️ Falta el gremio. Ábrelo para asignarlo.", true); + return; + } + + try { + showToast("🚀 Iniciando automatismo..."); + const res = await fetch(`${API_URL}/providers/automate/${id}`, { + method: 'POST', + headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, + body: JSON.stringify({ guild_id: guildId, cp: cp }) + }); + const data = await res.json(); + if (data.ok) { + showToast("✅ ¡En cola! Se ha enviado a los operarios."); + loadInbox(); // Refresca la lista sin cerrar modales (ya que no hay) + } else { showToast("❌ " + data.error, true); } + } catch (e) { showToast("❌ Error de conexión", true); } + } + async function sendToQueue() { const id = document.getElementById('impScrapedId').value; const payload = getFormPayload();