CREATE TABLE TABEPRECGER( 
   CDTABEPREC VARCHAR2(03) NOT NULL, 
   CDTABEPREC VARCHAR2(03) NOT NULL, 
   NMTABEPREC VARCHAR2(20) NOT NULL,
   DTULTATU DATE  NULL,
   NRORG NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_TABEPRECGER CHECK (IDATIVO IN ('S','N')),
   DTINCLUSAO 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'
)
/
 
ALTER TABLE TABEPRECGER ADD CONSTRAINT PK_TABEPRECGER PRIMARY KEY (CDTABEPREC)
/

CREATE TABLE TABEVENDGER(
   CDTABEPREC VARCHAR2(03) NOT NULL,
   DTINIVGPREC DATE NOT NULL,
   DTFINVGPREC DATE NOT NULL,
   DTREAJUSTE DATE,
   VRREAJUSTE FLOAT(126),
   IDSITVGPREC VARCHAR2(01) DEFAULT '1' NOT NULL,
   DTULTATU DATE  NULL,   
   NRORG NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_TABEVENDGER CHECK (IDATIVO IN ('S','N')),
   DTINCLUSAO 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'
)
/

ALTER TABLE TABEVENDGER ADD CONSTRAINT PK_TABEVENDGER PRIMARY KEY (CDTABEPREC, DTINIVGPREC)
/

ALTER TABLE TABEVENDGER ADD CONSTRAINT CKC_TABEVENDGER_IDSITVGPREC CHECK (IDSITVGPREC IN ('1', '2', '3', '4'))
/
CREATE INDEX VND00791_FK ON TABEVENDGER (CDTABEPREC ASC)
/
ALTER TABLE TABEVENDGER ADD CONSTRAINT FKVND00791TABVNDGER_TABPRCGR FOREIGN KEY (CDTABEPREC)
   REFERENCES TABEPRECGER (CDTABEPREC) ON DELETE CASCADE
/

CREATE TABLE ITEMPRECOGER(
   CDTABEPREC VARCHAR2(03) NOT NULL,
   DTINIVGPREC DATE NOT NULL,
   CDPRODUTO VARCHAR2(10) NOT NULL,
   CDPRPAITABPR VARCHAR2(10) NOT NULL,
   VRPRECITEM FLOAT(126),
   VRPRECITEMCL FLOAT(126),
   IDPRECVARIA VARCHAR2(1) NOT NULL,
   VRPRESUGITEM FLOAT(126),
   VRCUSTITEM FLOAT(126),
   VRMKUPITEM FLOAT(126),
   IDPRODPROMOC VARCHAR2(1) NOT NULL,
   HRINIVENPROD VARCHAR2(4),
   HRFIMVENPROD VARCHAR2(4),
   DTULTATU DATE  NULL,
   NRORG NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_ITEMPRECOGER CHECK (IDATIVO IN ('S','N')),
   DTINCLUSAO 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'
)
/

ALTER TABLE ITEMPRECOGER ADD CONSTRAINT PK_ITEMPRECOGER PRIMARY KEY (CDTABEPREC, DTINIVGPREC, CDPRODUTO)
/
CREATE INDEX VND00792_FK ON ITEMPRECOGER (CDTABEPREC ASC)
/
ALTER TABLE ITEMPRECOGER ADD CONSTRAINT FKVND00792ITPRECGER_TABPRECGER FOREIGN KEY (CDTABEPREC)
   REFERENCES TABEPRECGER (CDTABEPREC) ON DELETE CASCADE
/
CREATE INDEX VND00793_FK ON ITEMPRECOGER (CDTABEPREC ASC, DTINIVGPREC ASC)
/
ALTER TABLE ITEMPRECOGER ADD CONSTRAINT FKVND00793ITPRECGER_TABVNDGER FOREIGN KEY (CDTABEPREC, DTINIVGPREC)
   REFERENCES TABEVENDGER (CDTABEPREC, DTINIVGPREC) ON DELETE CASCADE
/
CREATE INDEX VND00794_FK ON ITEMPRECOGER (CDPRODUTO ASC)
/
ALTER TABLE ITEMPRECOGER ADD CONSTRAINT FKVND00794ITMPRECGER_PROD FOREIGN KEY (CDPRODUTO)
   REFERENCES PRODUTO (CDPRODUTO)
/

CREATE TABLE FILITABGER(
   CDTABEPREC VARCHAR2(03),
   CDFILIAL  VARCHAR2(04),
   DTULTATU DATE  NULL,
   NRORG NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FILITABGER CHECK (IDATIVO IN ('S','N')),
   DTINCLUSAO 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'
)
/

CREATE TABLE ITEMPRECODIAGER(
   CDTABEPREC VARCHAR2(3) NOT NULL,
   DTINIVGPREC DATE NOT NULL,
   CDPRODUTO VARCHAR2(10) NOT NULL,
   CDPRPAITABPR VARCHAR2(10) NOT NULL,
   NRDIASEMANPR VARCHAR2(1) NOT NULL,
   HRINIPRECDIA VARCHAR2(4) NOT NULL,
   CDTIPOCONSPD VARCHAR2(2) NOT NULL,
   HRFINPRECDIA VARCHAR2(4) NOT NULL,
   VRPRECODIA FLOAT(126) NOT NULL,
   IDPERVALORPR VARCHAR2(1) NOT NULL,
   IDDESCACREPR VARCHAR2(1) NOT NULL,
   DTINIVALPREC DATE NOT NULL,
   DTFINVALPREC DATE NOT NULL,
   DTULTATUITPD DATE,
   IDVISUACUPOM VARCHAR2(1) NOT NULL,
   CALCDESCONTOVRUNITARIO VARCHAR2(3) DEFAULT 'NAO' NOT NULL,
   NRTIPOPRECO VARCHAR2(1),
   NRORG NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_ITEMPRECODIAGER CHECK (IDATIVO IN ('S','N')),
   DTINCLUSAO 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',
   VRPRECODIF FLOAT(126)
)
/
CREATE INDEX VND00795_FK ON ITEMPRECODIAGER (CDTABEPREC ASC)
/
ALTER TABLE ITEMPRECODIAGER ADD CONSTRAINT FKVND00795ITPCDIAGER_TBPCGER FOREIGN KEY (CDTABEPREC)
   REFERENCES TABEPRECGER (CDTABEPREC) ON DELETE CASCADE
/
CREATE INDEX VND00796_FK ON ITEMPRECODIAGER (CDTABEPREC ASC,DTINIVGPREC ASC)
/
ALTER TABLE ITEMPRECODIAGER ADD CONSTRAINT FKVND00796ITPRCDIAG_TBVNDG FOREIGN KEY (CDTABEPREC, DTINIVGPREC)
   REFERENCES TABEVENDGER (CDTABEPREC, DTINIVGPREC) ON DELETE CASCADE
/
CREATE INDEX VND00797_FK ON ITEMPRECODIAGER (CDPRODUTO ASC)
/
ALTER TABLE ITEMPRECODIAGER ADD CONSTRAINT FKVND00797ITPRCDGER_PROD FOREIGN KEY (CDPRODUTO)
   REFERENCES PRODUTO (CDPRODUTO)
/