-- llx_guillotine_cut.sql
-- =====================================================================
--  Table: llx_guillotine_cut
--  Description: Cut jobs performed on a guillotine machine.
--  status: 0=planned, 1=confirmed
--  On confirmation: qty_in deducted from pack.qty_remaining; pieces created.
-- =====================================================================

CREATE TABLE IF NOT EXISTS llx_guillotine_cut (
  rowid          INT           NOT NULL AUTO_INCREMENT,
  ref            VARCHAR(64)   NOT NULL,
  fk_pack        INT           NOT NULL COMMENT 'FK to llx_guillotine_pack',
  fk_mo          INT           DEFAULT NULL COMMENT 'Target MO (informational)',
  qty_in         DOUBLE        NOT NULL DEFAULT 0 COMMENT 'Material quantity consumed from pack',
  qty_pieces     INT           NOT NULL DEFAULT 0 COMMENT 'Number of pieces produced',
  qty_waste      DOUBLE        NOT NULL DEFAULT 0 COMMENT 'Offcut / waste quantity',
  target_width   DOUBLE        DEFAULT NULL COMMENT 'Target width (mm)',
  target_length  DOUBLE        DEFAULT NULL COMMENT 'Target length (mm)',
  date_cut       DATETIME      DEFAULT NULL,
  fk_user        INT           DEFAULT NULL COMMENT 'Operator who performed cut',
  fk_ws          INT           DEFAULT NULL COMMENT 'FK to llx_workstation_workstation (optional)',
  note           TEXT          DEFAULT NULL,
  status         TINYINT       NOT NULL DEFAULT 0 COMMENT '0=planned,1=confirmed',
  entity         INT           NOT NULL DEFAULT 1,
  tms            TIMESTAMP     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (rowid),
  UNIQUE KEY uk_guillotine_cut_ref (ref, entity),
  KEY idx_guillotine_cut_entity  (entity),
  KEY idx_guillotine_cut_pack    (fk_pack),
  KEY idx_guillotine_cut_mo      (fk_mo),
  KEY idx_guillotine_cut_ws      (fk_ws),
  KEY idx_guillotine_cut_status  (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
