/*2020/02/19 创建发票合并规则表*/

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_INVOICEMERGERULE') 
 CREATE TABLE T_ER_INVOICEMERGERULE (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER VARCHAR(30) DEFAULT ' ' NOT NULL,
FSTATUS VARCHAR(30) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE CHAR(1) DEFAULT '1' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FINVOICETYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FISMERGE CHAR(1) DEFAULT '1' NOT NULL,
FMERGETYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FITEMEQUAL CHAR(1) DEFAULT '0' NOT NULL,
FGOODCODEEQUAL CHAR(1) DEFAULT '0' NOT NULL,
FGOODNAMEEQUAL CHAR(1) DEFAULT '0' NOT NULL,
FTAXRATEEQUAL CHAR(1) DEFAULT '0' NOT NULL,
FTAXNUMEQUAL CHAR(1) DEFAULT '0' NOT NULL,
FBUYERNAMEEQUAL CHAR(1) DEFAULT '0' NOT NULL,
FSALERNAMEEQUAL CHAR(1) DEFAULT '0' NOT NULL,
FPASSENGEREQUAL CHAR(1) DEFAULT '0' NOT NULL,
FUSERDEFINERULE NVARCHAR(2000) DEFAULT ' ' NOT NULL,
FJS NVARCHAR(2000) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_INVOICEMERGERULE_L') 
 CREATE TABLE T_ER_INVOICEMERGERULE_L (
FPKID VARCHAR(30) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID NVARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL
);


 EXEC P_ALTERPK 'PK_T_ER_INVOICEMERGERULE', 'T_ER_INVOICEMERGERULE', 'FID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_INVOICEMERGE_INVOICETYPE') CREATE  CLUSTERED INDEX IDX_INVOICEMERGE_INVOICETYPE ON T_ER_INVOICEMERGERULE ( FINVOICETYPE );


 EXEC P_ALTERPK 'PK_T_ER_INVOICEMERGERULE_L', 'T_ER_INVOICEMERGERULE_L', 'FPKID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_INVOICEMERGERULE_L_FID') CREATE UNIQUE  CLUSTERED INDEX IDX_INVOICEMERGERULE_L_FID ON T_ER_INVOICEMERGERULE_L ( FID );
