-- ABS-30624
--------------------------------------------CONTRACTPURCHASEORDER---------------------------------

ALTER TABLE CONTRACTPURCHASEORDER ADD (SINGLECUSTOMERPO VARCHAR2(1) DEFAULT 'N' NOT NULL 
                                             CONSTRAINT YN_VALIDATIONFIELD293 CHECK (SINGLECUSTOMERPO IN ('Y','N')));
 
COMMENT ON COLUMN CONTRACTPURCHASEORDER.SINGLECUSTOMERPO
  IS 'WHEN SET TO Y THERE CAN ONLY BE 1 ROW AT MOST IN CONTRACTPOCUSTOMER TABLE LINKED TO THIS CONTRACTPURCHASEORDER';

--------------------------------------------CONTRACTPRICELIST--------------------------------------------------

ALTER TABLE CONTRACTPRICELIST ADD 
(DEFAULTLIST VARCHAR2(1) DEFAULT 'N' NOT NULL CONSTRAINT YN_VALIDATIONFIELD294 CHECK (DEFAULTLIST IN ('Y','N')),
PRIORITY NUMBER DEFAULT 0 NOT NULL CONSTRAINT PRIORITY_VALID1_2 CHECK (PRIORITY BETWEEN 0 AND 9999),
PRICETYPE NUMBER DEFAULT 0 NOT NULL CONSTRAINT  PRICETYPE_VALID1_1 CHECK (PRICETYPE IN (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)));
 
COMMENT ON COLUMN CONTRACTPRICELIST.PRICETYPE
  IS '0 = Undefined / inherited
1 = Wash
2 = Rent
3 = Replacement
4 = Sales
5 = Weight
6 = Repair
7 = Emblem
8 = Emblem Template
9 = Garment Insurance
10 = Special Charge
11 = Residential rent
';

CREATE INDEX XIE1CONTRACTPRICELIST ON CONTRACTPRICELIST (CONTRACT_ID ASC, PRIORITY ASC);

UPDATE CONTRACTPRICELIST CPL
SET PRICETYPE = (SELECT GPL.PRICETYPE FROM GENERALPRICELIST GPL WHERE GPL.GENERALPRICELIST_ID = CPL.GENERALPRICELIST_ID)
WHERE CPL.GENERALPRICELIST_ID IS NOT NULL;

COMMIT;