martes, 23 de julio de 2019
Get Accounting Transaction Type
-- select * from fnt_get_transaction_type('C_Invoice', 1000050);
-- select * from fnt_get_transaction_type('C_Payment', 1000050);
-- drop function fnt_get_transaction_type(p_columnname varchar, p_record_id numeric(10,0));
create or replace function fnt_get_transaction_type(p_columnname varchar, p_record_id numeric(10,0))
returns varchar
as $$
declare
v_tablename varchar;
v_issotrx varchar;
v_node varchar;
v_transaction_type varchar;
b boolean = false;
begin
select
upper(et."name")
into
v_tablename
from ad_element e
join ad_element_trl et
on (e.ad_element_id = et.ad_element_id
and et.ad_language = 'es_NI')
where e.columnname = p_columnname || '_ID';
if(v_tablename = 'FACTURA')then
select
i.issotrx
into
v_issotrx
from c_invoice i
where i.c_invoice_id = p_record_id;
if(v_issotrx = 'Y')then
v_node = 'CxC';
b = true;
else
v_node = 'CxP';
b = true;
end if;
end if;
if(v_tablename = 'PAGO')then
select
p.isreceipt
into
v_issotrx
from c_payment p
where p.c_payment_id = p_record_id;
if(v_issotrx = 'Y')then
v_tablename = 'RECAUDO';
b = false;
else
b = false;
end if;
end if;
if(b = true)then
v_transaction_type = v_tablename || ' ' || v_node;
else
v_transaction_type = v_tablename;
end if;
return v_transaction_type;
end;
$$ language plpgsql;
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario