/**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_PURFOREENTRY') 
 CREATE TABLE T_MRP_PURFOREENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FSUPPLIER BIGINT DEFAULT 0 NOT NULL,
FMATERIAL BIGINT DEFAULT 0 NOT NULL,
FWEEK INT DEFAULT 0 NOT NULL,
FQTY DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_PURFOREHISTORY') 
 CREATE TABLE T_MRP_PURFOREHISTORY (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(30) DEFAULT ' ' NOT NULL,
FSTATUS NVARCHAR(30) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_PURFOREHISTORY_L') 
 CREATE TABLE T_MRP_PURFOREHISTORY_L (
FPKID NVARCHAR(18) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL
);



IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_MFTSTOCKDMDBILL') 
 CREATE TABLE T_MRP_MFTSTOCKDMDBILL (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(30) DEFAULT ' ' NOT NULL,
FSTATUS NVARCHAR(30) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_MFTSTOCKDMDBILL_L') 
 CREATE TABLE T_MRP_MFTSTOCKDMDBILL_L (
FPKID NVARCHAR(36) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID NVARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_MFTSTOCKDMDBILLENT') 
 CREATE TABLE T_MRP_MFTSTOCKDMDBILLENT (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FPRODUCTIONORGUNITID BIGINT DEFAULT 0 NOT NULL,
FSUPPLYORGUNITID BIGINT DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL,
FMATERIALATTR NVARCHAR(30) DEFAULT ' ' NOT NULL,
FPLANSTRATEGY BIGINT DEFAULT 0 NOT NULL,
FISOLATEDRULE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FBILLID NVARCHAR(50) DEFAULT ' ' NOT NULL,
FBILLDATE DATETIME,
FBILLTYPE BIGINT DEFAULT 0 NOT NULL,
FBIZTYPE BIGINT DEFAULT 0 NOT NULL,
FDEMANDQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCOMPUTINGPERIOD BIGINT DEFAULT 0 NOT NULL,
FBILLNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FBILLSTATUS NVARCHAR(30) DEFAULT ' ' NOT NULL,
FPRODUNIT BIGINT DEFAULT 0 NOT NULL,
FBASEUNIT BIGINT DEFAULT 0 NOT NULL,
FPROJECTNUMBER BIGINT DEFAULT 0 NOT NULL,
FTRACKNUMBER BIGINT DEFAULT 0 NOT NULL,
FBILLENTRYID NVARCHAR(50) DEFAULT ' ' NOT NULL,
FBILLENTRYSEQ BIGINT DEFAULT 0 NOT NULL,
FISTOCK CHAR(1) DEFAULT '0' NOT NULL,
FISDEMAND CHAR(1) DEFAULT '0' NOT NULL,
FECNVERSION BIGINT DEFAULT 0 NOT NULL,
FDEMANDSOURCETYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FMATERIALNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FMATERIALNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FPRODUCTORGNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FPRODUCTORGNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FOUTSTOCK BIGINT DEFAULT 0 NOT NULL,
FOUTPOSITION BIGINT DEFAULT 0 NOT NULL,
FAVAILQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FWORKCENTER BIGINT DEFAULT 0 NOT NULL,
FWORKPROCD BIGINT DEFAULT 0 NOT NULL,
FWORKSTATION BIGINT DEFAULT 0 NOT NULL,
FOUTSTOCKORG BIGINT DEFAULT 0 NOT NULL,
FINSTOCKORG BIGINT DEFAULT 0 NOT NULL,
FINSTOCK BIGINT DEFAULT 0 NOT NULL,
FINPOSITION BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_CALDETAILENTRY' AND KSQL_COL_NAME ='FREQSOURCEBILLNO') 
 ALTER TABLE T_MRP_CALDETAILENTRY ADD (FREQSOURCEBILLNO NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_CALDETAILENTRY' AND KSQL_COL_NAME ='FSUPPLYDETAIL') 
 ALTER TABLE T_MRP_CALDETAILENTRY ADD (FSUPPLYDETAIL NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_CALDETAILENTRY' AND KSQL_COL_NAME ='FSEXPMSG') 
 ALTER TABLE T_MRP_CALDETAILENTRY ADD (FSEXPMSG NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_CALDETAILENTRY' AND KSQL_COL_NAME ='FSEXPNUMBER') 
 ALTER TABLE T_MRP_CALDETAILENTRY ADD (FSEXPNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_CALDETAILENTRY' AND KSQL_COL_NAME ='FWAREHOUSEID') 
 ALTER TABLE T_MRP_CALDETAILENTRY ADD (FWAREHOUSEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_CALDETAILENTRY' AND KSQL_COL_NAME ='FLOCATIONID') 
 ALTER TABLE T_MRP_CALDETAILENTRY ADD (FLOCATIONID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_CALDETAILENTRY' AND KSQL_COL_NAME ='FINVPRIORITY') 
 ALTER TABLE T_MRP_CALDETAILENTRY ADD (FINVPRIORITY NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_CALDETAILENTRY' AND KSQL_COL_NAME ='FLLC') 
 ALTER TABLE T_MRP_CALDETAILENTRY ADD (FLLC NVARCHAR(255) DEFAULT ' ' NOT NULL );



IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_PURFORECASTENTRY') 
 CREATE TABLE T_MRP_PURFORECASTENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL,
FREMARK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPURPATTERN NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPURPERSON BIGINT DEFAULT 0 NOT NULL,
FTYPE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FISRELEASE CHAR(1) DEFAULT '0' NOT NULL,
FUNITID BIGINT DEFAULT 0 NOT NULL,
FRELEASETIME DATETIME,
FRELEASEPERSONID BIGINT DEFAULT 0 NOT NULL,
FEDITTIME DATETIME,
FQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FDATE DATETIME,
FCHANGEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FROWTYPE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FEDITPERSONID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_PURFORECAST') 
 CREATE TABLE T_MRP_PURFORECAST (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(30) DEFAULT ' ' NOT NULL,
FBILLSTATUS NVARCHAR(30) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FMODIFYTIME DATETIME,
FCREATETIME DATETIME,
FPLANPROGRAMID BIGINT DEFAULT 0 NOT NULL,
FPLANORGID BIGINT DEFAULT 0 NOT NULL,
FRUNLOG BIGINT DEFAULT 0 NOT NULL
);



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