-
${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,