/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\ER_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_EXPENSESHAREBILL_L') 
 CREATE TABLE T_ER_EXPENSESHAREBILL_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FAPPLIERPOSITIONSTR VARCHAR(100) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_EXPENSESHAREDETAIL') 
 CREATE TABLE T_ER_EXPENSESHAREDETAIL (
FID BIGINT DEFAULT 0 NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FEXPENSEITEMID BIGINT DEFAULT 0 NOT NULL,
FHAPPENDATE DATETIME,
FEXCHANGERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORIAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURRREIMBURSEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREIMBURSEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREMARK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FISSPECIALINVOICE CHAR(1) DEFAULT '1' NOT NULL,
FENTRYCURRENCY BIGINT DEFAULT 0 NOT NULL,
FEXPEAPPROVEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEAPPROVECURRAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXCLASSCODEID BIGINT DEFAULT 0 NOT NULL,
FINVOICENO NVARCHAR(129) DEFAULT ' ' NOT NULL,
FINVOICELINK NVARCHAR(129) DEFAULT ' ' NOT NULL,
FOFFSET CHAR(1) DEFAULT '1' NOT NULL,
FENTRYCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FENTRYCOSTDEPTID BIGINT DEFAULT 0 NOT NULL,
FSERIALNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FAIRPORTCONSTRUCTIONFEE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FGOODSNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDEDUCTIBLETAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FITEMFROM VARCHAR(2) DEFAULT '0' NOT NULL,
FINVOICETYPEITEM VARCHAR(2) DEFAULT '0' NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FSHARERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FLKWAITENTRYID VARCHAR(200) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_EXPENSESHARERULE') 
 CREATE TABLE T_ER_EXPENSESHARERULE (
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,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FSHARERATE DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_EXPENSESHAREWAIT') 
 CREATE TABLE T_ER_EXPENSESHAREWAIT (
FID BIGINT DEFAULT 0 NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FEXPENSEITEMID BIGINT DEFAULT 0 NOT NULL,
FHAPPENDATE DATETIME,
FEXCHANGERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORIAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURRREIMBURSEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREIMBURSEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREMARK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FISSPECIALINVOICE CHAR(1) DEFAULT '1' NOT NULL,
FENTRYCURRENCY BIGINT DEFAULT 0 NOT NULL,
FEXPEAPPROVEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEAPPROVECURRAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXCLASSCODEID BIGINT DEFAULT 0 NOT NULL,
FINVOICENO NVARCHAR(129) DEFAULT ' ' NOT NULL,
FINVOICELINK NVARCHAR(129) DEFAULT ' ' NOT NULL,
FOFFSET CHAR(1) DEFAULT '1' NOT NULL,
FENTRYCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FENTRYCOSTDEPTID BIGINT DEFAULT 0 NOT NULL,
FSERIALNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FAIRPORTCONSTRUCTIONFEE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FGOODSNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDEDUCTIBLETAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FITEMFROM VARCHAR(2) DEFAULT '0' NOT NULL,
FINVOICETYPEITEM VARCHAR(2) DEFAULT '0' NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FSRCBILLTYPE VARCHAR(100) DEFAULT ' ' NOT NULL,
FSOURCEBILLNO VARCHAR(100) DEFAULT ' ' NOT NULL,
FSOURCEBILLID VARCHAR(100) DEFAULT ' ' NOT NULL,
FSOURCEENTRYID VARCHAR(100) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_EXPENSESHAREBILL') 
 CREATE TABLE T_ER_EXPENSESHAREBILL (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO VARCHAR(60) DEFAULT ' ' NOT NULL,
FBILLSTATUS VARCHAR(30) DEFAULT ' ' 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,
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(100) DEFAULT ' ' NOT NULL,
FWAITAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FWAITAPPROVEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREIMBURSEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAPPROVEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FIMAGENUMBER VARCHAR(255) DEFAULT ' ' NOT NULL,
FFORMID VARCHAR(30) DEFAULT ' ' NOT NULL,
FHASVOUCHER CHAR(1) DEFAULT '0' NOT NULL,
FAPPLIERPOSITIONSTR NVARCHAR(100) DEFAULT ' ' NOT NULL,
FISOVERBUDGET CHAR(1) DEFAULT '0' NOT NULL,
FSHARESTATUS VARCHAR(30) DEFAULT ' ' NOT NULL,
FSHARERULE VARCHAR(30) DEFAULT ' ' NOT NULL,
FSHAREMETHOD VARCHAR(30) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FORISHAREDAMOUNT') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FORISHAREDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_EXPENSEDETAIL' AND KSQL_COL_NAME ='FSHAREDAMOUNT') 
 ALTER TABLE T_ER_EXPENSEDETAIL ADD (FSHAREDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSETRIPENTRY' AND KSQL_COL_NAME ='FORISHAREDAMOUNT') 
 ALTER TABLE T_ER_REIMBURSETRIPENTRY ADD (FORISHAREDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSETRIPENTRY' AND KSQL_COL_NAME ='FSHAREDAMOUNT') 
 ALTER TABLE T_ER_REIMBURSETRIPENTRY ADD (FSHAREDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMEXPDET' AND KSQL_COL_NAME ='FORISHAREDAMOUNT') 
 ALTER TABLE T_ER_PUBREIMEXPDET ADD (FORISHAREDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMEXPDET' AND KSQL_COL_NAME ='FSHAREDAMOUNT') 
 ALTER TABLE T_ER_PUBREIMEXPDET ADD (FSHAREDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_DAILYREIMBURSEBILL' AND KSQL_COL_NAME ='FISSHARED') 
 ALTER TABLE T_ER_DAILYREIMBURSEBILL ADD (FISSHARED CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_DAILYREIMBURSEBILL' AND KSQL_COL_NAME ='FSHAREDAMOUNT') 
 ALTER TABLE T_ER_DAILYREIMBURSEBILL ADD (FSHAREDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSEBILL' AND KSQL_COL_NAME ='FISSHARED') 
 ALTER TABLE T_ER_REIMBURSEBILL ADD (FISSHARED CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_REIMBURSEBILL' AND KSQL_COL_NAME ='FSHAREDAMOUNT') 
 ALTER TABLE T_ER_REIMBURSEBILL ADD (FSHAREDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMBILL' AND KSQL_COL_NAME ='FISSHARED') 
 ALTER TABLE T_ER_PUBREIMBILL ADD (FISSHARED CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMBILL' AND KSQL_COL_NAME ='FSHAREDAMOUNT') 
 ALTER TABLE T_ER_PUBREIMBILL ADD (FSHAREDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_EXPENSESHAREWAIT_LK') 
 CREATE TABLE T_ER_EXPENSESHAREWAIT_LK (
FDETAILID 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_EXPENSESHAREBILL_WB') 
 CREATE TABLE T_ER_EXPENSESHAREBILL_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_EXPENSESHAREBILL_LK') 
 CREATE TABLE T_ER_EXPENSESHAREBILL_LK (
FID BIGINT DEFAULT 0 NOT NULL,
FPKID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
STABLEID 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_EXPENSESHAREBILL_TC') 
 CREATE TABLE T_ER_EXPENSESHAREBILL_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
); 
 
/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\ER_table.sql **/
