CREATE TABLE FCM_SETOR (
	NRSETOR           NUMBER       NOT NULL,
	NMSETOR           VARCHAR2(150)  NOT NULL,
	NRFUNCRESPONSAVEL NUMBER, 
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CKC_IDATIVO_FCM_SETOR 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',
		CONSTRAINT PK_FCM_SETOR PRIMARY KEY (NRSETOR)
)
/

CREATE TABLE FCM_GRUPOLOCAL (
	NRGRUPOLOCAL      NUMBER       NOT NULL,
	NMGRUPOLOCAL      VARCHAR2(150)  NOT NULL,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_GRUPOLOCAL 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',
		CONSTRAINT PK_FCM_GRUPOLOCAL PRIMARY KEY (NRGRUPOLOCAL)
)
/

CREATE TABLE FCM_TIPOLOCALCLI (
	NRTIPOLOCALCLI    NUMBER       NOT NULL,
	NMTIPOLOCALCLI    VARCHAR2(150)  NOT NULL,
	IDTIPOLOCALCLI    VARCHAR2(1) DEFAULT '3' NOT NULL
		CONSTRAINT CHK_IDTIPOLOCALCLI CHECK (IDTIPOLOCALCLI IN ('1', '2', 3)),
	NRCHECKLISTPADR   NUMBER,
	DSICONETIPOLOCAL  VARCHAR2(4000),
	DSTIPOLOCALCLI    VARCHAR2(4000),
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_TIPOLOCALCLI 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',
		CONSTRAINT PK_FCM_TIPOLOCALCLI PRIMARY KEY (NRTIPOLOCALCLI)
		
)
/

CREATE TABLE FCM_LOCALCLI (
	NRLOCALCLIENTE        NUMBER       NOT NULL,
	NMLOCALCLIENTE        VARCHAR2(150)  NOT NULL,
	CDCLIENTE             VARCHAR2(21)   NOT NULL,
	NRTIPOLOCALCLI        NUMBER       NOT NULL,
	NRLOCALCLIENTEPAI     NUMBER,
	NRSETOR               NUMBER,
	NRGRUPOLOCAL          NUMBER,
	DSICONELOCAL          VARCHAR2(4000),
	DSQRCODE              VARCHAR2(4000),
	DSCODIGOLOCALCLI      VARCHAR2(50),
	CDPAISLOCALCLI        VARCHAR2(4),
	SGESTADOLOCALCLI      VARCHAR2(2),
	CDMUNICIPIOLOCALCLI   VARCHAR2(4),
	CDBAIRROLOCALCLI      VARCHAR2(10),
	DSENDELOCALCLI        VARCHAR2(2500),
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_LOCALCLI 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',
		CONSTRAINT PK_FCM_LOCALCLI PRIMARY KEY (NRLOCALCLIENTE)
)
/

CREATE INDEX FCM00001_FK ON FCM_LOCALCLI (CDCLIENTE ASC)
/

ALTER TABLE FCM_LOCALCLI 
  ADD CONSTRAINT FKFCM00001CLI_LOCALCLI FOREIGN KEY (CDCLIENTE)
      REFERENCES CLIENTE (CDCLIENTE)
/

CREATE INDEX FCM00002_FK ON FCM_LOCALCLI (NRTIPOLOCALCLI ASC)
/

ALTER TABLE FCM_LOCALCLI 
  ADD CONSTRAINT FKFCM00002TPLOCCLI_LOCCLI FOREIGN KEY (NRTIPOLOCALCLI)
      REFERENCES FCM_TIPOLOCALCLI (NRTIPOLOCALCLI)
/      

CREATE INDEX FCM00003_FK ON FCM_LOCALCLI (NRSETOR ASC)
/

ALTER TABLE FCM_LOCALCLI 
  ADD CONSTRAINT FKFCM00003SETOR_LOCALCLI FOREIGN KEY (NRSETOR)
      REFERENCES FCM_SETOR (NRSETOR)
/	  

CREATE INDEX FCM00004_FK ON FCM_LOCALCLI (NRGRUPOLOCAL ASC)
/

ALTER TABLE FCM_LOCALCLI 
  ADD CONSTRAINT FKFCM00004GRUPOLOCAL_LOCALCLI FOREIGN KEY (NRGRUPOLOCAL)
      REFERENCES FCM_GRUPOLOCAL (NRGRUPOLOCAL)
/	  

CREATE INDEX FCM00005_FK ON FCM_LOCALCLI (CDPAISLOCALCLI ASC)
/

ALTER TABLE FCM_LOCALCLI 
  ADD CONSTRAINT FKFCM00005PAIS_LOCALCLI FOREIGN KEY (CDPAISLOCALCLI)
      REFERENCES PAIS (CDPAIS)
/	  

CREATE INDEX FCM00006_FK ON FCM_LOCALCLI (CDPAISLOCALCLI ASC, SGESTADOLOCALCLI ASC)
/

ALTER TABLE FCM_LOCALCLI 
  ADD CONSTRAINT FKFCM00006ESTADO_LOCALCLI FOREIGN KEY (CDPAISLOCALCLI, SGESTADOLOCALCLI)
      REFERENCES ESTADO (CDPAIS, SGESTADO)
/	  

CREATE INDEX FCM00007_FK ON FCM_LOCALCLI (CDPAISLOCALCLI ASC, SGESTADOLOCALCLI ASC, CDMUNICIPIOLOCALCLI ASC)
/

ALTER TABLE FCM_LOCALCLI 
  ADD CONSTRAINT FKFCM00007MUNICIPIO_LOCALCLI FOREIGN KEY (CDPAISLOCALCLI, SGESTADOLOCALCLI, CDMUNICIPIOLOCALCLI)
      REFERENCES MUNICIPIO (CDPAIS, SGESTADO, CDMUNICIPIO) 
/

CREATE INDEX FCM00008_FK ON FCM_LOCALCLI (CDPAISLOCALCLI ASC, SGESTADOLOCALCLI ASC , CDMUNICIPIOLOCALCLI ASC, CDBAIRROLOCALCLI ASC)
/

ALTER TABLE FCM_LOCALCLI 
  ADD CONSTRAINT FKFCM00008BAIRRO_LOCALCLI FOREIGN KEY (CDPAISLOCALCLI, SGESTADOLOCALCLI, CDMUNICIPIOLOCALCLI, CDBAIRROLOCALCLI)
      REFERENCES BAIRRO (CDPAIS, SGESTADO, CDMUNICIPIO, CDBAIRRO) 
/

CREATE TABLE FCM_ATIVIDADE (
	NRATIVIDADE         NUMBER       NOT NULL,
	NMATIVIDADE         VARCHAR2(250)  NOT NULL,
	DSICONEATIVIDADE    VARCHAR2(4000),
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CKC_IDATIVO_FCM_ATIVIDADE 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',
		CONSTRAINT PK_FCM_ATIVIDADE PRIMARY KEY (NRATIVIDADE)
)
/

CREATE TABLE FCM_TAREFA (
	NRTAREFA         NUMBER       NOT NULL,
	NMTAREFA         VARCHAR2(150)  NOT NULL,
	NRATIVIDADE      NUMBER NOT NULL,
	DSPOPSERVICO     VARCHAR2(4000),
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_TAREFA 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',
		CONSTRAINT FCM_TAREFA PRIMARY KEY (NRTAREFA)
)
/

CREATE INDEX FCM00009_FK ON FCM_TAREFA (NRATIVIDADE ASC)
/

ALTER TABLE FCM_TAREFA
  ADD CONSTRAINT FKFCM00009ATIVIDADE_TAREFA FOREIGN KEY (NRATIVIDADE)
      REFERENCES FCM_ATIVIDADE (NRATIVIDADE)
/

CREATE TABLE FCM_CRITERIOTAREFA (
	NRCRITERIOTAREFA  NUMBER       NOT NULL,
	DSCRITERIOTAREFA  VARCHAR2(500)  NOT NULL,
	NRTAREFA          NUMBER  NOT NULL,
	IDTIPOCRITERIO    VARCHAR2(1) DEFAULT '1' NOT NULL,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_CRITERIOTAR 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',
		CONSTRAINT FCM_CRITERIOTAREFA PRIMARY KEY (NRCRITERIOTAREFA)
)
/

CREATE INDEX FCM00010_FK ON FCM_CRITERIOTAREFA (NRTAREFA ASC)
/

ALTER TABLE FCM_CRITERIOTAREFA 
  ADD CONSTRAINT FKFCM00010TAREFA_CRITERIOTAR FOREIGN KEY (NRTAREFA)
      REFERENCES FCM_TAREFA (NRTAREFA)
/

ALTER TABLE FCM_CRITERIOTAREFA ADD CONSTRAINT CHK_IDTIPOCRITERIO CHECK (IDTIPOCRITERIO IN ('1', '2'))
/

CREATE TABLE FCM_TAGSTAREFA (
	NRTAGSTAREFA       NUMBER  NOT NULL,
	NRTAREFA           NUMBER  NOT NULL,
	DSTAGSTAREFA       VARCHAR2(250),
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_TAGSTAREFA 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',
		CONSTRAINT PK_FCM_TAGSTAREFA PRIMARY KEY (NRTAGSTAREFA)
)
/

CREATE INDEX FCM00011_FK ON FCM_TAGSTAREFA (NRTAREFA ASC)
/

ALTER TABLE FCM_TAGSTAREFA 
  ADD CONSTRAINT FKFCM00011TAREFA_TAGSTAREFA FOREIGN KEY (NRTAREFA)
      REFERENCES FCM_TAREFA (NRTAREFA)
/

CREATE TABLE FCM_CHECKLIST (
	NRCHECKLIST           NUMBER       NOT NULL,
	NMCHECKLIST           VARCHAR2(150)  NOT NULL,
	DSCHECKLIST           VARCHAR2(4000),
	NRTIPOLOCALCLI        NUMBER,
	NRSETOR               NUMBER,
	NRCRITICIDADECHK      NUMBER,
	NRHABILIDADE          NUMBER,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_CHECKLIST 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',
		CONSTRAINT PK_FCM_CHECKLIST PRIMARY KEY (NRCHECKLIST)
)
/

CREATE INDEX FCM00012_FK ON FCM_CHECKLIST (NRCHECKLISTPADR ASC)
/

ALTER TABLE FCM_TIPOLOCALCLI 
  ADD CONSTRAINT FKFCM00012CHECKLIST_TPLOCCLI FOREIGN KEY (NRCHECKLISTPADR)
      REFERENCES FCM_CHECKLIST (NRCHECKLIST)
/

CREATE INDEX FCM00013_FK ON FCM_CHECKLIST (NRTIPOLOCALCLI ASC)
/


ALTER TABLE FCM_CHECKLIST 
  ADD CONSTRAINT FKFCM00013LOCALCLI_CHECKLIST FOREIGN KEY (NRTIPOLOCALCLI)
      REFERENCES FCM_TIPOLOCALCLI (NRTIPOLOCALCLI)      
/

CREATE INDEX FCM00014_FK ON FCM_CHECKLIST (NRSETOR ASC)
/

ALTER TABLE FCM_CHECKLIST 
  ADD CONSTRAINT FKFCM00014SETOR_CHECKLIST FOREIGN KEY (NRSETOR)
      REFERENCES FCM_SETOR (NRSETOR)  
/

CREATE TABLE FCM_ATIVIDADECHK (
	NRATIVIDADECHK      NUMBER       NOT NULL,
	NRATIVIDADE         VARCHAR2(250)  NOT NULL,
	NRCHECKLIST         NUMBER       NOT NULL,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_ATIVIDADECHK 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',
		CONSTRAINT PK_FCM_ATIVIDADECHK PRIMARY KEY (NRATIVIDADECHK)
)
/

CREATE INDEX FCM00015_FK ON FCM_ATIVIDADECHK (NRCHECKLIST ASC)
/

ALTER TABLE FCM_ATIVIDADECHK 
  ADD CONSTRAINT FKFCM00015CHECKLIST_ATIVCHK FOREIGN KEY (NRCHECKLIST)
      REFERENCES FCM_CHECKLIST (NRCHECKLIST) 
/

CREATE TABLE FCM_CRITICIDADECHK (
	NRCRITICIDADECHK      NUMBER       NOT NULL,
	NMCRITICIDADECHK      VARCHAR2(150)  NOT NULL,
	IDNIVELCRITICIDADE    VARCHAR2(2),
	NRCHECKLIST           NUMBER       NOT NULL,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_CRITICHK 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',
		CONSTRAINT PK_FCM_CRITICIDADECHK PRIMARY KEY (NRCRITICIDADECHK)
)
/

CREATE INDEX FCM00016_FK ON FCM_CHECKLIST (NRCRITICIDADECHK ASC)
/

ALTER TABLE FCM_CHECKLIST 
  ADD CONSTRAINT FKFCM00016CRITICHK_CHECKLIST FOREIGN KEY (NRCRITICIDADECHK)
      REFERENCES FCM_CRITICIDADECHK (NRCRITICIDADECHK)
/

ALTER TABLE FCM_CRITICIDADECHK ADD CONSTRAINT CHK_IDNIVELCRITICIDADE CHECK (IDNIVELCRITICIDADE IN ('1', '2','3','4', '5', '6', '7', '8','9', '10'))
/

CREATE TABLE FCM_TAREFACHK (
	NRTAREFACHK      NUMBER  NOT NULL,
	NRTAREFA         NUMBER  NOT NULL,
	NRCHECKLIST      NUMBER  NOT NULL,
	NRATIVIDADECHK   NUMBER  NOT NULL,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_TAREFACHK 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',
		CONSTRAINT FCM_TAREFACHK PRIMARY KEY (NRTAREFACHK)
)
/

CREATE INDEX FCM00017_FK ON FCM_TAREFACHK (NRTAREFA ASC)
/

ALTER TABLE FCM_TAREFACHK
  ADD CONSTRAINT FKFCM00017TAREFA_TAREFACHK FOREIGN KEY (NRTAREFA)
      REFERENCES FCM_TAREFA (NRTAREFA)
/

CREATE INDEX FCM00018_FK ON FCM_TAREFACHK (NRCHECKLIST ASC)
/

ALTER TABLE FCM_TAREFACHK 
  ADD CONSTRAINT FKFCM00018CHECKLIST_TAREFACHK FOREIGN KEY (NRCHECKLIST)
      REFERENCES FCM_CHECKLIST (NRCHECKLIST)
/

CREATE INDEX FCM00019_FK ON FCM_TAREFACHK (NRATIVIDADECHK ASC)
/

ALTER TABLE FCM_TAREFACHK 
  ADD CONSTRAINT FKFCM00019ATIVCHK_TAREFACHK FOREIGN KEY (NRATIVIDADECHK)
      REFERENCES FCM_ATIVIDADECHK (NRATIVIDADECHK)
/

CREATE TABLE FCM_CRITERIOTAREFACHK (
	NRCRITERIOTAREFACHK NUMBER    NOT NULL,
	NRCRITERIOTAREFA    NUMBER    NOT NULL,
	NRTAREFACHK         NUMBER    NOT NULL,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_CRITERTARCHK 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',
		CONSTRAINT FCM_CRITERIOTAREFACHK PRIMARY KEY (NRCRITERIOTAREFACHK)
)
/

CREATE INDEX FCM00020_FK ON FCM_CRITERIOTAREFACHK (NRCRITERIOTAREFA ASC)
/

ALTER TABLE FCM_CRITERIOTAREFACHK
  ADD CONSTRAINT FKFCM00020CRITERTAR_CRITERCHK FOREIGN KEY (NRCRITERIOTAREFA)
      REFERENCES FCM_CRITERIOTAREFA (NRCRITERIOTAREFA)
/

CREATE INDEX FCM00021_FK ON FCM_CRITERIOTAREFACHK (NRTAREFACHK ASC)
/

ALTER TABLE FCM_CRITERIOTAREFACHK 
  ADD CONSTRAINT FKFCM00021TAREFACHK_CRITERTAR FOREIGN KEY (NRTAREFACHK)
      REFERENCES FCM_TAREFACHK (NRTAREFACHK)
/

CREATE TABLE FCM_TAGSCHKTAREFA (
	NRTAGSCHKTAREFA    NUMBER    NOT NULL,
	NRTAGSTAREFA       NUMBER    NOT NULL,
	NRTAREFACHK        NUMBER    NOT NULL,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_TAGSCHKTAR 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',
		CONSTRAINT PK_FCM_TAGSCHKTAREFA PRIMARY KEY (NRTAGSCHKTAREFA)
)
/

CREATE INDEX FCM00022_FK ON FCM_TAGSCHKTAREFA (NRTAGSTAREFA ASC)
/

ALTER TABLE FCM_TAGSCHKTAREFA 
  ADD CONSTRAINT FKFCM00022TAGSTAR_TAGSTARCHK FOREIGN KEY (NRTAGSTAREFA)
      REFERENCES FCM_TAGSTAREFA (NRTAGSTAREFA)
/

CREATE INDEX FCM00023_FK ON FCM_TAGSCHKTAREFA (NRTAREFACHK ASC)
/

ALTER TABLE FCM_TAGSCHKTAREFA 
  ADD CONSTRAINT FKFCM00023TARCHK_TAGSTARCHK FOREIGN KEY (NRTAREFACHK)
      REFERENCES FCM_TAREFACHK (NRTAREFACHK)
/

CREATE TABLE FCM_RELCRITERIOTAGTAREFACHK (
	RELCRITERIOTAGTAREFACHK NUMBER    NOT NULL,
	NRCRITERIOTAREFACHK     NUMBER    NOT NULL,
	NRTAGSCHKTAREFA         NUMBER    NOT NULL,
	NRTAREFACHK             NUMBER    NOT NULL,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_RELCRITTAG 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',
		CONSTRAINT PK_FCM_RELCRITERIOTAGTAREFACHK PRIMARY KEY (RELCRITERIOTAGTAREFACHK)
)
/

CREATE INDEX FCM00024_FK ON FCM_RELCRITERIOTAGTAREFACHK (NRCRITERIOTAREFACHK ASC)
/

ALTER TABLE FCM_RELCRITERIOTAGTAREFACHK
  ADD CONSTRAINT FKFCM00024CRITTAR_RELCRITTAG FOREIGN KEY (NRCRITERIOTAREFACHK)
      REFERENCES FCM_CRITERIOTAREFACHK (NRCRITERIOTAREFACHK)
/

CREATE INDEX FCM00025_FK ON FCM_RELCRITERIOTAGTAREFACHK (NRTAGSCHKTAREFA ASC)
/

ALTER TABLE FCM_RELCRITERIOTAGTAREFACHK 
  ADD CONSTRAINT FKFCM00025TAGTARCHK_RELCRITTAG FOREIGN KEY (NRTAGSCHKTAREFA)
      REFERENCES FCM_TAGSCHKTAREFA (NRTAGSCHKTAREFA)
/

CREATE INDEX FCM00026_FK ON FCM_RELCRITERIOTAGTAREFACHK (NRTAREFACHK ASC)
/

ALTER TABLE FCM_RELCRITERIOTAGTAREFACHK 
  ADD CONSTRAINT FKFCM00026TARCHK_RELCRITTAG FOREIGN KEY (NRTAREFACHK)
      REFERENCES FCM_TAREFACHK (NRTAREFACHK)
/

CREATE TABLE FCM_RELACLOCALCHK (
	NRRELACLOCALCHK    NUMBER    NOT NULL,
	NRLOCALCLIENTE     NUMBER    NOT NULL,
	NRCHECKLIST        NUMBER    NOT NULL,
	IDCHECKLISTPADRAO  VARCHAR2(1) DEFAULT 'N' NOT NULL,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_RELACLOCALCHK 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',
		CONSTRAINT FCM_RELACLOCALCHK PRIMARY KEY (NRRELACLOCALCHK)
)
/

CREATE INDEX FCM00027_FK ON FCM_RELACLOCALCHK (NRLOCALCLIENTE ASC)
/

ALTER TABLE FCM_RELACLOCALCHK 
  ADD CONSTRAINT FKFCM00027LOCCLI_RELACLOCCHK FOREIGN KEY (NRLOCALCLIENTE)
      REFERENCES FCM_LOCALCLI (NRLOCALCLIENTE)
/

CREATE INDEX FCM00028_FK ON FCM_RELACLOCALCHK (NRCHECKLIST ASC)
/

ALTER TABLE FCM_RELACLOCALCHK 
  ADD CONSTRAINT FKFCM00028CHKLIST_RELACLOCCHK FOREIGN KEY (NRCHECKLIST)
      REFERENCES FCM_CHECKLIST (NRCHECKLIST)
/

ALTER TABLE FCM_RELACLOCALCHK ADD CONSTRAINT CHK_DSCRITERIOTAREFA CHECK (IDCHECKLISTPADRAO IN ('S', 'N'))
/

CREATE TABLE FCM_FUNCIONARIO (
	NRFUNCIONARIO       NUMBER       NOT NULL,
	NMFUNCIONARIO       VARCHAR2(150)  NOT NULL,
	NRPESSOA            VARCHAR2(10),       
	CDOPERADOR          VARCHAR2(12),
	NRRGFUNCIONARIO     VARCHAR2(20),
	NRCPFFUNCIONARIO    VARCHAR2(20),
	DSEMAILFUNCIONARIO  VARCHAR2(250),
	DSSENHAFUNC         VARCHAR2(4000),
	NRTELFUNCIONARIO    NUMBER,
	IDTURNOFUNCIONARIO  VARCHAR2(1),
	HRENTRADAPADR       VARCHAR2(5),
	HRSAIDAPADR         VARCHAR2(5),
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_FUNCIONARIO 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',
		CONSTRAINT PK_FCM_FUNCIONARIO PRIMARY KEY (NRFUNCIONARIO)
)
/

CREATE INDEX FCM00029_FK ON FCM_FUNCIONARIO (NRPESSOA ASC)
/

ALTER TABLE FCM_FUNCIONARIO 
  ADD CONSTRAINT FKFCM00029PESSOA_FUNCIONARIO FOREIGN KEY (NRPESSOA)
      REFERENCES PESSOA (NRPESSOA)
/

CREATE INDEX FCM00030_FK ON FCM_FUNCIONARIO (CDOPERADOR ASC)
/

ALTER TABLE FCM_FUNCIONARIO 
  ADD CONSTRAINT FKFCM00030OPER_FUNCIONARIO FOREIGN KEY (CDOPERADOR)
      REFERENCES OPERADOR (CDOPERADOR)
/

ALTER TABLE FCM_FUNCIONARIO ADD CONSTRAINT CHK_TURNO_FCM_FUNCIONARIO CHECK (IDTURNOFUNCIONARIO IS NULL OR IDTURNOFUNCIONARIO IN ('1', '2', '3'))
/

CREATE INDEX FCM00031_FK ON FCM_SETOR (NRFUNCRESPONSAVEL ASC)
/

ALTER TABLE FCM_SETOR 
  ADD CONSTRAINT FKFCM00031FUNCIONARIO_SETOR FOREIGN KEY (NRFUNCRESPONSAVEL)
      REFERENCES FCM_FUNCIONARIO (NRFUNCIONARIO)
/

CREATE TABLE FCM_APONTAMENTOFUNC (
	NRAPONTAMENTOFUNC   NUMBER  NOT NULL,
	NRFUNCIONARIO       NUMBER  NOT NULL,
	DTHORAENTRADA       DATE,
	DTHORASAIDA         DATE,
	QTTEMPOAPROPRIADO   DATE,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_APONTFUNC 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',
		CONSTRAINT PK_FCM_APONTAMENTOFUNC PRIMARY KEY (NRAPONTAMENTOFUNC)
)
/

CREATE INDEX FCM00032_FK ON FCM_APONTAMENTOFUNC (NRFUNCIONARIO ASC)
/


ALTER TABLE FCM_APONTAMENTOFUNC 
  ADD CONSTRAINT FKFCM00032FUNCIONAR_APONTFUNC FOREIGN KEY (NRFUNCIONARIO)
      REFERENCES FCM_FUNCIONARIO (NRFUNCIONARIO)
/

CREATE TABLE FCM_CHECKLISTAGEND (
	NRCHECKLISTAGEND    NUMBER  NOT NULL,
	NMCHECKLISTAGEND    VARCHAR2(250) NOT NULL,
	NRLOCALCLIENTE      NUMBER  NOT NULL,
	NRCHECKLIST         NUMBER  NOT NULL,
	NRFUNCIONARIO       NUMBER  NOT NULL,
	IDSITUACAOAGEND     VARCHAR2(1) DEFAULT '1' NOT NULL,
	DTHORAAGEND         VARCHAR2(5),
	DSJUSTCANCELAMENTO  VARCHAR2 (4000), 
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_CHKAGEND 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',
		CONSTRAINT PK_FCM_CHECKLISTAGEND PRIMARY KEY (NRCHECKLISTAGEND)
)
/

CREATE INDEX FCM00033_FK ON FCM_CHECKLISTAGEND (NRLOCALCLIENTE ASC)
/

ALTER TABLE FCM_CHECKLISTAGEND 
  ADD CONSTRAINT FKFCM00033LOCALCLI_CHKAGEND FOREIGN KEY (NRLOCALCLIENTE)
      REFERENCES FCM_LOCALCLI (NRLOCALCLIENTE)
/

CREATE INDEX FCM00034_FK ON FCM_CHECKLISTAGEND (NRCHECKLIST ASC)
/

ALTER TABLE FCM_CHECKLISTAGEND 
  ADD CONSTRAINT FKFCM00034CHECKLIST_CHKAGEND FOREIGN KEY (NRCHECKLIST)
      REFERENCES FCM_CHECKLIST (NRCHECKLIST)
/

CREATE INDEX FCM00035_FK ON FCM_CHECKLISTAGEND (NRFUNCIONARIO ASC)
/

ALTER TABLE FCM_CHECKLISTAGEND 
  ADD CONSTRAINT FKFCM00035FUNCIONAR_CHKAGEND FOREIGN KEY (NRFUNCIONARIO)
      REFERENCES FCM_FUNCIONARIO (NRFUNCIONARIO)
/

ALTER TABLE FCM_CHECKLISTAGEND ADD CONSTRAINT CHK_IDSITUACAOAGEND CHECK (IDSITUACAOAGEND IN ('1', '2', '3', '4', '5'))
/

CREATE TABLE FCM_TAREFAAGEND (
	NRTAREFAAGEND       NUMBER  NOT NULL,
	NRCHECKLISTAGEND    NUMBER  NOT NULL,
	NRTAREFACHK         NUMBER  NOT NULL,
	NRFUNCIONARIO       NUMBER  NOT NULL,
	DTHORATAREFAAGEND   DATE,
	DSOBSTAREFAAGEND    VARCHAR2(4000),
	IDREALIZADO         VARCHAR2(1) DEFAULT 'N' NOT NULL,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_TAREFAAGEND 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',
		CONSTRAINT PK_FCM_TAREFAAGEND PRIMARY KEY (NRTAREFAAGEND)
)
/

CREATE INDEX FCM00036_FK ON FCM_TAREFAAGEND (NRCHECKLISTAGEND ASC)
/

ALTER TABLE FCM_TAREFAAGEND 
  ADD CONSTRAINT FKFCM00036CHKAGEND_TAREFAGEND FOREIGN KEY (NRCHECKLISTAGEND)
      REFERENCES FCM_CHECKLISTAGEND (NRCHECKLISTAGEND)
/

CREATE INDEX FCM00037_FK ON FCM_TAREFAAGEND (NRTAREFACHK ASC)
/

ALTER TABLE FCM_TAREFAAGEND 
  ADD CONSTRAINT FKFCM00037TAREFCHK_TAREFAGEND FOREIGN KEY (NRTAREFACHK)
      REFERENCES FCM_TAREFACHK (NRTAREFACHK)
/

CREATE INDEX FCM00038_FK ON FCM_TAREFAAGEND (NRFUNCIONARIO ASC)
/

ALTER TABLE FCM_TAREFAAGEND 
  ADD CONSTRAINT FKFCM00038FUNCIONA_TAREFAGEND FOREIGN KEY (NRFUNCIONARIO)
      REFERENCES FCM_FUNCIONARIO (NRFUNCIONARIO)
/

ALTER TABLE FCM_TAREFAAGEND ADD CONSTRAINT CHK_IDREALIZADO_FCM_TAREFAAGEN CHECK (IDREALIZADO IN ('S', 'N'))
/

CREATE TABLE FCM_CRITERIOTARAGEND (
	NRCRITERIOTARAGEND  NUMBER  NOT NULL,
	NMCRITERIOTARAGEND  VARCHAR2(250) NOT NULL,
	NRTAREFAAGEND       NUMBER  NOT NULL,
	NRCRITERIOTAREFACHK NUMBER  ,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_CRITTARAGEND 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',
		CONSTRAINT PK_FCM_CRITERIOTARAGEND PRIMARY KEY (NRCRITERIOTARAGEND)
)
/

CREATE INDEX FCM00039_FK ON FCM_CRITERIOTARAGEND (NRTAREFAAGEND ASC)
/

ALTER TABLE FCM_CRITERIOTARAGEND 
  ADD CONSTRAINT FKFCM00039TARAGEN_CRITTARAGEN FOREIGN KEY (NRTAREFAAGEND)
      REFERENCES FCM_TAREFAAGEND (NRTAREFAAGEND)
/

CREATE INDEX FCM00040_FK ON FCM_CRITERIOTARAGEND (NRCRITERIOTAREFACHK ASC)
/

ALTER TABLE FCM_CRITERIOTARAGEND 
  ADD CONSTRAINT FKFCM00040CRITARCHK_CRITARAGEN FOREIGN KEY (NRCRITERIOTAREFACHK)
      REFERENCES FCM_CRITERIOTAREFACHK (NRCRITERIOTAREFACHK)
/

CREATE TABLE FCM_FOTOTAREFAAGEND (
	NRFOTOTAREFAAGEND   NUMBER  NOT NULL,
	NRTAREFAAGEND       NUMBER  NOT NULL,
	DSFOTOTAREFAAGEND   VARCHAR2(1000)  NOT NULL,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_FOTOTARAGEND 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',
		CONSTRAINT PK_FCM_FOTOTAREFAAGEND PRIMARY KEY (NRFOTOTAREFAAGEND)
)
/

CREATE INDEX FCM00041_FK ON FCM_FOTOTAREFAAGEND (NRTAREFAAGEND ASC)
/

ALTER TABLE FCM_FOTOTAREFAAGEND 
  ADD CONSTRAINT FKFCM00041TAREFAAGEN_FOTTARAG FOREIGN KEY (NRTAREFAAGEND)
      REFERENCES FCM_TAREFAAGEND (NRTAREFAAGEND)
/

CREATE TABLE FCM_GERENCIAMENTOCHK (
	NRGERENCIAMENTOCHK  NUMBER  NOT NULL,
	NMGERENCIAMENTOCHK  VARCHAR2(250) NOT NULL,
	NRCHECKLISTAGEND    NUMBER  NOT NULL,
	NRLOCALCLIENTE      NUMBER  NOT NULL, 
	NRCHECKLIST         NUMBER  NOT NULL,
	NRFUNCIONARIO       NUMBER  NOT NULL,
	IDSITUACAOGERCHK    VARCHAR2(1) DEFAULT '1' NOT NULL,
	DTHORAAGEND         VARCHAR2(5),
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_GERCHK 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',
		CONSTRAINT PK_FCM_GERENCIAMENTOCHK PRIMARY KEY (NRGERENCIAMENTOCHK)
)
/

CREATE INDEX FCM00042_FK ON FCM_GERENCIAMENTOCHK (NRCHECKLISTAGEND ASC)
/

ALTER TABLE FCM_GERENCIAMENTOCHK 
  ADD CONSTRAINT FKFCM00042CHECKAGEND_GERCHK FOREIGN KEY (NRCHECKLISTAGEND)
      REFERENCES FCM_CHECKLISTAGEND (NRCHECKLISTAGEND)
/

CREATE INDEX FCM00043_FK ON FCM_GERENCIAMENTOCHK (NRLOCALCLIENTE ASC)
/

ALTER TABLE FCM_GERENCIAMENTOCHK 
  ADD CONSTRAINT FKFCM00043LOCALCLI_GERCHK FOREIGN KEY (NRLOCALCLIENTE)
      REFERENCES FCM_LOCALCLI (NRLOCALCLIENTE)
/

CREATE INDEX FCM00044_FK ON FCM_GERENCIAMENTOCHK (NRCHECKLIST ASC)
/

ALTER TABLE FCM_GERENCIAMENTOCHK 
  ADD CONSTRAINT FKFCM00044CHECKLIST_GERCHK FOREIGN KEY (NRCHECKLIST)
      REFERENCES FCM_CHECKLIST (NRCHECKLIST)
/

CREATE INDEX FCM00045_FK ON FCM_GERENCIAMENTOCHK (NRFUNCIONARIO ASC)
/

ALTER TABLE FCM_GERENCIAMENTOCHK 
  ADD CONSTRAINT FKFCM00045FUNCIONARIO_GERCHK FOREIGN KEY (NRFUNCIONARIO)
      REFERENCES FCM_FUNCIONARIO (NRFUNCIONARIO)
/

ALTER TABLE FCM_GERENCIAMENTOCHK ADD CONSTRAINT CHK_IDSITUACAOGERCHK CHECK (IDSITUACAOGERCHK IN ('1', '2', '3'))
/

CREATE TABLE FCM_TAREFAGERCHK (
	NRTAREFAGERCHK      NUMBER  NOT NULL,
	NRGERENCIAMENTOCHK  NUMBER  NOT NULL,
	NRTAREFACHK         NUMBER  NOT NULL,
	NRFUNCIONARIO       NUMBER  NOT NULL,
	DTHORATAREFAGERCHK  DATE,
	DSOBSTAREFAGERCHK   VARCHAR2(4000),
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_TARGERCHK 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',
		CONSTRAINT PK_FCM_TAREFAGERCHK PRIMARY KEY (NRTAREFAGERCHK)
)
/

CREATE INDEX FCM00046_FK ON FCM_TAREFAGERCHK (NRGERENCIAMENTOCHK ASC)
/

ALTER TABLE FCM_TAREFAGERCHK 
  ADD CONSTRAINT FKFCM00046CHKAGEND_TARGERCHK FOREIGN KEY (NRGERENCIAMENTOCHK)
      REFERENCES FCM_GERENCIAMENTOCHK (NRGERENCIAMENTOCHK)
/

CREATE INDEX FCM00047_FK ON FCM_TAREFAGERCHK (NRFUNCIONARIO ASC)
/

ALTER TABLE FCM_TAREFAGERCHK 
  ADD CONSTRAINT FKFCM00047FUNCIONAR_TARGERCHK FOREIGN KEY (NRFUNCIONARIO)
      REFERENCES FCM_FUNCIONARIO (NRFUNCIONARIO)
/

CREATE INDEX FCM00048_FK ON FCM_TAREFAGERCHK (NRTAREFACHK ASC)
/

ALTER TABLE FCM_TAREFAGERCHK 
  ADD CONSTRAINT FKFCM00048TAREFACHK_TARGERCHK FOREIGN KEY (NRTAREFACHK)
      REFERENCES FCM_TAREFACHK (NRTAREFACHK)
/

CREATE TABLE FCM_CRITERIOTARGERCHK (
	NRCRITERIOTARGERCHK NUMBER  NOT NULL,
	NMCRITERIOTARGERCHK VARCHAR2(250) NOT NULL,
	NRTAREFAGERCHK      NUMBER  NOT NULL,
	NRCRITERIOTAREFACHK NUMBER  ,
	IDMARCADO           VARCHAR2(1) DEFAULT 'N' NOT NULL,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_CRITTARGECHK 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',
		CONSTRAINT PK_FCM_CRITERIOTARGERCHK PRIMARY KEY (NRCRITERIOTARGERCHK)
)
/

CREATE INDEX FCM00049_FK ON FCM_CRITERIOTARGERCHK (NRTAREFAGERCHK ASC)
/

ALTER TABLE FCM_CRITERIOTARGERCHK 
  ADD CONSTRAINT FKFCM00049TAGECHK_CRITAGECHK FOREIGN KEY (NRTAREFAGERCHK)
      REFERENCES FCM_TAREFAGERCHK (NRTAREFAGERCHK)
/

ALTER TABLE FCM_CRITERIOTARGERCHK ADD CONSTRAINT CHK_IDMARCADO_FCM_CRITTARGECHK CHECK (IDMARCADO IN ('S', 'N'))
/

CREATE TABLE FCM_FOTOTAREFAGERCHK (
	NRFOTOTAREFAAGEND   NUMBER  NOT NULL,
	NRTAREFAGERCHK      NUMBER  NOT NULL,
	DSFOTOTAREFAAGEND   VARCHAR2(1000)  NOT NULL,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_FOTOTARCHK 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',
		CONSTRAINT PK_FCM_FOTOTAREFAGERCHK PRIMARY KEY (NRFOTOTAREFAAGEND)
)
/

CREATE INDEX FCM00050_FK ON FCM_FOTOTAREFAGERCHK (NRTAREFAGERCHK ASC)
/

ALTER TABLE FCM_FOTOTAREFAGERCHK 
  ADD CONSTRAINT FKFCM00050TARCHK_FOTOTARCHK FOREIGN KEY (NRTAREFAGERCHK)
      REFERENCES FCM_TAREFAGERCHK (NRTAREFAGERCHK)
/


CREATE TABLE FCM_RELACFUNCSETOR (
	NRRELACFUNCSETOR  NUMBER  NOT NULL,
	NRSETOR           NUMBER  NOT NULL,
	NRFUNCIONARIO     NUMBER  NOT NULL,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_RELFUNCSET 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',
		CONSTRAINT PK_FCM_RELACFUNCSETOR PRIMARY KEY (NRRELACFUNCSETOR)
)
/

CREATE INDEX FCM00051_FK ON FCM_RELACFUNCSETOR (NRSETOR ASC)
/

ALTER TABLE FCM_RELACFUNCSETOR 
  ADD CONSTRAINT FKFCM00051SETOR_RELFUNCSET FOREIGN KEY (NRSETOR)
      REFERENCES FCM_SETOR (NRSETOR)
/

CREATE INDEX FCM00052_FK ON FCM_RELACFUNCSETOR (NRFUNCIONARIO ASC)
/

ALTER TABLE FCM_RELACFUNCSETOR 
  ADD CONSTRAINT FKFCM00052FUNCIONA_RELFUNCSET FOREIGN KEY (NRFUNCIONARIO)
      REFERENCES FCM_FUNCIONARIO (NRFUNCIONARIO) ON DELETE CASCADE 
/

CREATE TABLE FCM_PERFILACESSO (
	NRPERFILACESSO       NUMBER  NOT NULL,
	NMPERFILACESSO       VARCHAR2(250) NOT NULL,
	IDPERMISSSUSUARIO    VARCHAR2(1) DEFAULT 'A' NOT NULL,
	IDPERMISSSFUNCOES    VARCHAR2(1) DEFAULT 'A' NOT NULL,
	IDPERMISSSTAREFAS    VARCHAR2(1) DEFAULT 'A' NOT NULL,
	IDPERMISSSLOCAIS     VARCHAR2(1) DEFAULT 'A' NOT NULL,
	IDPERMISSSCHECKLIST  VARCHAR2(1) DEFAULT 'A' NOT NULL,
	IDPERMISSSRELATORIOS VARCHAR2(1) DEFAULT 'A' NOT NULL,
	IDPERMISSSGRAFICOS   VARCHAR2(1) DEFAULT 'A' NOT NULL,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_PERFILACESSO 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',
		CONSTRAINT PK_FCM_PERFILACESSO PRIMARY KEY (NRPERFILACESSO)
)
/

ALTER TABLE FCM_PERFILACESSO ADD CONSTRAINT CHK_IDPERMISSSUSUARIO CHECK (IDPERMISSSUSUARIO IN ('V', 'E', 'A'))
/

ALTER TABLE FCM_PERFILACESSO ADD CONSTRAINT CHK_IDPERMISSSFUNCOES CHECK (IDPERMISSSFUNCOES IN ('V', 'E', 'A'))
/

ALTER TABLE FCM_PERFILACESSO ADD CONSTRAINT CHK_IDPERMISSSTAREFAS CHECK (IDPERMISSSTAREFAS IN ('V', 'E', 'A'))
/

ALTER TABLE FCM_PERFILACESSO ADD CONSTRAINT CHK_IDPERMISSSLOCAIS CHECK (IDPERMISSSLOCAIS IN ('V', 'E', 'A'))
/

ALTER TABLE FCM_PERFILACESSO ADD CONSTRAINT CHK_IDPERMISSSCHECKLIST CHECK (IDPERMISSSCHECKLIST IN ('V', 'E', 'A'))
/

ALTER TABLE FCM_PERFILACESSO ADD CONSTRAINT CHK_IDPERMISSSRELATORIOS CHECK (IDPERMISSSRELATORIOS IN ('V', 'E', 'A'))
/

ALTER TABLE FCM_PERFILACESSO ADD CONSTRAINT CHK_IDPERMISSSGRAFICOS CHECK (IDPERMISSSGRAFICOS IN ('V', 'E', 'A'))
/

CREATE TABLE FCM_RELACFUNCPERFACESS (
	RELACFUNCPERFACESS NUMBER  NOT NULL,
	NRPERFILACESSO     NUMBER  NOT NULL,
	NRFUNCIONARIO      NUMBER  NOT NULL,
	NRORG             NUMBER 	     DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
	IDATIVO           VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
		CONSTRAINT CHK_IDATIVO_FCM_RELFUNPERACESS 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',
		CONSTRAINT PK_FCM_RELACFUNCPERFACESS PRIMARY KEY (RELACFUNCPERFACESS)
)
/

CREATE INDEX FCM00053_FK ON FCM_RELACFUNCPERFACESS (NRPERFILACESSO ASC)
/

ALTER TABLE FCM_RELACFUNCPERFACESS 
  ADD CONSTRAINT FKFCM00053_NRPERFILACESSO	 FOREIGN KEY (NRPERFILACESSO)
      REFERENCES FCM_PERFILACESSO (NRPERFILACESSO)
/

CREATE INDEX FCM00054_FK ON FCM_RELACFUNCPERFACESS (NRFUNCIONARIO ASC)
/

ALTER TABLE FCM_RELACFUNCPERFACESS 
  ADD CONSTRAINT FKFCM00054FUNC_RELFUNPERACESS FOREIGN KEY (NRFUNCIONARIO)
      REFERENCES FCM_FUNCIONARIO (NRFUNCIONARIO) ON DELETE CASCADE
/