Actualizar automatizaciones.html

This commit is contained in:
2026-02-14 11:23:13 +00:00
parent 95301abc47
commit c34c076131

View File

@@ -11,6 +11,8 @@
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.no-scrollbar::-webkit-scrollbar { display: none; } .no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; } .no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
.action-btn { transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); }
.action-btn:hover:not(:disabled) { transform: translateY(-2px); }
</style> </style>
</head> </head>
<body class="bg-gray-50 text-gray-800 font-sans antialiased overflow-hidden"> <body class="bg-gray-50 text-gray-800 font-sans antialiased overflow-hidden">
@@ -29,9 +31,9 @@
<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">Valida los expedientes bloqueados o listos para importar.</p> <p class="text-sm text-slate-500 mt-1 font-medium">Validación rápida y profesional de expedientes.</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 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>
@@ -52,8 +54,8 @@
Validación de Expediente Validación de Expediente
</h3> </h3>
<div class="flex gap-3 mt-1"> <div class="flex gap-3 mt-1">
<span id="displayRef" class="text-[10px] bg-slate-100 text-slate-500 px-2 py-0.5 rounded-lg font-bold border border-slate-200">REF: --</span> <span id="displayRef" class="text-[10px] bg-slate-100 text-slate-500 px-2 py-0.5 rounded-lg font-bold border border-slate-200 uppercase">REF: --</span>
<span id="displayCompany" class="text-[10px] bg-blue-50 text-blue-600 px-2 py-0.5 rounded-lg font-bold border border-blue-100 uppercase tracking-tighter">--</span> <span id="displayCompany" class="text-[10px] bg-blue-50 text-blue-600 px-2 py-0.5 rounded-lg font-bold border border-blue-100 uppercase tracking-tighter truncate max-w-[300px]">--</span>
</div> </div>
</div> </div>
<button onclick="closeModal()" class="bg-slate-50 p-2 rounded-full hover:bg-red-50 hover:text-red-500 transition-all"> <button onclick="closeModal()" class="bg-slate-50 p-2 rounded-full hover:bg-red-50 hover:text-red-500 transition-all">
@@ -67,16 +69,16 @@
<div class="grid grid-cols-1 md:grid-cols-2 gap-4"> <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="bg-slate-50/80 p-3 rounded-2xl border border-slate-100 flex items-center gap-3"> <div class="bg-slate-50/80 p-3 rounded-2xl border border-slate-100 flex items-center gap-3">
<div class="bg-white p-2 rounded-xl shadow-sm text-slate-400"><i data-lucide="user" class="w-4 h-4"></i></div> <div class="bg-white p-2 rounded-xl shadow-sm text-slate-400"><i data-lucide="user" class="w-4 h-4"></i></div>
<div class="flex flex-col min-w-0"> <div class="flex flex-col min-w-0 w-full">
<span class="text-[9px] font-black text-slate-400 uppercase leading-none mb-1">Asegurado</span> <span class="text-[9px] font-black text-slate-400 uppercase leading-none mb-1">Asegurado</span>
<input type="text" id="impName" readonly class="bg-transparent border-none p-0 text-sm font-bold text-slate-700 outline-none focus:ring-0 truncate"> <input type="text" id="impName" readonly class="bg-transparent border-none p-0 text-sm font-bold text-slate-700 outline-none focus:ring-0 truncate w-full">
</div> </div>
</div> </div>
<div class="bg-slate-50/80 p-3 rounded-2xl border border-slate-100 flex items-center gap-3"> <div class="bg-slate-50/80 p-3 rounded-2xl border border-slate-100 flex items-center gap-3">
<div class="bg-white p-2 rounded-xl shadow-sm text-emerald-500"><i data-lucide="phone" class="w-4 h-4"></i></div> <div class="bg-white p-2 rounded-xl shadow-sm text-emerald-500"><i data-lucide="phone" class="w-4 h-4"></i></div>
<div class="flex flex-col min-w-0"> <div class="flex flex-col min-w-0 w-full">
<span class="text-[9px] font-black text-slate-400 uppercase leading-none mb-1">Contacto Directo</span> <span class="text-[9px] font-black text-slate-400 uppercase leading-none mb-1">Contacto</span>
<input type="text" id="impPhone" readonly class="bg-transparent border-none p-0 text-sm font-black text-emerald-600 outline-none focus:ring-0"> <input type="text" id="impPhone" readonly class="bg-transparent border-none p-0 text-sm font-black text-emerald-600 outline-none focus:ring-0 w-full">
</div> </div>
</div> </div>
</div> </div>
@@ -84,10 +86,7 @@
<div class="grid grid-cols-1 md:grid-cols-5 gap-3"> <div class="grid grid-cols-1 md:grid-cols-5 gap-3">
<div class="md:col-span-4 space-y-1"> <div class="md:col-span-4 space-y-1">
<label class="text-[9px] font-black text-blue-600 uppercase tracking-widest ml-2">Dirección de la Reparación</label> <label class="text-[9px] font-black text-blue-600 uppercase tracking-widest ml-2">Dirección de la Reparación</label>
<div class="relative"> <input type="text" id="impAddress" required class="w-full border-2 border-slate-100 bg-white px-4 py-2.5 rounded-2xl text-sm font-medium outline-none focus:border-blue-500 transition-all shadow-sm">
<i data-lucide="map-pin" class="w-4 h-4 absolute left-4 top-3 text-slate-300"></i>
<input type="text" id="impAddress" required class="w-full border-2 border-slate-100 bg-white pl-10 pr-4 py-2.5 rounded-2xl text-sm font-medium outline-none focus:border-blue-500 transition-all shadow-sm">
</div>
</div> </div>
<div class="space-y-1"> <div class="space-y-1">
<label class="text-[9px] font-black text-blue-600 uppercase tracking-widest text-center block">C.P.</label> <label class="text-[9px] font-black text-blue-600 uppercase tracking-widest text-center block">C.P.</label>
@@ -95,16 +94,16 @@
</div> </div>
</div> </div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 p-4 rounded-[1.8rem] border-2 border-blue-50 bg-blue-50/20 shadow-sm"> <div class="grid grid-cols-1 md:grid-cols-2 gap-4 p-4 rounded-[1.8rem] border-2 border-blue-50 bg-blue-50/20">
<div class="space-y-1"> <div class="space-y-1">
<label class="text-[9px] font-black text-blue-600 uppercase tracking-widest ml-2">Gremio Especialista *</label> <label class="text-[9px] font-black text-blue-600 uppercase tracking-widest ml-2">Gremio Especialista *</label>
<select id="impGuild" required onchange="loadOpsForGuild(this.value)" class="w-full border border-blue-100 bg-white px-3 py-2 rounded-xl text-sm font-bold shadow-sm outline-none focus:ring-2 focus:ring-blue-500"> <select id="impGuild" required onchange="loadOpsForGuild(this.value)" class="w-full border border-blue-100 bg-white px-3 py-2 rounded-xl text-sm font-bold outline-none focus:ring-2 focus:ring-blue-500">
<option value="">-- Elegir Especialidad --</option> <option value="">-- Elegir Especialidad --</option>
</select> </select>
</div> </div>
<div class="space-y-1"> <div class="space-y-1">
<label class="text-[9px] font-black text-slate-400 uppercase tracking-widest ml-2">Asignación Operario</label> <label class="text-[9px] font-black text-slate-400 uppercase tracking-widest ml-2">Asignación Operario</label>
<select id="impOperator" class="w-full border border-blue-100 bg-white px-3 py-2 rounded-xl text-sm font-bold shadow-sm outline-none focus:ring-2 focus:ring-blue-500"> <select id="impOperator" class="w-full border border-blue-100 bg-white px-3 py-2 rounded-xl text-sm font-bold outline-none focus:ring-2 focus:ring-blue-500">
<option value="">-- Automática --</option> <option value="">-- Automática --</option>
</select> </select>
</div> </div>
@@ -112,17 +111,17 @@
<div class="space-y-3"> <div class="space-y-3">
<div class="space-y-1"> <div class="space-y-1">
<label class="text-[9px] font-black text-slate-400 uppercase tracking-widest ml-2">Descripción de la Avería</label> <label class="text-[9px] font-black text-slate-400 uppercase tracking-widest ml-2">Avería Detectada</label>
<textarea id="impDesc" rows="2" class="w-full border border-slate-200 bg-white px-4 py-2 rounded-2xl text-sm font-medium text-slate-600 outline-none focus:border-blue-400 resize-none shadow-sm"></textarea> <textarea id="impDesc" rows="2" class="w-full border border-slate-200 bg-white px-4 py-2 rounded-2xl text-sm font-medium text-slate-600 outline-none focus:border-blue-400 resize-none shadow-sm"></textarea>
</div> </div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4"> <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="relative"> <div>
<label class="text-[9px] font-black text-amber-600 uppercase tracking-widest ml-2 mb-1 block">Notas Internas</label> <label class="text-[9px] font-black text-amber-600 uppercase tracking-widest ml-2 mb-1 block">Notas Internas</label>
<textarea id="impNotesInt" rows="1" class="w-full border border-amber-100 bg-amber-50/30 px-3 py-2 rounded-xl text-xs outline-none focus:bg-white transition-all"></textarea> <textarea id="impNotesInt" rows="1" class="w-full border border-amber-100 bg-amber-50/30 px-3 py-2 rounded-xl text-xs outline-none focus:bg-white"></textarea>
</div> </div>
<div class="relative"> <div>
<label class="text-[9px] font-black text-blue-500 uppercase tracking-widest ml-2 mb-1 block">Notas Cliente</label> <label class="text-[9px] font-black text-blue-500 uppercase tracking-widest ml-2 mb-1 block">Notas Cliente</label>
<textarea id="impNotesExt" rows="1" class="w-full border border-blue-100 bg-blue-50/30 px-3 py-2 rounded-xl text-xs outline-none focus:bg-white transition-all"></textarea> <textarea id="impNotesExt" rows="1" class="w-full border border-blue-100 bg-blue-50/30 px-3 py-2 rounded-xl text-xs outline-none focus:bg-white"></textarea>
</div> </div>
</div> </div>
</div> </div>
@@ -130,20 +129,16 @@
<div class="flex items-center gap-3 pt-4 border-t"> <div class="flex items-center gap-3 pt-4 border-t">
<div class="flex-1 bg-slate-100 p-1.5 rounded-2xl flex items-center gap-2"> <div class="flex-1 bg-slate-100 p-1.5 rounded-2xl flex items-center gap-2">
<div class="bg-white px-4 py-2 rounded-xl shadow-sm"> <div class="bg-white px-4 py-2 rounded-xl shadow-sm">
<span class="text-[8px] font-black text-slate-400 uppercase block leading-none mb-1">Urgencia</span> <span class="text-[8px] font-black text-slate-400 uppercase block mb-1">Urgencia</span>
<select id="impUrgent" class="border-none bg-transparent text-xs font-black text-slate-700 focus:ring-0 p-0 cursor-pointer"> <select id="impUrgent" class="border-none bg-transparent text-xs font-black text-slate-700 focus:ring-0 p-0 cursor-pointer">
<option value="false">BAJA (Normal)</option> <option value="false">Normal</option>
<option value="true">⚠️ MUY URGENTE</option> <option value="true">🚨 URGENTE</option>
</select> </select>
</div> </div>
<div class="flex-1 text-center hidden md:block">
<p class="text-[10px] text-slate-400 font-bold uppercase tracking-tighter">Estado: <span class="text-blue-600">PENDIENTE</span></p>
</div> </div>
</div>
<button type="submit" class="bg-slate-900 hover:bg-emerald-600 text-white font-black px-10 py-4 rounded-[1.5rem] shadow-xl transition-all flex items-center gap-3 active:scale-95 text-xs uppercase tracking-widest group"> <button type="submit" class="bg-slate-900 hover:bg-emerald-600 text-white font-black px-10 py-4 rounded-[1.5rem] shadow-xl transition-all flex items-center gap-3 active:scale-95 text-xs uppercase tracking-widest group">
<span>TRASPASAR AL CRM</span> <span>TRASPASAR AL CRM</span>
<i data-lucide="chevron-right" class="w-4 h-4 group-hover:translate-x-1 transition-transform"></i> <i data-lucide="send" class="w-4 h-4"></i>
</button> </button>
</div> </div>
</form> </form>
@@ -166,21 +161,25 @@
}); });
async function loadGuilds() { async function loadGuilds() {
try {
const res = await fetch(`${API_URL}/guilds`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); const res = await fetch(`${API_URL}/guilds`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
const data = await res.json(); const data = await res.json();
allGuilds = data.guilds || []; allGuilds = data.guilds || [];
const sel = document.getElementById('impGuild'); const sel = document.getElementById('impGuild');
sel.innerHTML = '<option value="">-- Seleccionar Gremio --</option>'; sel.innerHTML = '<option value="">-- Seleccionar Gremio --</option>';
allGuilds.forEach(g => sel.innerHTML += `<option value="${g.id}">${g.name}</option>`); allGuilds.forEach(g => sel.innerHTML += `<option value="${g.id}">${g.name}</option>`);
} catch(e) {}
} }
async function loadOpsForGuild(guildId) { async function loadOpsForGuild(guildId) {
const sel = document.getElementById('impOperator'); const sel = document.getElementById('impOperator');
if(!guildId) { sel.innerHTML = '<option value="">-- Automática --</option>'; return; } if(!guildId) { sel.innerHTML = '<option value="">-- Automática --</option>'; return; }
try {
const res = await fetch(`${API_URL}/operators?guild_id=${guildId}`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); const res = await fetch(`${API_URL}/operators?guild_id=${guildId}`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
const data = await res.json(); const data = await res.json();
sel.innerHTML = '<option value="">-- Automática (Por defecto) --</option>'; sel.innerHTML = '<option value="">-- Automática (Por defecto) --</option>';
data.operators.forEach(op => sel.innerHTML += `<option value="${op.id}">${op.full_name}</option>`); data.operators.forEach(op => sel.innerHTML += `<option value="${op.id}">${op.full_name}</option>`);
} catch(e) {}
} }
async function loadInbox() { async function loadInbox() {
@@ -201,29 +200,35 @@
scrapedData.forEach(svc => { scrapedData.forEach(svc => {
const raw = svc.raw_data || {}; const raw = svc.raw_data || {};
const name = raw['Nombre Cliente'] || ""; const name = raw['Nombre Cliente'] || raw['CLIENTE'] || "";
const addr = raw['Dirección'] || ""; 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 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'); 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.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 = ` card.innerHTML = `
<div class="flex items-center gap-6 min-w-0"> <div class="flex items-center gap-6 min-w-0">
<div class="w-14 h-14 rounded-2xl flex flex-col items-center justify-center shrink-0 ${isBlocked ? 'bg-slate-200' : (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' : (svc.provider === 'homeserve' ? 'bg-red-50 text-red-600' : 'bg-blue-50 text-blue-600')}">
<span class="text-[8px] font-black">${shortProv}</span> <span class="text-[8px] font-black uppercase tracking-widest">${svc.provider === 'multiasistencia' ? 'MULTI' : 'HOME'}</span>
<i data-lucide="${isBlocked ? 'lock' : 'file-text'}" class="w-5 h-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 text-slate-800 truncate uppercase text-lg">${isBlocked ? 'Expediente Bloqueado' : name}</h3> <h3 class="font-black text-slate-800 truncate uppercase text-lg">${isBlocked ? 'Expediente Bloqueado' : name}</h3>
<p class="text-xs text-slate-400 truncate italic">${isBlocked ? 'Pendiente de liberación' : addr}</p> <p class="text-xs text-slate-400 truncate italic">${isBlocked ? 'Pendiente de liberación' : fullAddr}</p>
</div> </div>
</div> </div>
<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 mr-2"> <div class="hidden group-hover:flex items-center gap-1 pr-4 border-r mr-2">
<a href="https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(addr)}" target="_blank" class="p-2.5 rounded-xl bg-slate-50 text-slate-400 hover:text-blue-600 transition-all"><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="p-2.5 rounded-xl bg-slate-50 text-slate-400 hover:text-blue-600 transition-all shadow-sm"><i data-lucide="map" class="w-5 h-5"></i></a>
<button onclick="openEditor(${svc.id})" class="bg-blue-600 text-white p-4 rounded-2xl shadow-lg active:scale-90 transition-all"><i data-lucide="edit-3"></i></button> ${phone ? `
<a href="https://wa.me/34${phone}" target="_blank" class="p-2.5 rounded-xl bg-slate-50 text-slate-400 hover:text-emerald-600 transition-all shadow-sm"><i data-lucide="message-square" class="w-5 h-5"></i></a>
<a href="tel:${phone}" class="p-2.5 rounded-xl bg-slate-50 text-slate-400 hover:text-blue-600 transition-all shadow-sm"><i data-lucide="phone-call" class="w-5 h-5"></i></a>
` : ''}
<button onclick="openEditor(${svc.id})" class="bg-blue-600 text-white p-4 rounded-2xl shadow-lg active:scale-90 transition-all ml-2"><i data-lucide="edit-3" class="w-6 h-6"></i></button>
</div>` : '<i data-lucide="shield-off" class="text-slate-300 mx-4"></i>'} </div>` : '<i data-lucide="shield-off" class="text-slate-300 mx-4"></i>'}
</div>`; </div>`;
container.appendChild(card); container.appendChild(card);
@@ -237,11 +242,11 @@
if(!svc) return; if(!svc) return;
const raw = svc.raw_data; const raw = svc.raw_data;
// Pintar IDs informativos del nuevo header // ACTUALIZACIÓN DE CABECERA
document.getElementById('displayRef').innerText = `REF: ${svc.service_ref}`; document.getElementById('displayRef').innerText = `REF: ${svc.service_ref}`;
document.getElementById('displayCompany').innerText = raw['Compañía'] || raw['COMPAÑIA'] || svc.provider.toUpperCase(); document.getElementById('displayCompany').innerText = raw['Compañía'] || raw['COMPAÑIA'] || svc.provider.toUpperCase();
// Rellenar campos del formulario // RELLENAR FORMULARIO
document.getElementById('impScrapedId').value = id; document.getElementById('impScrapedId').value = id;
document.getElementById('impName').value = raw['Nombre Cliente'] || raw['CLIENTE'] || ""; document.getElementById('impName').value = raw['Nombre Cliente'] || raw['CLIENTE'] || "";
@@ -254,14 +259,12 @@
document.getElementById('impCP').value = raw['Código Postal'] || ""; document.getElementById('impCP').value = raw['Código Postal'] || "";
document.getElementById('impDesc').value = raw['Descripción'] || ""; 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(); document.getElementById('impUrgent').value = (raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true').toString();
// Reset de campos adicionales
document.getElementById('impNotesInt').value = ""; document.getElementById('impNotesInt').value = "";
document.getElementById('impNotesExt').value = ""; document.getElementById('impNotesExt').value = "";
document.getElementById('impGuild').value = ""; document.getElementById('impGuild').value = "";
document.getElementById('impOperator').innerHTML = '<option value="">-- Automática --</option>';
document.getElementById('importModal').classList.remove('hidden'); document.getElementById('importModal').classList.remove('hidden');
lucide.createIcons(); lucide.createIcons();
@@ -280,7 +283,7 @@
address: document.getElementById('impAddress').value, address: document.getElementById('impAddress').value,
cp: document.getElementById('impCP').value, cp: document.getElementById('impCP').value,
description: document.getElementById('impDesc').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, guild_id: document.getElementById('impGuild').value,
assigned_to: document.getElementById('impOperator').value || null, assigned_to: document.getElementById('impOperator').value || null,
internal_notes: document.getElementById('impNotesInt').value, internal_notes: document.getElementById('impNotesInt').value,
@@ -296,7 +299,7 @@
}); });
const result = await res.json(); const result = await res.json();
if(result.ok) { if(result.ok) {
showToast("✅ Expediente enviado al CRM"); showToast("✅ Traspasado con éxito");
closeModal(); closeModal();
loadInbox(); loadInbox();
} else { showToast("❌ Error al importar", true); } } else { showToast("❌ Error al importar", true); }