Actualizar automatizaciones.html
This commit is contained in:
@@ -34,7 +34,7 @@
|
|||||||
</span>
|
</span>
|
||||||
Buzón de Automatizaciones
|
Buzón de Automatizaciones
|
||||||
</h2>
|
</h2>
|
||||||
<p class="text-sm text-slate-500 mt-1 font-medium">Gestiona e importa los avisos capturados por los robots.</p>
|
<p class="text-sm text-slate-500 mt-1 font-medium">Validación y limpieza quirúrgica de expedientes externos.</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
|
||||||
@@ -92,7 +92,7 @@
|
|||||||
|
|
||||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
|
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||||
<div>
|
<div>
|
||||||
<label class="text-[11px] font-black text-slate-400 uppercase tracking-widest">Referencia</label>
|
<label class="text-[11px] font-black text-slate-400 uppercase tracking-widest">Ref. Expediente</label>
|
||||||
<input type="text" id="imp_ref" class="w-full border-2 border-slate-100 bg-slate-100 p-3 rounded-2xl text-sm font-bold text-slate-500" readonly>
|
<input type="text" id="imp_ref" class="w-full border-2 border-slate-100 bg-slate-100 p-3 rounded-2xl text-sm font-bold text-slate-500" readonly>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@@ -154,11 +154,18 @@
|
|||||||
const raw = svc.raw_data || {};
|
const raw = svc.raw_data || {};
|
||||||
const myMap = mappings.filter(m => m.provider === svc.provider);
|
const myMap = mappings.filter(m => m.provider === svc.provider);
|
||||||
|
|
||||||
// Extracción de datos
|
// --- LÓGICA DE EXTRACCIÓN Y LIMPIEZA ---
|
||||||
const rawName = raw[myMap.find(m => m.target_key === 'clientName')?.original_key] || "";
|
const rawName = raw[myMap.find(m => m.target_key === 'clientName')?.original_key] || "";
|
||||||
const rawAddr = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "";
|
const rawAddr = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "";
|
||||||
const rawPop = raw[myMap.find(m => m.target_key === 'poblacion')?.original_key] || "";
|
|
||||||
const fullAddr = `${rawAddr} ${rawPop}`.trim();
|
// Extraer CP y Población del campo CP capturado
|
||||||
|
const rawCPField = raw[myMap.find(m => m.target_key === 'cp')?.original_key] || raw['Población_CP'] || "";
|
||||||
|
const cpMatch = rawCPField.match(/\b\d{5}\b/);
|
||||||
|
const cpOnly = cpMatch ? cpMatch[0] : "";
|
||||||
|
const popOnly = rawCPField.replace(cpOnly, '').replace('-', '').trim();
|
||||||
|
|
||||||
|
// Dirección final: Calle + Población
|
||||||
|
const fullAddr = `${rawAddr} ${popOnly}`.trim();
|
||||||
|
|
||||||
const rawPhone = raw[myMap.find(m => m.target_key === 'phone')?.original_key] || raw['Teléfono'] || "";
|
const rawPhone = raw[myMap.find(m => m.target_key === 'phone')?.original_key] || raw['Teléfono'] || "";
|
||||||
const cleanPhone = rawPhone.match(/[6789]\d{8}/) ? rawPhone.match(/[6789]\d{8}/)[0] : "";
|
const cleanPhone = rawPhone.match(/[6789]\d{8}/) ? rawPhone.match(/[6789]\d{8}/)[0] : "";
|
||||||
@@ -173,20 +180,21 @@
|
|||||||
card.innerHTML = `
|
card.innerHTML = `
|
||||||
${isBlocked ? '<div class="absolute top-0 left-0 w-1 h-full bg-slate-400"></div>' : `<div class="absolute top-0 left-0 w-1 h-full ${svc.provider === 'homeserve' ? 'bg-red-500' : 'bg-blue-600'}"></div>`}
|
${isBlocked ? '<div class="absolute top-0 left-0 w-1 h-full bg-slate-400"></div>' : `<div class="absolute top-0 left-0 w-1 h-full ${svc.provider === 'homeserve' ? 'bg-red-500' : 'bg-blue-600'}"></div>`}
|
||||||
|
|
||||||
<div class="flex items-center gap-6 min-w-0">
|
<div class="flex items-center gap-6 min-w-0 text-left">
|
||||||
<div class="w-14 h-14 rounded-2xl flex flex-col items-center justify-center shrink-0 ${isBlocked ? 'bg-slate-200 text-slate-500' : (svc.provider === 'homeserve' ? 'bg-red-50 text-red-600' : 'bg-blue-50 text-blue-600')}">
|
<div class="w-14 h-14 rounded-2xl flex flex-col items-center justify-center shrink-0 ${isBlocked ? 'bg-slate-200 text-slate-500' : (svc.provider === 'homeserve' ? 'bg-red-50 text-red-600' : 'bg-blue-50 text-blue-600')}">
|
||||||
<span class="text-[8px] font-black uppercase tracking-widest">${shortProv}</span>
|
<span class="text-[8px] font-black uppercase tracking-widest">${shortProv}</span>
|
||||||
<i data-lucide="${isBlocked ? 'lock' : 'file-text'}" class="w-5 h-5 mt-0.5"></i>
|
<i data-lucide="${isBlocked ? 'lock' : 'file-text'}" class="w-5 h-5 mt-0.5"></i>
|
||||||
</div>
|
</div>
|
||||||
<div class="min-w-0">
|
<div class="min-w-0">
|
||||||
<h3 class="font-black ${isBlocked ? 'text-slate-400' : 'text-slate-800'} truncate text-lg uppercase">${isBlocked ? 'Expediente Bloqueado en Compañía' : (rawName || 'Nombre no detectado')}</h3>
|
<h3 class="font-black ${isBlocked ? 'text-slate-400' : 'text-slate-800'} truncate text-lg uppercase">${isBlocked ? 'Expediente Bloqueado' : (rawName || 'S/N')}</h3>
|
||||||
<p class="text-xs ${isBlocked ? 'text-slate-300' : 'text-slate-400'} flex items-center gap-1.5 mt-0.5 font-medium truncate italic">
|
<p class="text-xs ${isBlocked ? 'text-slate-300' : 'text-slate-400'} flex items-center gap-1.5 mt-0.5 font-medium truncate">
|
||||||
<i data-lucide="map-pin" class="w-3 h-3"></i> ${isBlocked ? 'Pendiente de liberación de datos' : (fullAddr || 'Sin dirección')}
|
<i data-lucide="map-pin" class="w-3 h-3"></i> ${isBlocked ? 'Pendiente de liberación' : (fullAddr || 'Sin dirección')}
|
||||||
</p>
|
</p>
|
||||||
${!isBlocked ? `
|
${!isBlocked ? `
|
||||||
<div class="mt-3 flex gap-3">
|
<div class="mt-3 flex gap-3">
|
||||||
<span class="text-[10px] bg-slate-100 text-slate-500 px-2.5 py-1 rounded-lg font-black border border-slate-200">#${svc.service_ref}</span>
|
<span class="text-[10px] bg-slate-100 text-slate-500 px-2.5 py-1 rounded-lg font-black border border-slate-200">#${svc.service_ref}</span>
|
||||||
${cleanPhone ? `<span class="text-[10px] bg-emerald-50 text-emerald-600 px-2.5 py-1 rounded-lg font-black border border-emerald-100">${cleanPhone}</span>` : ''}
|
${cleanPhone ? `<span class="text-[10px] bg-emerald-50 text-emerald-600 px-2.5 py-1 rounded-lg font-black border border-emerald-100">${cleanPhone}</span>` : ''}
|
||||||
|
${cpOnly ? `<span class="text-[10px] bg-blue-50 text-blue-600 px-2.5 py-1 rounded-lg font-black border border-blue-100">${cpOnly}</span>` : ''}
|
||||||
</div>` : ''}
|
</div>` : ''}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -194,16 +202,16 @@
|
|||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
${!isBlocked ? `
|
${!isBlocked ? `
|
||||||
<div class="hidden group-hover:flex items-center gap-1 pr-4 border-r border-slate-200 mr-2 fade-in">
|
<div class="hidden group-hover:flex items-center gap-1 pr-4 border-r border-slate-200 mr-2 fade-in">
|
||||||
<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-100 text-slate-400 hover:text-blue-600 hover:bg-white hover:shadow-sm" title="Google Maps"><i data-lucide="map" class="w-5 h-5"></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-100 text-slate-400 hover:text-blue-600 hover:bg-white hover:shadow-sm"><i data-lucide="map" class="w-5 h-5"></i></a>
|
||||||
${cleanPhone ? `
|
${cleanPhone ? `
|
||||||
<a href="https://wa.me/34${cleanPhone}" target="_blank" class="action-btn p-2.5 rounded-xl bg-slate-100 text-slate-400 hover:text-emerald-600 hover:bg-white hover:shadow-sm" title="WhatsApp"><i data-lucide="message-square" class="w-5 h-5"></i></a>
|
<a href="https://wa.me/34${cleanPhone}" target="_blank" class="action-btn p-2.5 rounded-xl bg-slate-100 text-slate-400 hover:text-emerald-600 hover:bg-white hover:shadow-sm"><i data-lucide="message-square" class="w-5 h-5"></i></a>
|
||||||
<a href="tel:${cleanPhone}" class="action-btn p-2.5 rounded-xl bg-slate-100 text-slate-400 hover:text-blue-600 hover:bg-white hover:shadow-sm" title="Llamar"><i data-lucide="phone-call" class="w-5 h-5"></i></a>
|
<a href="tel:${cleanPhone}" class="action-btn p-2.5 rounded-xl bg-slate-100 text-slate-400 hover:text-blue-600 hover:bg-white hover:shadow-sm"><i data-lucide="phone-call" class="w-5 h-5"></i></a>
|
||||||
` : ''}
|
` : ''}
|
||||||
</div>
|
</div>
|
||||||
<button onclick="openEditor(${svc.id})" class="bg-blue-600 hover:bg-slate-900 text-white p-4 rounded-2xl shadow-lg transition-all active:scale-90" title="Editar e Importar">
|
<button onclick="openEditor(${svc.id})" class="bg-blue-600 hover:bg-slate-900 text-white p-4 rounded-2xl shadow-lg transition-all active:scale-90">
|
||||||
<i data-lucide="edit-3" class="w-6 h-6"></i>
|
<i data-lucide="edit-3" class="w-6 h-6"></i>
|
||||||
</button>` : `
|
</button>` : `
|
||||||
<div class="bg-slate-100 text-slate-400 p-4 rounded-2xl border-2 border-dashed" title="Servicio bloqueado por el proveedor">
|
<div class="bg-slate-100 text-slate-400 p-4 rounded-2xl border-2 border-dashed">
|
||||||
<i data-lucide="shield-off" class="w-6 h-6"></i>
|
<i data-lucide="shield-off" class="w-6 h-6"></i>
|
||||||
</div>`}
|
</div>`}
|
||||||
</div>
|
</div>
|
||||||
@@ -226,14 +234,15 @@
|
|||||||
document.getElementById('imp_phone').value = phoneMatch ? phoneMatch[0] : "";
|
document.getElementById('imp_phone').value = phoneMatch ? phoneMatch[0] : "";
|
||||||
document.getElementById('imp_phone_extra').innerText = phoneVal !== (phoneMatch ? phoneMatch[0] : "") ? `Dato original capturado: ${phoneVal}` : "";
|
document.getElementById('imp_phone_extra').innerText = phoneVal !== (phoneMatch ? phoneMatch[0] : "") ? `Dato original capturado: ${phoneVal}` : "";
|
||||||
|
|
||||||
// 2. CP Y DIRECCIÓN + POBLACIÓN
|
// 2. SEPARAR CP Y POBLACIÓN DEL CAMPO CP
|
||||||
const addr = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "";
|
const rawAddr = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "";
|
||||||
const pop = raw[myMap.find(m => m.target_key === 'poblacion')?.original_key] || "";
|
const rawCPField = raw[myMap.find(m => m.target_key === 'cp')?.original_key] || raw['Población_CP'] || "";
|
||||||
const cpVal = raw[myMap.find(m => m.target_key === 'cp')?.original_key] || raw['Población_CP'] || "";
|
const cpMatch = rawCPField.match(/\b\d{5}\b/);
|
||||||
const cpMatch = cpVal.match(/\b\d{5}\b/);
|
const cpOnly = cpMatch ? cpMatch[0] : "";
|
||||||
|
const popOnly = rawCPField.replace(cpOnly, '').replace('-', '').trim();
|
||||||
|
|
||||||
document.getElementById('imp_address').value = `${addr} ${pop}`.trim();
|
document.getElementById('imp_address').value = `${rawAddr} ${popOnly}`.trim();
|
||||||
document.getElementById('imp_cp').value = cpMatch ? cpMatch[0] : "";
|
document.getElementById('imp_cp').value = cpOnly;
|
||||||
|
|
||||||
// 3. PROVEEDOR ACORTADO EN COMPAÑÍA
|
// 3. PROVEEDOR ACORTADO EN COMPAÑÍA
|
||||||
const cia = raw[myMap.find(m => m.target_key === 'compania')?.original_key] || raw['Compañía'] || "";
|
const cia = raw[myMap.find(m => m.target_key === 'compania')?.original_key] || raw['Compañía'] || "";
|
||||||
@@ -269,11 +278,11 @@
|
|||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/providers/import/${document.getElementById('scrapedId').value}`, {
|
const res = await fetch(`${API_URL}/providers/import/${document.getElementById('scrapedId').value}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem('token')}` },
|
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem("token")}` },
|
||||||
body: JSON.stringify(payload)
|
body: JSON.stringify(payload)
|
||||||
});
|
});
|
||||||
if(res.ok) {
|
if(res.ok) {
|
||||||
showToast("✅ ¡Expediente importado con éxito!");
|
showToast("✅ ¡Expediente importado!");
|
||||||
closeModal();
|
closeModal();
|
||||||
loadInbox();
|
loadInbox();
|
||||||
} else { showToast("Error al importar", true); }
|
} else { showToast("Error al importar", true); }
|
||||||
|
|||||||
Reference in New Issue
Block a user