diff --git a/app/routes/automation.py b/app/routes/automation.py index 2e21576..025a09a 100644 --- a/app/routes/automation.py +++ b/app/routes/automation.py @@ -160,8 +160,10 @@ async def debug_cmxc(request: Request, user: dict = Depends(get_current_user), f return JSONResponse({"error": fb_msg}) ok, err, rows_fb = fb.execute_query(""" SELECT r.IDRECEPCION, r.PREFIJO, r.NUM_FACTURA, r.PS_NUM, - r.NIT_EMPRESA, r.VALORTOTAL, r.FECHA_RECEPCION + r.NIT_EMPRESA, r.VALORTOTAL, r.FECHA_RECEPCION, + e.CODCONTRATO FROM RECEPCION r + LEFT JOIN EMPRESA e ON e.NIT = r.NIT_EMPRESA WHERE r.FECHA_RECEPCION BETWEEN :fecha_ini AND :fecha_fin AND r.PREFIJO = 'CMXC' ORDER BY r.IDRECEPCION @@ -170,30 +172,27 @@ async def debug_cmxc(request: Request, user: dict = Depends(get_current_user), f if not ok: return JSONResponse({"error": err}) + from app.routes.contratos import load_excluded_set + excluded = load_excluded_set() + + rows_con_estado = [] + for r in rows_fb: + cod = str(r.get("CODCONTRATO") or "").strip() + rows_con_estado.append({**r, "excluido": cod in excluded}) + # EnvĂ­os en SQLite conn_sq = get_connection() - import os - db_path = os.path.abspath(conn_sq.execute("PRAGMA database_list").fetchone()[2] if False else "rips_manager.db") - envios_hoy = conn_sq.execute(""" - SELECT factura, status, respuesta_api, mensaje_tns, created_at - FROM envios - WHERE DATE(created_at) = ? AND tipo IN ('rda','preserv') - ORDER BY id DESC - """, (fecha,)).fetchall() envios_recientes = conn_sq.execute(""" SELECT id, factura, tipo, status, created_at - FROM envios - ORDER BY id DESC LIMIT 10 + FROM envios ORDER BY id DESC LIMIT 15 """).fetchall() - total_envios = conn_sq.execute("SELECT COUNT(*) FROM envios").fetchone()[0] conn_sq.close() return JSONResponse({ "fecha": fecha, - "cmxc_firebird": {"total": len(rows_fb), "rows": rows_fb}, - "envios_hoy": [dict(e) for e in envios_hoy], + "excluidos_configurados": sorted(excluded), + "cmxc_firebird": {"total": len(rows_fb), "rows": rows_con_estado}, "envios_recientes": [dict(e) for e in envios_recientes], - "total_envios_db": total_envios, })