/**T_ER_APPLYPAYBILL(付款申请单)**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_APPLYPAYBILL')
 CREATE TABLE T_ER_APPLYPAYBILL (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO VARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS VARCHAR(1) 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,
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,
FLOANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
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,
FIMAGENUMBER VARCHAR(80) 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,
FBILLPAYERID BIGINT DEFAULT 0 NOT NULL,
FISURGENT CHAR(1) DEFAULT '0' NOT NULL,
FSTDREIMBURSETYPE VARCHAR(50) DEFAULT ' ' NOT NULL
);



/**(付款申请单_多语言)**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_APPLYPAYBILL_L')
 CREATE TABLE T_ER_APPLYPAYBILL_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_APPLYPAYBILL_LK')
 CREATE TABLE T_ER_APPLYPAYBILL_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_APPLYPAYBILL_TC')
 CREATE TABLE T_ER_APPLYPAYBILL_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_APPLYPAYBILL_WB')
 CREATE TABLE T_ER_APPLYPAYBILL_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
);

/**Y(付款申请单_分录付款信息)*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_APPLYPAYBILLPAYENTRY')
 CREATE TABLE T_ER_APPLYPAYBILLPAYENTRY (
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_APPLYPAYBILLRECENTRY')
 CREATE TABLE T_ER_APPLYPAYBILLRECENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FPAYMODEID BIGINT DEFAULT 0 NOT NULL,
FPAYERNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FPAYERID BIGINT DEFAULT 0 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,
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,
FSOURCEBILLTYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FSOURCEBILLNO VARCHAR(30) DEFAULT ' ' NOT NULL,
FSOURCEBILLID BIGINT DEFAULT 0 NOT NULL,
FSOURCEENTRYID BIGINT DEFAULT 0 NOT NULL
);



/**(付款申请单_分录立项合同信息)**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_APPLYPAYBILLENTRY')
 CREATE TABLE T_ER_APPLYPAYBILLENTRY (
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,
FENTRYCURRENCY BIGINT 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,
FENTRYPROJECTNO VARCHAR(30) DEFAULT ' ' NOT NULL,
FENTRYCONTRACTNO VARCHAR(30) DEFAULT ' ' NOT NULL,
FSTD_ENTRYCOSTCENTER BIGINT DEFAULT 0 NOT NULL,
FENTRYPROJECTNAME VARCHAR(500) DEFAULT ' ' NOT NULL,
FENTRYCONTRACTNAME VARCHAR(500) DEFAULT ' ' NOT NULL
);

/**付款申请单_收款信息分录关联表)*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_APPLYPAYBILLRECENTRY_LK')
 CREATE TABLE T_ER_APPLYPAYBILLRECENTRY_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
);