ALTER TABLE TURCAIXA ADD IDINTEGFECHAGPS VARCHAR2(1) NULL
   CONSTRAINT CKC_IDINTEGFECHAGPS_TURCAIXA CHECK (IDINTEGFECHAGPS IN ('S','N'))
/

ALTER TABLE VENDA ADD IDINTEGVENDAGPS VARCHAR2(1) NULL
   CONSTRAINT CKC_IDINTEGVENDAGPS_VENDA CHECK (IDINTEGVENDAGPS IN ('S','N'))
/

CREATE TABLE FECHAMENTODIA_INT (
   NRINSJURFILI      VARCHAR2(14)   NOT NULL,
   CDFILIAL          VARCHAR2(4)    NOT NULL,
   CDLOJA            VARCHAR2(10)   NOT NULL,
   NRECFREDZ         VARCHAR2(10)   NULL,
   CDCAIXA           VARCHAR2(3)    NOT NULL,
   DTMOVIMCAIXA      DATE           NOT NULL,
   VRMOVIVEND        FLOAT          NOT NULL,
   CDTIPORECE        VARCHAR2(3)    NOT NULL,
   NMTIPORECE        VARCHAR2(40)   NOT NULL,
   IDTIPORECE        VARCHAR2(1)    NOT NULL,
   ORIGEM            VARCHAR2(1)    NULL,
   IDINTERFACE       NUMBER         NOT NULL,
   TPINTERFACE       VARCHAR2(1)    NOT NULL
		CONSTRAINT CKC_TPINTERFACE_FECHADIA_INT CHECK (TPINTERFACE IN ('I','A','E')),
   DTINTERFACEORI    DATE           NOT NULL,
   DTINTERFACEDEST   DATE           NULL,
   STATUS            NUMBER         NOT NULL
		CONSTRAINT CKC_STATUS_FECHADIA_INT CHECK (STATUS IN (0,1,2,3)),
   APPORIGEM         NUMBER         NOT NULL
		CONSTRAINT CKC_APPORIGEM_FECHADIA_INT CHECK (APPORIGEM IN (1,2)),
   APPDESTINO        NUMBER         NOT NULL
		CONSTRAINT CKC_APPDESTINO_FECHADIA_INT CHECK (APPDESTINO IN (1,2)),
   TMPSTATUS         VARCHAR2(20)   NULL,
   DTTMPIDA          DATE           NULL,
   DTTMPVOLTA        DATE           NULL,
   OBSLOG            VARCHAR2(500)  NULL,
   LOTETMP           VARCHAR2(50)   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_FECHAMENTODIA_INT CHECK (IDATIVO IN ('S','N')),
		CONSTRAINT PK_FECHAMENTODIA_INT PRIMARY KEY (CDFILIAL, CDCAIXA, DTMOVIMCAIXA, CDTIPORECE)
)
/

CREATE TABLE CUPOM_INT (
   CHAVESEQUNIC      VARCHAR2(20)   NOT NULL,
   NRINSJURFILI      VARCHAR2(14)   NOT NULL,
   CDFILIAL          VARCHAR2(4)    NOT NULL,
   CDLOJA            VARCHAR2(10)   NOT NULL,
   NRECFREDZ         VARCHAR2(10)   NULL,
   CDCAIXA           VARCHAR2(3)    NOT NULL,
   DTENTRVENDA       DATE           NOT NULL,
   DTEMISSAO         DATE           NOT NULL,
   NRCUPOMFIS        VARCHAR2(10)   NULL,
   CDSERIESAT        VARCHAR2(10)   NULL,
   CDSERIENFCE       VARCHAR2(10)   NULL,
   NRNOTAFISCALCE    VARCHAR2(9)    NULL,
   NRACESSONFCE      VARCHAR2(50)   NULL,
   MOD               VARCHAR2(2)    NULL,
   NRPROTOCOLONFCE   VARCHAR2(20)   NULL,
   NRACESSOCANC      VARCHAR2(50)   NULL,
   VRTOTCUPOM        FLOAT          NOT NULL,
   VRTOTDESC         FLOAT          NOT NULL,
   VRTOTACRE         FLOAT          NOT NULL,
   VRTOTGORJETA      FLOAT          NULL,
   ICMSSOBREGORJETA  VARCHAR2(1)    NULL,
   NRINSCRCONS       VARCHAR2(20)   NULL,
   NMCONSVEND        VARCHAR2(50)   NULL,
   IDSTATUSNFCE      VARCHAR2(1)    NULL,
   IDSITUVENDA       VARCHAR2(1)    NOT NULL,
   ORIGEM            VARCHAR2(1)    NULL,
   IDINTERFACE       NUMBER         NOT NULL,
   TPINTERFACE       VARCHAR2(1)    NOT NULL
		CONSTRAINT CKC_TPINTERFACE_CUPOM_INT CHECK (TPINTERFACE IN ('I','A','E')),
   DTINTERFACEORI    DATE           NOT NULL,
   DTINTERFACEDEST   DATE           NULL,
   STATUS            NUMBER         NOT NULL
		CONSTRAINT CKC_STATUS_CUPOM_INT CHECK (STATUS IN (0,1,2,3)),
   APPORIGEM         NUMBER         NOT NULL
		CONSTRAINT CKC_APPORIGEM_CUPOM_INT CHECK (APPORIGEM IN (1,2)),
   APPDESTINO        NUMBER         NOT NULL
		CONSTRAINT CKC_APPDESTINO_CUPOM_INT CHECK (APPDESTINO IN (1,2)),
   TMPSTATUS         VARCHAR2(20)   NULL,
   DTTMPIDA          DATE           NULL,
   DTTMPVOLTA        DATE           NULL,
   OBSLOG            VARCHAR2(500)  NULL,
   LOTETMP           VARCHAR2(50)   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_CUPOM_INT CHECK (IDATIVO IN ('S','N')),
		CONSTRAINT PK_CUPOM_INT PRIMARY KEY (CHAVESEQUNIC)
)
/

CREATE TABLE ITEMCUPOM_INT (
   CHAVESEQUNIC      VARCHAR2(20)   NOT NULL,
   NRSEQUITVEND      VARCHAR2(3)    NOT NULL,
   CDPRODNCM         VARCHAR2(20)   NULL,
   CDPRODUTO         VARCHAR2(10)   NOT NULL,
   NMPRODUTO         VARCHAR2(50)   NOT NULL,
   QTPRODVEND        FLOAT          NOT NULL,
   VRUNITARIO        FLOAT          NOT NULL,
   VRDESITVEND       FLOAT          NOT NULL,
   VRACRITVEND       FLOAT          NOT NULL,
   VRTOTITEM         FLOAT          NOT NULL,
   IDSITUITEM        VARCHAR2(1)    NOT NULL,
   CDIMPOSTO         VARCHAR2(2)    NULL,
   SGIMPOSTO         VARCHAR2(10)   NULL,
   VRBASECALC        FLOAT          NULL,
   VRPEALPRODIT      FLOAT          NULL,
   VRIMPOPRODIT      FLOAT          NULL,
   IDMODALBASECALC   VARCHAR2(1)    NULL,
   VRBASECALCREDUZ   FLOAT          NULL,
   VRIMPOPRODREDUZ   FLOAT          NULL,
   CDCSTPRODI        VARCHAR2(3)    NULL,
   CDCSTPRODPC       VARCHAR2(3)    NULL,
   CDCFOPPROD        VARCHAR2(4)    NULL,
   VRPERCOFINS       FLOAT          NULL,
   VRIMPOCOFINS      FLOAT          NULL,
   VRPERPIS          FLOAT          NULL,
   VRIMPOPIS         FLOAT          NULL,
   IDINTERFACE       NUMBER         NOT NULL,
   TPINTERFACE       VARCHAR2(1)    NOT NULL
		CONSTRAINT CKC_TPINTERFACE_ITEMCUPOM_INT CHECK (TPINTERFACE IN ('I','A','E')),
   DTINTERFACEORI    DATE           NOT NULL,
   DTINTERFACEDEST   DATE           NULL,
   STATUS            NUMBER         NOT NULL
		CONSTRAINT CKC_STATUS_ITEMCUPOM_INT CHECK (STATUS IN (0,1,2,3)),
   APPORIGEM         NUMBER         NOT NULL
		CONSTRAINT CKC_APPORIGEM_ITEMCUPOM_INT CHECK (APPORIGEM IN (1,2)),
   APPDESTINO        NUMBER         NOT NULL
		CONSTRAINT CKC_APPDESTINO_ITEMCUPOM_INT CHECK (APPDESTINO IN (1,2)),
   TMPSTATUS         VARCHAR2(20)   NULL,
   DTTMPIDA          DATE           NULL,
   DTTMPVOLTA        DATE           NULL,
   OBSLOG            VARCHAR2(500)  NULL,
   LOTETMP           VARCHAR2(50)   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_ITEMCUPOM_INT CHECK (IDATIVO IN ('S','N')), 
		CONSTRAINT PK_ITEMCUPOM_INT PRIMARY KEY (CHAVESEQUNIC, NRSEQUITVEND)
)
/

CREATE INDEX VND00879_FK ON ITEMCUPOM_INT (CHAVESEQUNIC ASC)
/

ALTER TABLE ITEMCUPOM_INT
   ADD CONSTRAINT FKVND00879CUPOM_INT FOREIGN KEY (CHAVESEQUNIC)
      REFERENCES CUPOM_INT (CHAVESEQUNIC)
/

CREATE TABLE PAGCUPOM_INT (
   CHAVESEQUNIC      VARCHAR2(20)   NOT NULL,
   NRSEQUMOVI        VARCHAR2(10)   NOT NULL,
   IDTIPOMOVIVE      VARCHAR2(1)    NOT NULL,
   VRMOVIVEND        FLOAT          NOT NULL,
   CDADMINCART       VARCHAR2(20)   NULL,
   CDBANCARTCR       VARCHAR2(10)   NULL,
   TPINTEGRA         VARCHAR2(1)    NULL,
   CDTIPORECE        VARCHAR2(3)    NOT NULL,
   NMTIPORECE        VARCHAR2(40)   NOT NULL,
   IDTIPORECE        VARCHAR2(1)    NOT NULL,
   IDINTERFACE       NUMBER         NOT NULL,
   TPINTERFACE       VARCHAR2(1)    NOT NULL
      CONSTRAINT CKC_TPINTERFACE_PAGCUPOM_INT CHECK (TPINTERFACE IN ('I','A','E')),
   DTINTERFACEORI    DATE           NOT NULL,
   DTINTERFACEDEST   DATE           NULL,
   STATUS            NUMBER         NOT NULL
		CONSTRAINT CKC_STATUS_PAGCUPOM_INT CHECK (STATUS IN (0,1,2,3)),
   APPORIGEM         NUMBER         NOT NULL
		CONSTRAINT CKC_APPORIGEM_PAGCUPOM_INT CHECK (APPORIGEM IN (1,2)),
   APPDESTINO        NUMBER         NOT NULL
		CONSTRAINT CKC_APPDESTINO_PAGCUPOM_INT CHECK (APPDESTINO IN (1,2)),
   TMPSTATUS         VARCHAR2(20)   NULL,
   DTTMPIDA          DATE           NULL,
   DTTMPVOLTA        DATE           NULL,
   OBSLOG            VARCHAR2(500)  NULL,
   LOTETMP           VARCHAR2(50)   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_PAGCUPOM_INT CHECK (IDATIVO IN ('S','N')),
		CONSTRAINT PK_PAGCUPOM_INT PRIMARY KEY (CHAVESEQUNIC, NRSEQUMOVI)
)
/

CREATE INDEX VND00880_FK ON PAGCUPOM_INT (CHAVESEQUNIC ASC)
/

ALTER TABLE PAGCUPOM_INT
   ADD CONSTRAINT FKVND00880CUPOM_INT FOREIGN KEY (CHAVESEQUNIC)
      REFERENCES CUPOM_INT (CHAVESEQUNIC)
/

CREATE SEQUENCE VENDA_GPS_IDINT_FECHA INCREMENT BY 1 MINVALUE 1
/

CREATE SEQUENCE VENDA_GPS_IDINT_CUPOM INCREMENT BY 1 MINVALUE 1
/

CREATE SEQUENCE VENDA_GPS_IDINT_ITEM INCREMENT BY 1 MINVALUE 1
/

CREATE SEQUENCE VENDA_GPS_IDINT_PAG INCREMENT BY 1 MINVALUE 1
/