--ABS-105239
CREATE TABLE ERP_I_TEMPGARMENTRENTSTOP
(
TRANSFER_ID      NUMBER NOT NULL,
TRANSFER_STATUS  NUMBER DEFAULT 0 NOT NULL 
 CONSTRAINT CHK_ERP_ITEMPGARRNTST_V1 CHECK (TRANSFER_STATUS IN (-1,0,1)),
CUSTOMERNUMBER   NUMBER NOT NULL,
STARTYEAR        NUMBER(4) NOT NULL,
STARTWEEK        NUMBER(2) NOT NULL,
NUMBEROFWEEKS    NUMBER(3) DEFAULT 1 NOT NULL
 CONSTRAINT CHK_ERP_ITEMPGARRNTST_V2 CHECK (NUMBEROFWEEKS >=1) ,
TIMESTAMP        DATE DEFAULT SYSDATE NOT NULL
);
COMMENT ON COLUMN ERP_I_TEMPGARMENTRENTSTOP.TRANSFER_STATUS
  IS '0 = ready to be read, 1 = read correctly';
ALTER TABLE ERP_I_TEMPGARMENTRENTSTOP
 ADD CONSTRAINT PK_ERP_I_TMPGARMRENTSTOP PRIMARY KEY (TRANSFER_ID);
CREATE INDEX XIF1ERP_I_TMPGARMRENTSTOP ON ERP_I_TEMPGARMENTRENTSTOP(TRANSFER_STATUS);
CREATE INDEX XIF2ERP_I_TMPGARMRENTSTOP ON ERP_I_TEMPGARMENTRENTSTOP(CUSTOMERNUMBER);

CREATE TABLE ERP_I_TEMPGARMENTRENTSTOP_LOG
(
  TRANSFER_ID     NUMBER NOT NULL,
  TRANSFER_STATUS NUMBER DEFAULT 0 NOT NULL  CONSTRAINT CHK_ERP_I_TEMPGARRNTST_LOG_V1 CHECK (TRANSFER_STATUS IN (-1,0,1)),
  TEXT            VARCHAR2(1000) NULL,
  PROCESS_STATUS  NUMBER DEFAULT 0 NOT NULL,
  TIMESTAMP       DATE DEFAULT SYSDATE NOT NULL
);
COMMENT ON COLUMN ERP_I_TEMPGARMENTRENTSTOP_LOG.TRANSFER_STATUS
  IS '0 = ready to be read, 1 = read correctly';
COMMENT ON COLUMN ERP_I_TEMPGARMENTRENTSTOP_LOG.PROCESS_STATUS
  IS '0 = processed correctly, 1 = process stopped with errors';
ALTER TABLE ERP_I_TEMPGARMENTRENTSTOP_LOG
  ADD CONSTRAINT PK_ERP_I_TEMPGARRNTST_LOG PRIMARY KEY (TRANSFER_ID);
ALTER TABLE ERP_I_TEMPGARMENTRENTSTOP_LOG
  ADD CONSTRAINT FK_ERP_I_TEMPGARRNTSTT_LOG FOREIGN KEY (TRANSFER_ID)
  REFERENCES ERP_I_TEMPGARMENTRENTSTOP(TRANSFER_ID) ON DELETE CASCADE;