--- ABS-8061
-----------------------   STOCKCOUNTSCHEDULEDAY   -----------------------------
ALTER TABLE STOCKCOUNTSCHEDULEDAY ADD (ORDERINGDEADLINE DATE DEFAULT to_date('12:00:00','HH24:MI:SS') NOT NULL);

COMMENT ON COLUMN STOCKCOUNTSCHEDULEDAY.ORDERINGDEADLINE IS 'Only the time is stored';



--- ABS-6137
-----------------------   PRODUCTINFO   ----------------------------------------
CREATE TABLE PRODUCTINFO
(
PRODUCT_ID NUMBER NOT NULL,
INFO BLOB NOT NULL,
FILENAME VARCHAR2(60) NOT NULL,
SYSTEMUSER_ID NUMBER NOT NULL,
TIMESTAMP DATE NOT NULL
);


COMMENT ON COLUMN PRODUCTINFO.INFO IS 'This field can be used to store a document, Excell sheet, PDF file etc.';

ALTER TABLE PRODUCTINFO
   ADD CONSTRAINT XPKPRODUCTINFO PRIMARY KEY (PRODUCT_ID);


ALTER TABLE PRODUCTINFO
   ADD CONSTRAINT PRODUCTINFO_PRODUCT FOREIGN KEY (PRODUCT_ID) REFERENCES PRODUCT (PRODUCT_ID) ON DELETE CASCADE;



--- ABS-6151
-----------------------   PLANTPDFEXPORT   --------------------------------------
ALTER TABLE PLANTPDFEXPORT
DROP PRIMARY KEY;

DROP INDEX XPKPLANTPDFEXPORT;

DROP INDEX XAK1PLANTPDFEXPORT;

ALTER TABLE PLANTPDFEXPORT
ADD CONSTRAINT XPKPLANTPDFEXPORT PRIMARY KEY (PLANT_ID, REPORTNUMBER, KEYWORDFILEFORMAT);

CREATE UNIQUE INDEX XAK1PLANTPDFEXPORT ON PLANTPDFEXPORT (PLANT_ID, REPORTNAME, KEYWORDFILEFORMAT);

insert into plantpdfexport
  (plant_id, reportnumber, reportname, exportpdf, systemuser_id, timestamp, keywordfileformat)
  select p.plant_id, 3, 'Invoice', 'N', GETMINSYSTEMUSER(), sysdate, 2 from plant p;
commit;

