CREATE OR REPLACE FUNCTION CUSTO_LOGISTICA_MDR(
   P_CDFILIAL   IN FILIAL.CDFILIAL%TYPE,
   P_NRLANCTONF IN NOTAFISCAL.NRLANCTONF%TYPE)RETURN NUMBER
AS
  V_CUSTOLOG NUMBER;
BEGIN
   SELECT SUM(CUSTLOG + VRSEGU)
   INTO V_CUSTOLOG
   FROM
      (SELECT ROUND(SUM(NVL(I.VRCUSTLOGLAN,0)),2) AS CUSTLOG,
              ROUND(SUM(NVL(I.VRSEGULOGLAN,0)),2) AS VRSEGU
        FROM LANCTOESTOQ L, ITLANCTOEST I
       WHERE L.CDFILIAL   = P_CDFILIAL    AND
             L.NRLANCTONF = P_NRLANCTONF  AND
             L.CDFILIAL   = I.CDFILIAL    AND
             L.NRLANCESTQ = I.NRLANCESTQ);

   RETURN (V_CUSTOLOG);
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('CUSTO_LOGISTICA_MDR','5.01.003'); END;
/

