CREATE TABLE FCT_LEMBRETECONT (
    NRLEMBRETECONT		        NUMBER NOT NULL,
    NRSEQCONTRATO               NUMBER NOT NULL,
    DSLEMBRETECONT		        VARCHAR2(200) NOT NULL,
    DSEMAILLEMBRETE       	    VARCHAR2(4000),
    DTHRLEMBRETE                DATE,
    NRORG             NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
    DTINCLUSAO        DATE            DEFAULT SYSDATE,
    DTULTATU          DATE            DEFAULT SYSDATE,
    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',
		CONSTRAINT CKC_IDATIVO_FCT_LEMBRETECONTA CHECK (IDATIVO IN ('S','N'))
)
/

ALTER TABLE FCT_LEMBRETECONT ADD CONSTRAINT PK_FCT_LEMBRETECONT PRIMARY KEY (NRLEMBRETECONT)
/

ALTER TABLE FCT_LEMBRETECONT 
    ADD CONSTRAINT FKSM00439CNTRAT_RELCPRLMBRTCNT FOREIGN KEY (NRSEQCONTRATO)
        REFERENCES FCT_CONTRATO (NRSEQCONTRATO) ON DELETE CASCADE
/

CREATE INDEX SM00439_FK ON FCT_LEMBRETECONT (NRSEQCONTRATO ASC)
/

CREATE TABLE FCT_OPERLEMBRETECONT (
    NROPERLEMBRETECONT		    NUMBER NOT NULL,
    CDOPERADOR			        VARCHAR2(12) NOT NULL,
    NRLEMBRETECONT		        NUMBER NOT NULL,
    NRORG             NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
    DTINCLUSAO        DATE            DEFAULT SYSDATE,
    DTULTATU          DATE            DEFAULT SYSDATE,
    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',
		CONSTRAINT CKC_IDATIVO_FCT_OPERLEMBRTCONT CHECK (IDATIVO IN ('S','N'))
)
/

ALTER TABLE FCT_OPERLEMBRETECONT ADD CONSTRAINT PK_FCT_OPERLEMBRETECONT PRIMARY KEY (NROPERLEMBRETECONT)
/

ALTER TABLE FCT_OPERLEMBRETECONT 
    ADD CONSTRAINT FKSM00440OPERADR_RLCPRLMBRTCNT FOREIGN KEY (CDOPERADOR)
        REFERENCES OPERADOR (CDOPERADOR) ON DELETE CASCADE
/
CREATE INDEX SM00440_FK ON FCT_OPERLEMBRETECONT (CDOPERADOR ASC)
/

ALTER TABLE FCT_OPERLEMBRETECONT
    ADD CONSTRAINT FKSM00441NRLMBTCNT_RLCPRLBRCNT FOREIGN KEY (NRLEMBRETECONT)
        REFERENCES FCT_LEMBRETECONT (NRLEMBRETECONT) ON DELETE CASCADE
/
CREATE INDEX SM00441_FK ON FCT_OPERLEMBRETECONT (NRLEMBRETECONT ASC)
/

CREATE TABLE FCT_LEMBRETECONTNOTIF (
    NRLEMBRETECONTNOTIF		        NUMBER NOT NULL,
    NRLEMBRETECONT               NUMBER NOT NULL,
    IDTPNOTIFICACAOLEMBRCONT	VARCHAR2(1),
    QTEVENTOLEMBRETE            VARCHAR2(4),
    IDPERIODOEVENTLEMBRCONT	    VARCHAR2(1),
    IDTPEVENTLEMBRCONT	        VARCHAR2(1),
    QTDIASRECORRENCIA           VARCHAR2(4),
    IDDIASRECLEMBRCONT          VARCHAR2(50),
    IDEXIBICAOLEMBRCONT         VARCHAR2(50),
    NRORG             NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
    DTINCLUSAO        DATE            DEFAULT SYSDATE,
    DTULTATU          DATE            DEFAULT SYSDATE,
    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',
		CONSTRAINT CKC_IDATIVO_FCT_LEMBRETCONTNTF CHECK (IDATIVO IN ('S','N'))
)
/

ALTER TABLE FCT_LEMBRETECONTNOTIF ADD CONSTRAINT PK_FCT_LEMBRETECONTNOTIF PRIMARY KEY (NRLEMBRETECONTNOTIF)
/

ALTER TABLE FCT_LEMBRETECONTNOTIF 
    ADD CONSTRAINT FKSM00442FCT_LEMBRETE_NOTFCCAO FOREIGN KEY (NRLEMBRETECONT)
        REFERENCES FCT_LEMBRETECONT (NRLEMBRETECONT) ON DELETE CASCADE
/
CREATE INDEX SM00442_FK ON FCT_LEMBRETECONTNOTIF (NRLEMBRETECONT ASC)
/
        
ALTER TABLE FCT_LEMBRETECONTNOTIF ADD CONSTRAINT CKC_IDTPNOTIFICACAOLEMBRCONT CHECK (IDTPNOTIFICACAOLEMBRCONT IN ('E', 'R'))
/

ALTER TABLE FCT_LEMBRETECONTNOTIF ADD CONSTRAINT CKC_IDPERIODOEVENTLEMBRCONT CHECK (IDPERIODOEVENTLEMBRCONT IN ('D', 'S', 'M'))
/

ALTER TABLE FCT_LEMBRETECONTNOTIF ADD CONSTRAINT CKC_IDTPEVENTLEMBRCONT CHECK (IDTPEVENTLEMBRCONT IN ('A', 'D'))
/

ALTER TABLE FCT_LEMBRETECONTNOTIF ADD DTFINALRECORRENCIA DATE
/

CREATE TABLE FCT_LEMBRCONTNOTIFRECORR (
   NRLEMBRCONTNOTIFRECORR  NUMBER,
   NRLEMBRETECONTNOTIF     NUMBER,
   DTNOTIFICACAO           DATE,
   NRORG             NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
    DTINCLUSAO        DATE            DEFAULT SYSDATE,
    DTULTATU          DATE            DEFAULT SYSDATE,
    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',
		CONSTRAINT CKC_IDATIVO_FCT_LMBRCNTNTFRCOR CHECK (IDATIVO IN ('S','N'))
)
/


ALTER TABLE FCT_LEMBRCONTNOTIFRECORR ADD CONSTRAINT PK_FCT_LEMBRCONTNOTIFRECORR PRIMARY KEY (NRLEMBRCONTNOTIFRECORR)
/

ALTER TABLE FCT_LEMBRCONTNOTIFRECORR 
      ADD CONSTRAINT FKSM00443FCT_LEMBNTF_LMBNOTFRC FOREIGN KEY (NRLEMBRETECONTNOTIF)
          REFERENCES FCT_LEMBRETECONTNOTIF (NRLEMBRETECONTNOTIF) ON DELETE CASCADE
/
CREATE INDEX SM00443_FK ON FCT_LEMBRCONTNOTIFRECORR (NRLEMBRETECONTNOTIF ASC)
/
