/**火车结算单以及拆分表的建表语句 wenyue_chi**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRAINCHECKINGBILL') 
 CREATE TABLE T_ER_TRAINCHECKINGBILL (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS CHAR(1) DEFAULT 'A' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FORGID BIGINT DEFAULT 0 NOT NULL,
FSERVER VARCHAR(30) DEFAULT ' ' NOT NULL,
FOPERATIONTYPE CHAR(1) DEFAULT ' ' NOT NULL,
FHAPPENDDATE DATETIME,
FORDERID BIGINT DEFAULT 0 NOT NULL,
FCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FORDERDATE DATETIME,
FORDERNUM NVARCHAR(80) DEFAULT ' ' NOT NULL,
FORDERTYPE CHAR(1) DEFAULT ' ' NOT NULL,
FOABILLNUM NVARCHAR(80) DEFAULT ' ' NOT NULL,
FISBUSINESS CHAR(1) DEFAULT ' ' NOT NULL,
FPRODUCTTYPE CHAR(1) DEFAULT ' ' NOT NULL,
FBOOKEDNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSOURCEBOOKEDID BIGINT DEFAULT 0 NOT NULL,
FSETTLEMAIN BIGINT DEFAULT 0 NOT NULL,
FISBALANCE CHAR(1) DEFAULT ' ' NOT NULL,
FISRECONCILIATION CHAR(1) DEFAULT ' ' NOT NULL,
FORDERSTATUS VARCHAR(30) DEFAULT ' ' NOT NULL,
FSERVICEFEE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTOTALAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURRENCY BIGINT DEFAULT 0 NOT NULL,
FPAYBILLNUM NVARCHAR(80) DEFAULT ' ' NOT NULL,
FPAYBILLID BIGINT DEFAULT 0 NOT NULL,
FORDERTOTALAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBALANCEREMARK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FORDERORDERNUM NVARCHAR(80) DEFAULT ' ' NOT NULL,
FORDERFORMID NVARCHAR(80) DEFAULT ' ' NOT NULL,
FPUSHCOUNT INT DEFAULT 0 NOT NULL,
FORDERSERVER VARCHAR(30) DEFAULT ' ' NOT NULL,
FFORMID VARCHAR(30) DEFAULT ' ' NOT NULL,
FBILLSTATUSNAME VARCHAR(30) DEFAULT ' ' NOT NULL,
FCHECKINGBILLNUM NVARCHAR(80) DEFAULT ' ' NOT NULL,
FVOUCHERNUM NVARCHAR(80) DEFAULT ' ' NOT NULL,
FACCOUNTID VARCHAR(30) DEFAULT ' ' NOT NULL,
FISVOUCHER CHAR(1) DEFAULT '0' NOT NULL,
FTOTALTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FISDEDUCTIBLE CHAR(1) DEFAULT '0' NOT NULL,
FORDERSORT VARCHAR(30) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRAINCHECKINGBILL_A') 
 CREATE TABLE T_ER_TRAINCHECKINGBILL_A (
FID BIGINT DEFAULT 0 NOT NULL,
FPERIOD VARCHAR(30) DEFAULT ' ' NOT NULL,
FALLORDERBASEID BIGINT DEFAULT 0 NOT NULL,
FORDERDEDUCTRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSERVICEDEDUCTRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORDERAMOUNTTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSERVICEAMOUNTTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTOTALTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSETTLEMENTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPARENTORDERNUM VARCHAR(100) DEFAULT ' ' NOT NULL,
FPAYBILLSTATUS VARCHAR(100) DEFAULT ' ' NOT NULL,
FHASINVOICE CHAR(1) DEFAULT '0' NOT NULL,
FBATCHNO VARCHAR(100) DEFAULT ' ' NOT NULL,
FDEPARTADDRESS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FARRIVEADDRESS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDEPARTTIME DATETIME,
FARRIVETIME DATETIME
);

/** 结算单增加索引 start **/
 EXEC P_ALTERPK 'PK_T_ER_TRAINCHECKINGBILL', 'T_ER_TRAINCHECKINGBILL', 'FID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_TRAIN_BILLNO') CREATE INDEX IDX_ER_TRAIN_BILLNO ON T_ER_TRAINCHECKINGBILL ( FORDERNUM ,FSERVER );
 EXEC P_ALTERPK 'PK_T_ER_TRAINCHECKINGBILL_A', 'T_ER_TRAINCHECKINGBILL_A', 'FID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_TRAIN_A_ALORDID') CREATE INDEX IDX_ER_TRAIN_A_ALORDID ON T_ER_TRAINCHECKINGBILL_A ( FALLORDERBASEID );
/** 结算单增加索引 end **/


 
/** 结算单增加承担部门、乘客字段 start **/ 
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_VEHICLECHECKINGBILL' AND KSQL_COL_NAME ='FSETTLEDEPT') 
 ALTER TABLE T_ER_VEHICLECHECKINGBILL ADD (FSETTLEDEPT BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_HOTELCHECKINGBILL' AND KSQL_COL_NAME ='FSETTLEDEPT') 
 ALTER TABLE T_ER_HOTELCHECKINGBILL ADD (FSETTLEDEPT BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PLANECHECKINGBILL' AND KSQL_COL_NAME ='FSETTLEDEPT') 
 ALTER TABLE T_ER_PLANECHECKINGBILL ADD (FSETTLEDEPT BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_TRAINCHECKINGBILL' AND KSQL_COL_NAME ='FSETTLEDEPT') 
 ALTER TABLE T_ER_TRAINCHECKINGBILL ADD (FSETTLEDEPT BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_TRAINCHECKINGBILL' AND KSQL_COL_NAME ='FPASSEGERID') 
 ALTER TABLE T_ER_TRAINCHECKINGBILL ADD (FPASSEGERID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_TRAINCHECKINGBILL' AND KSQL_COL_NAME ='FPASSEGERNAME') 
 ALTER TABLE T_ER_TRAINCHECKINGBILL ADD (FPASSEGERNAME VARCHAR(100) DEFAULT ' ' NOT NULL );
 /** 结算单增加承担部门、乘客字段 end **/ 

 
 
  /** 结算单增加 编号 字段 start **/
  IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PLANECHECKINGBILL' AND KSQL_COL_NAME ='FBILLNO') 
 ALTER TABLE T_ER_PLANECHECKINGBILL ADD (FBILLNO VARCHAR(100) DEFAULT ' ' NOT NULL );
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_HOTELCHECKINGBILL' AND KSQL_COL_NAME ='FBILLNO') 
 ALTER TABLE T_ER_HOTELCHECKINGBILL ADD (FBILLNO VARCHAR(100) DEFAULT ' ' NOT NULL );
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_VEHICLECHECKINGBILL' AND KSQL_COL_NAME ='FBILLNO') 
 ALTER TABLE T_ER_VEHICLECHECKINGBILL ADD (FBILLNO VARCHAR(100) DEFAULT ' ' NOT NULL );
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_TRAINCHECKINGBILL' AND KSQL_COL_NAME ='FBILLNO') 
 ALTER TABLE T_ER_TRAINCHECKINGBILL ADD (FBILLNO VARCHAR(100) DEFAULT ' ' NOT NULL );
 /** 结算单增加 编号 字段 start **/
 
 /** 结算单编号 增加字段长度 start **/
 EXEC p_AlterColumn 'T_ER_VEHICLECHECKINGBILL', 'FBILLNO', 'NVARCHAR(100)', 'NOT NULL', '0100', ''' '''; 
 EXEC p_AlterColumn 'T_ER_ALLCHECKINGBILL', 'FBILLNO', 'NVARCHAR(100)', 'NOT NULL', '0100', ''' ''';
 EXEC p_AlterColumn 'T_ER_HOTELCHECKINGBILL', 'FBILLNO', 'NVARCHAR(100)', 'NOT NULL', '0100', ''' ''';
 EXEC p_AlterColumn 'T_ER_PLANECHECKINGBILL', 'FBILLNO', 'NVARCHAR(100)', 'NOT NULL', '0100', ''' ''';
 EXEC p_AlterColumn 'T_ER_TRAINCHECKINGBILL', 'FBILLNO', 'NVARCHAR(100)', 'NOT NULL', '0100', ''' ''';
 /** 结算单编号 增加字段长度 end **/