/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\ER_table.sql **/

/**创建火车订单表 start**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRAINBILL') 
 CREATE TABLE T_ER_TRAINBILL (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS CHAR(1) DEFAULT ' ' 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,
FORDERDATE DATETIME,
FORDERNUM NVARCHAR(80) DEFAULT ' ' NOT NULL,
FORDERTYPE CHAR(1) DEFAULT ' ' NOT NULL,
FOABILLNUM NVARCHAR(80) DEFAULT ' ' NOT NULL,
FTRIPID VARCHAR(30) DEFAULT ' ' NOT NULL,
FISBUSINESS CHAR(1) DEFAULT ' ' NOT NULL,
FPRODUCTTYPE CHAR(1) DEFAULT ' ' NOT NULL,
FPASSEGERID BIGINT DEFAULT 0 NOT NULL,
FSOURCEBOOKEDID BIGINT DEFAULT 0 NOT NULL,
FPASSEGERNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FBOOKEDNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FBOOKEDCOMPANY BIGINT DEFAULT 0 NOT NULL,
FBOOKEDDEPT BIGINT DEFAULT 0 NOT NULL,
FORIORDERNUM NVARCHAR(80) DEFAULT ' ' NOT NULL,
FHAPPENDDATE DATETIME,
FPARENTORDERNUM NVARCHAR(80) DEFAULT ' ' NOT NULL,
FEXPCOMMITDEPNUM BIGINT DEFAULT 0 NOT NULL,
FEXPCOMMITCOMNUM BIGINT DEFAULT 0 NOT NULL,
FCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FOVERDESC NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPAYBILLNUM NVARCHAR(80) DEFAULT ' ' NOT NULL,
FISCONFIRM CHAR(1) DEFAULT ' ' NOT NULL,
FISREIMBURSE CHAR(1) DEFAULT ' ' NOT NULL,
FISRECONCILIATION CHAR(1) DEFAULT ' ' NOT NULL,
FISVERIFIED CHAR(1) DEFAULT ' ' NOT NULL,
FISAPPROVE CHAR(1) DEFAULT ' ' NOT NULL,
FNEEDBILLING CHAR(1) DEFAULT ' ' NOT NULL,
FOPERATIONTYPE CHAR(1) DEFAULT ' ' NOT NULL,
FISADDINTEGRAL CHAR(1) DEFAULT ' ' NOT NULL,
FORDERSTATUS VARCHAR(30) DEFAULT ' ' NOT NULL,
FPAYMENTSTATUS 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,
FDEALAMOUNT 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_TRAINBILL_A') 
 CREATE TABLE T_ER_TRAINBILL_A (
FID BIGINT DEFAULT 0 NOT NULL,
FDEPARTADDRESS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FARRIVEADDRESS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FVENDORNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FTRAINSEAT CHAR(1) DEFAULT ' ' NOT NULL,
FDEPARTTIME DATETIME,
FARRIVETIME DATETIME
);
/** 创建火车订单表 end **/


/** 火车订单增加索引 start **/
EXEC P_ALTERPK 'PK_T_ER_TRAINBILL', 'T_ER_TRAINBILL', 'FID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_TRAINBILL_FORDERNUM') CREATE INDEX IDX_ER_TRAINBILL_FORDERNUM ON T_ER_TRAINBILL ( FOABILLNUM ,FORDERNUM );

EXEC P_ALTERPK 'PK_T_ER_TRAINBILL_A', 'T_ER_TRAINBILL_A', 'FID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_TRAINBILL_A_INDEX') CREATE INDEX IDX_ER_TRAINBILL_A_INDEX ON T_ER_TRAINBILL_A ( FDEPARTTIME );
/** 火车订单增加索引 start **/



/** 用车、火车增加乘客部门字段 start **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_TRAINBILL' AND KSQL_COL_NAME ='FPASSEGERDEPT') 
 ALTER TABLE T_ER_TRAINBILL ADD (FPASSEGERDEPT BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_VEHICLEBILL' AND KSQL_COL_NAME ='FPASSEGERDEPT') 
 ALTER TABLE T_ER_VEHICLEBILL ADD (FPASSEGERDEPT BIGINT DEFAULT 0 NOT NULL ); 
/** 用车、火车增加乘客部门字段 end **/ 

/** 订单编号增加字段 start **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PLANEBILL' AND KSQL_COL_NAME ='FBILLNO') 
 ALTER TABLE T_ER_PLANEBILL ADD (FBILLNO VARCHAR(100) DEFAULT ' ' NOT NULL );
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_HOTELBILL' AND KSQL_COL_NAME ='FBILLNO') 
 ALTER TABLE T_ER_HOTELBILL ADD (FBILLNO VARCHAR(100) DEFAULT ' ' NOT NULL );
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_VEHICLEBILL' AND KSQL_COL_NAME ='FBILLNO') 
 ALTER TABLE T_ER_VEHICLEBILL ADD (FBILLNO VARCHAR(100) DEFAULT ' ' NOT NULL );
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_TRAINBILL' AND KSQL_COL_NAME ='FBILLNO') 
 ALTER TABLE T_ER_TRAINBILL ADD (FBILLNO VARCHAR(100) DEFAULT ' ' NOT NULL );
 /** 订单编号增加字段 end **/
 
 
/** 订单编号、票状态增加字段长度 start **/
 EXEC p_AlterColumn 'T_ER_HOTELBILL', 'FBILLNO', 'NVARCHAR(100)', 'NOT NULL', '0100', ''' ''';
 EXEC p_AlterColumn 'T_ER_PLANEBILL', 'FBILLNO', 'NVARCHAR(100)', 'NOT NULL', '0100', ''' ''';
 EXEC p_AlterColumn 'T_ER_PLANEBILL', 'FTICKETSTATUS', 'VARCHAR(100)', 'NOT NULL', '0001', '''UNUSED''';
 EXEC p_AlterColumn 'T_ER_VEHICLEBILL', 'FBILLNO', 'NVARCHAR(100)', 'NOT NULL', '0100', ''' ''';
 EXEC p_AlterColumn 'T_ER_TRAINBILL', 'FBILLNO', 'NVARCHAR(100)', 'NOT NULL', '0100', ''' ''';
 /** 订单编号、票状态增加字段长度 end **/
 
 
/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\ER_table.sql **/
