---单头字段
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSEBILLDS' AND KSQL_COL_NAME ='FREIMBURSETYPE')
 ALTER TABLE T_ER_REIMBURSEBILLDS ADD (FREIMBURSETYPE VARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSEBILLDS' AND KSQL_COL_NAME ='FPROJECTTYPE')
ALTER TABLE T_ER_REIMBURSEBILLDS ADD (FPROJECTTYPE BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSEBILLDS' AND KSQL_COL_NAME ='FBILLPAYERTYPE')
 ALTER TABLE T_ER_REIMBURSEBILLDS ADD (FBILLPAYERTYPE VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSEBILLDS' AND KSQL_COL_NAME ='FBILLPAYERID')
 ALTER TABLE T_ER_REIMBURSEBILLDS ADD (FBILLPAYERID BIGINT DEFAULT 0 NOT NULL );
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSEBILLDS' AND KSQL_COL_NAME ='FTRIPTYPEID')
 ALTER TABLE T_ER_REIMBURSEBILLDS ADD (FTRIPTYPEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSEBILLDS' AND KSQL_COL_NAME ='FBOOKEDDATE')
ALTER TABLE T_ER_REIMBURSEBILLDS ADD (FBOOKEDDATE DATETIME);
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSEBILLDS' AND KSQL_COL_NAME ='FISONACCOUNT')
 ALTER TABLE T_ER_REIMBURSEBILLDS ADD (FISONACCOUNT CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSEBILLDS' AND KSQL_COL_NAME ='FONACCOUNTAMOUNT')
ALTER TABLE T_ER_REIMBURSEBILLDS ADD (FONACCOUNTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSEBILLDS' AND KSQL_COL_NAME ='FSTDREIMBURSETYPE')
 ALTER TABLE T_ER_REIMBURSEBILLDS ADD (FSTDREIMBURSETYPE VARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSEBILLDS' AND KSQL_COL_NAME ='FASSETORGID')
 ALTER TABLE T_ER_REIMBURSEBILLDS ADD (FASSETORGID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSEBILLDS' AND KSQL_COL_NAME ='FASSETTYPE')
 ALTER TABLE T_ER_REIMBURSEBILLDS ADD (FASSETTYPE VARCHAR(20) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSEBILLDS' AND KSQL_COL_NAME ='FISSTDOVER')
 ALTER TABLE T_ER_REIMBURSEBILLDS ADD (FISSTDOVER CHAR(1) DEFAULT '0' NOT NULL );

 --分录字段
 --费用明细
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_REIMBILLDSEXP')
 CREATE TABLE T_ER_REIMBILLDSEXP (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FEXPENSEITEMID BIGINT DEFAULT 0 NOT NULL,
FHAPPENDATE DATETIME,
FEXCHANGERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORIAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENTRYCURRENCY BIGINT DEFAULT 0 NOT NULL,
FTAXRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEAPPROVEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEAPPROVECURRAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAPPROVETAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENTRYCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FREIMCTLDEPTID BIGINT DEFAULT 0 NOT NULL,
FENTRYCOSTDEPTID BIGINT DEFAULT 0 NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FREMARK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FORGIEXPEBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPORIUSEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURRREIMBURSEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREIMBURSEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FHIGHSEASONDAYCOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPUSEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEORIREPAYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEREPAYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEORIHASREIMAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEHASREIMAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAIRPORTCONSTRUCTIONFEE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FDEDUCTIBLETAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FITEMINOUTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSOURCEBILLID BIGINT DEFAULT 0 NOT NULL,
FSOURCEENTRYID BIGINT DEFAULT 0 NOT NULL,
FREIMBURSER BIGINT DEFAULT 0 NOT NULL,
FSTDENTRYCOSTCENTERID BIGINT DEFAULT 0 NOT NULL,
FENTRYPROJECTNO VARCHAR(30) DEFAULT ' ' NOT NULL,
FWBPAYTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
FENTRYCONTRACTNO VARCHAR(30) DEFAULT ' ' NOT NULL,
FENTRYCONTRACTNAME VARCHAR(200) DEFAULT ' ',
FINVOICENO_ENTRY VARCHAR(200) DEFAULT ' ',
FSERIALNO_ENTRY VARCHAR(200) DEFAULT ' ',
FINVOICELINK VARCHAR(200) DEFAULT ' ',
FOVERDESC NVARCHAR(500) DEFAULT ' ',
FITEMREASONFORTRANSFEROUT VARCHAR(200) DEFAULT ' ',
FEXPENSEGOODSNAME VARCHAR(200) DEFAULT ' ',
FORDERNUM VARCHAR(500) DEFAULT ' ',
FSTD_ENTRYCOSTCENTER BIGINT DEFAULT 0 NOT NULL,
FTAXCLASSCODE BIGINT DEFAULT 0 NOT NULL,
FSOURCEBILLTYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FQUOTETYPE CHAR(1) DEFAULT '0' NOT NULL,
FISOVER CHAR(1) DEFAULT '0' NOT NULL,
FIS_SPECIAL_INVOICE CHAR(1) DEFAULT '0' NOT NULL,
FSETTLEMENTTYPE CHAR(1) DEFAULT '1' NOT NULL,
FOFFSET CHAR(1) DEFAULT '0' NOT NULL,
FSTARTDATE DATETIME,
FENDDATE DATETIME ,
FFROMPLACEID BIGINT DEFAULT 0 NOT NULL,
FTRIPENTRYAREA BIGINT DEFAULT 0 NOT NULL,
FTOPLACEID BIGINT DEFAULT 0 NOT NULL,
FTRIPEXPENSEITEMID BIGINT DEFAULT 0 NOT NULL,
FVEHICLE VARCHAR(50) DEFAULT ' ' NOT NULL,
FTRIPDAY INT DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_ER_REIMBILLDSEXP', 'T_ER_REIMBILLDSEXP', 'FENTRYID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_REIMBILLDSEXP_ID') CREATE INDEX IDX_ER_REIMBILLDSEXP_ID ON T_ER_REIMBILLDSEXP (FID);

--座位等级
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_REIMDSSEATGRADE')
 CREATE TABLE T_ER_REIMDSSEATGRADE (
FPKID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_ER_REIMDSSEATGRADE', 'T_ER_REIMDSSEATGRADE', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_REIMDSSEATGRADE') CREATE INDEX IDX_ER_REIMDSSEATGRADE ON T_ER_REIMDSSEATGRADE ( FENTRYID,FBASEDATAID );

--出差人
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_REIMBURSEDSPARTNER')
 CREATE TABLE T_ER_REIMBURSEDSPARTNER (
FPKID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FBASEDATAID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_ER_REIMBURSEDSPARTNER', 'T_ER_REIMBURSEDSPARTNER', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_REIMDSPARTNER_FENTRYID') CREATE INDEX IDX_ER_REIMDSPARTNER_FENTRYID ON T_ER_REIMBURSEDSPARTNER ( FENTRYID );

--收款信息
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_REIMDSACCINFO')
 CREATE TABLE T_ER_REIMDSACCINFO (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FPAYMODEID BIGINT DEFAULT 0 NOT NULL,
FPAYERID BIGINT DEFAULT 0 NOT NULL,
FPAYERNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FPAYERBANKID BIGINT DEFAULT 0 NOT NULL,
FPAYERACCOUNT02 VARCHAR(100) DEFAULT ' ' NOT NULL,
FPAYERACCOUNT VARCHAR(100) DEFAULT ' ' NOT NULL,
FACCOUNTCURRENCY BIGINT DEFAULT 0 NOT NULL,
FEXCHANGERATE DECIMAL(19,6) DEFAULT 0 NOT NULL,
FORIAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FQUOTETYPE CHAR(1) DEFAULT '0' NOT NULL,
FAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FPAYERACCOUNT01 VARCHAR(100) DEFAULT ' ' NOT NULL,
FENTRYREPAYDATE DATETIME,
FACCBALANCEAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FORIACCBALANCEAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FORIACCNOTPAYAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FACCNOTPAYAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FBUILDEDAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FORIACCPAYEDAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FACCPAYEDAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FSUPPLIER BIGINT DEFAULT 0 NOT NULL,
FCUSTOMER BIGINT DEFAULT 0 NOT NULL,
FCASORG BIGINT DEFAULT 0 NOT NULL,
FPAYERTYPE VARCHAR(30) DEFAULT ' ' NOT NULL
);
EXEC P_ALTERPK 'PK_ER_REIMDSACCINFO', 'T_ER_REIMDSACCINFO', 'FENTRYID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_REIMDSACCINFO_FSEQ') CREATE INDEX IDX_ER_REIMDSACCINFO_FSEQ ON T_ER_REIMDSACCINFO ( FID ,FSEQ );