--ABS-10103
--------------------------- UNIQUEITEMLOSS -------------------------
ALTER TABLE UNIQUEITEMLOSS ADD (LOSSCHARGEDATE DATE NULL);

COMMENT ON COLUMN UNIQUEITEMLOSS.LOSSCHARGEDATE
  IS 'Date the loss charge record is created';
  
UPDATE UNIQUEITEMLOSS U
   SET U.LOSSCHARGEDATE = TRUNC(U.TIMESTAMP)
 WHERE U.LOSSPERIODS_ID IS NULL
   AND U.LOSSSTATUS = 0; -- TO BE CHARGED.
COMMIT;


--ABS-10934 / 20015623
--------------------------- PLANTPRODUCTSETTINGS -------------------------
ALTER TABLE PLANTPRODUCTSETTINGS ADD (PACKINGGROUP NUMBER NULL,
									  PACKINGPRODUCTTYPE NUMBER(1) NULL);

COMMENT ON COLUMN PLANTPRODUCTSETTINGS.PACKINGGROUP
  IS 'Products will be grouped together based on this number when generating packing notes in case ‘Optimized Load packing’ is used.';
COMMENT ON COLUMN PLANTPRODUCTSETTINGS.PACKINGPRODUCTTYPE
  IS 'Defines the type of product with respect to packing. 
Possible values:
1 = Base product 
2 = Supplementary product';

--ABS-10931
--------------------------- SPECIFICSPECIALCHARGE -------------------------
ALTER TABLE COSTCENTER ADD (SPECIFICSPECIALCHARGE VARCHAR2(1) DEFAULT 'N' NOT NULL);

-------------------------- COSTCENTERSPECIALCHARGE -----------------------
CREATE TABLE COSTCENTERSPECIALCHARGE
(
  COSTCENTER_ID    NUMBER NOT NULL,
  CUSTOMER_ID      NUMBER NOT NULL,
  SPECIALCHARGE_ID NUMBER NOT NULL,
  SYSTEMUSER_ID    NUMBER NOT NULL,
  TIMESTAMP        DATE NOT NULL
);

CREATE INDEX XIF1COSTCENTERSPECIALCHARGE ON COSTCENTERSPECIALCHARGE (CUSTOMER_ID, SPECIALCHARGE_ID);
 
CREATE INDEX XIF2COSTCENTERSPECIALCHARGE ON COSTCENTERSPECIALCHARGE (COSTCENTER_ID);
   
ALTER TABLE COSTCENTERSPECIALCHARGE
  ADD CONSTRAINT COSTCENTERSPECIALCHARGE PRIMARY KEY (COSTCENTER_ID, CUSTOMER_ID, SPECIALCHARGE_ID);
  
ALTER TABLE COSTCENTERSPECIALCHARGE
  ADD CONSTRAINT COSTCENTERSPCHR_COSTCENTER_ID FOREIGN KEY (COSTCENTER_ID)
  REFERENCES COSTCENTER (COSTCENTER_ID) ON DELETE CASCADE;
  
ALTER TABLE COSTCENTERSPECIALCHARGE
  ADD CONSTRAINT CCSPCHR_CUST_ID_SPECCHR_ID FOREIGN KEY (CUSTOMER_ID, SPECIALCHARGE_ID)
  REFERENCES CUSTOMERSPECIALCHARGE (CUSTOMER_ID, SPECIALCHARGE_ID) ON DELETE CASCADE;

















