martes, 26 de febrero de 2019

Get Asset Disposed Reason on iDempiere


-- select * from fnt_getdisposed_reason('S');

create or replace function fnt_getdisposed_reason(p_reason char)
returns varchar
as $$
begin
    return
    (
        case p_reason
            when 'C' then 'Caridad'
            when 'S' then 'Descartado'
            when 'D' then 'Destruido'
            when 'T' then 'Robado'
            when 'S1' then 'Vendido'
            when 'S2' then 'Vendido sin Negocio'
        end
    );
end;
$$ language plpgsql;

viernes, 15 de febrero de 2019

Get Document No From AD_Table


-- select * from fnt_getdocumentno(319, 1000115);

-- select * from fnt_getdocumentno(472, 1000115);

-- select * from fnt_getdocumentno(318, 1000115);

create or replace function fnt_getdocumentno(p_table_id numeric(10,0), p_record_id numeric(10,0))
returns varchar
as $$
begin
    return
    (
        case p_table_id
            when 319 then
                (select i.documentno from m_inout i
                where i.m_inout_id = p_record_id)
            when 472 then
                (select i.documentno || '_' || il.line || '_' || mi.documentno from m_matchinv mi
                    join m_inoutline il
                    on mi.m_inoutline_id = il.m_inoutline_id
                    join m_inout i
                    on il.m_inout_id = i.m_inout_id
                where mi.m_matchinv_id = p_record_id)
            when 318 then
                (select f.documentno from c_invoice f
                where f.c_invoice_id = p_record_id)
        end
    );
end;
$$ language plpgsql;