/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\FA_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CLEARRSBILLENTRY' AND KSQL_COL_NAME ='FPRERESIDUALVAL') 
 ALTER TABLE T_FA_CLEARRSBILLENTRY ADD (FPRERESIDUALVAL DECIMAL(19,6) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CLEARRSBILLENTRY' AND KSQL_COL_NAME ='FCLEARDATE') 
 ALTER TABLE T_FA_CLEARRSBILLENTRY ADD (FCLEARDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_DEPRESYSTEMAPENTRY' AND KSQL_COL_NAME ='FDEPRELIMIT') 
 ALTER TABLE T_FA_DEPRESYSTEMAPENTRY ADD (FDEPRELIMIT DECIMAL(19,6) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CHANGEFIELDENTRY' AND KSQL_COL_NAME ='FISADJUSTDEPRE') 
 ALTER TABLE T_FA_CHANGEFIELDENTRY ADD (FISADJUSTDEPRE CHAR(1) DEFAULT '1' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CHANGEFIELDENTRY' AND KSQL_COL_NAME ='FBIZDATE') 
 ALTER TABLE T_FA_CHANGEFIELDENTRY ADD (FBIZDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CHANGEBILLFINENTRY' AND KSQL_COL_NAME ='FBIZDATE') 
 ALTER TABLE T_FA_CHANGEBILLFINENTRY ADD (FBIZDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CLRBILLENTRY_D' AND KSQL_COL_NAME ='FPRERESIDUALVAL') 
 ALTER TABLE T_FA_CLRBILLENTRY_D ADD (FPRERESIDUALVAL DECIMAL(19,6) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CLRBILLENTRY_D' AND KSQL_COL_NAME ='FBIZDATE') 
 ALTER TABLE T_FA_CLRBILLENTRY_D ADD (FBIZDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_RECALCULATE') 
 CREATE TABLE T_FA_RECALCULATE (
FID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FDEPREUSEID BIGINT DEFAULT 0 NOT NULL,
FBIZDATE DATETIME,
FAUDITDATE DATETIME,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FBILLSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FBILLNO NVARCHAR(30) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FCOEFFICIENTF DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_RECALCULATE_ENTRY') 
 CREATE TABLE T_FA_RECALCULATE_ENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FREALCARDID BIGINT DEFAULT 0 NOT NULL,
FFINCARDID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FBFORIVALUE DECIMAL(19,6) DEFAULT 0 NOT NULL,
FORIVALUE DECIMAL(19,6) DEFAULT 0 NOT NULL,
FBFNETWORTH DECIMAL(19,6) DEFAULT 0 NOT NULL,
FNETWORTH DECIMAL(19,6) DEFAULT 0 NOT NULL,
FBFNETAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FNETAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FBFPRERESIDUALVAL DECIMAL(19,6) DEFAULT 0 NOT NULL,
FPRERESIDUALVAL DECIMAL(19,6) DEFAULT 0 NOT NULL,
FBFACCUMDEPRE DECIMAL(19,6) DEFAULT 0 NOT NULL,
FACCUMDEP DECIMAL(19,6) DEFAULT 0 NOT NULL,
FBFADDUPYEARDEPRE DECIMAL(19,6) DEFAULT 0 NOT NULL,
FADDUPYEA DECIMAL(19,6) DEFAULT 0 NOT NULL,
FBFYEARORIGVALCHG DECIMAL(19,6) DEFAULT 0 NOT NULL,
FYEARORIGVALCHG DECIMAL(19,6) DEFAULT 0 NOT NULL,
FBFMONTHORIGVALCHG DECIMAL(19,6) DEFAULT 0 NOT NULL,
FMONTHORIGVALCHG DECIMAL(19,6) DEFAULT 0 NOT NULL,
FCURRENCYID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CARD_FIN' AND KSQL_COL_NAME ='FADDIDEPREAMOUNT') 
 ALTER TABLE T_FA_CARD_FIN ADD (FADDIDEPREAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CHANGERECORD' AND KSQL_COL_NAME ='FDYNAMIC') 
 ALTER TABLE T_FA_CHANGERECORD ADD (FDYNAMIC CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_MATERTOASSET' AND KSQL_COL_NAME ='FDEPREUSEID') 
 ALTER TABLE T_FA_MATERTOASSET ADD (FDEPREUSEID BIGINT DEFAULT 0 NOT NULL );

 EXEC p_AlterColumn 'T_FA_MATERTOASSET', 'FDEPREUSID', 'NULL', 'NULL', '1001', 'NULL';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CHANGEBAK_FIN' AND KSQL_COL_NAME ='FENDPERIODID') 
 ALTER TABLE T_FA_CHANGEBAK_FIN ADD (FENDPERIODID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CHANGEBAK_FIN' AND KSQL_COL_NAME ='FASSETCATID') 
 ALTER TABLE T_FA_CHANGEBAK_FIN ADD (FASSETCATID BIGINT DEFAULT 0 NOT NULL );

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