CREATE TABLE OUTCRECONT
(
    CDEMPRESA           VARCHAR2(2)            NOT NULL,
    CDOUTCRECONT        VARCHAR2(5)            NOT NULL,
    CDSITUTRIBPICO      VARCHAR2(2)            NOT NULL,
    IDOPERPICO          VARCHAR2(1)            DEFAULT '0' NOT NULL,
    VRALIQPIS           FLOAT                  NULL,
    VRALIQCOFINS        FLOAT                  NULL,
    CDNATUBCALC         VARCHAR2(5)            NULL,
    NRORG               NUMBER                 DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO          DATE                   NULL,
    DTULTATU            DATE                   NULL,
    NRORGINCLUSAO       NUMBER                 DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
    CDOPERINCLUSAO      VARCHAR2(12)           DEFAULT '1' NULL    ,
    NRORGULTATU         NUMBER                 DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
    CDOPERULTATU        VARCHAR2(12)           DEFAULT '1' NULL    ,
    IDORIGCRED          VARCHAR2(1)            DEFAULT 'S' NOT NULL
			CONSTRAINT CKC_IDORIGCRED_OUTCRECONT CHECK (IDORIGCRED IN ('0','1')),
    DTINIVALID          DATE                   NOT NULL,
    DTFIMVALID          DATE                   NULL,
    DSCREDITO           VARCHAR2(30)           NULL,
    IDATIVO             VARCHAR2(1)            DEFAULT 'S' NOT NULL
			CONSTRAINT CKC_IDATIVO_OUTCRECONT CHECK (IDATIVO IN ('S','N')),
			CONSTRAINT PK_OUTCRECONT PRIMARY KEY (CDEMPRESA, CDOUTCRECONT)
)
/

CREATE INDEX FIS00844_FK ON OUTCRECONT (CDEMPRESA ASC)
/

ALTER TABLE OUTCRECONT
    ADD CONSTRAINT FKFIS00844EMPRESA FOREIGN KEY (CDEMPRESA)
       REFERENCES EMPRESA (CDEMPRESA) 
/

CREATE TABLE OUTCRECONTCTBL
(
    CDEMPRESA           VARCHAR2(2)            NOT NULL,
    CDOUTCRECONT        VARCHAR2(5)            NOT NULL,
    CDCONTCTBL          VARCHAR2(20)           NOT NULL,
    NRORG               NUMBER                 DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    DTINCLUSAO          DATE                   NULL,
    DTULTATU            DATE                   NULL,
    NRORGINCLUSAO       NUMBER                 DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
    CDOPERINCLUSAO      VARCHAR2(12)           DEFAULT '1' NULL,
    NRORGULTATU         NUMBER                 DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
    CDOPERULTATU        VARCHAR2(12)           DEFAULT '1' NULL,
    IDCONSVRDEB         VARCHAR2(01)           DEFAULT 'S' NOT NULL
			CONSTRAINT CKC_IDCONSVRDEB_OUTCRECONTCTBL CHECK(IDCONSVRDEB IN ('S','N')),
    IDATIVO             VARCHAR2(1)            DEFAULT 'S' NOT NULL
			CONSTRAINT CKC_IDATIVO_OUTCRECONTCTBL CHECK (IDATIVO IN ('S','N')),
			CONSTRAINT PK_OUTCRECONTCTBL PRIMARY KEY (CDEMPRESA, CDOUTCRECONT, CDCONTCTBL)
)
/

CREATE INDEX FIS00845_FK ON OUTCRECONTCTBL (CDEMPRESA ASC, CDOUTCRECONT ASC)
/

ALTER TABLE OUTCRECONTCTBL
    ADD CONSTRAINT FKFIS00845OUTCRECONT FOREIGN KEY  (CDEMPRESA, CDOUTCRECONT)
       REFERENCES OUTCRECONT (CDEMPRESA, CDOUTCRECONT) ON DELETE CASCADE
/

CREATE INDEX FIS00846_FK ON OUTCRECONTCTBL (CDCONTCTBL ASC)
/

ALTER TABLE OUTCRECONTCTBL
    ADD CONSTRAINT FKFIS00846CONTCTBL FOREIGN KEY  (CDCONTCTBL)
       REFERENCES CONTCTBL (CDCONTCTBL)
/

ALTER TABLE DETAPURACONTR ADD VRBCOUTCRED FLOAT DEFAULT 0 NOT NULL
/

ALTER TABLE DETAPURACONTR ADD VRIMPOUTCRED FLOAT DEFAULT 0 NOT NULL
/