/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\FA_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_CHANGE_ITEM') 
 CREATE TABLE T_FA_CHANGE_ITEM (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT 'C' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE CHAR(1) DEFAULT '1' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FTOPIC NVARCHAR(30) DEFAULT ' ' NOT NULL
);


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


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_CHANGETYPE_ENTRY') 
 CREATE TABLE T_FA_CHANGETYPE_ENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FCHANGEITEMID BIGINT DEFAULT 0 NOT NULL
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_CHANGEBILLFINENTRY') 
 CREATE TABLE T_FA_CHANGEBILLFINENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FDEPREUSEID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FFINCARDID BIGINT DEFAULT 0 NOT NULL,
FBEFOREFININFO BIGINT DEFAULT 0 NOT NULL,
FCURRENCYID BIGINT DEFAULT 0 NOT NULL,
FAFTERFININFO BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_CHANGEBILLREALENTRY') 
 CREATE TABLE T_FA_CHANGEBILLREALENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FAFTREALCARDID BIGINT DEFAULT 0 NOT NULL,
FREALCARDID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_CHANGEFIELDENTRY') 
 CREATE TABLE T_FA_CHANGEFIELDENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FREALCARDID BIGINT DEFAULT 0 NOT NULL,
FDEPREUSEID BIGINT DEFAULT 0 NOT NULL,
FCURRENCYID BIGINT DEFAULT 0 NOT NULL,
FBASECURRENCYID BIGINT DEFAULT 0 NOT NULL,
FFINCARDID BIGINT DEFAULT 0 NOT NULL,
FFIELD VARCHAR(50) DEFAULT ' ' NOT NULL,
FBEFOREVALUE VARCHAR(50) DEFAULT ' ' NOT NULL,
FAFTERVALUE VARCHAR(50) DEFAULT ' ' NOT NULL,
FREASON NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_DEPRESYSTEMAPENTRY' AND KSQL_COL_NAME ='FNODEPRE') 
 ALTER TABLE T_FA_DEPRESYSTEMAPENTRY ADD (FNODEPRE CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CHANGEBILL' AND KSQL_COL_NAME ='FNEWCHANGETYPE') 
 ALTER TABLE T_FA_CHANGEBILL ADD (FNEWCHANGETYPE BIGINT DEFAULT 0 NOT NULL );

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