CREATE TABLE ATUCUSTPROD
(
   CDFILIAL            		VARCHAR2(4)         		NOT NULL,
   CDCONTCTBL          	VARCHAR2(20)       		NOT NULL,
   DSATUCUSTPROD       	VARCHAR2(50)        	NOT NULL,
   NRORG                       	NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO                    	VARCHAR2(1)     		DEFAULT 'S' NOT NULL
	CONSTRAINT CKC_IDATIVO_ATUCUSTPROD 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',
	CONSTRAINT PK_ATUCUSTPROD PRIMARY KEY (CDFILIAL, CDCONTCTBL)
)
/
CREATE INDEX FIS00750_FK ON ATUCUSTPROD (CDFILIAL ASC)
/
ALTER TABLE ATUCUSTPROD
	ADD CONSTRAINT FKFIS00750FILIAL FOREIGN KEY (CDFILIAL) 
		REFERENCES FILIAL (CDFILIAL)
/
CREATE INDEX FIS00751_FK ON ATUCUSTPROD (CDCONTCTBL ASC)
/
ALTER TABLE ATUCUSTPROD
	ADD CONSTRAINT FKFIS00751CONTCTBL FOREIGN KEY (CDCONTCTBL) 
		REFERENCES CONTCTBL (CDCONTCTBL)
/
CREATE TABLE CUSTOABSORCAOPR
(
   CDFILIAL            		VARCHAR2(4)         		NOT NULL,
   DTCUSTOABSORCAO     	DATE                		NOT NULL,
   VRTOTRATEADO             	FLOAT  			NOT NULL,
   CDPRODUTO           	VARCHAR2(10)        	NOT NULL,
   QTPRODUZIDA         	FLOAT 			NOT NULL,
   QTHSPRODUZIDOPR            FLOAT 			NOT NULL,
   VRCUSTOABSORCAO     	FLOAT               		NOT NULL,
   NRORG                       	NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO                    	VARCHAR2(1)     		DEFAULT 'S' NOT NULL
	CONSTRAINT CKC_IDATIVO_CUSTOABSORCAOPR 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',
	CONSTRAINT PK_CUSTOABSORCAOPR PRIMARY KEY (CDFILIAL, DTCUSTOABSORCAO, CDPRODUTO)
)
/
CREATE INDEX FIS00752_FK ON CUSTOABSORCAOPR (CDFILIAL ASC)
/
ALTER TABLE CUSTOABSORCAOPR
	ADD CONSTRAINT FKFIS00752FILIAL FOREIGN KEY (CDFILIAL) 
		REFERENCES FILIAL (CDFILIAL)
/
CREATE INDEX FIS00753_FK ON CUSTOABSORCAOPR (CDPRODUTO ASC)
/
ALTER TABLE CUSTOABSORCAOPR
	ADD CONSTRAINT FKFIS00753PRODUTO FOREIGN KEY (CDPRODUTO) 
		REFERENCES PRODUTO (CDPRODUTO) 