From dc9af65ae42e73bbf7b0bd4878863a983a7f338f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorem=20Ju=C3=A1rez?= Date: Wed, 24 Jun 2026 14:08:48 -0600 Subject: [PATCH] feat(cobranza): texto editable y precargado por bloque del cuerpo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit En la plantilla del mensaje, cada bloque del cuerpo (cliente, vehículo, monto, fecha límite, link) muestra al activarse un campo de texto a la derecha, precargado con su valor por defecto y editable. Acepta variables ({cliente},{vehiculo},{monto},{fecha},{concepto},{mes}). - Frontend: filas casilla+campo (se muestra solo si la casilla está activa), rellenado/guardado de los 5 texto_*; armarMensajeCobro y la vista previa usan los textos; se agrega la variable {fecha}. - Backend: PlantillaBody y DEFAULT_PLANTILLA con texto_cliente/vehiculo/monto/ fecha/link. Merge por parche retrocompatible. 22 tests OK. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/api/cobranza_api.py | 6 +++ src/services/cobranza_acumulada.py | 7 +++ web/cobranza.html | 78 +++++++++++++++++++++++++----- 3 files changed, 78 insertions(+), 13 deletions(-) diff --git a/src/api/cobranza_api.py b/src/api/cobranza_api.py index f3f3b29..b0af042 100644 --- a/src/api/cobranza_api.py +++ b/src/api/cobranza_api.py @@ -148,6 +148,12 @@ class PlantillaBody(BaseModel): incluir_cliente: bool | None = None incluir_fecha_limite: bool | None = None incluir_link: bool | None = None + # Texto editable de cada bloque del cuerpo. + texto_cliente: str | None = None + texto_vehiculo: str | None = None + texto_monto: str | None = None + texto_fecha: str | None = None + texto_link: str | None = None class EnviarMensajeBody(BaseModel): diff --git a/src/services/cobranza_acumulada.py b/src/services/cobranza_acumulada.py index 5d20a89..70ef47c 100644 --- a/src/services/cobranza_acumulada.py +++ b/src/services/cobranza_acumulada.py @@ -1179,6 +1179,13 @@ DEFAULT_PLANTILLA: dict = { # en el mensaje. Si False, el mensaje va sin link (solo cuentas SPEI) y # no se genera checkout. "incluir_link": True, + # Texto editable de cada bloque del cuerpo (soporta variables {cliente}, + # {vehiculo}, {monto}, {fecha}, {concepto}, {mes}). + "texto_cliente": "Cliente: {cliente}", + "texto_vehiculo": "Vehículo: {vehiculo}", + "texto_monto": "Monto: {monto}", + "texto_fecha": "Fecha límite: {fecha}", + "texto_link": "Puede pagar con tarjeta, SPEI o efectivo en Oxxo desde este link:", } diff --git a/web/cobranza.html b/web/cobranza.html index 62745ae..54fc0e7 100644 --- a/web/cobranza.html +++ b/web/cobranza.html @@ -146,6 +146,10 @@ .check-row { display: flex; align-items: center; gap: 11px; padding: 9px 2px; font-size: 13px; color: var(--text-primary); cursor: pointer; } .check-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; } + .bloque-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; } + .bloque-row .check-row { flex: 0 0 auto; min-width: 175px; } + .bloque-row .bloque-txt { flex: 1; min-width: 160px; padding: 8px 11px; font-size: 12.5px; } + .bloque-row .bloque-txt[hidden] { display: none; } .preview-msg { background: var(--surface-2); border: 1px solid var(--line); border-radius: 13px; padding: 1rem 1.1rem; font-size: 12.5px; color: var(--text-primary); white-space: pre-wrap; line-height: 1.6; font-family: 'DM Sans', sans-serif; } @@ -405,11 +409,27 @@
- - - - - +
Al activar cada bloque puedes editar su texto (acepta variables).
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
@@ -1685,6 +1705,24 @@ async function eliminarCuenta(id){ } catch(e){ toast("No se pudo eliminar: " + e.message); } } +// Bloques del cuerpo: casilla + texto editable (precargado) + clave de plantilla. +const BLOQUES = [ + {chk:"pl-cliente", txt:"pl-cliente-txt", key:"texto_cliente", def:"Cliente: {cliente}"}, + {chk:"pl-vehiculo", txt:"pl-vehiculo-txt", key:"texto_vehiculo", def:"Vehículo: {vehiculo}"}, + {chk:"pl-monto", txt:"pl-monto-txt", key:"texto_monto", def:"Monto: {monto}"}, + {chk:"pl-fecha", txt:"pl-fecha-txt", key:"texto_fecha", def:"Fecha límite: {fecha}"}, + {chk:"pl-link", txt:"pl-link-txt", key:"texto_link", def:"Puede pagar con tarjeta, SPEI o efectivo en Oxxo desde este link:"}, +]; + +// Muestra el campo de texto solo cuando su casilla está activa. +function sincBloquesUI(){ + BLOQUES.forEach(b => { + const chk = document.getElementById(b.chk), txt = document.getElementById(b.txt); + if(chk && txt) txt.hidden = !chk.checked; + }); +} +function bloqueChanged(){ sincBloquesUI(); renderVistaPreviaMsg(); } + function rellenarPlantillaInputs(){ const p = (configGlobal && configGlobal.plantilla) ? configGlobal.plantilla : {}; document.getElementById("pl-saludo").value = p.saludo || ""; @@ -1694,6 +1732,12 @@ function rellenarPlantillaInputs(){ document.getElementById("pl-monto").checked = p.incluir_monto !== false; document.getElementById("pl-fecha").checked = !!p.incluir_fecha_limite; document.getElementById("pl-link").checked = p.incluir_link !== false; + // Texto de cada bloque: usa el guardado o el default precargado. + BLOQUES.forEach(b => { + const e = document.getElementById(b.txt); + if(e) e.value = (p[b.key] != null ? p[b.key] : b.def); + }); + sincBloquesUI(); } async function guardarPlantilla(){ @@ -1706,6 +1750,7 @@ async function guardarPlantilla(){ incluir_fecha_limite: document.getElementById("pl-fecha").checked, incluir_link: document.getElementById("pl-link").checked, }; + BLOQUES.forEach(b => { body[b.key] = document.getElementById(b.txt).value; }); try { const pl = await api("/config/plantilla", {method:"POST", body: JSON.stringify(body)}); if(configGlobal) configGlobal.plantilla = pl; @@ -1748,12 +1793,22 @@ function armarMensajeCobro(r, monto, concepto, link){ const pl = cfg.plantilla || {}; const cuentas = (cfg.cuentas || []).filter(c => c.incluir_en_mensaje); const d = new Date(); + const fLim = new Date(); fLim.setDate(fLim.getDate() + 5); const vars = { cliente: r.cliente || "", vehiculo: r.vehiculo || "", monto: fmt(monto), concepto: concepto || "", mes: _MESES_CORTO[d.getMonth()] + " " + d.getFullYear(), + fecha: fLim.toLocaleDateString("es-MX",{day:"2-digit",month:"2-digit",year:"numeric"}), + }; + // Texto editable por bloque (cae al default si la plantilla no lo trae). + const T = { + cliente: pl.texto_cliente != null ? pl.texto_cliente : "Cliente: {cliente}", + vehiculo: pl.texto_vehiculo != null ? pl.texto_vehiculo : "Vehículo: {vehiculo}", + monto: pl.texto_monto != null ? pl.texto_monto : "Monto: {monto}", + fecha: pl.texto_fecha != null ? pl.texto_fecha : "Fecha límite: {fecha}", + link: pl.texto_link != null ? pl.texto_link : "Puede pagar con tarjeta, SPEI o efectivo en Oxxo desde este link:", }; const incluirLink = (pl.incluir_link !== false) && !!link; @@ -1761,13 +1816,10 @@ function armarMensajeCobro(r, monto, concepto, link){ if(pl.saludo) out += _aplicarVariables(pl.saludo, vars) + "\n\n"; out += "Le compartimos los datos para realizar su pago:\n\n"; out += `Concepto: ${concepto}\n`; - if(pl.incluir_cliente !== false && r.cliente) out += `Cliente: ${r.cliente}\n`; - if(pl.incluir_vehiculo !== false && r.vehiculo) out += `Vehículo: ${r.vehiculo}\n`; - if(pl.incluir_monto !== false) out += `Monto: ${fmt(monto)}\n`; - if(pl.incluir_fecha_limite){ - const f = new Date(); f.setDate(f.getDate() + 5); - out += `Fecha límite: ${f.toLocaleDateString("es-MX",{day:"2-digit",month:"2-digit",year:"numeric"})}\n`; - } + if(pl.incluir_cliente !== false && r.cliente) out += _aplicarVariables(T.cliente, vars) + "\n"; + if(pl.incluir_vehiculo !== false && r.vehiculo) out += _aplicarVariables(T.vehiculo, vars) + "\n"; + if(pl.incluir_monto !== false) out += _aplicarVariables(T.monto, vars) + "\n"; + if(pl.incluir_fecha_limite) out += _aplicarVariables(T.fecha, vars) + "\n"; out += "\n"; if(cuentas.length){ cuentas.forEach(c => { @@ -1779,7 +1831,7 @@ function armarMensajeCobro(r, monto, concepto, link){ }); } if(incluirLink){ - out += `Puede pagar con tarjeta, SPEI o efectivo en Oxxo desde este link:\n${link}\n\n`; + out += _aplicarVariables(T.link, vars) + `\n${link}\n\n`; } if(!cuentas.length && !incluirLink){ out += "⚠️ No hay cuentas activadas ni link configurado.\n\n";