--运营商机构名称字段
--付款申请分录
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYAPPLYENTRY' AND KSQL_COL_NAME IN ('FINSTITUTIONNAME')) 
 ALTER TABLE T_CAS_PAYAPPLYENTRY ADD (FINSTITUTIONNAME NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYINFOENTRY' AND KSQL_COL_NAME IN ('FRECINSTITUTIONNAME')) 
 ALTER TABLE T_CAS_PAYINFOENTRY ADD (FRECINSTITUTIONNAME NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYINFOENTRY' AND KSQL_COL_NAME IN ('FPAYINSTITUTIONNAME')) 
 ALTER TABLE T_CAS_PAYINFOENTRY ADD (FPAYINSTITUTIONNAME NVARCHAR(50) DEFAULT ' ' NOT NULL );
 EXEC p_AlterColumn 'T_CAS_PAYMENTBILL', 'FINSTITUTIONCODE', 'NVARCHAR(30)', 'NOT NULL', '0100', ''' ''';

--付款单
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYMENTBILL' AND KSQL_COL_NAME IN ('FINSTITUTIONNAME')) 
 ALTER TABLE T_CAS_PAYMENTBILL ADD (FINSTITUTIONNAME NVARCHAR(50) DEFAULT ' ' NOT NULL );
 
--支付信息变更单
 EXEC p_AlterColumn 'T_CAS_PAYCHGBILLENTRY', 'FINSTITUTIONCODE', 'NVARCHAR(30)', 'NOT NULL', '0100', ''' ''';

 EXEC p_AlterColumn 'T_CAS_PAYCHGBILLENTRY', 'FAFTERINSTITUTIONCODE', 'NVARCHAR(30)', 'NOT NULL', '0100', ''' ''';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYCHGBILLENTRY' AND KSQL_COL_NAME IN ('FINSTITUTIONNAME')) 
 ALTER TABLE T_CAS_PAYCHGBILLENTRY ADD (FINSTITUTIONNAME NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYCHGBILLENTRY' AND KSQL_COL_NAME IN ('FAFTERINSTITUTIONNAME')) 
 ALTER TABLE T_CAS_PAYCHGBILLENTRY ADD (FAFTERINSTITUTIONNAME NVARCHAR(50) DEFAULT ' ' NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_EXCHANGEBILL' AND KSQL_COL_NAME IN ('FHANDMARKNOMATCH'))
 ALTER TABLE T_CAS_EXCHANGEBILL ADD (FHANDMARKNOMATCH VARCHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYMENTBILL_E' AND KSQL_COL_NAME IN ('FHANDMARKNOMATCH'))
 ALTER TABLE T_CAS_PAYMENTBILL_E ADD (FHANDMARKNOMATCH VARCHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_AGENTPAYBILL_E' AND KSQL_COL_NAME IN ('FHANDMARKNOMATCH'))
 ALTER TABLE T_CAS_AGENTPAYBILL_E ADD (FHANDMARKNOMATCH VARCHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_RECEIVINGBILL_E' AND KSQL_COL_NAME IN ('FHANDMARKNOMATCH'))
 ALTER TABLE T_CAS_RECEIVINGBILL_E ADD (FHANDMARKNOMATCH VARCHAR(1) DEFAULT '0' NOT NULL );

 IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CAS_FLOWCONFIRMLOG')
  CREATE TABLE T_CAS_FLOWCONFIRMLOG (
     FID BIGINT DEFAULT 0 NOT NULL,
     FBILLNO VARCHAR(50) DEFAULT ' ' NOT NULL,
     FBILLSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
     FCREATORID BIGINT DEFAULT 0 NOT NULL,
     FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
     FAUDITORID BIGINT DEFAULT 0 NOT NULL,
     FAUDITDATE DATETIME,
     FMODIFYTIME DATETIME,
     FCREATETIME DATETIME,
     FACCOUNTBANK BIGINT DEFAULT 0 NOT NULL,
     FCURRENCY BIGINT DEFAULT 0 NOT NULL,
     FOPTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
     FMATCHRULE VARCHAR(50) DEFAULT ' ' NOT NULL,
     FOPTIME DATETIME,
     FTRACEID VARCHAR(50) DEFAULT ' ' NOT NULL
 );


 IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CAS_FLOWLOG_ENTRY')
  CREATE TABLE T_CAS_FLOWLOG_ENTRY (
     FID BIGINT DEFAULT 0 NOT NULL,
     FENTRYID BIGINT DEFAULT 0 NOT NULL,
     FSEQ BIGINT DEFAULT 0 NOT NULL,
     FBIZOBJECT VARCHAR(50) DEFAULT ' ' NOT NULL,
     FBILLTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
     FORGID BIGINT DEFAULT 0 NOT NULL,
     FBIZDATE DATETIME,
     FBIZBILLNO VARCHAR(50) DEFAULT ' ' NOT NULL,
     FBIZBILLID BIGINT DEFAULT 0 NOT NULL,
     FDETAILNUM BIGINT DEFAULT 0 NOT NULL,
     FDETAILID BIGINT DEFAULT 0 NOT NULL,
     FRECAMOUNT DECIMAL(19,4),
     FPAYAMOUNT DECIMAL(19,4)
 );
