-- ===========================================================
--  TABLE: FCT_TRABSERVCONTRATO
-- ===========================================================
CREATE TABLE FCT_TRABSERVCONTRATO (
    NRTRABSERVCONT    NUMBER NOT NULL,
    NRSEQCONTRATO     NUMBER,
    NRTIPOORCAMENTO   NUMBER,
    NRCOMPSERVICO     NUMBER,
    NRITCOMPSERVICO   NUMBER,
    IDESCOLHIDO       CHAR(1) NOT NULL,
    CDSERVORCA        NUMBER,
    QTSERVORCA        NUMBER,
    CDTPMEDIDASERV    NUMBER,
    QTMEDSERVORCA     NUMBER,
    VRUNITSERVORCA    FLOAT(126),
    VRTOTSERVORCA     FLOAT(126),
    IDELEMENTO        VARCHAR2(100),
    IDELEMENTOPAI     VARCHAR2(100),
    IDTIPOELEMENTO    CHAR(1) NOT NULL,
    IDSERVOBRIGCOMP   VARCHAR2(1),
    QTMEDIDAVARIAVEL  NUMBER,
    QTMEDIDACALC      FLOAT(126),
    NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)    DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FCT_TRASERVCONT CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          DATE                  			NULL,
    NRORGINCLUSAO     NUMBER          DEFAULT 1 		NULL,
    CDOPERINCLUSAO    VARCHAR2(12)    DEFAULT '1' 		NULL,
    NRORGULTATU       NUMBER          DEFAULT 1 		NULL,
    CDOPERULTATU      VARCHAR2(12)    DEFAULT '1'
)
/
ALTER TABLE FCT_TRABSERVCONTRATO ADD CONSTRAINT PK_FCT_TRABSERVCONTRATO PRIMARY KEY (NRTRABSERVCONT)
/
ALTER TABLE FCT_TRABSERVCONTRATO ADD CONSTRAINT CKC_IDTPELEMENTO_TRABSERVCONT CHECK(IDTIPOELEMENTO IN ('G','P', 'M'))
/
ALTER TABLE FCT_TRABSERVCONTRATO ADD CONSTRAINT CKC_IDESCOLHIDO_TRABSERVCONT CHECK(IDESCOLHIDO IN ('N', 'S'))
/
ALTER TABLE FCT_TRABSERVCONTRATO ADD CONSTRAINT CKC_IDATIVO_TRABSERVCONTRATO CHECK(IDATIVO IN ('N', 'S'))
/
ALTER TABLE FCT_TRABSERVCONTRATO ADD CONSTRAINT CKC_IDSEROBRIGCOMP_TRABSERCONT CHECK(IDSERVOBRIGCOMP IN ('S', 'N'))
/
ALTER TABLE FCT_TRABSERVCONTRATO ADD CONSTRAINT FKSM00253CONT_TRABSERVCONT
    FOREIGN KEY (NRSEQCONTRATO) REFERENCES FCT_CONTRATO (NRSEQCONTRATO)
/
CREATE INDEX FKSM00253 ON "FCT_TRABSERVCONTRATO" ("NRSEQCONTRATO" ASC)
/
ALTER TABLE FCT_TRABSERVCONTRATO ADD CONSTRAINT FKSM00254TPORCA_TRABSERVCONT
    FOREIGN KEY (NRTIPOORCAMENTO) REFERENCES FCT_TIPOORCAMENTO (NRTIPOORCAMENTO)
/
CREATE INDEX FKSM00254 ON "FCT_TRABSERVCONTRATO" ("NRTIPOORCAMENTO" ASC)
/
ALTER TABLE FCT_TRABSERVCONTRATO ADD CONSTRAINT FKSM00255COMPSERV_TRABSERVCONT
    FOREIGN KEY (NRCOMPSERVICO) REFERENCES FCT_COMPSERVICO(NRCOMPSERVICO)
/
CREATE INDEX FKSM00255 ON "FCT_TRABSERVCONTRATO" ("NRCOMPSERVICO" ASC)
/
ALTER TABLE FCT_TRABSERVCONTRATO ADD CONSTRAINT FKSM00256SERVORC_TRABSERVCONT
    FOREIGN KEY (CDSERVORCA) REFERENCES FCT_SERVICOORCA(CDSERVORCA)
/
CREATE INDEX FKSM00256 ON "FCT_TRABSERVCONTRATO" ("CDSERVORCA" ASC)
/
ALTER TABLE FCT_TRABSERVCONTRATO ADD CONSTRAINT FKSM00257TPMED_TRABSERVCONT
    FOREIGN KEY (CDTPMEDIDASERV) REFERENCES FCT_TIPOMEDIDASERV (CDTPMEDIDASERV)
/
CREATE INDEX FKSM00257 ON "FCT_TRABSERVCONTRATO" ("CDTPMEDIDASERV" ASC)
/

-- ===========================================================
--  TABLE: FCT_RELACMEDIDACONTRATO 
-- ===========================================================
CREATE TABLE FCT_RELACMEDIDACONTRATO (
    NRMEDIDACONTRATO      NUMBER NOT NULL,
    NRSEQCONTRATO         NUMBER NOT NULL,
    CDTPMEDIDAVARIAVEL    NUMBER,
    QTMEDIDAVARIAVEL      NUMBER,
    IDELEMENTORAIZ        VARCHAR2(100),
    QTFRANQUIA            NUMBER,
    NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)    DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FCT_RELAMEDCONT CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          DATE                  			NULL,
    NRORGINCLUSAO     NUMBER          DEFAULT 1 		NULL,
    CDOPERINCLUSAO    VARCHAR2(12)    DEFAULT '1' 		NULL,
    NRORGULTATU       NUMBER          DEFAULT 1 		NULL,
    CDOPERULTATU      VARCHAR2(12)    DEFAULT '1'
)
/
ALTER TABLE FCT_RELACMEDIDACONTRATO ADD CONSTRAINT PK_FCT_RELACMEDIDACONTRATO PRIMARY KEY (NRMEDIDACONTRATO)
/
ALTER TABLE FCT_RELACMEDIDACONTRATO ADD CONSTRAINT CKC_ATIVO_RELACMEDIDACONTRATO CHECK(IDATIVO IN ('S', 'N'))
/
ALTER TABLE FCT_RELACMEDIDACONTRATO ADD CONSTRAINT FKSM00258MEDIDA_RELACMEDCONT
    FOREIGN KEY (CDTPMEDIDAVARIAVEL) REFERENCES FCT_TIPOMEDIDASERV (CDTPMEDIDASERV)
/
CREATE INDEX FKSM00258 ON "FCT_RELACMEDIDACONTRATO" ("CDTPMEDIDAVARIAVEL" ASC)
/
ALTER TABLE FCT_RELACMEDIDACONTRATO ADD CONSTRAINT FKSM00259CONT_RELACMEDCONT
    FOREIGN KEY (NRSEQCONTRATO) REFERENCES FCT_CONTRATO(NRSEQCONTRATO)
/
CREATE INDEX FKSM00259 ON "FCT_RELACMEDIDACONTRATO" ("NRSEQCONTRATO" ASC)
/

-- ===========================================================
--  TABLE: FCT_COMPSERVCONTRATO 
-- ===========================================================
CREATE TABLE FCT_COMPSERVCONTRATO (
    NRCOMPSERVCONT      NUMBER NOT NULL,
    NRSEQCONTRATO       NUMBER NOT NULL,
    NRCOMPSERVICO       NUMBER NOT NULL,
    NMCOMPSERVICO       VARCHAR2(100),
    NRCOMPSERVICOPAI    NUMBER,
    IDCOMPOBRIGATORIA   CHAR(1),
    IDESCOLHIDO         CHAR(1),
    NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)    DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FCT_COMPSERVCONT CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          DATE                  			NULL,
    NRORGINCLUSAO     NUMBER          DEFAULT 1 		NULL,
    CDOPERINCLUSAO    VARCHAR2(12)    DEFAULT '1' 		NULL,
    NRORGULTATU       NUMBER          DEFAULT 1 		NULL,
    CDOPERULTATU      VARCHAR2(12)    DEFAULT '1'
)
/
ALTER TABLE FCT_COMPSERVCONTRATO ADD CONSTRAINT PK_FCT_COMPSERVCONTRATO PRIMARY KEY (NRCOMPSERVCONT)
/
ALTER TABLE FCT_COMPSERVCONTRATO ADD CONSTRAINT CKC_ATIVO_COMPSERVCONTRATO CHECK(IDATIVO IN ('S', 'N'))
/
ALTER TABLE FCT_COMPSERVCONTRATO ADD CONSTRAINT FKSM00260CONT_COMPSERVCONT
    FOREIGN KEY (NRSEQCONTRATO) REFERENCES FCT_CONTRATO(NRSEQCONTRATO)
/
CREATE INDEX FKSM00260 ON "FCT_COMPSERVCONTRATO" ("NRSEQCONTRATO" ASC)
/
ALTER TABLE FCT_COMPSERVCONTRATO ADD CONSTRAINT FKSM00261COMPSER_COMPSERCONT
    FOREIGN KEY (NRCOMPSERVICO) REFERENCES FCT_COMPSERVICO (NRCOMPSERVICO)
/
CREATE INDEX FKSM00261 ON "FCT_COMPSERVCONTRATO" ("NRCOMPSERVICO" ASC)
/

-- ===========================================================
--  TABLE: FCT_ITEMCONTRATO 
-- ===========================================================
ALTER TABLE FCT_ITEMCONTRATO ADD NMCONTRATUALITEMCONT VARCHAR2(250)
/
ALTER TABLE FCT_ITEMCONTRATO ADD IDELEMENTO VARCHAR2(100)
/
ALTER TABLE FCT_ITEMCONTRATO ADD VRUNITITEMCONTTBLPRECO FLOAT(126)
/
ALTER TABLE FCT_ITEMCONTRATO ADD CDTPMEDIDAVARIAVEL NUMBER
/

-- ===========================================================
--  TABLE: FCT_ITNEGOCIACAOCONTRATO 
-- ===========================================================
ALTER TABLE FCT_ITNEGOCIACAOCONTRATO ADD NRITEMCONTRATOPAI NUMBER
/

-- ===========================================================
--  TABLE: FCT_VARPRECBASESERVCONT 
-- ===========================================================
CREATE TABLE FCT_VARPRECBASESERVCONT (
    NRVARPRECBASESERVCONT NUMBER NOT NULL,
    NRSEQCONTRATO         NUMBER NOT NULL,
    CDSERVORCA            NUMBER NOT NULL,
    CDTPMEDIDASERV        NUMBER NOT NULL,
    CDTPMEDIDAVARIAVEL    NUMBER,
    QTMEDIDAINIVARIACAO   NUMBER,
    QTMEDIDAFIMVARIACAO   NUMBER,
    QTFRANQUIA            NUMBER,
    VRPRECOVARIACAO       NUMBER,
    IDMULTIPVARIACAO      CHAR(1),
    NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)    DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FCT_VPRBASERCONT CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          DATE                  			NULL,
    NRORGINCLUSAO     NUMBER          DEFAULT 1 		NULL,
    CDOPERINCLUSAO    VARCHAR2(12)    DEFAULT '1' 		NULL,
    NRORGULTATU       NUMBER          DEFAULT 1 		NULL,
    CDOPERULTATU      VARCHAR2(12)    DEFAULT '1'
)
/
ALTER TABLE FCT_VARPRECBASESERVCONT ADD CONSTRAINT PK_FCT_VARPRECBASESERVCONT PRIMARY KEY(NRVARPRECBASESERVCONT)
/
ALTER TABLE FCT_VARPRECBASESERVCONT ADD CONSTRAINT FKSM00263CONT_VPRBASERCONT
    FOREIGN KEY (NRSEQCONTRATO) REFERENCES FCT_CONTRATO(NRSEQCONTRATO)
/
CREATE INDEX FKSM00263 ON "FCT_VARPRECBASESERVCONT" ("NRSEQCONTRATO" ASC)
/
ALTER TABLE FCT_VARPRECBASESERVCONT ADD CONSTRAINT FKSM00264SERV_VPRBASERCONT
    FOREIGN KEY (CDSERVORCA) REFERENCES FCT_SERVICOORCA(CDSERVORCA)
/
CREATE INDEX FKSM00264 ON "FCT_VARPRECBASESERVCONT" ("CDSERVORCA" ASC)
/
ALTER TABLE FCT_VARPRECBASESERVCONT ADD CONSTRAINT FKSM00265MEDIDA_VPRBASERCONT
    FOREIGN KEY (CDTPMEDIDASERV) REFERENCES FCT_TIPOMEDIDASERV (CDTPMEDIDASERV)
/
CREATE INDEX FKSM00265 ON "FCT_VARPRECBASESERVCONT" ("CDTPMEDIDASERV" ASC)
/
ALTER TABLE FCT_VARPRECBASESERVCONT ADD CONSTRAINT CKC_ATIVO_VARPRECBASESERVCONT CHECK(IDATIVO IN ('S', 'N'))
/
ALTER TABLE FCT_VARPRECBASESERVCONT ADD CONSTRAINT CKC_MUTVAR_VARPRECBASESERVCONT CHECK(IDMULTIPVARIACAO IN ('S', 'N'))
/

-- ===========================================================
--  TABLE: FCT_NEGOCIACAOCONTRATO 
-- ===========================================================
ALTER TABLE FCT_NEGOCIACAOCONTRATO DROP CONSTRAINT FKSM00236FCT_NEGCONT_NEGPRO
/

-- ===========================================================
--  TABLE: FCT_ITNEGOCIACAOCONTRATO 
-- ===========================================================
ALTER TABLE FCT_ITNEGOCIACAOCONTRATO DROP CONSTRAINT FKSM00244FCT_ITNGCONT_ITNGPRO