import psycopg2

conn = psycopg2.connect(
    host="192.168.0.61",
    port=55432,
    database="njts_acct",
    user="njts_app",
    password="njts_app2025"
)

cur = conn.cursor()

print("=" * 140)
print("【accountsテーブルの account_type 一覧】")
print("=" * 140)

# 查询所有不同的account_type
cur.execute("""
    SELECT DISTINCT account_type
    FROM accounts
    ORDER BY account_type
""")

types = cur.fetchall()
print(f"\n見つかった account_type:\n")
for (acc_type,) in types:
    print(f"  - '{acc_type}'")

# 再查询所有资产相关的科目
print("\n" + "=" * 140)
print("【資産関連と思われる科目】")
print("=" * 140)

cur.execute("""
    SELECT 
        account_id,
        account_code,
        account_name,
        account_type
    FROM accounts
    WHERE account_type LIKE '%資%' OR account_type LIKE '%Asset%' OR account_code < '200'
    ORDER BY account_code
""")

all_accounts = cur.fetchall()
print(f"\n見つかった科目数: {len(all_accounts)}\n")

for account_id, code, name, acc_type in all_accounts:
    print(f"{code:>4} | {name:25} | {acc_type:15}")

cur.close()
conn.close()
