diff --git a/automatizaciones.html b/automatizaciones.html index 168b678..d879b60 100644 --- a/automatizaciones.html +++ b/automatizaciones.html @@ -13,7 +13,7 @@ .no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; } .service-card { cursor: pointer; transition: all 0.2s ease; position: relative; } .service-card:hover:not(.archived) { transform: translateY(-2px); border-color: #3b82f6; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); } - .archived { opacity: 0.7; grayscale: 100%; cursor: not-allowed; } + .archived { opacity: 0.7; grayscale: 100%; } @@ -26,13 +26,13 @@
-
+

Buzón de Automatizaciones

-

Gestiona y filtra tus expedientes capturados.

+

Filtra por proveedor, compañía o cualquier dato del asegurado.

-
+
- +
- + - +
@@ -64,7 +64,6 @@ -
@@ -234,27 +224,26 @@ async function loadInbox() { const container = document.getElementById('inboxContainer'); try { + // MODIFICACIÓN: Ya no filtramos solo pending en la llamada, traemos todo para el buscador const resSvc = await fetch(`${API_URL}/providers/scraped`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); const dataSvc = await resSvc.json(); scrapedData = dataSvc.services || []; - // Actualizar Filtro de Compañías - const companyFilter = document.getElementById('filterCompany'); - const companies = [...new Set(scrapedData.map(s => { + // Actualizamos lista de compañías para el filtro + const compSelect = document.getElementById('filterCompany'); + const uniqueCompanies = [...new Set(scrapedData.map(s => { const raw = s.raw_data || {}; - return (raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "DESCONOCIDA").toString().toUpperCase().trim(); + return (raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "S/C").toString().toUpperCase().trim(); }))].sort(); - companyFilter.innerHTML = ''; - companies.forEach(c => { - companyFilter.innerHTML += ``; - }); + compSelect.innerHTML = ''; + uniqueCompanies.forEach(c => compSelect.innerHTML += ``); - renderFilteredInbox(); // Render inicial con filtros aplicados + renderFilteredInbox(); // } catch (e) { showToast("Error de conexión", true); } } - // FUNCIÓN PARA RENDERIZAR SEGÚN FILTROS + // FUNCIÓN DE FILTRADO REACTIVO (NUEVA) function renderFilteredInbox() { const container = document.getElementById('inboxContainer'); const search = document.getElementById('searchBox').value.toUpperCase(); @@ -266,26 +255,28 @@ 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 phone = (raw['Teléfono'] || raw['TELEFONO'] || "").toUpperCase(); + const comp = (raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "").toUpperCase(); - const matchesSearch = name.includes(search) || ref.includes(search) || addr.includes(search); - const matchesProvider = provider === "ALL" || svc.provider === provider; - const matchesCompany = company === "ALL" || compName === company; + const matchesSearch = name.includes(search) || ref.includes(search) || addr.includes(search) || phone.includes(search); + const matchesProvider = provider === 'ALL' || svc.provider === provider; + const matchesCompany = company === 'ALL' || comp === company; return matchesSearch && matchesProvider && matchesCompany; }); container.innerHTML = ""; if(filtered.length === 0) { - container.innerHTML = '
No se encontraron expedientes con los filtros actuales.
'; + container.innerHTML = '
No se encontraron expedientes.
'; return; } filtered.forEach(svc => { const raw = svc.raw_data || {}; - const isArchived = svc.status === 'archived'; + 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'] || ""; @@ -297,11 +288,13 @@ 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); + if (isArchived) showToast("⚠️ Este servicio está ARCHIVADO (ya no aparece en la web de compañía).", true); else openEditor(svc.id); }; + card.innerHTML = `
@@ -317,7 +310,6 @@ ${statusLabel}

${fullAddr}

-
#${svc.service_ref} ${guildName ? `${guildName}` : ''} @@ -327,9 +319,9 @@
${!isArchived ? ` - `; @@ -409,17 +401,10 @@ headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify(payload) }); - if(res.ok) { - showToast("✅ Borrador guardado correctamente"); - loadInbox(); - } else { - showToast("❌ Error al guardar", true); - } - } catch (e) { - showToast("❌ Error de red", true); - } finally { - btn.disabled = false; - } + if(res.ok) { showToast("✅ Borrador guardado correctamente"); loadInbox(); } + else { showToast("❌ Error al guardar", true); } + } catch (e) { showToast("❌ Error de red", true); } + finally { btn.disabled = false; } } async function handleFinalImport(event) {