CREATE TABLE FAT_ANALISE_RESULTADO (	
	CDEMPRESA VARCHAR2(2), 
	NMEMPRESA VARCHAR2(40), 
	NMRAZSOCEMPR VARCHAR2(80), 
	SGESTADO VARCHAR2(2), 
	NMESTADO VARCHAR2(30), 
	CDMUNICIPIO VARCHAR2(4), 
	NMMUNICIPIO VARCHAR2(30), 
	CDFILIAL VARCHAR2(4), 
	NMFILIAL VARCHAR2(30), 
	CDCLIENTE VARCHAR2(21), 
	NMRAZSOCCLIE VARCHAR2(100), 
	NMFANTCLIE VARCHAR2(100), 
	NRINSJURCLIE VARCHAR2(20), 
	VRSEGURO FLOAT(126), 
	VRFRETE FLOAT(126), 
	VRINCENTIVOS FLOAT(126), 
	VRMARKETING FLOAT(126), 
	VRDESPESAS FLOAT(126), 
	VR_CUSTO_VARIAVEL FLOAT(126), 
	QT_OBJETIVO_FIS FLOAT(126), 
	QT_OBJETIVO_FIN FLOAT(126), 
	QT_PRODUTO FLOAT(126), 
	VR_BRUTITEM FLOAT(126), 
	VR_FECP FLOAT(126), 
	VR_IPI FLOAT(126), 
	VR_ICMS FLOAT(126), 
	VR_ICMSST FLOAT(126), 
	VR_PIS FLOAT(126), 
	VR_COFINS FLOAT(126), 
	VR_COMISSOES FLOAT(126), 
	DSDATA DATE, 
	DSANO VARCHAR2(4), 
	DSSEMESTRE VARCHAR2(45), 
	DSTRIMESTRE VARCHAR2(45), 
	DSBIMESTRE VARCHAR2(45), 
	DSQUADRIMESTRE VARCHAR2(45), 
	DSMES VARCHAR2(2), 
	DSMES_ANO VARCHAR2(7), 
	ORDANOMES VARCHAR2(6), 
	CDMACROREGIAO VARCHAR2(3), 
	NMMACROREGIAO VARCHAR2(35), 
	CDMICROREGIAO VARCHAR2(3), 
	NMMICROREGIAO VARCHAR2(50), 
	CDVENDEDOR VARCHAR2(4), 
	NMVENDEDOR VARCHAR2(50), 
	CDSEGMER VARCHAR2(5), 
	DSSEGMER VARCHAR2(40), 
	CDGRUPCLIE VARCHAR2(10), 
	NMGRUPCLIE VARCHAR2(50), 
	CDATIVCLI VARCHAR2(10), 
	DSATIVCLI VARCHAR2(50),
	NRORG             NUMBER 	      DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FAT_ANALI_RESULT CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          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 FATURAMENTO_PRODVENDIDO(
	DSDATA DATE, 
	DSMES_ANO VARCHAR2(7), 
	ORDANOMES VARCHAR2(6), 
	DSANO VARCHAR2(4), 
	DSMES VARCHAR2(2), 
	DSBIMESTRE VARCHAR2(45), 
	DSTRIMESTRE VARCHAR2(45), 
	DSSEMESTRE VARCHAR2(45), 
	DSQUADRIMESTRE VARCHAR2(45), 
	DTEMISSAO DATE, 
	NRLANCTONF VARCHAR2(10), 
	NRNOTAFISC VARCHAR2(20), 
	CDEMPRESA VARCHAR2(2), 
	NMEMPRESA VARCHAR2(40), 
	NMRAZSOCEMPR VARCHAR2(80), 
	CDMACROREGIAO CHAR(3), 
	NMMACROREGIAO VARCHAR2(35), 
	CDMICROREGIAO VARCHAR2(3), 
	NMMICROREGIAO VARCHAR2(50), 
	CDVENDEDOR VARCHAR2(4), 
	NMVENDEDOR VARCHAR2(50), 
	SGESTADO VARCHAR2(2), 
	NMESTADO VARCHAR2(30), 
	CDMUNICIPIO VARCHAR2(4), 
	NMMUNICIPIO VARCHAR2(30), 
	CDFILIAL VARCHAR2(4), 
	NMFILIAL VARCHAR2(30), 
	CDCLIENTE VARCHAR2(21), 
	NMRAZSOCCLIE VARCHAR2(100), 
	NMFANTCLIE VARCHAR2(100), 
	NRINSJURCLIE VARCHAR2(20), 
	CDSEGMER VARCHAR2(5), 
	DSSEGMER VARCHAR2(40), 
	CDGRUPCLIE VARCHAR2(10), 
	NMGRUPCLIE VARCHAR2(50), 
	CDATIVCLI VARCHAR2(10), 
	DSATIVCLI VARCHAR2(50), 
	CDGRUPPROD VARCHAR2(10), 
	NMGRUPPROD VARCHAR2(40), 
	CDSUBGRPROD VARCHAR2(10), 
	NMSUBGRPROD VARCHAR2(40), 
	CDPRODUTO VARCHAR2(10), 
	CDARVPROD VARCHAR2(20), 
	NMPRODUTO VARCHAR2(50), 
	QT_PRODUTO FLOAT(126), 
	VR_BRUTITEM FLOAT(126), 
	QT_OBJETIVO_FIS FLOAT(126), 
	QT_OBJETIVO_FIN FLOAT(126), 
	VR_FECP FLOAT(126), 
	VR_IPI FLOAT(126), 
	VR_ICMS FLOAT(126), 
	VR_ICMSST FLOAT(126), 
	VR_PIS FLOAT(126), 
	VR_PISST FLOAT(126), 
	VR_COFINS FLOAT(126), 
	VR_COFINS_ST FLOAT(126), 
	VR_II FLOAT(126), 
	VR_ISSQNE FLOAT(126), 
	VR_FRETE FLOAT(126), 
	VR_SEGURO FLOAT(126), 
	VR_DESCONTOS FLOAT(126), 
	VR_OUTRAS_DESP FLOAT(126), 
	VR_DESPESAS_ADU FLOAT(126), 
	VR_COMISSOES FLOAT(126), 
	VR_CUSTO_VARIAVEL FLOAT(126), 
	NRPEDIDO VARCHAR2(10), 
	NRITEMPED VARCHAR2(10), 
	NRSEQITPROD VARCHAR2(4), 
	CDPRECOBASE VARCHAR2(2),
	NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FAT_PRODVEND CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          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 FATURAMENTO_DESPESACLI(
	DSDATA DATE, 
	DSMES_ANO VARCHAR2(7), 
	ORDANOMES VARCHAR2(6), 
	DSANO VARCHAR2(4), 
	DSMES VARCHAR2(2), 
	DSBIMESTRE VARCHAR2(45), 
	DSTRIMESTRE VARCHAR2(45), 
	DSSEMESTRE VARCHAR2(45), 
	DSQUADRIMESTRE VARCHAR2(45), 
	DTEMISSAO DATE, 
	NRLANCTONF VARCHAR2(20), 
	NRNOTAFISC VARCHAR2(20), 
	CDEMPRESA VARCHAR2(2), 
	NMEMPRESA VARCHAR2(40), 
	NMRAZSOCEMPR VARCHAR2(80), 
	CDMACROREGIAO CHAR(3), 
	NMMACROREGIAO VARCHAR2(35), 
	CDMICROREGIAO VARCHAR2(3), 
	NMMICROREGIAO VARCHAR2(50), 
	CDVENDEDOR VARCHAR2(4), 
	NMVENDEDOR VARCHAR2(50), 
	SGESTADO VARCHAR2(2), 
	NMESTADO VARCHAR2(30), 
	CDMUNICIPIO VARCHAR2(4), 
	NMMUNICIPIO VARCHAR2(30), 
	CDFILIAL VARCHAR2(4), 
	NMFILIAL VARCHAR2(30), 
	CDCLIENTE VARCHAR2(21), 
	NMRAZSOCCLIE VARCHAR2(100), 
	NMFANTCLIE VARCHAR2(100), 
	NRINSJURCLIE VARCHAR2(20), 
	CDSEGMER VARCHAR2(5), 
	DSSEGMER VARCHAR2(40), 
	CDGRUPCLIE VARCHAR2(10), 
	NMGRUPCLIE VARCHAR2(50), 
	CDATIVCLI VARCHAR2(10), 
	DSATIVCLI VARCHAR2(50), 
	VRFRETE FLOAT(126), 
	VRINCENTIVOS FLOAT(126), 
	VRMARKETING FLOAT(126), 
	VRDESPESAS FLOAT(126), 
	VRINCENTIVOSDOC FLOAT(126), 
	VRMARKETINGDOC FLOAT(126), 
	VRDESPESASDOC FLOAT(126), 
	DSDESCRICAO VARCHAR2(600), 
	DSITEM VARCHAR2(100), 
	VRVALOR FLOAT(126), 
	IDTPDESPESA VARCHAR2(20),
	NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FAT_DESPESACLI CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          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 PAR_CTB_DESPESAS(	
	IDTPDESPESA VARCHAR2(20), 
	CDCONTCTBL VARCHAR2(20), 
	IDDESPESA VARCHAR2(3), 
	DSTPDESPESA VARCHAR2(100),
    NRORG             NUMBER 	      DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_PAR_CTB_DESPESAS CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          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 CARTEIRA_DE_PEDIDOS (
	DSDATA DATE, 
	DSMES_ANO VARCHAR2(7), 
	ORDANOMES VARCHAR2(6), 
	DSANO VARCHAR2(4), 
	DSMES VARCHAR2(2), 
	DSBIMESTRE VARCHAR2(45), 
	DSTRIMESTRE VARCHAR2(45), 
	DSSEMESTRE VARCHAR2(45), 
	DSQUADRIMESTRE VARCHAR2(45), 
	DTPEDIDO DATE, 
	CDFILIAL VARCHAR2(4), 
	DTENTPED DATE, 
	QTITEMPED FLOAT(126), 
	VRPREUNITPED FLOAT(126), 
	NRPEDIDO VARCHAR2(10), 
	CDARVPROD VARCHAR2(20), 
	CDPRODUTO VARCHAR2(10), 
	NMPRODUTO VARCHAR2(50), 
	CDCLIENTE VARCHAR2(21), 
	NMRAZSOCCLIE VARCHAR2(100), 
	NMFANTCLIE VARCHAR2(100), 
	NMFILIAL VARCHAR2(30), 
	CDSEGMER VARCHAR2(5), 
	DSSEGMER VARCHAR2(40), 
	CDGRUPCLIE VARCHAR2(10), 
	NMGRUPCLIE VARCHAR2(50), 
	CDATIVCLI VARCHAR2(10), 
	DSATIVCLI VARCHAR2(50), 
	CDVENDEDOR VARCHAR2(4), 
	NMVENDEDOR VARCHAR2(50), 
	CDGRUPPROD VARCHAR2(10), 
	NMGRUPPROD VARCHAR2(40), 
	CDSUBGRPROD VARCHAR2(10), 
	NMSUBGRPROD VARCHAR2(40), 
	SGESTADO VARCHAR2(2), 
	NMESTADO VARCHAR2(30), 
	CDMUNICIPIO VARCHAR2(4), 
	NMMUNICIPIO VARCHAR2(30), 
	CDEMPRESA VARCHAR2(2), 
	NMEMPRESA VARCHAR2(40), 
	NMRAZSOCEMPR VARCHAR2(80), 
	CDMACROREGIAO CHAR(3), 
	NMMACROREGIAO VARCHAR2(35), 
	CDMICROREGIAO VARCHAR2(3), 
	NMMICROREGIAO VARCHAR2(50), 
	IDSITPED VARCHAR2(30),  
	NRITEMPED VARCHAR2(10), 
	VRBRUTITEMPED FLOAT(126),
	NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_CARTEIRA_DE_PED CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          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 RECEITA_MENSAL(
	DSDATA DATE, 
	DSMES_ANO VARCHAR2(7), 
	ORDANOMES VARCHAR2(6), 
	DSANO VARCHAR2(4), 
	DSMES VARCHAR2(2), 
	DSBIMESTRE VARCHAR2(45), 
	DSTRIMESTRE VARCHAR2(45), 
	DSSEMESTRE VARCHAR2(45), 
	DSQUADRIMESTRE VARCHAR2(45), 
	VRSEGURO FLOAT(126), 
	VRFRETE FLOAT(126), 
	VRINCENTIVOS FLOAT(126), 
	VRMARKETING FLOAT(126), 
	VRDESPESAS FLOAT(126), 
	VR_CUSTO_VARIAVEL FLOAT(126), 
	QT_OBJETIVO_FIS FLOAT(126), 
	QT_OBJETIVO_FIN FLOAT(126), 
	QT_PRODUTO FLOAT(126), 
	VR_BRUTITEM FLOAT(126), 
	VR_FECP FLOAT(126), 
	VR_IPI FLOAT(126), 
	VR_ICMS FLOAT(126), 
	VR_ICMSST FLOAT(126), 
	VR_PIS FLOAT(126), 
	VR_COFINS FLOAT(126), 
	VR_COMISSOES FLOAT(126),
	NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_RECEITA_MENSAL CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          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 ROMANEIO_NF(
	DSDATA DATE, 
	DSMES_ANO VARCHAR2(7), 
	ORDANOMES VARCHAR2(6), 
	DSANO VARCHAR2(4), 
	DSMES VARCHAR2(2), 
	DSBIMESTRE VARCHAR2(45), 
	DSTRIMESTRE VARCHAR2(45), 
	DSSEMESTRE VARCHAR2(45), 
	DSQUADRIMESTRE VARCHAR2(45), 
	DTEMISSAO DATE, 
	NRLANCTONF VARCHAR2(10), 
	NRNOTAFISC VARCHAR2(20), 
	CDTIPOOPER VARCHAR2(2), 
	NMTIPOOPER VARCHAR2(30), 
	NRPEDIDO VARCHAR2(10), 
	CDEMPRESA VARCHAR2(2), 
	NMEMPRESA VARCHAR2(40), 
	NMRAZSOCEMPR VARCHAR2(80), 
	CDMACROREGIAO CHAR(3), 
	NMMACROREGIAO VARCHAR2(35), 
	CDMICROREGIAO VARCHAR2(3), 
	NMMICROREGIAO VARCHAR2(50), 
	CDVENDEDOR VARCHAR2(4), 
	NMVENDEDOR VARCHAR2(50), 
	SGESTADO VARCHAR2(2), 
	NMESTADO VARCHAR2(30), 
	CDMUNICIPIO VARCHAR2(4), 
	NMMUNICIPIO VARCHAR2(30), 
	CDFILIAL VARCHAR2(4), 
	NMFILIAL VARCHAR2(30), 
	CDCLIENTE VARCHAR2(21), 
	NMRAZSOCCLIE VARCHAR2(100), 
	NMFANTCLIE VARCHAR2(100), 
	NRINSJURCLIE VARCHAR2(20), 
	CDSEGMER VARCHAR2(5), 
	DSSEGMER VARCHAR2(40), 
	CDGRUPCLIE VARCHAR2(10), 
	NMGRUPCLIE VARCHAR2(50), 
	CDATIVCLI VARCHAR2(10), 
	DSATIVCLI VARCHAR2(50), 
	CDGRUPPROD VARCHAR2(10), 
	NMGRUPPROD VARCHAR2(40), 
	CDSUBGRPROD VARCHAR2(10), 
	NMSUBGRPROD VARCHAR2(40), 
	CDPRODUTO VARCHAR2(10), 
	CDARVPROD VARCHAR2(20), 
	NMPRODUTO VARCHAR2(50), 
	QT_PRODUTO FLOAT(126), 
	VR_BRUTITEM FLOAT(126), 
	QT_OBJETIVO_FIS FLOAT(126), 
	QT_OBJETIVO_FIN FLOAT(126), 
	VR_FECP FLOAT(126), 
	VR_IPI FLOAT(126), 
	VR_ICMS FLOAT(126), 
	VR_ICMSST FLOAT(126), 
	VR_PIS FLOAT(126), 
	VR_PISST FLOAT(126), 
	VR_COFINS FLOAT(126), 
	VR_COFINS_ST FLOAT(126), 
	VR_II FLOAT(126), 
	VR_ISSQNE FLOAT(126), 
	VR_FRETE FLOAT(126), 
	VR_SEGURO FLOAT(126), 
	VR_DESCONTOS FLOAT(126), 
	VR_OUTRAS_DESP FLOAT(126), 
	VR_DESPESAS_ADU FLOAT(126), 
	VR_COMISSOES FLOAT(126), 
	VR_CUSTO_VARIAVEL FLOAT(126),
	NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_ROMANEIO_NF CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          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 FAT_RESUMO_RESULTADO(
	NMORGANIZACAO VARCHAR2(250), 
	DSANO VARCHAR2(4), 
	DSSEMESTRE VARCHAR2(20), 
	DSTRIMESTRE VARCHAR2(20), 
	DSBIMESTRE VARCHAR2(20), 
	DSQUADRIMESTRE VARCHAR2(45), 
	DSMES VARCHAR2(20), 
	DSMES_ANO VARCHAR2(20), 
	IDTIPORESULT VARCHAR2(20), 
	ORDANOMES VARCHAR2(20), 
	ORD_ITEM VARCHAR2(20), 
	DSDATA DATE, 
	DSITEM VARCHAR2(100), 
	VR_ITEM FLOAT(126), 
	VR_PERC_RECBRUT FLOAT(126),
	NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FAT_RESUMO_RESULT CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          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 FAT_RESUMO_RESULTADO_EMP(
	NMORGANIZACAO VARCHAR2(250), 
	CDEMPRESA VARCHAR2(2), 
	NMEMPRESA VARCHAR2(40), 
	DSANO VARCHAR2(4), 
	DSSEMESTRE VARCHAR2(20), 
	DSTRIMESTRE VARCHAR2(20), 
	DSBIMESTRE VARCHAR2(20), 
	DSQUADRIMESTRE VARCHAR2(45), 
	DSMES VARCHAR2(20), 
	DSMES_ANO VARCHAR2(20), 
	IDTIPORESULT VARCHAR2(20), 
	ORDANOMES VARCHAR2(20), 
	ORD_ITEM VARCHAR2(20), 
	DSDATA DATE, 
	DSITEM VARCHAR2(100), 
	VR_ITEM FLOAT(126), 
	VR_PERC_RECBRUT FLOAT(126),
	NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FAT_RESU_RST_EMP CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          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 FAT_RESUMO_RESULTADO_MAC(
	NMORGANIZACAO VARCHAR2(250), 
	CDEMPRESA VARCHAR2(2), 
	NMEMPRESA VARCHAR2(40), 
	CDMACROREGIAO VARCHAR2(20), 
	NMMACROREGIAO VARCHAR2(100), 
	DSANO VARCHAR2(4), 
	DSSEMESTRE VARCHAR2(20), 
	DSTRIMESTRE VARCHAR2(20), 
	DSBIMESTRE VARCHAR2(20), 
	DSQUADRIMESTRE VARCHAR2(45), 
	DSMES VARCHAR2(20), 
	DSMES_ANO VARCHAR2(20), 
	IDTIPORESULT VARCHAR2(20), 
	ORDANOMES VARCHAR2(20), 
	ORD_ITEM VARCHAR2(20), 
	DSDATA DATE, 
	DSITEM VARCHAR2(100), 
	VR_ITEM FLOAT(126), 
	VR_PERC_RECBRUT FLOAT(126),
	NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FAT_RESU_RST_MAC CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          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 FAT_RESUMO_RESULTADO_UF(
	NMORGANIZACAO VARCHAR2(250), 
	CDEMPRESA VARCHAR2(2), 
	NMEMPRESA VARCHAR2(40), 
	CDMACROREGIAO VARCHAR2(20), 
	NMMACROREGIAO VARCHAR2(100), 
	SGESTADO VARCHAR2(2), 
	NMESTADO VARCHAR2(30), 
	DSANO VARCHAR2(4), 
	DSSEMESTRE VARCHAR2(20), 
	DSTRIMESTRE VARCHAR2(20), 
	DSBIMESTRE VARCHAR2(20), 
	DSQUADRIMESTRE VARCHAR2(45), 
	DSMES VARCHAR2(20), 
	DSMES_ANO VARCHAR2(20), 
	IDTIPORESULT VARCHAR2(20), 
	ORDANOMES VARCHAR2(20), 
	ORD_ITEM VARCHAR2(20), 
	DSDATA DATE, 
	DSITEM VARCHAR2(100), 
	VR_ITEM FLOAT(126), 
	VR_PERC_RECBRUT FLOAT(126),
	NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FAT_RESU_RST_UF CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          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 FAT_RESUMO_RESULTADO_VEN(
	NMORGANIZACAO VARCHAR2(250), 
	CDEMPRESA VARCHAR2(2), 
	NMEMPRESA VARCHAR2(40), 
	CDMACROREGIAO VARCHAR2(20), 
	NMMACROREGIAO VARCHAR2(100), 
	SGESTADO VARCHAR2(2), 
	NMESTADO VARCHAR2(30), 
	CDVENDEDOR VARCHAR2(4), 
	NMVENDEDOR VARCHAR2(50), 
	DSANO VARCHAR2(4), 
	DSSEMESTRE VARCHAR2(20), 
	DSTRIMESTRE VARCHAR2(20), 
	DSBIMESTRE VARCHAR2(20), 
	DSQUADRIMESTRE VARCHAR2(45), 
	DSMES VARCHAR2(20), 
	DSMES_ANO VARCHAR2(20), 
	IDTIPORESULT VARCHAR2(20), 
	ORDANOMES VARCHAR2(20), 
	ORD_ITEM VARCHAR2(20), 
	DSDATA DATE, 
	DSITEM VARCHAR2(100), 
	VR_ITEM FLOAT(126), 
	VR_PERC_RECBRUT FLOAT(126),
	NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FAT_RESU_RST_VEN CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          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 FAT_RESUMO_RESULTADO_MIC(
	
	NMORGANIZACAO VARCHAR2(250), 
	CDEMPRESA VARCHAR2(2), 
	NMEMPRESA VARCHAR2(40), 
	CDMACROREGIAO VARCHAR2(20), 
	NMMACROREGIAO VARCHAR2(100), 
	SGESTADO VARCHAR2(2), 
	NMESTADO VARCHAR2(30), 
	CDVENDEDOR VARCHAR2(4), 
	NMVENDEDOR VARCHAR2(50), 
	CDMICROREGIAO VARCHAR2(100), 
	NMMICROREGIAO VARCHAR2(100), 
	DSANO VARCHAR2(4), 
	DSSEMESTRE VARCHAR2(20), 
	DSTRIMESTRE VARCHAR2(20), 
	DSBIMESTRE VARCHAR2(20), 
	DSQUADRIMESTRE VARCHAR2(45), 
	DSMES VARCHAR2(20), 
	DSMES_ANO VARCHAR2(20), 
	IDTIPORESULT VARCHAR2(20), 
	ORDANOMES VARCHAR2(20), 
	ORD_ITEM VARCHAR2(20), 
	DSDATA DATE, 
	DSITEM VARCHAR2(100), 
	VR_ITEM FLOAT(126), 
	VR_PERC_RECBRUT FLOAT(126),
	NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FAT_RESU_RST_MIC CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          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 FAT_RESUMO_RESULTADO_CLI(	
	NMORGANIZACAO VARCHAR2(250), 
	CDEMPRESA VARCHAR2(2), 
	NMEMPRESA VARCHAR2(40), 
	CDMACROREGIAO VARCHAR2(20), 
	NMMACROREGIAO VARCHAR2(100), 
	SGESTADO VARCHAR2(2), 
	NMESTADO VARCHAR2(30), 
	CDVENDEDOR VARCHAR2(4), 
	NMVENDEDOR VARCHAR2(50), 
	CDMICROREGIAO VARCHAR2(100), 
	NMMICROREGIAO VARCHAR2(100), 
	CDCLIENTE VARCHAR2(21), 
	NMRAZSOCCLIE VARCHAR2(100), 
	NMFANTCLIE VARCHAR2(50), 
	NRINSJURCLIE VARCHAR2(20), 
	DSANO VARCHAR2(4), 
	DSSEMESTRE VARCHAR2(20), 
	DSTRIMESTRE VARCHAR2(20), 
	DSBIMESTRE VARCHAR2(20), 
	DSQUADRIMESTRE VARCHAR2(45), 
	DSMES VARCHAR2(20), 
	DSMES_ANO VARCHAR2(20), 
	IDTIPORESULT VARCHAR2(20), 
	ORDANOMES VARCHAR2(20), 
	ORD_ITEM VARCHAR2(20), 
	DSDATA DATE, 
	DSITEM VARCHAR2(100), 
	VR_ITEM FLOAT(126), 
	VR_PERC_RECBRUT FLOAT(126),
	   NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_FAT_RESU_RST_CLI CHECK (IDATIVO IN ('S','N')),
   DTINCLUSAO        DATE                  			NULL,
   DTULTATU          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 MACROREGIAO
(
	CDMACROREGIAO      VARCHAR2(3),      
	NMMACROREGIAO      VARCHAR2(40),
		CONSTRAINT PK_MACROREGIAO PRIMARY KEY (CDMACROREGIAO),
	NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_MACROREGIAO CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          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 REGIAOPED ADD CDMACROREGIAO VARCHAR2(3)
/

ALTER TABLE REGIAOPED ADD NMMACROREGIAO VARCHAR2(40)
/

CREATE TABLE CENTCUSTREGPED
(
	CDREGIAOPED    VARCHAR2(3) NOT NULL,    
	NMREGIAOPED    VARCHAR2(50) NOT NULL, 
	CDCENTCUST     VARCHAR2(4) NOT NULL,  
	NMCENTCUST     VARCHAR2(40) NOT NULL, 
		CONSTRAINT PK_CENTCUSTREGPED PRIMARY KEY (CDREGIAOPED, CDCENTCUST),
	NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_CENTCUSTREGPED CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          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 CARTEIRA_DE_CLIENTES 
  (
   	DSDATA DATE, 
	DSMES_ANO VARCHAR2(7), 
	ORDANOMES VARCHAR2(6), 
	DSANO VARCHAR2(4), 
	DSMES VARCHAR2(2), 
	DSBIMESTRE VARCHAR2(45), 
	DSTRIMESTRE VARCHAR2(45), 
	DSSEMESTRE VARCHAR2(45), 
	DSQUADRIMESTRE VARCHAR2(45), 
	CDCLIENTE VARCHAR2(21), 
	NMRAZSOCCLIE VARCHAR2(100), 
	NMFANTCLIE VARCHAR2(100), 
	SGESTADO VARCHAR2(2), 
	NMESTADO VARCHAR2(30), 
	CDMUNICIPIO VARCHAR2(4), 
	NMMUNICIPIO VARCHAR2(30), 
	CDMICROREGIAO VARCHAR2(3), 
	NMMICROREGIAO VARCHAR2(50), 
	CDMACROREGIAO VARCHAR2(20), 
	NMMACROREGIAO VARCHAR2(35), 
	CDSEGMER VARCHAR2(5), 
	DSSEGMER VARCHAR2(40), 
	CDGRUPCLIE VARCHAR2(10), 
	NMGRUPCLIE VARCHAR2(50), 
	CDATIVCLI VARCHAR2(10), 
	DSATIVCLI VARCHAR2(50), 
	CLI_INAT FLOAT(126), 
	CLI_ATIV FLOAT(126), 
	CLI_COM_COMPRA FLOAT(126), 
	CLI_SEM_COMPRA FLOAT(126),
	NRORG             NUMBER 	     DEFAULT         SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_CART_DE_CLIENT CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO        DATE                  			NULL,
    DTULTATU          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'
   )
  /