/**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_DEPRESYSTEMAPENTRY' AND KSQL_COL_NAME ='FDEPRECONVENTIONID') 
 ALTER TABLE T_FA_DEPRESYSTEMAPENTRY ADD (FDEPRECONVENTIONID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_DEPRE_CONVENTION_L') 
 CREATE TABLE T_FA_DEPRE_CONVENTION_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_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETBOOK' AND KSQL_COL_NAME ='FISGROUPBOOK') 
 ALTER TABLE T_FA_ASSETBOOK ADD (FISGROUPBOOK CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CHANGEBILLFINENTRY' AND KSQL_COL_NAME ='FISADJUSTDEPRE') 
 ALTER TABLE T_FA_CHANGEBILLFINENTRY ADD (FISADJUSTDEPRE CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CARD_REAL' AND KSQL_COL_NAME ='FMATERIALGROUPID') 
 ALTER TABLE T_FA_CARD_REAL ADD (FMATERIALGROUPID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_DEPRESPLITSETUP_L') 
 CREATE TABLE T_FA_DEPRESPLITSETUP_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_DEPRESPLITSUBENTRY') 
 CREATE TABLE T_FA_DEPRESPLITSUBENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FASSTYPE NVARCHAR(100) DEFAULT ' ' NOT NULL,
FASSID BIGINT DEFAULT 0 NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_MATERASSET_ENTRY') 
 CREATE TABLE T_FA_MATERASSET_ENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FMATIRAILGROUPID BIGINT DEFAULT 0 NOT NULL,
FASSETCATID BIGINT DEFAULT 0 NOT NULL
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_MATERTOASSET_L') 
 CREATE TABLE T_FA_MATERTOASSET_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_DEPRE_CONVENT_ENTRY') 
 CREATE TABLE T_FA_DEPRE_CONVENT_ENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FDATEFROM DATETIME,
FDATETO DATETIME,
FDATEDEPRE DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CHANGERECORD' AND KSQL_COL_NAME ='FNEEDTRACE') 
 ALTER TABLE T_FA_CHANGERECORD ADD (FNEEDTRACE CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CHANGERECORD' AND KSQL_COL_NAME ='FTRACEPERIODID') 
 ALTER TABLE T_FA_CHANGERECORD ADD (FTRACEPERIODID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CHANGERECORD' AND KSQL_COL_NAME ='FDESC') 
 ALTER TABLE T_FA_CHANGERECORD ADD (FDESC NVARCHAR(100) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_DEPRESPLITSETUP') 
 CREATE TABLE T_FA_DEPRESPLITSETUP (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(30) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
FENABLE CHAR(1) DEFAULT '0' NOT NULL,
FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FCTRLSTRATEGY VARCHAR(10) DEFAULT ' ' NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FDEPREUSEID BIGINT DEFAULT 0 NOT NULL,
FREALCARDID BIGINT DEFAULT 0 NOT NULL,
FBEGINPERIODID BIGINT DEFAULT 0 NOT NULL,
FENDPERIODID BIGINT DEFAULT 0 NOT NULL,
FMSG NCLOB
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_DEPRE_CONVENTION') 
 CREATE TABLE T_FA_DEPRE_CONVENTION (
FNUMBER NVARCHAR(30) 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,
FMESSAGE NVARCHAR(100) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FPERIODTYPEID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_DEPRESPLITENTRY') 
 CREATE TABLE T_FA_DEPRESPLITENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FORGDUTYID BIGINT DEFAULT 0 NOT NULL,
FPERCENT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FASSINFO NVARCHAR(1000)
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CLRBILLENTRY_D' AND KSQL_COL_NAME ='FCLEARRATE') 
 ALTER TABLE T_FA_CLRBILLENTRY_D ADD (FCLEARRATE DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_CLRBILLENTRY_D' AND KSQL_COL_NAME ='FISCLEARALL') 
 ALTER TABLE T_FA_CLRBILLENTRY_D ADD (FISCLEARALL CHAR(1) DEFAULT '1' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_DEPRESUMASS') 
 CREATE TABLE T_FA_DEPRESUMASS (
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FASSTYPE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FASSID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_DEPREENTRY_D_SUM' AND KSQL_COL_NAME ='FORGDUTYID') 
 ALTER TABLE T_FA_DEPREENTRY_D_SUM ADD (FORGDUTYID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_DEPREMETHOD' AND KSQL_COL_NAME ='FCUSTOMFORMULA') 
 ALTER TABLE T_FA_DEPREMETHOD ADD (FCUSTOMFORMULA NVARCHAR(1000) );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_DEPREMETHOD' AND KSQL_COL_NAME ='FBASE') 
 ALTER TABLE T_FA_DEPREMETHOD ADD (FBASE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_DEPREMETHOD' AND KSQL_COL_NAME ='FDEDUCTRESIDUALVAL') 
 ALTER TABLE T_FA_DEPREMETHOD ADD (FDEDUCTRESIDUALVAL CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_DEPREMETHOD' AND KSQL_COL_NAME ='FTIMES') 
 ALTER TABLE T_FA_DEPREMETHOD ADD (FTIMES INT DEFAULT 1 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_CLEARRSBILL') 
 CREATE TABLE T_FA_CLEARRSBILL (
FID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(30) DEFAULT ' ' NOT NULL,
FRESTARTDATE DATETIME,
FRESTARTPERIODID BIGINT DEFAULT 0 NOT NULL,
FBILLSTATUS VARCHAR(50) DEFAULT 'A' NOT NULL,
FREASON NVARCHAR(255) DEFAULT ' ',
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FAUDITDATE DATETIME,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FA_CLEARRSBILLENTRY') 
 CREATE TABLE T_FA_CLEARRSBILLENTRY (
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,
FFINCARDID BIGINT DEFAULT 0 NOT NULL,
FCLEARQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FMEASUREUNITID BIGINT DEFAULT 0 NOT NULL,
FBASECURRENCYID BIGINT DEFAULT 0 NOT NULL,
FCLEARFARE DECIMAL(19,6) DEFAULT 0 NOT NULL,
FCLEARINCOME DECIMAL(19,6) DEFAULT 0 NOT NULL,
FASSETVALUE DECIMAL(19,6) DEFAULT 0 NOT NULL,
FADDUPDEPRE DECIMAL(19,6) DEFAULT 0 NOT NULL,
FDECVAL DECIMAL(19,6) DEFAULT 0 NOT NULL,
FNETVAL DECIMAL(19,6) DEFAULT 0 NOT NULL,
FNETAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FREMARK NVARCHAR(255) DEFAULT ' ',
FCLEARRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FISCLEARALL CHAR(1) DEFAULT '1' NOT NULL,
FCLEARID BIGINT DEFAULT 0 NOT NULL,
FCLEARENTRYID BIGINT DEFAULT 0 NOT NULL,
FCLEARPERIODID BIGINT DEFAULT 0 NOT NULL
);



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