-- ABS-121330/ ABS-128056

-- RAGREASONILSUBTYPE TABLE --
CREATE TABLE RAGREASONILSUBTYPE
(
  RAGREASON_ID          NUMBER NOT NULL,
  INVOICELINESUBTYPE_ID NUMBER NOT NULL,
  SYSTEMUSER_ID         NUMBER NOT NULL,
  TIMESTAMP             DATE NOT NULL
)
;

ALTER TABLE RAGREASONILSUBTYPE
  ADD CONSTRAINT XPKRAGREASONILSUBTYPE PRIMARY KEY (RAGREASON_ID);
  
CREATE INDEX XIF1RAGREASONILSUBTYPE ON RAGREASONILSUBTYPE (INVOICELINESUBTYPE_ID);

ALTER TABLE RAGREASONILSUBTYPE
  ADD CONSTRAINT FK_RAGREASONILST_RAGREASON FOREIGN KEY (RAGREASON_ID)
  REFERENCES RAGREASON (RAGREASON_ID) ON DELETE CASCADE;

ALTER TABLE RAGREASONILSUBTYPE
  ADD CONSTRAINT FK_RAGREASONILST_ILST FOREIGN KEY (INVOICELINESUBTYPE_ID)
  REFERENCES INVOICELINESUBTYPE (INVOICELINESUBTYPE_ID) ON DELETE CASCADE;

-- REASONLINKTORAGREASON TABLE --
CREATE TABLE REASONLINKTORAGREASON
(
  REASONCODE_ID NUMBER NOT NULL,
  RAGREASON_ID  NUMBER NOT NULL,
  SYSTEMUSER_ID NUMBER NOT NULL,
  TIMESTAMP     DATE NOT NULL
)
;

ALTER TABLE REASONLINKTORAGREASON
  ADD CONSTRAINT XPKREASONLINKTORAGREASON PRIMARY KEY (REASONCODE_ID);
  
CREATE INDEX XIF1REASONLINKTORAGREASON ON REASONLINKTORAGREASON (RAGREASON_ID);

ALTER TABLE REASONLINKTORAGREASON
  ADD CONSTRAINT FK_REASONLINKTORR_RC FOREIGN KEY (REASONCODE_ID)
  REFERENCES REASONCODE (REASONCODE_ID) ON DELETE CASCADE;
  
ALTER TABLE REASONLINKTORAGREASON
  ADD CONSTRAINT FK_REASONLINKTORR_RAGREASON FOREIGN KEY (RAGREASON_ID)
  REFERENCES RAGREASON (RAGREASON_ID) ON DELETE CASCADE;

