CREATE OR REPLACE PROCEDURE 
FCT_CRIA_VENCIMENTO(P_CDFILIAL VARCHAR2,
                    P_NRLANCTONF VARCHAR2, 
                    P_NRORG NUMBER)
AS 
BEGIN
 
   FOR C_VENC IN (SELECT VP.NRSEQCONTRATO,VP.DTINICOMPET, VP.DTFINCOMPET,VP.QTDIASVENCIMENTO, VP.DTVENCIMENTO, 
                         VP.VRVENCIMENTO, LPAD(TO_CHAR(ROWNUM),2, '0') AS PARCELA
                    FROM FCT_VENCPREVCONT VP, FCT_APURACAO AP
                   WHERE (AP.CDFILIAL = P_CDFILIAL)
                     AND (AP.NRLANCTONF = P_NRLANCTONF) 
                     AND (AP.NRORG = P_NRORG)
                     AND (VP.NRAPURACAO = AP.NRAPURACAO)
                     AND (VP.NRORG = AP.NRORG)
                  ORDER BY VP.DTVENCIMENTO) LOOP
       
      INSERT INTO CONTARECEBER (CDFILIAL, NRLANCTONF, NRSEQVENREC, NRPARCELAREC, QTDIASVENREC, 
                                DTORIGVENREC, VRORIGREC, DTATUAVENREC, VRATUAREC, IDSTATREC, 
                                IDCONTAIMPOSTO, NRORG)
                VALUES (P_CDFILIAL, P_NRLANCTONF, '01', C_VENC.PARCELA, C_VENC.QTDIASVENCIMENTO,
                        C_VENC.DTVENCIMENTO, C_VENC.VRVENCIMENTO, C_VENC.DTVENCIMENTO, C_VENC.VRVENCIMENTO, 'A', 
                        'N', P_NRORG);

   
   END LOOP;    
END;