CREATE TABLE USR_CHQ_FORNECEDOR
(
	CDFORNECEDOR VARCHAR2(20) NOT NULL,
	NMRAZAOSOC   VARCHAR2(40) NOT NULL,
	NMFANTFORNE  VARCHAR2(40) NOT NULL,
	DSENDERECOP  VARCHAR2(40),
	CDPAISP      VARCHAR2(4)  NOT NULL,
	SGESTADOP    VARCHAR2(2)  NOT NULL,
	CDMUNICIPIOP VARCHAR2(7)  NOT NULL,
	CDCEPP       VARCHAR2(15),
	NMBAIRROP    VARCHAR2(30),
	EMAIL        VARCHAR2(40),
	IDINTERFACE  NUMBER       NOT NULL,
	TPINTERFACE  VARCHAR2(1)  NOT NULL
		CONSTRAINT CKC_TPINTERFACE_USR_CHQ_FORN CHECK (TPINTERFACE IN ('I','A','E')),	
	DTINTERFACEDEST DATE,
	STATUS       NUMBER       NOT NULL
		CONSTRAINT CKC_STATUS_USR_CHQ_FORN CHECK (STATUS IN (0,1,2))
)
/

CREATE TABLE USR_CHQ_CLIENTE
(
	CDCLIENTE    VARCHAR2(20) NOT NULL,
	NMRAZAOSOC   VARCHAR2(40) NOT NULL,
	NMFANTCLIE   VARCHAR2(40) NOT NULL,
	DSENDERECOP  VARCHAR2(40),
	CDPAISP      VARCHAR2(4)  NOT NULL,
	SGESTADOP    VARCHAR2(2)  NOT NULL,
	CDMUNICIPIOP VARCHAR2(7)  NOT NULL,
	CDCEPP       VARCHAR2(15),
	NMBAIRROP    VARCHAR2(30),
	EMAIL        VARCHAR2(40),
   CDCLIENTEUN  VARCHAR2(30) NOT NULL,
	IDINTERFACE  NUMBER       NOT NULL,
	TPINTERFACE  VARCHAR2(1)  NOT NULL
		CONSTRAINT CKC_TPINTERFACE_USR_CHQ_CLI CHECK (TPINTERFACE IN ('I','A','E')),	
	DTINTERFACEDEST DATE,
	STATUS       NUMBER       NOT NULL
		CONSTRAINT CKC_STATUS_USR_CHQ_CLI CHECK (STATUS IN(0,1,2))
)
/

CREATE TABLE USR_CHQ_INTECLIE
(
   CDCLIENTE    VARCHAR2(20) NOT NULL,
   CDCLIENTEUN  VARCHAR2(30) NOT NULL,
   NMINTECLIE   VARCHAR2(50) NOT NULL,
   DSENDERECOP  VARCHAR2(40),
   CDPAISP      VARCHAR2(4)  NOT NULL,
   SGESTADOP    VARCHAR2(2)  NOT NULL,
   CDMUNICIPIOP VARCHAR2(7)  NOT NULL,
   CDCEPP       VARCHAR2(15),
   NMBAIRROP    VARCHAR2(30),
   EMAIL        VARCHAR2(40),
   IDTPINTECLIE VARCHAR2(1)
      CONSTRAINT CKC_IDTPINTECL_USR_CHQ_INCLI CHECK (IDTPINTECLIE IN ('P','D','G','F','O','S','I','R','N')),
	IDINTERFACE  NUMBER       NOT NULL,
	TPINTERFACE  VARCHAR2(1)  NOT NULL
		CONSTRAINT CKC_TPINTERFACE_USR_CHQ_INCLI CHECK (TPINTERFACE IN ('I','A','E')),
	DTINTERFACEDEST DATE,
	STATUS       NUMBER       NOT NULL
		CONSTRAINT CKC_STATUS_USR_CHQ_INCLI CHECK (STATUS IN(0,1,2))
)
/

CREATE TABLE USR_CHQ_PEDIDO
(
   NRPEDIDO     INTEGER      NOT NULL,
   NRSEQPEDIDO  INTEGER      NOT NULL,
   CDCLIENTE    VARCHAR2(20) NOT NULL,
   CDCLIENTEUN  VARCHAR2(30) NOT NULL,
   DTPEDIDO     DATE         NOT NULL,
   DTENTPEDIDO  DATE,
   IDORIGPED    VARCHAR2(1)  NOT NULL,
   CDFORNECEDOR VARCHAR2(20) NOT NULL,
   VRTOTPED     FLOAT        NOT NULL,
   IDSTATUSPED  VARCHAR2 (1) NOT NULL
      CONSTRAINT CKC_STATUS_CHQ_IDSTATUSPED CHECK (IDSTATUSPED IN ('P','A','L','C','F','T')),
   VRDESCONTO   FLOAT,
   VRLIQPED     FLOAT        NOT NULL,
	IDINTERFACE  NUMBER       NOT NULL,
	TPINTERFACE  VARCHAR2(1)  NOT NULL
		CONSTRAINT CKC_TPINTERFACE_USR_CHQ_PED CHECK (TPINTERFACE IN ('I','A','E')),	
	DTINTERFACEDEST DATE,
	STATUS       NUMBER       NOT NULL
		CONSTRAINT CKC_STATUS_USR_CHQ_PED CHECK (STATUS IN(0,1,2))
)
/

CREATE TABLE USR_CHQ_ITEMPEDIDO
(
   NRPEDIDO     INTEGER      NOT NULL,
   NRSEQITEMPED INTEGER      NOT NULL,
   NRITEMPED    INTEGER      NOT NULL,
   CDPRODFORN   VARCHAR2(20) NOT NULL,
   CDARVPROD    VARCHAR2(20) NOT NULL,
   SGUNIDADE    VARCHAR2(10) NOT NULL,
   QTITEMPED    FLOAT        NOT NULL,
   VRUNITITPED  FLOAT        NOT NULL,
   VRTOTITPED   FLOAT        NOT NULL,
	IDINTERFACE  NUMBER       NOT NULL,
	TPINTERFACE  VARCHAR2(1)  NOT NULL
		CONSTRAINT CKC_TPINTERFACE_USR_CHQ_ITPED CHECK (TPINTERFACE IN ('I','A','E')),	
	DTINTERFACEDEST DATE,
	STATUS      NUMBER       NOT NULL
		CONSTRAINT CKC_STATUS_USR_CHQ_ITPED CHECK (STATUS IN(0,1,2))
)
/

CREATE TABLE USR_CHQ_LOG
(
	IDINTERFACE INTEGER NOT NULL,
	IDSEQLOG    INTEGER NOT NULL,
	IDPROCESSO  INTEGER NOT NULL
		CONSTRAINT CKC_IDPROCESSO_USR_CHQ_LOG CHECK (IDPROCESSO BETWEEN 1 AND 5),
	DTLOG       DATE    NOT NULL,
	STATUS      INTEGER NOT NULL
		CONSTRAINT CKC_STATUS_USR_CHQ_LOG CHECK (STATUS IN (0,1)),
	OBSSTATUS   VARCHAR2(250) NOT NULL
)
/

CREATE SEQUENCE USR_CHQ_IDSEQLOG INCREMENT BY 1 MINVALUE 1
/

CREATE TABLE USR_EXP_POSIESTQ
(
   CDFILIAL VARCHAR2(4),
   DTPOSICAO DATE,
   CDPRODUTO VARCHAR2(20),
   CDALMOXARIFADO VARCHAR2(6),
   CDLOCALESTOQ VARCHAR2(6),
   CDLOTEESTOQ VARCHAR2(20),
   VRQTDEESTQ FLOAT
)
/

CREATE INDEX USR_EXP_POSIESTQ_01 ON USR_EXP_POSIESTQ(CDFILIAL)
/

ALTER TABLE PEDIDO ADD NRPEDIDO_PROT INTEGER NULL
/

ALTER TABLE PEDIDO ADD NRSEQPEDIDO_PROT INTEGER NULL
/

ALTER TABLE ITEMPEDIDO ADD NRPEDIDO_PROT INTEGER NULL
/

ALTER TABLE ITEMPEDIDO ADD NRSEQITEMPED_PROT INTEGER NULL
/

-- VERSAO --
BEGIN ATUVEROBJ('ATUALIZACAO_ESTRUTURA_BD','6.05.XXX'); END;
/