--ABS-163485
ALTER TABLE UNIQUEBUNDLE ADD (ERP_EXPORTED VARCHAR2(1) DEFAULT 'N' NOT NULL);
CREATE INDEX XIF11UNIQUEBUNDLE ON UNIQUEBUNDLE (ERP_EXPORTED);

CREATE TABLE ERP_O_CUST_BUNDLE_REJECTS
(
  TRANSFER_ID           NUMBER NOT NULL,
  TRANSFER_STATUS       NUMBER DEFAULT 0 NOT NULL,
  PROCESSBUCODE         VARCHAR2(6) NOT NULL,
  CREATIONDATE          DATE NOT NULL,
  CUSTOMERNUMBER        NUMBER NOT NULL,
  CUSTOMERNAME          VARCHAR2(40) NOT NULL,
  CUSTOMER_COCNUMBER    VARCHAR2(20) NOT NULL,
  PRODUCTCODE           VARCHAR2(12) NOT NULL,
  SIZECODE              VARCHAR2(12) NOT NULL,
  FINISHINGMETHOD       VARCHAR2(6) NOT NULL,
  REJECTEDQTY           NUMBER NOT NULL,
  TIMESTAMP             DATE DEFAULT SYSDATE NOT NULL
);
CREATE INDEX INDX_ERP_O_CUST_BUNDLE_REJECTS_STATUS ON ERP_O_CUST_BUNDLE_REJECTS (TRANSFER_STATUS);
ALTER TABLE ERP_O_CUST_BUNDLE_REJECTS ADD CONSTRAINT PK_ERP_O_CUST_BUNDLE_REJECTS PRIMARY KEY (TRANSFER_ID);
COMMENT ON COLUMN ERP_O_CUST_BUNDLE_REJECTS.TRANSFER_STATUS
  IS '0 = ready to be read, 1 = read correctly';

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