-- 全球报销设置增加计税方式
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_WORLDCONFIG' AND KSQL_COL_NAME ='FCALWITHHOLDINGTAXTYPE')
ALTER TABLE T_ER_WORLDCONFIG ADD (FCALWITHHOLDINGTAXTYPE VARCHAR(10) DEFAULT ' ' NOT NULL );

-- 挂账付款申请单 增加预扣税额合计 往来方承担预扣税
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_APPLYPAYBILL' AND KSQL_COL_NAME ='FTOTALCURWHTAXAMOUNT')
ALTER TABLE T_ER_APPLYPAYBILL ADD (FTOTALCURWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_APPLYPAYBILL' AND KSQL_COL_NAME ='FTOTALWHTAXAMOUNT')
ALTER TABLE T_ER_APPLYPAYBILL ADD (FTOTALWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_APPLYPAYBILL' AND KSQL_COL_NAME ='FWHTAXBEAR')
ALTER TABLE T_ER_APPLYPAYBILL ADD (FWHTAXBEAR CHAR(1) DEFAULT '1' NOT NULL );


-- 立项单 增加预扣税额合计
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_APPLYPROJECTBILL_S' AND KSQL_COL_NAME ='FTOTALCURWHTAXAMOUNT')
ALTER TABLE T_ER_APPLYPROJECTBILL_S ADD (FTOTALCURWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_APPLYPROJECTBILL_S' AND KSQL_COL_NAME ='FTOTALWHTAXAMOUNT')
ALTER TABLE T_ER_APPLYPROJECTBILL_S ADD (FTOTALWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );

-- 合同台账 增加预扣税额合计
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_CONTRACTBILL_S' AND KSQL_COL_NAME ='FTOTALCURWHTAXAMOUNT')
ALTER TABLE T_ER_CONTRACTBILL_S ADD (FTOTALCURWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_CONTRACTBILL_S' AND KSQL_COL_NAME ='FTOTALWHTAXAMOUNT')
ALTER TABLE T_ER_CONTRACTBILL_S ADD (FTOTALWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );

-- 暂估 增加预扣税额合计
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_COSTESTIMATEBILL' AND KSQL_COL_NAME ='FTOTALCURWHTAXAMOUNT')
ALTER TABLE T_ER_COSTESTIMATEBILL ADD (FTOTALCURWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_COSTESTIMATEBILL' AND KSQL_COL_NAME ='FTOTALWHTAXAMOUNT')
ALTER TABLE T_ER_COSTESTIMATEBILL ADD (FTOTALWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );

-- 预付 增加预扣税额合计 往来方承担预扣税
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PREPAYBILL' AND KSQL_COL_NAME ='FTOTALCURWHTAXAMOUNT')
ALTER TABLE T_ER_PREPAYBILL ADD (FTOTALCURWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PREPAYBILL' AND KSQL_COL_NAME ='FWHTAXBEAR')
ALTER TABLE T_ER_PREPAYBILL ADD (FWHTAXBEAR CHAR(1) DEFAULT '1' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PREPAYBILL' AND KSQL_COL_NAME ='FTOTALWHTAXAMOUNT')
ALTER TABLE T_ER_PREPAYBILL ADD (FTOTALWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );

-- 预付单 预付信息增加冲销预扣税
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PREPAYBILLENTRY' AND KSQL_COL_NAME ='FCURWHTAXUSEDAMOUNT')
ALTER TABLE T_ER_PREPAYBILLENTRY ADD (FCURWHTAXUSEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PREPAYBILLENTRY' AND KSQL_COL_NAME ='FWHTAXUSEDAMOUNT')
ALTER TABLE T_ER_PREPAYBILLENTRY ADD (FWHTAXUSEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );


-- 对公报销 增加预扣税额合计(费用)  预扣税额合计(发票) 往来方承担预扣税
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMBILL_A' AND KSQL_COL_NAME ='FWHTAXBEAR')
ALTER TABLE T_ER_PUBREIMBILL_A ADD (FWHTAXBEAR CHAR(1) DEFAULT '1' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMBILL_A' AND KSQL_COL_NAME ='FTOTALCURINVWHTAXAMOUNT')
ALTER TABLE T_ER_PUBREIMBILL_A ADD (FTOTALCURINVWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMBILL_A' AND KSQL_COL_NAME ='FTOTALCURWHTAXAMOUNT')
ALTER TABLE T_ER_PUBREIMBILL_A ADD (FTOTALCURWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMBILL_A' AND KSQL_COL_NAME ='FTOTALWHTAXAMOUNT')
ALTER TABLE T_ER_PUBREIMBILL_A ADD (FTOTALWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMBILL_A' AND KSQL_COL_NAME ='FTOTALINVWHTAXAMOUNT')
ALTER TABLE T_ER_PUBREIMBILL_A ADD (FTOTALINVWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );

-- 费用预提 增加预扣税额合计
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_WITHHOLDINGBILL' AND KSQL_COL_NAME ='FTOTALCURWHTAXAMOUNT')
ALTER TABLE T_ER_WITHHOLDINGBILL ADD (FTOTALCURWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_WITHHOLDINGBILL' AND KSQL_COL_NAME ='FTOTALWHTAXAMOUNT')
ALTER TABLE T_ER_WITHHOLDINGBILL ADD (FTOTALWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );

-- 对公报销 增加发票税务明细表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_WHINVTAXDETAIL')
CREATE TABLE T_ER_WHINVTAXDETAIL (
                                     FWHINVDETAILID BIGINT DEFAULT 0 NOT NULL,
                                     FENTRYID BIGINT DEFAULT 0 NOT NULL,
                                     FSEQ INT DEFAULT 0 NOT NULL,
                                     FWHTAXCODE BIGINT DEFAULT 0 NOT NULL,
                                     FWHTAXCATEGORY BIGINT DEFAULT 0 NOT NULL,
                                     FWHTAXRATEBASE BIGINT DEFAULT 0 NOT NULL,
                                     FWHTAXRATEPERCENT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                     FWHTAXCURRENCY BIGINT DEFAULT 0 NOT NULL,
                                     FWHTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                     FWHOFFSETLOGO CHAR(1) DEFAULT '0' NOT NULL,
                                     FWHTAXDESC NVARCHAR(255) DEFAULT ' ' NOT NULL
);



-- 发票税务明细表主键
EXEC p_AlterPK 'PK_ER_WHINVTAXDETAIL', 'T_ER_WHINVTAXDETAIL', 'FWHINVDETAILID', '1';



