-
-
-
-
-
Asegurado
-
+
+
+
+
+ Validación de Expediente
+
+
+ REF: --
+ --
-
-
-
- Contacto Directo
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Urgencia
-
-
-
-
-
-
-
+
+
+
-
@@ -166,21 +161,25 @@
});
async function loadGuilds() {
- const res = await fetch(`${API_URL}/guilds`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
- const data = await res.json();
- allGuilds = data.guilds || [];
- const sel = document.getElementById('impGuild');
- sel.innerHTML = '
';
- allGuilds.forEach(g => sel.innerHTML += `
`);
+ try {
+ const res = await fetch(`${API_URL}/guilds`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
+ const data = await res.json();
+ allGuilds = data.guilds || [];
+ const sel = document.getElementById('impGuild');
+ sel.innerHTML = '
';
+ allGuilds.forEach(g => sel.innerHTML += `
`);
+ } catch(e) {}
}
async function loadOpsForGuild(guildId) {
const sel = document.getElementById('impOperator');
if(!guildId) { sel.innerHTML = '
'; return; }
- const res = await fetch(`${API_URL}/operators?guild_id=${guildId}`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
- const data = await res.json();
- sel.innerHTML = '
';
- data.operators.forEach(op => sel.innerHTML += `
`);
+ try {
+ const res = await fetch(`${API_URL}/operators?guild_id=${guildId}`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
+ const data = await res.json();
+ sel.innerHTML = '
';
+ data.operators.forEach(op => sel.innerHTML += `
`);
+ } catch(e) {}
}
async function loadInbox() {
@@ -201,29 +200,35 @@
scrapedData.forEach(svc => {
const raw = svc.raw_data || {};
- const name = raw['Nombre Cliente'] || "";
- const addr = raw['Dirección'] || "";
+ const name = raw['Nombre Cliente'] || raw['CLIENTE'] || "";
+ const addr = raw['Dirección'] || raw['DOMICILIO'] || "";
+ const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || "";
+ const fullAddr = `${addr} ${pop}`.trim();
const isBlocked = (!name || name.toUpperCase().includes('SIN NOMBRE') || !addr);
- const shortProv = svc.provider === 'multiasistencia' ? 'MULTI' : 'HOME';
+ const phone = (raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "").match(/[6789]\d{8}/)?.[0] || "";
const card = document.createElement('div');
card.className = `bg-white p-5 rounded-2xl border ${isBlocked ? 'opacity-50' : 'shadow-sm hover:border-blue-300'} flex items-center justify-between transition-all group fade-in`;
card.innerHTML = `
- ${shortProv}
-
+ ${svc.provider === 'multiasistencia' ? 'MULTI' : 'HOME'}
+
${isBlocked ? 'Expediente Bloqueado' : name}
-
${isBlocked ? 'Pendiente de liberación' : addr}
+
${isBlocked ? 'Pendiente de liberación' : fullAddr}
${!isBlocked ? `
-
-
+
+ ${phone ? `
+
+
+ ` : ''}
+
` : '
'}
`;
container.appendChild(card);
@@ -232,40 +237,38 @@
} catch (e) { showToast("Error de conexión", true); }
}
- function openEditor(id) {
- const svc = scrapedData.find(s => s.id === id);
- if(!svc) return;
- const raw = svc.raw_data;
+ function openEditor(id) {
+ const svc = scrapedData.find(s => s.id === id);
+ if(!svc) return;
+ const raw = svc.raw_data;
- // Pintar IDs informativos del nuevo header
- document.getElementById('displayRef').innerText = `REF: ${svc.service_ref}`;
- document.getElementById('displayCompany').innerText = raw['Compañía'] || raw['COMPAÑIA'] || svc.provider.toUpperCase();
+ // ACTUALIZACIÓN DE CABECERA
+ document.getElementById('displayRef').innerText = `REF: ${svc.service_ref}`;
+ document.getElementById('displayCompany').innerText = raw['Compañía'] || raw['COMPAÑIA'] || svc.provider.toUpperCase();
- // Rellenar campos del formulario
- document.getElementById('impScrapedId').value = id;
- document.getElementById('impName').value = raw['Nombre Cliente'] || raw['CLIENTE'] || "";
-
- const rawPhone = raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "";
- document.getElementById('impPhone').value = rawPhone.match(/[6789]\d{8}/)?.[0] || "";
-
- const addr = raw['Dirección'] || raw['DOMICILIO'] || "";
- const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || "";
- document.getElementById('impAddress').value = `${addr} ${pop}`.trim();
-
- document.getElementById('impCP').value = raw['Código Postal'] || "";
- document.getElementById('impDesc').value = raw['Descripción'] || "";
- document.getElementById('impRef').value = svc.service_ref;
- document.getElementById('impCompany').value = raw['Compañía'] || raw['COMPAÑIA'] || svc.provider.toUpperCase();
- document.getElementById('impUrgent').value = (raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true').toString();
-
- // Reset de campos adicionales
- document.getElementById('impNotesInt').value = "";
- document.getElementById('impNotesExt').value = "";
- document.getElementById('impGuild').value = "";
+ // RELLENAR FORMULARIO
+ document.getElementById('impScrapedId').value = id;
+ document.getElementById('impName').value = raw['Nombre Cliente'] || raw['CLIENTE'] || "";
+
+ const rawPhone = raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "";
+ document.getElementById('impPhone').value = rawPhone.match(/[6789]\d{8}/)?.[0] || "";
+
+ const addr = raw['Dirección'] || raw['DOMICILIO'] || "";
+ const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || "";
+ document.getElementById('impAddress').value = `${addr} ${pop}`.trim();
+
+ document.getElementById('impCP').value = raw['Código Postal'] || "";
+ document.getElementById('impDesc').value = raw['Descripción'] || "";
+ document.getElementById('impUrgent').value = (raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true').toString();
+
+ document.getElementById('impNotesInt').value = "";
+ document.getElementById('impNotesExt').value = "";
+ document.getElementById('impGuild').value = "";
+ document.getElementById('impOperator').innerHTML = '
';
- document.getElementById('importModal').classList.remove('hidden');
- lucide.createIcons();
-}
+ document.getElementById('importModal').classList.remove('hidden');
+ lucide.createIcons();
+ }
function closeModal() { document.getElementById('importModal').classList.add('hidden'); }
@@ -280,7 +283,7 @@
address: document.getElementById('impAddress').value,
cp: document.getElementById('impCP').value,
description: document.getElementById('impDesc').value,
- company_ref: document.getElementById('impRef').value,
+ company_ref: document.getElementById('displayRef').innerText.replace('REF: ', ''),
guild_id: document.getElementById('impGuild').value,
assigned_to: document.getElementById('impOperator').value || null,
internal_notes: document.getElementById('impNotesInt').value,
@@ -296,7 +299,7 @@
});
const result = await res.json();
if(result.ok) {
- showToast("✅ Expediente enviado al CRM");
+ showToast("✅ Traspasado con éxito");
closeModal();
loadInbox();
} else { showToast("❌ Error al importar", true); }