IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_INVOICEPGINFO_L')
CREATE TABLE T_ER_INVOICEPGINFO_L (
                                      FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
                                      FID BIGINT DEFAULT 0 NOT NULL,
                                      FNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                      FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_QUICKREIMCONFIG_L')
CREATE TABLE T_ER_QUICKREIMCONFIG_L (
                                        FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
                                        FID BIGINT DEFAULT 0 NOT NULL,
                                        FNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                        FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL
);


/** 一键报销配置 **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_QUICKREIMCONFIG')
CREATE TABLE T_ER_QUICKREIMCONFIG (
                                      FID BIGINT DEFAULT 0 NOT NULL,
                                      FNUMBER VARCHAR(255) DEFAULT ' ' NOT NULL,
                                      FSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
                                      FCREATORID BIGINT DEFAULT 0 NOT NULL,
                                      FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
                                      FENABLE VARCHAR(50) DEFAULT '0' NOT NULL,
                                      FCREATETIME DATETIME,
                                      FMODIFYTIME DATETIME,
                                      FMASTERID BIGINT DEFAULT 0 NOT NULL,
                                      FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
                                      FORGID BIGINT DEFAULT 0 NOT NULL,
                                      FUSEORG BIGINT DEFAULT 0 NOT NULL,
                                      FCTRLSTRATEGY VARCHAR(50) DEFAULT ' ' NOT NULL,
                                      FSOURCEDATAID BIGINT DEFAULT 0 NOT NULL,
                                      FBITINDEX BIGINT DEFAULT 0 NOT NULL,
                                      FSOURCEBITINDEX BIGINT DEFAULT 0 NOT NULL,
                                      FINVOICEPLUGIN BIGINT DEFAULT 0 NOT NULL,
                                      FMENUIMG VARCHAR(255) DEFAULT ' ' NOT NULL,
                                      FSRCFORMID VARCHAR(255) DEFAULT ' ' NOT NULL
);

/** 发票导入插件 **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_INVOICEPGINFO')
CREATE TABLE T_ER_INVOICEPGINFO (
                                    FID BIGINT DEFAULT 0 NOT NULL,
                                    FNUMBER VARCHAR(255) DEFAULT ' ' NOT NULL,
                                    FSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
                                    FCREATORID BIGINT DEFAULT 0 NOT NULL,
                                    FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
                                    FENABLE VARCHAR(50) DEFAULT '0' NOT NULL,
                                    FCREATETIME DATETIME,
                                    FMODIFYTIME DATETIME,
                                    FMASTERID BIGINT DEFAULT 0 NOT NULL,
                                    FPLUGINPATH VARCHAR(255) DEFAULT ' ' NOT NULL,
                                    FCLICKSIGN VARCHAR(255) DEFAULT ' ' NOT NULL,
                                    FBILLNAME VARCHAR(50) DEFAULT ' ' NOT NULL,
                                    FCLIENTTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
                                    FBILLTYPE VARCHAR(50) DEFAULT ' ' NOT NULL
);


EXEC P_ALTERPK 'PK_T_ER_INVOICEPGINFO_L', 'T_ER_INVOICEPGINFO_L', 'FPKID', '1';

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


EXEC P_ALTERPK 'PK_T_ER_QUICKREIMCONFIG_L', 'T_ER_QUICKREIMCONFIG_L', 'FPKID', '1';

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


EXEC P_ALTERPK 'PK_T_ER_QUICKREIMCONFIG', 'T_ER_QUICKREIMCONFIG', 'FID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_REIMCONFIG_FNUMBER') CREATE INDEX IDX_REIMCONFIG_FNUMBER ON T_ER_QUICKREIMCONFIG ( FNUMBER );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_REIMCONFIG_FCREATEORG') CREATE INDEX IDX_REIMCONFIG_FCREATEORG ON T_ER_QUICKREIMCONFIG ( FCREATEORGID );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_REIMCONFIG_FINVPLUGIN') CREATE INDEX IDX_REIMCONFIG_FINVPLUGIN ON T_ER_QUICKREIMCONFIG ( FINVOICEPLUGIN );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_REIMCONFIG_FCTRL') CREATE INDEX IDX_REIMCONFIG_FCTRL ON T_ER_QUICKREIMCONFIG ( FCTRLSTRATEGY );


EXEC P_ALTERPK 'PK_T_ER_INVOICEPGINFO', 'T_ER_INVOICEPGINFO', 'FID', '0';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_INVPGINFO_FNUMBER') CREATE INDEX IDX_INVPGINFO_FNUMBER ON T_ER_INVOICEPGINFO ( FNUMBER );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_INVPGINFO_BILLCLIENT') CREATE  CLUSTERED INDEX IDX_INVPGINFO_BILLCLIENT ON T_ER_INVOICEPGINFO ( FCLIENTTYPE ,FBILLTYPE );