Actualizar proveedores.html
This commit is contained in:
@@ -48,10 +48,15 @@
|
|||||||
</h2>
|
</h2>
|
||||||
<p class="text-sm text-slate-500 mt-1 font-medium">Filtra por proveedor, compañía o cualquier dato del asegurado.</p>
|
<p class="text-sm text-slate-500 mt-1 font-medium">Filtra por proveedor, compañía o cualquier dato del asegurado.</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<button id="btnSmartSort" onclick="toggleSmartSort()" class="bg-indigo-50 border-2 border-indigo-100 hover:border-indigo-400 text-indigo-700 px-5 py-2.5 rounded-xl font-bold flex items-center gap-2 transition-all active:scale-95 shadow-sm">
|
||||||
|
<i data-lucide="sparkles" class="w-4 h-4"></i> Orden Inteligente
|
||||||
|
</button>
|
||||||
<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>
|
||||||
|
|
||||||
<div class="bg-white p-4 rounded-2xl border border-slate-200 shadow-sm mb-4 flex flex-wrap gap-4 items-center">
|
<div class="bg-white p-4 rounded-2xl border border-slate-200 shadow-sm mb-4 flex flex-wrap gap-4 items-center">
|
||||||
<div class="flex-1 min-w-[280px] relative text-left">
|
<div class="flex-1 min-w-[280px] relative text-left">
|
||||||
@@ -209,6 +214,7 @@
|
|||||||
let scrapedData = [];
|
let scrapedData = [];
|
||||||
let systemStatuses = []; // Guardará los estados reales de la DB
|
let systemStatuses = []; // Guardará los estados reales de la DB
|
||||||
let pollingInterval = null;
|
let pollingInterval = null;
|
||||||
|
let isSmartSortActive = false; // Variable para el botón Orden Inteligente
|
||||||
|
|
||||||
const companyLogos = {
|
const companyLogos = {
|
||||||
'REPSOL': 'https://cdn.sanity.io/images/rn4tswnp/production/1bc5be0207b732bd18dd0fc38e063d5701267068-1000x832.png?rect=6,0,994,832&h=320&auto=format&dpr=2',
|
'REPSOL': 'https://cdn.sanity.io/images/rn4tswnp/production/1bc5be0207b732bd18dd0fc38e063d5701267068-1000x832.png?rect=6,0,994,832&h=320&auto=format&dpr=2',
|
||||||
@@ -253,7 +259,55 @@
|
|||||||
if (modal.classList.contains('hidden')) {
|
if (modal.classList.contains('hidden')) {
|
||||||
await loadInbox();
|
await loadInbox();
|
||||||
}
|
}
|
||||||
}, 20000);
|
}, 30000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleSmartSort() {
|
||||||
|
isSmartSortActive = !isSmartSortActive;
|
||||||
|
const btn = document.getElementById('btnSmartSort');
|
||||||
|
if (isSmartSortActive) {
|
||||||
|
btn.classList.remove('bg-indigo-50', 'text-indigo-700', 'border-indigo-100', 'hover:border-indigo-400');
|
||||||
|
btn.classList.add('bg-indigo-600', 'text-white', 'border-indigo-600', 'shadow-indigo-200', 'hover:bg-indigo-700');
|
||||||
|
} else {
|
||||||
|
btn.classList.remove('bg-indigo-600', 'text-white', 'border-indigo-600', 'shadow-indigo-200', 'hover:bg-indigo-700');
|
||||||
|
btn.classList.add('bg-indigo-50', 'text-indigo-700', 'border-indigo-100', 'hover:border-indigo-400');
|
||||||
|
}
|
||||||
|
renderFilteredInbox();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calcular la prioridad del servicio
|
||||||
|
function getServicePriority(svc) {
|
||||||
|
const raw = svc.raw_data || {};
|
||||||
|
const autoStatus = (svc.automation_status || '').toLowerCase();
|
||||||
|
const sysStatus = (svc.status || '').toLowerCase();
|
||||||
|
const dbStatusId = raw.status_operativo;
|
||||||
|
const dbStatusObj = systemStatuses.find(st => String(st.id) === String(dbStatusId));
|
||||||
|
const opName = raw['assigned_to_name'] || null;
|
||||||
|
|
||||||
|
// Fallo bolsa: 2
|
||||||
|
if (autoStatus === 'failed') return 2;
|
||||||
|
|
||||||
|
// Bolsa activa: 5 (Resto)
|
||||||
|
if (autoStatus.includes('bolsa') || autoStatus === 'in_progress') return 5;
|
||||||
|
|
||||||
|
if (dbStatusObj) {
|
||||||
|
const stName = dbStatusObj.name.toLowerCase();
|
||||||
|
// Sin asignar de DB: 1
|
||||||
|
if (stName.includes('pendiente') && !stName.includes('cita')) return 1;
|
||||||
|
// Esperando al cliente: 3
|
||||||
|
if (stName.includes('esperando')) return 3;
|
||||||
|
// Citado: 4
|
||||||
|
if (stName.includes('citado')) return 4;
|
||||||
|
// Resto de estados: 5
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asignado o Importado: 5 (Resto)
|
||||||
|
if (raw['assigned_to'] || (sysStatus === 'imported' && opName)) return 5;
|
||||||
|
if (sysStatus === 'imported') return 5;
|
||||||
|
|
||||||
|
// Por defecto (Sin asignar): 1
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadStatuses() {
|
async function loadStatuses() {
|
||||||
@@ -526,9 +580,22 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SEPARAR ACTIVOS Y ARCHIVADOS
|
// SEPARAR ACTIVOS Y ARCHIVADOS
|
||||||
const activeServices = filtered.filter(svc => svc.status !== 'archived');
|
let activeServices = filtered.filter(svc => svc.status !== 'archived');
|
||||||
const archivedServices = filtered.filter(svc => svc.status === 'archived');
|
const archivedServices = filtered.filter(svc => svc.status === 'archived');
|
||||||
|
|
||||||
|
// APLICAR ORDEN INTELIGENTE SI ESTÁ ACTIVO
|
||||||
|
if (isSmartSortActive) {
|
||||||
|
activeServices.sort((a, b) => {
|
||||||
|
const priorityA = getServicePriority(a);
|
||||||
|
const priorityB = getServicePriority(b);
|
||||||
|
if (priorityA !== priorityB) {
|
||||||
|
return priorityA - priorityB;
|
||||||
|
}
|
||||||
|
// Mantener el orden original si tienen la misma prioridad
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 1. RENDERIZAR ACTIVOS
|
// 1. RENDERIZAR ACTIVOS
|
||||||
activeServices.forEach(svc => container.appendChild(buildServiceCard(svc)));
|
activeServices.forEach(svc => container.appendChild(buildServiceCard(svc)));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user