/* 费用预提单 主表 start */
IF NOT EXISTS(SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_WITHHOLDINGBILL')
CREATE TABLE T_ER_WITHHOLDINGBILL (
    FID                 BIGINT          DEFAULT 0   NOT NULL,
    FBILLNO             NVARCHAR(80)    DEFAULT ' ' NOT NULL,
    FBILLSTATUS         NVARCHAR(80)    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(500)   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                NVARCHAR(80)    DEFAULT ' ' NOT NULL,
    FFORMID             NVARCHAR(80)    DEFAULT ' ' NOT NULL,
    FAPPLIERPOSITIONSTR NVARCHAR(80)    DEFAULT ' ' NOT NULL,
    FHASVOUCHER         CHAR(1)         DEFAULT '0' NOT NULL,
    FISOVERBUDGET       CHAR(1)         DEFAULT '0' NOT NULL,
    FAPPLYAMOUNT        DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FIMAGENUMBER        NVARCHAR(80)    DEFAULT ' ' NOT NULL,
    FBALANCEAMOUNT      DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FLOANEDAMOUNT       DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FBILLCANLOANAMOUNT  DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FAPPROVEAMOUNT      DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FBILLTYPE           BIGINT          DEFAULT 0   NOT NULL,
    FWITHHOLDINGTYPE    BIGINT          DEFAULT 0   NOT NULL,
    FUSEDAMOUNT         DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FISWRITEOFF         CHAR(1)         DEFAULT '0' NOT NULL,
    FSTD_COSTCENTER     BIGINT          DEFAULT 0   NOT NULL,
    FWLUNIT             BIGINT          DEFAULT 0   NOT NULL,
    FWLTYPE             NVARCHAR(80)    DEFAULT ' ' NOT NULL,
    FFIPERIOD           DATETIME
);
/* 费用预提单 主表 end */

/* 费用预提单 主表 多语言 start */
IF NOT EXISTS(SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_WITHHOLDINGBILL_L')
CREATE TABLE T_ER_WITHHOLDINGBILL_L (
    FPKID               NVARCHAR(80) DEFAULT ' ' NOT NULL,
    FID                 BIGINT       DEFAULT 0   NOT NULL,
    FLOCALEID           NVARCHAR(80) DEFAULT ' ' NOT NULL,
    FAPPLIERPOSITIONSTR NVARCHAR(80) DEFAULT ' ' NOT NULL
);
/* 费用预提单 主表 多语言 end */

/* 费用预提单 关联表 start */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_WITHHOLDINGBILL_LK')
CREATE TABLE T_ER_WITHHOLDINGBILL_LK (
    FID BIGINT DEFAULT 0 NOT NULL,
    FPKID BIGINT DEFAULT 0 NOT NULL,
    FSEQ BIGINT DEFAULT 0 NOT NULL,
    FSTABLEID BIGINT DEFAULT 0 NOT NULL,
    FSBILLID BIGINT DEFAULT 0 NOT NULL,
    FSID BIGINT DEFAULT 0 NOT NULL
);
/* 费用预提单 关联表 end */

/* 费用预提单 追踪表 start */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_WITHHOLDINGBILL_TC')
CREATE TABLE T_ER_WITHHOLDINGBILL_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 */


/* 费用预提单 反写记录表 start */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_WITHHOLDINGBILL_WB')
CREATE TABLE T_ER_WITHHOLDINGBILL_WB (
    FID BIGINT DEFAULT 0 NOT NULL,
    FENTRYID BIGINT DEFAULT 0 NOT NULL,
    FSEQ BIGINT DEFAULT 0 NOT NULL,
    FRULEVERID BIGINT DEFAULT 0 NOT NULL,
    FRULEITEMID BIGINT DEFAULT 0 NOT NULL,
    FOPERATE NVARCHAR(80) 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
);
/* 费用预提单 反写记录表 end */

/* 费用预提单 明细 start */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_WITHHOLDINGENTRY')
CREATE TABLE T_ER_WITHHOLDINGENTRY (
    FID BIGINT DEFAULT 0 NOT NULL,
    FENTRYID BIGINT DEFAULT 0 NOT NULL,
    FSEQ BIGINT 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,
    FAPPLYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
    FCURRAPPLYAMOUNT 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,
    FORGIEXPEBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
    FEXPEBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
    FPUSHEDAMOUNT 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,
    FPUSHEDCURRAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
    FSTD_ENTRYCOSTCENTER BIGINT DEFAULT 0 NOT NULL,
    FENTRYWLUNIT BIGINT DEFAULT 0 NOT NULL,
    FENTRYPRODUCTTYPE BIGINT DEFAULT 0 NOT NULL,
    FSOURCEBILLTYPE NVARCHAR(80) DEFAULT ' ' NOT NULL,
    FSOURCEBILLID BIGINT DEFAULT 0 NOT NULL,
    FSOURCEENTRYID BIGINT DEFAULT 0 NOT NULL,
    FENTRYWLTYPE NVARCHAR(80) DEFAULT ' ' 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,
    FENTRYFIACCOUNT BIGINT DEFAULT 0 NOT NULL,
    FOFFSET CHAR(1) DEFAULT '0' NOT NULL,
    FDEDUCTIBLETAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
    FSOURCEBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
    FDESC NVARCHAR(500) DEFAULT ' ' NOT NULL
);
/* 费用预提单 明细 end */

/* 费用预提单 明细 关联表 start */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_WITHHOLDINGENTRY_LK')
CREATE TABLE T_ER_WITHHOLDINGENTRY_LK (
    FENTRYID BIGINT DEFAULT 0 NOT NULL,
    FPKID BIGINT DEFAULT 0 NOT NULL,
    FSEQ BIGINT DEFAULT 0 NOT NULL,
    FSTABLEID BIGINT DEFAULT 0 NOT NULL,
    FSBILLID BIGINT DEFAULT 0 NOT NULL,
    FSID BIGINT DEFAULT 0 NOT NULL
);
/* 费用预提单 明细 关联表 end */