--ABS-44121/ ABS-54463

---CONTRACTCOMPONENTBGPROTECTION table---
CREATE TABLE CONTRACTCOMPONENTBGPROTECTION
(
  CONTRACT_ID                   NUMBER NOT NULL,
  MATERIALMAINTENANCEPERCENTAGE NUMBER NULL,
  GARMENTSETUP                  VARCHAR2(1) NULL CONSTRAINT YN_VALIDATIONFIELD392
                                CHECK (GARMENTSETUP IN ('Y', 'N')),
  GARMENTMAINTENANCE            VARCHAR2(1) NULL CONSTRAINT YN_VALIDATIONFIELD393
                                CHECK (GARMENTMAINTENANCE IN ('Y', 'N')),
  GARMENTLOSS                   VARCHAR2(1) NULL CONSTRAINT YN_VALIDATIONFIELD394
                                CHECK (GARMENTLOSS IN ('Y', 'N')),
  GARMENTREPAIR                 VARCHAR2(1) NULL CONSTRAINT YN_VALIDATIONFIELD395
                                CHECK (GARMENTREPAIR IN ('Y', 'N')),
  SYSTEMUSER_ID                 NUMBER NOT NULL,
  TIMESTAMP                     DATE NOT NULL
)
;

ALTER TABLE CONTRACTCOMPONENTBGPROTECTION
  ADD CONSTRAINT XPKCONTRACTCOMPBGPROTECTION PRIMARY KEY (CONTRACT_ID);
  
ALTER TABLE CONTRACTCOMPONENTBGPROTECTION
  ADD CONSTRAINT CONTRACTCOMPBGPROTECTION_C FOREIGN KEY (CONTRACT_ID)
  REFERENCES CONTRACT (CONTRACT_ID) ON DELETE CASCADE;

ALTER TABLE CONTRACTCOMPONENTBGPROTECTION
  ADD CONSTRAINT CONTRCOMPBGPROTECTION_CHECK1
  CHECK ((MATERIALMAINTENANCEPERCENTAGE IS NULL) OR (MATERIALMAINTENANCEPERCENTAGE IS NOT NULL AND MATERIALMAINTENANCEPERCENTAGE BETWEEN 0 AND 100));
  
INSERT INTO CONTRACTATTRIBUTE
  (CONTRACTATTRIBUTE_ID,
   GROUPNUMBER,
   SEQUENCENUMBER,
   FACTORYNAME,
   INTERNALNAME,
   SYSTEMUSER_ID,
   TIMESTAMP,
   NOVALUERULE)
VALUES
  (105,
   4,
   13,
   'Budget Protection',
   'customerBudgetProtectionField',
   GETMINSYSTEMUSER(),
   sysdate,
   0);
COMMIT;