CREATE TABLE RELAT_MOVIEST_K280 
(
    NRRELATMOVI         VARCHAR2(10)           NOT NULL,
    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    
	CONSTRAINT CKC_IDENTRSAIDME_MOVIEST_K280 CHECK (IDENTRSAIDME IS NULL OR (IDENTRSAIDME IN ('E','S','-'))),
    CDTIPOOPERME        VARCHAR2(2)            NULL    ,
    CDTIPORETIME        VARCHAR2(2)            NULL    ,    
   NRORG                       NUMBER DEFAULT 	 SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO                    VARCHAR2(1)     DEFAULT 'S' NOT NULL
	CONSTRAINT CKC_IDATIVO_RELMOVIESTK280 CHECK (IDATIVO IN ('S','N')),
   DTINCLUSAO             DATE                   NULL,
   DTULTATU                  DATE                  NULL,
   NRORGINCLUSAO      NUMBER             DEFAULT 1 NULL,
   CDOPERINCLUSAO    VARCHAR2(12)  DEFAULT '1' NULL,
   NRORGULTATU          NUMBER             DEFAULT 1 NULL,
   CDOPERULTATU        VARCHAR2(12)  DEFAULT '1',
	CONSTRAINT PK_RELAT_MOVIEST_K280 PRIMARY KEY (CDFILIMOVIEST, NRRELATMOVI, CDFILLANCMEST, NRLANCMOVIEST, NRSEQUMOVIEST, NRLOTEESTQME, NRSUBLOTEME, CDPRODMOVIEST, DTLANCMOVIEST, CDALMOXARIRM, CDLOCALESTRM)
)
/
CREATE INDEX RELAT_MOVIEST_K280_01 ON RELAT_MOVIEST_K280 (NRRELATMOVI ASC, IDTIPOMOVIEST ASC, QTLANCAMENTO ASC)
/
CREATE INDEX RELAT_MOVIEST_K280_02 ON RELAT_MOVIEST_K280 (NRRELATMOVI ASC, IDTIPOMOVIEST ASC, CDFILIMOVIEST ASC, NRLANCMOVIEST ASC, NRSEQUMOVIEST ASC, QTTOTALANT ASC)
/
CREATE OR REPLACE VIEW PROD_AJUSTE_FILIAL AS
   SELECT I.CDPRODUTO, P.CDARVPROD, I.CDFILIMOVI, F.CDEMPRESA, F.CDINSCESTA, MAX(I.DTLANCMOVI) AS DTLANCMOVI, TO_CHAR(DTLANCMOVI,'MM/YYYY') AS DTREFERENCIA
    FROM ITLANCTOEST I, FILIAL F, PRODUTO P
   WHERE I.IDTIPOMOVI = '1'
     AND I.CDFILIMOVI = F.CDFILIAL
     AND I.CDPRODMOVI = P.CDPRODUTO
GROUP BY I.CDPRODUTO, P.CDARVPROD, I.CDFILIMOVI, F.CDEMPRESA, F.CDINSCESTA,  TO_CHAR(DTLANCMOVI,'MM/YYYY')
/
ALTER TABLE ITMAPARECUP ADD IDDEDUCAO VARCHAR2(1) DEFAULT '9' NOT NULL 
   CONSTRAINT CKC_IDDEDU_ITMAP CHECK (IDDEDUCAO IN ('0','1','2','9'))
/
ALTER TABLE ITMAPARECUP ADD NRPROCESSO  VARCHAR2(100) NULL
/
ALTER TABLE ITMAPARECUP ADD IDORIGEMPROC  VARCHAR2(1)  DEFAULT '9' NOT NULL
   CONSTRAINT CKC_IDORIG_ITMAP CHECK (IDORIGEMPROC IN ('0','1','2','9'))
/
ALTER TABLE ITMAPARECUP ADD DSPROCESSO VARCHAR2(255) NULL