CREATE OR REPLACE FUNCTION CONSULTA_FORMPGTO
( P_CDFILIAL     IN NOTAFISCAL.CDFILIAL%TYPE,
  P_NRLANCTONF   IN NOTAFISCAL.NRLANCTONF%TYPE,
  P_IDORIGDESTNF IN NOTAFISCAL.IDORIGDESTNF%TYPE) RETURN NUMBER
IS
   V_FORMAPAGAMENTO  INTEGER;
BEGIN
   IF P_IDORIGDESTNF = 'F' THEN
      SELECT DECODE(FO.IDTPFORPGTFO, NULL, 0, 1)
        INTO V_FORMAPAGAMENTO
        FROM NOTAFISCAL NF, FORNECEDOR FO
       WHERE NF.CDFORNECED = FO.CDFORNECED
         AND NF.CDFILIAL = P_CDFILIAL
         AND NF.NRLANCTONF = P_NRLANCTONF;
   ELSE
      SELECT DECODE(CL.IDTPFORPGTCL, NULL, 0, 1)
        INTO V_FORMAPAGAMENTO
        FROM NOTAFISCAL NF, CLIENTE CL
       WHERE NF.CDCLIENTE = CL.CDCLIENTE
         AND NF.CDFILIAL = P_CDFILIAL
         AND NF.NRLANCTONF = P_NRLANCTONF;
   END IF;

   RETURN(V_FORMAPAGAMENTO);
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('CONSULTA_FORMPGTO','5.05.007'); END;
/

