/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\CAS_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CAS_CASHVERIFIADJENTRY') 
 CREATE TABLE T_CAS_CASHVERIFIADJENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FADJUSTMENTITEM NVARCHAR(50) DEFAULT ' ' NOT NULL,
FADJUSTMENTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCOMMENT NVARCHAR(500) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CAS_CASHVERIFICATION') 
 CREATE TABLE T_CAS_CASHVERIFICATION (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
FBILLSTATUS NVARCHAR(30) 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,
FORGID BIGINT DEFAULT 0 NOT NULL,
FCHECKDATE DATETIME,
FCASHIERID BIGINT DEFAULT 0 NOT NULL,
FCURRENCYID BIGINT DEFAULT 0 NOT NULL,
FCASHACCOUNTID BIGINT DEFAULT 0 NOT NULL,
FACCOUNTBALANCE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBOOKEDUNPAID DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNBOOKEDRECEIVED DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBOOKEDUNRECEIVED DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNBOOKEDPAID DECIMAL(23,10) DEFAULT 0 NOT NULL,
FADJUSTBALANCE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREALCASHAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINVENTORYSURPLUS DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINVENTORYDEFICIT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FACCOUNTBALANCERMK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FBOOKEDUNPAIDRMK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FUNBOOKEDRECEIVEDRMK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FBOOKEDUNRECEIVEDRMK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FUNBOOKEDPAIDRMK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FADJUSTBALANCERMK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FREALCASHAMOUNTRMK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FINVENTORYSURPLUSRMK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FINVENTORYDEFICITRMK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FISVOUCHER CHAR(1) DEFAULT '0' NOT NULL,
FCHECKRESULT NVARCHAR(30) DEFAULT '0' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CAS_CURRENCYFACEVALUE') 
 CREATE TABLE T_CAS_CURRENCYFACEVALUE (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(30) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSTATUS NVARCHAR(30) DEFAULT ' ' NOT NULL,
FENABLE INT DEFAULT 0 NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FCURRENCYID BIGINT DEFAULT 0 NOT NULL,
FBASEUNIT NVARCHAR(30) DEFAULT ' ' NOT NULL,
FENABLEDDENOMINATION NVARCHAR(500) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CAS_CURRENCYFACEVALUE_L') 
 CREATE TABLE T_CAS_CURRENCYFACEVALUE_L (
FPKID NVARCHAR(18) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CAS_CURRENCYFVENTRY') 
 CREATE TABLE T_CAS_CURRENCYFVENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FFACEVALUE INT DEFAULT 0 NOT NULL,
FUNIT NVARCHAR(30) DEFAULT ' ' NOT NULL,
FDENOMINATION NVARCHAR(100) DEFAULT ' ' NOT NULL,
FCONVERSIONRATIO DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUSESTATUS CHAR(1) DEFAULT ' ' NOT NULL
);


 EXEC p_AlterColumn 'T_CAS_RECEIVINGBILL', 'FBANKCHECKFLAG', 'VARCHAR(1024)', 'NOT NULL', '0100', ''' ''';

 EXEC p_AlterColumn 'T_CAS_RECBILLCHANG', 'FBANKCHECKFLAG', 'VARCHAR(1024)', 'NOT NULL', '0100', ''' ''';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_RECBILLCHANG' AND KSQL_COL_NAME ='FISDELETE') 
 ALTER TABLE T_CAS_RECBILLCHANG ADD (FISDELETE CHAR(1) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CLAIMBILL' AND KSQL_COL_NAME ='FDRAFTBILLTYPEID') 
 ALTER TABLE T_CAS_CLAIMBILL ADD (FDRAFTBILLTYPEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CLAIMBILL' AND KSQL_COL_NAME ='FDRAFTBILLEXPIREDATE') 
 ALTER TABLE T_CAS_CLAIMBILL ADD (FDRAFTBILLEXPIREDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CLAIMBILL' AND KSQL_COL_NAME ='FDRAWERNAME') 
 ALTER TABLE T_CAS_CLAIMBILL ADD (FDRAWERNAME NVARCHAR(80) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CLAIMBILL' AND KSQL_COL_NAME ='FBUSINESSTYPE') 
 ALTER TABLE T_CAS_CLAIMBILL ADD (FBUSINESSTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CLAIMBILL' AND KSQL_COL_NAME ='FISNOTICEMERGE') 
 ALTER TABLE T_CAS_CLAIMBILL ADD (FISNOTICEMERGE CHAR(1) DEFAULT '0' NOT NULL );
 EXEC p_AlterColumn 'T_CAS_CLAIMNOTICEBILL', 'FBANKCHECKFLAG', 'NVARCHAR(1024)', 'NOT NULL', '0100', ''' ''';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CLAIMNOTICEBILL' AND KSQL_COL_NAME ='FDRAFTBILLTYPEID') 
 ALTER TABLE T_CAS_CLAIMNOTICEBILL ADD (FDRAFTBILLTYPEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CLAIMNOTICEBILL' AND KSQL_COL_NAME ='FDRAFTBILLEXPIREDATE') 
 ALTER TABLE T_CAS_CLAIMNOTICEBILL ADD (FDRAFTBILLEXPIREDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CLAIMNOTICEBILL' AND KSQL_COL_NAME ='FDRAWERNAME') 
 ALTER TABLE T_CAS_CLAIMNOTICEBILL ADD (FDRAWERNAME NVARCHAR(80) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CLAIMNOTICEBILL' AND KSQL_COL_NAME ='FBUSINESSTYPE') 
 ALTER TABLE T_CAS_CLAIMNOTICEBILL ADD (FBUSINESSTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CLAIMNOTICEBILL' AND KSQL_COL_NAME ='FMERGESTATUS') 
 ALTER TABLE T_CAS_CLAIMNOTICEBILL ADD (FMERGESTATUS NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CLAIMNOTICEBILL' AND KSQL_COL_NAME ='FMARGEID') 
 ALTER TABLE T_CAS_CLAIMNOTICEBILL ADD (FMARGEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CLAIMNOTICEBILL' AND KSQL_COL_NAME ='FSETTLEMENTTYPE') 
 ALTER TABLE T_CAS_CLAIMNOTICEBILL ADD (FSETTLEMENTTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CAS_CASHVERIFICASHENTRY') 
 CREATE TABLE T_CAS_CASHVERIFICASHENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FDENOMINATION NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCONVERSIONRATIO DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCASHQTY BIGINT DEFAULT 0 NOT NULL,
FCASHAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCOMMENT NVARCHAR(500) DEFAULT ' ' NOT NULL,
FCURRENCYFVENTRYID BIGINT DEFAULT 0 NOT NULL
);



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