CREATE VIEW vw_apontprod(
  DOCTIP_CODIGO
, DOCCAB_NUMERO
, PALETE_BARCODE
, PRDCAD_CODIGO
, INVAPO_QDE
, UOMCAD_CODIGO
, INVAPO_QDEPRI
, UOMCAD_CODPRI
, DATA_APONT
, HORA_APONT
, USER_APONT
, DATA_TRANSF
, HORA_TRANSF
, USER_TRANSF
, DATA_RECEB
, HORA_RECEB
, USER_RECEB
, TRANS_CODIGO
, DOCCAB_STATUS
, INVAPO_STATUS
, EMPRES_CODIGO
, FILIAL_CODIGO
, PRDCAD_DESCRICAO) AS
SELECT DISTINCT
       D.DOCTIP_CODIGO AS DOCTIP_CODIGO
     , D.DOCCAB_NUMERO AS DOCCAB_NUMERO
     , P.PALETE_BARCODE AS PALETE_BARCODE
     , I1.PRDCAD_CODIGO AS PRDCAD_CODIGO
     , I1.INVAPO_QDE AS INVAPO_QDE
     , I1.UOMCAD_CODIGO AS UOMCAD_CODIGO
     , I1.INVAPO_QDEPRI AS INVAPO_QDEPRI
     , I1.UOMCAD_CODPRI AS UOMCAD_CODPRI
     , I1.INVAPO_DATA AS DATA_APONT
     , I1.INVAPO_HORA AS HORA_APONT
     , I1.USUCAD_CODIGO AS USER_APONT
     , I2.INVAPO_DATA AS DATA_TRANSF
     , I2.INVAPO_HORA AS HORA_TRANSF
     , I2.USUCAD_CODIGO AS USER_TRANSF
     , I3.INVAPO_DATA AS DATA_RECEB
     , I3.INVAPO_HORA AS HORA_RECEB
     , I3.USUCAD_CODIGO AS USER_RECEB
     , I1.TRANS_CODIGO AS TRANS_CODIGO
     , D.DOCCAB_STATUS AS DOCCAB_STATUS
     , I1.INVAPO_STATUS AS INVAPO_STATUS
     , D.EMPRES_CODIGO AS EMPRES_CODIGO
     , D.FILIAL_CODIGO AS FILIAL_CODIGO
     , PR.PRDCAD_DESCRICAO AS PRDCAD_DESCRICAO
    FROM invapo I1
  LEFT JOIN doccab D ON (I1.DOCCAB_SEQ = D.DOCCAB_SEQ)
  LEFT JOIN palete P ON (I1.PALETE_SEQ = P.PALETE_SEQ)
  LEFT JOIN invapo I2 ON (I1.PALETE_SEQ = I2.PALETE_SEQ AND
                          I2.TRANS_CODIGO = 5002)
  LEFT JOIN invapo I3 ON (I1.PALETE_SEQ = I3.PALETE_SEQ AND
                          I3.TRANS_CODIGO = 5003)
  LEFT JOIN prdcad PR ON (I1.PRDCAD_CODIGO = PR.PRDCAD_CODIGO AND
			  D.EMPRES_CODIGO = PR.EMPRES_CODIGO AND
			  D.FILIAL_CODIGO = PR.FILIAL_CODIGO)