-- llx_guillotine_pack.sql
-- =====================================================================
--  Table: llx_guillotine_pack
--  Description: Incoming material packs received before guillotine cutting.
--  Note: No DROP TABLE — safe to run on re-enable without data loss.
-- =====================================================================

CREATE TABLE IF NOT EXISTS llx_guillotine_pack (
  rowid          INT           NOT NULL AUTO_INCREMENT,
  ref            VARCHAR(64)   NOT NULL,
  fk_product     INT           NOT NULL COMMENT 'FK to llx_product',
  fk_lot         INT           DEFAULT NULL COMMENT 'FK to llx_product_lot',
  qty_received   DOUBLE        NOT NULL DEFAULT 0,
  qty_remaining  DOUBLE        NOT NULL DEFAULT 0,
  date_received  DATETIME      NOT NULL,
  fk_user        INT           DEFAULT NULL COMMENT 'User who received the pack',
  note           TEXT          DEFAULT NULL,
  status         TINYINT       NOT NULL DEFAULT 0 COMMENT '0=draft,1=open,2=closed',
  entity         INT           NOT NULL DEFAULT 1,
  tms            TIMESTAMP     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (rowid),
  UNIQUE KEY uk_guillotine_pack_ref (ref, entity),
  KEY idx_guillotine_pack_entity    (entity),
  KEY idx_guillotine_pack_product   (fk_product),
  KEY idx_guillotine_pack_lot       (fk_lot),
  KEY idx_guillotine_pack_status    (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
