/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\CAS_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CASHMGTINITBANK' AND KSQL_COL_NAME ='FBATCHNO') 
 ALTER TABLE T_CAS_CASHMGTINITBANK ADD (FBATCHNO NVARCHAR(80) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CASHMGTINITCASH' AND KSQL_COL_NAME ='FBATCHNO') 
 ALTER TABLE T_CAS_CASHMGTINITCASH ADD (FBATCHNO NVARCHAR(80) DEFAULT ' ' NOT NULL );
 EXEC p_AlterColumn 'T_CAS_ACCOUNTCASHS', 'FADMINID', 'BIGINT', 'NOT NULL', '0011', '0';

 EXEC p_AlterColumn 'T_CAS_EXCHANGEBILL', 'FREMARK', 'NVARCHAR(50)', 'NOT NULL', '0011', ''' ''';

 EXEC p_AlterColumn 'T_CAS_FUNDFLOWITEM_L', 'FNAME', 'NVARCHAR(255)', 'NOT NULL', '0100', ''' ''';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CAS_AGENTPAYBILL_E') 
 CREATE TABLE T_CAS_AGENTPAYBILL_E (
FID BIGINT DEFAULT 0 NOT NULL,
FPAYMENTCHANNEL VARCHAR(30) DEFAULT ' ' NOT NULL,
FONLINEBANKACCTID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYMENTBILLENTRY' AND KSQL_COL_NAME ='FTAXRATE') 
 ALTER TABLE T_CAS_PAYMENTBILLENTRY ADD (FTAXRATE DECIMAL(19,6) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYMENTBILLENTRY' AND KSQL_COL_NAME ='FTAXAMT') 
 ALTER TABLE T_CAS_PAYMENTBILLENTRY ADD (FTAXAMT DECIMAL(19,6) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_RECEIVINGBILLENTRY' AND KSQL_COL_NAME ='FSETTLEORGID') 
 ALTER TABLE T_CAS_RECEIVINGBILLENTRY ADD (FSETTLEORGID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYMENTBILL_E' AND KSQL_COL_NAME ='FEXRATETABLEID') 
 ALTER TABLE T_CAS_PAYMENTBILL_E ADD (FEXRATETABLEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYMENTBILL_E' AND KSQL_COL_NAME ='FEXRATEDATE') 
 ALTER TABLE T_CAS_PAYMENTBILL_E ADD (FEXRATEDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYMENTBILL_E' AND KSQL_COL_NAME ='FPAYMENTCHANNEL') 
 ALTER TABLE T_CAS_PAYMENTBILL_E ADD (FPAYMENTCHANNEL VARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYMENTBILL_E' AND KSQL_COL_NAME ='FONLINEBANKACCTID') 
 ALTER TABLE T_CAS_PAYMENTBILL_E ADD (FONLINEBANKACCTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYMENTBILL_E' AND KSQL_COL_NAME ='FISCHANGE') 
 ALTER TABLE T_CAS_PAYMENTBILL_E ADD (FISCHANGE CHAR(1) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CAS_PAYMENTBILL_BL') 
 CREATE TABLE T_CAS_PAYMENTBILL_BL (
FPKID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CAS_PAYCHGBILL') 
 CREATE TABLE T_CAS_PAYCHGBILL (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FCHGDATE DATETIME,
FORGID BIGINT DEFAULT 0 NOT NULL,
FAPPLYUSERID BIGINT DEFAULT 0 NOT NULL,
FSOURCETYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
FSOURCEBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FCHGTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
FREMARK VARCHAR(30) DEFAULT ' ' NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FBILLSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FSOURCEBILLID BIGINT DEFAULT 0 NOT NULL,
FSOURCEBILLTYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FSOURCECURRENCYID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CAS_PAYCHGBILLENTRY') 
 CREATE TABLE T_CAS_PAYCHGBILLENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FPAYCHANNEL NVARCHAR(30) DEFAULT ' ' NOT NULL,
FSETTLETYPEID BIGINT DEFAULT 0 NOT NULL,
FSETTLETNUMBER NVARCHAR(100) DEFAULT ' ' NOT NULL,
FPAYERACCTBANKID BIGINT DEFAULT 0 NOT NULL,
FPAYERBANKID BIGINT DEFAULT 0 NOT NULL,
FACTPAYAMT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FAFTERPAYCHANNEL NVARCHAR(40) DEFAULT ' ' NOT NULL,
FAFTERSETTLETYPEID BIGINT DEFAULT 0 NOT NULL,
FAFTERSETTLETNUMBER NVARCHAR(100) DEFAULT ' ' NOT NULL,
FAFTERPAYERACCTBANKID BIGINT DEFAULT 0 NOT NULL,
FAFTERPAYERBANKID BIGINT DEFAULT 0 NOT NULL,
FLINENUMBER INT DEFAULT 0 NOT NULL,
FRECER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FRECERNAME NVARCHAR(80) DEFAULT ' ' NOT NULL,
FRECACCTBANK NVARCHAR(80) DEFAULT ' ' NOT NULL,
FRECERBANKID BIGINT DEFAULT 0 NOT NULL,
FUSAGE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FAFTERRECERNAME NVARCHAR(80) DEFAULT ' ' NOT NULL,
FAFTERRECACCTBANKID BIGINT DEFAULT 0 NOT NULL,
FAFTERRECERBANKID BIGINT DEFAULT 0 NOT NULL,
FAFTERUSAGE NVARCHAR(255) DEFAULT ' ' NOT NULL
);

 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYMENTBILL_E' AND KSQL_COL_NAME ='FONLINEBANKACCTID') 
 ALTER TABLE T_CAS_PAYMENTBILL_E ADD (FONLINEBANKACCTID BIGINT DEFAULT 0 NOT NULL );

  IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_AGENTPAYBILL_E' AND KSQL_COL_NAME ='FONLINEBANKACCTID') 
 ALTER TABLE T_CAS_AGENTPAYBILL_E ADD (FONLINEBANKACCTID BIGINT DEFAULT 0 NOT NULL );
 
/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\CAS_table.sql **/
