create table SDX_NOTAFISCAL
(
  CDNOTAFISCORIG       VARCHAR2(20)     NOT NULL,
  CDFILIAL             VARCHAR2(04)     NOT NULL,
  CDEMPRESA            VARCHAR2(02)     NOT NULL,
  NRINSJURNF           VARCHAR2(20)     NOT NULL,
  NRNOTAFISC           VARCHAR2(20)         NULL,
  DTEMISSAO            DATE                 NULL,
  DTENTRSAID           DATE             NOT NULL,
  IDENTRSAIDOP         VARCHAR2(01)     NOT NULL
     constraint CKC_SDX_IDENTRSAIDOP check (IDENTRSAIDOP in ('E','S')),
  CDTIPOOPER           VARCHAR2(02)     NOT NULL,
  CDSERIE              VARCHAR2(05)     NOT NULL,
  CDMODDOCFISC         VARCHAR2(02)     NOT NULL,
  CDFILIEMIT           VARCHAR2(04)         NULL,
  CDFILIRECE           VARCHAR2(04)         NULL,
  CDALMOXARIFE         VARCHAR2(06)         NULL,
  CDLOCALESTOQ         VARCHAR2(06)         NULL,
  DSOBSERVERROS        VARCHAR2(400)        NULL,
  constraint PK_SDX_NOTAFISCAL primary Key (CDNOTAFISCORIG)
)
/

create table SDX_ITEMPRODUTO
(
  CDNOTAFISCORIG       VARCHAR2(20)     NOT NULL,
  CDFILIAL             VARCHAR2(04)     NOT NULL,
  CDPRODUTO            VARCHAR2(20)     NOT NULL,
  QTITEMPROD           FLOAT            NOT NULL,
  VRUNITITEM           FLOAT            NOT NULL,
  VRDESCITEM           FLOAT                NULL,
  VRTOTAITEM           FLOAT            NOT NULL,
  CDFISOPEITEM         VARCHAR2(11)         NULL,
  CDSITUTRIBPR         VARCHAR2(03)         NULL,
  CDALMOXARIFE         VARCHAR2(06)         NULL,
  CDLOCALESTOQ         VARCHAR2(06)         NULL,
  NRLOTEESTQ           VARCHAR2(20)         NULL,
  NRSUBLOTE            VARCHAR2(04)         NULL,
  DSOBSERVERROS        VARCHAR2(400)        NULL,
  constraint PK_SDX_ITEMPRODUTO primary key (CDNOTAFISCORIG, CDPRODUTO, VRUNITITEM)
)
/

create table SDX_ITEMENCARGO
(
  CDNOTAFISCORIG       VARCHAR2(20)     NOT NULL,
  CDFILIAL             VARCHAR2(04)     NOT NULL,
  CDENCARGO            VARCHAR2(02)     NOT NULL,
  VRITEMENCA           FLOAT            NOT NULL,
  DSOBSERVERROS        VARCHAR2(400)        NULL,
  constraint PK_SDX_ITEMENCARGO primary key (CDNOTAFISCORIG, CDENCARGO)
)
/

create table SDX_AFRELACNF
(
  CDNOTAFISCORIG       VARCHAR2(20)     NOT NULL,
  CDFILIAL             VARCHAR2(04)     NOT NULL,
  NRINSJURNF           VARCHAR2(20)     NOT NULL,
  CDPEDCOMPRA          VARCHAR2(12)     NOT NULL,
  CDPRODUTO            VARCHAR2(20)     NOT NULL,
  DTENTREGA            DATE             NOT NULL,
  DSOBSERVERROS        VARCHAR(400)         NULL,
  constraint PK_SDX_AFRELACNF primary key (CDNOTAFISCORIG, CDPEDCOMPRA, CDPRODUTO, DTENTREGA)
)
/

create table SDX_CONTROLEINT
(
  CDNOTAFISCORIG       VARCHAR2(20)     NOT NULL,
  DTEXPORTACAO         DATE                 NULL,
  DTIMPORTACAO         DATE                 NULL,
  DSOBSERVERROS        VARCHAR2(400)        NULL,
  constraint PK_SDX_CONTROLEINT primary key (CDNOTAFISCORIG)
)
/

ALTER TABLE ITEMAUTF ADD SDX_CDPEDCOMPRA VARCHAR2(12) NULL
/

create index ITEMAUTF_SDX on ITEMAUTF (CDFILDEST asc, SDX_CDPEDCOMPRA asc, CDPRODUTO asc, DTPROGENTAF asc)
/

ALTER TABLE NOTAFISCAL ADD SDX_CDNOTAFISCORIG VARCHAR2(20) NULL
/

create index SDX_CONTROLEINT_01 on SDX_CONTROLEINT (DTIMPORTACAO asc)
/

create index SDX_INT_FILIAL_01 on FILIAL (NRINSJURFILI asc)
/

create index SDX_INT_FORNE_01 on FORNECEDOR (NRINSJURFORN asc)
/

create index SDX_INT_CLIENTE_01 on CLIENTE (NRINSJURCLIE asc)
/

create index SDX_CDNOTAFISCORIG_01 on NOTAFISCAL (SDX_CDNOTAFISCORIG asc)
/

-- VERSAO --
BEGIN ATUVEROBJ('ATUALIZACAO_ESTRUTURA_BD','5.09.000'); END;
/