ALTER TABLE CONFIGSERVPROPCOM MODIFY IDTEMPERATURA VARCHAR2(30) NULL
/
CREATE TABLE LISTAPRECOTCO
(
   NRLISTAPRECOTCO 	NUMBER 		NOT NULL,
   DTREFERENCIA 	DATE 		NOT NULL,
   CDREGIAO 		VARCHAR2(5) 	NOT NULL,
   CDFILIAL 		VARCHAR2(4) 	NOT NULL,
   IDTIPOAPUR 		VARCHAR2(1) 	    NULL,   
   NRORG 		NUMBER		DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
   IDATIVO 		VARCHAR2(1) 	DEFAULT 'S'   NOT NULL
	CONSTRAINT CKC_IDATIVO_LISTAPRECOTCO CHECK (IDATIVO IN ('S', 'N')),
   DTINCLUSAO 		DATE 			      NULL,
   DTULTATU 		DATE 			      NULL,
   NRORGINCLUSAO 	NUMBER          DEFAULT 1     NULL,
   CDOPERINCLUSAO 	VARCHAR2(12) 	DEFAULT '1'   NULL,
   NRORGULTATU 		NUMBER          DEFAULT 1     NULL,
   CDOPERULTATU 	VARCHAR2(12) 	DEFAULT '1'   NULL,
   	CONSTRAINT PK_LISTAPRECOTCO PRIMARY KEY (NRLISTAPRECOTCO)
)
/
ALTER TABLE LISTAPRECOTCO ADD
	CONSTRAINT FKPLA01165REGIAO FOREIGN KEY (CDREGIAO)
		REFERENCES REGIAO (CDREGIAO)
/
CREATE INDEX FKPLA01165REGIAO ON LISTAPRECOTCO (CDREGIAO)
/
ALTER TABLE LISTAPRECOTCO ADD
	CONSTRAINT FKPLA01166FILIAL FOREIGN KEY (CDFILIAL)
		REFERENCES FILIAL (CDFILIAL)
/
CREATE INDEX FKPLA01166FILIAL ON LISTAPRECOTCO (CDFILIAL)
/
CREATE INDEX IDXLISTAPRECOTCO01 ON LISTAPRECOTCO (DTREFERENCIA, CDREGIAO)
/
CREATE TABLE PRODLISTAPRECOTCO
(
   NRPRODLISTAPRECOTCO 		NUMBER 		NOT NULL,
   NRLISTAPRECOTCO 		NUMBER 		NOT NULL,	
   IDESCOLHIDO 			VARCHAR2(1) 	DEFAULT 'N' NOT NULL
   	CONSTRAINT CKC_IDESCOLHIDO_PRODLISTAPRECO CHECK (IDESCOLHIDO IN ('S', 'N')),
   CDPRODESTO 			VARCHAR2(10) 	NOT NULL,
   VRCUSTO 			FLOAT 		NOT NULL,
   CDFILIAL 			VARCHAR2(4) 	NOT NULL,
   NRCOLEPRECO 			VARCHAR2(10) 	    NULL,
   CDMARCA 			VARCHAR2(5) 	NOT NULL,
   CDREGIAO 			VARCHAR2(3) 	NOT NULL,
   CDFORNECED 			VARCHAR2(21) 	NOT NULL,
   CDPRODUTO 			VARCHAR2(10) 	NOT NULL,   
   DTINIVALITM 			DATE 		NOT NULL,
   DTFINVALITM 			DATE 		NOT NULL,
   VRPRECUNIITM 		FLOAT 		NOT NULL,
   VRPRECOITMPI 		FLOAT 		    NULL,
   VRPRECECOITM 		FLOAT 		    NULL,
   VRFATOCONV 			FLOAT 		    NULL,
   IDFORNECEDOROL 		VARCHAR2(5) 	DEFAULT 'N'   NOT NULL
   	CONSTRAINT CKC_IDFORNECEDOROL_PRODLISTPR CHECK (IDFORNECEDOROL IN ('S', 'N')),
   IDCUSTOPELAMEDIA 		VARCHAR2(5) 	DEFAULT 'N'   NOT NULL
   	CONSTRAINT CKC_IDCUSTPELAMEDIA_PRODLIST CHECK (IDCUSTOPELAMEDIA IN ('S', 'N')),
   IDFORNEPRIOTCO 		VARCHAR2(5) 	DEFAULT 'N'   NOT NULL
   	CONSTRAINT CKC_IDFORNEPRIOTCO_PRODLISTPR CHECK (IDFORNEPRIOTCO IN ('S', 'N')),
   NRORG 			NUMBER			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 	NOT NULL,
   IDATIVO 			VARCHAR2(1) 	DEFAULT 'S'   NOT NULL
  	CONSTRAINT CKC_IDATIVO_PRODLISTPRECOTCO CHECK (IDATIVO IN ('S', 'N')),
   DTINCLUSAO 			DATE 			      NULL,
   DTULTATU 			DATE 			      NULL,
   NRORGINCLUSAO 		NUMBER          DEFAULT 1     NULL,
   CDOPERINCLUSAO 		VARCHAR2(12) 	DEFAULT '1'   NULL,
   NRORGULTATU 			NUMBER          DEFAULT 1     NULL,
   CDOPERULTATU 		VARCHAR2(12) 	DEFAULT '1'   NULL,
	CONSTRAINT PK_PRODLISTAPRECOTCO PRIMARY KEY (NRPRODLISTAPRECOTCO)
)
/
ALTER TABLE PRODLISTAPRECOTCO ADD
	CONSTRAINT FKPLA01167LISTAPRECOTCO FOREIGN KEY (NRLISTAPRECOTCO)
		REFERENCES LISTAPRECOTCO (NRLISTAPRECOTCO)
		ON DELETE CASCADE
/
CREATE INDEX FKPLA01167LISTAPRECOTCO ON PRODLISTAPRECOTCO (NRLISTAPRECOTCO)
/
ALTER TABLE PRODLISTAPRECOTCO ADD
	CONSTRAINT FKPLA01168PRODESTO FOREIGN KEY (CDPRODESTO)
		REFERENCES PRODUTO (CDPRODUTO)
/
CREATE INDEX FKPLA01168PRODESTO ON PRODLISTAPRECOTCO (CDPRODESTO)
/
ALTER TABLE PRODLISTAPRECOTCO ADD
	CONSTRAINT FKPLA01169FILIAL FOREIGN KEY (CDFILIAL)
		REFERENCES FILIAL (CDFILIAL)
/
CREATE INDEX FKPLA01169FILIAL ON PRODLISTAPRECOTCO (CDFILIAL)
/
ALTER TABLE PRODLISTAPRECOTCO ADD
	CONSTRAINT FKPLA01170MARCA FOREIGN KEY (CDMARCA)
		REFERENCES MARCA (CDMARCA)
/
CREATE INDEX FKPLA01170MARCA ON PRODLISTAPRECOTCO (CDMARCA)
/
ALTER TABLE PRODLISTAPRECOTCO ADD
	CONSTRAINT FKPLA01171REGIAO FOREIGN KEY (CDREGIAO)
		REFERENCES REGIAO (CDREGIAO)
/
CREATE INDEX FKPLA01171REGIAO ON PRODLISTAPRECOTCO (CDREGIAO)
/
ALTER TABLE PRODLISTAPRECOTCO ADD
	CONSTRAINT FKPLA01172FORNECEDOR FOREIGN KEY (CDFORNECED)
		REFERENCES FORNECEDOR (CDFORNECED)
/
CREATE INDEX FKPLA01172FORNECEDOR ON PRODLISTAPRECOTCO (CDFORNECED)
/
ALTER TABLE PRODLISTAPRECOTCO ADD
	CONSTRAINT FKPLA01173PRODUTO FOREIGN KEY (CDPRODUTO)
		REFERENCES PRODUTO (CDPRODUTO)
/
CREATE INDEX FKPLA01173PRODUTO ON PRODLISTAPRECOTCO (CDPRODUTO)
/
CREATE INDEX IDXPRODLISTAPRECOTCO01 ON PRODLISTAPRECOTCO (NRLISTAPRECOTCO, IDESCOLHIDO)
/
CREATE INDEX IDXPRODLISTAPRECOTCO02 ON PRODLISTAPRECOTCO (NRLISTAPRECOTCO, CDPRODESTO)
/
ALTER TABLE CARDAPIOTRAB ADD NRLISTAPRECOTCO NUMBER NULL
/
ALTER TABLE CARDAPIOTRAB ADD
	CONSTRAINT FKPLA01174LISTAPRECOTCO FOREIGN KEY (NRLISTAPRECOTCO)
		REFERENCES LISTAPRECOTCO (NRLISTAPRECOTCO)
		ON DELETE CASCADE
/
CREATE INDEX FKPLA01174LISTAPRECOTCO ON CARDAPIOTRAB (NRLISTAPRECOTCO)
/
ALTER TABLE PRODUTOCARDTRAB ADD NRPRODLISTAPRECOTCO NUMBER NULL
/
ALTER TABLE HISTNOTIFPROPCOM ADD NRDETALHESERVPROPCOM NUMBER NULL
/

ALTER TABLE HISTNOTIFPROPCOM ADD
	CONSTRAINT FKPLA01175DETALHESERVPROPCOM FOREIGN KEY (NRDETALHESERVPROPCOM)
		REFERENCES DETALHESERVPROPCOM (NRDETALHESERVPROPCOM)
/
CREATE INDEX FKPLA01175DETALHESERVPROPCOM ON HISTNOTIFPROPCOM (NRDETALHESERVPROPCOM)
/
ALTER TABLE HISTNOTIFPROPCOM MODIFY TXHISTORICO NULL