ALTER TABLE FCT_RELACSERVICO ADD IDMEDIDAFIXA VARCHAR2(1) DEFAULT 'N'
/
ALTER TABLE FCT_RELACSERVICO ADD CONSTRAINT CKC_IDMEDFIXA_RELACSERV CHECK(IDMEDIDAFIXA IN('S', 'N'))
/
CREATE TABLE FCT_CAPAPARAMFATPROP (
    NRCAPAPARAMFATPROP  	NUMBER 		NOT NULL,
    NRSEQORCAMENTO      	NUMBER 		NOT NULL,
    NRGRUPOFATURA       	NUMBER,
    CDPRODFATURA        	VARCHAR2(10),
    CDFILIALFATURA      	VARCHAR2(4),
    NRPARCFATURA        	NUMBER,
    IDTPFATURA          	CHAR(1) 		NOT NULL,
    QTPARCELASFATU      	NUMBER,
    IDTPCALCPARCINC     	CHAR(1) 		NOT NULL,
    IDGERARATEIO        	CHAR(1) 		DEFAULT 'N' NOT NULL,
    IDAPURAAPONTAMENTO  CHAR(1) 		DEFAULT 'N' NOT NULL,
    IDATIVO             		CHAR(1) 		DEFAULT 'S' NOT NULL,
    NRORG               		NUMBER 		DEFAULT NVL(SYS_CONTEXT('nrorg_ctx', 'nrorg'), 1) NOT NULL,
    DTINCLUSAO          	DATE 		DEFAULT SYSDATE NOT NULL,
    DTULTATU            	DATE,
    NRORGINCLUSAO       	NUMBER 		NOT NULL,
    CDOPERINCLUSAO      	VARCHAR2(12) 	NOT NULL,
    NRORGULTATU         	NUMBER,
    CDOPERULTATU        	VARCHAR2(12)
)
/
ALTER TABLE FCT_CAPAPARAMFATPROP
    ADD CONSTRAINT PK_FCT_CAPAPARAMFATPROP PRIMARY KEY (NRCAPAPARAMFATPROP)
/
ALTER TABLE FCT_CAPAPARAMFATPROP
    ADD CONSTRAINT FKSM00172FCT_ORCAMENTO FOREIGN KEY (NRSEQORCAMENTO)
        REFERENCES FCT_ORCAMENTO (NRSEQORCAMENTO) ON DELETE CASCADE
/
ALTER TABLE FCT_CAPAPARAMFATPROP
    ADD CONSTRAINT FKSM00173FCT_GRUPOFATURA FOREIGN KEY (NRGRUPOFATURA)
        REFERENCES FCT_GRUPOFATURA (NRGRUPOFATURA)
/
ALTER TABLE FCT_CAPAPARAMFATPROP
    ADD CONSTRAINT FKSM00174PRODUTO FOREIGN KEY (CDPRODFATURA)
        REFERENCES PRODUTO (CDPRODUTO)
/
ALTER TABLE FCT_CAPAPARAMFATPROP
    ADD CONSTRAINT FKSM00175FILIAL FOREIGN KEY (CDFILIALFATURA)
        REFERENCES FILIAL (CDFILIAL)
/
ALTER TABLE FCT_CAPAPARAMFATPROP
    ADD CONSTRAINT FKSM00176PARCNEGOCIO FOREIGN KEY (NRPARCFATURA)
        REFERENCES PARCNEGOCIO (NRPARCNEGOCIO)
/
ALTER TABLE FCT_CAPAPARAMFATPROP
    ADD CONSTRAINT CKC_IDTPFATURA_FCT_CAPAPFPRO CHECK (IDTPFATURA IN ('A', 'X', 'P', 'O'))
/
ALTER TABLE FCT_CAPAPARAMFATPROP
    ADD CONSTRAINT CKC_IDTPCALCPARC_FCT_CAPAPFPRO CHECK (IDTPCALCPARCINC IN ('1', '2', '3'))
/
ALTER TABLE FCT_CAPAPARAMFATPROP
    ADD CONSTRAINT CKC_IDGERARATEIO_FCT_CAPAPFPRO CHECK (IDGERARATEIO IN ('S', 'N'))
/
ALTER TABLE FCT_CAPAPARAMFATPROP
    ADD CONSTRAINT CKC_IDAPURAAPO_FCT_CAPAPFPRO CHECK (IDAPURAAPONTAMENTO IN ('S', 'N'))
/
ALTER TABLE FCT_CAPAPARAMFATPROP
    ADD CONSTRAINT CKC_IDATIVO_FCT_CAPAPFPRO CHECK (IDATIVO IN ('S', 'N'))
/
CREATE TABLE FCT_PARAMFATPROP (
    NRPARAMFATPROP   	NUMBER 		NOT NULL,
    NRSEQORCAMENTO  	NUMBER 		NOT NULL,
    NRDIACOMPETINI  	NUMBER 		NOT NULL,
    NRDIACOMPETFIN  	NUMBER 		NOT NULL,
    IDMESCOMPETINI  	CHAR(1) 		NOT NULL,
    IDMESCOMPETFIN  	CHAR(1) 		NOT NULL,
    QTDIASAPURACAO  	NUMBER 		NOT NULL,
    IDTPCALCVENC    	CHAR(1) 		NOT NULL,
    NRDIACALCVENC   	NUMBER 		NOT NULL,
    IDMESCALCVENC   	CHAR(1),
    QTDIASFATUVENC  	NUMBER,
    IDATIVO         		CHAR(1) 		DEFAULT 'S' NOT NULL,
    NRORG           		NUMBER 		DEFAULT NVL(SYS_CONTEXT('nrorg_ctx', 'nrorg'), 1) NOT NULL,
    DTINCLUSAO      		DATE 		DEFAULT SYSDATE NOT NULL,
    DTULTATU        		DATE,
    NRORGINCLUSAO   	NUMBER 		NOT NULL,
    CDOPERINCLUSAO  	VARCHAR2(12) 	NOT NULL,
    NRORGULTATU     	NUMBER,
    CDOPERULTATU    	VARCHAR2(12)
)
/
ALTER TABLE FCT_PARAMFATPROP
    ADD CONSTRAINT PK_FCT_PARAMFATPROP PRIMARY KEY (NRPARAMFATPROP)
/
ALTER TABLE FCT_PARAMFATPROP
    ADD CONSTRAINT  FKSM00177FCT_ORCAMENTO FOREIGN KEY (NRSEQORCAMENTO)
        REFERENCES FCT_ORCAMENTO (NRSEQORCAMENTO) ON DELETE CASCADE
/
ALTER TABLE FCT_PARAMFATPROP
    ADD CONSTRAINT CKC_IDMESINI_FCT_PARAMFATPROP CHECK (IDMESCOMPETINI IN ('1', '2', '3'))
/
ALTER TABLE FCT_PARAMFATPROP
    ADD CONSTRAINT CKC_IDMESFIN_FCT_PARAMFATPROP CHECK (IDMESCOMPETFIN IN ('1', '2', '3'))
/
ALTER TABLE FCT_PARAMFATPROP
    ADD CONSTRAINT CKC_IDTPCALC_FCT_PARAMFATPROP CHECK (IDTPCALCVENC IN ('1', '2'))
/
ALTER TABLE FCT_PARAMFATPROP
    ADD CONSTRAINT CKC_IDMESCALC_FCT_PARAMFATPROP CHECK (IDMESCALCVENC IN ('1', '2', '3'))
/
ALTER TABLE FCT_PARAMFATPROP
    ADD CONSTRAINT CKC_IDATIVO_FCT_PARAMFATPROP CHECK (IDATIVO IN ('S', 'N'))
/
CREATE TABLE FCT_PARAMFATITPROP (
    NRPARAMFATITPROP 	NUMBER 		NOT NULL,
    NRITEMORCAMENTO 	NUMBER		NOT NULL,
    NRSEQORCAMENTO  	NUMBER 		NOT NULL,
    NRGRUPOFATURA   	NUMBER,
    CDPRODFATURA    	VARCHAR2(10),
    CDFILIALFATURA  	VARCHAR2(4),
    NRPARCFATURA    	NUMBER,
    IDTPFATURA      		CHAR(1) 		NOT NULL,
    QTPARCELASFATU  	NUMBER,
    IDATIVO         		CHAR(1) 		DEFAULT 'S' NOT NULL,
    NRORG          		NUMBER 		DEFAULT NVL(SYS_CONTEXT('nrorg_ctx', 'nrorg'), 1) NOT NULL,
    DTINCLUSAO      		DATE		DEFAULT SYSDATE NOT NULL,
    DTULTATU        		DATE,
    NRORGINCLUSAO   	NUMBER 		NOT NULL,
    CDOPERINCLUSAO  	VARCHAR2(12) 	NOT NULL,
    NRORGULTATU     	NUMBER,
    CDOPERULTATU    	VARCHAR2(12)
)
/
ALTER TABLE FCT_PARAMFATITPROP
    ADD CONSTRAINT PK_FCT_PARAMFATITPROP PRIMARY KEY (NRPARAMFATITPROP)
/
ALTER TABLE FCT_PARAMFATITPROP
    ADD CONSTRAINT FKSM00178FCT_ITEMORCAMENTO FOREIGN KEY (NRITEMORCAMENTO)
        REFERENCES FCT_ITEMORCAMENTO (NRITEMORCAMENTO) ON DELETE CASCADE
/
ALTER TABLE FCT_PARAMFATITPROP
    ADD CONSTRAINT FKSM00179FCT_ORCAMENTO FOREIGN KEY (NRSEQORCAMENTO)
        REFERENCES FCT_ORCAMENTO (NRSEQORCAMENTO)
/
ALTER TABLE FCT_PARAMFATITPROP
    ADD CONSTRAINT FKSM00180FCT_GRUPOFATURA FOREIGN KEY (NRGRUPOFATURA)
        REFERENCES FCT_GRUPOFATURA (NRGRUPOFATURA)
/
ALTER TABLE FCT_PARAMFATITPROP
    ADD CONSTRAINT FKSM00181PRODUTO FOREIGN KEY (CDPRODFATURA)
        REFERENCES PRODUTO (CDPRODUTO)
/
ALTER TABLE FCT_PARAMFATITPROP
    ADD CONSTRAINT FKSM00182FILIAL FOREIGN KEY (CDFILIALFATURA)
        REFERENCES FILIAL (CDFILIAL)
/
ALTER TABLE FCT_PARAMFATITPROP
    ADD CONSTRAINT FKSM00183PARCNEGOCIO FOREIGN KEY (NRPARCFATURA)
        REFERENCES PARCNEGOCIO (NRPARCNEGOCIO)
/
ALTER TABLE FCT_PARAMFATITPROP
    ADD CONSTRAINT CKC_IDTPFATURA_FCT_PFATITPRO CHECK (IDTPFATURA IN ('A', 'X', 'P', 'O'))
/
ALTER TABLE FCT_PARAMFATITPROP
    ADD CONSTRAINT CKC_IDATIVO_FCT_PFATITPRO CHECK (IDATIVO IN ('S', 'N'))