/** 额度申请单 增加 申请明细分录、额度明细分录 **/
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_APPLYDETAIL') 
 CREATE TABLE T_ER_APPLYDETAIL (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FENTRYCOMPANY BIGINT DEFAULT 0 NOT NULL,
FENTRYEMPLOYEE BIGINT DEFAULT 0 NOT NULL,
FENTRYCOSTCOMPANY BIGINT DEFAULT 0 NOT NULL,
FENTRYCOSTDEPT BIGINT DEFAULT 0 NOT NULL,
FSTDENTRYCOSTCENTERID BIGINT DEFAULT 0 NOT NULL,
FEXPENSEITEM BIGINT DEFAULT 0 NOT NULL,
FSTDPROJECT BIGINT DEFAULT 0 NOT NULL,
FENTRYCURRENCY BIGINT DEFAULT 0 NOT NULL,
FEXCHANGERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQUOTETYPE CHAR(1) DEFAULT '0' NOT NULL,
FHAPPENDATE DATETIME,
FEXPENSEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURREXPENSEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEAPPROVEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEAPPROVECURRAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENTRYEFFECTIVEDATE DATETIME,
FENTRYDUEDATE DATETIME,
FENTRYREMARK VARCHAR(30) DEFAULT ' ' NOT NULL,
FORGIEXPEBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREIMBURSEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREIMBURSEDCURRAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCANLOANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCANLOANCURRAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPUSHEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPUSHEDCURRAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPORIWITHHOLDINGAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPWITHHOLDINGAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_REIMCTLDETAIL') 
 CREATE TABLE T_ER_REIMCTLDETAIL (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FREIMCTLCOMPANY BIGINT DEFAULT 0 NOT NULL,
FREIMCTLEMPLOYEE BIGINT DEFAULT 0 NOT NULL,
FREIMCTLCOSTCOMPANY BIGINT DEFAULT 0 NOT NULL,
FREIMCTLEXPENSEITEM BIGINT DEFAULT 0 NOT NULL,
FREIMCTLCURRENCY BIGINT DEFAULT 0 NOT NULL,
FREIMCTLDATAYEAR VARCHAR(4) DEFAULT ' ' NOT NULL,
FREIMCTLTOTALAMOUNT DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FREIMCTLQUARTER1 DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREIMCTLQUARTER2 DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREIMCTLQUARTER3 DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREIMCTLQUARTER4 DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREIMCTLMONTH1 DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FREIMCTLMONTH2 DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FREIMCTLMONTH3 DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FREIMCTLMONTH4 DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FREIMCTLMONTH5 DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FREIMCTLMONTH6 DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FREIMCTLMONTH7 DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FREIMCTLMONTH8 DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FREIMCTLMONTH9 DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FREIMCTLMONTH10 DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FREIMCTLMONTH11 DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FREIMCTLMONTH12 DECIMAL(23,10) DEFAULT 0.000000 NOT NULL,
FREIMCTLREMARK VARCHAR(30) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMCTLAPPLYBILL' AND KSQL_COL_NAME ='FBALANCEAMOUNT')
ALTER TABLE T_ER_REIMCTLAPPLYBILL ADD (FBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMCTLAPPLYBILL' AND KSQL_COL_NAME ='FLOANEDAMOUNT')
ALTER TABLE T_ER_REIMCTLAPPLYBILL ADD (FLOANEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMCTLAPPLYBILL' AND KSQL_COL_NAME ='FBILLCANLOANAMOUNT')
ALTER TABLE T_ER_REIMCTLAPPLYBILL ADD (FBILLCANLOANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMCTLAPPLYBILL' AND KSQL_COL_NAME ='FWITHHOLDINGAMOUNT')
ALTER TABLE T_ER_REIMCTLAPPLYBILL ADD (FWITHHOLDINGAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMCTLAPPLYBILL' AND KSQL_COL_NAME ='FSTDCOSTCENTERID')
ALTER TABLE T_ER_REIMCTLAPPLYBILL ADD (FSTDCOSTCENTERID BIGINT DEFAULT 0 NOT NULL );

EXEC P_ALTERPK 'PK_T_ER_APPLYDETAIL', 'T_ER_APPLYDETAIL', 'FENTRYID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_CTLAPPLYDETAIL_FSEQ') CREATE INDEX IDX_ER_CTLAPPLYDETAIL_FSEQ ON T_ER_APPLYDETAIL ( FID ,FSEQ );


EXEC P_ALTERPK 'PK_T_ER_REIMCTLDETAIL', 'T_ER_REIMCTLDETAIL', 'FENTRYID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_REIMCTLDETAIL_FSEQ') CREATE INDEX IDX_ER_REIMCTLDETAIL_FSEQ ON T_ER_REIMCTLDETAIL ( FID ,FSEQ );

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