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

-- 发票信息分录增加 开票方税号 字段
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEINFO' AND KSQL_COL_NAME ='FSALERTAXNO') 
 ALTER TABLE T_ER_INVOICEINFO ADD (FSALERTAXNO NVARCHAR(50) DEFAULT ' ' NOT NULL );

 -- 发票信息分录增加 数量 字段
   IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEINFO' AND KSQL_COL_NAME ='FNUM') 
 ALTER TABLE T_ER_INVOICEINFO ADD (FNUM 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 ='FUNITPRICE') 
 ALTER TABLE T_ER_INVOICEINFO ADD (FUNITPRICE 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 ='FSPECMODEL') 
 ALTER TABLE T_ER_INVOICEINFO ADD (FSPECMODEL NVARCHAR(50) DEFAULT ' ' NOT NULL );
 -- 发票信息分录增加 单位 字段
  IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEINFO' AND KSQL_COL_NAME ='FUNIT') 
 ALTER TABLE T_ER_INVOICEINFO ADD (FUNIT NVARCHAR(50) DEFAULT ' ' NOT NULL );

 /*发票明细分录添加 开票方税号 字段*/
  IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEITEM' AND KSQL_COL_NAME ='FSALERTAXNO') 
 ALTER TABLE T_ER_INVOICEITEM ADD (FSALERTAXNO NVARCHAR(50) DEFAULT ' ' NOT NULL );


 -- 商旅付款申请单 的两张表和其他报销单不一样，上述的字段都加一遍。
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEINFOCP' AND KSQL_COL_NAME ='FSALERTAXNO') 
ALTER TABLE T_ER_INVOICEINFOCP ADD (FSALERTAXNO NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEINFOCP' AND KSQL_COL_NAME ='FNUM') 
ALTER TABLE T_ER_INVOICEINFOCP ADD (FNUM DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEINFOCP' AND KSQL_COL_NAME ='FUNITPRICE') 
ALTER TABLE T_ER_INVOICEINFOCP ADD (FUNITPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEINFOCP' AND KSQL_COL_NAME ='FSPECMODEL') 
ALTER TABLE T_ER_INVOICEINFOCP ADD (FSPECMODEL NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEINFOCP' AND KSQL_COL_NAME ='FUNIT') 
ALTER TABLE T_ER_INVOICEINFOCP ADD (FUNIT NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_INVOICEITEMCP' AND KSQL_COL_NAME ='FSALERTAXNO') 
ALTER TABLE T_ER_INVOICEITEMCP ADD (FSALERTAXNO NVARCHAR(50) DEFAULT ' ' NOT NULL );

 -- 对公费用报销单 的两张表和其他报销单不一样，上述的字段都加一遍。
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMINVOICEINFO' AND KSQL_COL_NAME ='FSALERTAXNO') 
ALTER TABLE T_ER_PUBREIMINVOICEINFO ADD (FSALERTAXNO NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMINVOICEINFO' AND KSQL_COL_NAME ='FNUM') 
ALTER TABLE T_ER_PUBREIMINVOICEINFO ADD (FNUM DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMINVOICEINFO' AND KSQL_COL_NAME ='FUNITPRICE') 
ALTER TABLE T_ER_PUBREIMINVOICEINFO ADD (FUNITPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMINVOICEINFO' AND KSQL_COL_NAME ='FSPECMODEL') 
ALTER TABLE T_ER_PUBREIMINVOICEINFO ADD (FSPECMODEL NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMINVOICEINFO' AND KSQL_COL_NAME ='FUNIT') 
ALTER TABLE T_ER_PUBREIMINVOICEINFO ADD (FUNIT NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMINVOICEITEM' AND KSQL_COL_NAME ='FSALERTAXNO') 
ALTER TABLE T_ER_PUBREIMINVOICEITEM ADD (FSALERTAXNO NVARCHAR(50) DEFAULT ' ' NOT NULL );

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