CREATE TABLE PRODUTOCARDTRAB (
	NRPRODUTOCARDTRAB		NUMBER 														NOT NULL,
    NRCARDAPIOTRAB 			NUMBER														NOT NULL,
    CDPRODUTO				VARCHAR2(10)												NOT NULL,
	CDMARCA 				VARCHAR2(5)													NOT NULL,
    VRCUSTO 				FLOAT														NOT NULL,
	NRORG 					NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_PRODUTOCARDTRAB CHECK (IDATIVO IN ('S', 'N')),
	DTINCLUSAO 				DATE 														NULL,
	DTULTATU 				DATE 														NULL,
	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' 								NULL,
	CONSTRAINT PK_PRODUTOCARDTRAB PRIMARY KEY (NRPRODUTOCARDTRAB),
	CONSTRAINT UN_PRODUTOCARDTRAB UNIQUE (NRCARDAPIOTRAB, CDPRODUTO)
)
/
ALTER TABLE PRODUTOCARDTRAB ADD
	CONSTRAINT FKPLA01089CARDAPIOTRAB FOREIGN KEY (NRCARDAPIOTRAB)
		REFERENCES CARDAPIOTRAB (NRCARDAPIOTRAB)
/
CREATE INDEX FKPLA01089CARDAPIOTRAB ON PRODUTOCARDTRAB (NRCARDAPIOTRAB)
/
ALTER TABLE PRODUTOCARDTRAB ADD
	CONSTRAINT FKPLA01090PRODUTO FOREIGN KEY (CDPRODUTO)
		REFERENCES PRODUTO (CDPRODUTO)
/
CREATE INDEX FKPLA01090PRODUTO ON PRODUTOCARDTRAB (CDPRODUTO)
/
CREATE TABLE RECEPRATCARDTRAB (
	NRRECEPRATCARDTRAB		NUMBER 														NOT NULL,
    NRCARDAPIOTRAB 			NUMBER														NOT NULL,
    CDFILAUXPRAT 			VARCHAR2(4)													NOT NULL,
	CDPRATO					VARCHAR2(10)												NOT NULL,
    CDPRODUTO				VARCHAR2(10)												NOT NULL,
	QTPRODRECCARDTRAB 		FLOAT														NOT NULL,
    VRPEFATCOCCARDTRAB 		FLOAT														NOT NULL,
	VRPEFATCORCARDTRAB 		FLOAT														NOT NULL,
	SGUNIDADE				VARCHAR2(10)												NOT NULL,
	QTBRUTACARDTRABUNR 		FLOAT														NOT NULL,
	IDPRODBASECARDTRAB		VARCHAR2(1)		DEFAULT 'N'									NOT NULL
		CONSTRAINT CKC_IDPRODBASECARDTRAB_RECCART CHECK (IDPRODBASECARDTRAB IN ('S', 'N')),
	IDQTDEFIXCARDTRAB		VARCHAR2(1)		DEFAULT 'N'									NOT NULL
		CONSTRAINT CKC_IDQTDEFIXCARDTRAB_RECCART CHECK (IDQTDEFIXCARDTRAB IN ('S', 'N')),
	NRORG 					NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_RECEPRATCARDTRAB CHECK (IDATIVO IN ('S', 'N')),
	DTINCLUSAO 				DATE 														NULL,
	DTULTATU 				DATE 														NULL,
	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' 								NULL,
	CONSTRAINT PK_RECEPRATCARDTRAB PRIMARY KEY (NRRECEPRATCARDTRAB),
	CONSTRAINT UN_RECEPRATCARDTRAB UNIQUE (NRCARDAPIOTRAB, CDFILAUXPRAT, CDPRATO, CDPRODUTO)
)
/
ALTER TABLE RECEPRATCARDTRAB ADD
	CONSTRAINT FKPLA01091CARDAPIOTRAB FOREIGN KEY (NRCARDAPIOTRAB)
		REFERENCES CARDAPIOTRAB (NRCARDAPIOTRAB)
/
CREATE INDEX FKPLA01091CARDAPIOTRAB ON RECEPRATCARDTRAB (NRCARDAPIOTRAB)
/
ALTER TABLE RECEPRATCARDTRAB ADD
	CONSTRAINT FKPLA01092PRODUTO FOREIGN KEY (CDPRODUTO)
		REFERENCES PRODUTO (CDPRODUTO)
/
CREATE INDEX FKPLA01092PRODUTO ON RECEPRATCARDTRAB (CDPRODUTO)
/
ALTER TABLE RECEPRATCARDTRAB ADD
	CONSTRAINT FKPLA01093UNIDMEDIDA FOREIGN KEY (SGUNIDADE)
		REFERENCES UNIDMEDIDA (SGUNIDADE)
/
CREATE INDEX FKPLA01093UNIDMEDIDA ON RECEPRATCARDTRAB (SGUNIDADE)
/
ALTER TABLE RECEPRATCARDTRAB ADD
	CONSTRAINT FKPLA01094PRATO FOREIGN KEY (CDFILAUXPRAT, CDPRATO)
		REFERENCES PRATO (CDFILAUXPRAT, CDPRATO)
/
CREATE INDEX FKPLA01094PRATO ON RECEPRATCARDTRAB (CDFILAUXPRAT, CDPRATO)
/
CREATE TABLE PROPOSTACOMERCIAL (
	NRPROPOSTACOMERCIAL		NUMBER 														NOT NULL,
    CDPROPOSTACOMERCIAL 	VARCHAR2(10)												NOT NULL,
    NRGERENTENEGOCIO 		NUMBER														NOT NULL,
	DTLANCAMENTO			DATE														NOT NULL,
	CDCLIENTE				VARCHAR2(21)												NULL,
	CDPROSPECT				VARCHAR2(21)												NULL,
	IDRETENCAO				VARCHAR2(1)		DEFAULT 'N'									NOT NULL
		CONSTRAINT CKC_IDRETENCAO CHECK (IDRETENCAO IN ('S', 'N')),
	CDATIVCLI				VARCHAR2(10)												NOT NULL,
	CDSEGMER 				VARCHAR2(5)													NOT NULL,
	NRTIPOCONTRATO			NUMBER														NOT NULL,
	IDEDITAL				VARCHAR2(1)		DEFAULT 'N'									NOT NULL
		CONSTRAINT CKC_IDEDITAL CHECK (IDEDITAL IN ('S', 'N')),
	IDSUGERIDO				VARCHAR2(1)		DEFAULT 'N'									NOT NULL
		CONSTRAINT CKC_IDSUGERIDO CHECK (IDSUGERIDO IN ('S', 'N')),
	CDPAIS					VARCHAR2(5)													NOT NULL,
	SGESTADO				VARCHAR2(2)													NOT NULL,
	CDMUNICIPIO				VARCHAR2(4)													NOT NULL,
	DSENDERECO				VARCHAR2(4000)												NOT NULL,
	DTINIVIGENCIA			DATE														NOT NULL,
	DTFIMVIGENCIA			DATE														NULL,
	NRORG 					NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_PROPOSTACOMERCIAL CHECK (IDATIVO IN ('S', 'N')),
	DTINCLUSAO 				DATE 														NULL,
	DTULTATU 				DATE 														NULL,
	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' 								NULL,
	CONSTRAINT PK_PROPOSTACOMERCIAL PRIMARY KEY (NRPROPOSTACOMERCIAL),
	CONSTRAINT UN_PROPOSTACOMERCIAL UNIQUE (CDPROPOSTACOMERCIAL)
)
/
ALTER TABLE PROPOSTACOMERCIAL ADD
	CONSTRAINT FKPLA01096GERENTENEGOCIO FOREIGN KEY (NRGERENTENEGOCIO)
		REFERENCES GERENTENEGOCIO (NRGERENTENEGOCIO)
/
CREATE INDEX FKPLA01096GERENTENEGOCIO ON PROPOSTACOMERCIAL (NRGERENTENEGOCIO)
/
ALTER TABLE PROPOSTACOMERCIAL ADD
	CONSTRAINT FKPLA01097ATIVCLIENTE FOREIGN KEY (CDATIVCLI)
		REFERENCES ATIVCLIENTE (CDATIVCLI)
/
CREATE INDEX FKPLA01097ATIVCLIENTE ON PROPOSTACOMERCIAL (CDATIVCLI)
/
ALTER TABLE PROPOSTACOMERCIAL ADD
	CONSTRAINT FKPLA01098SEGMERCADO FOREIGN KEY (CDSEGMER)
		REFERENCES SEGMERCADO (CDSEGMER)
/
CREATE INDEX FKPLA01098SEGMERCADO ON PROPOSTACOMERCIAL (CDSEGMER)
/
ALTER TABLE PROPOSTACOMERCIAL ADD
	CONSTRAINT FKPLA01099TIPOCONTRATO FOREIGN KEY (NRTIPOCONTRATO)
		REFERENCES TIPOCONTRATO (NRTIPOCONTRATO)
/
CREATE INDEX FKPLA01099TIPOCONTRATO ON PROPOSTACOMERCIAL (NRTIPOCONTRATO)
/
CREATE TABLE DOCUMENTOPROPCOM (
	NRDOCUMENTOPROPCOM		NUMBER 														NOT NULL,
    NRPROPOSTACOMERCIAL 	NUMBER														NOT NULL,
    NMDOCUMENTOPROPCOM 		VARCHAR2(50)												NOT NULL,
	DSCAMINHOFILESERVER		VARCHAR2(4000)												NOT NULL,
	NRORG 					NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
	IDATIVO 				VARCHAR2(1) 	DEFAULT 'S' 								NOT NULL
		CONSTRAINT CKC_IDATIVO_DOCUMENTOPROPCOM CHECK (IDATIVO IN ('S', 'N')),
	DTINCLUSAO 				DATE 														NULL,
	DTULTATU 				DATE 														NULL,
	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' 								NULL,
	CONSTRAINT PK_DOCUMENTOPROPCOM PRIMARY KEY (NRDOCUMENTOPROPCOM)
)
/
ALTER TABLE DOCUMENTOPROPCOM ADD
	CONSTRAINT FKPLA01100PROPOSTACOMERCIAL FOREIGN KEY (NRPROPOSTACOMERCIAL)
		REFERENCES PROPOSTACOMERCIAL (NRPROPOSTACOMERCIAL)
/
CREATE INDEX FKPLA01100PROPOSTACOMERCIAL ON DOCUMENTOPROPCOM (NRPROPOSTACOMERCIAL)