/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\IFM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IFM_BIZDEALBILL')
 CREATE TABLE T_IFM_BIZDEALBILL (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FSOURCEBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FAPPLITYPE NVARCHAR(80) DEFAULT ' ' NOT NULL,
FAPPLIDATE DATETIME,
FAPPLICATID BIGINT DEFAULT 0 NOT NULL,
FDEALUSERID BIGINT DEFAULT 0 NOT NULL,
FDEALDATE DATETIME,
FSETTLECENTERID BIGINT DEFAULT 0 NOT NULL,
FAPPLIAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCONTRACTAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FISLIMITCLAUSE CHAR(1) DEFAULT '0' NOT NULL,
FCONTRACTBILLNO NVARCHAR(80) DEFAULT '  ' NOT NULL,
FBILLSTATUS NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBUSINESSSTATUS NVARCHAR(80) DEFAULT ' ' NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FLOANTYPE NVARCHAR(80) DEFAULT ' ' NOT NULL,
FCREDITORTYPE NVARCHAR(80) DEFAULT ' ' NOT NULL,
FCREDITORID BIGINT DEFAULT 0 NOT NULL,
FFINPRODUCTID BIGINT DEFAULT 0 NOT NULL,
FCURRENCYID BIGINT DEFAULT 0 NOT NULL,
FAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FISCYCLELOAN CHAR(1) DEFAULT '0' NOT NULL,
FLOANCONTRACTBILLID BIGINT DEFAULT 0 NOT NULL,
FSOURCEBILLID BIGINT DEFAULT 0 NOT NULL,
FSRCLOANBILLID BIGINT DEFAULT 0 NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FCONTRACTNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FSIGNDATE DATETIME,
FSTARTDATE DATETIME,
FTERM NVARCHAR(80) DEFAULT ' ' NOT NULL,
FENDDATE DATETIME,
FACCOUNTBANKID BIGINT DEFAULT 0 NOT NULL,
FGUARANTEE NVARCHAR(80) DEFAULT ' ' NOT NULL,
FDRAWWAY NVARCHAR(80) DEFAULT ' ' NOT NULL,
FLOANUSEID BIGINT DEFAULT 0 NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FCREDITLIMITID BIGINT DEFAULT 0 NOT NULL,
FNOTDRAWAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FDRAWAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FLOANDATE DATETIME,
FSTARTINTDATE DATETIME,
FEXPIREDATE DATETIME,
FREPAYACCOUNTID BIGINT DEFAULT 0 NOT NULL,
FNOTREPAYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREPAYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPREDICTINTEREST DECIMAL(23,10) DEFAULT 0 NOT NULL,
FISCALLINT CHAR(1) DEFAULT '0' NOT NULL,
FACTINTEREST DECIMAL(23,10) DEFAULT 0 NOT NULL,
FDEDUCTACCOUNTID BIGINT DEFAULT 0 NOT NULL,
FPAYINTTYPE NVARCHAR(80) DEFAULT ' ' NOT NULL,
FSETTLEINSTDATE DATETIME,
FENDINSTDATE DATETIME,
FBIZDATE DATETIME,
FINTERESTTYPE NVARCHAR(80) DEFAULT ' ' NOT NULL,
FRATETYPEID BIGINT DEFAULT 0 NOT NULL,
FLOANRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FRATESIGN NVARCHAR(80) DEFAULT ' ' NOT NULL,
FRATEFLOATPOINT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASIS NVARCHAR(80) DEFAULT ' ' NOT NULL,
FRATEADJUSTSTYLE NVARCHAR(80) DEFAULT ' ' NOT NULL,
FRATEADJUSTDATE DATETIME,
FRATEADJUSTCYCLETYPE NVARCHAR(80) DEFAULT ' ' NOT NULL,
FRATEADJUSTCYCLE INT DEFAULT 0 NOT NULL,
FREPAYMENTWAY NVARCHAR(80) DEFAULT ' ' NOT NULL,
FSTAGEPLANID BIGINT DEFAULT 0 NOT NULL,
FSETTLEINTMODE NVARCHAR(80) DEFAULT ' ' NOT NULL,
FINTERESTSETTLEDPLANID BIGINT DEFAULT 0 NOT NULL,
FRATEDEADLINE NVARCHAR(80) DEFAULT ' ' NOT NULL,
FSRCLOANBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FMAINORGID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IFM_BIZDEALBILL_CA') 
 CREATE TABLE T_IFM_BIZDEALBILL_CA (
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_IFM_CURRENTINTBILL') 
 CREATE TABLE T_IFM_CURRENTINTBILL (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
FBILLSTATUS NVARCHAR(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,
FORGID BIGINT DEFAULT 0 NOT NULL,
FINTERESTDAY DATETIME,
FCOMMENT NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDATASOURCE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FBATCHNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
FINNERACCTID BIGINT DEFAULT 0 NOT NULL,
FLOANNUM NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCURRENCYID BIGINT DEFAULT 0 NOT NULL,
FPRINCIPAL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSETTLECENTERID BIGINT DEFAULT 0 NOT NULL,
FRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FACCPTNO NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IFM_CURRINTBILL_ENTRY') 
 CREATE TABLE T_IFM_CURRINTBILL_ENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FINSTSTARTDATE DATETIME,
FINSTENDDATE DATETIME,
FINSTDAYS BIGINT DEFAULT 0 NOT NULL,
FINSTPRINCIPAL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINTRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINSTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINSTCTG NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IFM_INTBILL_BATCH_INT') 
 CREATE TABLE T_IFM_INTBILL_BATCH_INT (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FINTDETAILNUM NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSTARTDATE DATETIME,
FENDDATE DATETIME,
FINTDAYS BIGINT DEFAULT 0 NOT NULL,
FRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURRENCYID BIGINT DEFAULT 0 NOT NULL,
FINTERESTAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINTCOMMENT NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPRINCIPLE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FINTTYPE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FLOANCONTRACTBILLNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCONTRACTNUM NVARCHAR(50) DEFAULT ' ' NOT NULL,
FLOANBILLNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
FLOANBILLID BIGINT DEFAULT 0 NOT NULL,
FINTBILLID BIGINT DEFAULT 0 NOT NULL,
FINNERACCTID BIGINT DEFAULT 0 NOT NULL,
FLOANNUM NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IFM_INTBILL_BATCH_L') 
 CREATE TABLE T_IFM_INTBILL_BATCH_L (
FPKID NVARCHAR(30) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID NVARCHAR(30) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IFM_INTBILL_BATCH') 
 CREATE TABLE T_IFM_INTBILL_BATCH (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(30) DEFAULT ' ' NOT NULL,
FBILLSTATUS NVARCHAR(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,
FORGID BIGINT DEFAULT 0 NOT NULL,
FBIZDATE DATETIME,
FSETTLECENTERID BIGINT DEFAULT 0 NOT NULL,
FBIZTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FBIZDEALNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
FINTERESTTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FDATASOURCE NVARCHAR(30) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IFM_BIZDEALBILL_INT') 
 CREATE TABLE T_IFM_BIZDEALBILL_INT (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FINSTSTARTDATE DATETIME,
FINSTENDDATE DATETIME,
FINSTDAYS INT DEFAULT 0 NOT NULL,
FINSTPRINCIPAL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FRATETRANDAYS INT DEFAULT 0 NOT NULL,
FINSTAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINSTCTG NVARCHAR(80) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IFM_BIZDEALBILL_L') 
 CREATE TABLE T_IFM_BIZDEALBILL_L (
FPKID NVARCHAR(30) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID NVARCHAR(30) DEFAULT ' ' NOT NULL,
FDEALOPINION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FLIMITCLAUSEEXPLAIN NVARCHAR(255) DEFAULT ' ' NOT NULL,
FOTHEREXPLAIN NVARCHAR(255) DEFAULT ' ' NOT NULL,
FCONTRACTNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSUMMARY NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IFM_PRODUCT' AND KSQL_COL_NAME ='FREFERRATEID') 
 ALTER TABLE T_IFM_PRODUCT ADD (FREFERRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IFM_PRODUCT' AND KSQL_COL_NAME ='FPRODUCTTERM') 
 ALTER TABLE T_IFM_PRODUCT ADD (FPRODUCTTERM NVARCHAR(80) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CFM_FINANCINGVARIETIES_P') 
 CREATE TABLE T_CFM_FINANCINGVARIETIES_P (
FID BIGINT DEFAULT 0 NOT NULL,
FSERVICECATEGORY NVARCHAR(80) DEFAULT ' ' NOT NULL,
FCURRENCYID BIGINT DEFAULT 0 NOT NULL,
FCATEGORY NVARCHAR(80) DEFAULT ' ' NOT NULL,
FRATEPRODUCTID BIGINT DEFAULT 0 NOT NULL,
FPRODUCTPRICE NVARCHAR(80) DEFAULT ' ' NOT NULL,
FFLOATPOINTS BIGINT DEFAULT 0 NOT NULL,
FRATESIGN NVARCHAR(80) DEFAULT ' ' NOT NULL,
FRATESIGNBP NVARCHAR(80) DEFAULT ' ' NOT NULL,
FRATEFLOATPOINTS BIGINT DEFAULT 0 NOT NULL,
FFLOATRATE CHAR(1) DEFAULT '0' NOT NULL,
FRATEPRICE NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBASIS NVARCHAR(80) DEFAULT ' ' NOT NULL,
FREFERRATEID BIGINT DEFAULT 0 NOT NULL,
FBIZTYPE NVARCHAR(80) DEFAULT ' ' NOT NULL,
FEFFECTIVEDATE DATETIME,
FPRODUCTTERM NVARCHAR(80) DEFAULT ' ' NOT NULL
);

 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IFM_INTBILL_BATCH' AND KSQL_COL_NAME ='FBIZDEALNO')
 ALTER TABLE T_IFM_INTBILL_BATCH ADD (FBIZDEALNO NVARCHAR(80) DEFAULT ' ' NOT NULL);
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IFM_INNERACCT' AND KSQL_COL_NAME ='FINTERESTDATE')
 ALTER TABLE T_IFM_INNERACCT ADD (FINTERESTDATE DATETIME );
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IFM_INTBILL_BATCH_INT' AND KSQL_COL_NAME ='FINTDETAIL_TAG')
 ALTER TABLE T_IFM_INTBILL_BATCH_INT ADD (FINTDETAIL_TAG NCLOB );
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IFM_INTBILL_BATCH_INT' AND KSQL_COL_NAME ='FINTDETAIL')
 ALTER TABLE T_IFM_INTBILL_BATCH_INT ADD (FINTDETAIL NVARCHAR(255) DEFAULT ' ' NOT NULL);


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