CREATE TABLE NFPREVALIDFIS_AUX
(
    CDFILIAL            VARCHAR2(4)     NOT NULL,
    NRLANCTONF          VARCHAR2(10)    NOT NULL,
    CDIMPOSTONFE        VARCHAR2(02)    NOT NULL,
    DTEMISSAONFPRE      DATE            NULL    ,
    DTENTRSAIDNFPRE     DATE            NULL    ,
    IDENTRSAIDNFPRE     VARCHAR2(1)     NULL    ,
    NRNOTAFISCNFPRE     VARCHAR2(20)    NULL    ,
    VRNOTAFISCNFPRE     FLOAT           NULL    ,
    CDFORNECEDNFPRE     VARCHAR2(21)    NULL    ,
    CDCLIENTENFPRE      VARCHAR2(21)    NULL    ,
    CDFILIEMITNFPRE     VARCHAR2(4)     NULL    ,
    CDFILIRECENFPRE     VARCHAR2(4)     NULL    ,
	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 CKC_IDATIVO_NFPREVALIDFIS_AUX CHECK (IDATIVO IN ('S','N')),
		CONSTRAINT PK_NFPREVALIDFIS_AUX PRIMARY KEY (CDFILIAL, NRLANCTONF, CDIMPOSTONFE)
)
/

CREATE INDEX FIS00883_FK ON NFPREVALIDFIS_AUX (CDFILIAL ASC, NRLANCTONF ASC)
/

ALTER TABLE NFPREVALIDFIS_AUX
    ADD CONSTRAINT FKFIS00883NOTAFISC FOREIGN KEY  (CDFILIAL, NRLANCTONF)
       REFERENCES NOTAFISCAL (CDFILIAL, NRLANCTONF)
/

CREATE INDEX FIS00884_FK ON NFPREVALIDFIS_AUX (CDIMPOSTONFE ASC)
/

ALTER TABLE NFPREVALIDFIS_AUX
    ADD CONSTRAINT FKFIS00884MPOSTONFE FOREIGN KEY  (CDIMPOSTONFE)
       REFERENCES IMPOSTONFE (CDIMPOSTONFE)
/

CREATE INDEX FIS00885_FK ON NFPREVALIDFIS_AUX (CDFORNECEDNFPRE ASC)
/

ALTER TABLE NFPREVALIDFIS_AUX
    ADD CONSTRAINT FKFIS00885FORNECED FOREIGN KEY  (CDFORNECEDNFPRE)
       REFERENCES FORNECEDOR (CDFORNECED)
/

CREATE INDEX FIS00886_FK ON NFPREVALIDFIS_AUX (CDCLIENTENFPRE ASC)
/

ALTER TABLE NFPREVALIDFIS_AUX
    ADD CONSTRAINT FKFIS00886CLIENTE FOREIGN KEY  (CDCLIENTENFPRE)
       REFERENCES CLIENTE (CDCLIENTE)
/

CREATE INDEX FIS00887_FK ON NFPREVALIDFIS_AUX (CDFILIEMITNFPRE ASC)
/

ALTER TABLE NFPREVALIDFIS_AUX
    ADD CONSTRAINT FKFIS00887FILIAL FOREIGN KEY  (CDFILIEMITNFPRE)
       REFERENCES FILIAL (CDFILIAL)
/

CREATE INDEX FIS00888_FK ON NFPREVALIDFIS_AUX (CDFILIRECENFPRE ASC)
/

ALTER TABLE NFPREVALIDFIS_AUX
    ADD CONSTRAINT FKFIS00888FILIAL FOREIGN KEY  (CDFILIRECENFPRE)
       REFERENCES FILIAL (CDFILIAL)
/

CREATE TABLE ERRONFPREVALID_AUX
(
    CDFILIAL            VARCHAR2(4)     NOT NULL,
    NRLANCTONF          VARCHAR2(10)    NOT NULL,
	CDIMPOSTONFE        VARCHAR2(02)    NOT NULL,
    NRSEQERRONFPRE      VARCHAR2(3)     NOT NULL,
    DSERRONFPRE         VARCHAR2(300)   NULL    ,
    IDERRONFPRE         VARCHAR2(30)    NULL    ,
    IDERROAVISNFPRE     VARCHAR2(1)     NULL    ,
	DSTIPOVALIDA        VARCHAR2(30)    NULL    ,
	DTVALIDACAO         DATE            NULL    ,
	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 CKC_IDATIVO_ERRONFPREVALID_AUX CHECK (IDATIVO IN ('S','N')),
		CONSTRAINT PK_ERRONFPREVALID_AUX PRIMARY KEY (CDFILIAL, NRLANCTONF, CDIMPOSTONFE, NRSEQERRONFPRE)
)    
/

CREATE INDEX FIS00889_FK ON ERRONFPREVALID_AUX (CDFILIAL ASC, NRLANCTONF ASC)
/

ALTER TABLE ERRONFPREVALID_AUX
    ADD CONSTRAINT FKFIS00889NOTAFISC FOREIGN KEY  (CDFILIAL, NRLANCTONF)
       REFERENCES NOTAFISCAL (CDFILIAL, NRLANCTONF)
/

CREATE INDEX FIS00890_FK ON ERRONFPREVALID_AUX (CDIMPOSTONFE ASC)
/

ALTER TABLE ERRONFPREVALID_AUX
    ADD CONSTRAINT FKFIS00890IMPOSTONFE FOREIGN KEY  (CDIMPOSTONFE)
       REFERENCES IMPOSTONFE (CDIMPOSTONFE)
/