CREATE TABLE CTRLTRCKIDACS
(
	NRCTRLTRCKIDACS		NUMBER,
	DSTRACKINGID		VARCHAR2(50),
	DSTPDOCUMENTO		VARCHAR2(100),
	DSNMEMPRESAORIG		VARCHAR2(100),
	NMARQUIVORET		VARCHAR2(200),
	IDRETIRADO		VARCHAR2(1)	DEFAULT 'N' 	NOT NULL,
		CONSTRAINT CKC_CTRLTRCKIDACS_IDRET CHECK (IDRETIRADO IN ('N', 'S')),
	DTRETIRADA		DATE,
	DTDISPONIVEL		DATE,
	NRORG 	       		NUMBER DEFAULT 	SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO			VARCHAR2(1)	DEFAULT 'S' 	NOT NULL,
		CONSTRAINT CKC_IDATIVO_CTRLTRCKIDACS 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_CTRLTRCKIDACS PRIMARY KEY (NRCTRLTRCKIDACS)
)
/

ALTER TABLE CTRLTRCKIDACS ADD CONSTRAINT UN_DSTRACKINGID_CTRLTRCKIDACS UNIQUE (DSTRACKINGID)
/
CREATE TABLE HEADERACSTAGE
(
	NRHEADERACSTAGE		NUMBER,
	DSOPERADORA		VARCHAR2(50),
	DSTPREGACSTAGE		VARCHAR2(50),
	DSTPREG			VARCHAR2(50),
	DSDTEMISSAO		VARCHAR2(50),
	DSTPEXTRATO		VARCHAR2(50),
	DSNMCOMERCIAL		VARCHAR2(50),
	DSSEQMOVIMENTO		VARCHAR2(50),
	DSNRPVMATRIZ		VARCHAR2(50),
	DSTPMOVIMENTO		VARCHAR2(50),
	DSVERSAOARQUIVO		VARCHAR2(50),
	NRORG 	       		NUMBER 		DEFAULT 	SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO			VARCHAR2(1)	DEFAULT 'S' 	NOT NULL,
		CONSTRAINT CKC_IDATIVO_HEADERACSTAGE 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_HEADERACSTAGE PRIMARY KEY (NRHEADERACSTAGE)
)
/
CREATE TABLE CONTMSGACSTAGE
(
   	NRCONTMSGACSTAGE 	NUMBER 		NOT NULL,
   	NRHEADERACSTAGE 	NUMBER 		NOT NULL,
   	DSTRACKINGID 		VARCHAR2(50),
   	DSTPREGACSTAGE 		VARCHAR2(50), /* 1 */
   	DSTPREGADQ 		VARCHAR2(50),
   	DSNRPVMATRIZ 		VARCHAR2(50),
   	DSNMCOMMATRIZ 		VARCHAR2(50),
   	DSNRPV 			VARCHAR2(50),
   	DSNRRV 			VARCHAR2(50),
   	DSNRBANCO 		VARCHAR2(50),
   	DSNRAGENCIA 		VARCHAR2(50),
   	DSNRCONTCORR 		VARCHAR2(50),
   	DSDTRESVENDA 		VARCHAR2(50), /* 10 */
   	DSQTCVNSU 		VARCHAR2(50),
   	DSVRBRUT		VARCHAR2(50),
   	DSVRGORJETA 		VARCHAR2(50),
   	DSVRREJEITADO 		VARCHAR2(50),
   	DSVRLIQUIDO 		VARCHAR2(50),
   	DSVRDESCONTO 		VARCHAR2(50),
   	DSBANDPROD 		VARCHAR2(50),
   	DSDTCREDITO 		VARCHAR2(50),
   	DSBANDEIRA 		VARCHAR2(50),
   	DSVRCVNSU 		VARCHAR2(50), /* 20 */
  	DSNRCARTAO 		VARCHAR2(50),
   	DSSTATUSCVNSU 		VARCHAR2(50),
   	DSCVNSU 		VARCHAR2(50),
   	DSNRREFERENCIA		VARCHAR2(50),
   	DSNRAUTORIZACAO 	VARCHAR2(50),
   	DSHORATRANS 		VARCHAR2(50),
   	DSTIPOCAPTURA 		VARCHAR2(50),
   	DSNRTERMINAL 		VARCHAR2(50),
   	DSDTCREDPRIMPAR 	VARCHAR2(50),
   	DSDTCVNSU 		VARCHAR2(50), /* 30 */
   	DSNRPARCELA 		VARCHAR2(50),
   	DSVRLIQCVNSU 		VARCHAR2(50),
   	DSVRLIQPRIMPAR 		VARCHAR2(50),
   	DSVRLIQOUTRPAR 		VARCHAR2(50),
   	DSVRPARCELA 		VARCHAR2(50),
   	DSVRDESCPARCELA		VARCHAR2(50),
   	DSVRPARCELALIQ 		VARCHAR2(50),
   	DSQTCVNSUREJEIT 	VARCHAR2(50),
   	DSVRTOTROTATIVO 	VARCHAR2(50), /* 40 */
   	DSVRTOTPARCSJURO 	VARCHAR2(50),
   	DSVRTOTDOLAR 		VARCHAR2(50),
   	DSTPRESUMO 		VARCHAR2(50),
   	DSQTRESUVENDAAC 	VARCHAR2(50),
   	DSVRBRUTPREDAT 		VARCHAR2(50),
   	DSVRDESCPREDAT 		VARCHAR2(50),
   	DSVRLIQPREDAT 		VARCHAR2(50),
   	DSTPTRANS 		VARCHAR2(50),
   	DSSTATUSTRANS 		VARCHAR2(50),
   	DSVRCOMPRA 		VARCHAR2(50), /* 50 */
   	DSVRSAQUE 		VARCHAR2(50),
   	DSFORMACAPT		VARCHAR2(50),
   	DSDTPAGRV 		VARCHAR2(50),
   	DSVRCOMIS 		VARCHAR2(50),
   	DSVRCREDITO 		VARCHAR2(50),
   	DSINDTPPAGTO		VARCHAR2(50),
   	DSCNPJESTAB 		VARCHAR2(50),
   	DSDTTRANS 		VARCHAR2(50),
   	DSVRTRANS 		VARCHAR2(50),
   	DSNRPARCPAGA 		VARCHAR2(50), /* 60 */
   	DSVRPARCPAGA 		VARCHAR2(50),
   	DSDTPAGTO 		VARCHAR2(50),
   	DSREDECAPORIG 		VARCHAR2(50),
   	DSCODAFILIACAO 		VARCHAR2(50),
   	DSESTABSUB 		VARCHAR2(50),
  	 DSDTAPRES 		VARCHAR2(50),
   	DSDTPREVPGTO 		VARCHAR2(50),
   	DSDTENVBANCO 		VARCHAR2(50),
   	DSSINALVRBRUTO 		VARCHAR2(50),
   	DSSINALTXADM 		VARCHAR2(50), /* 70 */
   	DSSINALVRREJ 		VARCHAR2(50),
   	DSSINALVRLIQ 		VARCHAR2(50),
   	DSSTATUSPGTO 		VARCHAR2(50),
   	DSIDENREVACEL 		VARCHAR2(50),
  	DSORIGAJUSTE 		VARCHAR2(50),
   	DSVRCOMPLEMT 		VARCHAR2(50),
   	DSIDENTANT 		VARCHAR2(50),
   	DSNROPANT 		VARCHAR2(50),
   	DSSINALVRBRUTANT 	VARCHAR2(50),
   	DSVRBRUTANT 		VARCHAR2(50), /* 80 */
   	DSNRUNICORO 		VARCHAR2(50),
   	DSTXADMIN 		VARCHAR2(50),
   	DSTARADMIN 		VARCHAR2(50),
   	DSTXGARANTIA 		VARCHAR2(50),
  	DSNRLOGTERM 		VARCHAR2(50),
  	DSMATRIZPGTO		VARCHAR2(50),
   	DSREENVIOPGTO 		VARCHAR2(50),
   	DSCONCAPLICADO 		VARCHAR2(50),
   	DSPLANO 		VARCHAR2(50),
   	DSDTVENDAAJUSTE 	VARCHAR2(50), /* 90 */
   	DSSINALCOMPPARC 	VARCHAR2(50),
  	DSPARCELA 		VARCHAR2(50),
   	DSMOTREJEICAO 		VARCHAR2(50),
   	DSTID 			VARCHAR2(50),
   	DSDIGCARTAO 		VARCHAR2(50),
   	DSVRTOTVENDA 		VARCHAR2(50),
  	DSVRPROXPARC 		VARCHAR2(50),
   	DSNRNOTAFISCAL 		VARCHAR2(50),
   	DSINDCARTEMIEXT 	VARCHAR2(50),
   	DSNRLOGTERMINAL 	VARCHAR2(50), /* 100 */
   	DSREFCODPED 		VARCHAR2(50),
   	DSNRUNICOTRANS 		VARCHAR2(50),
   	DSINDCIELOPROMO 	VARCHAR2(50),
   	DSMODENTRCART 		VARCHAR2(50),
   	DSCODVENDA 		VARCHAR2(50),
   	DSCODINTAJUSTE 		VARCHAR2(50),
   	NRORG 	       		NUMBER 		DEFAULT 	SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO			VARCHAR2(1)	DEFAULT 'S' 	NOT NULL,
		CONSTRAINT CKC_IDATIVO_CONTMSGACSTAGE 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_CONTMSGACSTAGE PRIMARY KEY (NRCONTMSGACSTAGE)
)
/
   
ALTER TABLE CONTMSGACSTAGE ADD 
		CONSTRAINT FKVND00731CONTMSGACST_HEADER FOREIGN KEY (NRHEADERACSTAGE)
   				REFERENCES HEADERACSTAGE (NRHEADERACSTAGE)
/

ALTER TABLE RETORIGVENDA ADD NRHEADERACSTAGE NUMBER
/

ALTER TABLE RETORIGVENDA ADD 
		CONSTRAINT FKVND00732RETORIGVENDA_HEADE FOREIGN KEY (NRHEADERACSTAGE)
   			REFERENCES HEADERACSTAGE (NRHEADERACSTAGE)
/

ALTER TABLE RETORIGVENDA MODIFY NRCTRLACESWS NULL
/

ALTER TABLE RETORIGFINANC ADD NRHEADERACSTAGE NUMBER
/

ALTER TABLE RETORIGFINANC ADD 
		CONSTRAINT FKVND00733RETORIGFIN_HEADERA FOREIGN KEY (NRHEADERACSTAGE)
   			REFERENCES HEADERACSTAGE (NRHEADERACSTAGE)
/

ALTER TABLE RETORIGFINANC MODIFY NRCTRLACESWS NULL
/