From 379512c8671796b4f64e8fdae20f1fd4e7d6750f Mon Sep 17 00:00:00 2001 From: marsalva Date: Sun, 15 Feb 2026 14:38:37 +0000 Subject: [PATCH] Actualizar automatizaciones.html --- automatizaciones.html | 177 +++++++++++++++++++++++++++--------------- 1 file changed, 114 insertions(+), 63 deletions(-) diff --git a/automatizaciones.html b/automatizaciones.html index dc7137b..168b678 100644 --- a/automatizaciones.html +++ b/automatizaciones.html @@ -26,19 +26,36 @@
-
+

Buzón de Automatizaciones

-

Pulsa sobre cualquier servicio activo para validar los datos.

+

Gestiona y filtra tus expedientes capturados.

+
+
+ + +
+
+ + +
+
+
@@ -220,67 +237,105 @@ const resSvc = await fetch(`${API_URL}/providers/scraped`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); const dataSvc = await resSvc.json(); scrapedData = dataSvc.services || []; - container.innerHTML = ""; - if(scrapedData.length === 0) { - container.innerHTML = '
No hay expedientes pendientes.
'; - return; - } - scrapedData.forEach(svc => { - const raw = svc.raw_data || {}; - const isArchived = svc.status === 'archived'; - const statusLabel = isArchived ? 'ARCHIVADO' : 'SERVICIO ACTIVO'; - const statusClass = isArchived ? 'bg-gray-100 text-gray-500 border-gray-200' : 'bg-emerald-50 text-emerald-600 border-emerald-100'; - const name = raw['Nombre Cliente'] || raw['CLIENTE'] || "S/N"; - const addr = raw['Dirección'] || raw['DOMICILIO'] || ""; - const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || ""; - const fullAddr = `${addr} ${pop}`.trim(); - const phone = (raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "").match(/[6789]\d{8}/)?.[0] || ""; - - // --- OBTENER NOMBRES DE GREMIO Y OPERARIO (SI EXISTEN EN EL BORRADOR) --- - const guildName = allGuilds.find(g => g.id == raw['guild_id'])?.name || null; - const opName = raw['assigned_to_name'] || null; + + // Actualizar Filtro de Compañías + const companyFilter = document.getElementById('filterCompany'); + const companies = [...new Set(scrapedData.map(s => { + const raw = s.raw_data || {}; + return (raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "DESCONOCIDA").toString().toUpperCase().trim(); + }))].sort(); + + companyFilter.innerHTML = ''; + companies.forEach(c => { + companyFilter.innerHTML += ``; + }); - const card = document.createElement('div'); - card.className = `service-card bg-white p-5 rounded-2xl border ${isArchived ? 'archived' : 'shadow-sm'} flex items-center justify-between transition-all group fade-in text-left`; - card.onclick = (e) => { - if (e.target.closest('a') || e.target.closest('button')) return; - if (isArchived) showToast("⚠️ Este servicio está ARCHIVADO y no se puede editar.", true); - else openEditor(svc.id); - }; - card.innerHTML = ` -
-
- ${svc.provider === 'multiasistencia' ? 'MULTI' : 'HOME'} - + renderFilteredInbox(); // Render inicial con filtros aplicados + } catch (e) { showToast("Error de conexión", true); } + } + + // FUNCIÓN PARA RENDERIZAR SEGÚN FILTROS + function renderFilteredInbox() { + const container = document.getElementById('inboxContainer'); + const search = document.getElementById('searchBox').value.toUpperCase(); + const provider = document.getElementById('filterProvider').value; + const company = document.getElementById('filterCompany').value; + + const filtered = scrapedData.filter(svc => { + const raw = svc.raw_data || {}; + const name = (raw['Nombre Cliente'] || raw['CLIENTE'] || "").toUpperCase(); + const ref = (svc.service_ref || "").toUpperCase(); + const addr = (raw['Dirección'] || raw['DOMICILIO'] || "").toUpperCase(); + const compName = (raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "").toString().toUpperCase().trim(); + + const matchesSearch = name.includes(search) || ref.includes(search) || addr.includes(search); + const matchesProvider = provider === "ALL" || svc.provider === provider; + const matchesCompany = company === "ALL" || compName === company; + + return matchesSearch && matchesProvider && matchesCompany; + }); + + container.innerHTML = ""; + if(filtered.length === 0) { + container.innerHTML = '
No se encontraron expedientes con los filtros actuales.
'; + return; + } + + filtered.forEach(svc => { + const raw = svc.raw_data || {}; + const isArchived = svc.status === 'archived'; + const statusLabel = isArchived ? 'ARCHIVADO' : 'SERVICIO ACTIVO'; + const statusClass = isArchived ? 'bg-gray-100 text-gray-500 border-gray-200' : 'bg-emerald-50 text-emerald-600 border-emerald-100'; + const name = raw['Nombre Cliente'] || raw['CLIENTE'] || "S/N"; + const addr = raw['Dirección'] || raw['DOMICILIO'] || ""; + const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || ""; + const fullAddr = `${addr} ${pop}`.trim(); + const phone = (raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "").match(/[6789]\d{8}/)?.[0] || ""; + + const guildName = allGuilds.find(g => g.id == raw['guild_id'])?.name || null; + const opName = raw['assigned_to_name'] || null; + + const card = document.createElement('div'); + card.className = `service-card bg-white p-5 rounded-2xl border ${isArchived ? 'archived' : 'shadow-sm'} flex items-center justify-between transition-all group fade-in text-left`; + card.onclick = (e) => { + if (e.target.closest('a') || e.target.closest('button')) return; + if (isArchived) showToast("⚠️ Este servicio está ARCHIVADO y no se puede editar.", true); + else openEditor(svc.id); + }; + card.innerHTML = ` +
+
+ ${svc.provider === 'multiasistencia' ? 'MULTI' : 'HOME'} + +
+
+ +
+
+
+

${name}

+ ${statusLabel}
-
- -
-
-
-

${name}

- ${statusLabel} -
-

${fullAddr}

- -
- #${svc.service_ref} - ${guildName ? `${guildName}` : ''} - ${opName ? `${opName}` : ''} -
+

${fullAddr}

+ +
+ #${svc.service_ref} + ${guildName ? `${guildName}` : ''} + ${opName ? `${opName}` : ''}
-
- ${!isArchived ? ` - ` : ''} -
`; - container.appendChild(card); - }); - lucide.createIcons(); - } catch (e) { showToast("Error de conexión", true); } +
+
+ ${!isArchived ? ` + +
` : ''} +
`; + container.appendChild(card); + }); + lucide.createIcons(); } async function openEditor(id) { @@ -307,7 +362,6 @@ const isUrgent = raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true' || raw['URGENTE'] === 'SI'; document.getElementById('impUrgent').value = isUrgent.toString(); - // --- RECUPERACIÓN DE DATOS GUARDADOS PREVIAMENTE --- document.getElementById('impNotesInt').value = raw['internal_notes'] || ""; document.getElementById('impNotesExt').value = raw['client_notes'] || ""; @@ -315,7 +369,6 @@ document.getElementById('impGuild').value = savedGuild; if(savedGuild) { - // Cargamos operarios y luego seleccionamos el guardado await loadOpsForGuild(savedGuild); document.getElementById('impOperator').value = raw['assigned_to'] || ""; } else { @@ -333,7 +386,6 @@ const btn = e.currentTarget; btn.disabled = true; - // --- OBTENER NOMBRE DEL OPERARIO SELECCIONADO PARA MOSTRAR EN LA TARJETA --- const opSelect = document.getElementById('impOperator'); const opName = opSelect.options[opSelect.selectedIndex]?.text.includes('--') ? null : opSelect.options[opSelect.selectedIndex]?.text; @@ -344,7 +396,6 @@ cp: document.getElementById('impCP').value, description: document.getElementById('impDesc').value, is_urgent: document.getElementById('impUrgent').value === 'true', - // --- CAMPOS CORREGIDOS PARA EL GUARDADO --- guild_id: document.getElementById('impGuild').value, assigned_to: document.getElementById('impOperator').value, assigned_to_name: opName,