"""Check the exact loan 18112026-000012 status"""
import pymysql

DB_CONFIG = {
    'host': 'localhost',
    'port': 3306,
    'db': 'xygbfpsg_loans',
    'user': 'xygbfpsg_graz',
    'password': 'j.ez-xy6##y.rllB',
    'charset': 'utf8mb4'
}

conn = pymysql.connect(**DB_CONFIG)

with conn.cursor() as cur:
    # Check this specific loan
    cur.execute("""
        SELECT loan_number, status, is_rolled_over, is_deleted
        FROM loans
        WHERE loan_number = '18112026-000012'
    """)
    row = cur.fetchone()
    
    if row:
        loan_num, status, is_rolled, is_deleted = row
        print(f"Loan 18112026-000012 found!")
        print(f"  loan_number: {loan_num}")
        print(f"  status: '{status}'")
        print(f"  is_rolled_over: {is_rolled}")
        print(f"  is_deleted: {is_deleted}")
        print()
        
        # Check old template logic (what's currently on server)
        old_logic = status in ('active', 'rolled_over')
        print(f"OLD template logic (status == 'active' or status == 'rolled_over'):")
        print(f"  Button shows: {old_logic}")
        print()
        
        # Check new template logic (what should work)
        new_logic = status in ('active', 'rolled_over') or is_rolled
        print(f"NEW template logic (status == 'active' or status == 'rolled_over' or is_rolled_over):")
        print(f"  Button shows: {new_logic}")
        print()
        
        if not old_logic:
            print(f"❌ OLD logic FAILS because:")
            print(f"   status is '{status}' (not 'active' or 'rolled_over')")
        else:
            print(f"✅ OLD logic should work!")
            
        if not new_logic:
            print(f"❌ NEW logic FAILS")
        else:
            print(f"✅ NEW logic works!")
    else:
        print("❌ Loan 18112026-000012 NOT FOUND in database!")
        print("\nSearching for similar loan numbers...")
        cur.execute("""
            SELECT loan_number, status, is_rolled_over, is_deleted
            FROM loans
            WHERE loan_number LIKE '%18112026%' OR loan_number LIKE '%000012%'
        """)
        rows = cur.fetchall()
        if rows:
            print(f"Found {len(rows)} similar loans:")
            for row in rows:
                print(f"  {row[0]} - status: '{row[1]}', rolled: {row[2]}, deleted: {row[3]}")
        else:
            print("No similar loans found")

conn.close()
