/*商旅付款申请点添加发票相关的分录表*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_INVOICEINFOCP') 
 CREATE TABLE T_ER_INVOICEINFOCP (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FINVOICETYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FINVOICENO NVARCHAR(129) DEFAULT ' ' NOT NULL,
FINVOICECODE NVARCHAR(129) DEFAULT ' ' NOT NULL,
FTOTALAMOUNT DECIMAL(23,10) DEFAULT 0.0000000000 NOT NULL,
FTAXRATE DECIMAL(23,10) DEFAULT 0.0000000000 NOT NULL,
FTAXAMOUNT DECIMAL(23,10) DEFAULT 0.0000000000 NOT NULL,
FSERIALNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FREMARK NVARCHAR(255),
FBUYERNAME NVARCHAR(80) DEFAULT ' ' NOT NULL,
FMAKEOUTCOMPNAME NVARCHAR(80) DEFAULT ' ' NOT NULL,
FCOUNT INT DEFAULT 0 NOT NULL,
FFROMINVOICECLOUD CHAR(1) DEFAULT '0' NOT NULL,
FBUYERORGID BIGINT DEFAULT 0 NOT NULL,
FOFFSET CHAR(1) DEFAULT '0' NOT NULL,
FOFFSETAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINOUTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FVALIDATEMESSAGE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FINVOICEDATE DATETIME,
FPASSENGERNAME NVARCHAR(255),
FAIRPORTCONSTRUCTIONFEE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FALLTAXRATE VARCHAR(100) DEFAULT ' ' NOT NULL,
FINVOICEFROM VARCHAR(30) DEFAULT '1' NOT NULL,
FISMAPEXPENSE CHAR(1) DEFAULT '1' NOT NULL,
FFROMCITY NVARCHAR(50) DEFAULT ' ' NOT NULL,
FTOCITY NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_INVOICEITEMCP') 
 CREATE TABLE T_ER_INVOICEITEMCP (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FITEMENTRYID BIGINT DEFAULT 0 NOT NULL,
FINVOICEHEADENTRYID BIGINT DEFAULT 0 NOT NULL,
FUNITPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXCLUDEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSPECMODEL NVARCHAR(50) DEFAULT ' ' NOT NULL,
FUNIT NVARCHAR(50) DEFAULT ' ' NOT NULL,
FTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FGOODSCODE VARCHAR(255) DEFAULT ' ' NOT NULL,
FNUM DECIMAL(23,10) DEFAULT 0 NOT NULL,
FGOODSNAME VARCHAR(255) DEFAULT ' ' NOT NULL,
FINVOICEITEMOFFSET CHAR(1) DEFAULT '0' NOT NULL
);


 EXEC P_ALTERPK 'PK_T_ER_INVOICEINFOCP', 'T_ER_INVOICEINFOCP', 'FENTRYID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOICEINFOCP_FSEQ') CREATE  CLUSTERED INDEX IDX_ER_INVOICEINFOCP_FSEQ ON T_ER_INVOICEINFOCP ( FID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOICECP_QUERY') CREATE INDEX IDX_ER_INVOICECP_QUERY ON T_ER_INVOICEINFOCP ( FSERIALNO );


 EXEC P_ALTERPK 'PK_T_ER_INVOICEITEMCP', 'T_ER_INVOICEITEMCP', 'FENTRYID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOICEITEMCP_ITEMENTRY') CREATE INDEX IDX_ER_INVOICEITEMCP_ITEMENTRY ON T_ER_INVOICEITEMCP ( FITEMENTRYID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOICEITEMCP_INVHEAD') CREATE INDEX IDX_ER_INVOICEITEMCP_INVHEAD ON T_ER_INVOICEITEMCP ( FINVOICEHEADENTRYID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOICEITEMCP_FID') CREATE  CLUSTERED INDEX IDX_ER_INVOICEITEMCP_FID ON T_ER_INVOICEITEMCP ( FID );