/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\MRP_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_PLS_DETAIL') 
 CREATE TABLE T_MRP_PLS_DETAIL (
FID BIGINT DEFAULT 0 NOT NULL,
FPLSSCHEME BIGINT DEFAULT 0 NOT NULL,
FPLSOPERATIONNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_PLS_DETAIL_ENTRY') 
 CREATE TABLE T_MRP_PLS_DETAIL_ENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FSOURCEORDERBILLNO NVARCHAR(30) DEFAULT ' ' NOT NULL,
FSOURCEORDERTYPE NVARCHAR(36) DEFAULT ' ' NOT NULL,
FMATERIELCODE BIGINT DEFAULT 0 NOT NULL,
FUNIT BIGINT DEFAULT 0 NOT NULL,
FPROCESSROUTEBILLNO BIGINT DEFAULT 0 NOT NULL,
FPRODUCTIONVERSION BIGINT DEFAULT 0 NOT NULL,
FECNVERSION BIGINT DEFAULT 0 NOT NULL,
FWORKCENTRE BIGINT DEFAULT 0 NOT NULL,
FPLSDATE DATETIME,
FPLANPREPAREDATE DATETIME,
FBOM BIGINT DEFAULT 0 NOT NULL,
FWORKSTARTTIME BIGINT DEFAULT 0 NOT NULL,
FWORKENDTIME BIGINT DEFAULT 0 NOT NULL,
FORDERINITIALQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORDERCALCULATEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FWORKPOWERQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FWORKPLSQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FYIELDRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FYIELDQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FWORKREMAININGQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORDERREMAININGQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPRODUCTIONORDER BIGINT DEFAULT 0 NOT NULL,
FTIMECONSUMING BIGINT DEFAULT 0 NOT NULL,
FDATEUNIT NVARCHAR(36) DEFAULT ' ' NOT NULL,
FAVAILABLEDATE DATETIME,
FPRODUCTIONORGID BIGINT DEFAULT 0 NOT NULL,
FPLSPLANNERID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_PLS_RESULT') 
 CREATE TABLE T_MRP_PLS_RESULT (
FID BIGINT DEFAULT 0 NOT NULL,
FPLSSCHEMEID BIGINT DEFAULT 0 NOT NULL,
FPLSOPERATIONNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSOURCEORDERBILLNO NVARCHAR(30) DEFAULT ' ' NOT NULL,
FSOURCEORDERTYPE NVARCHAR(36) DEFAULT ' ' NOT NULL,
FMATERIELCODE BIGINT DEFAULT 0 NOT NULL,
FUNIT BIGINT DEFAULT 0 NOT NULL,
FPRODUCTIONVERSION BIGINT DEFAULT 0 NOT NULL,
FECNVERSION BIGINT DEFAULT 0 NOT NULL,
FWORKCENTRE BIGINT DEFAULT 0 NOT NULL,
FPROCESSROUTEBILLNO BIGINT DEFAULT 0 NOT NULL,
FPLSDATE DATETIME,
FPLANPREPAREDATE DATETIME,
FBOM BIGINT DEFAULT 0 NOT NULL,
FWORKSTARTTIME BIGINT DEFAULT 0 NOT NULL,
FWORKENDTIME BIGINT DEFAULT 0 NOT NULL,
FORDERINITIALQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORDERCALCULATEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FWORKPOWERQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FWORKPLSQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FYIELDRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FYIELDQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FWORKREMAININGQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPRODUCTIONORDER BIGINT DEFAULT 0 NOT NULL,
FTIMECONSUMING BIGINT DEFAULT 0 NOT NULL,
FDATEUNIT NVARCHAR(36) DEFAULT ' ' NOT NULL,
FAVAILABLEDATE DATETIME,
FPRODUCTIONORGID BIGINT DEFAULT 0 NOT NULL,
FPLSPLANNERID BIGINT DEFAULT 0 NOT NULL,
FSTATUS NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCREATER BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIER BIGINT DEFAULT 0 NOT NULL,
FMODIFYDATE DATETIME,
FBILLORDER BIGINT DEFAULT 0 NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_PLS_DETAIL_ENTRY' AND KSQL_COL_NAME ='FWCTIMECONSUMING') 
 ALTER TABLE T_MRP_PLS_DETAIL_ENTRY ADD (FWCTIMECONSUMING DECIMAL(23,10) DEFAULT 0 NOT NULL );

/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\MRP_table.sql **/
