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("=" * 100)
print("ID 445 データ復元処理")
print("=" * 100)

# ID 445を再に入力
# journal_entries の INSERT
cur.execute("""
    INSERT INTO journal_entries (
        journal_entry_id,
        entry_date,
        description,
        fiscal_year,
        revision_count,
        is_latest,
        is_deleted,
        created_at,
        created_by
    ) VALUES (
        445,
        '2025-06-30',
        '遠達ビル 事務所費用',
        2025,
        1,
        TRUE,
        FALSE,
        NOW(),
        'system'
    )
""")

print(f"✓ journal_entries 插入: ID 445")

# journal_lines の INSERT
lines_data = [
    (445, 36, 154546.00, 0),      # 地代家賃
    (445, 2, 0, 170660.00),       # 普通預金
    (445, 7, 15454.00, 0),        # 仮払金  
    (445, 38, 660.00, 0)          # 支払手数料
]

for entry_id, account_id, debit, credit in lines_data:
    cur.execute("""
        INSERT INTO journal_lines (journal_entry_id, account_id, debit, credit)
        VALUES (%s, %s, %s, %s)
    """, (entry_id, account_id, debit, credit))

print(f"✓ journal_lines 插入: 4行")

conn.commit()

print("\n✅ ID 445 復元完了！")

cur.close()
conn.close()
