-- =========================================================================
-- IMPORT DATA SEBENAR: Financial Bulanan JUN 2026 (dari By_Company.xlsx)
-- Sumber: sheet 'CSOPL (June - A26)' — Consolidated Statement of P&L
-- 26 daripada 32 syarikat dipadankan (6 syarikat dalam Excel bukan
-- sebahagian senarai 32 rasmi -- lihat nota di bawah, DILANGKAU):
--   MBI: MBI Corporate (bukan subsidiary, entiti holding)
--   DEIGB: Darul Ehsan Investment Group Berhad (tiada dalam senarai 32 rasmi)
--   MANTAPMURNI: MantapMurni Sdn Bhd (tiada dalam senarai 32 rasmi)
--   FINTECH: Selangor Fintech Sdn Bhd (tiada dalam senarai 32 rasmi)
--   E-WALLET: Selangor E-Wallet Sdn Bhd (tiada dalam senarai 32 rasmi)
--   DSA: Dialisis Sri Andalas Sdn Bhd (tiada dalam senarai 32 rasmi)
--
-- Line item: Revenue, Cost of Sales, Gross Profit (terus dari Excel),
-- EBITDA (anggaran = Result from Operating Activities + |Depreciation|,
-- sebab Excel tiada baris EBITDA eksplisit), PBT/(LBT), PAT/(LAT) (terus).
-- Unit ditukar daripada RM sebenar -> RM'000 (bahagi 1000) sepadan sistem.
--
-- Jalankan di phpMyAdmin > tab SQL. Guna ON DUPLICATE KEY UPDATE — selamat
-- dijalankan berulang kali, dan TIDAK timpa data Suku Tahun/FY sedia ada
-- (period_type='MONTHLY' berasingan sepenuhnya daripada 'YTD'/'FY').
-- =========================================================================

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 'AISHOLDINGS' AS code, 'Revenue' AS label, 1802334.45 AS amount
    UNION ALL
    SELECT 'AISHOLDINGS' AS code, 'Cost of Sales' AS label, 616509.55 AS amount
    UNION ALL
    SELECT 'AISHOLDINGS' AS code, 'Gross Profit' AS label, 1185824.91 AS amount
    UNION ALL
    SELECT 'AISHOLDINGS' AS code, 'EBITDA' AS label, 1157464.97 AS amount
    UNION ALL
    SELECT 'AISHOLDINGS' AS code, 'PBT/(LBT)' AS label, 366279.04 AS amount
    UNION ALL
    SELECT 'AISHOLDINGS' AS code, 'PAT/(LAT)' AS label, 360671.83 AS amount
    UNION ALL
    SELECT 'PNSB' AS code, 'Revenue' AS label, 145432.14 AS amount
    UNION ALL
    SELECT 'PNSB' AS code, 'Cost of Sales' AS label, 5419.34 AS amount
    UNION ALL
    SELECT 'PNSB' AS code, 'Gross Profit' AS label, 140012.8 AS amount
    UNION ALL
    SELECT 'PNSB' AS code, 'EBITDA' AS label, 120735.32 AS amount
    UNION ALL
    SELECT 'PNSB' AS code, 'PBT/(LBT)' AS label, 120309.73 AS amount
    UNION ALL
    SELECT 'PNSB' AS code, 'PAT/(LAT)' AS label, 113572.24 AS amount
    UNION ALL
    SELECT 'UNISEL' AS code, 'Revenue' AS label, 25318.78 AS amount
    UNION ALL
    SELECT 'UNISEL' AS code, 'Cost of Sales' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'UNISEL' AS code, 'Gross Profit' AS label, 25666.56 AS amount
    UNION ALL
    SELECT 'UNISEL' AS code, 'EBITDA' AS label, -9173.81 AS amount
    UNION ALL
    SELECT 'UNISEL' AS code, 'PBT/(LBT)' AS label, -24607.12 AS amount
    UNION ALL
    SELECT 'UNISEL' AS code, 'PAT/(LAT)' AS label, -24607.12 AS amount
    UNION ALL
    SELECT 'BBGC' AS code, 'Revenue' AS label, 2290.8 AS amount
    UNION ALL
    SELECT 'BBGC' AS code, 'Cost of Sales' AS label, 1041.97 AS amount
    UNION ALL
    SELECT 'BBGC' AS code, 'Gross Profit' AS label, 1248.83 AS amount
    UNION ALL
    SELECT 'BBGC' AS code, 'EBITDA' AS label, -842.74 AS amount
    UNION ALL
    SELECT 'BBGC' AS code, 'PBT/(LBT)' AS label, -1349.3 AS amount
    UNION ALL
    SELECT 'BBGC' AS code, 'PAT/(LAT)' AS label, -1462.07 AS amount
    UNION ALL
    SELECT 'KSSB' AS code, 'Revenue' AS label, 147435.17 AS amount
    UNION ALL
    SELECT 'KSSB' AS code, 'Cost of Sales' AS label, 122133.11 AS amount
    UNION ALL
    SELECT 'KSSB' AS code, 'Gross Profit' AS label, 25302.06 AS amount
    UNION ALL
    SELECT 'KSSB' AS code, 'EBITDA' AS label, 5022.21 AS amount
    UNION ALL
    SELECT 'KSSB' AS code, 'PBT/(LBT)' AS label, 2700.22 AS amount
    UNION ALL
    SELECT 'KSSB' AS code, 'PAT/(LAT)' AS label, 1971.49 AS amount
    UNION ALL
    SELECT 'TSSB' AS code, 'Revenue' AS label, 6820.99 AS amount
    UNION ALL
    SELECT 'TSSB' AS code, 'Cost of Sales' AS label, 4571.1 AS amount
    UNION ALL
    SELECT 'TSSB' AS code, 'Gross Profit' AS label, 2249.89 AS amount
    UNION ALL
    SELECT 'TSSB' AS code, 'EBITDA' AS label, -300.39 AS amount
    UNION ALL
    SELECT 'TSSB' AS code, 'PBT/(LBT)' AS label, -367.29 AS amount
    UNION ALL
    SELECT 'TSSB' AS code, 'PAT/(LAT)' AS label, -380.04 AS amount
    UNION ALL
    SELECT 'RMSB' AS code, 'Revenue' AS label, 41554.0 AS amount
    UNION ALL
    SELECT 'RMSB' AS code, 'Cost of Sales' AS label, 39451.0 AS amount
    UNION ALL
    SELECT 'RMSB' AS code, 'Gross Profit' AS label, 2106.0 AS amount
    UNION ALL
    SELECT 'RMSB' AS code, 'EBITDA' AS label, 770.0 AS amount
    UNION ALL
    SELECT 'RMSB' AS code, 'PBT/(LBT)' AS label, 766.0 AS amount
    UNION ALL
    SELECT 'RMSB' AS code, 'PAT/(LAT)' AS label, 582.0 AS amount
    UNION ALL
    SELECT 'ISB' AS code, 'Revenue' AS label, 1751.46 AS amount
    UNION ALL
    SELECT 'ISB' AS code, 'Cost of Sales' AS label, 5876.2 AS amount
    UNION ALL
    SELECT 'ISB' AS code, 'Gross Profit' AS label, 6232.65 AS amount
    UNION ALL
    SELECT 'ISB' AS code, 'EBITDA' AS label, -361.28 AS amount
    UNION ALL
    SELECT 'ISB' AS code, 'PBT/(LBT)' AS label, -466.35 AS amount
    UNION ALL
    SELECT 'ISB' AS code, 'PAT/(LAT)' AS label, -466.35 AS amount
    UNION ALL
    SELECT 'SIDEC' AS code, 'Revenue' AS label, 10638.94 AS amount
    UNION ALL
    SELECT 'SIDEC' AS code, 'Cost of Sales' AS label, 7437.55 AS amount
    UNION ALL
    SELECT 'SIDEC' AS code, 'Gross Profit' AS label, 5574.31 AS amount
    UNION ALL
    SELECT 'SIDEC' AS code, 'EBITDA' AS label, 3091.51 AS amount
    UNION ALL
    SELECT 'SIDEC' AS code, 'PBT/(LBT)' AS label, 100.09 AS amount
    UNION ALL
    SELECT 'SIDEC' AS code, 'PAT/(LAT)' AS label, 13.39 AS amount
    UNION ALL
    SELECT 'MSSB' AS code, 'Revenue' AS label, 2147.84 AS amount
    UNION ALL
    SELECT 'MSSB' AS code, 'Cost of Sales' AS label, 9541.12 AS amount
    UNION ALL
    SELECT 'MSSB' AS code, 'Gross Profit' AS label, 2989.4 AS amount
    UNION ALL
    SELECT 'MSSB' AS code, 'EBITDA' AS label, 743.7 AS amount
    UNION ALL
    SELECT 'MSSB' AS code, 'PBT/(LBT)' AS label, 436.39 AS amount
    UNION ALL
    SELECT 'MSSB' AS code, 'PAT/(LAT)' AS label, 435.27 AS amount
    UNION ALL
    SELECT 'DEFM' AS code, 'Revenue' AS label, 36271.3 AS amount
    UNION ALL
    SELECT 'DEFM' AS code, 'Cost of Sales' AS label, 35206.78 AS amount
    UNION ALL
    SELECT 'DEFM' AS code, 'Gross Profit' AS label, 1064.52 AS amount
    UNION ALL
    SELECT 'DEFM' AS code, 'EBITDA' AS label, -1001.69 AS amount
    UNION ALL
    SELECT 'DEFM' AS code, 'PBT/(LBT)' AS label, -1154.83 AS amount
    UNION ALL
    SELECT 'DEFM' AS code, 'PAT/(LAT)' AS label, -1154.83 AS amount
    UNION ALL
    SELECT 'INPEN_STDC' AS code, 'Revenue' AS label, 3767.45 AS amount
    UNION ALL
    SELECT 'INPEN_STDC' AS code, 'Cost of Sales' AS label, 1651.23 AS amount
    UNION ALL
    SELECT 'INPEN_STDC' AS code, 'Gross Profit' AS label, 2116.22 AS amount
    UNION ALL
    SELECT 'INPEN_STDC' AS code, 'EBITDA' AS label, 332.41 AS amount
    UNION ALL
    SELECT 'INPEN_STDC' AS code, 'PBT/(LBT)' AS label, -934.01 AS amount
    UNION ALL
    SELECT 'INPEN_STDC' AS code, 'PAT/(LAT)' AS label, -934.01 AS amount
    UNION ALL
    SELECT 'KPS' AS code, 'Revenue' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'KPS' AS code, 'Cost of Sales' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'KPS' AS code, 'Gross Profit' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'KPS' AS code, 'EBITDA' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'KPS' AS code, 'PBT/(LBT)' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'KPS' AS code, 'PAT/(LAT)' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'AIRLESTARI' AS code, 'Revenue' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'AIRLESTARI' AS code, 'Cost of Sales' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'AIRLESTARI' AS code, 'Gross Profit' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'AIRLESTARI' AS code, 'EBITDA' AS label, -781.6 AS amount
    UNION ALL
    SELECT 'AIRLESTARI' AS code, 'PBT/(LBT)' AS label, -781.6 AS amount
    UNION ALL
    SELECT 'AIRLESTARI' AS code, 'PAT/(LAT)' AS label, -781.6 AS amount
    UNION ALL
    SELECT 'LLSB' AS code, 'Revenue' AS label, 14113.93 AS amount
    UNION ALL
    SELECT 'LLSB' AS code, 'Cost of Sales' AS label, 8823.18 AS amount
    UNION ALL
    SELECT 'LLSB' AS code, 'Gross Profit' AS label, 5290.75 AS amount
    UNION ALL
    SELECT 'LLSB' AS code, 'EBITDA' AS label, 1959.19 AS amount
    UNION ALL
    SELECT 'LLSB' AS code, 'PBT/(LBT)' AS label, 1950.46 AS amount
    UNION ALL
    SELECT 'LLSB' AS code, 'PAT/(LAT)' AS label, 1950.46 AS amount
    UNION ALL
    SELECT 'KHSB' AS code, 'Revenue' AS label, 60126.22 AS amount
    UNION ALL
    SELECT 'KHSB' AS code, 'Cost of Sales' AS label, 40253.57 AS amount
    UNION ALL
    SELECT 'KHSB' AS code, 'Gross Profit' AS label, 19872.65 AS amount
    UNION ALL
    SELECT 'KHSB' AS code, 'EBITDA' AS label, 6188.63 AS amount
    UNION ALL
    SELECT 'KHSB' AS code, 'PBT/(LBT)' AS label, 3078.68 AS amount
    UNION ALL
    SELECT 'KHSB' AS code, 'PAT/(LAT)' AS label, 572.9 AS amount
    UNION ALL
    SELECT 'KDEBWM' AS code, 'Revenue' AS label, 324113.18 AS amount
    UNION ALL
    SELECT 'KDEBWM' AS code, 'Cost of Sales' AS label, 296319.9 AS amount
    UNION ALL
    SELECT 'KDEBWM' AS code, 'Gross Profit' AS label, 27793.28 AS amount
    UNION ALL
    SELECT 'KDEBWM' AS code, 'EBITDA' AS label, 12827.6 AS amount
    UNION ALL
    SELECT 'KDEBWM' AS code, 'PBT/(LBT)' AS label, 6079.02 AS amount
    UNION ALL
    SELECT 'KDEBWM' AS code, 'PAT/(LAT)' AS label, 4377.0 AS amount
    UNION ALL
    SELECT 'SSDU' AS code, 'Revenue' AS label, 1406.0 AS amount
    UNION ALL
    SELECT 'SSDU' AS code, 'Cost of Sales' AS label, 2518.0 AS amount
    UNION ALL
    SELECT 'SSDU' AS code, 'Gross Profit' AS label, -74.0 AS amount
    UNION ALL
    SELECT 'SSDU' AS code, 'EBITDA' AS label, -2013.0 AS amount
    UNION ALL
    SELECT 'SSDU' AS code, 'PBT/(LBT)' AS label, -3357.0 AS amount
    UNION ALL
    SELECT 'SSDU' AS code, 'PAT/(LAT)' AS label, -3357.0 AS amount
    UNION ALL
    SELECT 'KUSEL' AS code, 'Revenue' AS label, 31291.41 AS amount
    UNION ALL
    SELECT 'KUSEL' AS code, 'Cost of Sales' AS label, 20969.66 AS amount
    UNION ALL
    SELECT 'KUSEL' AS code, 'Gross Profit' AS label, 10321.75 AS amount
    UNION ALL
    SELECT 'KUSEL' AS code, 'EBITDA' AS label, 4509.53 AS amount
    UNION ALL
    SELECT 'KUSEL' AS code, 'PBT/(LBT)' AS label, 3689.74 AS amount
    UNION ALL
    SELECT 'KUSEL' AS code, 'PAT/(LAT)' AS label, 1977.26 AS amount
    UNION ALL
    SELECT 'SELATI' AS code, 'Revenue' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'SELATI' AS code, 'Cost of Sales' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'SELATI' AS code, 'Gross Profit' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'SELATI' AS code, 'EBITDA' AS label, -16.94 AS amount
    UNION ALL
    SELECT 'SELATI' AS code, 'PBT/(LBT)' AS label, -41.24 AS amount
    UNION ALL
    SELECT 'SELATI' AS code, 'PAT/(LAT)' AS label, -41.24 AS amount
    UNION ALL
    SELECT 'WBS' AS code, 'Revenue' AS label, 3650.79 AS amount
    UNION ALL
    SELECT 'WBS' AS code, 'Cost of Sales' AS label, 2022.31 AS amount
    UNION ALL
    SELECT 'WBS' AS code, 'Gross Profit' AS label, 1628.48 AS amount
    UNION ALL
    SELECT 'WBS' AS code, 'EBITDA' AS label, 152.56 AS amount
    UNION ALL
    SELECT 'WBS' AS code, 'PBT/(LBT)' AS label, -9.62 AS amount
    UNION ALL
    SELECT 'WBS' AS code, 'PAT/(LAT)' AS label, -10.81 AS amount
    UNION ALL
    SELECT 'HIS' AS code, 'Revenue' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'HIS' AS code, 'Cost of Sales' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'HIS' AS code, 'Gross Profit' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'HIS' AS code, 'EBITDA' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'HIS' AS code, 'PBT/(LBT)' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'HIS' AS code, 'PAT/(LAT)' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'SMARTSEL' AS code, 'Revenue' AS label, 5654.08 AS amount
    UNION ALL
    SELECT 'SMARTSEL' AS code, 'Cost of Sales' AS label, 5555.84 AS amount
    UNION ALL
    SELECT 'SMARTSEL' AS code, 'Gross Profit' AS label, 98.24 AS amount
    UNION ALL
    SELECT 'SMARTSEL' AS code, 'EBITDA' AS label, -1582.39 AS amount
    UNION ALL
    SELECT 'SMARTSEL' AS code, 'PBT/(LBT)' AS label, -1704.55 AS amount
    UNION ALL
    SELECT 'SMARTSEL' AS code, 'PAT/(LAT)' AS label, -1704.55 AS amount
    UNION ALL
    SELECT 'YAWAS' AS code, 'Revenue' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'YAWAS' AS code, 'Cost of Sales' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'YAWAS' AS code, 'Gross Profit' AS label, 2471.6 AS amount
    UNION ALL
    SELECT 'YAWAS' AS code, 'EBITDA' AS label, 570.02 AS amount
    UNION ALL
    SELECT 'YAWAS' AS code, 'PBT/(LBT)' AS label, 403.7 AS amount
    UNION ALL
    SELECT 'YAWAS' AS code, 'PAT/(LAT)' AS label, 256.65 AS amount
    UNION ALL
    SELECT 'HIJRAH' AS code, 'Revenue' AS label, 7739.46 AS amount
    UNION ALL
    SELECT 'HIJRAH' AS code, 'Cost of Sales' AS label, 0.0 AS amount
    UNION ALL
    SELECT 'HIJRAH' AS code, 'Gross Profit' AS label, 7739.46 AS amount
    UNION ALL
    SELECT 'HIJRAH' AS code, 'EBITDA' AS label, 1248.03 AS amount
    UNION ALL
    SELECT 'HIJRAH' AS code, 'PBT/(LBT)' AS label, 941.04 AS amount
    UNION ALL
    SELECT 'HIJRAH' AS code, 'PAT/(LAT)' AS label, 815.04 AS amount
    UNION ALL
    SELECT 'YANIS' AS code, 'Revenue' AS label, 11.12 AS amount
    UNION ALL
    SELECT 'YANIS' AS code, 'Cost of Sales' AS label, 546.1 AS amount
    UNION ALL
    SELECT 'YANIS' AS code, 'Gross Profit' AS label, 3602.76 AS amount
    UNION ALL
    SELECT 'YANIS' AS code, 'EBITDA' AS label, 1970.26 AS amount
    UNION ALL
    SELECT 'YANIS' AS code, 'PBT/(LBT)' AS label, 1895.41 AS amount
    UNION ALL
    SELECT 'YANIS' AS code, 'PAT/(LAT)' AS label, 1895.37 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);