-- Function: adempiere.fn_get_period(date)
-- DROP FUNCTION adempiere.fn_get_period(date);
CREATE OR REPLACE FUNCTION adempiere.fn_get_period(p_dateacct date)
RETURNS numeric AS
$BODY$
declare
p_id_anio numeric(10,0) = extract(year from now()::date);
p_id_periodo numeric(10,0) = 0;
begin
p_id_anio =
(
select
y.c_year_id
from c_year y
where y.ad_client_id = 1000000
and y.isactive = 'Y'
and y.fiscalyear = extract(year from p_dateacct)::varchar
);
p_id_periodo =
(
select
p.c_period_id
from c_period p
where p.ad_client_id = 1000000
and p.isactive = 'Y'
and p.periodtype = 'S'
and p.c_year_id = p_id_anio
and p_dateacct between p.startdate and p.enddate
);
return p_id_periodo;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION adempiere.fn_get_period(date)
OWNER TO adempiere;
-- set search_path to adempiere;
-- select * from fnt_get_periodname('20170908 1449'::timestamp without time zone);
create or replace function fnt_get_periodname(p_fecha timestamp without time zone)
returns varchar
as $$
begin
return
(
select p.name from c_period p
where p.c_period_id = fn_get_period(p_fecha::date)
);
end;
$$ language plpgsql;
-- select * from fnt_get_periodname('20170908'::date);
create or replace function fnt_get_periodname(p_fecha date)
returns varchar
as $$
begin
return
(
select p.name from c_period p
where p.c_period_id = fn_get_period(p_fecha)
);
end;
$$ language plpgsql;
No hay comentarios:
Publicar un comentario