CREATE TABLE RFPMAIN (
	NRRFPMAIN           NUMBER          NOT NULL,
	COMPRADOR           VARCHAR2(50)    NOT NULL,
	CDFILIAL            VARCHAR2(04)    NOT NULL,
	DTVALIDADEINICIAL   DATE            NOT NULL,
	DTVALIDADEFINAL     DATE            NOT NULL,
	STATUS              VARCHAR2(13)    NOT NULL,
	DTIMPORTACAO        DATE            NOT NULL,
	RESPONSAVEL         VARCHAR2(50)    NOT NULL,
	DSARQUIVO           VARCHAR2(99)    NOT NULL,
	CDOPERLOGADO        VARCHAR2(12)    NOT NULL,
	CDFILCENTCMP        VARCHAR2(04),
	CDCOMPRADOR         VARCHAR2(12),
	MESSAGE             VARCHAR2(99),
	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 PK_RFPMAIN PRIMARY KEY (NRRFPMAIN),
		CONSTRAINT FKSUP00666RFPMAIN_CDFILIAL FOREIGN KEY (CDFILIAL) REFERENCES FILIAL (CDFILIAL),
		CONSTRAINT FKSUP00667RFPMAIN_CDOPERLOGADO FOREIGN KEY (CDOPERLOGADO) REFERENCES OPERADOR (CDOPERADOR),
		CONSTRAINT FKSUP00668RFPMAIN_CDFILCENTCMP FOREIGN KEY (CDFILCENTCMP) REFERENCES FILIAL (CDFILIAL),
		CONSTRAINT FKSUP00669RFPMAIN_CDCOMPRADOR FOREIGN KEY (CDCOMPRADOR) REFERENCES COMPRADOR (CDOPERADOR),  
		CONSTRAINT CKC_IDATIVO_RFPMAIN CHECK (IDATIVO IN ('S','N')),
		CONSTRAINT CKC_RFPMAIN_STATUS CHECK (STATUS IN ('PENDENTE', 'INCONSISTENTE', 'GERADO'))
)
/

CREATE INDEX SUP00666_FK ON RFPMAIN (CDFILIAL ASC)
/

CREATE INDEX SUP00667_FK ON RFPMAIN (CDOPERLOGADO ASC)
/

CREATE INDEX SUP00668_FK ON RFPMAIN (CDFILCENTCMP ASC)
/

CREATE INDEX SUP00669_FK ON RFPMAIN (CDCOMPRADOR ASC)
/


CREATE SEQUENCE SEQ_RFPMAIN_NRRFPMAIN START WITH 1 INCREMENT BY 1
/

CREATE TABLE RFPFORNECEDOR (
    NRRFPFORNECEDOR   NUMBER       NOT NULL,
    NRRFPMAIN         NUMBER       NOT NULL,
    NRINSJURFRFP      VARCHAR2(50),
    CDFORNECED        VARCHAR2(21),
    MESSAGE           VARCHAR2(99),
    CDFORMPGTO        VARCHAR2(02), 
    IDTPFORPGTFO      VARCHAR2(01),    
    NRPARCPGTOFO      NUMBER(2),      
    NRDIAPGFIXFO      NUMBER(2),      
    IDUTDIAPGTFO      VARCHAR2(01),  
    IDTPFRETFORN      VARCHAR2(01), 
    CDTIPCOB          VARCHAR2(02),
    VRPEDESCFORN      FLOAT(126),
    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 PK_RFPFORNECEDOR PRIMARY KEY (NRRFPFORNECEDOR),
		CONSTRAINT FKSUP00670RFPFORNECDR_NRFPMAIN FOREIGN KEY (NRRFPMAIN) REFERENCES RFPMAIN (NRRFPMAIN),
		CONSTRAINT FKSUP00671RFPFORNECDR_CDFORNCD FOREIGN KEY (CDFORNECED) REFERENCES FORNECEDOR (CDFORNECED),
		CONSTRAINT CKC_IDATIVO_RFPFORNECEDOR CHECK (IDATIVO IN ('S','N'))
)
/

CREATE INDEX SUP00670_FK ON RFPFORNECEDOR (NRRFPMAIN ASC)
/

CREATE INDEX SUP00671_FK ON RFPFORNECEDOR (CDFORNECED ASC)
/

CREATE SEQUENCE SEQ_RFPFORNECEDOR_NRRFPFORN START WITH 1 INCREMENT BY 1
/

CREATE TABLE RFPREGIAO (
    NRRFPREGIAO       NUMBER          NOT NULL,
    NRRFPMAIN         NUMBER          NOT NULL,
    CODREGIAO         VARCHAR2(20) 	  NOT NULL,
    CDREGIAO          VARCHAR2(03),
    MESSAGE	          VARCHAR2(99),
    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 PK_RFPREGIAO PRIMARY KEY (NRRFPREGIAO),
		CONSTRAINT FKSUP00672RFPREGIAO_NRRFPMAIN FOREIGN KEY (NRRFPMAIN) REFERENCES RFPMAIN (NRRFPMAIN),
		CONSTRAINT FKSUP00673RFPREGIAO_CDREGIAO FOREIGN KEY (CDREGIAO) REFERENCES REGIAO (CDREGIAO),
		CONSTRAINT CKC_IDATIVO_RFPREGIAO CHECK (IDATIVO IN ('S','N'))
)
/

CREATE INDEX SUP00672_FK ON RFPREGIAO (NRRFPMAIN ASC)
/

CREATE INDEX SUP00673_FK ON RFPREGIAO (CDREGIAO ASC)
/

CREATE SEQUENCE SEQ_RFPREGIAO_NRRFPREGIAO START WITH 1 INCREMENT BY 1
/

CREATE TABLE RFPPRODMARCA (
    NRRFPPRODMARCA    NUMBER       NOT NULL,
    NRRFPMAIN         NUMBER       NOT NULL,
    CODPRODUTO        VARCHAR2(50),
    CDPRODUTO         VARCHAR2(10),
    CODMARCA1         VARCHAR2(20),
    CDMARCA1          VARCHAR2(05),
    VRPRECO1          NUMBER(10,2),
    CODMARCA2         VARCHAR2(20),
    CDMARCA2          VARCHAR2(05),
    VRPRECO2          NUMBER(10,2),
    CODMARCA3         VARCHAR2(20),
    CDMARCA3          VARCHAR2(05),
    VRPRECO3          NUMBER(10,2),
    CODMARCA4         VARCHAR2(20),
    CDMARCA4          VARCHAR2(05),
    VRPRECO4          NUMBER(10,2),
    CODMARCA5         VARCHAR2(20),
    CDMARCA5          VARCHAR2(05),
    VRPRECO5          NUMBER(10,2),
    MESSAGE           VARCHAR2(99),
    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 PK_RFPPRODMARCA PRIMARY KEY (NRRFPPRODMARCA),
		CONSTRAINT FKSUP00674RFPRODMARCA_NRFPMAIN FOREIGN KEY (NRRFPMAIN) REFERENCES RFPMAIN (NRRFPMAIN),
		CONSTRAINT FKSUP00675RFPRODMARCA_CDPRODTO FOREIGN KEY (CDPRODUTO) REFERENCES PRODUTO (CDPRODUTO),
		CONSTRAINT FKSUP00676RFPRODMARCA_CDMARCA1 FOREIGN KEY (CDMARCA1) REFERENCES MARCA (CDMARCA),
		CONSTRAINT FKSUP00677RFPRODMARCA_CDMARCA2 FOREIGN KEY (CDMARCA2) REFERENCES MARCA (CDMARCA),
		CONSTRAINT FKSUP00678RFPRODMARCA_CDMARCA3 FOREIGN KEY (CDMARCA3) REFERENCES MARCA (CDMARCA),
		CONSTRAINT FKSUP00679RFPRODMARCA_CDMARCA4 FOREIGN KEY (CDMARCA4) REFERENCES MARCA (CDMARCA),
		CONSTRAINT FKSUP00680RFPRODMARCA_CDMARCA5 FOREIGN KEY (CDMARCA5) REFERENCES MARCA (CDMARCA),
		CONSTRAINT CKC_IDATIVO_RFPPRODMARCA CHECK (IDATIVO IN ('S','N'))
)
/
CREATE INDEX SUP00674_FK ON RFPPRODMARCA (NRRFPMAIN ASC)
/

CREATE INDEX SUP00675_FK ON RFPPRODMARCA (CDPRODUTO ASC)
/

CREATE INDEX SUP00676_FK ON RFPPRODMARCA (CDMARCA1 ASC)
/

CREATE INDEX SUP00677_FK ON RFPPRODMARCA (CDMARCA2 ASC)
/

CREATE INDEX SUP00678_FK ON RFPPRODMARCA (CDMARCA3 ASC)
/

CREATE INDEX SUP00679_FK ON RFPPRODMARCA (CDMARCA4 ASC)
/

CREATE INDEX SUP00680_FK ON RFPPRODMARCA (CDMARCA5 ASC)
/


CREATE SEQUENCE SEQ_RFPPRODMARCA_NRRFPPRDMARCA START WITH 1 INCREMENT BY 1
/

CREATE TABLE RFPITEMCOTA (
    NRRFPITEMCOTA     NUMBER         NOT NULL,
    NRRFPMAIN         NUMBER         NOT NULL,
    CDREGIAO          VARCHAR2(03)   NOT NULL,
    CDFORNECED        VARCHAR2(21),
    CDPRODUTO         VARCHAR2(10),
    CDARVPROD         VARCHAR2(20),
    CDMARCA           VARCHAR2(05),
    VRPRECO           NUMBER(10,2),
    CDFILCENTCMP      VARCHAR2(04),
    CDCOMPRADOR       VARCHAR2(12),
    DTVALIDADEFINAL   DATE,
    STATUS            VARCHAR2(13)    NOT NULL,
    MESSAGE           VARCHAR2(99),
    CDFORMPGTO        VARCHAR2(02), 
    IDTPFORPGTFO      VARCHAR2(01),    
    NRPARCPGTOFO      NUMBER(2),      
    NRDIAPGFIXFO      NUMBER(2),      
    IDUTDIAPGTFO      VARCHAR2(01),  
    IDTPFRETFORN      VARCHAR2(01), 
    CDTIPCOB          VARCHAR2(02),
    VRPEDESCFORN      FLOAT(126), 
    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 PK_RFPITEMCOTA PRIMARY KEY (NRRFPITEMCOTA),
		CONSTRAINT FKSUP00680RFPITEMCOTA_NRFPMAIN FOREIGN KEY (NRRFPMAIN) REFERENCES RFPMAIN (NRRFPMAIN),
		CONSTRAINT FKSUP00680RFPITEMCOTA_CDPRODTO FOREIGN KEY (CDPRODUTO) REFERENCES PRODUTO (CDPRODUTO),
		CONSTRAINT FKSUP00680RFPITEMCOTA_CDMARCA FOREIGN KEY (CDMARCA) REFERENCES MARCA (CDMARCA),
		CONSTRAINT CKC_STATUS_RFPITEMCOTA CHECK (STATUS IN ('PENDENTE', 'INCONSISTENTE', 'GERADO')),
		CONSTRAINT CKC_IDATIVO_RFPITEMCOTA CHECK (IDATIVO IN ('S','N'))    
)
/

CREATE INDEX SUP00681_FK ON RFPITEMCOTA (NRRFPMAIN ASC)
/

CREATE INDEX SUP00682_FK ON RFPITEMCOTA (CDPRODUTO ASC)
/

CREATE INDEX SUP00683_FK ON RFPITEMCOTA (CDMARCA ASC)
/

CREATE SEQUENCE SEQ_RFPITEMCOTA_NRRFPITEMCOTA START WITH 1 INCREMENT BY 1
/