create or replace PROCEDURE DASHBOARD_FIN_DIVISAO_RECEITAS AS   
BEGIN
    DELETE FROM PDCDIVISAOREC;

    FOR RECEITAS IN (
        SELECT
            CR.NRORG,
            CR.CDEMPRESA,
            CR.CDTPCTRECEB,
            TR.DSTPCTRECEB,
            BR.DTVENBOLREC,
            CR.VRATUAREC
        FROM
            BOLETRECEBER BR,
            CONTARECEBER CR,
            TIPOCTRECEBER TR
        WHERE
            BR.CDFILIAL = CR.CDFILIBOLREC
            AND BR.NRLANBOLREC = CR.NRLANBOLREC
            AND CR.CDTPCTRECEB = TR.CDTPCTRECEB
        ORDER BY
            CR.VRATUAREC DESC
    ) LOOP
        INSERT INTO PDCDIVISAOREC (
            NRORG,
            CDEMPRESA,
            CDTPCTRECEB,
            DSTPCTRECEB,
            DTVENBOLREC,
            VRATUAREC
        ) VALUES (
            RECEITAS.NRORG,
            RECEITAS.CDEMPRESA,
            RECEITAS.CDTPCTRECEB,
            RECEITAS.DSTPCTRECEB,
            RECEITAS.DTVENBOLREC,
            RECEITAS.VRATUAREC
        );

    END LOOP;

END;
/