/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\BCM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_ACCOUNTCHGRD') 
 CREATE TABLE T_BCM_ACCOUNTCHGRD (
FENTITYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 1 NOT NULL,
FCHANGETYPE VARCHAR(2) DEFAULT ' ' NOT NULL,
FBIZEFFDATE DATETIME,
FBIZEXPDATE DATETIME,
FBIZMODIFIER BIGINT DEFAULT 0 NOT NULL,
FBIZMODIFYTIME DATETIME,
FMODELID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_CHKALLOCATE') 
 CREATE TABLE T_BCM_CHKALLOCATE (
FID BIGINT DEFAULT 0 NOT NULL,
FCHKSETTINGID BIGINT DEFAULT 0 NOT NULL,
FSTAGEID BIGINT DEFAULT 0 NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATEDATE DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYDATE DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_FLOWSTEP') 
 CREATE TABLE T_BCM_FLOWSTEP (
FID BIGINT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FSCENE BIGINT DEFAULT 0 NOT NULL,
FNUMBER VARCHAR(50) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FENABLE CHAR(1) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FSORT INT DEFAULT 0 NOT NULL,
FFLOWSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
FSTEPTYPE CHAR(1) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_PHASESUBMIT') 
 CREATE TABLE T_BCM_PHASESUBMIT (
FID BIGINT DEFAULT 0 NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FCREATETIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FSTATUS CHAR(1) DEFAULT '0' NOT NULL,
FENABLE CHAR(1) DEFAULT '0' NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FSCENARIO BIGINT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FDATEEND DATETIME,
FDATEBEGIN DATETIME,
FDIMGRP NVARCHAR(1000) DEFAULT ' ' NOT NULL
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_STAGESTATUS') 
 CREATE TABLE T_BCM_STAGESTATUS (
FID BIGINT DEFAULT 0 NOT NULL,
FMERGECONTROL BIGINT DEFAULT 0 NOT NULL,
FSTAGE BIGINT DEFAULT 0 NOT NULL,
FFLOWSTEP BIGINT DEFAULT 0 NOT NULL,
FCHECKRESULT CHAR(1) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_CHKFORMULASETTING' AND KSQL_COL_NAME ='FSTAGEALLOCATE') 
 ALTER TABLE T_BCM_CHKFORMULASETTING ADD (FSTAGEALLOCATE NVARCHAR(200) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_CHKREPORT' AND KSQL_COL_NAME ='FPHASE') 
 ALTER TABLE T_BCM_CHKREPORT ADD (FPHASE BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_PERIODMANAGEENTITY') 
 CREATE TABLE T_BCM_PERIODMANAGEENTITY (
FID BIGINT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FYEARID BIGINT DEFAULT 0 NOT NULL,
FPERIODID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FSCENARIOID BIGINT DEFAULT 0 NOT NULL,
FDATASTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FENTRYSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FEXECUTEACTION CHAR(1) DEFAULT ' ' NOT NULL,
FOPTIME DATETIME,
FOPERATOR BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_APPROVALAUTHORITY') 
 CREATE TABLE T_BCM_APPROVALAUTHORITY (
FID BIGINT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FAPPROVALLEVELID BIGINT DEFAULT 0 NOT NULL,
FAPPROVALSTAGEID BIGINT DEFAULT 0 NOT NULL,
FSCENARIOID BIGINT DEFAULT 0 NOT NULL,
FUSERNAME NVARCHAR(30) DEFAULT ' ' NOT NULL,
FUSERSID BIGINT DEFAULT 0 NOT NULL,
FUSERTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FAPPROVALSTAGE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FAUTHORITY CHAR(1) DEFAULT '1' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_PHASESUBMIT_L') 
 CREATE TABLE T_BCM_PHASESUBMIT_L (
FPKID NVARCHAR(30) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID NVARCHAR(20) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(500) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_PHASESUBMITCASE') 
 CREATE TABLE T_BCM_PHASESUBMITCASE (
FID BIGINT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FPHASESUBMIT BIGINT DEFAULT 0 NOT NULL,
FPHASESUBMITGRP BIGINT DEFAULT 0 NOT NULL,
FCASEVALUE NCLOB
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_PHASESUBMITGRP_L') 
 CREATE TABLE T_BCM_PHASESUBMITGRP_L (
FPKID NVARCHAR(30) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID NVARCHAR(20) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(500) DEFAULT ' ' NOT NULL
);



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