/**新差旅出差申请单相关表语句**/
/**单头表**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NREQBILL')
CREATE TABLE T_ER_NREQBILL
(
    FID                      BIGINT          DEFAULT 0   NOT NULL,
    FBILLSTATUS              NVARCHAR(10)    DEFAULT ' ' NOT NULL,
    FBILLNO                  NVARCHAR(50)    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,
    FORGID                   BIGINT          DEFAULT 0   NOT NULL,
    FCOMPANYID               BIGINT          DEFAULT 0   NOT NULL,
    FTEL                     NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FBIZDATE                 DATETIME,
    FCOSTDEPTID              BIGINT          DEFAULT 0   NOT NULL,
    FCOSTCOMPANYID           BIGINT          DEFAULT 0   NOT NULL,
    FSTDCOSTCENTERID         BIGINT          DEFAULT 0   NOT NULL,
    FPAYCOMPANYID            BIGINT          DEFAULT 0   NOT NULL,
    FTRIPTYPEID              BIGINT          DEFAULT 0   NOT NULL,
    FISCURRENCY              CHAR(1)         DEFAULT '0' NOT NULL,
    FISTRAVELERS             CHAR(1)         DEFAULT '0' NOT NULL,
    FISPAYBYHEAD             CHAR(1)         DEFAULT '0' NOT NULL,
    FLOANAMOUNT              DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FREPAYMENTDATE           DATETIME,
    FROUTETYPE               NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FDESCRIPTION             NVARCHAR(1000)  DEFAULT ' ' NOT NULL,
    FRETURNEDMOUNT           DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FIMAGENO                 NVARCHAR(100)   DEFAULT ' ' NOT NULL,
    FRFROM                   NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FRTO                     NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FFIRSTTO                 NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FRSTARTDATE              DATETIME,
    FRENDDATE                DATETIME,
    FISLOAN                  CHAR(1)         DEFAULT '0' NOT NULL,
    FRVEHICLE                NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FFULLAPP                 CHAR(1)         DEFAULT '0' NOT NULL,
    FEDITENTRY               NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FRFIRSTENDATE            DATETIME,
    FPLANDAYS                BIGINT          DEFAULT 0   NOT NULL,
    FREIMBUESETIME           BIGINT          DEFAULT 0   NOT NULL,
    FNEEDUPLOADINVOICE       CHAR(1)         DEFAULT '0' NOT NULL,
    FCURRENCYID              BIGINT          DEFAULT 0   NOT NULL,
    FAPPLIERID               BIGINT          DEFAULT 0   NOT NULL,
    FAPPLIERPOSITION         NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FORIRECEIVEAMOUNT        DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FRACCOUNTCURRENCY        BIGINT          DEFAULT 0   NOT NULL,
    FRACCEXCHANGERATE        DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FFORMID                  NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FAPPROVEAMOUNT           DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FBALANCEAMOUNT           DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FEXPENSESASSUMESHOWTYPES DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FISQUERYBUDGET           CHAR(1)         DEFAULT '0' NOT NULL,
    FNEXTAUDITOR             NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FISOVERBUDGET            CHAR(1)         DEFAULT '0' NOT NULL,
    FAMOUNT                  DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FUSEDAMOUNT              DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FENCASHAMOUNT            DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FHEADPAYDATE             DATETIME,
    FUNAUDITMSG              NVARCHAR(1000)  DEFAULT ' ' NOT NULL,
    FSOURCEBILLID            NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FPAYAMOUNT               DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FNOTPAYAMOUNT            DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FHASVOUCHER              CHAR(1)         DEFAULT '0' NOT NULL,
    FORIGIN                  NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FISMULWAYTO              CHAR(1)         DEFAULT '0' NOT NULL,
    FATTACHMENTCOUNT         BIGINT          DEFAULT 0   NOT NULL,
    FISMANUALREPAY           CHAR(1)         DEFAULT '0' NOT NULL,
    FISCHANGE                CHAR(1)         DEFAULT '0' NOT NULL,
    FBOOKEDDATE              DATETIME,
    FUNREPAYMENTAMOUNT       DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FBIZITEM                 BIGINT          DEFAULT 0   NOT NULL
);
EXEC P_ALTERPK 'PK_ER_NREQBILL', 'T_ER_NREQBILL', 'FID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREQBILLNO')
CREATE INDEX IDX_ER_NREQBILLNO ON T_ER_NREQBILL (FBILLNO);

/**单头拆分表**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NREQBILL_A')
CREATE TABLE T_ER_NREQBILL_A
(
    FID                 BIGINT       DEFAULT 0   NOT NULL,
    FISENABLEINVOICE    CHAR(1)      DEFAULT '0' NOT NULL,
    FNEEDIMAGESCAN      NVARCHAR(50) DEFAULT ' ' NOT NULL,
    FINVOKEINVOICECLOUD CHAR(1)      DEFAULT '0' NOT NULL
);
EXEC P_ALTERPK 'PK_ER_NREQBILL_A', 'T_ER_NREQBILL_A', 'FID', '1';

/*出差申请单多语言表*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NREQBILL_L')
CREATE TABLE T_ER_NREQBILL_L
(
    FID              BIGINT        DEFAULT 0   NOT NULL,
    FLOCALEID        VARCHAR(36)   DEFAULT ' ' NOT NULL,
    FPKID            VARCHAR(18)   DEFAULT ' ' NOT NULL,
    FAPPLIERPOSITION NVARCHAR(100) DEFAULT ' ' NOT NULL
);
EXEC P_ALTERPK 'PK_ER_NREQBILL_L', 'T_ER_NREQBILL_L', 'FPKID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREQBILL_L')
CREATE UNIQUE INDEX IDX_ER_NREQBILL_L ON T_ER_NREQBILL_L (FID, FLOCALEID);

/**行程表**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NREQTRIPENTRY')
CREATE TABLE T_ER_NREQTRIPENTRY
(
    FENTRYID              BIGINT          DEFAULT 0              NOT NULL,
    FID                   BIGINT          DEFAULT 0              NOT NULL,
    FSEQ                  INT             DEFAULT 0              NOT NULL,
    FFROMPLACEID          BIGINT          DEFAULT 0              NOT NULL,
    FTOPLACEID            BIGINT          DEFAULT 0              NOT NULL,
    FSTARTDATE            DATETIME,
    FENDDATE              DATETIME,
    FTRIPDAY              INT             DEFAULT 0              NOT NULL,
    FENTRYCOSTCOMPANYID   BIGINT          DEFAULT 0              NOT NULL,
    FENTRYCOSTDEPTID      BIGINT          DEFAULT 0              NOT NULL,
    FPROJECTID            BIGINT          DEFAULT 0              NOT NULL,
    FVEHICLE              NVARCHAR(50)    DEFAULT ' '            NOT NULL,
    FVEHICLES             NVARCHAR(500)   DEFAULT ' '            NOT NULL,
    FTRIPENTRYSTATUS      NVARCHAR(50)    DEFAULT ' '            NOT NULL,
    FINDEX                INT             DEFAULT 0              NOT NULL,
    FRCURRENCYID          BIGINT          DEFAULT 0              NOT NULL,
    FTRIPEXPENSEITEMID    BIGINT          DEFAULT 0              NOT NULL,
    FORIAMOUNT            DECIMAL(23, 10) DEFAULT 0              NOT NULL,
    FTRIPAMOUNT           DECIMAL(23, 10) DEFAULT 0              NOT NULL,
    FTRIPORIACCAPPAMOUNT  DECIMAL(23, 10) DEFAULT 0              NOT NULL,
    FTRIPACCAPPAMOUNT     DECIMAL(23, 10) DEFAULT 0              NOT NULL,
    FORIACCBALANCEAMOUNT  DECIMAL(23, 10) DEFAULT 0              NOT NULL,
    FACCBALANCEAMOUNT     DECIMAL(23, 10) DEFAULT 0              NOT NULL,
    FORIACCUSEDAMOUNT     DECIMAL(23, 10) DEFAULT 0              NOT NULL,
    FACCUSEDAMOUNT        DECIMAL(23, 10) DEFAULT 0              NOT NULL,
    FEXPEORIREPAYAMOUNT   DECIMAL(23, 10) DEFAULT 0              NOT NULL,
    FEXPEREPAYAMOUNT      DECIMAL(23, 10) DEFAULT 0              NOT NULL,
    FENTRYCREATETIME      DATETIME,
    FTRIPCURRENCYID       BIGINT          DEFAULT 0              NOT NULL,
    FTRIPEXCHANGERATE     DECIMAL(23, 10) DEFAULT 0              NOT NULL,
    FTRIPQUOTETYPE        CHAR(1)         DEFAULT '0'            NOT NULL,
    FISTRIPMULCURRENCY    CHAR(1)         DEFAULT '0'            NOT NULL,
    FTRIPENTRYAREA        BIGINT          DEFAULT 0              NOT NULL,
    FSTDENTRYCOSTCENTERID BIGINT          DEFAULT 0              NOT NULL,
    FENTRYKEY             NVARCHAR(50)    DEFAULT 'tripentrykey' NOT NULL
);
EXEC P_ALTERPK 'PK_ER_NREQTRIPENTRY', 'T_ER_NREQTRIPENTRY', 'FENTRYID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREQTRIPENTRY')
CREATE INDEX IDX_ER_NREQTRIPENTRY ON T_ER_NREQTRIPENTRY (FID);

/**行程明细表**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NREQENTRY')
CREATE TABLE T_ER_NREQENTRY
(
    FENTRYID         BIGINT          DEFAULT 0   NOT NULL,
    FDETAILID        BIGINT          DEFAULT 0   NOT NULL,
    FSEQ             INT             DEFAULT 0   NOT NULL,
    FCURRENCYID      BIGINT          DEFAULT 0   NOT NULL,
    FEXPENSEITEMID   BIGINT          DEFAULT 0   NOT NULL,
    FNOTAXAMOUNT     DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FEXCHANGERATE    DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FTAXAMOUNT       DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FAMOUNT          DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FORIAMOUNT       DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FTAXRATE         DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FDETAILQUOTETYPE CHAR(1)         DEFAULT '0' NOT NULL,
    FDAYCOUNT        BIGINT          DEFAULT 0   NOT NULL,
    FCOMMENT         NVARCHAR(255)   DEFAULT ' ' NOT NULL,
    FISVACTAX        CHAR(1)         DEFAULT '0' NOT NULL,
    FTRIPTOPLACEID   BIGINT          DEFAULT 0   NOT NULL
);
EXEC P_ALTERPK 'PK_ER_NREQENTRY', 'T_ER_NREQENTRY', 'FDETAILID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREQENTRYID')
CREATE INDEX IDX_ER_NREQENTRYID ON T_ER_NREQENTRY (FENTRYID);

/**单头多出差人**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPMULTITRAVELERS')
CREATE TABLE T_ER_NTRIPMULTITRAVELERS
(
    FPKID       BIGINT DEFAULT 0 NOT NULL,
    FID         BIGINT DEFAULT 0 NOT NULL,
    FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_ER_NTRIPMULTITRAVELERS', 'T_ER_NTRIPMULTITRAVELERS', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTRAVELERSBILLID')
CREATE INDEX IDX_ER_NTRAVELERSBILLID ON T_ER_NTRIPMULTITRAVELERS (FID);
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTRAVELERSUSERID')
CREATE INDEX IDX_ER_NTRAVELERSUSERID ON T_ER_NTRIPMULTITRAVELERS (FBASEDATAID);

/**行程多出差人**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NREQBILLPARTNER')
CREATE TABLE T_ER_NREQBILLPARTNER
(
    FPKID       BIGINT DEFAULT 0 NOT NULL,
    FENTRYID    BIGINT DEFAULT 0 NOT NULL,
    FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_ER_NREQBILLPARTNER', 'T_ER_NREQBILLPARTNER', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREQBILLPARTNER')
CREATE INDEX IDX_ER_NREQBILLPARTNER ON T_ER_NREQBILLPARTNER (FENTRYID);

/**行程途径地**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRIPMULWAYTOINTER')
CREATE TABLE T_ER_TRIPMULWAYTOINTER
(
    FPKID       BIGINT DEFAULT 0 NOT NULL,
    FENTRYID    BIGINT DEFAULT 0 NOT NULL,
    FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_ER_TRIPMULWAYTOINTER', 'T_ER_TRIPMULWAYTOINTER', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_TRIPMULWAYTOINTER')
CREATE INDEX IDX_ER_TRIPMULWAYTOINTER ON T_ER_TRIPMULWAYTOINTER (FENTRYID);

/**行程变更记录表**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPCHANGEHISTORY')
CREATE TABLE T_ER_NTRIPCHANGEHISTORY
(
    FENTRYID             BIGINT          DEFAULT 0   NOT NULL,
    FID                  BIGINT          DEFAULT 0   NOT NULL,
    FSEQ                 INT             DEFAULT 0   NOT NULL,
    FFROMPLACEID         BIGINT          DEFAULT 0   NOT NULL,
    FTOPLACEID           BIGINT          DEFAULT 0   NOT NULL,
    FSTARTDATE           DATETIME,
    FENDDATE             DATETIME,
    FCHANGETIME          DATETIME,
    FVEHICLE             VARCHAR(50)     DEFAULT ' ' NOT NULL,
    FTRIPEXPENSEITEMID   BIGINT          DEFAULT 0   NOT NULL,
    FENTRYCOSTDEPTID     BIGINT          DEFAULT 0   NOT NULL,
    FENTRYCOSTCOMPANYID  BIGINT          DEFAULT 0   NOT NULL,
    FPROJECTID           BIGINT          DEFAULT 0   NOT NULL,
    FORIAMOUNT           DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FTRIPAMOUNT          DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FTRIPORIACCAPPAMOUNT DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FTRIPACCAPPAMOUNT    DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FTRIPCURRENCYID      BIGINT          DEFAULT 0   NOT NULL,
    FEXCHANGERATE        DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FISTRIPMULCURRENCY   CHAR(1)         DEFAULT '0' NOT NULL,
    FSRCENTRYDATA        NCLOB,
    FSRCENTRYDATA_TAG    NCLOB,
    FSRCENTRYID          BIGINT          DEFAULT 0   NOT NULL,
    FCHANGER             BIGINT          DEFAULT 0   NOT NULL,
    FCHANGEDATE          DATETIME
);
EXEC P_ALTERPK 'PK_ER_NTRIPCHANGEHISTORY', 'T_ER_NTRIPCHANGEHISTORY', 'FENTRYID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_NCHANGE_SRCENTRYID')
CREATE INDEX IDX_NCHANGE_SRCENTRYID ON T_ER_NTRIPCHANGEHISTORY (FSRCENTRYID);

---发票云附件分录表---
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NINVOICEATTACHINFO')
CREATE TABLE T_ER_NINVOICEATTACHINFO
(
    FID            BIGINT       DEFAULT 0   NOT NULL,
    FENTRYID       BIGINT       DEFAULT 0   NOT NULL,
    FSEQ           INT          DEFAULT 0   NOT NULL,
    FATTACHNO      NVARCHAR(80) DEFAULT ' ' NOT NULL,
    FATTACHNAME    VARCHAR(255),
    FORIGINALNAME  VARCHAR(255),
    FATTACHTYPE    VARCHAR(30),
    FGATHERTIME    DATETIME,
    FATTACHREMARK  NVARCHAR(1024),
    FATTACHURL     VARCHAR(512),
    FSNAPSHOTURL   VARCHAR(512),
    FROTATIONANGLE VARCHAR(30)
);
---索引---
EXEC P_ALTERPK 'PK_ER_NINVOICEATTACHINFO', 'T_ER_NINVOICEATTACHINFO', 'FENTRYID', '0';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_TABNAME = 'T_ER_NINVOICEATTACHINFO' AND KSQL_INDNAME = 'IDX_ER_NINVOICEATTACHINFO_FID')
CREATE INDEX IDX_ER_NINVOICEATTACHINFO_FID ON T_ER_NINVOICEATTACHINFO (FID);

---付款信息表---
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPREQPAYENTRY')
CREATE TABLE T_ER_NTRIPREQPAYENTRY
(
    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,
    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,
    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,
    FTARGETSETTLETYPE  BIGINT          DEFAULT 0   NOT NULL,
    FTARGETPAYACCTID   BIGINT          DEFAULT 0   NOT NULL
);
---索引---
EXEC P_ALTERPK 'PK_ER_NTRIPREQPAYENTRY', 'T_ER_NTRIPREQPAYENTRY', 'FENTRYID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTQPE_TARGETBILLID_NO')
CREATE INDEX IDX_ER_NTQPE_TARGETBILLID_NO ON T_ER_NTRIPREQPAYENTRY (FTARGETBILLID, FTARGETBILLNO);
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTQPE_FEQ')
CREATE INDEX IDX_ER_NTQPE_FEQ ON T_ER_NTRIPREQPAYENTRY (FID, FSEQ);

---收款信息表---
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NREQACCOUNTENTRY')
CREATE TABLE T_ER_NREQACCOUNTENTRY
(
    FID                  BIGINT          DEFAULT 0   NOT NULL,
    FENTRYID             BIGINT          DEFAULT 0   NOT NULL,
    FSEQ                 INT             DEFAULT 0   NOT NULL,
    FPAYMODEID           BIGINT          DEFAULT 0   NOT NULL,
    FPAYERTYPE           NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FPAYERID             BIGINT          DEFAULT 0   NOT NULL,
    FPAYERNAME           NVARCHAR(100)   DEFAULT ' ' NOT NULL,
    FPAYERBANKID         BIGINT          DEFAULT 0   NOT NULL,
    FPAYERACCOUNT        NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FPAYERACCOUNTNAME    NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FPAYERACCOUNT02      NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FQUOTETYPE           CHAR(1)         DEFAULT '0' NOT NULL,
    FCURRENCYID          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      NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FBANKLOGO            NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FENTRYREPAYDATE      DATETIME,
    FORIACCBALANCEAMOUNT DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FACCBALANCEAMOUNT    DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FORIACCAPPAMOUNT     DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FACCAPPAMOUNT        DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FORIACCPAYEDAMOUNT   DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FACCPAYEDAMOUNT      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,
    FENTRYSTATUS         NVARCHAR(50)    DEFAULT ' ' NOT NULL,
    FACCPAIDAMOUNT       DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FPAIDAMOUNT          DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FPAYERDEPTID         BIGINT          DEFAULT 0   NOT NULL,
    FPAYERCOMPID         BIGINT          DEFAULT 0   NOT NULL
);
EXEC P_ALTERPK 'PK_ER_NREQACCOUNTENTRY', 'T_ER_NREQACCOUNTENTRY', 'FENTRYID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREQACCOUNTENTRY')
CREATE INDEX IDX_ER_NREQACCOUNTENTRY ON T_ER_NREQACCOUNTENTRY (FID, FSEQ);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NREQBILL_WB')
CREATE TABLE T_ER_NREQBILL_WB
(
    FID         BIGINT          DEFAULT 0   NOT NULL,
    FOPERATE    VARCHAR(30)     DEFAULT ' ' NOT NULL,
    FRULEVERID  BIGINT          DEFAULT 0   NOT NULL,
    FSBILLID    BIGINT          DEFAULT 0   NOT NULL,
    FSTABLEID   BIGINT          DEFAULT 0   NOT NULL,
    FSID        BIGINT          DEFAULT 0   NOT NULL,
    FWRITEVALUE DECIMAL(23, 10) DEFAULT 0   NOT NULL,
    FSEQ        INT             DEFAULT 0   NOT NULL,
    FENTRYID    BIGINT          DEFAULT 0   NOT NULL,
    FRULEITEMID BIGINT          DEFAULT 0   NOT NULL
);
EXEC P_ALTERPK 'PK_ER_NREQBILL_WB', 'T_ER_NREQBILL_WB', 'FENTRYID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREQBILL_WB')
CREATE INDEX IDX_ER_NREQBILL_WB ON T_ER_NREQBILL_WB (FID);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NREQBILL_TC')
CREATE TABLE T_ER_NREQBILL_TC
(
    FID       BIGINT DEFAULT 0 NOT NULL,
    FTBILLID  BIGINT DEFAULT 0 NOT NULL,
    FTTABLEID BIGINT DEFAULT 0 NOT NULL,
    FSBILLID  BIGINT DEFAULT 0 NOT NULL,
    FSTABLEID BIGINT DEFAULT 0 NOT NULL,
    FSID      BIGINT DEFAULT 0 NOT NULL,
    FTID      BIGINT DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_ER_NREQBILL_TC', 'T_ER_NREQBILL_TC', 'FID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREQBILL_TC_FTBLD')
CREATE INDEX IDX_ER_NREQBILL_TC_FTBLD ON T_ER_NREQBILL_TC (FTBILLID);
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREQBILL_TC_FSBLD')
CREATE INDEX IDX_ER_NREQBILL_TC_FSBLD ON T_ER_NREQBILL_TC (FSBILLID);



IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_NREQBILL' AND KSQL_COL_NAME IN ('FBIZTYPE'))
ALTER TABLE T_ER_NREQBILL
    ADD (FBIZTYPE VARCHAR (2) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_NREQBILL' AND KSQL_COL_NAME IN ('FBILLTYPE'))
ALTER TABLE T_ER_NREQBILL
    ADD (FBILLTYPE BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_NREQBILL' AND KSQL_COL_NAME IN ('FWRITEBILLMODE'))
ALTER TABLE T_ER_NREQBILL
    ADD (FWRITEBILLMODE VARCHAR (2) DEFAULT ' ' NOT NULL );


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_NREQTRIPENTRY' AND KSQL_COL_NAME IN ('FSOURCETRIPID'))
ALTER TABLE T_ER_NREQTRIPENTRY
    ADD (FSOURCETRIPID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_NREQTRIPENTRY' AND KSQL_COL_NAME IN ('FTRIPCANCEL'))
ALTER TABLE T_ER_NREQTRIPENTRY
    ADD (FTRIPCANCEL CHAR (1) DEFAULT ' ' NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_NREQENTRY' AND KSQL_COL_NAME IN ('FSOURCEENTRYID'))
ALTER TABLE T_ER_NREQENTRY
    ADD (FSOURCEENTRYID BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_NREQTRIPENTRY' AND KSQL_COL_NAME IN ('FTRIPORIAMOUNT'))
ALTER TABLE T_ER_NREQTRIPENTRY ADD (FTRIPORIAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL);

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

EXEC P_ALTERPK 'PK_T_ER_NREQBILL_LK', 'T_ER_NREQBILL_LK', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREQBILL_LK_FID')
CREATE INDEX IDX_ER_NREQBILL_LK_FID ON T_ER_NREQBILL_LK (FID);


/*行程LK*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NREQTRIPENTRY_LK')
CREATE TABLE T_ER_NREQTRIPENTRY_LK
(
    FSBILLID  BIGINT DEFAULT 0 NOT NULL,
    FSTABLEID BIGINT DEFAULT 0 NOT NULL,
    FSID      BIGINT DEFAULT 0 NOT NULL,
    FSEQ      INT    DEFAULT 0 NOT NULL,
    FENTRYID  BIGINT DEFAULT 0 NOT NULL,
    FPKID     BIGINT DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_T_ER_NREQTRIPENTRY_LK', 'T_ER_NREQTRIPENTRY_LK', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREQTRIPENTRY_LK_FENTRY')
CREATE INDEX IDX_ER_NREQTRIPENTRY_LK_FENTRY ON T_ER_NREQTRIPENTRY_LK (FENTRYID);

/*干系人*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPREQOWER')
CREATE TABLE T_ER_NTRIPREQOWER
(
    FID         BIGINT DEFAULT 0 NOT NULL,
    FBASEDATAID BIGINT DEFAULT 0 NOT NULL,
    FPKID       BIGINT DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_NTRIPREQOWER', 'T_ER_NTRIPREQOWER', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTRIPREQOWER_FID')
CREATE INDEX IDX_ER_NTRIPREQOWER_FID ON T_ER_NTRIPREQOWER (FID);

/**变更行程途径地**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_HISTORYMULWAYTOINTER')
CREATE TABLE T_ER_HISTORYMULWAYTOINTER
(
    FPKID       BIGINT DEFAULT 0 NOT NULL,
    FENTRYID    BIGINT DEFAULT 0 NOT NULL,
    FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_ER_HISTORMULWAYTOINTER', 'T_ER_HISTORYMULWAYTOINTER', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_HISTORMULWAYTOINTER')
CREATE INDEX IDX_ER_HISTORMULWAYTOINTER ON T_ER_HISTORYMULWAYTOINTER (FENTRYID);

/**变更行程多出差人**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPCHANGETRAVEL')
CREATE TABLE T_ER_NTRIPCHANGETRAVEL
(
    FPKID       BIGINT DEFAULT 0 NOT NULL,
    FENTRYID    BIGINT DEFAULT 0 NOT NULL,
    FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_ER_NTRIPCHANGETRAVEL', 'T_ER_NTRIPCHANGETRAVEL', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTRIPCHANGETRAVEL')
CREATE INDEX IDX_ER_NTRIPCHANGETRAVEL ON T_ER_NTRIPCHANGETRAVEL (FENTRYID);
