--ABS-113854
CREATE TABLE CONTAINER_DELIVERYSCAN
(
  CONTAINER_PRIMARYID       VARCHAR2(12) NOT NULL,
  SCANTIMESTAMP             DATE NOT NULL,
  SCANSTATION               VARCHAR2(12) NOT NULL,
  NUMBER_OF_GARMENTS        NUMBER NOT NULL,
  LAST_ITEM_BATCH           NUMBER(1) NOT NULL,
  STATUS                    NUMBER(1) NULL,
  CUSTOMERNUMBER            NUMBER NULL,
  DEPARTMENTNUMBER          NUMBER NULL,
  DISTRIBUTIONPOINT_LINK_ID NUMBER NULL,
  PACKINGNOTE_ID            NUMBER NULL,
  ACTUAL_NUMBER_OF_GARMENTS NUMBER NULL,
  TIMESTAMP                 DATE DEFAULT SYSDATE NOT NULL,
  SYSTEMUSER_ID             NUMBER DEFAULT 0 NOT NULL
);
COMMENT ON COLUMN CONTAINER_DELIVERYSCAN.SCANTIMESTAMP IS 'Time of scanning the container by a robot';
COMMENT ON COLUMN CONTAINER_DELIVERYSCAN.SCANSTATION IS 'Workstation code that did the deliveryscan';
COMMENT ON COLUMN CONTAINER_DELIVERYSCAN.NUMBER_OF_GARMENTS IS 'Number of garments that are placed on the container';
COMMENT ON COLUMN CONTAINER_DELIVERYSCAN.LAST_ITEM_BATCH IS '0=No, 1=Yes batch is complete';
COMMENT ON COLUMN CONTAINER_DELIVERYSCAN.STATUS IS '0=Ok, any other value represents an error';
ALTER TABLE CONTAINER_DELIVERYSCAN ADD CONSTRAINT XPKCONTAINER_DELIVERYSCAN PRIMARY KEY (CONTAINER_PRIMARYID, SCANTIMESTAMP);
ALTER TABLE CONTAINER_DELIVERYSCAN ADD CONSTRAINT PK2_CONTAINER_DELIVERYSCAN UNIQUE (SCANSTATION, SCANTIMESTAMP);
CREATE INDEX XIF1CONTAINER_DELIVERYSCAN ON CONTAINER_DELIVERYSCAN (DISTRIBUTIONPOINT_LINK_ID);
ALTER TABLE CONTAINER_DELIVERYSCAN ADD CONSTRAINT CHK_CONTDELSCAN_LAST_ITEM_BATCH CHECK (LAST_ITEM_BATCH IN (0,1));
ALTER TABLE CONTAINER_DELIVERYSCAN ADD CONSTRAINT FK1_CONT_DELSCAN_DISTRPOINT_ID FOREIGN KEY (DISTRIBUTIONPOINT_LINK_ID)
  REFERENCES DISTRIBUTIONPOINT_LINK (DISTRIBUTIONPOINT_LINK_ID);
