-- Planning Capacity Override — per-day available hours override per workstation
-- One row = "On date D, workstation W has N available hours (overrides weekday default)"
-- Example uses: bank holiday (0h), overtime day (16h), shutdown week
-- PHASE 2 — created 2026-03-27

SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS llx_planning_capacity_override (
    rowid           INT UNSIGNED NOT NULL AUTO_INCREMENT,
    fk_ws           INT UNSIGNED NOT NULL,              -- llx_workstation_workstation.rowid
    override_date   DATE NOT NULL,                      -- the specific calendar date
    available_hours DECIMAL(4,1) NOT NULL,              -- 0 = closed, 8 = short, 12 = full
    note            VARCHAR(100) NULL,                  -- e.g. "Bank Holiday", "Overtime"
    fk_user         INT UNSIGNED NULL,                  -- who set the override
    entity          INT NOT NULL DEFAULT 1,
    tms             TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,

    PRIMARY KEY (rowid),
    UNIQUE KEY uq_cap_ovr_ws_date (fk_ws, override_date, entity),
    KEY idx_cap_ovr_entity   (entity),
    KEY idx_cap_ovr_ws       (entity, fk_ws),
    KEY idx_cap_ovr_date     (entity, fk_ws, override_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
