-- 驳回调整单需求新增字段
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_BGAPPLYBILL' AND KSQL_COL_NAME ='FSRCBILLNUMBER') 
 ALTER TABLE T_EB_BGAPPLYBILL ADD (FSRCBILLNUMBER NVARCHAR(60) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_BGAPPLYBILL' AND KSQL_COL_NAME ='FTEMPLATEID') 
 ALTER TABLE T_EB_BGAPPLYBILL ADD (FTEMPLATEID BIGINT DEFAULT 0 NOT NULL);


-- 驳回记录表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_BILLREJECTLOG') 
 CREATE TABLE T_EB_BILLREJECTLOG (
FID BIGINT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FSPBILLNUMBER        NVARCHAR(60)         NOT NULL DEFAULT ' ',
FBHBILLNUMBER        NVARCHAR(50)         NOT NULL DEFAULT ' ',
FTEMPLATEID          BIGINT 			  DEFAULT 0 NOT NULL,
FDATAJSON            NCLOB,
FAFTERDATAJSON       NCLOB,
FSUMMARYDATAJSON     NCLOB,
FREJECTSTATUS        CHAR(1)              NOT NULL DEFAULT ' ',
FREJECTTXT			 NCLOB,
FREJECTUSER			 BIGINT               NOT NULL DEFAULT 0,
FCREATERID			 BIGINT               NOT NULL DEFAULT 0,
FCREATEDATE			 DATETIME
);
 
EXEC P_ALTERPK 'PK_EB_BILLREJECTLOG', 'T_EB_BILLREJECTLOG', 'FID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_BILLREJECTLOG_P1')
CREATE INDEX IDX_EB_BILLREJECTLOG_P1 ON T_EB_BILLREJECTLOG (
FSPBILLNUMBER ASC
);

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_BILLREJECTLOG_P2')
CREATE INDEX IDX_EB_BILLREJECTLOG_P2 ON T_EB_BILLREJECTLOG (
FBHBILLNUMBER ASC
);
 
 
 