CREATE OR REPLACE PROCEDURE DASHBOARD_FIN_TITULOS_PAG AS
BEGIN
    DELETE FROM PCDTITPAGAR;

    FOR BOLET_PAG IN (
        SELECT
            BP.NRORG,
            TO_CHAR(BP.DTVENBOLPAG,'DD/MM/YYYY') DTVENBOLPAG,
            FO.NRINSJURFORN,
            FO.NMRAZSOCFORN,
            BP.NRPARCBOLPAG,
            BP.IDSTATBPAG,
            BP.VRBOLPAG,
            BP.VRFINALBPAG,
            BP.CDEMPRESA,
            E.NMEMPRESA,
            BP.CDFILIAL,
            BP.NRLANBOLPAG,
            FO.CDFORNECED
        FROM
            BOLETPAGAR BP,
            FORNECEDOR FO,
            EMPRESA E
        WHERE
            BP.CDFORNECED = FO.CDFORNECED
            AND BP.IDSTATBPAG <> 'B'
            AND BP.CDEMPRESA = E.CDEMPRESA
    ) LOOP
    
        INSERT INTO PCDTITPAGAR (
            NRORG,
            DTVENBOLPAG,
            NRINSJURFORN,
            NMRAZSOCFORN,
            NRPARCBOLPAG,
            IDSTATBPAG,
            VRBOLPAG,
            VRFINALBPAG,
            CDEMPRESA,
            NMEMPRESA,
            CDFILIAL,
            NRLANBOLPAG,
            CDFORNECED
        ) VALUES (
            BOLET_PAG.NRORG,
            BOLET_PAG.DTVENBOLPAG,
            BOLET_PAG.NRINSJURFORN,
            BOLET_PAG.NMRAZSOCFORN,
            BOLET_PAG.NRPARCBOLPAG,
            BOLET_PAG.IDSTATBPAG,
            BOLET_PAG.VRBOLPAG,
            BOLET_PAG.VRFINALBPAG,
            BOLET_PAG.CDEMPRESA,
            BOLET_PAG.NMEMPRESA,
            BOLET_PAG.CDFILIAL,
            BOLET_PAG.NRLANBOLPAG,
            BOLET_PAG.CDFORNECED
        );

    END LOOP;

END;
/