miércoles, 29 de agosto de 2018
Get Payment Amount in iDempiere
-- select * from fnt_get_payment_amt(1000113);
create or replace function fnt_get_payment_amt(p_invoice_id numeric(10,0))
returns numeric(10,2)
as $$
begin
return
coalesce((
with cte_abonos_factura as
(
select
case
when p.c_currency_id = 209 then
(pa.amount + pa.discountamt + pa.writeoffamt)
else
(pa.amount * adempiere.fnc_hm_gettasacambio(p.dateacct)) +
(pa.discountamt * adempiere.fnc_hm_gettasacambio(p.dateacct)) +
(pa.writeoffamt * adempiere.fnc_hm_gettasacambio(p.dateacct))
end::numeric(20,2) as monto_pago
from c_paymentallocate pa
join c_payment p
on pa.c_payment_id = p.c_payment_id
where p.docstatus = 'CO'
and pa.c_invoice_id = p_invoice_id
)
select
sum(af.monto_pago)
from cte_abonos_factura af
), 0.00);
end;
$$ language plpgsql;
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario