 /*Order 502238*/     
      /*
      CHANGE REPORT for Table RENTALQTYADJUSTMENT
          - Adding a new relationship RENTQTYADJ_MOUNTINGORDER_ID
          - Adding a new relationship RENTQTYADJ_QUALITYGRADE_ID
          - Adding column SAMPLEITEM
          - Adding column DESIREDMOUNTINGDATE
          - Adding column ACTUALMOUNTINGDATE
          - Adding column MOUNTINGORDER_ID
          - Adding column STARTRENTDATE
          - Adding column ENDRENTDATE
          - Adding column SALESITEM
          - Adding column SALESPRICE
          - Adding column QUALITYGRADE_ID
          - Adding column QUANTITYFIRSTDELIVERY
          - Adding column TOBEMOUNTED
          - Adding column STARTSERVICE
          - Adding index XIF3RENTALQTYADJUSTMENT
          - Adding index XIF4RENTALQTYADJUSTMENT
      ACTION is ALTER or modify Table RENTALQTYADJUSTMENT
      */

ALTER TABLE RENTALQTYADJUSTMENT ADD (SAMPLEITEM           VARCHAR2(1) DEFAULT 
    'N' NOT NULL
                                   CONSTRAINT YN_ValidationNew121
                                          CHECK (SAMPLEITEM IN ('Y', 'N')));


ALTER TABLE RENTALQTYADJUSTMENT ADD (DESIREDMOUNTINGDATE  DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL);


ALTER TABLE RENTALQTYADJUSTMENT ADD (ACTUALMOUNTINGDATE   DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL);


ALTER TABLE RENTALQTYADJUSTMENT ADD (MOUNTINGORDER_ID     NUMBER NULL);


ALTER TABLE RENTALQTYADJUSTMENT ADD (STARTRENTDATE        DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL);


ALTER TABLE RENTALQTYADJUSTMENT ADD (ENDRENTDATE          DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL);


ALTER TABLE RENTALQTYADJUSTMENT ADD (SALESITEM            VARCHAR2(1) DEFAULT 
    'N' NOT NULL
                                   CONSTRAINT YN_ValidationNew122
                                          CHECK (SALESITEM IN ('Y', 'N')));


ALTER TABLE RENTALQTYADJUSTMENT ADD (SALESPRICE           NUMBER(15,6) NULL);


ALTER TABLE RENTALQTYADJUSTMENT ADD (QUALITYGRADE_ID      NUMBER   DEFAULT 0 NOT NULL);


ALTER TABLE RENTALQTYADJUSTMENT ADD (QUANTITYFIRSTDELIVERY NUMBER DEFAULT 1 NOT NULL);


ALTER TABLE RENTALQTYADJUSTMENT ADD (TOBEMOUNTED          VARCHAR2(1) DEFAULT 
    'N' NOT NULL
                                   CONSTRAINT YN_ValidationNew123
                                          CHECK (TOBEMOUNTED IN ('Y', 'N')));


ALTER TABLE RENTALQTYADJUSTMENT ADD (STARTSERVICE         VARCHAR2(1) DEFAULT 
    'N' NOT NULL
                                   CONSTRAINT YN_ValidationNew124
                                          CHECK (STARTSERVICE IN ('Y', 'N')));





UPDATE RENTALQTYADJUSTMENT SET
RENTALQTYADJUSTMENT.QUALITYGRADE_ID =
(SELECT T.QUALITYGRADE_ID
  FROM QUALITYGRADE T
 WHERE T.PRIORITY = (SELECT MIN(Q.PRIORITY)
                       FROM QUALITYGRADE Q
                      WHERE Q.NEWGARMENT = 'Y')),
RENTALQTYADJUSTMENT.QUANTITYFIRSTDELIVERY = RENTALQTYADJUSTMENT.QUANTITY ;

CREATE INDEX XIF3RENTALQTYADJUSTMENT ON RENTALQTYADJUSTMENT
(
       MOUNTINGORDER_ID               ASC
);

CREATE INDEX XIF4RENTALQTYADJUSTMENT ON RENTALQTYADJUSTMENT
(
       QUALITYGRADE_ID                ASC
);

ALTER TABLE RENTALQTYADJUSTMENT
       ADD  ( CONSTRAINT RENTQTYADJ_MOUNTINGORDER_ID
              FOREIGN KEY (MOUNTINGORDER_ID)
                             REFERENCES WORKORDER ) ;


ALTER TABLE RENTALQTYADJUSTMENT
       ADD  ( CONSTRAINT RENTQTYADJ_QUALITYGRADE_ID
              FOREIGN KEY (QUALITYGRADE_ID)
                             REFERENCES QUALITYGRADE ) ;