CREATE TABLE PARAMTPRATSERV (
  NRPARAMTPRATSERV NUMBER(10) NOT NULL, 
  CDFILIAL VARCHAR2(4) NOT NULL, 
  CDSERVFILI VARCHAR2(5) NOT NULL, 
  CDTIPOPRAT VARCHAR2(2) NOT NULL, 
  NRORG NUMBER(10) NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  DTINCLUSAO VARCHAR2(4000) DEFAULT NULL NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NULL,
  CONSTRAINT PK_PARAMTPRATSERV PRIMARY KEY(NRPARAMTPRATSERV, NRORG)
)
/
ALTER TABLE PARAMTPRATSERV ADD CONSTRAINT FKPLA00926SERVICO FOREIGN KEY (CDFILIAL, CDSERVFILI, NRORG) REFERENCES SERVICO (CDFILIAL, CDSERVFILI, NRORG)
/
ALTER TABLE PARAMTPRATSERV ADD CONSTRAINT FKPLA00925TIPOPRAT FOREIGN KEY (CDTIPOPRAT, NRORG) REFERENCES TIPOPRAT (CDTIPOPRAT, NRORG)
/
ALTER TABLE PARAMTPRATSERV ADD CONSTRAINT CKC_IDATIVO_PARAMTPRATSERV CHECK (IDATIVO IN ('S','N'))
/
CREATE INDEX FKPLA00926SERVICO ON PARAMTPRATSERV (CDFILIAL, CDSERVFILI, NRORG)
/
CREATE INDEX FKPLA00925TIPOPRAT ON PARAMTPRATSERV (CDTIPOPRAT, NRORG)
/
CREATE TABLE PARAMSERVICOOPER (
  CDFILIAL VARCHAR2(4) NOT NULL, 
  CDSERVFILI VARCHAR2(5) NOT NULL, 
  IDNOTIFICAREFE VARCHAR2(30) DEFAULT 'NAO_NOTIFICA' NOT NULL, 
  HRALTERACLI VARCHAR2(4) DEFAULT NULL NULL, 
  VRACRESCIMO DOUBLE PRECISION DEFAULT NULL NULL, 
  VRREDUCAO DOUBLE PRECISION DEFAULT NULL NULL, 
  NRDIASALT DOUBLE PRECISION DEFAULT NULL NULL, 
  DSEMAILNOTIF VARCHAR2(200) DEFAULT NULL NULL, 
  IDFORMALTERA VARCHAR2(30) DEFAULT 'COMENSAL' NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NOT NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NOT NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NOT NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NOT NULL,
  CONSTRAINT PK_PARAMSERVICOOPER PRIMARY KEY(CDFILIAL, CDSERVFILI, NRORG)
)
/
ALTER TABLE PARAMSERVICOOPER ADD CONSTRAINT FKPLA00933SERVICO FOREIGN KEY (CDFILIAL, CDSERVFILI, NRORG) REFERENCES SERVICO (CDFILIAL, CDSERVFILI, NRORG)
/
ALTER TABLE PARAMSERVICOOPER ADD CONSTRAINT CKC_IDNOTIFICAREFE_SERVICOOPER CHECK (IDNOTIFICAREFE  IN ('NOTIFICA_ACIMA_LIMITE','NOTIFICA_ABAIXO_LIMITE', 'NOTIFICA_TODAS', 'NAO_NOTIFICA'))
/
ALTER TABLE PARAMSERVICOOPER ADD CONSTRAINT CKC_IDFORMALTERA_SERVICOOPER CHECK (IDFORMALTERA  IN ('COMENSAL','APROVACAO'))
/
ALTER TABLE PARAMSERVICOOPER ADD CONSTRAINT CKC_IDATIVO_SERVICOOPER CHECK (IDATIVO IN ('S','N'))
/
CREATE TABLE CONFIRMAREFE (
  NRCONFIRMAREFE NUMBER(10) NOT NULL, 
  CDFILIAL VARCHAR2(4) DEFAULT NULL NULL, 
  CDSERVFILI VARCHAR2(5) DEFAULT NULL NULL, 
  NRCARDAPIO VARCHAR2(10) DEFAULT NULL NULL, 
  DTCARDAPIO DATE DEFAULT NULL NULL, 
  CDPRATO VARCHAR2(10) DEFAULT NULL NULL, 
  CDCLIENTE VARCHAR2(21) DEFAULT NULL NULL, 
  CDDESTFILI VARCHAR2(3) DEFAULT NULL NULL, 
  CDTURNO VARCHAR2(1) DEFAULT NULL NULL, 
  QTCOMEORIGINAL DOUBLE PRECISION DEFAULT NULL NULL, 
  QTCOMEALTERADA DOUBLE PRECISION DEFAULT NULL NULL, 
  QTTOTALALTERADA DOUBLE PRECISION DEFAULT NULL NULL, 
  IDQTDEAPROVADA VARCHAR2(30) DEFAULT 'PENDENTE' NOT NULL, 
  DSPARAMETROS VARCHAR2(200) DEFAULT NULL NULL, 
  NRORG VARCHAR2(1) DEFAULT '1' NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NOT NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NOT NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NOT NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NOT NULL,
  CONSTRAINT PK_CONFIRMAREFE PRIMARY KEY(NRCONFIRMAREFE, NRORG)
)
/
ALTER TABLE CONFIRMAREFE ADD CONSTRAINT FKPLA00934SERVICO FOREIGN KEY (CDFILIAL, CDSERVFILI, NRORG) REFERENCES SERVICO (CDFILIAL, CDSERVFILI, NRORG)
/
ALTER TABLE CONFIRMAREFE ADD CONSTRAINT CKC_IDQTDEAPROVADA_CONFIRMARE CHECK (IDQTDEAPROVADA IN ('PENDENTE','APROVADA'))
/
ALTER TABLE CONFIRMAREFE ADD CONSTRAINT CKC_IDATIVO_CONFIRMAREFE CHECK (IDATIVO IN ('S','N'))
/
CREATE INDEX FKPLA00934SERVICO ON CONFIRMAREFE (CDFILIAL, CDSERVFILI, NRORG)
/
ALTER TABLE CONFIRMAREFE DROP CONSTRAINT CKC_IDATIVO_CONFIRMAREFE
/
ALTER TABLE CONFIRMAREFE ADD CONSTRAINT CKC_IDATIVO_CONFIRMAREFE CHECK (IDATIVO IN ('S','N'))