/*** 费用标准功能新增的单据字段 -- 费用报销单单头+分录 **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FTREATTYPE') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FTREATTYPE NVARCHAR(10) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FTREATWAY') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FTREATWAY NVARCHAR(10) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FMEETTYPE') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FMEETTYPE NVARCHAR(10) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FMEETLEVEL') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FMEETLEVEL NVARCHAR(10) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FCITYAREA') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FCITYAREA BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FREIMBURSELEVEL') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FREIMBURSELEVEL BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FFEESTANDARDAMT') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FFEESTANDARDAMT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FFEESTANDARDDESC') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FFEESTANDARDDESC NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FTREATNUM') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FTREATNUM INT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FESCORTNUM') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FESCORTNUM INT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FGOODSNUM') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FGOODSNUM INT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FDAYSNUM') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FDAYSNUM INT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FCONTROLAMT') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FCONTROLAMT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FISOVER') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FISOVER CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FOVERDESC') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FOVERDESC NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FFEESTANDID') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FFEESTANDID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_DAILYREIMBURSEBILL' AND KSQL_COL_NAME ='FREIMBURSETYPE') 
 ALTER TABLE T_ER_DAILYREIMBURSEBILL ADD (FREIMBURSETYPE VARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_DAILYREIMBURSEBILL' AND KSQL_COL_NAME ='FISOVER') 
 ALTER TABLE T_ER_DAILYREIMBURSEBILL ADD (FISOVER CHAR(1) DEFAULT '0' NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_DAILYAPPLYBILL' AND KSQL_COL_NAME ='FSTDREIMBURSETYPE') 
 ALTER TABLE T_ER_DAILYAPPLYBILL ADD (FSTDREIMBURSETYPE VARCHAR(30) DEFAULT ' ' NOT NULL );

/*** 报销提醒的长度增加到50 **/
EXEC p_AlterColumn 'T_ER_TIPSINFO', 'FBILLTYPE', 'VARCHAR(50)', 'NOT NULL', '0100', ''' ''';


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

 EXEC P_ALTERPK 'PK_T_ER_STANDARD_ENTRY', 'T_ER_STANDARD_ENTRY', 'FENTRYID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_STANDENTRY_FID') CREATE INDEX IDX_ER_STANDENTRY_FID ON T_ER_STANDARD_ENTRY ( FID );



