-- 2024年度（2024年6月1日～2025年5月31日）期首残高データ
-- ★残高試算表_20250724.pdfより

-- 既存データを削除（2024年度のみ）
DELETE FROM opening_balances WHERE fiscal_year = 2024;

-- 期首残高データの挿入
INSERT INTO opening_balances (fiscal_year, account_id, opening_debit, opening_credit) VALUES
-- 現金（101）
(2024, (SELECT account_id FROM accounts WHERE account_code = '101'), 878375, 0),

-- 普通預金（102）- UFJ/0788058 として登録
(2024, (SELECT account_id FROM accounts WHERE account_code = '102'), 11246013, 0),

-- 売掛金（201）
(2024, (SELECT account_id FROM accounts WHERE account_code = '201'), 5269872, 0),

-- 仮払金（203）
(2024, (SELECT account_id FROM accounts WHERE account_code = '203'), 1284834, 0),

-- 買掛金（501）
(2024, (SELECT account_id FROM accounts WHERE account_code = '501'), 0, 9933067),

-- 未払金（502）
(2024, (SELECT account_id FROM accounts WHERE account_code = '502'), 0, 840000),

-- 未払法人税等（504）
(2024, (SELECT account_id FROM accounts WHERE account_code = '504'), 0, 94700),

-- 未払消費税等（505）
(2024, (SELECT account_id FROM accounts WHERE account_code = '505'), 0, 1498400),

-- 預り金（506）
(2024, (SELECT account_id FROM accounts WHERE account_code = '506'), 0, 61300),

-- 資本金（601）
(2024, (SELECT account_id FROM accounts WHERE account_code = '601'), 0, 6000000);

-- 繰越利益剰余金（602）は自動計算されるため入力不要

-- 確認用クエリ
SELECT 
    a.account_code,
    a.account_name,
    ob.opening_debit,
    ob.opening_credit
FROM opening_balances ob
JOIN accounts a ON ob.account_id = a.account_id
WHERE ob.fiscal_year = 2024
ORDER BY a.account_code;
