/**预付单**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_PREPAYBILL')
 CREATE TABLE T_ER_PREPAYBILL (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO VARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS VARCHAR(1) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 1 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 1 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,
FFORMID VARCHAR(30) DEFAULT ' ' NOT NULL,
FAPPLIERPOSITIONSTR NVARCHAR(100) DEFAULT ' ' NOT NULL,
FHASVOUCHER CHAR(1) DEFAULT '0' NOT NULL,
FHEAD_PAYDATE DATETIME,
FISOVERBUDGET CHAR(1) DEFAULT '0' NOT NULL,
FREPAYMENTDATE DATETIME,
FAPPROVEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUSEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPAYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FNOTPAYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FLOANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAPPLIEDREIMBURSEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FIMAGENUMBER VARCHAR(80) DEFAULT ' ' NOT NULL,
FISIMPORT CHAR(1) DEFAULT '0' NOT NULL,
FRETURNEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPREPAYTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
FSTD_COSTCENTER BIGINT DEFAULT 0 NOT NULL,
FISPAYBYHEAD CHAR(1) DEFAULT '0' NOT NULL,
FSTDBILLTYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FBILLPAYERTYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FISURGENT CHAR(1) DEFAULT '0' NOT NULL,
FBILLPAYERID BIGINT DEFAULT 0 NOT NULL
);


/**预付单预付信息分录)**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_PREPAYBILLENTRY')
 CREATE TABLE T_ER_PREPAYBILLENTRY (
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,
FEXCHANGERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FLOANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURRLOANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEAPPROVEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEAPPROVECURRAMOUNT 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,
FREMARK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FORGIEXPEBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPORIUSEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPUSEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEORIREPAYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEREPAYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEORIHASREIMAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXPEHASREIMAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSOURCEBILLID BIGINT DEFAULT 0 NOT NULL,
FSOURCEENTRYID BIGINT DEFAULT 0 NOT NULL,
FENTRYPROJECTNO VARCHAR(30) DEFAULT ' ' NOT NULL,
FENTRYCONTRACTNO VARCHAR(30) DEFAULT ' ' NOT NULL,
FSTD_ENTRYCOSTCENTER BIGINT DEFAULT 0 NOT NULL,
FSOURCEBILLTYPE VARCHAR(30) DEFAULT ' ' NOT NULL
);
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PREPAYBILLENTRY' AND KSQL_COL_NAME ='FSOURCEBILLNO')
 ALTER TABLE T_ER_PREPAYBILLENTRY ADD (FSOURCEBILLNO VARCHAR(30) DEFAULT ' ' NOT NULL );

/** 预付单收款信息分录）**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_PREPAYBILLRECENTRY')
 CREATE TABLE T_ER_PREPAYBILLRECENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FPAYMODEID BIGINT DEFAULT 0 NOT NULL,
FPAYERID BIGINT DEFAULT 0 NOT NULL,
FPAYERNAME NVARCHAR(100) DEFAULT ' ' NOT NULL ,
FPAYERBANKID BIGINT DEFAULT 0 NOT NULL,
FPAYERACCOUNT02 VARCHAR(100) DEFAULT ' ' NOT NULL,
FPAYERACCOUNT VARCHAR(100) DEFAULT ' ' NOT NULL,
FACCOUNTCURRENCY BIGINT DEFAULT 0 NOT NULL,
FENTRYCURRENCY BIGINT DEFAULT 0 NOT NULL,
FEXCHANGERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORIAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPAYERACCOUNT01 VARCHAR(100) DEFAULT ' ' NOT NULL,
FBANKLOGO VARCHAR(50) DEFAULT ' ' NOT NULL,
FENTRYREPAYDATE DATETIME,
FACCBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORIACCBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORGIAPPLYEDREIMAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAPPLYEDREIMAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORGIWRITEOFFAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FWRITEOFFAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORIACCNOTPAYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FACCNOTPAYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBUILDEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORIACCPAYEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FACCPAYEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENTRYSTATUS CHAR(1) DEFAULT '0' NOT NULL,
FORGIREPAIDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREPAIDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPAYERDEPTID BIGINT DEFAULT 0 NOT NULL,
FPAYERCOMPID BIGINT DEFAULT 0 NOT NULL,
FSUPPLIER BIGINT DEFAULT 0 NOT NULL,
FCUSTOMER BIGINT DEFAULT 0 NOT NULL,
FENTRYPAYERTYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FPAYERACCOUNTNAME VARCHAR(100) DEFAULT ' ' NOT NULL,
FCASORG BIGINT DEFAULT 0 NOT NULL
);

/**预付单付款信息分录)**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_PREPAYBILLPAYENTRY')
 CREATE TABLE T_ER_PREPAYBILLPAYENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FTARGETBILLID BIGINT DEFAULT 0 NOT NULL,
FTARGETBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FTARGETBIZDATE DATETIME,
FTARGETPAYDATE DATETIME,
FTARGETPAYORG BIGINT DEFAULT 0 NOT NULL,
FTARGETOPENORG BIGINT DEFAULT 0 NOT NULL,
FTARGETPAYACCT VARCHAR(50) DEFAULT ' ' NOT NULL,
FTARGETPAYACCTID BIGINT DEFAULT 0 NOT NULL,
FTARGETPAYBANK BIGINT DEFAULT 0 NOT NULL,
FTARGETCURRENCY BIGINT DEFAULT 0 NOT NULL,
FTARGETEXCHANGE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTARGETPAYAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTARGETLOCALAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTARGETENTRUSTORG BIGINT DEFAULT 0 NOT NULL,
FTARGETSETTLETYPE BIGINT DEFAULT 0 NOT NULL,
FDPCURRENCY BIGINT DEFAULT 0 NOT NULL,
FDPEXCHANGERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FDPAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FDPLOCALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAGREEDRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FLOSSAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FFEE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FFEECURRENCY BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_PREPAYBILL_L')
 CREATE TABLE T_ER_PREPAYBILL_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_PREPAYBILL_LK')
 CREATE TABLE T_ER_PREPAYBILL_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_PREPAYBILL_TC')
 CREATE TABLE T_ER_PREPAYBILL_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_PREPAYBILL_WB')
 CREATE TABLE T_ER_PREPAYBILL_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_PREPAYBILLENTRY_LK')
 CREATE TABLE T_ER_PREPAYBILLENTRY_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
);

