-- ORDER 20011858



---------------- TRANSACTIONTYE --------------------

  INSERT INTO TRANSACTIONTYPE
          (TRANSACTIONTYPE_ID,
           FACTORYDESCRIPTION,
           SYSTEMUSER_ID,
           TIMESTAMP)
        VALUES
          (545, 'OUTSCAN / SHIPPING', GETMINSYSTEMUSER(), SYSDATE);



---------------- WEIGHTOVERRIDE --------------------

CREATE SEQUENCE SEQ_WEIGHTOVERRIDE
START WITH 1
INCREMENT BY 1;

CREATE TABLE WEIGHTOVERRIDE
(
  WEIGHTOVERRIDE_ID    NUMBER NOT NULL ,
  CONTAINER_ID         NUMBER NOT NULL ,
  WORKSTATION_ID       NUMBER NOT NULL ,
  OVERRIDETIMESTAMP    DATE NOT NULL ,
  OVERRIDEUSER_ID      NUMBER NOT NULL ,
  CALCULATEDWEIGHT     NUMBER NOT NULL ,
  REALWEIGHT           NUMBER NOT NULL ,
  CUSTOMER_LINK_ID     NUMBER NULL ,
  SYSTEMUSER_ID        NUMBER NOT NULL,
  TIMESTAMP            DATE NOT NULL
);

ALTER TABLE WEIGHTOVERRIDE
ADD CONSTRAINT  XPKWEIGHTOVERRIDE PRIMARY KEY (WEIGHTOVERRIDE_ID);

CREATE INDEX XIF1WEIGHTOVERRIDE ON WEIGHTOVERRIDE
(CONTAINER_ID   ASC);

CREATE INDEX XIF2WEIGHTOVERRIDE ON WEIGHTOVERRIDE
(WORKSTATION_ID   ASC);

CREATE INDEX XIF3WEIGHTOVERRIDE ON WEIGHTOVERRIDE
(OVERRIDEUSER_ID   ASC);

CREATE INDEX XIF4WEIGHTOVERRIDE ON WEIGHTOVERRIDE
(CUSTOMER_LINK_ID   ASC);

ALTER TABLE WEIGHTOVERRIDE
ADD CONSTRAINT WEIGHTOVERRIDE_CONTAINER FOREIGN KEY (CONTAINER_ID) REFERENCES CONTAINER (CONTAINER_ID);

ALTER TABLE WEIGHTOVERRIDE
ADD CONSTRAINT WEIGHTOVERRIDE_WORKSTATION FOREIGN KEY (WORKSTATION_ID) REFERENCES WORKSTATION (WORKSTATION_ID);

ALTER TABLE WEIGHTOVERRIDE
ADD CONSTRAINT WEIGHTOVERRIDE_OVERRIDEUSER FOREIGN KEY (OVERRIDEUSER_ID) REFERENCES SYSTEMUSER (SYSTEMUSER_ID);

ALTER TABLE WEIGHTOVERRIDE
ADD CONSTRAINT WEIGHTOVERRIDE_CUSTOMER_LINK FOREIGN KEY (CUSTOMER_LINK_ID) REFERENCES CUSTOMER_LINK (CUSTOMER_LINK_ID);



---------------- SYSTEMUSER --------------------


ALTER TABLE SYSTEMUSER ADD (WEIGHTOVERRIDE NUMBER DEFAULT 0 NOT NULL );


COMMENT ON COLUMN SYSTEMUSER.WEIGHTOVERRIDE IS '0 = NOT APPLICABLE OR SYSTEMUSER IS NOT AUTHORIZED TO OVERRIDE WEIGHTS
1 = SYSTEMUSER IS AUTHORIZED TO OVERRIDE WEIGHTS';



---------------- PACKINGNOTE --------------------


ALTER TABLE PACKINGNOTE ADD (WEIGHTOVERRRIDE_ID NUMBER NULL);

CREATE  INDEX XIF16PACKINGNOTE ON PACKINGNOTE
(WEIGHTOVERRRIDE_ID   ASC);

ALTER TABLE PACKINGNOTE
ADD CONSTRAINT PACKINGNOTE_WEIGHTOVERRRIDE_ID FOREIGN KEY (WEIGHTOVERRRIDE_ID) REFERENCES WEIGHTOVERRIDE (WEIGHTOVERRIDE_ID) ON DELETE SET NULL;
