-- Copyright (C) 2026 Marcin Flaumenhaft
-- ScanStation module — per-piece job tracking table
-- Each CONFIRM and SCRAP stamps a sequential piece_num per MO

CREATE TABLE IF NOT EXISTS llx_scanstation_job_tracking (
    rowid      INT AUTO_INCREMENT PRIMARY KEY,
    fk_mo      INT NOT NULL,
    fk_log     INT NOT NULL,
    piece_num  INT NOT NULL,
    scan_type  VARCHAR(20) NOT NULL DEFAULT 'confirm',
    fk_ws      INT,
    op_rank    INT,
    qty        DECIMAL(10,2) NOT NULL DEFAULT 1,
    fk_user    INT,
    date_stamp DATETIME NOT NULL,
    entity     INT NOT NULL DEFAULT 1,
    INDEX idx_ss_jt_fk_mo         (fk_mo),
    INDEX idx_ss_jt_fk_log        (fk_log),
    INDEX idx_ss_jt_entity        (entity),
    INDEX idx_ss_jt_mo_type       (fk_mo, scan_type),
    INDEX idx_ss_jt_mo_user_date  (fk_mo, fk_user, date_stamp)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
