create or replace PROCEDURE DASHBOARD_FIN_TITULOS_REC AS 
BEGIN
    DELETE FROM PDCTITRECEBER;

    FOR BOLETO_REC IN (
        SELECT
            BR.NRORG,
            TO_CHAR(BR.DTVENBOLREC,'DD/MM/YYYY') DTVENBOLREC,
            CL.NRINSJURCLIE,
            CL.NMRAZSOCCLIE,
            BR.NRPARCBOLREC,
            BR.IDSTATBREC,
            BR.VRBOLREC,
            BR.VRFINALBREC,
            BR.CDEMPRESA,
            E.NMEMPRESA,
            BR.CDFILIAL,
            BR.NRLANBOLREC,
            CL.CDCLIENTE
        FROM
            BOLETRECEBER BR,
            CLIENTE CL,
            EMPRESA E
        WHERE
            BR.CDCLIENTE = CL.CDCLIENTE
            AND BR.IDSTATBREC <> 'B'
            AND BR.CDEMPRESA = E.CDEMPRESA
        ORDER BY
            BR.DTVENBOLREC ASC,
            CL.NMRAZSOCCLIE,
            BR.NRPARCBOLREC DESC
    ) LOOP
        INSERT INTO PDCTITRECEBER (
            NRORG,
            CDEMPRESA,
            CDFILIAL,
            DTVENBOLREC,
            NRPARCBOLREC,
            NRLANBOLREC,
            IDSTATBREC,
            VRBOLREC,
            VRFINALBREC,
            CDCLIENTE,
            NMRAZSOCCLIE,
            NRINSJURCLIE,
            NMEMPRESA
        ) VALUES (
            BOLETO_REC.NRORG,
            BOLETO_REC.CDEMPRESA,
            BOLETO_REC.CDFILIAL,
            BOLETO_REC.DTVENBOLREC,
            BOLETO_REC.NRPARCBOLREC,
            BOLETO_REC.NRLANBOLREC,
            BOLETO_REC.IDSTATBREC,
            BOLETO_REC.VRBOLREC,
            BOLETO_REC.VRFINALBREC,
            BOLETO_REC.CDCLIENTE,
            BOLETO_REC.NMRAZSOCCLIE,
            BOLETO_REC.NRINSJURCLIE,
            BOLETO_REC.NMEMPRESA
        );

    END LOOP;

END;