/** 立项单和暂估单表头添加字段 **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_COSTESTIMATEBILL' AND KSQL_COL_NAME ='FSHARERULE') 
 ALTER TABLE T_ER_COSTESTIMATEBILL ADD (FSHARERULE VARCHAR(50) DEFAULT 'monthrule' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_COSTESTIMATEBILL' AND KSQL_COL_NAME ='FSHAREMETHOD') 
 ALTER TABLE T_ER_COSTESTIMATEBILL ADD (FSHAREMETHOD VARCHAR(50) DEFAULT 'rate' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_APPLYPROJECTBILL' AND KSQL_COL_NAME ='FSHARERULE') 
 ALTER TABLE T_ER_APPLYPROJECTBILL ADD (FSHARERULE VARCHAR(50) DEFAULT 'monthrule' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_APPLYPROJECTBILL' AND KSQL_COL_NAME ='FSHAREMETHOD') 
 ALTER TABLE T_ER_APPLYPROJECTBILL ADD (FSHAREMETHOD VARCHAR(50) DEFAULT 'rate' NOT NULL );
 
 /**立项单分摊规则分录 **/
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_APPLYPROJECTRULE') 
 CREATE TABLE T_ER_APPLYPROJECTRULE (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FENTRYCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FENTRYCOSTDEPTID BIGINT DEFAULT 0 NOT NULL,
FENTRYMONTH DATETIME,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FSHARERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSHAREREMARK NVARCHAR(255) DEFAULT ' ' NOT NULL
);
 
 /**暂估单分摊规则分录 **/
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_COSTESTIMATERULE') 
 CREATE TABLE T_ER_COSTESTIMATERULE (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FENTRYCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FENTRYCOSTDEPTID BIGINT DEFAULT 0 NOT NULL,
FENTRYMONTH DATETIME,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FSHARERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSHAREREMARK NVARCHAR(255) DEFAULT ' ' NOT NULL
);
 
 /**立项单分摊结果分录 **/
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_APPLYPROJECTSHARED') 
 CREATE TABLE T_ER_APPLYPROJECTSHARED (
FID BIGINT DEFAULT 0 NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FENTRYCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FENTRYCOSTDEPTID BIGINT DEFAULT 0 NOT NULL,
FEXPENSEITEMID BIGINT DEFAULT 0 NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FENTRYMONTH DATETIME,
FHAPPENDATE DATETIME,
FENTRYCURRENCY BIGINT DEFAULT 0 NOT NULL,
FEXCHANGERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREIMBURSEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURRREIMBURSEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORIAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEAPPROVEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEAPPROVECURRAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSHARERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREMARK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FLKWAITENTRYID VARCHAR(200) DEFAULT ' ' NOT NULL
);
 
 /**暂估单分摊结果分录 **/
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_COSTESTIMATESHARED') 
 CREATE TABLE T_ER_COSTESTIMATESHARED (
FID BIGINT DEFAULT 0 NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FENTRYCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FENTRYCOSTDEPTID BIGINT DEFAULT 0 NOT NULL,
FEXPENSEITEMID BIGINT DEFAULT 0 NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FENTRYMONTH DATETIME,
FHAPPENDATE DATETIME,
FENTRYCURRENCY BIGINT DEFAULT 0 NOT NULL,
FEXCHANGERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREIMBURSEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURRREIMBURSEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORIAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEAPPROVEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEAPPROVECURRAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSHARERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREMARK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FLKWAITENTRYID VARCHAR(200) DEFAULT ' ' NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_APPLYPROJECTRULE', 'T_ER_APPLYPROJECTRULE', 'FDETAILID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_ER_APPLYPRORL_FSEQ') CREATE INDEX IDX_T_ER_APPLYPRORL_FSEQ ON T_ER_APPLYPROJECTRULE ( FENTRYID ,FSEQ );


 EXEC P_ALTERPK 'PK_T_ER_COSTESTIMATERULE', 'T_ER_COSTESTIMATERULE', 'FDETAILID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_ER_CSESTIMATERL_FSEQ') CREATE INDEX IDX_T_ER_CSESTIMATERL_FSEQ ON T_ER_COSTESTIMATERULE ( FENTRYID ,FSEQ );


 EXEC P_ALTERPK 'PK_T_ER_APPLYPROJECTSHARED', 'T_ER_APPLYPROJECTSHARED', 'FDETAILID', '1';

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


 EXEC P_ALTERPK 'PK_T_ER_COSTESTIMATESHARED', 'T_ER_COSTESTIMATESHARED', 'FDETAILID', '1';

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