import pandas as pd
df = pd.read_excel(r'C:\Users\Claudio\AppData\Local\Temp\dre_copia.xlsx', sheet_name='Planilha1')
date_cols = [c for c in df.columns if hasattr(c, 'year') and 2021 <= c.year <= 2025]

# CAIXA subcontas
mask = df['Conta'].astype(str).str.strip().str.upper() == 'CAIXA'
print("=== CAIXA ===")
for idx, row in df[mask].iterrows():
    total = row[date_cols].apply(pd.to_numeric, errors='coerce').fillna(0).sum()
    sub = str(row['SubConta']).strip()
    print(repr(sub), f"Total={total:,.0f}")

# FATURAMENTO BRUTO row 87
print("\n=== FATURAMENTO BRUTO (row 87) por ano ===")
row87 = df.iloc[87]
for a in [2021,2022,2023,2024,2025]:
    cols_ano = [c for c in date_cols if c.year == a]
    total = row87[cols_ano].apply(pd.to_numeric, errors='coerce').fillna(0).sum()
    print(f"  {a}: {total:,.0f}")

print("\n=== CMV row 91 por ano ===")
row91 = df.iloc[91]
for a in [2021,2022,2023,2024,2025]:
    cols_ano = [c for c in date_cols if c.year == a]
    total = row91[cols_ano].apply(pd.to_numeric, errors='coerce').fillna(0).sum()
    print(f"  {a}: {total:,.0f}")

# DAS tributario
print("\n=== DAS por ano ===")
mask_das = (df['Conta'].astype(str).str.strip().str.upper() == 'DESPESAS FIXAS/TRIBUTARIAS') & \
           (df['SubConta'].astype(str).str.strip().str.upper() == 'DAS')
row_das = df[mask_das]
for a in [2021,2022,2023,2024,2025]:
    cols_ano = [c for c in date_cols if c.year == a]
    total = row_das[cols_ano].apply(pd.to_numeric, errors='coerce').fillna(0).sum().sum()
    print(f"  {a}: {total:,.0f}")
