/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\IM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSDIRBILL' AND KSQL_COL_NAME ='FISCHARGEOFF') 
 ALTER TABLE T_IM_TRANSDIRBILL ADD (FISCHARGEOFF CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSDIRBILL' AND KSQL_COL_NAME ='FISCHARGEOFFED') 
 ALTER TABLE T_IM_TRANSDIRBILL ADD (FISCHARGEOFFED CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_OTHEROUTBILL' AND KSQL_COL_NAME ='FISCHARGEOFF') 
 ALTER TABLE T_IM_OTHEROUTBILL ADD (FISCHARGEOFF CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_OTHEROUTBILL' AND KSQL_COL_NAME ='FISCHARGEOFFED') 
 ALTER TABLE T_IM_OTHEROUTBILL ADD (FISCHARGEOFFED CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_OTHERINBILL' AND KSQL_COL_NAME ='FISCHARGEOFF') 
 ALTER TABLE T_IM_OTHERINBILL ADD (FISCHARGEOFF CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_OTHERINBILL' AND KSQL_COL_NAME ='FISCHARGEOFFED') 
 ALTER TABLE T_IM_OTHERINBILL ADD (FISCHARGEOFFED CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURRECBILL' AND KSQL_COL_NAME ='FISCHARGEOFF') 
 ALTER TABLE T_IM_PURRECBILL ADD (FISCHARGEOFF CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURRECBILL' AND KSQL_COL_NAME ='FISCHARGEOFFED') 
 ALTER TABLE T_IM_PURRECBILL ADD (FISCHARGEOFFED CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_ADJUSTBILL' AND KSQL_COL_NAME ='FISCHARGEOFF') 
 ALTER TABLE T_IM_ADJUSTBILL ADD (FISCHARGEOFF CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_ADJUSTBILL' AND KSQL_COL_NAME ='FISCHARGEOFFED') 
 ALTER TABLE T_IM_ADJUSTBILL ADD (FISCHARGEOFFED CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_ASSEMBBILL' AND KSQL_COL_NAME ='FISCHARGEOFF') 
 ALTER TABLE T_IM_ASSEMBBILL ADD (FISCHARGEOFF CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_ASSEMBBILL' AND KSQL_COL_NAME ='FISCHARGEOFFED') 
 ALTER TABLE T_IM_ASSEMBBILL ADD (FISCHARGEOFFED CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_LOCATIONTRANSFER' AND KSQL_COL_NAME ='FISCHARGEOFF') 
 ALTER TABLE T_IM_LOCATIONTRANSFER ADD (FISCHARGEOFF CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_LOCATIONTRANSFER' AND KSQL_COL_NAME ='FISCHARGEOFFED') 
 ALTER TABLE T_IM_LOCATIONTRANSFER ADD (FISCHARGEOFFED CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_DISASSEMBLEBILL' AND KSQL_COL_NAME ='FISCHARGEOFF') 
 ALTER TABLE T_IM_DISASSEMBLEBILL ADD (FISCHARGEOFF CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_DISASSEMBLEBILL' AND KSQL_COL_NAME ='FISCHARGEOFFED') 
 ALTER TABLE T_IM_DISASSEMBLEBILL ADD (FISCHARGEOFFED CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_MREQOUTBILL' AND KSQL_COL_NAME ='FISCHARGEOFF') 
 ALTER TABLE T_IM_MREQOUTBILL ADD (FISCHARGEOFF CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_MREQOUTBILL' AND KSQL_COL_NAME ='FISCHARGEOFFED') 
 ALTER TABLE T_IM_MREQOUTBILL ADD (FISCHARGEOFFED CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURINBILL' AND KSQL_COL_NAME ='FISCHARGEOFF') 
 ALTER TABLE T_IM_PURINBILL ADD (FISCHARGEOFF CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURINBILL' AND KSQL_COL_NAME ='FISCHARGEOFFED') 
 ALTER TABLE T_IM_PURINBILL ADD (FISCHARGEOFFED CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_SALOUTBILL' AND KSQL_COL_NAME ='FISCHARGEOFF') 
 ALTER TABLE T_IM_SALOUTBILL ADD (FISCHARGEOFF CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_SALOUTBILL' AND KSQL_COL_NAME ='FISCHARGEOFFED') 
 ALTER TABLE T_IM_SALOUTBILL ADD (FISCHARGEOFFED CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSINBILL' AND KSQL_COL_NAME ='FISCHARGEOFF') 
 ALTER TABLE T_IM_TRANSINBILL ADD (FISCHARGEOFF CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSINBILL' AND KSQL_COL_NAME ='FISCHARGEOFFED') 
 ALTER TABLE T_IM_TRANSINBILL ADD (FISCHARGEOFFED CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSOUTBILL' AND KSQL_COL_NAME ='FISCHARGEOFF') 
 ALTER TABLE T_IM_TRANSOUTBILL ADD (FISCHARGEOFF CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSOUTBILL' AND KSQL_COL_NAME ='FISCHARGEOFFED') 
 ALTER TABLE T_IM_TRANSOUTBILL ADD (FISCHARGEOFFED CHAR(1) DEFAULT '0' NOT NULL );
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PRODUCTINBILL' AND KSQL_COL_NAME ='FISCHARGEOFF') 
 ALTER TABLE T_IM_PRODUCTINBILL ADD (FISCHARGEOFF CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PRODUCTINBILL' AND KSQL_COL_NAME ='FISCHARGEOFFED') 
 ALTER TABLE T_IM_PRODUCTINBILL ADD (FISCHARGEOFFED CHAR(1) DEFAULT '0' NOT NULL );

 
-- 冲销日志脚本
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_CHARGEAGAINST_LOG') 
 CREATE TABLE T_IM_CHARGEAGAINST_LOG (
FID BIGINT DEFAULT 0 NOT NULL,
FCASOURCEBILLNO  NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCASTATUS  CHAR(1) DEFAULT ' ' NOT NULL,
FCABILLFAILCAUSE NVARCHAR(2000) DEFAULT ' ' NOT NULL,
FCREATEDATE DATETIME,
FCREATOR BIGINT DEFAULT 0 NOT NULL,
FCASOURCEID BIGINT DEFAULT 0 NOT NULL,
FCASOURCETYPE NVARCHAR(50) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_CHARGEAGAINST_LOG_E') 
 CREATE TABLE T_IM_CHARGEAGAINST_LOG_E (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FSOURCEBILLNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSOURCEID BIGINT DEFAULT 0 NOT NULL,
FSOURCETYPE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCAGENERBILLNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCAGENERID BIGINT DEFAULT 0 NOT NULL,
FGENERATSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FFAILMESSAGE NVARCHAR(2000) DEFAULT ' ' NOT NULL
);

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