From da2795c74c71236f3824feec66190cd6103e2555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorem=20Ju=C3=A1rez?= Date: Tue, 4 Aug 2026 15:09:16 -0600 Subject: [PATCH] =?UTF-8?q?feat(cobranza):=20pesta=C3=B1a=20'Cuentas'=20ag?= =?UTF-8?q?rupada=20por=20cliente=20con=20subcuentas=20(Fase=201)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nueva vista en el panel: acordeón por cliente ordenado por saldo, subcuentas desglosadas (vehículo/concepto) seleccionables con total en vivo de la selección. Reusa Generar cobro / Saldar / Editar existentes (edición inline funciona también dentro del acordeón). Solo frontend; sin cambios de backend ni de datos. Co-Authored-By: Claude Opus 4.8 --- web/cobranza.html | 164 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 161 insertions(+), 3 deletions(-) diff --git a/web/cobranza.html b/web/cobranza.html index 00a80a4..1655618 100644 --- a/web/cobranza.html +++ b/web/cobranza.html @@ -60,7 +60,7 @@ .header p { font-size: 12.5px; color: var(--text-secondary); margin-top: 3px; } .tabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 1.4rem; animation: fadeUp 0.62s ease both; } - .tab { flex: 1; padding: 9px 8px; border: none; background: transparent; border-radius: 9px; font-size: 13px; font-weight: 600; font-family: 'DM Sans', sans-serif; color: var(--text-secondary); cursor: pointer; transition: all 0.18s ease; } + .tab { flex: 1; padding: 9px 4px; border: none; background: transparent; border-radius: 9px; font-size: 12.5px; font-weight: 600; font-family: 'DM Sans', sans-serif; color: var(--text-secondary); cursor: pointer; transition: all 0.18s ease; white-space: nowrap; } .tab:hover { color: var(--text-primary); } .tab.active { background: var(--surface); box-shadow: 0 1px 2px rgba(18,24,38,.08), 0 0 0 1px var(--line); color: var(--accent); } @@ -209,6 +209,34 @@ .btn-danger-soft { background: var(--surface); color: var(--danger); border-color: var(--line); } .btn-danger-soft:hover { background: var(--danger-soft); border-color: transparent; } + /* Vista Cuentas: acordeón por cliente con subcuentas seleccionables */ + .cta-block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card); box-shadow: var(--nm-out); margin-bottom: 12px; animation: fadeUp 0.5s ease both; overflow: hidden; } + .cta-head { display: flex; align-items: center; gap: 10px; padding: 0.95rem 1.1rem; cursor: pointer; user-select: none; } + .cta-head:hover { background: var(--surface-2); } + .cta-chev { flex: 0 0 auto; width: 22px; height: 22px; border-radius: 7px; background: var(--accent-soft); color: var(--accent); font-size: 12px; display: inline-flex; align-items: center; justify-content: center; } + .cta-name { flex: 1; min-width: 0; font-size: 14.5px; font-weight: 700; letter-spacing: -0.2px; line-height: 1.25; } + .cta-sub { font-size: 11px; font-weight: 500; color: var(--text-secondary); margin-top: 2px; } + .cta-selbadge { color: var(--accent); font-weight: 700; } + .cta-tot { flex: 0 0 auto; text-align: right; font-family: 'Space Grotesk', sans-serif; font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.3px; } + .cta-mora { font-family: 'DM Sans', sans-serif; font-size: 10px; font-weight: 600; color: var(--warning); margin-top: 1px; } + .cta-body { border-top: 1px solid var(--line); padding: 0.85rem 1rem 1rem; background: var(--surface-2); } + .cta-seltodo { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; color: var(--text-secondary); cursor: pointer; margin-bottom: 10px; } + .cta-seltodo input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; } + .sub-card { background: var(--surface); border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--nm-subtle); margin-bottom: 10px; overflow: hidden; transition: border-color 0.15s ease, box-shadow 0.15s ease; } + .sub-card.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 6px 14px -6px var(--accent-glow); } + .sub-row { display: flex; align-items: center; gap: 10px; padding: 0.75rem 0.85rem; cursor: pointer; } + .sub-check { flex: 0 0 auto; width: 20px; height: 20px; border-radius: 7px; border: 2px solid var(--line-strong); background: var(--surface); color: #fff; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; transition: all 0.15s ease; } + .sub-check.on { background: var(--accent); border-color: var(--accent); } + .sub-main { flex: 1; min-width: 0; } + .sub-title { font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; } + .sub-meta { font-size: 11px; color: var(--text-secondary); margin-top: 3px; } + .sub-saldo { flex: 0 0 auto; font-family: 'Space Grotesk', sans-serif; font-size: 14.5px; font-weight: 600; font-variant-numeric: tabular-nums; } + .sub-actions { display: flex; gap: 7px; padding: 0 0.85rem 0.8rem; } + .sub-actions .btn { padding: 8px 10px; font-size: 11.5px; border-radius: 10px; } + .cta-foot { display: flex; justify-content: space-between; align-items: center; padding: 0.7rem 0.2rem 0; font-size: 12.5px; font-weight: 600; color: var(--text-secondary); } + .cta-foot .val { font-family: 'Space Grotesk', sans-serif; font-size: 16px; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; } + .cta-foot.empty { justify-content: center; font-weight: 500; font-size: 11.5px; color: var(--text-tertiary); } + /* Modo edición inline */ .edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 1rem; } .edit-field label { font-size: 10px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.4px; display: block; margin-bottom: 5px; font-weight: 700; } @@ -362,6 +390,7 @@
+ @@ -395,6 +424,11 @@
+
+ +
+
+
@@ -696,7 +730,7 @@ async function refrescarDuplicados(){ } catch(e){ /* sin banner */ } } -function render(){ renderTarjetas(); renderTabla(); renderStats(); } +function render(){ renderTarjetas(); renderCuentas(); renderTabla(); renderStats(); } function renderStats(){ let total=0, mora=0; // Desglose del total (saldo pendiente) por tipo de cobro. @@ -716,6 +750,128 @@ function renderStats(){ document.getElementById("stat-otro").textContent = fmtK(porTipo.otro); } +// ── Vista CUENTAS: agrupado por cliente con subcuentas ───────── +let ctaClientes = []; // [{nombre, rs, total, mora}] del último render +let ctaSel = new Set(); // ids de subcuentas (renglones) seleccionadas +let ctaAbiertas = new Set(); // nombres de cliente con acordeón abierto + +function ctaResumenSub(r){ + const partes = []; + const periodos = Array.isArray(r.periodos) ? r.periodos : []; + if(r.tipo === "renta" && periodos.length >= 2){ + partes.push(periodos.length + " meses pendientes"); + } + if((r.tipo === "vr" || r.tipo === "extra") && r.fecha_vencimiento){ + partes.push("vence " + fmtFechaEs(r.fecha_vencimiento)); + } else if(r.tipo === "renta" && r.dia_pago){ + partes.push("paga día " + r.dia_pago); + } + if(Number(r.moratorio) > 0) partes.push("mora " + fmt(r.moratorio)); + if(Number(r.dias_retraso) > 0) partes.push(r.dias_retraso + "d de atraso"); + return partes.join(" · "); +} + +function renderCuentas(){ + const cont = document.getElementById("cta-lista"); + if(!cont) return; + // Poda la selección de renglones que ya no existen (saldados/eliminados). + const vivos = new Set(renglones.map(r => r.id)); + [...ctaSel].forEach(id => { if(!vivos.has(id)) ctaSel.delete(id); }); + + const grupos = new Map(); + renglones.forEach(r => { + const k = (r.cliente || "").trim() || "(Sin cliente)"; + if(!grupos.has(k)) grupos.set(k, []); + grupos.get(k).push(r); + }); + ctaClientes = [...grupos.entries()] + .map(([nombre, rs]) => ({ nombre, rs, + total: rs.reduce((s,r)=>s+(Number(r.saldo)||0),0), + mora: rs.reduce((s,r)=>s+(Number(r.moratorio)||0),0) })) + .sort((a,b) => b.total - a.total); + + const nCli = ctaClientes.length; + document.getElementById("cta-count").textContent = + nCli + (nCli === 1 ? " cliente" : " clientes") + " · " + + renglones.length + (renglones.length === 1 ? " subcuenta" : " subcuentas"); + + if(!nCli){ + cont.innerHTML = `
Sin cobranza activa. Usa "Cargar cobranza de hoy" en Tarjetas.
`; + return; + } + + cont.innerHTML = ctaClientes.map((c,i) => { + const abierta = ctaAbiertas.has(c.nombre); + const sel = c.rs.filter(r => ctaSel.has(r.id)); + const totalSel = sel.reduce((s,r)=>s+(Number(r.saldo)||0),0); + const selBadge = sel.length + ? ` · ${sel.length} sel · ${fmt(totalSel)}` : ""; + const moraLinea = c.mora > 0 ? `
mora ${fmt(c.mora)}
` : ""; + let body = ""; + if(abierta){ + const subcards = c.rs.map(r => { + if(editingId === r.id) return `
${renderEditInline(r)}
`; + const marcada = ctaSel.has(r.id); + return ` +
+
+ ${marcada ? "✓" : ""} +
+
${r.vehiculo} ${tipoLabel(r)}
+
${ctaResumenSub(r)}
+
+
${fmt(r.saldo)}
+
+
+ + + +
+
`; + }).join(""); + const todas = sel.length === c.rs.length; + const foot = sel.length + ? `
${sel.length} seleccionada${sel.length===1?"":"s"}${fmt(totalSel)}
` + : `
Toca una subcuenta para seleccionarla y ver el total a cobrar.
`; + body = ` +
+ + ${subcards} + ${foot} +
`; + } + return ` +
+
+ ${abierta ? "▾" : "▸"} +
${escapeAttr(c.nombre)} +
${c.rs.length} subcuenta${c.rs.length===1?"":"s"}${selBadge}
+
+
${fmt(c.total)}${moraLinea}
+
+ ${body} +
`; + }).join(""); +} + +function ctaToggle(i){ + const c = ctaClientes[i]; if(!c) return; + if(ctaAbiertas.has(c.nombre)) ctaAbiertas.delete(c.nombre); else ctaAbiertas.add(c.nombre); + renderCuentas(); +} +function ctaSelSub(id){ + if(ctaSel.has(id)) ctaSel.delete(id); else ctaSel.add(id); + renderCuentas(); +} +function ctaSelTodo(i){ + const c = ctaClientes[i]; if(!c) return; + const todas = c.rs.every(r => ctaSel.has(r.id)); + c.rs.forEach(r => { if(todas) ctaSel.delete(r.id); else ctaSel.add(r.id); }); + renderCuentas(); +} + function renderTarjetas(){ const lista = document.getElementById("lista"); lista.innerHTML = ""; @@ -884,11 +1040,13 @@ function entrarEdicion(id){ editingId = id; editDraft = {}; // se reconstruye en renderEditInline renderTarjetas(); + renderCuentas(); } function cancelarEdicion(){ editingId = null; editDraft = {}; renderTarjetas(); + renderCuentas(); } async function guardarEdicion(){ if(!editDraft.id) return; @@ -1635,7 +1793,7 @@ function cerrar(){ document.getElementById("modal").classList.remove("open"); document.getElementById("modal-inner").classList.remove("lote"); } -const VISTAS_VALIDAS = ["tarjetas", "tabla", "directorio", "mensaje"]; +const VISTAS_VALIDAS = ["tarjetas", "cuentas", "tabla", "directorio", "mensaje"]; const VIEW_KEY = "cobranza_view"; function setView(v){