--Order 20011171.80

--------PRODUCTLISTPERCUSTOMER----------

ALTER TABLE PRODUCTLISTPERCUSTOMER
	ADD (INTERNALCALCPERCENTAGELOG NUMBER(4,1)  NULL);

ALTER TABLE PRODUCTLISTPERCUSTOMER
	ADD (INTERNALCALCPERCENTAGECOG NUMBER(4,1)  NULL);

COMMENT ON COLUMN PRODUCTLISTPERCUSTOMER.INTERNALCALCPERCENTAGELOG IS 'Internal calculation percentage for LOG items, only relevant when module INTERNALCALC is active.';

COMMENT ON COLUMN PRODUCTLISTPERCUSTOMER.INTERNALCALCPERCENTAGECOG IS 'Internal calculation percentage for COG items, only relevant when module INTERNALCALC is active.';


--------CHAIN----------


ALTER TABLE CHAIN
	ADD (INTERNALCALCPERCENTAGELOG NUMBER(4,1)  NULL);

ALTER TABLE CHAIN
	ADD (INTERNALCALCPERCENTAGECOG NUMBER(4,1)  NULL);

COMMENT ON COLUMN CHAIN.INTERNALCALCPERCENTAGELOG IS 'Internal calculation percentage for LOG items, only relevant when module INTERNALCALC is active.';

COMMENT ON COLUMN CHAIN.INTERNALCALCPERCENTAGECOG IS 'Internal calculation percentage for COG items, only relevant when module INTERNALCALC is active.';


--------WEIGHINGCATEGORY----------


ALTER TABLE WEIGHINGCATEGORY
	ADD (INTERNALCALCPERCENTAGE NUMBER(4,1)  NULL);

COMMENT ON COLUMN WEIGHINGCATEGORY.INTERNALCALCPERCENTAGE IS 'Internal calculation percentage for all weighed items, only relevant when module INTERNALCALC is active.';

--------PACKINGNOTELINE & PACKINGNOTECONTAINER----------


ALTER TABLE PACKINGNOTELINE
	ADD (INTERNALCALCPRICELOG NUMBER(15,6)  DEFAULT 0 NOT NULL);

ALTER TABLE PACKINGNOTELINE
	ADD (INTERNALCALCPRICECOG NUMBER(15,6)  DEFAULT 0 NOT NULL);

ALTER TABLE PACKINGNOTELINE
	ADD (FIXEDINTERNALCALCPRICE VARCHAR2(1)  DEFAULT 'N' NOT NULL CONSTRAINT YN_ValidationField53 CHECK (FIXEDINTERNALCALCPRICE IN ('Y', 'N')));


COMMENT ON COLUMN PACKINGNOTELINE.INTERNALCALCPRICELOG IS 'Internal calculation price for delivered LOG items, only relevant when module INTERNALCALC is active.';

COMMENT ON COLUMN PACKINGNOTELINE.INTERNALCALCPRICECOG IS 'Internal calculation price for delivered COG items, only relevant when module INTERNALCALC is active.';

COMMENT ON COLUMN PACKINGNOTELINE.FIXEDINTERNALCALCPRICE IS 'This attributes indicates whether internal calculation prices are fixed or not. Only relevant when module INTERNALCALC is active.';


ALTER TABLE PACKINGNOTECONTAINER
	ADD (INTERNALCALCPRICE NUMBER(15,6)  DEFAULT 0 NOT NULL);

COMMENT ON COLUMN PACKINGNOTECONTAINER.INTERNALCALCPRICE IS 'Internal calculation price for delivered weights, only relevant when module INTERNALCALC is active.';


--------WEIGHINGTICKETLINE----------

ALTER TABLE WEIGHINGTICKETLINE
	ADD (INTERNALCALCPRICE NUMBER(15,6)  DEFAULT 0 NOT NULL);

ALTER TABLE WEIGHINGTICKETLINE
	ADD (FIXEDINTERNALCALCPRICE VARCHAR2(1)  DEFAULT 'N' NOT NULL CONSTRAINT YN_ValidationField54 CHECK (FIXEDINTERNALCALCPRICE IN ('Y', 'N')));

COMMENT ON COLUMN WEIGHINGTICKETLINE.INTERNALCALCPRICE IS 'Internal calculation price for registered weights, only relevant when module INTERNALCALC is active.';

COMMENT ON COLUMN WEIGHINGTICKETLINE.FIXEDINTERNALCALCPRICE IS 'This attributes indicates whether the internal calculation price is fixed or not.';


--------WEIGHINGTICKET----------

ALTER TABLE WEIGHINGTICKET
	ADD (INTERNALPROCESSINGBU_ID NUMBER NULL);

ALTER TABLE WEIGHINGTICKET
ADD CONSTRAINT WEIGHINGTICKET_INTERNALBU FOREIGN KEY (INTERNALPROCESSINGBU_ID) REFERENCES BUSINESSUNIT (BUSINESSUNIT_ID);

CREATE  INDEX XIF7WEIGHINGTICKET ON WEIGHINGTICKET
(INTERNALPROCESSINGBU_ID   ASC);


--------COSTPRICELIST----------

ALTER TABLE COSTPRICELIST
	ADD CONSTRAINT PriceType_valid1  CHECK (PRICETYPE IN (1, 2, 3));

ALTER TABLE COSTPRICELIST
	ADD (SERVICETYPE NUMBER  DEFAULT 0 NOT NULL CONSTRAINT ServiceType_valid1  CHECK (SERVICETYPE IN (0, 1, 2)));

ALTER TABLE COSTPRICELIST
	ADD (PROCESSBUSINESSUNIT_ID NUMBER NULL);

ALTER TABLE COSTPRICELIST
	ADD (INTERNALPROCESSINGBU_ID NUMBER NULL);

DROP INDEX XAK1COSTPRICELIST;

CREATE UNIQUE INDEX XAK1COSTPRICELIST ON COSTPRICELIST
(PRICETYPE   ASC,CODE   ASC,SERVICETYPE   ASC);

CREATE  INDEX XIF2COSTPRICELIST ON COSTPRICELIST
(PROCESSBUSINESSUNIT_ID   ASC);

CREATE  INDEX XIF3COSTPRICELIST ON COSTPRICELIST
(INTERNALPROCESSINGBU_ID   ASC);

COMMENT ON COLUMN COSTPRICELIST.PRICETYPE IS '1 = Merchandise Cost
2 = Processing Cost
3 = Internal Calculation';

COMMENT ON COLUMN COSTPRICELIST.SERVICETYPE IS '0 = Not applicable (default)
1 = Wash
2 = All-in-Rent';

ALTER TABLE COSTPRICELIST
ADD CONSTRAINT COSTPRICELIST_PROCESSBU FOREIGN KEY (PROCESSBUSINESSUNIT_ID) REFERENCES BUSINESSUNIT (BUSINESSUNIT_ID);

ALTER TABLE COSTPRICELIST
ADD CONSTRAINT COSTPRICELIST_INTERNALBU FOREIGN KEY (INTERNALPROCESSINGBU_ID) REFERENCES BUSINESSUNIT (BUSINESSUNIT_ID);


--------COSTPRICELISTDETAIL----------

ALTER TABLE COSTPRICELISTDETAIL
	ADD (PRICETYPE NUMBER  DEFAULT 0 NOT NULL CONSTRAINT PriceType_valid2  CHECK (PRICETYPE IN (0, 1, 2)));


COMMENT ON COLUMN COSTPRICELISTDETAIL.PRICETYPE IS '0 = All items (default)
1 = LOG only
2 = COG only';

DROP INDEX XAK1COSTPRICELISTDETAIL;

CREATE UNIQUE INDEX XAK1COSTPRICELISTDETAIL ON COSTPRICELISTDETAIL
(COSTPRICELIST_ID   ASC,PRODUCT_ID   ASC,SIZEDEFINITION_ID   ASC,FINISHINGMETHOD_ID   ASC,PRICETYPE   ASC,STARTDATE ASC);


--------CUSTOMER----------

ALTER TABLE CUSTOMER
	ADD (INTERNALCALCPERCENTAGELOG NUMBER(4,1)  NULL);

ALTER TABLE CUSTOMER
	ADD (INTERNALCALCPERCENTAGECOG NUMBER(4,1)  NULL);


COMMENT ON COLUMN CUSTOMER.INTERNALCALCPERCENTAGELOG IS 'Internal calculation percentage for LOG items, only relevant when module INTERNALCALC is active.';

COMMENT ON COLUMN CUSTOMER.INTERNALCALCPERCENTAGECOG IS 'Internal calculation percentage for COG items, only relevant when module INTERNALCALC is active.';


--------BUSINESSUNITINTERNALCALCINFO----------


CREATE TABLE BUSINESSUNITINTERNALCALCINFO
(
	BUSINESSUNIT_ID      NUMBER NOT NULL ,
	INTERNALPROCESSINGBU_ID NUMBER NOT NULL ,
	WASHINTERNCALCPERCENTLOG NUMBER(4,1) DEFAULT  0  NOT NULL ,
	WASHINTERNCALCPERCENTCOG NUMBER(4,1) DEFAULT  0  NOT NULL ,
	WASHCOSTPRICELIST_ID NUMBER NULL ,
	SPLITINTERNCALCPERCENTLOG NUMBER(4,1) DEFAULT  0  NOT NULL ,
	SPLITINTERNCALCPERCENTCOG NUMBER(4,1) DEFAULT  0  NOT NULL ,
	RENTCOSTPRICELIST_ID NUMBER NULL ,
	RENTPRICEFACTOR      NUMBER(3,1) DEFAULT  0  NOT NULL ,
	RENTINTERNALCALCPERCENTAGE NUMBER(4,1) DEFAULT  0  NOT NULL ,
	SYSTEMUSER_ID        NUMBER NOT NULL ,
	TIMESTAMP            DATE NOT NULL 
);


COMMENT ON COLUMN BUSINESSUNITINTERNALCALCINFO.WASHINTERNCALCPERCENTLOG IS 'Internal calculation percentage for LOG items, only relevant when module INTERNALCALC is active.';

COMMENT ON COLUMN BUSINESSUNITINTERNALCALCINFO.WASHINTERNCALCPERCENTCOG IS 'Internal calculation percentage for COG items, only relevant when module INTERNALCALC is active.';

COMMENT ON COLUMN BUSINESSUNITINTERNALCALCINFO.SPLITINTERNCALCPERCENTLOG IS 'Internal calculation percentage for LOG items, only relevant when module INTERNALCALC is active.';

COMMENT ON COLUMN BUSINESSUNITINTERNALCALCINFO.SPLITINTERNCALCPERCENTCOG IS 'Internal calculation percentage for COG items, only relevant when module INTERNALCALC is active.';

COMMENT ON COLUMN BUSINESSUNITINTERNALCALCINFO.RENTPRICEFACTOR IS 'Price factor for rental items, only relevant when module INTERNALCALC is active.';

COMMENT ON COLUMN BUSINESSUNITINTERNALCALCINFO.RENTINTERNALCALCPERCENTAGE IS 'Internal calculation percentage for rental items, only relevant when module INTERNALCALC is active.';

CREATE  INDEX XIF1BUSINESSUNITINTERNCALCINFO ON BUSINESSUNITINTERNALCALCINFO
(BUSINESSUNIT_ID   ASC);

CREATE  INDEX XIF2BUSINESSUNITINTERNCALCINFO ON BUSINESSUNITINTERNALCALCINFO
(INTERNALPROCESSINGBU_ID   ASC);

CREATE  INDEX XIF3BUSINESSUNITINTERNCALCINFO ON BUSINESSUNITINTERNALCALCINFO
(WASHCOSTPRICELIST_ID   ASC);

CREATE  INDEX XIF4BUSINESSUNITINTERNCALCINFO ON BUSINESSUNITINTERNALCALCINFO
(RENTCOSTPRICELIST_ID   ASC);

ALTER TABLE BUSINESSUNITINTERNALCALCINFO
ADD CONSTRAINT  XPKBUSINESSUNITINTERNCALCINFO PRIMARY KEY (BUSINESSUNIT_ID,INTERNALPROCESSINGBU_ID);

ALTER TABLE BUSINESSUNITINTERNALCALCINFO
ADD CONSTRAINT BUINTERNALCALCINF_BU FOREIGN KEY (BUSINESSUNIT_ID) REFERENCES BUSINESSUNIT (BUSINESSUNIT_ID);

ALTER TABLE BUSINESSUNITINTERNALCALCINFO
ADD CONSTRAINT BUINTERNALCALCINF_INTERNALBU FOREIGN KEY (INTERNALPROCESSINGBU_ID) REFERENCES BUSINESSUNIT (BUSINESSUNIT_ID);

ALTER TABLE BUSINESSUNITINTERNALCALCINFO
ADD CONSTRAINT BUINTERNALCALC_WASHCOSTPRICE FOREIGN KEY (WASHCOSTPRICELIST_ID) REFERENCES COSTPRICELIST (COSTPRICELIST_ID);

ALTER TABLE BUSINESSUNITINTERNALCALCINFO
ADD CONSTRAINT BUINTERNALCALC_RENTPRICELIST FOREIGN KEY (RENTCOSTPRICELIST_ID) REFERENCES COSTPRICELIST (COSTPRICELIST_ID);

