create or replace FUNCTION BUSCA_IMPOSTO_ICMSST_ITEM(
   P_CDFILIAL     IN ITEMPRODUTO.CDFILIAL%TYPE,
   P_NRLANCTONF   IN ITEMPRODUTO.NRLANCTONF%TYPE,
   P_NRSEQITPROD  IN ITEMPRODUTO.NRSEQITPROD%TYPE) RETURN NUMBER

AS
   V_VRIMPOSTOIT ITEMPROIMPOS.VRIMPOSTOIT%TYPE;
BEGIN
   SELECT NVL(SUM(IP.VRIMPOSTOIT),0) AS VRIMPOSTOIT
     INTO V_VRIMPOSTOIT
     FROM IMPOSTO I, IMPOSTONFE IM, ITEMPROIMPOS IP
    WHERE IM.CDIMPOSTONFE = '80'
      AND IM.CDIMPOSTONFE = I.CDIMPOSTONFE
      AND I.CDIMPOSTO = IP.CDIMPOSTO
      AND IP.CDFILIAL = P_CDFILIAL
      AND IP.NRLANCTONF = P_NRLANCTONF
      AND IP.NRSEQITPROD = P_NRSEQITPROD
      AND IP.IDIMPDESONERAIT  = 'N'
      AND IP.NRITPROIMPOS = '1';

   RETURN(V_VRIMPOSTOIT);
END;
/

