/**Begin D:\PDM_UPGRADE\PDM1\FA_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_CHANGE_APPLY') 
 CREATE TABLE T_FA_CHANGE_APPLY (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(255) DEFAULT ' ' NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FASSETORGID BIGINT DEFAULT 0 NOT NULL,
FAPPLYDATE DATETIME,
FCHANGETYPEID BIGINT DEFAULT 0 NOT NULL,
FAPPLYDEPTID BIGINT DEFAULT 0 NOT NULL,
FAPPLIANTID BIGINT DEFAULT 0 NOT NULL,
FREMARK VARCHAR(255) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FBILLSTATUS CHAR(1) DEFAULT 'A' NOT NULL,
FBIZSTATUS CHAR(1) DEFAULT 'A' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_CHANGE_APPLY_ENTRY') 
 CREATE TABLE T_FA_CHANGE_APPLY_ENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FREALCARDID BIGINT DEFAULT 0 NOT NULL,
FBEFASSETNAME NVARCHAR(300) DEFAULT ' ' NOT NULL,
FAFTASSETNAME NVARCHAR(300) DEFAULT ' ' NOT NULL,
FBEFUNITID BIGINT DEFAULT 0 NOT NULL,
FAFTUNITID BIGINT DEFAULT 0 NOT NULL,
FBEFSUPPLIERID BIGINT DEFAULT 0 NOT NULL,
FAFTSUPPLIERID BIGINT DEFAULT 0 NOT NULL,
FBEFUSESTATUSID BIGINT DEFAULT 0 NOT NULL,
FAFTUSESTATUSID BIGINT DEFAULT 0 NOT NULL,
FBEFHEADUSEDEPTID BIGINT DEFAULT 0 NOT NULL,
FAFTHEADUSEDEPTID BIGINT DEFAULT 0 NOT NULL,
FBEFHEADUSEPERSONID BIGINT DEFAULT 0 NOT NULL,
FAFTHEADUSEPERSONID BIGINT DEFAULT 0 NOT NULL,
FBEFASSETCATID BIGINT DEFAULT 0 NOT NULL,
FAFTASSETCATID BIGINT DEFAULT 0 NOT NULL,
FBEFSTOREPLACEID BIGINT DEFAULT 0 NOT NULL,
FAFTSTOREPLACEID BIGINT DEFAULT 0 NOT NULL,
FBEFISSTORAGED CHAR(1) DEFAULT ' ' NOT NULL,
FAFTISSTORAGED CHAR(1) DEFAULT ' ' NOT NULL,
FBEFORIGINMETHODID BIGINT DEFAULT 0 NOT NULL,
FAFTORIGINMETHODID BIGINT DEFAULT 0 NOT NULL,
FBEFASSETAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAFTASSETAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBEFCOSTCENTERID BIGINT DEFAULT 0 NOT NULL,
FAFTCOSTCENTERID BIGINT DEFAULT 0 NOT NULL,
FREASON VARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_CHANGE_APPLY_ENTRY_L') 
 CREATE TABLE T_FA_CHANGE_APPLY_ENTRY_L (
FPKID VARCHAR(18) DEFAULT ' ' NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FBEFASSETNAME NVARCHAR(300) DEFAULT ' ' NOT NULL,
FAFTASSETNAME NVARCHAR(300) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_CHANGE_APPLY_LK') 
 CREATE TABLE T_FA_CHANGE_APPLY_LK (
FPKID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FSBILLID BIGINT DEFAULT 0 NOT NULL,
FSTABLEID BIGINT DEFAULT 0 NOT NULL,
FSID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_CHANGE_APPLY_TC') 
 CREATE TABLE T_FA_CHANGE_APPLY_TC (
FID BIGINT DEFAULT 0 NOT NULL,
FTBILLID BIGINT DEFAULT 0 NOT NULL,
FTTABLEID BIGINT DEFAULT 0 NOT NULL,
FTID BIGINT DEFAULT 0 NOT NULL,
FSBILLID BIGINT DEFAULT 0 NOT NULL,
FSTABLEID BIGINT DEFAULT 0 NOT NULL,
FSID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_CHANGE_APPLY_WB') 
 CREATE TABLE T_FA_CHANGE_APPLY_WB (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 1 NOT NULL,
FRULEVERID BIGINT DEFAULT 0 NOT NULL,
FRULEITEMID BIGINT DEFAULT 0 NOT NULL,
FOPERATE VARCHAR(30) DEFAULT ' ' NOT NULL,
FSBILLID BIGINT DEFAULT 0 NOT NULL,
FSTABLEID BIGINT DEFAULT 0 NOT NULL,
FSID BIGINT DEFAULT 0 NOT NULL,
FWRITEVALUE DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CHANGE_ITEM' AND KSQL_COL_NAME IN ('FCHANGEAPPLYKEY'))
 ALTER TABLE T_FA_CHANGE_ITEM ADD (FCHANGEAPPLYKEY VARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_CHANGEAPPLY_CHGITEMS') 
 CREATE TABLE T_FA_CHANGEAPPLY_CHGITEMS (
FPKID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);



/**End D:\PDM_UPGRADE\PDM1\FA_table.sql **/
