CREATE TABLE CP_CALL_SIGNATURE (
	NRCALLSIGNATURE     NUMBER NOT NULL,
	NRCALL              NUMBER,
	IDDOCUMCERTSIGN     VARCHAR2(50),
	CHAVEDOCCERTISIGN   VARCHAR2(50),
	IDSIGNATCERTISIGN   NUMBER,
	NAMESIGNATORY       VARCHAR2(250),
	CPFSIGNATORY        NUMBER,
	MAILSIGNATORY       VARCHAR2(250),
	DSURLSIGNATURE      VARCHAR2(250),
	IDSITUACAO          VARCHAR2(1),
	DSJUSTIFICARECUSA   VARCHAR2(4000),
	CALL_RELATIONSHIP   VARCHAR2(10),
	CALL_REFERENCE      VARCHAR2(250),
	CALL_PRODUCT        VARCHAR2(10),
	CALL_CLASSIFICATION VARCHAR2(10),
	CALL_BOARD          VARCHAR2(10),
	CALL_DESCRIPTION    VARCHAR2(2000),
	CALL_COMMENT        VARCHAR2(4000),
	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_CP_CALL_SIGNATURE CHECK (IDATIVO IN ('S','N'))
)
/

ALTER TABLE CP_CALL_SIGNATURE ADD CONSTRAINT PK_CP_CALL_SIGNATURE PRIMARY KEY (NRCALLSIGNATURE)
/

ALTER TABLE CP_CALL_SIGNATURE 
  ADD CONSTRAINT FKSM00447CP_CALL_SIGNAT FOREIGN KEY (NRCALL)
     REFERENCES CP_CALL (NRCALL) ON DELETE CASCADE
/

CREATE INDEX SM00447_FK ON CP_CALL_SIGNATURE (NRCALL ASC)
/
     
ALTER TABLE CP_CALL_SIGNATURE ADD CONSTRAINT CKC_IDSITUACAO_CALL_SIGNAT CHECK(IDSITUACAO IN ('P','A','R', 'M'))
/

ALTER TABLE CP_CALL_SIGNATURE ADD CONSTRAINT CKC_IDATIVO_CALL_SIGNAT CHECK(IDATIVO IN ('S','N'))
/

CREATE TABLE CP_LOGCALLSIGNATURE (
	NRLOGCALLSIGNATURE NUMBER NOT NULL,
	NRCALL             NUMBER,
	IDDOCUMCERTSIGN    VARCHAR2(50),
	CPFSIGNATORY       NUMBER,
	DSERRO             VARCHAR2(4000),
	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_CP_LOGCALLSIGNATRE CHECK (IDATIVO IN ('S','N'))
)
/

ALTER TABLE CP_LOGCALLSIGNATURE ADD CONSTRAINT PK_CP_LOGCALLSIGNATURE PRIMARY KEY (NRLOGCALLSIGNATURE)
/

ALTER TABLE CP_LOGCALLSIGNATURE 
  ADD CONSTRAINT FKSM00448CP_LOGCALLSIGNAT FOREIGN KEY (NRCALL)
     REFERENCES CP_CALL (NRCALL) ON DELETE CASCADE
/

CREATE INDEX SM00448_FK ON CP_LOGCALLSIGNATURE (NRCALL ASC)
/
