-- ========================
-- TABLE: FCT_ITEMCONTRATO
-- ========================
ALTER TABLE FCT_ITEMCONTRATO ADD NRITEMORCAMENTO NUMBER
/
ALTER TABLE FCT_ITEMCONTRATO
ADD CONSTRAINT FK_FCT_ITEMCONTRATO_ITEMORC FOREIGN KEY (NRITEMORCAMENTO)
        REFERENCES FCT_ITEMORCAMENTO (NRITEMORCAMENTO)
/

-- ==============================
-- TABLE: FCT_NEGOCIACAOPROPOSTA
-- ==============================
CREATE TABLE FCT_NEGOCIACAOPROPOSTA (
    NRNEGOCIACAOPROPOSTA NUMBER NOT NULL,
    NRSEQORCAMENTO       NUMBER NOT NULL,
    NRTIPOORCAMENTO      NUMBER NOT NULL,
    IDTPFATURA           CHAR(1) NOT NULL,
    CDFILIALFATURA       VARCHAR2(4) NOT NULL,
    NRPARCFATURA         NUMBER NOT NULL,
    CDTIPOOPERFATURA     VARCHAR2(2) NOT NULL,
    CDSERIENF            VARCHAR2(5) NOT NULL,
    CDEMPRESA            VARCHAR2(2) NOT NULL,
    CDINSCESTA           VARCHAR2(16) NOT NULL,
    CDINSCMUNI           VARCHAR2(16) NOT NULL,
    VRTOTITEM            FLOAT NOT NULL,
    VRPERCDESCITEM       FLOAT,
    VRDESCITEM           FLOAT,
    VRTOTITEMCOMDESC     FLOAT NOT NULL,
    IDATIVO              VARCHAR2(1)  DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_FCT_NEGPROPOSTA    CHECK (IDATIVO IN ('S','N')),
    NRORG                NUMBER  DEFAULT   SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO           DATE NULL,
    NRORGINCLUSAO        NUMBER DEFAULT 1 NULL,
    CDOPERINCLUSAO       VARCHAR2(12) DEFAULT '1' NULL,
    DTULTATU             DATE NULL,
    NRORGULTATU          NUMBER DEFAULT 1,
    CDOPERULTATU         VARCHAR2(12) DEFAULT '1'
)
/
ALTER TABLE FCT_NEGOCIACAOPROPOSTA
    ADD CONSTRAINT PK_FCT_NEGOCIACAOPROPOSTA PRIMARY KEY (NRNEGOCIACAOPROPOSTA)
/
CREATE INDEX FKSM00217 ON "FCT_NEGOCIACAOPROPOSTA" ("NRSEQORCAMENTO" ASC)
/
ALTER TABLE FCT_NEGOCIACAOPROPOSTA
    ADD CONSTRAINT FKSM00217FCT_NEGOPROP_ORCAMEN FOREIGN KEY (NRSEQORCAMENTO)
        REFERENCES FCT_ORCAMENTO (NRSEQORCAMENTO) ON DELETE CASCADE
/
CREATE INDEX FKSM00218 ON "FCT_NEGOCIACAOPROPOSTA" ("NRTIPOORCAMENTO" ASC)
/
ALTER TABLE FCT_NEGOCIACAOPROPOSTA
    ADD CONSTRAINT FKSM00218FCT_NEGOPROP_TPORCAM FOREIGN KEY (NRTIPOORCAMENTO)
        REFERENCES FCT_TIPOORCAMENTO (NRTIPOORCAMENTO)
/
CREATE INDEX FKSM00219 ON "FCT_NEGOCIACAOPROPOSTA" ("CDFILIALFATURA" ASC)
/
ALTER TABLE FCT_NEGOCIACAOPROPOSTA
    ADD CONSTRAINT FKSM00219FCT_NEGOPROP_FILI FOREIGN KEY (CDFILIALFATURA)
        REFERENCES FILIAL (CDFILIAL)
/
CREATE INDEX FKSM00220 ON "FCT_NEGOCIACAOPROPOSTA" ("NRPARCFATURA" ASC)
/
ALTER TABLE FCT_NEGOCIACAOPROPOSTA
    ADD CONSTRAINT FKSM00220FCT_NEGPROP_PARCNEG FOREIGN KEY (NRPARCFATURA)
        REFERENCES PARCNEGOCIO (NRPARCNEGOCIO)
/
CREATE INDEX FKSM00221 ON "FCT_NEGOCIACAOPROPOSTA" ("CDEMPRESA" ASC , "CDINSCESTA" ASC, "CDINSCMUNI" ASC, "CDSERIENF" ASC)
/
ALTER TABLE FCT_NEGOCIACAOPROPOSTA
    ADD CONSTRAINT FKSM00221FCT_NEGOPROP_SERIENF FOREIGN KEY (CDEMPRESA, CDINSCESTA, CDINSCMUNI, CDSERIENF)
        REFERENCES SERIENF (CDEMPRESA, CDINSCESTA, CDINSCMUNI, CDSERIE)
/
ALTER TABLE FCT_NEGOCIACAOPROPOSTA
    ADD CONSTRAINT CKC_IDTPFATURA_FCT_NEGOPROP CHECK (IDTPFATURA IN ('A', 'X', 'P'))
/

-- ================================
-- TABLE: FCT_ITNEGOCIACAOPROPOSTA
-- ================================

CREATE TABLE FCT_ITNEGOCIACAOPROPOSTA (
    NRITNEGOCIACAOPROPOSTA NUMBER NOT NULL,
    NRNEGOCIACAOPROPOSTA   NUMBER NOT NULL,
    NRITEMORCAMENTO        NUMBER NOT NULL,
    NRITEMORCAMENTOPAI     NUMBER,
    VRTOTITEM              FLOAT NOT NULL,
    VRPERCDESCITEM         FLOAT,
    VRDESCITEM             FLOAT,
    VRTOTITEMCOMDESC       FLOAT NOT NULL,
    CDSERVORCA             NUMBER,
    CDPRODFATURA           VARCHAR2(10) NOT NULL,
    NRPARCFATURA           NUMBER NOT NULL,
     IDATIVO              VARCHAR2(1)  DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_FCT_ITNEGOCIAPRO  CHECK (IDATIVO IN ('S','N')),
    NRORG                NUMBER  DEFAULT   SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO           DATE NULL,
    NRORGINCLUSAO        NUMBER DEFAULT 1 NULL,
    CDOPERINCLUSAO       VARCHAR2(12) DEFAULT '1' NULL,
    DTULTATU             DATE NULL,
    NRORGULTATU          NUMBER DEFAULT 1,
    CDOPERULTATU         VARCHAR2(12) DEFAULT '1'
)
/

ALTER TABLE FCT_ITNEGOCIACAOPROPOSTA
    ADD CONSTRAINT PK_FCT_ITNEGOCIACAOPROPOSTA PRIMARY KEY (NRITNEGOCIACAOPROPOSTA)
/
CREATE INDEX FKSM00222 ON "FCT_ITNEGOCIACAOPROPOSTA" ("NRNEGOCIACAOPROPOSTA" ASC)
/
ALTER TABLE FCT_ITNEGOCIACAOPROPOSTA
    ADD CONSTRAINT FKSM00222FCT_ITNEGPROP_NEGPROP FOREIGN KEY (NRNEGOCIACAOPROPOSTA)
        REFERENCES FCT_NEGOCIACAOPROPOSTA (NRNEGOCIACAOPROPOSTA) ON DELETE CASCADE
/
CREATE INDEX FKSM00223 ON "FCT_ITNEGOCIACAOPROPOSTA" ("NRITEMORCAMENTO" ASC)
/
ALTER TABLE FCT_ITNEGOCIACAOPROPOSTA
    ADD CONSTRAINT FKSM00223FCT_ITNEGPROP_ITORC FOREIGN KEY (NRITEMORCAMENTO)
        REFERENCES FCT_ITEMORCAMENTO (NRITEMORCAMENTO) ON DELETE CASCADE
/
CREATE INDEX FKSM00224 ON "FCT_ITNEGOCIACAOPROPOSTA" ("NRITEMORCAMENTOPAI" ASC)
/
ALTER TABLE FCT_ITNEGOCIACAOPROPOSTA
    ADD CONSTRAINT FKSM00224FCT_ITNEGPRO_ITORCPAI FOREIGN KEY (NRITEMORCAMENTOPAI)
        REFERENCES FCT_ITEMORCAMENTO (NRITEMORCAMENTO)
/
CREATE INDEX FKSM00225 ON "FCT_ITNEGOCIACAOPROPOSTA" ("CDSERVORCA" ASC)
/
ALTER TABLE FCT_ITNEGOCIACAOPROPOSTA
    ADD CONSTRAINT FKSM00225FCT_ITNGOPRO_SERVORC FOREIGN KEY (CDSERVORCA)
        REFERENCES FCT_SERVICOORCA (CDSERVORCA)
/
CREATE INDEX FKSM00226 ON "FCT_ITNEGOCIACAOPROPOSTA" ("CDPRODFATURA" ASC)
/
ALTER TABLE FCT_ITNEGOCIACAOPROPOSTA
    ADD CONSTRAINT FKSM00226FCT_ITNEGOPROP_PROD FOREIGN KEY (CDPRODFATURA)
        REFERENCES PRODUTO (CDPRODUTO)
/
CREATE INDEX FKSM00227 ON "FCT_ITNEGOCIACAOPROPOSTA" ("NRPARCFATURA" ASC)
/
ALTER TABLE FCT_ITNEGOCIACAOPROPOSTA
    ADD CONSTRAINT FKSM00227FCT_ITNEGPRO_PARCNEG FOREIGN KEY (NRPARCFATURA)
        REFERENCES PARCNEGOCIO (NRPARCNEGOCIO)
/

-- ===========================
-- TABLE: FCT_PARCELANEGOPROP
-- ===========================

CREATE TABLE FCT_PARCELANEGOPROP (
    NRPARCELANEGOPROP    NUMBER NOT NULL,
    NRNEGOCIACAOPROPOSTA NUMBER NOT NULL,
    QTDIASFATURAMENTO    NUMBER,
    NRDIAVENCIMENTO      NUMBER,
    VRPARCELA            FLOAT NOT NULL,
    IDATIVO              VARCHAR2(1)  DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_FCT_PARCNEGPROP    CHECK (IDATIVO IN ('S','N')),
    NRORG                NUMBER  DEFAULT   SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO           DATE NULL,
    NRORGINCLUSAO        NUMBER DEFAULT 1 NULL,
    CDOPERINCLUSAO       VARCHAR2(12) DEFAULT '1' NULL,
    DTULTATU             DATE NULL,
    NRORGULTATU          NUMBER DEFAULT 1,
    CDOPERULTATU         VARCHAR2(12) DEFAULT '1'
)
/

ALTER TABLE FCT_PARCELANEGOPROP
    ADD CONSTRAINT PK_FCT_PARCELANEGOPROP PRIMARY KEY (NRPARCELANEGOPROP)
/
CREATE INDEX FKSM00228 ON "FCT_PARCELANEGOPROP" ("NRNEGOCIACAOPROPOSTA" ASC)
/
ALTER TABLE FCT_PARCELANEGOPROP
    ADD CONSTRAINT FKSM00228FCT_PARCNEGPRO_NEGPRO FOREIGN KEY (NRNEGOCIACAOPROPOSTA)
        REFERENCES FCT_NEGOCIACAOPROPOSTA (NRNEGOCIACAOPROPOSTA) ON DELETE CASCADE
/

-- ===============================
-- TABLE: FCT_DESCPERIODONEGOPROP
-- ===============================

CREATE TABLE FCT_DESCPERIODONEGOPROP (
    NRDESCPERIODONEGOPROP NUMBER NOT NULL,
    NRNEGOCIACAOPROPOSTA  NUMBER NOT NULL,
    VRPERCDESCITEM        FLOAT NOT NULL,
    VRDESCITEM            FLOAT NOT NULL,
    VRTOTITEMCOMDESC      FLOAT NOT NULL,
    QTMESESDESC           FLOAT NOT NULL,
    DTFINALVALIDADEDESC   DATE,
    IDATIVO              VARCHAR2(1)  DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_FCT_DESPERNEGPROP     CHECK (IDATIVO IN ('S','N')),
    NRORG                NUMBER  DEFAULT   SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO           DATE NULL,
    NRORGINCLUSAO        NUMBER DEFAULT 1 NULL,
    CDOPERINCLUSAO       VARCHAR2(12) DEFAULT '1' NULL,
    DTULTATU             DATE NULL,
    NRORGULTATU          NUMBER DEFAULT 1,
    CDOPERULTATU         VARCHAR2(12) DEFAULT '1'
)
/

ALTER TABLE FCT_DESCPERIODONEGOPROP
    ADD CONSTRAINT PK_FCT_DESCPERIODONEGOPROP PRIMARY KEY (NRDESCPERIODONEGOPROP)
/
CREATE INDEX FKSM00229 ON "FCT_DESCPERIODONEGOPROP" ("NRNEGOCIACAOPROPOSTA" ASC)
/
ALTER TABLE FCT_DESCPERIODONEGOPROP
    ADD CONSTRAINT FKSM00229FCT_DESPERIO_NEGPRO FOREIGN KEY (NRNEGOCIACAOPROPOSTA)
        REFERENCES FCT_NEGOCIACAOPROPOSTA (NRNEGOCIACAOPROPOSTA) ON DELETE CASCADE
/

-- ===============================
-- TABLE: FCT_COMPETENCIANEGOPROP
-- ===============================

CREATE TABLE FCT_COMPETENCIANEGOPROP (
    NRCOMPETENCIANEGOPROP NUMBER NOT NULL,
    NRNEGOCIACAOPROPOSTA  NUMBER NOT NULL,
    NRDIACOMPETINI        NUMBER NOT NULL,
    NRDIACOMPETFIN        NUMBER NOT NULL,
    IDMESCOMPETINI        CHAR(1) NOT NULL,
    IDMESCOMPETFIN        CHAR(1) NOT NULL,
    QTDIASAPURACAO        NUMBER NOT NULL,
    IDTPCALCVENC          CHAR(1) NOT NULL,
    NRDIACALCVENC         NUMBER NOT NULL,
    IDMESCALCVENC         CHAR(1),
    QTDIASFATUVENC        NUMBER,
    IDATIVO              VARCHAR2(1)  DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_FCT_COMPTENEGPROP     CHECK (IDATIVO IN ('S','N')),
    NRORG                NUMBER  DEFAULT   SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO           DATE NULL,
    NRORGINCLUSAO        NUMBER DEFAULT 1 NULL,
    CDOPERINCLUSAO       VARCHAR2(12) DEFAULT '1' NULL,
    DTULTATU             DATE NULL,
    NRORGULTATU          NUMBER DEFAULT 1,
    CDOPERULTATU         VARCHAR2(12) DEFAULT '1'
)
/

ALTER TABLE FCT_COMPETENCIANEGOPROP
    ADD CONSTRAINT PK_FCT_COMPETENCIANEGOPROP PRIMARY KEY (NRCOMPETENCIANEGOPROP)
/
CREATE INDEX FKSM00230 ON "FCT_COMPETENCIANEGOPROP" ("NRNEGOCIACAOPROPOSTA" ASC)
/
ALTER TABLE FCT_COMPETENCIANEGOPROP
    ADD CONSTRAINT FKSM00230FCT_COMPNEGPRO_NEGPRO FOREIGN KEY (NRNEGOCIACAOPROPOSTA)
        REFERENCES FCT_NEGOCIACAOPROPOSTA (NRNEGOCIACAOPROPOSTA) ON DELETE CASCADE
/

-- ==============================
-- TABLE: FCT_NEGOCIACAOCONTRATO
-- ==============================

CREATE TABLE FCT_NEGOCIACAOCONTRATO (
    NRNEGOCIACAOCONTRATO NUMBER NOT NULL,
    NRSEQCONTRATO        NUMBER NOT NULL,
    NRTIPOORCAMENTO      NUMBER NOT NULL,
    IDTPFATURA           CHAR(1) NOT NULL,
    CDFILIALFATURA       VARCHAR2(4) NOT NULL,
    NRPARCFATURA         NUMBER NOT NULL,
    CDTIPOOPERFATURA     VARCHAR2(2) NOT NULL,
    CDSERIENF            VARCHAR2(5) NOT NULL,
    CDEMPRESA            VARCHAR2(2) NOT NULL,
    CDINSCESTA           VARCHAR2(16) NOT NULL,
    CDINSCMUNI           VARCHAR2(16) NOT NULL,
    VRTOTITEM            FLOAT NOT NULL,
    VRPERCDESCITEM       FLOAT,
    VRDESCITEM           FLOAT,
    VRTOTITEMCOMDESC     FLOAT NOT NULL,
    NRNEGOCIACAOPROPOSTA NUMBER,
    IDATIVO              VARCHAR2(1)  DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_FCT_NEGOCIACONT   CHECK (IDATIVO IN ('S','N')),
    NRORG                NUMBER  DEFAULT   SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO           DATE NULL,
    NRORGINCLUSAO        NUMBER DEFAULT 1 NULL,
    CDOPERINCLUSAO       VARCHAR2(12) DEFAULT '1' NULL,
    DTULTATU             DATE NULL,
    NRORGULTATU          NUMBER DEFAULT 1,
    CDOPERULTATU         VARCHAR2(12) DEFAULT '1'
)
/

ALTER TABLE FCT_NEGOCIACAOCONTRATO
    ADD CONSTRAINT PK_FCT_NEGOCIACAOCONTRATO PRIMARY KEY (NRNEGOCIACAOCONTRATO)
/
CREATE INDEX FKSM00231 ON "FCT_NEGOCIACAOCONTRATO" ("NRSEQCONTRATO" ASC)
/
ALTER TABLE FCT_NEGOCIACAOCONTRATO
    ADD CONSTRAINT FKSM00231FCT_NEGCONT_CONT FOREIGN KEY (NRSEQCONTRATO)
        REFERENCES FCT_CONTRATO (NRSEQCONTRATO) ON DELETE CASCADE
/
CREATE INDEX FKSM00232 ON "FCT_NEGOCIACAOCONTRATO" ("NRTIPOORCAMENTO" ASC)
/
ALTER TABLE FCT_NEGOCIACAOCONTRATO
    ADD CONSTRAINT FKSM00232FCT_NEGCONT_TPORCA FOREIGN KEY (NRTIPOORCAMENTO)
        REFERENCES FCT_TIPOORCAMENTO (NRTIPOORCAMENTO)
/
CREATE INDEX FKSM00233 ON "FCT_NEGOCIACAOCONTRATO" ("CDFILIALFATURA" ASC)
/
ALTER TABLE FCT_NEGOCIACAOCONTRATO
    ADD CONSTRAINT FKSM00233FCT_NEGCONT_FILI FOREIGN KEY (CDFILIALFATURA)
        REFERENCES FILIAL (CDFILIAL)
/
CREATE INDEX FKSM00234 ON "FCT_NEGOCIACAOCONTRATO" ("NRPARCFATURA" ASC)
/
ALTER TABLE FCT_NEGOCIACAOCONTRATO
    ADD CONSTRAINT FKSM00234FCT_NEGCONT_PARCNEG FOREIGN KEY (NRPARCFATURA)
        REFERENCES PARCNEGOCIO (NRPARCNEGOCIO)
/
CREATE INDEX FKSM00235 ON "FCT_NEGOCIACAOCONTRATO" ("CDEMPRESA" ASC , "CDINSCESTA" ASC, "CDINSCMUNI" ASC, "CDSERIENF" ASC)
/
ALTER TABLE FCT_NEGOCIACAOCONTRATO
    ADD CONSTRAINT FKSM00235FCT_NEGCONT_SERIENF FOREIGN KEY (CDEMPRESA, CDINSCESTA, CDINSCMUNI, CDSERIENF)
        REFERENCES SERIENF (CDEMPRESA, CDINSCESTA, CDINSCMUNI, CDSERIE)
/
CREATE INDEX FKSM00236 ON "FCT_NEGOCIACAOCONTRATO" ("NRNEGOCIACAOPROPOSTA" ASC)
/
ALTER TABLE FCT_NEGOCIACAOCONTRATO
    ADD CONSTRAINT FKSM00236FCT_NEGCONT_NEGPRO FOREIGN KEY (NRNEGOCIACAOPROPOSTA)
        REFERENCES FCT_NEGOCIACAOPROPOSTA (NRNEGOCIACAOPROPOSTA)
/
ALTER TABLE FCT_NEGOCIACAOCONTRATO
    ADD CONSTRAINT CKC_IDTPFATURA_FCT_NEGOCONT CHECK (IDTPFATURA IN ('A', 'X', 'P'))
/

-- ================================
-- TABLE: FCT_ITNEGOCIACAOCONTRATO
-- ================================

CREATE TABLE FCT_ITNEGOCIACAOCONTRATO (
    NRITNEGOCIACAOCONTRATO NUMBER NOT NULL,
    NRNEGOCIACAOCONTRATO   NUMBER NOT NULL,
    NRITEMOCONTRATO        NUMBER,
    NRITEMORCAMENTO        NUMBER,
    NRITEMORCAMENTOPAI     NUMBER,
    VRTOTITEM              FLOAT NOT NULL,
    VRPERCDESCITEM         FLOAT,
    VRDESCITEM             FLOAT,
    VRTOTITEMCOMDESC       FLOAT NOT NULL,
    CDSERVORCA             NUMBER,
    CDPRODFATURA           VARCHAR2(10) NOT NULL,
    NRPARCFATURA           NUMBER NOT NULL,
    NRITNEGOCIACAOPROPOSTA NUMBER,
    IDATIVO              VARCHAR2(1)  DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_FCT_NEGPROPOSTA    CHECK (IDATIVO IN ('S','N')),
    NRORG                NUMBER  DEFAULT   SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO           DATE NULL,
    NRORGINCLUSAO        NUMBER DEFAULT 1 NULL,
    CDOPERINCLUSAO       VARCHAR2(12) DEFAULT '1' NULL,
    DTULTATU             DATE NULL,
    NRORGULTATU          NUMBER DEFAULT 1,
    CDOPERULTATU         VARCHAR2(12) DEFAULT '1'
)
/

ALTER TABLE FCT_ITNEGOCIACAOCONTRATO
    ADD CONSTRAINT PK_FCT_ITNEGOCIACAOCONTRATO PRIMARY KEY (NRITNEGOCIACAOCONTRATO)
/
CREATE INDEX FKSM00237 ON "FCT_ITNEGOCIACAOCONTRATO" ("NRNEGOCIACAOCONTRATO" ASC)
/
ALTER TABLE FCT_ITNEGOCIACAOCONTRATO
    ADD CONSTRAINT FKSM00237FCT_ITNEGCONT_NEGCON FOREIGN KEY (NRNEGOCIACAOCONTRATO)
        REFERENCES FCT_NEGOCIACAOCONTRATO (NRNEGOCIACAOCONTRATO) ON DELETE CASCADE
/
CREATE INDEX FKSM00238 ON "FCT_ITNEGOCIACAOCONTRATO" ("NRITEMOCONTRATO" ASC)
/
ALTER TABLE FCT_ITNEGOCIACAOCONTRATO
    ADD CONSTRAINT FKSM00238FCT_ITNEGCONT_ITCONT FOREIGN KEY (NRITEMOCONTRATO)
        REFERENCES FCT_ITEMCONTRATO (NRITEMOCONTRATO) ON DELETE CASCADE
/
CREATE INDEX FKSM00239 ON "FCT_ITNEGOCIACAOCONTRATO" ("NRITEMORCAMENTO" ASC)
/
ALTER TABLE FCT_ITNEGOCIACAOCONTRATO
    ADD CONSTRAINT FKSM00239FCT_ITNEGCONT_ITMORC FOREIGN KEY (NRITEMORCAMENTO)
        REFERENCES FCT_ITEMORCAMENTO (NRITEMORCAMENTO)
/
CREATE INDEX FKSM00240 ON "FCT_ITNEGOCIACAOCONTRATO" ("NRITEMORCAMENTOPAI" ASC)
/
ALTER TABLE FCT_ITNEGOCIACAOCONTRATO
    ADD CONSTRAINT FKSM00240FCT_ITNGCNT_ITMORCPAI FOREIGN KEY (NRITEMORCAMENTOPAI)
        REFERENCES FCT_ITEMORCAMENTO (NRITEMORCAMENTO)
/
CREATE INDEX FKSM00241 ON "FCT_ITNEGOCIACAOCONTRATO" ("CDSERVORCA" ASC)
/
ALTER TABLE FCT_ITNEGOCIACAOCONTRATO
    ADD CONSTRAINT FKSM00241FCT_ITNEGCONT_SERVORC FOREIGN KEY (CDSERVORCA)
        REFERENCES FCT_SERVICOORCA (CDSERVORCA)
/
CREATE INDEX FKSM00242 ON "FCT_ITNEGOCIACAOCONTRATO" ("CDPRODFATURA" ASC)
/
ALTER TABLE FCT_ITNEGOCIACAOCONTRATO
    ADD CONSTRAINT FKSM00242FCT_ITNEGCONT_PROD FOREIGN KEY (CDPRODFATURA)
        REFERENCES PRODUTO (CDPRODUTO)
/
CREATE INDEX FKSM00243 ON "FCT_ITNEGOCIACAOCONTRATO" ("NRPARCFATURA" ASC)
/
ALTER TABLE FCT_ITNEGOCIACAOCONTRATO
    ADD CONSTRAINT FKSM00243FCT_ITNEGCONT_PARCNEG FOREIGN KEY (NRPARCFATURA)
        REFERENCES PARCNEGOCIO (NRPARCNEGOCIO)
/
CREATE INDEX FKSM00244 ON "FCT_ITNEGOCIACAOCONTRATO" ("NRITNEGOCIACAOPROPOSTA" ASC)
/
ALTER TABLE FCT_ITNEGOCIACAOCONTRATO
    ADD CONSTRAINT FKSM00244FCT_ITNGCONT_ITNGPRO FOREIGN KEY (NRITNEGOCIACAOPROPOSTA)
        REFERENCES FCT_ITNEGOCIACAOPROPOSTA (NRITNEGOCIACAOPROPOSTA)
/

-- ===========================
-- TABLE: FCT_PARCELANEGOCONT
-- ===========================

CREATE TABLE FCT_PARCELANEGOCONT (
    NRPARCELANEGOCONT    NUMBER NOT NULL,
    NRNEGOCIACAOCONTRATO NUMBER NOT NULL,
    QTDIASFATURAMENTO    NUMBER,
    NRDIAVENCIMENTO      NUMBER,
    VRPARCELA            FLOAT NOT NULL,
    NRPARCELANEGOPROP    NUMBER,
    IDATIVO              VARCHAR2(1)  DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_FCT_PARCENEGCONT    CHECK (IDATIVO IN ('S','N')),
    NRORG                NUMBER  DEFAULT   SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO           DATE NULL,
    NRORGINCLUSAO        NUMBER DEFAULT 1 NULL,
    CDOPERINCLUSAO       VARCHAR2(12) DEFAULT '1' NULL,
    DTULTATU             DATE NULL,
    NRORGULTATU          NUMBER DEFAULT 1,
    CDOPERULTATU         VARCHAR2(12) DEFAULT '1'
)
/

ALTER TABLE FCT_PARCELANEGOCONT
    ADD CONSTRAINT PK_FCT_PARCELANEGOCONT PRIMARY KEY (NRPARCELANEGOCONT)
/
CREATE INDEX FKSM00245 ON "FCT_PARCELANEGOCONT" ("NRNEGOCIACAOCONTRATO" ASC)
/
ALTER TABLE FCT_PARCELANEGOCONT
    ADD CONSTRAINT FKSM00245FCT_PRCNEGCON_NEGCON FOREIGN KEY (NRNEGOCIACAOCONTRATO)
        REFERENCES FCT_NEGOCIACAOCONTRATO (NRNEGOCIACAOCONTRATO) ON DELETE CASCADE
/
CREATE INDEX FKSM00246 ON "FCT_PARCELANEGOCONT" ("NRPARCELANEGOPROP" ASC)
/
ALTER TABLE FCT_PARCELANEGOCONT
    ADD CONSTRAINT FKSM00246FCT_PRCNGCONT_PARCNP FOREIGN KEY (NRPARCELANEGOPROP)
        REFERENCES FCT_PARCELANEGOPROP (NRPARCELANEGOPROP)
/

-- ===============================
-- TABLE: FCT_DESCPERIODONEGOCONT
-- ===============================

CREATE TABLE FCT_DESCPERIODONEGOCONT (
    NRDESCPERIODONEGOCONT NUMBER NOT NULL,
    NRNEGOCIACAOCONTRATO  NUMBER NOT NULL,
    VRPERCDESCITEM        FLOAT NOT NULL,
    VRDESCITEM            FLOAT NOT NULL,
    VRTOTITEMCOMDESC      FLOAT NOT NULL,
    QTMESESDESC           FLOAT NOT NULL,
    DTFINALVALIDADEDESC   DATE,
    NRDESCPERIODONEGOPROP NUMBER,
    IDATIVO              VARCHAR2(1)  DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_FCT_DESPERNEGCONT    CHECK (IDATIVO IN ('S','N')),
    NRORG                NUMBER  DEFAULT   SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO           DATE NULL,
    NRORGINCLUSAO        NUMBER DEFAULT 1 NULL,
    CDOPERINCLUSAO       VARCHAR2(12) DEFAULT '1' NULL,
    DTULTATU             DATE NULL,
    NRORGULTATU          NUMBER DEFAULT 1,
    CDOPERULTATU         VARCHAR2(12) DEFAULT '1'
)
/

ALTER TABLE FCT_DESCPERIODONEGOCONT
    ADD CONSTRAINT PK_FCT_DESCPERIODONEGOCONT PRIMARY KEY (NRDESCPERIODONEGOCONT)
/
CREATE INDEX FKSM00247 ON "FCT_DESCPERIODONEGOCONT" ("NRNEGOCIACAOCONTRATO" ASC)
/
ALTER TABLE FCT_DESCPERIODONEGOCONT
    ADD CONSTRAINT FKSM00247FCT_DESCPERI_NEGCONT FOREIGN KEY (NRNEGOCIACAOCONTRATO)
        REFERENCES FCT_NEGOCIACAOCONTRATO (NRNEGOCIACAOCONTRATO) ON DELETE CASCADE
/
CREATE INDEX FKSM00248 ON "FCT_DESCPERIODONEGOCONT" ("NRDESCPERIODONEGOPROP" ASC)
/
ALTER TABLE FCT_DESCPERIODONEGOCONT
    ADD CONSTRAINT FKSM00248FCT_DESPERI_DESCNP FOREIGN KEY (NRDESCPERIODONEGOPROP)
        REFERENCES FCT_DESCPERIODONEGOPROP (NRDESCPERIODONEGOPROP)
/

-- ===============================
-- TABLE: FCT_COMPETENCIANEGOCONT
-- ===============================

CREATE TABLE FCT_COMPETENCIANEGOCONT (
    NRCOMPETENCIANEGOCONT NUMBER NOT NULL,
    NRNEGOCIACAOCONTRATO  NUMBER NOT NULL,
    NRDIACOMPETINI        NUMBER NOT NULL,
    NRDIACOMPETFIN        NUMBER NOT NULL,
    IDMESCOMPETINI        CHAR(1) NOT NULL,
    IDMESCOMPETFIN        CHAR(1) NOT NULL,
    QTDIASAPURACAO        NUMBER NOT NULL,
    IDTPCALCVENC          CHAR(1) NOT NULL,
    NRDIACALCVENC         NUMBER NOT NULL,
    IDMESCALCVENC         CHAR(1),
    QTDIASFATUVENC        NUMBER,
    NRCOMPETENCIANEGOPROP NUMBER,
    IDATIVO              VARCHAR2(1)  DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_FCT_COMPETNEGCONT  CHECK (IDATIVO IN ('S','N')),
    NRORG                NUMBER  DEFAULT   SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO           DATE NULL,
    NRORGINCLUSAO        NUMBER DEFAULT 1 NULL,
    CDOPERINCLUSAO       VARCHAR2(12) DEFAULT '1' NULL,
    DTULTATU             DATE NULL,
    NRORGULTATU          NUMBER DEFAULT 1,
    CDOPERULTATU         VARCHAR2(12) DEFAULT '1'
)
/

ALTER TABLE FCT_COMPETENCIANEGOCONT
    ADD CONSTRAINT PK_FCT_COMPETENCIANEGOCONT PRIMARY KEY (NRCOMPETENCIANEGOCONT)
/
CREATE INDEX FKSM00249 ON "FCT_COMPETENCIANEGOCONT" ("NRNEGOCIACAOCONTRATO" ASC)
/
ALTER TABLE FCT_COMPETENCIANEGOCONT
    ADD CONSTRAINT FKSM00249FCT_COMPNGPRO_NGCONT FOREIGN KEY (NRNEGOCIACAOCONTRATO)
        REFERENCES FCT_NEGOCIACAOCONTRATO (NRNEGOCIACAOCONTRATO) ON DELETE CASCADE
/
CREATE INDEX FKSM00250 ON "FCT_COMPETENCIANEGOCONT" ("NRCOMPETENCIANEGOPROP" ASC)
/
ALTER TABLE FCT_COMPETENCIANEGOCONT
    ADD CONSTRAINT FKSM00250FCT_COMPNGPRO_COMPNP FOREIGN KEY (NRCOMPETENCIANEGOPROP)
        REFERENCES FCT_COMPETENCIANEGOPROP (NRCOMPETENCIANEGOPROP)
/

/* ======================
| TABLE: FCT_FATURACONT |
======================= */

ALTER TABLE FCT_FATURACONT MODIFY NRGRUPOFATURA NULL
/

ALTER TABLE FCT_FATURACONT ADD CDTIPOOPERFATURA VARCHAR2(2) NULL
/

ALTER TABLE FCT_FATURACONT MODIFY CDTIPOOPERFATURA NULL
/

ALTER TABLE FCT_FATURACONT ADD CDSERIENF VARCHAR2(5) NULL
/

ALTER TABLE FCT_FATURACONT MODIFY CDSERIENF NULL
/

ALTER TABLE FCT_FATURACONT ADD CDEMPRESA VARCHAR2(2) NULL
/

ALTER TABLE FCT_FATURACONT MODIFY CDEMPRESA NULL
/

ALTER TABLE FCT_FATURACONT ADD CDINSCESTA VARCHAR2(16) NULL
/

ALTER TABLE FCT_FATURACONT MODIFY CDINSCESTA NULL
/

ALTER TABLE FCT_FATURACONT ADD CDINSCMUNI VARCHAR2(16) NULL
/

ALTER TABLE FCT_FATURACONT MODIFY CDINSCMUNI NULL
/


/* =========================
| TABLE: FCT_MEDICAOFATURA |
========================== */

ALTER TABLE FCT_MEDICAOFATURA MODIFY NRGRUPOFATURA NULL
/

ALTER TABLE FCT_MEDICAOFATURA ADD CDTIPOOPERFATURA VARCHAR2(2) NULL
/

ALTER TABLE FCT_MEDICAOFATURA MODIFY CDTIPOOPERFATURA NULL
/

ALTER TABLE FCT_MEDICAOFATURA ADD CDSERIENF VARCHAR2(5) NULL
/

ALTER TABLE FCT_MEDICAOFATURA MODIFY CDSERIENF NULL
/

ALTER TABLE FCT_MEDICAOFATURA ADD CDEMPRESA VARCHAR2(2) NULL
/

ALTER TABLE FCT_MEDICAOFATURA MODIFY CDEMPRESA NULL
/

ALTER TABLE FCT_MEDICAOFATURA ADD CDINSCESTA VARCHAR2(16) NULL
/

ALTER TABLE FCT_MEDICAOFATURA MODIFY CDINSCESTA NULL
/

ALTER TABLE FCT_MEDICAOFATURA ADD CDINSCMUNI VARCHAR2(16) NULL
/

ALTER TABLE FCT_MEDICAOFATURA MODIFY CDINSCMUNI NULL
/

-- ============================
-- TABLE: FCT_PARAMEMAILFILIAL
-- =============================
ALTER TABLE FCT_PARAMEMAILFILIAL ADD DSHOSTEMAIL VARCHAR2(500)
/
ALTER TABLE FCT_PARAMEMAILFILIAL ADD DSPORTAEMAIL VARCHAR2(500)
/
ALTER TABLE FCT_PARAMEMAILFILIAL ADD DSUSUARIOEMAIL VARCHAR2(500)
/
ALTER TABLE FCT_PARAMEMAILFILIAL ADD DSSENHAEMAIL VARCHAR2(500)