ALTER TABLE FCM_SOLICITACAOSERV ADD NRLOCALCLIENTE  NUMBER(38)
/

ALTER TABLE FCM_ORDEMSERV ADD NRLOCALCLIENTE  NUMBER(38)
/

ALTER TABLE FCM_ORDEMSERV ADD IDTAREFARESPONSAVEL VARCHAR2(1)
/

ALTER TABLE FCM_ORDEMSERV ADD CONSTRAINT CKC_IDTRFARESPNSVLFCM_ORDMSERV CHECK (IDTAREFARESPONSAVEL IN ('S', 'N'))
/

ALTER TABLE FCM_ORDEMSERV DROP CONSTRAINT CKC_IDSITUACAO_FCM_ORDEMSERV
/

ALTER TABLE FCM_ORDEMSERV ADD CONSTRAINT CKC_IDSITUACAO_FCM_ORDEMSERV CHECK (IDSITUACAO IN ('1', '2', '3', '4', '5'))
/

ALTER TABLE FCM_ORDEMSERV ADD NRMODELOPOP NUMBER
/

ALTER TABLE FCM_ORDEMSERV ADD NREQUIPE NUMBER
/

ALTER TABLE FCM_ORDEMSERV ADD DURACAOORDEM INTERVAL DAY TO SECOND DEFAULT INTERVAL '0' SECOND
/

ALTER TABLE FCM_ORDEMSERV ADD NRSOLICITACAOSERV NUMBER
/

ALTER TABLE FCM_GERCHKHISTORICO ADD JUSTIFICATIVAKANBAN  VARCHAR2(4000)
/
ALTER TABLE FCM_ORDEMSERV ADD CONSTRAINT FKFCM00215RESPONSAVEL_EXTERNO FOREIGN KEY (NRSOLICITACAOSERV) 
	REFERENCES FCM_SOLICITACAOSERV (NRSOLICITACAOSERV) ON DELETE CASCADE
/

CREATE INDEX FCM00215_FK ON FCM_ORDEMSERV (NRSOLICITACAOSERV ASC)
/

CREATE TABLE FCM_PROFISSIONALEXTERNO (
	NRPROFISSIONALEXTERNO	NUMBER        NOT NULL,
    NMPROFISSIONALEXTERNO	VARCHAR2(150) NOT NULL,
	NMEMPRESA				VARCHAR2(150),
    INSCRICAO   		    VARCHAR2(20),
    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_FCM_PRFSSIONLEXTRN CHECK (IDATIVO IN ('S','N'))
)
/

ALTER TABLE FCM_PROFISSIONALEXTERNO ADD CONSTRAINT PK_FCM_PROFISSIONALEXTERNO PRIMARY KEY (NRPROFISSIONALEXTERNO)
/

CREATE TABLE FCM_RESPONSAVELORDEMS (
	NRRESPONSAVELORDEMS		NUMBER        NOT NULL,
	NRORDEMSERV   		    NUMBER        NOT NULL,
    NRPROFISSIONALEXTERNO	NUMBER,
	CDOPERADOR				VARCHAR2(12),
    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_FCM_RSPNSAVELRDEMS CHECK (IDATIVO IN ('S','N'))
)
/

ALTER TABLE FCM_RESPONSAVELORDEMS ADD CONSTRAINT PK_FCM_RESPONSAVELORDEMS PRIMARY KEY (NRRESPONSAVELORDEMS)
/
ALTER TABLE FCM_RESPONSAVELORDEMS 
  ADD CONSTRAINT FKFCM00216RESPONSAVEL_ORDEM FOREIGN KEY (NRORDEMSERV)
    REFERENCES FCM_ORDEMSERV (NRORDEMSERV)
/
	
CREATE INDEX FCM00216_FK ON FCM_RESPONSAVELORDEMS (NRORDEMSERV ASC)
/

ALTER TABLE FCM_RESPONSAVELORDEMS 
  ADD CONSTRAINT FKFCM00217RESPONSAVEL_EXTERNO FOREIGN KEY (NRPROFISSIONALEXTERNO)
    REFERENCES FCM_PROFISSIONALEXTERNO (NRPROFISSIONALEXTERNO)
/

CREATE INDEX FCM00217_FK ON FCM_RESPONSAVELORDEMS (NRPROFISSIONALEXTERNO ASC)
/

ALTER TABLE FCM_RESPONSAVELORDEMS 
  ADD CONSTRAINT FKFCM00218RESPONSAVEL_OPERADOR FOREIGN KEY (CDOPERADOR)
    REFERENCES OPERADOR (CDOPERADOR)
/

CREATE INDEX FCM00218_FK ON FCM_RESPONSAVELORDEMS (CDOPERADOR ASC)
/

CREATE TABLE FCM_RELACEPIORDEMS (
	NRRELACEPIORDEMS		NUMBER        NOT NULL,
    NREPI			        NUMBER        NOT NULL,
    NRORDEMSERV   		    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_FCM_RELACEPIORDEMS CHECK (IDATIVO IN ('S','N'))
)
/

ALTER TABLE FCM_RELACEPIORDEMS ADD CONSTRAINT PK_FCM_RELACEPIORDEMS PRIMARY KEY (NRRELACEPIORDEMS)
/

ALTER TABLE FCM_RELACEPIORDEMS 
  ADD CONSTRAINT FKFCM00219RELACEPIORDEMS_EPI FOREIGN KEY (NREPI)
    REFERENCES FCM_EPI (NREPI)
/
	
CREATE INDEX FCM00219_FK ON FCM_RELACEPIORDEMS (NREPI ASC)
/

ALTER TABLE FCM_RELACEPIORDEMS 
  ADD CONSTRAINT FKFCM00220RELACEPIORDEMS_ORDEM FOREIGN KEY (NRORDEMSERV)
    REFERENCES FCM_ORDEMSERV (NRORDEMSERV)
/

CREATE INDEX FCM00220_FK ON FCM_RELACEPIORDEMS (NRORDEMSERV ASC)
/
