--20010982.60

CREATE TABLE REASONCODEDIALOGS
(
	REASONCODE_ID        NUMBER NOT NULL ,
	DIALOG_ID            NUMBER NOT NULL ,
	SELECTABLE           VARCHAR2(1) DEFAULT  'Y'  NOT NULL  CONSTRAINT  YN_ValidationField38 CHECK (SELECTABLE IN ('Y', 'N')),
	SYSTEMUSER_ID        NUMBER NOT NULL ,
	TIMESTAMP            DATE NOT NULL 
) TABLESPACE ABS_DATA;

CREATE SEQUENCE SEQ_REASONCODEDIALOGS
START WITH 1
INCREMENT BY 1;

CREATE  INDEX XIF1REASONCODEDIALOGS ON REASONCODEDIALOGS
(DIALOG_ID   ASC) TABLESPACE INDX;



CREATE  INDEX XIF2REASONCODEDIALOGS ON REASONCODEDIALOGS
(REASONCODE_ID   ASC) TABLESPACE INDX;



ALTER TABLE REASONCODEDIALOGS
ADD CONSTRAINT  XPKREASONCODEDIALOGS PRIMARY KEY (REASONCODE_ID,DIALOG_ID);



ALTER TABLE REASONCODEDIALOGS
ADD CONSTRAINT REASONCODEDIALOGS_DIALOGS FOREIGN KEY (DIALOG_ID) REFERENCES DIALOGS (DIALOG_ID) ON DELETE CASCADE;



ALTER TABLE REASONCODEDIALOGS
ADD CONSTRAINT REASONCODEDIALOGS_REASONCODE FOREIGN KEY (REASONCODE_ID) REFERENCES REASONCODE (REASONCODE_ID) ON DELETE CASCADE;


INSERT INTO REASONCODEDIALOGS
  (REASONCODE_ID, DIALOG_ID, SELECTABLE, SYSTEMUSER_ID, TIMESTAMP)
  SELECT R.REASONCODE_ID,
         D.DIALOG_ID,
         'Y',
         GETMINSYSTEMUSER(),
         GETCURRENTDATETIME()
    FROM REASONCODE R,
         DIALOGS    D WHERE D.CODE IN('DeliveryNote',
                                    'DeliveryVariations',
                                    'GarmentDispenser',
                                    'RagInBatch',
                                    'RagItemsFromStock',
                                    'ReceiveItemsFromPO',
                                    'ReceiveItemsInStockNoPO',
                                    'ReplacementRenewal',
                                    'StockCorrectionNonUnique',
                                    'StockCorrectionUnique',
                                    'Wearer',
                                    'WorkOrderApproval',
                                    'WorkOrder',
                                    'ReturnToStock',
                                    'ReceiveItemsFromDismountingOrder',
                                    'MoveStock',
                                    'MoveStockWithinStockroom',
                                    'ConfirmSterilization',
                                    'SterilizationRunStatusControl',
                                    'StandardDelivery',
                                    'ORPackStatusControl',
                                    'IssueGarmentsDirect',
                                    'IssueGarmentsFromStock');



