CREATE TABLE RELAT_ANALMOVI_ANALI 
(
   CDFILIAL           	VARCHAR2(4)  NOT NULL,
   IDSALDOESTAN       	VARCHAR2(2)  NOT NULL,
   CDTIPORETIAN       	VARCHAR2(2)  NOT NULL,
   IDENTRSAIDAN      	VARCHAR2(1)  NOT NULL,
   CDTIPOOPERAN      	VARCHAR2(2)  NOT NULL,
   VRSALDOESTAN      	FLOAT   ,
   QTSALDOESTAN       	FLOAT   ,
   NMTIPORETIAN       	VARCHAR2(40) ,
   CDALMOXARIFE       	VARCHAR2(6)  ,
   CDLOCALESTOQ       	VARCHAR2(6),
   NRORG              	NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO            	VARCHAR2(1)     DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_RELATANMOVAN 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',
		CONSTRAINT PK_RELAT_ANALMOVI_ANALI primary key (CDFILIAL, IDSALDOESTAN, CDTIPORETIAN, IDENTRSAIDAN, CDTIPOOPERAN)
)
/

CREATE TABLE RELAT_TOTAMOVI_ANALI
(
    CDFILIAL           VARCHAR2(4)  NOT NULL,
    CDPRODTOTAMOVI     VARCHAR2(20) NOT NULL,
    CDALMOXARIFE       VARCHAR2(6)  NOT NULL,
    CDLOCALESTOQ       VARCHAR2(6)  NOT NULL,
    IDTIPOTOTAMOVI     VARCHAR2(1)  NOT NULL,
    VRSOMPINI          FLOAT   ,
    VRSOMAINV          FLOAT   ,
    VRSOMINVE          FLOAT   ,
    VRSOMENTR          FLOAT   ,
    VRSOMRETI          FLOAT   ,
    VRSOMSAID          FLOAT   ,
    VRSOMDFOR          FLOAT   ,
    VRSOMSATU          FLOAT   ,
    SGUNIDTOTAME       VARCHAR2(10) ,
    VRQTDEPINIME       FLOAT   ,
    VRQTDEAINVME       FLOAT   ,
    VRQTDEINVEME       FLOAT   ,
    VRQTDEENTRME       FLOAT   ,
    VRQTDERETIME       FLOAT   ,
    VRQTDESAIDME       FLOAT   ,
    VRQTDEDFORME       FLOAT   ,
    VRQTDESATUME       FLOAT   ,
    VRSOMCUSTLOG       FLOAT   ,
    VRSOMCUSTSEG       FLOAT   ,
    VRPESOTOTAME       FLOAT   ,
    VRSOMDIFSAID       FLOAT  ,
    NRORG              	NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO            	VARCHAR2(1)     DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_RELTOTMOVAN 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',
		CONSTRAINT PK_RELAT_TOTAMOVI_ANALI primary key (CDFILIAL, CDPRODTOTAMOVI, CDALMOXARIFE, CDLOCALESTOQ, IDTIPOTOTAMOVI)
)
/

CREATE TABLE RELAT_MOVIEST_ANALI
(
    CDFILLANCMEST       VARCHAR2(4)            NOT NULL,
    NRLANCMOVIEST       VARCHAR2(10)           NOT NULL,
    NRSEQUMOVIEST       VARCHAR2(4)            NOT NULL,
    NRLOTEESTQME        VARCHAR2(20)           NOT NULL,
    NRSUBLOTEME         VARCHAR2(4)            NOT NULL,
    CDPRODUTO           VARCHAR2(20)           NOT NULL,
    CDPRODMOVIEST       VARCHAR2(20)           NOT NULL,
    DTLANCMOVIEST       DATE                   NOT NULL,
    CDALMOXARIRM        VARCHAR2(6)            NOT NULL,
    CDLOCALESTRM        VARCHAR2(6)            NOT NULL,
    CDFILIMOVIEST       VARCHAR2(4)            NOT NULL,
    IDTIPOMOVIEST       VARCHAR2(1)            NOT NULL,
    QTDEMOVIEST         FLOAT                  NULL    ,
    QTLANCAMENTO        FLOAT                  NULL    ,
    QTLANCMOVIEST       FLOAT                  NULL    ,
    IDORDEMCALC         VARCHAR2(1)            NULL    ,
    IDALTCMEDMOV        VARCHAR2(1)            NULL    ,
    QTTOTALANT          FLOAT                  NULL    ,
    IDENTRSAIDME        VARCHAR2(1)            NULL    ,
    CDTIPOOPERME        VARCHAR2(2)            NULL    ,
    VRCUSTMEDI          FLOAT                  NULL    ,
    VRCUSTMOVIEST       FLOAT                  NULL    ,
    VRCUSTBRUT          FLOAT                  NULL    ,
    VRCUSTMEES          FLOAT                  NULL    ,
    VRCUSTMEBR          FLOAT                  NULL    ,
    VRLANCMOVIEST       FLOAT                  NULL,
    VRBRUTMOVIEST       FLOAT                  NULL,
    VRUNILANCEST        FLOAT                  NULL,
    VRTOTLANCEST        FLOAT                  NULL,
    VRTOTALANT          FLOAT                  NULL,
    VRCUSTENTRME        FLOAT                  NULL,
    VRCUSTLOGLME        FLOAT                  NULL,
    VRCUSTSEGLME        FLOAT                  NULL,
    VRCUSTLOGEME        FLOAT                  NULL,
    VRCUSTSEGEME        FLOAT                  NULL,
    VRPESOBRUTME        FLOAT                  NULL,
    VRDIFCUSTEME        FLOAT                  NULL,
    VRDIFECUST          FLOAT               NULL,
    CDTOTMOVIEST        VARCHAR2(20)        NULL,
    NMPRODMOVIEST       VARCHAR2(50)        NULL,
    SGUNIDMOVI          VARCHAR2(10)        NULL,
    NMTIPORETIME        VARCHAR2(40)        NULL,
		CONSTRAINT CKC_IDENTRSAIDME_MOVIEST_ANALI CHECK (IDENTRSAIDME IS NULL OR (IDENTRSAIDME IN ('E','S','-'))),
    CDTIPORETIME        VARCHAR2(2)            NULL    ,
    NRORG              	NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
    IDATIVO            	VARCHAR2(1)     DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_RELMOVESTAN 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',
		CONSTRAINT PK_RELAT_MOVIEST_ANALI PRIMARY KEY (CDFILIMOVIEST, CDFILLANCMEST, NRLANCMOVIEST, NRSEQUMOVIEST, NRLOTEESTQME, NRSUBLOTEME, CDPRODMOVIEST, DTLANCMOVIEST, CDALMOXARIRM, CDLOCALESTRM)
)
/
CREATE INDEX RELAT_MOVIEST_ANALI_01 ON RELAT_MOVIEST_ANALI (IDTIPOMOVIEST ASC, QTLANCAMENTO ASC)
/
CREATE INDEX RELAT_MOVIEST_ANALI_02 ON RELAT_MOVIEST_ANALI (IDTIPOMOVIEST ASC, CDFILIMOVIEST ASC, NRLANCMOVIEST ASC, NRSEQUMOVIEST ASC, QTTOTALANT ASC)
/
ALTER TABLE PARAMESTOQUE ADD NRMESANTEMOVIEST NUMBER(10) NULL
/
ALTER TABLE PARAMESTOQUE ADD DTMOVIESTINI DATE NULL
/
ALTER TABLE PARAMESTOQUE ADD DTMOVIESTFIN DATE NULL
/
ALTER TABLE PARAMESTOQUE ADD HRAGEMOVIEST VARCHAR2(5) 