Actualizar automatizaciones.html

This commit is contained in:
2026-02-15 14:38:37 +00:00
parent ab94a02a7e
commit 379512c867

View File

@@ -26,19 +26,36 @@
<main class="flex-1 overflow-x-hidden overflow-y-auto bg-gray-50 p-6 relative"> <main class="flex-1 overflow-x-hidden overflow-y-auto bg-gray-50 p-6 relative">
<div id="automationView" class="fade-in max-w-6xl mx-auto"> <div id="automationView" class="fade-in max-w-6xl mx-auto">
<div class="flex justify-between items-center mb-8"> <div class="flex justify-between items-center mb-6">
<div> <div>
<h2 class="text-2xl font-black text-slate-800 flex items-center gap-3"> <h2 class="text-2xl font-black text-slate-800 flex items-center gap-3">
<span class="bg-blue-600 p-2.5 rounded-xl text-white shadow-lg"><i data-lucide="bot"></i></span> <span class="bg-blue-600 p-2.5 rounded-xl text-white shadow-lg"><i data-lucide="bot"></i></span>
Buzón de Automatizaciones Buzón de Automatizaciones
</h2> </h2>
<p class="text-sm text-slate-500 mt-1 font-medium">Pulsa sobre cualquier servicio activo para validar los datos.</p> <p class="text-sm text-slate-500 mt-1 font-medium">Gestiona y filtra tus expedientes capturados.</p>
</div> </div>
<button onclick="loadInbox()" class="bg-white border-2 border-slate-200 hover:border-blue-600 hover:text-blue-600 text-slate-600 px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 transition-all active:scale-95 shadow-sm"> <button onclick="loadInbox()" class="bg-white border-2 border-slate-200 hover:border-blue-600 hover:text-blue-600 text-slate-600 px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 transition-all active:scale-95 shadow-sm">
<i data-lucide="refresh-cw" class="w-4 h-4"></i> Actualizar <i data-lucide="refresh-cw" class="w-4 h-4"></i> Actualizar
</button> </button>
</div> </div>
<div class="bg-white p-4 rounded-2xl border border-slate-200 shadow-sm mb-6 flex flex-wrap gap-4 items-center">
<div class="flex-1 min-w-[200px] relative">
<i data-lucide="search" class="w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"></i>
<input type="text" id="searchBox" oninput="renderFilteredInbox()" placeholder="Buscar por nombre, ref, dirección..." class="w-full pl-10 pr-4 py-2.5 bg-slate-50 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-blue-500 outline-none transition-all">
</div>
<div class="flex gap-2">
<select id="filterProvider" onchange="renderFilteredInbox()" class="bg-slate-50 border border-slate-200 text-xs font-bold px-4 py-2.5 rounded-xl outline-none focus:ring-2 focus:ring-blue-500">
<option value="ALL">TODOS LOS PROVEEDORES</option>
<option value="homeserve">HOME (HOMESERVE)</option>
<option value="multiasistencia">MULTI (MULTIASISTENCIA)</option>
</select>
<select id="filterCompany" onchange="renderFilteredInbox()" class="bg-slate-50 border border-slate-200 text-xs font-bold px-4 py-2.5 rounded-xl outline-none focus:ring-2 focus:ring-blue-500">
<option value="ALL">TODAS LAS COMPAÑÍAS</option>
</select>
</div>
</div>
<div id="inboxContainer" class="space-y-4 text-left"></div> <div id="inboxContainer" class="space-y-4 text-left"></div>
</div> </div>
</main> </main>
@@ -220,12 +237,51 @@
const resSvc = await fetch(`${API_URL}/providers/scraped`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); const resSvc = await fetch(`${API_URL}/providers/scraped`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
const dataSvc = await resSvc.json(); const dataSvc = await resSvc.json();
scrapedData = dataSvc.services || []; scrapedData = dataSvc.services || [];
// 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 = '<option value="ALL">TODAS LAS COMPAÑÍAS</option>';
companies.forEach(c => {
companyFilter.innerHTML += `<option value="${c}">${c}</option>`;
});
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 = ""; container.innerHTML = "";
if(scrapedData.length === 0) { if(filtered.length === 0) {
container.innerHTML = '<div class="p-12 text-center text-slate-400 bg-white rounded-3xl border-2 border-dashed">No hay expedientes pendientes.</div>'; container.innerHTML = '<div class="p-12 text-center text-slate-400 bg-white rounded-3xl border-2 border-dashed">No se encontraron expedientes con los filtros actuales.</div>';
return; return;
} }
scrapedData.forEach(svc => {
filtered.forEach(svc => {
const raw = svc.raw_data || {}; const raw = svc.raw_data || {};
const isArchived = svc.status === 'archived'; const isArchived = svc.status === 'archived';
const statusLabel = isArchived ? 'ARCHIVADO' : 'SERVICIO ACTIVO'; const statusLabel = isArchived ? 'ARCHIVADO' : 'SERVICIO ACTIVO';
@@ -236,7 +292,6 @@
const fullAddr = `${addr} ${pop}`.trim(); const fullAddr = `${addr} ${pop}`.trim();
const phone = (raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "").match(/[6789]\d{8}/)?.[0] || ""; 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 guildName = allGuilds.find(g => g.id == raw['guild_id'])?.name || null;
const opName = raw['assigned_to_name'] || null; const opName = raw['assigned_to_name'] || null;
@@ -273,14 +328,14 @@
<div class="flex items-center gap-2 text-left"> <div class="flex items-center gap-2 text-left">
${!isArchived ? ` ${!isArchived ? `
<div class="hidden group-hover:flex items-center gap-2 pr-4 transition-all"> <div class="hidden group-hover:flex items-center gap-2 pr-4 transition-all">
<a href="https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(fullAddr)}" target="_blank" class="action-btn p-2.5 rounded-xl bg-slate-50 text-slate-400 hover:text-blue-600 shadow-sm"><i data-lucide="map"></i></a> <a href="https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(fullAddr)}" target="_blank" class="action-btn p-2.5 rounded-xl bg-slate-50 text-slate-400 hover:text-blue-600 shadow-sm"><i data-lucide="map" class="w-5 h-5"></i></a>
${phone ? `<a href="https://wa.me/34${phone}" target="_blank" class="action-btn p-2.5 rounded-xl bg-slate-50 text-slate-400 hover:text-emerald-600 shadow-sm"><i data-lucide="message-square"></i></a>` : ''} ${phone ? `<a href="https://wa.me/34${phone}" target="_blank" class="action-btn p-2.5 rounded-xl bg-slate-50 text-slate-400 hover:text-emerald-600 shadow-sm"><i data-lucide="message-square" class="w-5 h-5"></i></a>` : ''}
</div>` : ''} </div>
<div class="bg-blue-600 text-white p-4 rounded-2xl shadow-lg group-hover:scale-105 transition-all"><i data-lucide="chevron-right" class="w-6 h-6"></i></div>` : ''}
</div>`; </div>`;
container.appendChild(card); container.appendChild(card);
}); });
lucide.createIcons(); lucide.createIcons();
} catch (e) { showToast("Error de conexión", true); }
} }
async function openEditor(id) { async function openEditor(id) {
@@ -307,7 +362,6 @@
const isUrgent = raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true' || raw['URGENTE'] === 'SI'; const isUrgent = raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true' || raw['URGENTE'] === 'SI';
document.getElementById('impUrgent').value = isUrgent.toString(); document.getElementById('impUrgent').value = isUrgent.toString();
// --- RECUPERACIÓN DE DATOS GUARDADOS PREVIAMENTE ---
document.getElementById('impNotesInt').value = raw['internal_notes'] || ""; document.getElementById('impNotesInt').value = raw['internal_notes'] || "";
document.getElementById('impNotesExt').value = raw['client_notes'] || ""; document.getElementById('impNotesExt').value = raw['client_notes'] || "";
@@ -315,7 +369,6 @@
document.getElementById('impGuild').value = savedGuild; document.getElementById('impGuild').value = savedGuild;
if(savedGuild) { if(savedGuild) {
// Cargamos operarios y luego seleccionamos el guardado
await loadOpsForGuild(savedGuild); await loadOpsForGuild(savedGuild);
document.getElementById('impOperator').value = raw['assigned_to'] || ""; document.getElementById('impOperator').value = raw['assigned_to'] || "";
} else { } else {
@@ -333,7 +386,6 @@
const btn = e.currentTarget; const btn = e.currentTarget;
btn.disabled = true; btn.disabled = true;
// --- OBTENER NOMBRE DEL OPERARIO SELECCIONADO PARA MOSTRAR EN LA TARJETA ---
const opSelect = document.getElementById('impOperator'); const opSelect = document.getElementById('impOperator');
const opName = opSelect.options[opSelect.selectedIndex]?.text.includes('--') ? null : opSelect.options[opSelect.selectedIndex]?.text; const opName = opSelect.options[opSelect.selectedIndex]?.text.includes('--') ? null : opSelect.options[opSelect.selectedIndex]?.text;
@@ -344,7 +396,6 @@
cp: document.getElementById('impCP').value, cp: document.getElementById('impCP').value,
description: document.getElementById('impDesc').value, description: document.getElementById('impDesc').value,
is_urgent: document.getElementById('impUrgent').value === 'true', is_urgent: document.getElementById('impUrgent').value === 'true',
// --- CAMPOS CORREGIDOS PARA EL GUARDADO ---
guild_id: document.getElementById('impGuild').value, guild_id: document.getElementById('impGuild').value,
assigned_to: document.getElementById('impOperator').value, assigned_to: document.getElementById('impOperator').value,
assigned_to_name: opName, assigned_to_name: opName,