/* 发票信息分录增加对平 **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEINFO' AND KSQL_COL_NAME ='FINVOICEITEMEQUAL')
ALTER TABLE T_ER_INVOICEINFO ADD (FINVOICEITEMEQUAL CHAR(1) DEFAULT '1' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEINFOCP' AND KSQL_COL_NAME ='FINVOICEITEMEQUAL')
ALTER TABLE T_ER_INVOICEINFOCP ADD (FINVOICEITEMEQUAL CHAR(1) DEFAULT '1' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMINVOICEINFO' AND KSQL_COL_NAME ='FINVOICEITEMEQUAL')
ALTER TABLE T_ER_PUBREIMINVOICEINFO ADD (FINVOICEITEMEQUAL CHAR(1) DEFAULT '1' NOT NULL );



/* 发票明细分录增加发票类型,发票号码,发票币别,价税合计,开票日期 **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEITEM' AND KSQL_COL_NAME ='FINVOICETYPE')
ALTER TABLE T_ER_INVOICEITEM ADD (FINVOICETYPE BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEITEM' AND KSQL_COL_NAME ='FINVOICENO')
ALTER TABLE T_ER_INVOICEITEM ADD (FINVOICENO NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEITEM' AND KSQL_COL_NAME ='FINVOICECURRENCY')
ALTER TABLE T_ER_INVOICEITEM ADD (FINVOICECURRENCY BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEITEM' AND KSQL_COL_NAME ='FINVOICEDATE')
ALTER TABLE T_ER_INVOICEITEM ADD (FINVOICEDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEITEM' AND KSQL_COL_NAME ='FTOTALAMOUNT')
ALTER TABLE T_ER_INVOICEITEM ADD (FTOTALAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEITEMCP' AND KSQL_COL_NAME ='FINVOICETYPE')
ALTER TABLE T_ER_INVOICEITEMCP ADD (FINVOICETYPE BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEITEMCP' AND KSQL_COL_NAME ='FINVOICENO')
ALTER TABLE T_ER_INVOICEITEMCP ADD (FINVOICENO NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEITEMCP' AND KSQL_COL_NAME ='FINVOICECURRENCY')
ALTER TABLE T_ER_INVOICEITEMCP ADD (FINVOICECURRENCY BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEITEMCP' AND KSQL_COL_NAME ='FINVOICEDATE')
ALTER TABLE T_ER_INVOICEITEMCP ADD (FINVOICEDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEITEMCP' AND KSQL_COL_NAME ='FTOTALAMOUNT')
ALTER TABLE T_ER_INVOICEITEMCP ADD (FTOTALAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMINVOICEITEM' AND KSQL_COL_NAME ='FINVOICETYPE')
ALTER TABLE T_ER_PUBREIMINVOICEITEM ADD (FINVOICETYPE BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMINVOICEITEM' AND KSQL_COL_NAME ='FINVOICENO')
ALTER TABLE T_ER_PUBREIMINVOICEITEM ADD (FINVOICENO NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMINVOICEITEM' AND KSQL_COL_NAME ='FINVOICECURRENCY')
ALTER TABLE T_ER_PUBREIMINVOICEITEM ADD (FINVOICECURRENCY BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMINVOICEITEM' AND KSQL_COL_NAME ='FINVOICEDATE')
ALTER TABLE T_ER_PUBREIMINVOICEITEM ADD (FINVOICEDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMINVOICEITEM' AND KSQL_COL_NAME ='FTOTALAMOUNT')
ALTER TABLE T_ER_PUBREIMINVOICEITEM ADD (FTOTALAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );

-- 差旅 对公 费用发票明细  增加单头税率字段
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEITEM' AND KSQL_COL_NAME ='FINVOICETAXRATE')
ALTER TABLE T_ER_INVOICEITEM ADD (FINVOICETAXRATE NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMINVOICEITEM' AND KSQL_COL_NAME ='FINVOICETAXRATE')
ALTER TABLE T_ER_PUBREIMINVOICEITEM ADD (FINVOICETAXRATE NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_NINVOICEITEM' AND KSQL_COL_NAME ='FINVOICETAXRATE')
ALTER TABLE T_ER_NINVOICEITEM ADD (FINVOICETAXRATE NVARCHAR(255) DEFAULT ' ' NOT NULL );

-- 差旅 对公 费用发票明细  增加单头税率 单头税额字段
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEITEM' AND KSQL_COL_NAME ='FINVOICETAXAMOUNT')
ALTER TABLE T_ER_INVOICEITEM ADD (FINVOICETAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMINVOICEITEM' AND KSQL_COL_NAME ='FINVOICETAXAMOUNT')
ALTER TABLE T_ER_PUBREIMINVOICEITEM ADD (FINVOICETAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_NINVOICEITEM' AND KSQL_COL_NAME ='FINVOICETAXAMOUNT')
ALTER TABLE T_ER_NINVOICEITEM ADD (FINVOICETAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );

-- 差旅 费用 发票信息增加多税率信息字段
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEINFO' AND KSQL_COL_NAME ='FTAXDETAILS')
ALTER TABLE T_ER_INVOICEINFO ADD (FTAXDETAILS NVARCHAR(500) DEFAULT ' ' NOT NULL );


