CREATE OR REPLACE PROCEDURE DASHBOARD_FIN_DIVISAO_DESPESAS AS
BEGIN
    DELETE FROM PDCDIVISAOPAG;

    FOR DESPESAS IN (
        SELECT
            CP.NRORG,
            CP.CDEMPRESA,
            CP.CDTPCTPAGAR,
            TR.DSTPCTPAGAR,
            BR.DTVENBOLPAG,
            CP.VRATUAPAG
        FROM
            BOLETPAGAR BR,
            CONTAPAGAR CP,
            TIPOCTPAGAR TR
        WHERE
            BR.CDFILIAL = CP.CDFILIBPAG
            AND BR.NRLANBOLPAG = CP.NRLANBOLPAG
            AND CP.CDTPCTPAGAR = TR.CDTPCTPAGAR

    ) LOOP
        INSERT INTO PDCDIVISAOPAG (
            NRORG,
            CDEMPRESA,
            CDTPCTPAGAR,
            DSTPCTPAGAR,
            DTVENBOLPAG,
            VRATUAPAG
        ) VALUES (
            DESPESAS.NRORG,
            DESPESAS.CDEMPRESA,
            DESPESAS.CDTPCTPAGAR,
            DESPESAS.DSTPCTPAGAR,
            DESPESAS.DTVENBOLPAG,
            DESPESAS.VRATUAPAG
        );

    END LOOP;

END;

/
-- VERSAO --
BEGIN ATUVEROBJ('DASHBOARD_FIN_DIVISAO_DESPESAS','6.49.002'); END;
/
