CREATE TABLE FCT_DOCASSINATPROP (
    NRDOCASSINATPROP   NUMBER  NOT NULL,
    NRASSDIGITALORCA   NUMBER  NOT NULL,
    NRSEQORCADOC       NUMBER  NOT NULL,
    NRSEQORCAMENTO     NUMBER  NOT NULL,
    IDSITUACAO         CHAR(1) DEFAULT 'P' NOT NULL,
    DSJUSTIFICARECUSA  VARCHAR2(4000),
    IDSIGNATCERTSIGN   VARCHAR2(500),
    NRORG              NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO            VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FCT_DOCASSPROP CHECK (IDATIVO IN ('S','N')),
    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'
)
/  

ALTER TABLE FCT_DOCASSINATPROP ADD CONSTRAINT PK_FCT_DOCASSINATPROP PRIMARY KEY (NRDOCASSINATPROP)
/

CREATE INDEX SM00310_FK ON FCT_DOCASSINATPROP (NRASSDIGITALORCA ASC)
/

ALTER TABLE FCT_DOCASSINATPROP
    ADD CONSTRAINT FKSM00310FCT_ASSORC_DOCASSPRO FOREIGN KEY (NRASSDIGITALORCA)
      REFERENCES FCT_ASSINATDIGITALPROP (NRASSDIGITALORCA) ON DELETE CASCADE
/

CREATE INDEX SM00311_FK ON FCT_DOCASSINATPROP (NRSEQORCAMENTO ASC)
/

ALTER TABLE FCT_DOCASSINATPROP
    ADD CONSTRAINT FKSM00311FCT_ORC_DOCASSPROP FOREIGN KEY (NRSEQORCAMENTO)
      REFERENCES FCT_ORCAMENTO (NRSEQORCAMENTO) ON DELETE CASCADE
/

CREATE INDEX SM00312_FK ON FCT_DOCASSINATPROP (NRSEQORCADOC ASC)
/

ALTER TABLE FCT_DOCASSINATPROP
    ADD CONSTRAINT FKSM00312FCT_ORCDOC_DOCASSPROP FOREIGN KEY (NRSEQORCADOC)
      REFERENCES FCT_ORCAMENTODOC (NRSEQORCADOC) 
/

ALTER TABLE FCT_DOCASSINATPROP ADD CONSTRAINT CK_IDATIVO_DOCASSPROP CHECK(IDATIVO IN ('S','N'))
/

ALTER TABLE FCT_DOCASSINATPROP ADD CONSTRAINT CK_IDSITUACAO_DOCASSPROP CHECK(IDSITUACAO IN ('P','A', 'R', 'M'))
/


-- ===============================================================================
-- TABLE: FCT_DOCASSINATCONTR (Documentos de Assinaturas - Lancamento de Contrato)
-- ===============================================================================

CREATE TABLE FCT_DOCASSINATCONTR (
    NRDOCASSINATCONTR   NUMBER  NOT NULL,
    NRASSDIGITALCONTR   NUMBER  NOT NULL,
    NRSEQCONTDOC        NUMBER  NOT NULL,
    NRSEQCONTRATO       NUMBER  NOT NULL, 
    IDSITUACAO          CHAR(1) DEFAULT 'P' NOT NULL,
    DSJUSTIFICARECUSA   VARCHAR2(4000),
    IDSIGNATCERTSIGN    VARCHAR2(500),
    NRORG               NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO             VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FCT_DOCASSCONTR CHECK (IDATIVO IN ('S','N')),
    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'
)
/  

ALTER TABLE FCT_DOCASSINATCONTR ADD CONSTRAINT PK_FCT_DOCASSINATCONTR PRIMARY KEY (NRDOCASSINATCONTR)
/

CREATE INDEX SM00313_FK ON FCT_DOCASSINATCONTR (NRASSDIGITALCONTR ASC)
/

ALTER TABLE FCT_DOCASSINATCONTR
    ADD CONSTRAINT FKSM00313FCT_ASSCON_DOCASSCON FOREIGN KEY (NRASSDIGITALCONTR)
      REFERENCES FCT_ASSINATDIGITALCONTR (NRASSDIGITALCONTR) ON DELETE CASCADE
/

CREATE INDEX SM00314_FK ON FCT_DOCASSINATCONTR (NRSEQCONTRATO ASC)
/

ALTER TABLE FCT_DOCASSINATCONTR
    ADD CONSTRAINT FKSM00314FCT_CONT_DOCASSCONT FOREIGN KEY (NRSEQCONTRATO)
      REFERENCES FCT_CONTRATO (NRSEQCONTRATO) ON DELETE CASCADE
/

CREATE INDEX SM00315_FK ON FCT_DOCASSINATCONTR (NRSEQCONTDOC ASC)
/

ALTER TABLE FCT_DOCASSINATCONTR
    ADD CONSTRAINT FKSM00315FCT_CONDOC_DOCASSCON FOREIGN KEY (NRSEQCONTDOC)
      REFERENCES FCT_CONTRATODOC (NRSEQCONTDOC) 
/

ALTER TABLE FCT_DOCASSINATCONTR ADD CONSTRAINT CK_IDATIVO_DOCASSCONT CHECK(IDATIVO IN ('S','N'))
/

ALTER TABLE FCT_DOCASSINATCONTR ADD CONSTRAINT CK_IDSITUACAO_DOCASSCONT CHECK(IDSITUACAO IN ('P','A', 'R', 'M'))
/