feat(cobranza): originación por movimiento en modal Movs + export PDF por subcuenta
Cada movimiento del modal (Tarjetas y Cuentas) muestra la Originación de la cuenta en su desglose, como el estado de cuenta. Botón nuevo 'Exportar estado de cuenta (PDF)' en el modal: el endpoint /api/estado-cuenta.pdf acepta ahora vehiculo/tipo opcionales para acotar el reporte a UNA subcuenta (saldos y movimientos filtrados). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
88b853e870
commit
3095afdb2b
2 files changed
+26
-4
No files matched your search
+14
-3
@@ -530,15 +530,24 @@ async def estado_cuenta_pdf(
|
||||
token: str = Query(...),
|
||||
cliente: str = Query(...),
|
||||
limite: int | None = Query(default=None, ge=1, le=cobranza_acumulada.MOV_MAX),
|
||||
vehiculo: str | None = Query(default=None),
|
||||
tipo: str | None = Query(default=None),
|
||||
):
|
||||
"""Estado de cuenta PDF de un cliente: saldos vigentes por subcuenta +
|
||||
últimos X movimientos de la bitácora (X = config `movimientos_visibles`
|
||||
o el `limite` pedido)."""
|
||||
o el `limite` pedido).
|
||||
|
||||
Con `vehiculo`/`tipo` el reporte se acota a UNA subcuenta (lo usa el
|
||||
botón Exportar PDF del modal de movimientos)."""
|
||||
numero = await _numero_token(token)
|
||||
objetivo = cobranza_acumulada._norm(cliente)
|
||||
veh_obj = cobranza_acumulada._norm(vehiculo) if vehiculo else None
|
||||
renglones = [
|
||||
r for r in await cobranza_acumulada.listar(numero)
|
||||
if cobranza_acumulada._norm(r.get("cliente") or "") == objetivo
|
||||
and (veh_obj is None
|
||||
or cobranza_acumulada._norm(r.get("vehiculo") or "") == veh_obj)
|
||||
and (tipo is None or (r.get("tipo") or "renta") == tipo)
|
||||
]
|
||||
cfg = await cobranza_acumulada.obtener_config_global()
|
||||
visibles = (
|
||||
@@ -546,7 +555,8 @@ async def estado_cuenta_pdf(
|
||||
or cobranza_acumulada.MOV_DEFAULT_VISIBLES
|
||||
)
|
||||
movs = await cobranza_acumulada.obtener_movimientos(
|
||||
numero, cliente=cliente, limite=visibles,
|
||||
numero, cliente=cliente, vehiculo=vehiculo, tipo=tipo,
|
||||
limite=visibles,
|
||||
)
|
||||
if not renglones and not movs:
|
||||
raise HTTPException(status_code=404, detail="Sin datos de ese cliente")
|
||||
@@ -557,7 +567,8 @@ async def estado_cuenta_pdf(
|
||||
cliente=nombre, renglones=renglones, movimientos=movs,
|
||||
visibles=visibles,
|
||||
)
|
||||
slug = re.sub(r"[^A-Za-z0-9]+", "-", cliente).strip("-").lower() or "cliente"
|
||||
base = cliente if not vehiculo else f"{cliente}-{vehiculo}"
|
||||
slug = re.sub(r"[^A-Za-z0-9]+", "-", base).strip("-").lower() or "cliente"
|
||||
return Response(
|
||||
content=pdf,
|
||||
media_type="application/pdf",
|
||||
|
||||
+12
-1
@@ -917,6 +917,15 @@ function descargarEdoCuenta(i){
|
||||
"&cliente=" + encodeURIComponent(c.nombre), "_blank");
|
||||
}
|
||||
|
||||
// Estado de cuenta PDF acotado a UNA subcuenta (desde el modal Movs).
|
||||
function exportarMovsPdf(id){
|
||||
const r = renglones.find(x => x.id === id); if(!r) return;
|
||||
window.open(API + "/estado-cuenta.pdf?token=" + encodeURIComponent(TOKEN) +
|
||||
"&cliente=" + encodeURIComponent(r.cliente || "") +
|
||||
"&vehiculo=" + encodeURIComponent(r.vehiculo || "") +
|
||||
"&tipo=" + encodeURIComponent(r.tipo || "renta"), "_blank");
|
||||
}
|
||||
|
||||
// ── Cobro consolidado: un mensaje con el desglose de la selección ──
|
||||
let consolidadoState = null; // {texto, total, cliente, id_ref} del backend
|
||||
|
||||
@@ -1595,7 +1604,8 @@ async function abrirMovs(id){
|
||||
document.getElementById("modal-inner").innerHTML = `
|
||||
<div class="modal-header"><span class="modal-title">Movimientos</span><button class="modal-close" onclick="cerrar()">×</button></div>
|
||||
<p style="font-size:13px;color:var(--text-secondary);margin-bottom:1rem">${r.cliente}<br>${r.vehiculo} · <span class="pill-tipo ${r.tipo}" style="margin:0">${tipoLabel(r)}</span><br><span style="font-size:11.5px">${metaSub.join(" · ")}</span></p>
|
||||
<div id="movs-lista" style="font-size:13px;color:var(--text-tertiary)">Cargando…</div>`;
|
||||
<div id="movs-lista" style="font-size:13px;color:var(--text-tertiary)">Cargando…</div>
|
||||
<button class="btn-wide" style="margin-top:14px" onclick="exportarMovsPdf('${r.id}')"><svg class="ic" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M14 2v6h6"/></svg> Exportar estado de cuenta (PDF)</button>`;
|
||||
document.getElementById("modal").classList.add("open");
|
||||
try {
|
||||
const res = await api("/movimientos?cliente=" + encodeURIComponent(r.cliente||"") +
|
||||
@@ -1618,6 +1628,7 @@ async function abrirMovs(id){
|
||||
despues = cap - Number(m.abonado);
|
||||
}
|
||||
const det = [];
|
||||
if(m.fecha_alta) det.push("Originación " + fmtFechaEs(m.fecha_alta));
|
||||
if(despues != null) det.push("Saldo previo " + fmt(despues + (Number(m.monto)||0)));
|
||||
if(despues != null) det.push("Saldo después " + fmt(despues));
|
||||
if(m.nota) det.push(m.nota);
|
||||
|
||||
Reference in new issue
Block a user