lunes, 12 de febrero de 2018

Restore Reversal Journal in iDempiere


-- SET search_path TO adempiere;

-- SELECT * FROM fnt_restore_journal(1004836);

CREATE OR REPLACE FUNCTION fnt_restore_journal(p_gournal_id NUMERIC(10,0))
RETURNS BOOLEAN
AS $$
DECLARE
    v_status CHAR(2);
    v_reversal NUMERIC(10,0);
    v_secuencia VARCHAR;
BEGIN
    SELECT
        g.docstatus,
        g.reversal_id
    INTO
        v_status,
        v_reversal
    FROM gl_journal g
    WHERE g.gl_journal_id = p_gournal_id;
   
    IF(v_status = 'RE')THEN
        UPDATE gl_journal
            SET docstatus = 'CO',
            docaction = 'RE',
            reversal_id = NULL
        WHERE gl_journal.gl_journal_id = p_gournal_id;
       
        DELETE FROM fact_acct
        WHERE fact_acct.ad_client_id = 1000000
            AND fact_acct.ad_table_id = 224
            AND fact_acct.record_id = v_reversal;
           
        DELETE FROM gl_journalline
        WHERE gl_journalline.gl_journal_id = v_reversal;
       
        DELETE FROM gl_journal
        WHERE gl_journal.gl_journal_id = v_reversal;
       
        v_secuencia = (SELECT * FROM update_sequences_table('GL_JournalLine'));
        v_secuencia = (SELECT * FROM update_sequences_table('GL_Journal'));
       
        RETURN TRUE;
    END IF;
   
    RETURN FALSE;
END;
$$ LANGUAGE plpgsql;

No hay comentarios:

Publicar un comentario