import warnings; warnings.filterwarnings('ignore')
import sys; sys.path.insert(0, '.')
from app.core.database import engine
from sqlalchemy import text

with engine.connect() as conn:
    print("=== FISCAL YEARS ===")
    r = conn.execute(text("SELECT id, year_name, start_date, end_date, status, is_active FROM fiscal_years ORDER BY start_date"))
    for row in r:
        print(f"  {row[1]} | {row[2]} - {row[3]} | status={row[4]} | active={row[5]} | id={row[0]}")

    print()
    print("=== ALL PERIODS ===")
    r2 = conn.execute(text("""
        SELECT fp.period_name, fp.start_date, fp.end_date, fp.status, fy.year_name
        FROM fiscal_periods fp
        JOIN fiscal_years fy ON fy.id = fp.fiscal_year_id
        ORDER BY fp.start_date
    """))
    for row in r2:
        today_marker = " <-- TODAY" if str(row[1]) <= "2026-03-05" <= str(row[2]) else ""
        print(f"  {row[4]} | {row[0]} | {row[1]}-{row[2]} | {row[3]}{today_marker}")
