IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_COSTESTIMATEBILL')
 CREATE TABLE T_ER_COSTESTIMATEBILL (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS CHAR(1) 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,
FCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FBIZDATE DATETIME,
FISCURRENCY CHAR(1) DEFAULT '0' NOT NULL,
FDESCRIPTION NVARCHAR(1000) DEFAULT ' ' NOT NULL,
FCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FCOSTDEPTID BIGINT DEFAULT 0 NOT NULL,
FAPPLIERID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FCURRENCYID BIGINT DEFAULT 0 NOT NULL,
FTEL VARCHAR(30) DEFAULT ' ' NOT NULL,
FFORMID VARCHAR(30) DEFAULT ' ' NOT NULL,
FAPPLYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAPPROVEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBILLCANLOANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FLOANEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FIMAGENUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FHASVOUCHER CHAR(1) DEFAULT '0' NOT NULL,
FAPPLIERPOSITIONSTR NVARCHAR(100) DEFAULT ' ' NOT NULL,
FISOVERBUDGET CHAR(1) DEFAULT '0' NOT NULL,
FPROJECTNAMEDESC NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPROJECTTYPE BIGINT DEFAULT 0 NOT NULL,
FBILLTYPE BIGINT DEFAULT 0 NOT NULL,
FUSEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCHANGEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCHANGETIMES INT DEFAULT 0 NOT NULL,
FISCHANGE CHAR(1) DEFAULT '0' NOT NULL,
FCOSTCENTERID BIGINT DEFAULT 0 NOT NULL,
FWLTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
FWLUNIT BIGINT DEFAULT 0 NOT NULL,
FWITHHOLDINGAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCHANGETYPE CHAR(1) DEFAULT '0' NOT NULL,
FFIPERIOD DATETIME,
FACAPPROVEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_COSTESTIMATEBILL_LK')
 CREATE TABLE T_ER_COSTESTIMATEBILL_LK (
FID BIGINT DEFAULT 0 NOT NULL,
FPKID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FSTABLEID BIGINT DEFAULT 0 NOT NULL,
FSBILLID BIGINT DEFAULT 0 NOT NULL,
FSID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_COSTESTIMATEBILL_TC')
 CREATE TABLE T_ER_COSTESTIMATEBILL_TC (
FID BIGINT DEFAULT 0 NOT NULL,
FTBILLID BIGINT DEFAULT 0 NOT NULL,
FTTABLEID BIGINT DEFAULT 0 NOT NULL,
FTID BIGINT DEFAULT 0 NOT NULL,
FSBILLID BIGINT DEFAULT 0 NOT NULL,
FSTABLEID BIGINT DEFAULT 0 NOT NULL,
FSID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_COSTESTIMATEBILL_WB')
 CREATE TABLE T_ER_COSTESTIMATEBILL_WB (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FRULEVERID BIGINT DEFAULT 0 NOT NULL,
FRULEITEMID BIGINT DEFAULT 0 NOT NULL,
FOPERATE VARCHAR(30) DEFAULT ' ' NOT NULL,
FSTABLEID BIGINT DEFAULT 0 NOT NULL,
FSID BIGINT DEFAULT 0 NOT NULL,
FSBILLID BIGINT DEFAULT 0 NOT NULL,
FWRITEVALUE DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_COSTESTIMATEENTRY')
 CREATE TABLE T_ER_COSTESTIMATEENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FEXPENSEITEMID BIGINT DEFAULT 0 NOT NULL,
FHAPPENDATE DATETIME,
FENTRYCURRENCY BIGINT DEFAULT 0 NOT NULL,
FEXCHANGERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURRAPPLYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAPPLYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEAPPROVEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEAPPROVECURRAMOUNT DECIMAL(23,10) DEFAULT 0 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,
FENTRYCHANGEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENTRYORICHANGEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENTRYCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FENTRYCOSTDEPTID BIGINT DEFAULT 0 NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FENTRYCOSTCENTERID BIGINT DEFAULT 0 NOT NULL,
FENTRYWLTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
FENTRYWLUNIT BIGINT DEFAULT 0 NOT NULL,
FENTRYPRODUCTTYPE BIGINT 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,
FPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSOURCEBILLTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
FSOURCEBILLID BIGINT DEFAULT 0 NOT NULL,
FSOURCEENTRYID BIGINT DEFAULT 0 NOT NULL,
FSOURCEBILLNO VARCHAR(50) DEFAULT ' ' NOT NULL,
FENTRYREMARK VARCHAR(500) DEFAULT ' ' NOT NULL,
FEXPORIWITHHOLDINGAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPWITHHOLDINGAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENTRYAPPLYPROJECTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENTRYCHANGEABLEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FITEMFROM CHAR(1) DEFAULT '0' NOT NULL,
FCHANGETAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FACTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCHANGEORIENTRYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FACORIENTRYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FACEXPEAPPROVEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FACEXPEAPPROVECURRAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_COSTESTIMATEENTRY_LK')
 CREATE TABLE T_ER_COSTESTIMATEENTRY_LK (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FPKID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FSTABLEID BIGINT DEFAULT 0 NOT NULL,
FSBILLID BIGINT DEFAULT 0 NOT NULL,
FSID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_COSTESTIMATEOWER')
 CREATE TABLE T_ER_COSTESTIMATEOWER (
FPKID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);



