CREATE TABLE MODELODOCCDA (
    NRMODELODOCCDA 	  NUMBER NOT NULL, 
	DSMODELODOCORCA   VARCHAR2(250), 
	IDDOCPADRAO 	  VARCHAR2(1) DEFAULT 'N' 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'
)
/
ALTER TABLE MODELODOCCDA ADD CONSTRAINT PK_MODELODOCCDA PRIMARY KEY (NRMODELODOCCDA)
/
ALTER TABLE MODELODOCCDA ADD CONSTRAINT CKC_IDATIVO_MODELODOCCDA CHECK (IDATIVO IN ('S', 'N'))
/
ALTER TABLE MODELODOCCDA ADD CONSTRAINT CKC_IDATIVO_IDDOCPADRAO CHECK (IDDOCPADRAO IN ('S', 'N'))
/
CREATE TABLE SERVPRESTDOC (
    NRSERVPRESTDOC      NUMBER NOT NULL,
	CDEMPRESA           VARCHAR2(2) NOT NULL,
    CDFUNC              VARCHAR2(10) NOT NULL,
    CDCLIENTE           VARCHAR2(21)NOT NULL,
    DTSERVPREST         DATE  NOT NULL,
    NRSERVPREST         VARCHAR2(5) NOT NULL,
    NRMODELODOCCDA      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'
)
/
ALTER TABLE SERVPRESTDOC ADD CONSTRAINT PK_SERVPRESTDOC PRIMARY KEY (NRSERVPRESTDOC)
/
ALTER TABLE SERVPRESTDOC 
  ADD CONSTRAINT FKSM00426SERVPRESTSERVPRESTDOC FOREIGN KEY (CDEMPRESA, CDFUNC, CDCLIENTE, DTSERVPREST, NRSERVPREST)
      REFERENCES SERVPREST (CDEMPRESA, CDFUNC, CDCLIENTE, DTSERVPREST, NRSERVPREST)
/
CREATE INDEX SM00426_FK ON SERVPRESTDOC (CDEMPRESA, CDFUNC, CDCLIENTE, DTSERVPREST, NRSERVPREST)
/
ALTER TABLE SERVPRESTDOC 
  ADD CONSTRAINT FKSM00427MODDOCCDASERVPRESTDOC FOREIGN KEY (NRMODELODOCCDA)
      REFERENCES MODELODOCCDA (NRMODELODOCCDA)
/
CREATE INDEX SM00427_FK ON SERVPRESTDOC (NRMODELODOCCDA ASC)
/
ALTER TABLE SERVPRESTDOC ADD CONSTRAINT CKC_IDATIVO_SERVPRESTDOC CHECK (IDATIVO IN ('S', 'N'))
/
ALTER TABLE SERVPRESTDOC ADD IDDOCUMCERTSIGN VARCHAR2(500)
/
ALTER TABLE SERVPRESTDOC ADD CHAVEDOCUMCERTSIGN VARCHAR2(500)
/
ALTER TABLE SERVPRESTDOC ADD IDSITASSINATURA VARCHAR2(20)
/
ALTER TABLE SERVPRESTDOC ADD CONSTRAINT CKC_IDSITASSINA_SRVPRSTDOC CHECK (IDSITASSINATURA IN ('ENVIADO', 'PARCIAL','NAO_ENVIADO', 'ASSINADO', 'RECUSADO', 'MANUAL'))
/
ALTER TABLE SERVPRESTDOC ADD DTASSINATURA  DATE
/
ALTER TABLE SERVPRESTDOC ADD DSJUSTIFRECUSAASSINAT VARCHAR2(4000)
/
ALTER TABLE INTECLIE ADD NRCPFICLIE VARCHAR2(20)
/
CREATE TABLE SERVPRESTDOCASSINA (
	NRSERVPRESTDOCASSINA  NUMBER NOT NULL,    
	NRSERVPRESTDOC        NUMBER NOT NULL,
	NRCPFSIGNATARIO       VARCHAR2(20) NOT NULL,
	NMSIGNATARIO          VARCHAR2(2000),
	DSEMAILSIGNATARIO     VARCHAR2(1000),
	IDTIPOASSINATURA      CHAR(1),
	IDSITASSINATURA       VARCHAR2(20),
	DTASSINATURA          DATE,
	DSURLASSINATURA       VARCHAR2(500),
	DSJUSTIFRECUSAASSINAT VARCHAR2(4000),
	DSJUSTIFMANUALASSINAT VARCHAR2(4000),
	DTALTSITUMANUAL       DATE,
	CDOPERALTSITUMANUAL   VARCHAR2(12),
	IDSIGNATCERTSIGN      VARCHAR2(500),
	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_SERVPRESTDOCASS CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE SERVPRESTDOCASSINA ADD CONSTRAINT PK_SERVPRESTDOCASSINA PRIMARY KEY (NRSERVPRESTDOCASSINA)
/
ALTER TABLE SERVPRESTDOCASSINA
  ADD CONSTRAINT FKSM00423SERPRETDOCSRVPREDOCAS FOREIGN KEY (NRSERVPRESTDOC)
      REFERENCES SERVPRESTDOC (NRSERVPRESTDOC)
/
CREATE INDEX SM00423_FK ON SERVPRESTDOCASSINA (NRSERVPRESTDOC ASC)
/
ALTER TABLE SERVPRESTDOCASSINA ADD CONSTRAINT CKC_IDTPASSINA_SRVPRSTDOCASS CHECK (IDTIPOASSINATURA IN ('E', 'D'))
/
ALTER TABLE SERVPRESTDOCASSINA ADD CONSTRAINT CKC_IDSITASSINA_SRVPRSTDOCASS CHECK (IDSITASSINATURA IN ('ENVIADO', 'NAO_ENVIADO', 'ASSINADO', 'RECUSADO', 'MANUAL'))
/
-- ============================================================
--   Table: SERVPRESTDOCLOGASSINA                       
-- ============================================================
CREATE TABLE SERVPRESTDOCLOGASSINA (
	NRSERVPRESTDOCLOGASSINA NUMBER NOT NULL,     
	NRSERVPRESTDOC          NUMBER NOT NULL, 
	NRSERVPRESTDOCASSINA    NUMBER,
    IDDOCUMCERTSIGN         VARCHAR2(500),
	NRCPFSIGNATARIO         VARCHAR2(20),    
	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_SERVPRESTDOCLOG CHECK (IDATIVO IN ('S','N'))
)
/
ALTER TABLE SERVPRESTDOCLOGASSINA ADD CONSTRAINT PK_SERVPRESTDOCLOGASSINA PRIMARY KEY (NRSERVPRESTDOCLOGASSINA)
/
ALTER TABLE SERVPRESTDOCLOGASSINA
  ADD CONSTRAINT FKSM00424SERVPTDOCSRVPTDOCLOG FOREIGN KEY (NRSERVPRESTDOC)
      REFERENCES SERVPRESTDOC (NRSERVPRESTDOC)
/
CREATE INDEX SM00424_FK ON SERVPRESTDOCLOGASSINA (NRSERVPRESTDOC ASC)
/
ALTER TABLE SERVPRESTDOCLOGASSINA
  ADD CONSTRAINT FKSM00425SRVPRTDCASRVPRTDCLOG FOREIGN KEY (NRSERVPRESTDOCASSINA)
      REFERENCES SERVPRESTDOCASSINA (NRSERVPRESTDOCASSINA)
/
CREATE INDEX SM00425_FK ON SERVPRESTDOCLOGASSINA (NRSERVPRESTDOCASSINA ASC)