diff --git a/src/api/cobranza_api.py b/src/api/cobranza_api.py index 543046e..201641b 100644 --- a/src/api/cobranza_api.py +++ b/src/api/cobranza_api.py @@ -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", diff --git a/web/cobranza.html b/web/cobranza.html index a952c34..3d1c199 100644 --- a/web/cobranza.html +++ b/web/cobranza.html @@ -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 = `
${r.cliente}
${r.vehiculo} · ${tipoLabel(r)}
${metaSub.join(" · ")}