-- =========================================================================
-- IMPORT DATA JUN 2026 — 6 syarikat yang sebelum ini dilangkau (kini
-- ditambah ke sistem sebagai entiti Investment Holding/Commercial).
-- Jalankan SELEPAS migration_add_mbi_holding_and_excluded_companies.sql
-- (syarikat mesti wujud dalam jadual subsidiaries dahulu).
-- Sumber & kaedah SAMA seperti import_june_2026_actuals.sql sebelum ini
-- (disahkan silang dengan baris TOTAL rasmi dalam Excel).
-- =========================================================================

INSERT INTO financial_records (record_id, subsidiary_id, line_item_id, fiscal_year, month, period_type, value_type, amount_rm000, status)
SELECT UUID(), s.subsidiary_id, li.line_item_id, 2026, 6, 'MONTHLY', 'ACTUAL', v.amount, 'approved'
FROM (
    SELECT 'MBI' AS code, 'Revenue' AS label, 43086.83 AS amount
    UNION ALL
    SELECT 'MBI' AS code, 'Cost of Sales' AS label, 8012.82 AS amount
    UNION ALL
    SELECT 'MBI' AS code, 'Gross Profit' AS label, 35074.01 AS amount
    UNION ALL
    SELECT 'MBI' AS code, 'EBITDA' AS label, -37558.09 AS amount
    UNION ALL
    SELECT 'MBI' AS code, 'PBT/(LBT)' AS label, -40084.33 AS amount
    UNION ALL
    SELECT 'MBI' AS code, 'PAT/(LAT)' AS label, -47295.83 AS amount
    UNION ALL
    SELECT 'DEIGB' AS code, 'Revenue' AS label, 439702.66 AS amount
    UNION ALL
    SELECT 'DEIGB' AS code, 'Cost of Sales' AS label, 358911.79 AS amount
    UNION ALL
    SELECT 'DEIGB' AS code, 'Gross Profit' AS label, 80790.86 AS amount
    UNION ALL
    SELECT 'DEIGB' AS code, 'EBITDA' AS label, 26605.33 AS amount
    UNION ALL
    SELECT 'DEIGB' AS code, 'PBT/(LBT)' AS label, 30640.91 AS amount
    UNION ALL
    SELECT 'DEIGB' AS code, 'PAT/(LAT)' AS label, 19682.76 AS amount
    UNION ALL
    SELECT 'MANTAPMURNI' AS code, 'Revenue' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'MANTAPMURNI' AS code, 'Cost of Sales' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'MANTAPMURNI' AS code, 'Gross Profit' AS label, 2808.1 AS amount
    UNION ALL
    SELECT 'MANTAPMURNI' AS code, 'EBITDA' AS label, 2229.99 AS amount
    UNION ALL
    SELECT 'MANTAPMURNI' AS code, 'PBT/(LBT)' AS label, -778.11 AS amount
    UNION ALL
    SELECT 'MANTAPMURNI' AS code, 'PAT/(LAT)' AS label, -778.11 AS amount
    UNION ALL
    SELECT 'FINTECH' AS code, 'Revenue' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'FINTECH' AS code, 'Cost of Sales' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'FINTECH' AS code, 'Gross Profit' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'FINTECH' AS code, 'EBITDA' AS label, -1.26 AS amount
    UNION ALL
    SELECT 'FINTECH' AS code, 'PBT/(LBT)' AS label, -1.44 AS amount
    UNION ALL
    SELECT 'FINTECH' AS code, 'PAT/(LAT)' AS label, -1.44 AS amount
    UNION ALL
    SELECT 'E-WALLET' AS code, 'Revenue' AS label, 20.17 AS amount
    UNION ALL
    SELECT 'E-WALLET' AS code, 'Cost of Sales' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'E-WALLET' AS code, 'Gross Profit' AS label, 20.17 AS amount
    UNION ALL
    SELECT 'E-WALLET' AS code, 'EBITDA' AS label, -172.17 AS amount
    UNION ALL
    SELECT 'E-WALLET' AS code, 'PBT/(LBT)' AS label, -3212.71 AS amount
    UNION ALL
    SELECT 'E-WALLET' AS code, 'PAT/(LAT)' AS label, -3212.71 AS amount
    UNION ALL
    SELECT 'DSA' AS code, 'Revenue' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'DSA' AS code, 'Cost of Sales' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'DSA' AS code, 'Gross Profit' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'DSA' AS code, 'EBITDA' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'DSA' AS code, 'PBT/(LBT)' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'DSA' AS code, 'PAT/(LAT)' AS label, 0.0 AS amount
) v
JOIN subsidiaries s ON s.code = v.code
JOIN financial_line_items li ON li.label = v.label
ON DUPLICATE KEY UPDATE amount_rm000 = VALUES(amount_rm000);