fix: update /debug-fb/recepcion to show all columns and empresa tables
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
85ae3a0b3e
commit
7aa02fe6ac
+31
-26
@@ -69,7 +69,7 @@ async def listar_diagnosticos(
|
|||||||
|
|
||||||
@router.get("/recepcion")
|
@router.get("/recepcion")
|
||||||
async def debug_recepcion(user: dict = Depends(get_current_user)):
|
async def debug_recepcion(user: dict = Depends(get_current_user)):
|
||||||
"""Diagnóstico: qué hay en RECEPCION hoy sin filtros restrictivos."""
|
"""Diagnóstico: columnas de RECEPCION, tabla EMPRESA y link a tarifa."""
|
||||||
try:
|
try:
|
||||||
conn = get_connection()
|
conn = get_connection()
|
||||||
cfg = {r["key"]: r["value"] for r in conn.execute("SELECT * FROM config").fetchall()}
|
cfg = {r["key"]: r["value"] for r in conn.execute("SELECT * FROM config").fetchall()}
|
||||||
@@ -81,37 +81,42 @@ async def debug_recepcion(user: dict = Depends(get_current_user)):
|
|||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
# Últimas 5 recepciones sin ningún filtro
|
# Todas las columnas de RECEPCION
|
||||||
ok1, _, rows1 = fb.execute_query(
|
ok_c, _, cols = fb.execute_query(
|
||||||
"SELECT FIRST 5 r.IDRECEPCION, r.FECHA_RECEPCION, r.HORAINICIORECEPCION, "
|
"SELECT TRIM(f.RDB$FIELD_NAME) AS COL "
|
||||||
"r.NUM_FACTURA, r.COD_PACIENTE "
|
"FROM RDB$RELATION_FIELDS f "
|
||||||
"FROM RECEPCION r ORDER BY r.IDRECEPCION DESC", None
|
"WHERE TRIM(f.RDB$RELATION_NAME) = 'RECEPCION' "
|
||||||
|
"ORDER BY f.RDB$FIELD_POSITION", None
|
||||||
)
|
)
|
||||||
result["ultimas_5_sin_filtro"] = list(rows1) if ok1 and rows1 else f"error: {rows1}"
|
result["columnas_recepcion"] = [r["COL"] for r in (cols or [])] if ok_c else []
|
||||||
|
|
||||||
# Fecha actual en Firebird
|
# Tablas con EMPRESA o CONVENIO en el nombre
|
||||||
ok2, _, rows2 = fb.execute_query("SELECT CURRENT_DATE AS FH FROM RDB$DATABASE", None)
|
ok_e, _, tabs = fb.execute_query(
|
||||||
result["current_date_firebird"] = rows2[0] if ok2 and rows2 else "error"
|
"SELECT TRIM(r.RDB$RELATION_NAME) AS TABLA FROM RDB$RELATIONS r "
|
||||||
|
"WHERE r.RDB$SYSTEM_FLAG = 0 "
|
||||||
# Cuántas recepciones de hoy (CURRENT_DATE) sin filtro NUM_FACTURA
|
" AND (UPPER(TRIM(r.RDB$RELATION_NAME)) CONTAINING 'EMPRESA' "
|
||||||
ok3, _, rows3 = fb.execute_query(
|
" OR UPPER(TRIM(r.RDB$RELATION_NAME)) CONTAINING 'CONVENIO') "
|
||||||
"SELECT COUNT(*) AS CNT FROM RECEPCION r WHERE r.FECHA_RECEPCION = CURRENT_DATE", None
|
"ORDER BY TABLA", None
|
||||||
)
|
)
|
||||||
result["hoy_sin_filtro_factura"] = rows3[0] if ok3 and rows3 else "error"
|
result["tablas_empresa_convenio"] = [r["TABLA"] for r in (tabs or [])] if ok_e else []
|
||||||
|
|
||||||
# Cuántas con NUM_FACTURA > 0
|
# Columnas + muestra de cada tabla encontrada
|
||||||
ok4, _, rows4 = fb.execute_query(
|
for t in result["tablas_empresa_convenio"][:4]:
|
||||||
"SELECT COUNT(*) AS CNT FROM RECEPCION r "
|
ok_tc, _, tcols = fb.execute_query(
|
||||||
"WHERE r.FECHA_RECEPCION = CURRENT_DATE AND r.NUM_FACTURA > 0", None
|
"SELECT TRIM(f.RDB$FIELD_NAME) AS COL FROM RDB$RELATION_FIELDS f "
|
||||||
)
|
f"WHERE TRIM(f.RDB$RELATION_NAME) = '{t}' ORDER BY f.RDB$FIELD_POSITION", None
|
||||||
result["hoy_con_factura"] = rows4[0] if ok4 and rows4 else "error"
|
)
|
||||||
|
ok_tr, _, trows = fb.execute_query(f"SELECT FIRST 2 * FROM {t}", None)
|
||||||
|
result[f"tabla_{t}"] = {
|
||||||
|
"columnas": [c["COL"] for c in (tcols or [])] if ok_tc else [],
|
||||||
|
"muestra": list(trows or []) if ok_tr else [],
|
||||||
|
}
|
||||||
|
|
||||||
# Distintas fechas recientes en la tabla
|
# 1 recepción completa para ver si tiene COD_TARIFA o NIT_EMPRESA
|
||||||
ok5, _, rows5 = fb.execute_query(
|
ok_r, _, rec = fb.execute_query(
|
||||||
"SELECT FIRST 5 DISTINCT r.FECHA_RECEPCION FROM RECEPCION r "
|
"SELECT FIRST 1 r.* FROM RECEPCION r ORDER BY r.IDRECEPCION DESC", None
|
||||||
"ORDER BY r.FECHA_RECEPCION DESC", None
|
|
||||||
)
|
)
|
||||||
result["fechas_recientes"] = list(rows5) if ok5 and rows5 else "error"
|
result["recepcion_completa"] = dict(rec[0]) if ok_r and rec else {}
|
||||||
|
|
||||||
fb.disconnect()
|
fb.disconnect()
|
||||||
return JSONResponse(result)
|
return JSONResponse(result)
|
||||||
|
|||||||
Reference in New Issue
Block a user