-- ==============================================================================
-- TABLE: SDX_ZFMMBR_MATERI
-- ==============================================================================
CREATE TABLE SDX_ZFMMBR_MATERI (
  NUM_SEQ             NUMBER NOT NULL,
  COD_ITEM_SAP        VARCHAR2(18)  NOT NULL,
  DES_ITEM            VARCHAR2(50) NOT NULL,
  COD_UM              VARCHAR2(4) NOT NULL,
  COD_NBM             VARCHAR2(16),
  DESC_NBM            VARCHAR2(60),
  COD_GR_FISCAL       NUMBER,
  IND_INATIVO         VARCHAR2(1) NOT NULL,
  TXT_JUSTIFICATIVA   VARCHAR2(1024),
  COD_MOTIVO          NUMBER,
  COD_USUARIO         VARCHAR2(20),
  DTA_INATIVO         DATE,
  QTD_PESO_LIQ        FLOAT,
  QTD_PESO_BRUTO      FLOAT,
  DES_GERAL           VARCHAR2(1),
  IND_PDV             VARCHAR2(1),
  TIP_CONTROLE        NUMBER,
  COD_TIPO            NUMBER,
  PER_IPI             FLOAT,
  VLR_IPI             FLOAT,
  PER_II              FLOAT,
  PER_DESCONTO        FLOAT,
  IND_DESC_MANUAL     NUMBER,
  TIP_ABC             NUMBER,
  TIP_ABC2            NUMBER,
  DTA_INCLUSAO        DATE,
  COD_GU              NUMBER,
  IDX_CONVERSAO       FLOAT,
  IND_AGRUPA_ROM      NUMBER,
  TIP_ATENDE_SE       NUMBER,
  IND_GARANTIA        NUMBER,
  COD_EDITADO_108     VARCHAR2(100),
  COD_EDITADO_109     VARCHAR2(100),
  COD_EDITADO_110     VARCHAR2(100),
  COD_EDITADO_125     VARCHAR2(100),
  COD_EDITADO_148     VARCHAR2(100),
  COD_UNIDADE         NUMBER,
  TIP_CALCULO         NUMBER,
  IND_DESTINO         NUMBER,
  TIP_FORNECIMENTO    NUMBER,
  IND_ORDEM           NUMBER,
  IND_ABASTECE        NUMBER,
  COD_UM_COMPRA       VARCHAR2(4),
  IDX_CONV_COMPRA     FLOAT,
  QTD_ARREDONDA       NUMBER,
  IND_STATUS          NUMBER,
  COD_ARV_PROD        VARCHAR2(40),
  DESC_COD_ARV        VARCHAR2(40),
  COD_CEST            VARCHAR2(9),
  DESC_CEST           VARCHAR2(60),
  constraint PK_SDX_ZFMMBR_MATERI primary key (NUM_SEQ)
)
/

-- ==============================================================================
-- TABLE: SDX_ZFMMBR_MAT_RE
-- ==============================================================================
CREATE TABLE SDX_ZFMMBR_MAT_RE (
  NUM_SEQ           NUMBER NOT NULL,
  COD_ITEM_SAP      VARCHAR2(18)  NOT NULL,
  COD_ITEM_NL       NUMBER,
  DES_ITEM          VARCHAR2(50) NOT NULL,
  COD_UM            VARCHAR2(4) NOT NULL,
  COD_NBM           VARCHAR2(16),
  DESC_NBM          VARCHAR2(60),
  COD_GR_FISCAL     VARCHAR2(4),
  IND_INATIVO       VARCHAR2(1) NOT NULL,
  TXT_JUSTIFICATIVA VARCHAR2(1024),
  COD_MOTIVO        NUMBER,
  COD_USUARIO       VARCHAR2(20),
  DTA_INATIVO       DATE,
  QTD_PESO_LIQ      FLOAT,
  QTD_PESO_BRUTO    FLOAT,
  DES_GERAL         VARCHAR2(1),
  IND_PDV           VARCHAR2(1),
  TIP_CONTROLE      NUMBER,
  COD_TIPO          NUMBER,
  PER_IPI           FLOAT,
  VLR_IPI           FLOAT,
  PER_II            FLOAT,
  PER_DESCONTO      FLOAT,
  IND_DESC_MANUAL   NUMBER,
  TIP_ABC           NUMBER,
  TIP_ABC2          NUMBER,
  DTA_INCLUSAO      DATE,
  COD_GU            NUMBER,
  IDX_CONVERSAO     FLOAT NOT NULL,
  IND_AGRUPA_ROM    NUMBER,
  TIP_ATENDE_SE     NUMBER,
  IND_GARANTIA      NUMBER,
  COD_EDITADO_108   VARCHAR2(100),
  COD_EDITADO_109   VARCHAR2(100),
  COD_EDITADO_110   VARCHAR2(100),
  COD_EDITADO_125   VARCHAR2(100),
  COD_EDITADO_148   VARCHAR2(100),
  COD_UNIDADE       NUMBER,
  TIP_CALCULO       NUMBER,
  IND_DESTINO       NUMBER,
  TIP_FORNECIMENTO  NUMBER,
  IND_ORDEM         NUMBER,
  IND_ABASTECE      NUMBER,
  COD_UM_COMPRA     VARCHAR2(4),
  IDX_CONV_COMPRA   FLOAT,
  QTD_ARREDONDA     NUMBER,
  IND_STATUS        NUMBER,
  DTA_IMPORTACAO    DATE,
  TXT_LOG           VARCHAR2(1024),
  NUM_SEQ_ORIGEM    NUMBER,
  COD_ARV_PROD      VARCHAR2(40),
  DESC_COD_ARV      VARCHAR2(40),
  COD_CEST          VARCHAR2(9),
  DESC_CEST         VARCHAR2(60),
  COD_ITEM_TK       VARCHAR2(20),
  constraint PK_SDX_ZFMMBR_MAT_RE primary key (NUM_SEQ)
)
/

alter table SDX_ZFMMBR_MAT_RE
    add constraint FK_SDX_SEQMATER foreign key (NUM_SEQ_ORIGEM)
       references SDX_ZFMMBR_MATERI (NUM_SEQ)
/


-- ==============================================================================
-- TABLE: SDX_ZFARBR_CUSTTEKOI
-- ==============================================================================
CREATE TABLE SDX_ZFARBR_CUSTTEKOI (
  NUMREGINT           NUMBER NOT NULL,
  NUM_SEQ_CLI         NUMBER,
  NUM_INSC            VARCHAR2(20)  NOT NULL,
  COD_CLIENTE_SAP     VARCHAR2(20),
  DES_PESSOA          VARCHAR2(40) NOT NULL,
  DES_FANTASIA        VARCHAR2(40),
  DES_ENDERECO        VARCHAR2(60),
  CDPAIS              VARCHAR2(4) NOT NULL,
  SGESTADO            VARCHAR2(2) NOT NULL,
  CDMUNCIPIO          VARCHAR2(7) NOT NULL,
  NUM_CEP             VARCHAR2(15),
  DES_BAIRRO          VARCHAR2(50),
  EMAIL               VARCHAR2(40),
  NUM_INSC_EST        VARCHAR2(16),
  NUM_INSC_MUN        VARCHAR2(16),
  NUM_FONE            VARCHAR2(25),
  NRRAMAL             VARCHAR2(4),
  NRFAX               VARCHAR2(25),
  CDFILIAL            VARCHAR2(20),
  TXT_ERRO            VARCHAR2(1024),
  CODRETORNO          VARCHAR2(1),
  DTA_INCLUSAO        DATE,
  DTA_IMPORTACAO      DATE,
  constraint SDX_ZFARBR_CUSTTEKOI primary key (NUMREGINT)
)
/

-- ==============================================================================
-- TABLE: SDX_SAP_CLIENTES
-- ==============================================================================
CREATE TABLE SDX_SAP_CLIENTES (
  NUMREGINT           NUMBER NOT NULL,
  NUM_SEQ_CLI         NUMBER,
  NUM_INSC            VARCHAR2(20)  NOT NULL,
  COD_CLIENTE_SAP     VARCHAR2(20),
  DES_PESSOA          VARCHAR2(40) NOT NULL,
  DES_FANTASIA        VARCHAR2(40),
  DES_ENDERECO        VARCHAR2(60),
  CDPAIS              VARCHAR2(4) NOT NULL,
  SGESTADO            VARCHAR2(2) NOT NULL,
  CDMUNCIPIO          VARCHAR2(7) NOT NULL,
  NUM_CEP             VARCHAR2(15),
  DES_BAIRRO          VARCHAR2(50),
  EMAIL               VARCHAR2(40),
  NUM_INSC_EST        VARCHAR2(16),
  NUM_INSC_MUN        VARCHAR2(16),
  NUM_FONE            VARCHAR2(25),
  NRRAMAL             VARCHAR2(4),
  NRFAX               VARCHAR2(25),
  CDFILIAL            VARCHAR2(20),
  TXT_ERRO            VARCHAR2(1024),
  CODRETORNO          VARCHAR2(1),
  DTA_INCLUSAO        DATE,
  DTA_IMPORTACAO      DATE,
  constraint SDX_SAP_CLIENTES primary key (NUMREGINT)
)
/

-- ==============================================================================
-- TABLE: SDX_ZMBRBR_0776_UNID
-- ==============================================================================
CREATE TABLE SDX_ZMBRBR_0776_UNID (
  NUMREGINT           NUMBER NOT NULL,
  NUM_SEQ_UNI         NUMBER,
  CDFILIAL            VARCHAR2(20),
  COD_UNIDADE_SAP     VARCHAR2(20) NOT NULL,
  DES_UNIDADE         VARCHAR2(40) NOT NULL,
  DES_RAZAO_SOCIAL    VARCHAR2(40) NOT NULL,
  NUM_CGC_UNIDADE     VARCHAR2(20),
  CDEMPRESA           VARCHAR2(2),
  COD_EMP_SAP         VARCHAR2(20) NOT NULL,
  NUM_INSC_EST        VARCHAR2(16) NOT NULL,
  NUM_INSC_MUN        VARCHAR2(16),
  DES_ENDERECO_ENT    VARCHAR2(60),
  CDPAIS_BP           VARCHAR2(4),
  SGESTADO_BP         VARCHAR2(2),
  COD_IBGE_ENT        VARCHAR2(7),
  NUM_CEP_ENT         VARCHAR2(15),
  DES_BAIRRO_ENT      VARCHAR2(50),
  DES_EMAIL           VARCHAR2(40),
  NUM_CGC_FAT         VARCHAR2(20),
  DES_ENDERECO_FAT    VARCHAR2(60),
  CDPAIS              VARCHAR2(4),
  SGESTADO            VARCHAR2(2),
  COD_IBGE_FAT        VARCHAR2(7),
  DES_BAIRRO_FAT      VARCHAR2(60),
  NUM_CEP_FAT         VARCHAR2(15),
  TXT_ERRO            VARCHAR2(1024),
  CODRETORNO          VARCHAR2(1),
  DTA_INCLUSAO        DATE,
  DTA_IMPORTACAO      DATE,
  constraint SDX_ZMBRBR_0776_UNID primary key (NUMREGINT)
)
/

-- ==============================================================================
-- TABLE: SDX_SAP_UNIDADES
-- ==============================================================================
CREATE TABLE SDX_SAP_UNIDADES (
  NUMREGINT           NUMBER NOT NULL,
  NUM_SEQ_UNI         NUMBER,
  CDFILIAL            VARCHAR2(20),
  COD_UNIDADE_SAP     VARCHAR2(20) NOT NULL,
  DES_UNIDADE         VARCHAR2(40) NOT NULL,
  DES_RAZAO_SOCIAL    VARCHAR2(40) NOT NULL,
  NUM_CGC_UNIDADE     VARCHAR2(20),
  CDEMPRESA           VARCHAR2(2),
  COD_EMP_SAP         VARCHAR2(20) NOT NULL,
  NUM_INSC_EST        VARCHAR2(16) NOT NULL,
  NUM_INSC_MUN        VARCHAR2(16),
  DES_ENDERECO_ENT    VARCHAR2(60),
  CDPAIS_BP           VARCHAR2(4),
  SGESTADO_BP         VARCHAR2(2),
  COD_IBGE_ENT        VARCHAR2(7),
  NUM_CEP_ENT         VARCHAR2(15),
  DES_BAIRRO_ENT      VARCHAR2(50),
  DES_EMAIL           VARCHAR2(40),
  NUM_CGC_FAT         VARCHAR2(20),
  DES_ENDERECO_FAT    VARCHAR2(60),
  CDPAIS              VARCHAR2(4),
  SGESTADO            VARCHAR2(2),
  COD_IBGE_FAT        VARCHAR2(7),
  DES_BAIRRO_FAT      VARCHAR2(60),
  NUM_CEP_FAT         VARCHAR2(15),
  TXT_ERRO            VARCHAR2(1024),
  CODRETORNO          VARCHAR2(1),
  DTA_INCLUSAO        DATE,
  DTA_IMPORTACAO      DATE,
  constraint SDX_SAP_UNIDADES primary key (NUMREGINT)
)
/

ALTER TABLE SDX_ZFMMBR_MAT_RE ADD NUMREGINT NUMBER
/
ALTER TABLE SDX_ZFMMBR_MAT_RE ADD CONSTRAINT CKC_MATERI_RE_UK UNIQUE (NUMREGINT)
/
ALTER TABLE FILIAL MODIFY NMFILIAL VARCHAR2(40)
/

alter table SDX_ZFMMBR_MAT_RE
    drop constraint FK_SDX_SEQMATER
/

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