import sys
sys.path.insert(0, '/app')

from app.core.database import get_connection

print("=" * 80)
print("【所有账户和小口現金/未払金 相关账户查询】")
print("=" * 80)

with get_connection() as conn:
    with conn.cursor() as cur:
        # 查找包含"小口"或"現金"的科目
        print("\n【小口現金 相关账户】")
        cur.execute("""
            SELECT account_id, account_code, account_name, account_type
            FROM accounts
            WHERE account_name LIKE '%小口%' OR account_name LIKE '%現金%'
            ORDER BY account_id
        """)
        
        cash_accounts = cur.fetchall()
        if cash_accounts:
            for acc in cash_accounts:
                print(f"  • ID {acc['account_id']}: {acc['account_code']} {acc['account_name']} ({acc['account_type']})")
        else:
            print("  (该类账户未找到)")

        # 查找包含"未払"或"应"的科目
        print("\n【未払金/应付类账户】")
        cur.execute("""
            SELECT account_id, account_code, account_name, account_type
            FROM accounts
            WHERE account_name LIKE '%未払%' OR account_name LIKE '%応%' OR account_code = '502'
            ORDER BY account_id
        """)
        
        payable_accounts = cur.fetchall()
        if payable_accounts:
            for acc in payable_accounts:
                print(f"  • ID {acc['account_id']}: {acc['account_code']} {acc['account_name']} ({acc['account_type']})")
        else:
            print("  (该类账户未找到)")

        # 所有的账户列表
        print("\n【所有账户列表】")
        cur.execute("""
            SELECT account_id, account_code, account_name
            FROM accounts
            ORDER BY account_id
            LIMIT 30
        """)
        
        all_accounts = cur.fetchall()
        for acc in all_accounts:
            print(f"  • ID {acc['account_id']}: {acc['account_code']} {acc['account_name']}")

print("\n" + "=" * 80)
