-- 140_formula_registry.sql — registry rumus Calculation Engine (Sprint 4, WP-4A)
--
-- SUMBER KEBENARAN urutan & aktivasi rumus. Tambah rumus = 1 class App\Formula\* + 1 baris di sini.
-- formula_code di bawah ADALAH kode yang WAJIB dikembalikan FormulaInterface::code() dan yang
-- dipakai FormulaInterface::dependsOn() (dependsOn memakai formula_code, BUKAN measure_code).
--
--   formula_code | class                          | measure yang ditulis                       | aktif
--   -------------+--------------------------------+--------------------------------------------+------
--   REV_TOTAL    | App\Formula\RevenueRollup      | REV_TOTAL (ref='', m0..12), REV_DEPT        | 1
--   EXP_TOTAL    | App\Formula\ExpenseRollup      | EXP_SECTION, EXP_DEPT, EXP_TOTAL            | 1
--   GOP          | App\Formula\GopFormula         | GOP                                         | 1
--   NET          | App\Formula\NetFormula         | NET                                         | 1
--   PCT_REV      | App\Formula\CommonSizePct      | PCT_REV (month=0)                           | 1
--   QTR_SEM      | App\Formula\QuarterSemester    | QTR, SEM                                    | 1
--   ROOM_STAT    | App\Formula\RoomStatistics     | ROOM_SOLD/ROOM_OCC/ROOM_ARR/ROOM_REVPAR     | 1
--   PACE         | App\Formula\PaceFormula        | PACE — belum aktif (butuh closed-month)     | 0
--   MFEE         | App\Formula\ManagementFee      | placeholder Sprint 7/9                      | 0
--   CIT          | App\Formula\CorporateIncomeTax | placeholder Sprint 7/9                      | 0
--   BEP          | App\Formula\BreakEven          | placeholder Sprint 7/9                      | 0
--
-- calc_order = fallback/tie-break urutan eksekusi; urutan sebenarnya dari topological sort
-- dependsOn() (CalculationService). Baris is_active=0 TIDAK diinstansiasi & TIDAK menghasilkan
-- baris calc_result.
-- Catatan escaping: backslash dalam string MySQL harus digandakan ('App\\Formula\\X').
-- CalculationService juga menerima nama pendek tanpa namespace bila suatu saat dipakai.

INSERT INTO formula_registry (formula_code, class_name, calc_order, is_active) VALUES
('REV_TOTAL', 'App\\Formula\\RevenueRollup',      10, 1),
('EXP_TOTAL', 'App\\Formula\\ExpenseRollup',      20, 1),
('GOP',       'App\\Formula\\GopFormula',         30, 1),
('NET',       'App\\Formula\\NetFormula',         40, 1),
('PCT_REV',   'App\\Formula\\CommonSizePct',      50, 1),
('QTR_SEM',   'App\\Formula\\QuarterSemester',    60, 1),
('ROOM_STAT', 'App\\Formula\\RoomStatistics',     70, 1),
('PACE',      'App\\Formula\\PaceFormula',        80, 0),
('MFEE',      'App\\Formula\\ManagementFee',      90, 0),
('CIT',       'App\\Formula\\CorporateIncomeTax', 100, 0),
('BEP',       'App\\Formula\\BreakEven',          110, 0)
ON DUPLICATE KEY UPDATE
    class_name = VALUES(class_name),
    calc_order = VALUES(calc_order),
    is_active  = VALUES(is_active);
