-- T_FA_ASSETSPLITBILL（拆分单）表
-- 业务类型
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITBILL' AND KSQL_COL_NAME IN ('FBIZTYPE')) 
 ALTER TABLE T_FA_ASSETSPLITBILL ADD (FBIZTYPE CHAR(1) DEFAULT 'A' NOT NULL );
-- 自动携带
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITBILL' AND KSQL_COL_NAME IN ('FISAUTOCARRY')) 
 ALTER TABLE T_FA_ASSETSPLITBILL ADD (FISAUTOCARRY CHAR(1) DEFAULT '1' NOT NULL );
-- 手工编码
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITBILL' AND KSQL_COL_NAME IN ('FISMANUALCODE')) 
 ALTER TABLE T_FA_ASSETSPLITBILL ADD (FISMANUALCODE CHAR(1) DEFAULT '0' NOT NULL );
-- 记账标识
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITBILL' AND KSQL_COL_NAME IN ('FVOUCHERFLAG')) 
 ALTER TABLE T_FA_ASSETSPLITBILL ADD (FVOUCHERFLAG CHAR(1) DEFAULT 'B' NOT NULL );

-- T_FA_ASSETSPLITENTRY_D（拆分后分录）表
-- 序号
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FINDEX')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FINDEX INT DEFAULT 1 NOT NULL );
-- 源卡片
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FISSOURCECARD')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FISSOURCECARD CHAR(1) DEFAULT ' ' NOT NULL );
-- 资产类别
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FASSETCATID')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FASSETCATID BIGINT DEFAULT 0 NOT NULL );
-- 条形码
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FBARCODE')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FBARCODE VARCHAR(30) DEFAULT ' ' NOT NULL );
-- 启用日期
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FREALACCOUNTDATE')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FREALACCOUNTDATE DATETIME );
-- 来源方式
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FORIGINMETHODID')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FORIGINMETHODID BIGINT DEFAULT 0 NOT NULL );
-- 供应商
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FSUPPLIERID')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FSUPPLIERID BIGINT DEFAULT 0 NOT NULL );
-- 存放地点
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FSTOREPLACEID')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FSTOREPLACEID BIGINT DEFAULT 0 NOT NULL );
-- 使用状态
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FUSESTATUSID')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FUSESTATUSID BIGINT DEFAULT 0 NOT NULL );
-- 使用人
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FHEADUSEPERSONID')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FHEADUSEPERSONID BIGINT DEFAULT 0 NOT NULL );
-- 使用部门
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FHEADUSEDEPTID')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FHEADUSEDEPTID BIGINT DEFAULT 0 NOT NULL );
-- 成本中心
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FCOSTCENTRERID')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FCOSTCENTRERID BIGINT DEFAULT 0 NOT NULL );
-- 产品线
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FPRODUCTLINEID')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FPRODUCTLINEID BIGINT DEFAULT 0 NOT NULL );
-- 附属设备
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FISFACILITY')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FISFACILITY CHAR(1) DEFAULT '0' NOT NULL );
-- 是否库存
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FISSTORAGED')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FISSTORAGED CHAR(1) DEFAULT '0' NOT NULL );
-- 折旧用途
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FDEPREUSEID')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FDEPREUSEID BIGINT DEFAULT 0 NOT NULL );
-- 财务入账日期
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FFINACCOUNTDATE')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FFINACCOUNTDATE DATETIME );
-- 预计使用期间
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FPREUSINGAMOUNT')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FPREUSINGAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL );
-- 累计折旧变动
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FMONTHACCUMDEPRECHG')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FMONTHACCUMDEPRECHG DECIMAL(23,10) DEFAULT 0 NOT NULL );
-- 实物json
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FREALJSON')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FREALJSON VARCHAR(10) DEFAULT ' ' NOT NULL );
-- 实物json（大文本）
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FREALJSON_TAG')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FREALJSON_TAG NCLOB );
-- 财务json
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FFINJSON')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FFINJSON VARCHAR(10) DEFAULT ' ' NOT NULL );
-- 财务json（大文本）
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY_D' AND KSQL_COL_NAME IN ('FFINJSON_TAG')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY_D ADD (FFINJSON_TAG NCLOB );

-- T_FA_ASSETSPLITENTRY（拆分前卡片）
-- 折旧用途（该字段pdm文件中之前版本已经有，现在需要重新生成一下sql加字段语句。）
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FA_ASSETSPLITENTRY' AND KSQL_COL_NAME IN ('FDEPREUSEID')) 
 ALTER TABLE T_FA_ASSETSPLITENTRY ADD (FDEPREUSEID BIGINT DEFAULT 0 NOT NULL ); 