


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_PUBREIMCONTRACT')
CREATE TABLE T_ER_PUBREIMCONTRACT (
                                      FID BIGINT DEFAULT 0 NOT NULL,
                                      FENTRYID BIGINT DEFAULT 0 NOT NULL,
                                      FSEQ INT DEFAULT 0 NOT NULL,
                                      FCONTRACTCODE VARCHAR(50) DEFAULT ' ' NOT NULL,
                                      FCONTRACTNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
                                      FSIGNDATE DATETIME,
                                      FCONTRACTDESCRIPTION NVARCHAR(1000) DEFAULT ' ' NOT NULL,
                                      FCONTRACTAPPLIER BIGINT DEFAULT 0 NOT NULL,
                                      FCONTRACTCOSTORG BIGINT DEFAULT 0 NOT NULL,
                                      FCONTRACTPARTA BIGINT DEFAULT 0 NOT NULL,
                                      FCONTRACTPARTBTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
                                      FCONTRACTPARTB NVARCHAR(100) DEFAULT ' ' NOT NULL,
                                      FCONTRACTPAYTYPEID BIGINT DEFAULT 0 NOT NULL,
                                      FCONTRACTHAPPENDATE DATETIME,
                                      FCONTRACTPROJECT BIGINT DEFAULT 0 NOT NULL,
                                      FCONTRACTEXPENSEITEM BIGINT DEFAULT 0 NOT NULL,
                                      FCONTRACTENTRYCURRENCY BIGINT DEFAULT 0 NOT NULL,
                                      FCONTRACTENTRYCHANGERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                      FCONTRACTEXPQUOTETYPE CHAR(1) DEFAULT ' ' NOT NULL,
                                      FCONTRACTCANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                      FCONTRACTCURRCANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                      FCONTRACTWRITEOFF DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                      FCONTRACTCURRWRITEOFF DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                      FCONTRACTREIMAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                      FCONTRACTCURRREIMAMOUNT DECIMAL(23,10) DEFAULT 0 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_PUBREIMCONTRACT_LK')
CREATE TABLE T_ER_PUBREIMCONTRACT_LK (
                                         FID 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
);




EXEC P_ALTERPK 'PK_T_ER_PUBREIMCONTRACT', 'T_ER_PUBREIMCONTRACT', 'FENTRYID', '1';

  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_PUBREIMCONTRACT_FCONTRACTCODE') CREATE INDEX IDX_ER_PUBREIMCONTRACT_FCONTRACTCODE ON T_ER_PUBREIMCONTRACT ( FCONTRACTCODE );


EXEC P_ALTERPK 'PK_T_ER_PUBREIMCONTRACT_LK', 'T_ER_PUBREIMCONTRACT_LK', 'FPKID', '1';

  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_PUBREIMCONTRACT_LK') CREATE INDEX IDX_ER_PUBREIMCONTRACT_LK ON T_ER_PUBREIMCONTRACT_LK ( FSBILLID );


