/** 个人额度表 添加数据来源和来源单据ID **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSEAMOUNT' AND KSQL_COL_NAME ='FWBSRCBILLTYPE') 
 ALTER TABLE T_ER_REIMBURSEAMOUNT ADD (FWBSRCBILLTYPE VARCHAR(25) DEFAULT 'er_reimburseamount' NOT NULL );

 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSEAMOUNT' AND KSQL_COL_NAME ='FWBSRCBILLID')
  ALTER TABLE T_ER_REIMBURSEAMOUNT ADD (FWBSRCBILLID BIGINT DEFAULT 0 NOT NULL );
 
 /**额度申请单 新建表 **/
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_REIMCTLAPPLYBILL') 
 CREATE TABLE T_ER_REIMCTLAPPLYBILL (
FID BIGINT DEFAULT 0 NOT NULL,
FAMOUNTTYPE CHAR(1) DEFAULT '1' NOT NULL,
FCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FEMPLOYEE BIGINT DEFAULT 0 NOT NULL,
FEXPENSEITEM BIGINT DEFAULT 0 NOT NULL,
FCURRENCY BIGINT DEFAULT 0 NOT NULL,
FTOTALAMOUNT DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FJANUARYAMOUNT DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FFEBRUARYAMOUNT DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FMARCHAMOUNT DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FAPPLIERID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FTEL VARCHAR(30) DEFAULT ' ' NOT NULL,
FFORMID VARCHAR(30) DEFAULT ' ' NOT NULL,
FAPPLYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAPPROVEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FIMAGENUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FATTACHMENTACOUNT BIGINT DEFAULT 0 NOT NULL,
FNEXTAUDITOR NVARCHAR(100) DEFAULT ' ' NOT NULL,
FAPPLIERPOSITIONSTR NVARCHAR(100) DEFAULT ' ' NOT NULL,
FAPRILAMOUNT DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FMAYAMOUNT DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FJUNEAMOUNT DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FJULYAMOUNT DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FAUGUSTAMOUNT DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FSEPTEMBERAMOUNT DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FOCTOBERAMOUNT DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FNOVEMBERAMOUNT DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FDECEMBERAMOUNT DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FQUARTER1 DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQUARTER2 DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQUARTER3 DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQUARTER4 DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FMODIFYTIME DATETIME,
FCREATETIME DATETIME,
FBIZDATE DATETIME,
FDESCRIPTION NVARCHAR(1000) DEFAULT ' ' NOT NULL,
FEFFECTIVEDATE DATETIME,
FDUEDATE DATETIME,
FREIMBURSECONTROLCOMANY BIGINT DEFAULT 0 NOT NULL,
FSTDBILLTYPE BIGINT DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_REIMCTLAPPLYBILL', 'T_ER_REIMCTLAPPLYBILL', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_CTLAPPLY_FCREATORID') CREATE INDEX IDX_ER_CTLAPPLY_FCREATORID ON T_ER_REIMCTLAPPLYBILL ( FCREATORID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_CTLAPPLY_FBILLSTATUS') CREATE INDEX IDX_ER_CTLAPPLY_FBILLSTATUS ON T_ER_REIMCTLAPPLYBILL ( FBILLSTATUS );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_CTLAPPLY_FAPPLIERID') CREATE INDEX IDX_ER_CTLAPPLY_FAPPLIERID ON T_ER_REIMCTLAPPLYBILL ( FAPPLIERID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_CTLAPPLY_FCOMPANYID') CREATE INDEX IDX_ER_CTLAPPLY_FCOMPANYID ON T_ER_REIMCTLAPPLYBILL ( FCOMPANYID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_CTLAPPLY_BIZDATE_BILLNO') CREATE INDEX IDX_ER_CTLAPPLY_BIZDATE_BILLNO ON T_ER_REIMCTLAPPLYBILL ( FBILLNO ,FBIZDATE );

 /**额度申请单 新建多语言表 **/
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_REIMCTLAPPLYBILL_L') 
 CREATE TABLE T_ER_REIMCTLAPPLYBILL_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FAPPLIERPOSITIONSTR NVARCHAR(100) DEFAULT ' ' NOT NULL
);


 EXEC P_ALTERPK 'PK_T_ER_REIMCTLAPPLYBILL_L', 'T_ER_REIMCTLAPPLYBILL_L', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_CTLAPPLYBILL_L_FLCID') CREATE INDEX IDX_ER_CTLAPPLYBILL_L_FLCID ON T_ER_REIMCTLAPPLYBILL_L ( FID ,FLOCALEID );
 