--liquibase formatted sql

--changeset cyril:stock in
CREATE TABLE `stock_in`
(
    `id`                    INT         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,
    `modifiedBy`            VARCHAR(30) NULL DEFAULT NULL,
    `deleted`               TINYINT(1) NOT NULL DEFAULT '0',
    `code`                  VARCHAR(30) NOT NULL,
    `supplierId`            INT NULL,
    `shopId`                INT NULL,
    `refId`                 INT NULL,
    `refType`               VARCHAR(5) NULL,
    `orderDate`             DATETIME NULL,
    `estimatedCompleteDate` DATETIME NULL,
    `completeDate`          DATETIME NULL,
    `status`                VARCHAR(10) NOT NULL DEFAULT 'pending',
    `m18DataLogId`          INT         NOT NULL,
    CONSTRAINT pk_stock_in PRIMARY KEY (id),
    CONSTRAINT FK_STOCK_IN_ON_SUPPLIERID FOREIGN KEY (supplierId) REFERENCES shop (id),
    CONSTRAINT FK_STOCK_IN_ON_SHOPID FOREIGN KEY (shopId) REFERENCES shop (id),
    CONSTRAINT FK_STOCK_IN_ON_M18DATALOGID FOREIGN KEY (m18DataLogId) REFERENCES m18_data_log (id)
);

CREATE TABLE `stock_in_line`
(
    `id`            INT         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,
    `modifiedBy`    VARCHAR(30) NULL DEFAULT NULL,
    `deleted`       TINYINT(1) NOT NULL DEFAULT '0',
    `itemId`        INT         NOT NULL,
    `itemNo`        VARCHAR(20) NOT NULL,
    `stockInId`     INT         NOT NULL,
    `demandQty`     DECIMAL(14, 2) NULL,
    `acceptedQty`   DECIMAL(14, 2) NULL,
    `price`         DECIMAL(14, 2) NULL,
    `priceUnit`     VARCHAR(5) NULL,
    `productDate`   DATETIME NULL,
    `shelfLifeDate` DATETIME NULL,
    `status`        VARCHAR(10) NOT NULL DEFAULT 'pending',
    `userId`        INT NULL,
    `m18DataLogId`  INT         NOT NULL,
    CONSTRAINT pk_stock_in_line PRIMARY KEY (id),
    CONSTRAINT FK_STOCK_IN_LINE_ON_ITEMID FOREIGN KEY (itemId) REFERENCES items (id),
    CONSTRAINT FK_STOCK_IN_LINE_ON_STOCKINID FOREIGN KEY (stockInId) REFERENCES stock_in (id),
    CONSTRAINT FK_STOCK_IN_LINE_ON_USERID FOREIGN KEY (userId) REFERENCES user (id),
    CONSTRAINT FK_STOCK_IN_LINE_ON_M18DATALOGID FOREIGN KEY (m18DataLogId) REFERENCES m18_data_log (id)
);