-- ============================================================
--   DBMS NAME:      ORACLE VERSION 7.X
--   CREATED ON:     25/08/97  10:22
--   PROGRAMADOR:    LUCIANA CORREA
-- ============================================================
--   VIEW: MAPA_VIEW
-- ============================================================
CREATE OR REPLACE VIEW MAPA_VIEW
(NRMAPABASEV,CDEQUIPPRO, DTMAPABASEV, VRENTREGUE,VRDEVOLVIDO,VRSANGRIA, VRABASTECIDO) AS
SELECT ENT.NRMAPABASEV,ENT.CDEQUIPPRO, ENT.DTMAPABASEV, ENT.VALOR AS VRENTREGUE,
       DEV.VALOR AS VRDEVOLVIDO,SAN.VALOR AS VRSANGRIA, ABA.VALOR AS VRABASTECIDO
FROM
(SELECT MP.CDEQUIPPRO, MP.DTMAPABASEV, MP.NRMAPABASEV, SUM(MV.VRMOVIVALOR) AS VALOR
FROM  MOVIVALOR MV, MAPABASEV MP
WHERE MV.IDTIPMOVIVLR(+) = '4'
  AND MV.NRMAPABASEV(+)  = MP.NRMAPABASEV
  AND MV.CDFILIAL   (+)  = MP.CDFILIAL
GROUP BY MP.CDEQUIPPRO, MP.DTMAPABASEV,MP.NRMAPABASEV) ENT,
(SELECT MP.CDEQUIPPRO, MP.DTMAPABASEV, MP.NRMAPABASEV,SUM(MV.VRMOVIVALOR) AS VALOR
FROM  MOVIVALOR MV, MAPABASEV MP
WHERE MV.IDTIPMOVIVLR(+) = '5'
  AND MV.NRMAPABASEV(+) = MP.NRMAPABASEV
  AND MV.CDFILIAL   (+) = MP.CDFILIAL
GROUP BY MP.CDEQUIPPRO, MP.DTMAPABASEV , MP.NRMAPABASEV) DEV,
(SELECT MP.CDEQUIPPRO, MP.DTMAPABASEV, MP.NRMAPABASEV,SUM(MV.VRMOVIVALOR) AS VALOR
FROM  MOVIVALOR MV, MAPABASEV MP
WHERE MV.IDTIPMOVIVLR(+) = '2'
  AND MV.NRMAPABASEV(+) = MP.NRMAPABASEV
  AND MV.CDFILIAL   (+) = MP.CDFILIAL
GROUP BY MP.CDEQUIPPRO, MP.DTMAPABASEV, MP.NRMAPABASEV) SAN,
(SELECT MP.CDEQUIPPRO, MP.DTMAPABASEV, MP.NRMAPABASEV, SUM((TR.QTSALDTROCMA - TR.QTINITROCMA) * NU.VRNUMERARIO) AS VALOR
FROM TROCOMAPABAS TR, NUMERARIO NU, MAPABASEV MP
WHERE TR.CDNUMERARIO = NU.CDNUMERARIO(+)
  AND MP.CDFILIAL    = TR.CDFILIAL(+)
  AND MP.NRMAPABASEV = TR.NRMAPABASEV(+)
GROUP BY MP.CDEQUIPPRO, MP.DTMAPABASEV, MP.NRMAPABASEV) ABA
WHERE ENT.NRMAPABASEV = DEV.NRMAPABASEV AND
      ENT.NRMAPABASEV = SAN.NRMAPABASEV AND
      ENT.NRMAPABASEV = ABA.NRMAPABASEV
/
