--liquibase formatted sql
--changeset fai:20260326_py_job_order_print_submit

CREATE TABLE IF NOT EXISTS `py_job_order_print_submit` (
    `id`           BIGINT       NOT NULL AUTO_INCREMENT,
    `created`      DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `createdBy`    VARCHAR(30)  NULL     DEFAULT NULL,
    `version`      INT          NOT NULL DEFAULT '0',
    `modified`     DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `modifiedBy`   VARCHAR(30)  NULL     DEFAULT NULL,
    `deleted`      TINYINT(1)   NOT NULL DEFAULT '0',

    `job_order_id` INT          NOT NULL COMMENT 'FK job_order (must match job_order.id type)',
    `qty`          INT          NOT NULL COMMENT 'Quantity printed this submit (labels, bags, etc.)',
    `print_channel` VARCHAR(32) NOT NULL DEFAULT 'LABEL' COMMENT 'LABEL=標簽機, DATAFLEX=打袋機, …',

    CONSTRAINT `pk_py_job_order_print_submit` PRIMARY KEY (`id`),
    KEY `idx_py_jops_job_order` (`job_order_id`),
    KEY `idx_py_jops_channel_created` (`print_channel`, `created`),
    CONSTRAINT `fk_py_jops_job_order` FOREIGN KEY (`job_order_id`) REFERENCES `job_order` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
  COMMENT='Per-submit print qty for Bag2/py clients; cumulative per job order for wastage/stock.';
