fix: automation.html usa status string (success/warning/error) no booleano ok

- Fila warning: amarillo, sin botón reenviar
- Tab 'Ya existe' en filtros para ver solo warnings
- Filtros basados en status en lugar de ok boolean
- Toast muestra conteo correcto de 3 estados

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-24 11:02:20 -05:00
co-authored by Claude Sonnet 4.6
parent 6a452cd950
commit cefc8b664b
+37 -21
View File
@@ -125,6 +125,10 @@
class="px-3 py-1 text-xs font-medium rounded-md transition-all">
<i class="fas fa-times-circle mr-1"></i>Errores <span id="filter-cnt-errores" class="font-bold"></span>
</button>
<button id="filter-btn-advertencias" onclick="setResultFilter('advertencias')"
class="px-3 py-1 text-xs font-medium rounded-md transition-all">
<i class="fas fa-exclamation-circle mr-1"></i>Ya existe <span id="filter-cnt-advertencias" class="font-bold"></span>
</button>
<button id="filter-btn-enviados" onclick="setResultFilter('enviados')"
class="px-3 py-1 text-xs font-medium rounded-md transition-all">
<i class="fas fa-check-circle mr-1"></i>Enviados <span id="filter-cnt-enviados" class="font-bold"></span>
@@ -499,26 +503,27 @@ function renderResults(r) {
_resultAll = [];
activeSteps.forEach(s => {
(r[s.resultKey].detalle || []).forEach((item, i) => {
_resultAll.push({ item, step: s, idx: `${s.pasoKey}-${i}`, ok: item.ok });
const st = item.status || (item.ok ? 'success' : 'error');
_resultAll.push({ item, step: s, idx: `${s.pasoKey}-${i}`, status: st });
});
});
const errCount = _resultAll.filter(e => !e.ok).length;
const okCount = _resultAll.filter(e => e.ok).length;
const errCount = _resultAll.filter(e => e.status === 'error').length;
const warnCount = _resultAll.filter(e => e.status === 'warning').length;
const okCount = _resultAll.filter(e => e.status === 'success').length;
// Filter counts
document.getElementById('filter-cnt-errores').textContent = `(${errCount})`;
document.getElementById('filter-cnt-enviados').textContent = `(${okCount})`;
document.getElementById('filter-cnt-todos').textContent = `(${_resultAll.length})`;
document.getElementById('filter-cnt-errores').textContent = `(${errCount})`;
document.getElementById('filter-cnt-advertencias').textContent = `(${warnCount})`;
document.getElementById('filter-cnt-enviados').textContent = `(${okCount})`;
document.getElementById('filter-cnt-todos').textContent = `(${_resultAll.length})`;
// Default filter: errores si hay, si no todos
const defaultFilter = errCount > 0 ? 'errores' : 'todos';
const defaultFilter = errCount > 0 ? 'errores' : warnCount > 0 ? 'advertencias' : 'todos';
setResultFilter(defaultFilter);
document.getElementById('results-section').classList.remove('hidden');
showToast(
errCount === 0 ? `Envío completado · ${okCount} registros OK` : `${errCount} fallo(s) · ${okCount} OK`,
errCount === 0 ? `Envío completado · ${okCount} OK · ${warnCount} ya existían` : `${errCount} fallo(s) · ${okCount} OK · ${warnCount} ya existían`,
errCount === 0 ? 'success' : 'warning'
);
}
@@ -529,32 +534,34 @@ function setResultFilter(filter) {
// Actualizar estilos de botones
const configs = {
errores: { active: 'bg-white shadow text-red-600', inactive: 'text-gray-500 hover:text-gray-700' },
enviados: { active: 'bg-white shadow text-green-600', inactive: 'text-gray-500 hover:text-gray-700' },
todos: { active: 'bg-white shadow text-gray-700', inactive: 'text-gray-500 hover:text-gray-700' },
errores: { active: 'bg-white shadow text-red-600', inactive: 'text-gray-500 hover:text-gray-700' },
advertencias: { active: 'bg-white shadow text-yellow-600', inactive: 'text-gray-500 hover:text-gray-700' },
enviados: { active: 'bg-white shadow text-green-600', inactive: 'text-gray-500 hover:text-gray-700' },
todos: { active: 'bg-white shadow text-gray-700', inactive: 'text-gray-500 hover:text-gray-700' },
};
['errores','enviados','todos'].forEach(f => {
['errores','advertencias','enviados','todos'].forEach(f => {
const btn = document.getElementById(`filter-btn-${f}`);
const base = 'px-3 py-1 text-xs font-medium rounded-md transition-all';
btn.className = `${base} ${f === filter ? configs[f].active : configs[f].inactive}`;
});
// Filtrar items
let items;
if (filter === 'errores') items = _resultAll.filter(e => !e.ok);
else if (filter === 'enviados') items = _resultAll.filter(e => e.ok);
if (filter === 'errores') items = _resultAll.filter(e => e.status === 'error');
else if (filter === 'advertencias') items = _resultAll.filter(e => e.status === 'warning');
else if (filter === 'enviados') items = _resultAll.filter(e => e.status === 'success');
else items = _resultAll;
const listEl = document.getElementById('results-list');
if (items.length === 0) {
const msg = filter === 'errores' ? 'Sin errores — todo enviado correctamente' :
filter === 'advertencias' ? 'Sin advertencias' :
filter === 'enviados' ? 'No hay registros enviados' : 'Sin resultados';
listEl.innerHTML = `<div class="p-8 text-center text-gray-400 text-sm"><i class="fas ${filter==='errores'?'fa-check-circle text-green-400':'fa-inbox'} text-2xl mb-2 block"></i>${msg}</div>`;
return;
}
listEl.innerHTML = items.map(({ item, step: s, idx, ok }) => {
listEl.innerHTML = items.map(({ item, step: s, idx, status }) => {
let label1 = '', label2 = '', dtype = s.tipo, did = '';
if (s.tipo === 'tercero') {
@@ -569,8 +576,7 @@ function setResultFilter(filter) {
const msg = (item.msg || '').trim();
if (ok) {
// Fila exitosa
if (status === 'success') {
return `
<div class="px-5 py-3 flex items-center gap-3 hover:bg-gray-50 transition-colors">
<span class="text-green-500 shrink-0 text-base"><i class="fas fa-check-circle"></i></span>
@@ -581,8 +587,18 @@ function setResultFilter(filter) {
<span class="text-gray-600 text-xs flex-1 truncate">${escHtml(label2)}</span>
<span class="text-green-600 text-xs max-w-[220px] truncate shrink-0" title="${escHtml(msg)}">${escHtml(msg.slice(0,60))}</span>
</div>`;
} else if (status === 'warning') {
return `
<div class="px-5 py-3 flex items-center gap-3 bg-yellow-50 hover:bg-yellow-100 transition-colors border-l-4 border-yellow-400">
<span class="text-yellow-500 shrink-0 text-base"><i class="fas fa-exclamation-circle"></i></span>
<span class="${_BADGE[s.color]} text-xs font-semibold px-2 py-0.5 rounded shrink-0">
<i class="fas ${s.icon} mr-1 opacity-70 text-xs"></i>${s.label}
</span>
<span class="font-mono text-gray-800 text-xs w-28 shrink-0 truncate" title="${escHtml(label1)}">${escHtml(label1)}</span>
<span class="text-gray-600 text-xs flex-1 truncate">${escHtml(label2)}</span>
<span class="text-yellow-700 text-xs max-w-[260px] truncate shrink-0" title="${escHtml(msg)}">${escHtml(msg.slice(0,80))}</span>
</div>`;
} else {
// Fila con error + botón reenviar
return `
<div data-resend-row class="px-5 py-3 flex items-start gap-3 bg-red-50 hover:bg-red-100 transition-colors border-l-4 border-red-400">
<span class="text-red-400 shrink-0 text-base mt-0.5 fail-status-icon"><i class="fas fa-times-circle"></i></span>