CREATE TABLE FCM_TIPOSOLICITACAO (
    NRTIPOSOLICITACAO    NUMBER NOT NULL,
    NMTIPOSOLICITACAO    VARCHAR2(250) NOT NULL,
    IDPRIORIDADEPADR     CHAR(1),
    NRORG             	 NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           	 VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
      CONSTRAINT CKC_IDATIVO_FCM_TIPOSOLICIT CHECK (IDATIVO IN ('S','N')),
    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 FCM_TIPOSOLICITACAO ADD CONSTRAINT PK_FCM_TIPOSOLICITACAO PRIMARY KEY (NRTIPOSOLICITACAO)
/

ALTER TABLE FCM_TIPOSOLICITACAO ADD CONSTRAINT CKC_IDPRIORIDADEPADR CHECK (IDPRIORIDADEPADR IN ('1', '2', '3', '4'))
/

CREATE TABLE FCM_SOLICITACAO (
    NRSOLICITACAO        NUMBER NOT NULL,
    NMSOLICITACAO        VARCHAR2(250) NOT NULL,
    DTSOLICITACAO        DATE NOT NULL,
    IDSITUACAO           CHAR(1) DEFAULT '1' NOT NULL,
    NRLOCALCLIENTE       NUMBER NOT NULL,
    NRTIPOSOLICITACAO    NUMBER,
    IDPRIORIDADE         CHAR(1),
    NRFUNCABERTURA       NUMBER,
    NRFUNCRESPONSAVEL    NUMBER,
    DSSOLICITACAO        VARCHAR2(4000),
    NRORG             	 NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           	 VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
      CONSTRAINT CKC_IDATIVO_FCM_SOLICITACAO CHECK (IDATIVO IN ('S','N')),
    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 FCM_SOLICITACAO ADD CONSTRAINT PK_FCM_SOLICITACAO PRIMARY KEY (NRSOLICITACAO)
/

CREATE INDEX FCM00080_FK ON FCM_SOLICITACAO (NRLOCALCLIENTE ASC)
/

ALTER TABLE FCM_SOLICITACAO 
  ADD CONSTRAINT FKFCM00080LOCALCLI_SOLICIT FOREIGN KEY (NRLOCALCLIENTE)
      REFERENCES FCM_LOCALCLI (NRLOCALCLIENTE)
/

CREATE INDEX FCM00081_FK ON FCM_SOLICITACAO (NRTIPOSOLICITACAO ASC)
/

ALTER TABLE FCM_SOLICITACAO 
  ADD CONSTRAINT FKFCM00081TPSOLICITA_SOLICITA FOREIGN KEY (NRTIPOSOLICITACAO)
      REFERENCES FCM_TIPOSOLICITACAO (NRTIPOSOLICITACAO)
/

CREATE INDEX FCM00082_FK ON FCM_SOLICITACAO (NRFUNCABERTURA ASC)
/

ALTER TABLE FCM_SOLICITACAO 
  ADD CONSTRAINT FKFCM00082FUNCABERT_SOLICITA FOREIGN KEY (NRFUNCABERTURA)
      REFERENCES FCM_FUNCIONARIO (NRFUNCIONARIO)
/

CREATE INDEX FCM00083_FK ON FCM_SOLICITACAO (NRFUNCRESPONSAVEL ASC)
/

ALTER TABLE FCM_SOLICITACAO 
  ADD CONSTRAINT FKFCM00083FUNCRESPONS_SOLICITA FOREIGN KEY (NRFUNCRESPONSAVEL)
      REFERENCES FCM_FUNCIONARIO (NRFUNCIONARIO)
/

ALTER TABLE FCM_SOLICITACAO ADD CONSTRAINT CKC_IDSITUACAO_SOLICITA CHECK (IDSITUACAO IN ('1', '2', '3', '4'))
/

ALTER TABLE FCM_SOLICITACAO ADD CONSTRAINT CKC_IDPRIORIDADE CHECK (IDPRIORIDADE IN ('1', '2', '3', '4'))
/

CREATE TABLE FCM_SOLICITACAOTAREFAS (
    NRSOLICITACAOTAREFAS   NUMBER NOT NULL,
    NRSOLICITACAO          NUMBER NOT NULL,
    NRCHECKLISTAGEND       NUMBER,
    NRORG             	   NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           	   VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
      CONSTRAINT CKC_IDATIVO_FCM_SOLICITATAR CHECK (IDATIVO IN ('S','N')),
    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 FCM_SOLICITACAOTAREFAS ADD CONSTRAINT PK_FCM_SOLICITACAOTAREFAS PRIMARY KEY (NRSOLICITACAOTAREFAS)
/

CREATE INDEX FCM00084_FK ON FCM_SOLICITACAOTAREFAS (NRSOLICITACAO ASC)
/

ALTER TABLE FCM_SOLICITACAOTAREFAS 
  ADD CONSTRAINT FKFCM00084SOLICIT_SOLICITATAR FOREIGN KEY (NRSOLICITACAO)
      REFERENCES FCM_SOLICITACAO (NRSOLICITACAO)
/

CREATE INDEX FCM00085_FK ON FCM_SOLICITACAOTAREFAS (NRCHECKLISTAGEND ASC)
/

ALTER TABLE FCM_SOLICITACAOTAREFAS 
  ADD CONSTRAINT FKFCM00085CHKAGEND_SOLICTAR FOREIGN KEY (NRCHECKLISTAGEND)
      REFERENCES FCM_CHECKLISTAGEND (NRCHECKLISTAGEND)
/

ALTER TABLE FCM_CHECKLISTAGEND MODIFY NRCHECKLIST NULL
/

CREATE TABLE FCM_SOLICITACAOHISTORICO (
    NRSOLICITACAOHISTORICO   NUMBER NOT NULL,
    NRSOLICITACAO            NUMBER NOT NULL,
    NMSOLICITACAO            VARCHAR2(250) NOT NULL,
    DTHISTSOLICITACAO        DATE NOT NULL,
    IDSITUACAO               CHAR(1) DEFAULT '1' NOT NULL,
    IDTIPOHISTORICO          CHAR(1),
    NRFUNCSOLICITANTE        NUMBER,
    DSSOLICITACAO            VARCHAR2(4000),
    IDSATISFACAOSOLICITA     CHAR(1),
    NRORG             	     NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           	   	 VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
      CONSTRAINT CKC_IDATIVO_FCM_SOLICITAHIS CHECK (IDATIVO IN ('S','N')),
    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 FCM_SOLICITACAOHISTORICO ADD CONSTRAINT PK_FCM_SOLICITACAOHISTORICO PRIMARY KEY (NRSOLICITACAOHISTORICO)
/  

CREATE INDEX FCM00086_FK ON FCM_SOLICITACAOHISTORICO (NRSOLICITACAO ASC)
/


ALTER TABLE FCM_SOLICITACAOHISTORICO 
  ADD CONSTRAINT FKFCM00086SOLICIT_SOLICITAHIS FOREIGN KEY (NRSOLICITACAO)
      REFERENCES FCM_SOLICITACAO (NRSOLICITACAO)
/

CREATE INDEX FCM00087_FK ON FCM_SOLICITACAOHISTORICO (NRFUNCSOLICITANTE ASC)
/

ALTER TABLE FCM_SOLICITACAOHISTORICO 
  ADD CONSTRAINT FKFCM00087FUNCI_SOLICITAHIS FOREIGN KEY (NRFUNCSOLICITANTE)
      REFERENCES FCM_FUNCIONARIO (NRFUNCIONARIO)
/

ALTER TABLE FCM_SOLICITACAOHISTORICO ADD CONSTRAINT CKC_IDSITUACAO_SOLICITAHIS CHECK (IDSITUACAO IN ('1', '2', '3', '4'))
/

ALTER TABLE FCM_SOLICITACAOHISTORICO ADD CONSTRAINT CKC_IDTIPOHISTORICO CHECK (IDTIPOHISTORICO IN ('1', '2', '3', '4'))
/

ALTER TABLE FCM_SOLICITACAOHISTORICO ADD CONSTRAINT CKC_IDSATISFACAOSOLICITA CHECK (IDSATISFACAOSOLICITA IN ('1', '2', '3', '4', '5'))
/

CREATE TABLE FCM_SOLICITACAOIMAGENS (
    NRSOLICITACAOIMAGENS     NUMBER NOT NULL,
    NRSOLICITACAO            NUMBER NOT NULL,
    DSFOTOSOLICITACAO        VARCHAR(2000),
    NRORG             	     NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           	   	 VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
      CONSTRAINT CKC_IDATIVO_FCM_SOLICITAIMG CHECK (IDATIVO IN ('S','N')),
    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 FCM_SOLICITACAOIMAGENS ADD CONSTRAINT PK_FCM_SOLICITACAOIMAGENS PRIMARY KEY (NRSOLICITACAOIMAGENS)
/

CREATE INDEX FCM00088_FK ON FCM_SOLICITACAOIMAGENS (NRSOLICITACAO ASC)
/

ALTER TABLE FCM_SOLICITACAOIMAGENS 
  ADD CONSTRAINT FKFCM00088SOLICIT_SOLICITIMG FOREIGN KEY (NRSOLICITACAO)
      REFERENCES FCM_SOLICITACAO (NRSOLICITACAO)
/

ALTER TABLE FCM_CHECKLISTAGEND ADD IDNOTIFICADO CHAR(1) DEFAULT 'N' NOT NULL
/ 

ALTER TABLE FCM_CHECKLISTAGEND ADD CONSTRAINT CKC_CHKLISTAGEND_IDNOTIFICADO CHECK (IDNOTIFICADO IN ('S', 'N'))
/ 

ALTER TABLE FCM_GERENCIAMENTOCHK ADD IDNOTIFICADO CHAR(1) DEFAULT 'N' NOT NULL
/ 

ALTER TABLE FCM_GERENCIAMENTOCHK ADD CONSTRAINT CKC_GERENCCHK_IDNOTIFICADO CHECK (IDNOTIFICADO IN ('S', 'N'))
/ 

DROP TABLE FCM_APONTAMENTOFUNC
/ 

CREATE TABLE FCM_APONTAMENTO (
    NRAPONTAMENTO     		 NUMBER NOT NULL,
    DTAPONTAMENTO     		 DATE NOT NULL,
    NRFUNCIONARIO     		 NUMBER NOT NULL,
    HRENTRADA          		 VARCHAR2 (5),
    HRSAIDA           		 VARCHAR2 (5),
    HRINTERVALO       		 VARCHAR2 (5),
    HRTRABALHADAS     		 VARCHAR2 (5),
    HRAUSENCIA        		 VARCHAR2 (5),
    HRTOTAIS          		 VARCHAR2 (5),
    IDFALTA           		 VARCHAR2(1) DEFAULT 'N' NOT NULL,
    IDAPURADO         		 VARCHAR2(1) DEFAULT 'N' NOT NULL,
    NRORG             	     NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           	   	 VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
      CONSTRAINT CKC_IDATIVO_FCM_APONT CHECK (IDATIVO IN ('S','N')),
    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 FCM_APONTAMENTO ADD CONSTRAINT PK_FCM_APONTAMENTO PRIMARY KEY (NRAPONTAMENTO)
/ 

CREATE INDEX FCM00089_FK ON FCM_APONTAMENTO (NRFUNCIONARIO ASC)
/

ALTER TABLE FCM_APONTAMENTO 
  ADD CONSTRAINT FKFCM00089FUNCIONARIO_APONT FOREIGN KEY (NRFUNCIONARIO)
      REFERENCES FCM_FUNCIONARIO (NRFUNCIONARIO)
/ 

ALTER TABLE FCM_APONTAMENTO ADD CONSTRAINT CKC_IDFALTA_FCM_APONT CHECK (IDFALTA IN ('S', 'N'))
/ 

ALTER TABLE FCM_APONTAMENTO ADD CONSTRAINT CKC_IDAPURADO_FCM_APONT CHECK (IDAPURADO IN ('S', 'N'))
/

CREATE TABLE FCM_REGISTROHORAS (
    NRREGISTROHORAS    		 NUMBER NOT NULL,
    NRAPONTAMENTO      		 NUMBER NOT NULL,
    DTHRENTRADA        		 VARCHAR2 (5),
    DTHRSAIDA          		 VARCHAR2 (5),
    HRTEMPOREGISTRO    		 VARCHAR2 (5),
    IDTIPORESGISTRO    		 VARCHAR2(1),
    IDALMOCO           		 VARCHAR2(1) DEFAULT 'N' NOT NULL,
    DSOBSREGISTRO      		 VARCHAR2(4000),
    NRORG             	     NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           	   	 VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
      CONSTRAINT CKC_IDATIVO_FCM_REGHORAS CHECK (IDATIVO IN ('S','N')),
    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 FCM_REGISTROHORAS ADD CONSTRAINT PK_FCM_REGISTROHORAS PRIMARY KEY (NRREGISTROHORAS)
/ 

CREATE INDEX FCM00090_FK ON FCM_REGISTROHORAS (NRAPONTAMENTO ASC)
/

ALTER TABLE FCM_REGISTROHORAS 
  ADD CONSTRAINT FKFCM00090APONT_REGHORAS FOREIGN KEY (NRAPONTAMENTO)
      REFERENCES FCM_APONTAMENTO (NRAPONTAMENTO)
/ 

ALTER TABLE FCM_REGISTROHORAS ADD CONSTRAINT CKC_IDTIPORESGISTRO_FCM_REGHR CHECK (IDTIPORESGISTRO IN ('E', 'S'))
/ 

ALTER TABLE FCM_REGISTROHORAS ADD CONSTRAINT CKC_IDALMOCO_FCM_REGHORAS CHECK (IDALMOCO IN ('S', 'N'))
/

CREATE TABLE FCM_ANEXOSAPONTAMENTO (
    NRANEXOSAPONTAMENTO  NUMBER NOT NULL,
    NRREGISTROHORAS      NUMBER NOT NULL,
    DSCAMINHOANEXO       VARCHAR2(4000),
    NRORG             	     NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           	   	 VARCHAR2(1)     DEFAULT 'S' 					NOT NULL
      CONSTRAINT CK_IDATIVO_FCM_ANEXAPONT CHECK (IDATIVO IN ('S','N')),
    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 FCM_ANEXOSAPONTAMENTO ADD CONSTRAINT PK_FCM_ANEXOSAPONTAMENTO PRIMARY KEY (NRANEXOSAPONTAMENTO)
/ 

CREATE INDEX FCM00091_FK ON FCM_ANEXOSAPONTAMENTO (NRREGISTROHORAS ASC)
/

ALTER TABLE FCM_ANEXOSAPONTAMENTO 
  ADD CONSTRAINT FKFCM00091REGISTHR_ANEXAPONT FOREIGN KEY (NRREGISTROHORAS)
      REFERENCES FCM_REGISTROHORAS (NRREGISTROHORAS)
/