-- migrate_add_booked_scrap.sql
-- Adds booking-status columns to llx_scanstation_log for Scrap Confirmation workflow.
-- NULL = pending manager review | >0 = booked (rowid in llx_scrap) | -1 = rejected
-- Run each statement separately in phpMyAdmin.
-- Ignore error 1060 (Duplicate column name) — column already added.
-- Ignore error 1061 (Duplicate key name)    — index already added.

ALTER TABLE llx_scanstation_log
  ADD COLUMN booked_scrap_id INT DEFAULT NULL
  COMMENT 'NULL=pending | >0=rowid in llx_scrap | -1=rejected';

ALTER TABLE llx_scanstation_log
  ADD COLUMN confirmation_note VARCHAR(255) DEFAULT NULL
  COMMENT 'Manager note on rejection or booking';

ALTER TABLE llx_scanstation_log
  ADD COLUMN confirmed_by INT DEFAULT NULL
  COMMENT 'fk_user who booked or rejected';

ALTER TABLE llx_scanstation_log
  ADD COLUMN confirmed_at DATETIME DEFAULT NULL
  COMMENT 'Timestamp of booking or rejection';

-- Index to speed up the pending-scrap query
ALTER TABLE llx_scanstation_log
  ADD INDEX idx_ss_log_booking (scan_type, booked_scrap_id, entity);
