-- llx_scrap_log.sql
-- =====================================================================
--  Table: llx_scrap_log
--  Description: Audit trail for scrap records (create / edit / delete)
-- =====================================================================

CREATE TABLE IF NOT EXISTS llx_scrap_log (
  rowid        INT          NOT NULL AUTO_INCREMENT,
  fk_scrap     INT          NOT NULL,                  -- references llx_scrap (no FK constraint: row may be deleted)
  action       VARCHAR(10)  NOT NULL,                  -- 'create', 'edit', 'delete'
  log_date     DATETIME     NOT NULL,
  fk_user      INT          DEFAULT NULL,
  old_qty      DOUBLE       DEFAULT NULL,
  new_qty      DOUBLE       DEFAULT NULL,
  old_cost     DOUBLE       DEFAULT NULL,
  new_cost     DOUBLE       DEFAULT NULL,
  old_reason   VARCHAR(255) DEFAULT NULL,
  new_reason   VARCHAR(255) DEFAULT NULL,
  old_date     DATETIME     DEFAULT NULL,
  new_date     DATETIME     DEFAULT NULL,
  entity       INT          DEFAULT 1,
  PRIMARY KEY (rowid),
  KEY idx_scrap_log_fk_scrap (fk_scrap),
  KEY idx_scrap_log_entity   (entity),
  KEY idx_scrap_log_user     (fk_user)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
