IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRIPREIM_AUTOCREATE')
CREATE TABLE T_ER_TRIPREIM_AUTOCREATE
(
    FID              BIGINT       DEFAULT 0   NOT NULL,
    FNUMBER          VARCHAR(100) DEFAULT ' ' NOT NULL,
    FNAME            NVARCHAR(100) DEFAULT ' ' NOT NULL,
    FSTATUS          CHAR(1)      DEFAULT 'C' NOT NULL,
    FCREATORID       BIGINT       DEFAULT 0   NOT NULL,
    FMODIFIERID      BIGINT       DEFAULT 0   NOT NULL,
    FENABLE          CHAR(1)      DEFAULT '1' NOT NULL,
    FCREATETIME      DATETIME,
    FMODIFYTIME      DATETIME,
    FMASTERID        BIGINT       DEFAULT 0   NOT NULL,
    FCREATEORGID     BIGINT       DEFAULT 0   NOT NULL,
    FORGID           BIGINT       DEFAULT 0   NOT NULL,
    FCTRLSTRATEGY    CHAR(1)      DEFAULT '5' NOT NULL,
    FSOURCEDATAID    BIGINT       DEFAULT 0   NOT NULL,
    FBITINDEX        BIGINT       DEFAULT 0   NOT NULL,
    FSOURCEBITINDEX  BIGINT       DEFAULT 0   NOT NULL,
    FSRCCREATEORGID  BIGINT       DEFAULT 0   NOT NULL,
    FONLYLINKEDORDER CHAR(1)      DEFAULT '0' NOT NULL,
    FAUTOMATICMATCH  CHAR(1)      DEFAULT '0' NOT NULL,
    FPUSHMODE        CHAR(1)      DEFAULT '0' NOT NULL,
    FPUSHPERSON      VARCHAR(30)  DEFAULT ' ' NOT NULL,
    FPUSHTIME        BIGINT       DEFAULT 0   NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_AUTOCREATEREIMLOG')
CREATE TABLE T_ER_AUTOCREATEREIMLOG
(
    FID                BIGINT       DEFAULT 0   NOT NULL,
    FBILLNO             VARCHAR(100) DEFAULT ' ' NOT NULL,
    FBILLID            BIGINT       DEFAULT 0   NOT NULL,
    FCOMPANY           BIGINT       DEFAULT 0   NOT NULL,
    FTRIPREIMBURSETYPE VARCHAR(30)  DEFAULT ' ' NOT NULL,
    FTO                NVARCHAR(200) DEFAULT ' ' NOT NULL,
    FAUTOCREATECONFIG  BIGINT       DEFAULT 0   NOT NULL,
    FCREATOR           BIGINT       DEFAULT 0   NOT NULL,
    FISSUCCESS         CHAR(1)      DEFAULT '0' NOT NULL,
    FERRORMSG          NVARCHAR(200) DEFAULT ' ' NOT NULL,
    FAPPLIER           BIGINT       DEFAULT 0   NOT NULL,
    FRSTARTDATE        DATETIME,
    FRENDDATE          DATETIME,
    FPUSHTIME          DATETIME,
    FCREATEDATE        DATETIME,
    FMODIFYDATE        DATETIME,
    FPUSHTIMECONFIG    INT          DEFAULT 0   NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRIPREIM_AUTOCREATE_L')
CREATE TABLE T_ER_TRIPREIM_AUTOCREATE_L
(
    FPKID     VARCHAR(30) DEFAULT ' ' NOT NULL,
    FID       BIGINT      DEFAULT 0   NOT NULL,
    FNAME     NVARCHAR(200) DEFAULT ' ' NOT NULL,
    FLOCALEID VARCHAR(20) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_AUTOCREATEREIMLOG_L')
CREATE TABLE T_ER_AUTOCREATEREIMLOG_L
(
    FPKID     VARCHAR(30) DEFAULT ' ' NOT NULL,
    FID       BIGINT      DEFAULT 0   NOT NULL,
    FNAME     NVARCHAR(200) DEFAULT ' ' NOT NULL,
    FLOCALEID VARCHAR(20) DEFAULT ' ' NOT NULL
);

EXEC P_ALTERPK 'PK_ER_TRIPREIM_AUTOCREATE', 'T_ER_TRIPREIM_AUTOCREATE', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_ER_TRIPREIM_AUTOCREATE') CREATE INDEX IDX_T_ER_TRIPREIM_AUTOCREATE ON T_ER_TRIPREIM_AUTOCREATE ( FMASTERID );


EXEC P_ALTERPK 'PK_ER_AUTOCREATEREIMLOG', 'T_ER_AUTOCREATEREIMLOG', 'FID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_AUTOCREATEREIMLOG') CREATE INDEX IDX_ER_AUTOCREATEREIMLOG ON T_ER_AUTOCREATEREIMLOG ( FPUSHTIME ,FAUTOCREATECONFIG );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_AUTOCREATEREIMLOGBILLID') CREATE INDEX IDX_ER_AUTOCREATEREIMLOGBILLID ON T_ER_AUTOCREATEREIMLOG ( FBILLID );

EXEC P_ALTERPK 'PK_ER_TRIPREIM_AUTOCREATE_L', 'T_ER_TRIPREIM_AUTOCREATE_L', 'FPKID', '1';

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


EXEC P_ALTERPK 'PK_ER_AUTOCREATEREIMLOG_L', 'T_ER_AUTOCREATEREIMLOG_L', 'FPKID', '1';

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