-- ABS-7454
ALTER TABLE STANDARDINVENTORY ADD (SEASON_ID NUMBER NULL ,
                   SEASONCHANGEMODE NUMBER DEFAULT 0 NOT NULL CONSTRAINT SEASONCHANGEMODE_VALID1_1  CHECK (SEASONCHANGEMODE IN (0,1)),
                   FINISHINGMETHOD_ID NUMBER NULL,
                   FMCHANGEMODE NUMBER DEFAULT 0 NOT NULL CONSTRAINT FMCHANGEMODE_VALID1_1  CHECK (FMCHANGEMODE IN (0,1)));

COMMENT ON COLUMN STANDARDINVENTORY.SEASONCHANGEMODE
  IS '0 = Default
	  1 = Fixed';
	  
COMMENT ON COLUMN STANDARDINVENTORY.FMCHANGEMODE
  IS '0 = Default
     1 = Fixed';
	 
CREATE INDEX XIF1STANDARDINVENTORY ON STANDARDINVENTORY (SEASON_ID);

CREATE INDEX XIF2STANDARDINVENTORY ON STANDARDINVENTORY (FINISHINGMETHOD_ID);
	 
ALTER TABLE STANDARDINVENTORY
  ADD CONSTRAINT STANDARDINVENTORY_SEASON_ID FOREIGN KEY (SEASON_ID) REFERENCES SEASON (SEASON_ID) ON DELETE SET NULL;
  
ALTER TABLE STANDARDINVENTORY
  ADD CONSTRAINT STANDARDINVENTORY_FM_ID FOREIGN KEY (FINISHINGMETHOD_ID)  REFERENCES FINISHINGMETHOD (FINISHINGMETHOD_ID) ON DELETE SET NULL;
  
  
  
--ABS-5789
------------ CUSTOMERRAGREASON------------------
CREATE TABLE CUSTOMERRAGREASON
(
  CUSTOMER_ID   NUMBER NOT NULL,
  RAGREASON_ID  NUMBER NOT NULL,
  SYSTEMUSER_ID NUMBER NOT NULL,
  TIMESTAMP     DATE NOT NULL);
  
ALTER TABLE CUSTOMERRAGREASON
  ADD CONSTRAINT XPKCUSTOMERRAGREASON PRIMARY KEY (CUSTOMER_ID, RAGREASON_ID);

CREATE INDEX XIF1CUSTOMERRAGREASON ON CUSTOMERRAGREASON (CUSTOMER_ID);

CREATE INDEX XIF2CUSTOMERRAGREASON ON CUSTOMERRAGREASON (RAGREASON_ID);

ALTER TABLE CUSTOMERRAGREASON
  ADD CONSTRAINT CUSTOMERRAGREASON_CUSTOMER_ID FOREIGN KEY (CUSTOMER_ID)
  REFERENCES CUSTOMER (CUSTOMER_ID) ON DELETE CASCADE;
  
  ALTER TABLE CUSTOMERRAGREASON
  ADD CONSTRAINT CUSTOMERRAGREASON_RAGREASON_ID FOREIGN KEY (RAGREASON_ID)
  REFERENCES RAGREASON (RAGREASON_ID) ON DELETE CASCADE;