diff --git a/public.php b/public.php index 0d110a66..19cb3aa7 100755 --- a/public.php +++ b/public.php @@ -2011,7 +2011,7 @@ $installersData = json_decode($config['installersDataWhatsApp'] ?? '{"instalador
-

+

📋 Tareas e Instalaciones Activas por Técnico

Selecciona un técnico instalador para consultar sus tareas "En curso" y reenviar notificaciones por WhatsApp

@@ -2746,52 +2746,48 @@ $installersData = json_decode($config['installersDataWhatsApp'] ?? '{"instalador const tableWrapper = document.getElementById('jobsTableWrapper'); const noResults = document.getElementById('jobsNoResults'); - title.innerHTML = `📋 Tareas Activas: ${installerName}`; - emptyState.style.display = 'none'; - loading.style.display = 'block'; - tableWrapper.style.display = 'none'; - noResults.style.display = 'none'; - - // Scroll suave a la sección de jobs - title.scrollIntoView({ - behavior: 'smooth', - block: 'start' - }); + if (title) title.innerHTML = `📋 Tareas Activas: ${escapeHtml(installerName)}`; + if (emptyState) emptyState.style.display = 'none'; + if (loading) loading.style.display = 'block'; + if (tableWrapper) tableWrapper.style.display = 'none'; + if (noResults) noResults.style.display = 'none'; try { const resp = await fetch(`?action=get_installer_jobs&installerId=${installerId}`); const jobs = await resp.json(); - loading.style.display = 'none'; + if (loading) loading.style.display = 'none'; - if (!jobs.length) { - noResults.style.display = 'block'; + if (!Array.isArray(jobs) || !jobs.length) { + if (noResults) noResults.style.display = 'block'; return; } const tbody = document.querySelector('#installerJobsTable tbody'); - tbody.innerHTML = jobs.map(job => { - const dateFormatted = job.date ? new Date(job.date).toLocaleDateString('es-MX', { - day: '2-digit', - month: '2-digit', - year: 'numeric' - }) : 'S/F'; - const titleClean = job.title.replace('[NOTIFICACION-PENDIENTE]', '').replace('[CLIENTE-SIN-WHATSAPP]', '').trim(); - return ` - #${job.id} - [${job.clientId}] ${job.clientName} - ${dateFormatted} - ${titleClean || job.description || 'Sin descripción'} - - - - `; - }).join(''); - tableWrapper.style.display = 'block'; + if (tbody) { + tbody.innerHTML = jobs.map(job => { + const dateFormatted = job.date ? new Date(job.date).toLocaleDateString('es-MX', { + day: '2-digit', + month: '2-digit', + year: 'numeric' + }) : 'S/F'; + const titleClean = String(job.title || '').replace('[NOTIFICACION-PENDIENTE]', '').replace('[CLIENTE-SIN-WHATSAPP]', '').trim(); + return ` + #${job.id} + [${job.clientId || '-'}] ${escapeHtml(job.clientName)} + ${dateFormatted} + ${escapeHtml(titleClean || job.description || 'Sin descripción')} + + + + `; + }).join(''); + } + if (tableWrapper) tableWrapper.style.display = 'block'; } catch (e) { - loading.style.display = 'none'; - noResults.style.display = 'block'; + if (loading) loading.style.display = 'none'; + if (noResults) noResults.style.display = 'block'; console.error('Error loading installer jobs:', e); } }