drop function if exists sp_getouterfilenamebyschet;
drop procedure if exists sp_getouterfilenamebyschet;

create or replace procedure public.sp_getouterfilenamebyschet(
	"schetid" uuid default null::uuid,
	"filename" text default null::text,
	inout "result" text default null::text
)
language 'plpgsql'
as $body$

begin

if (("filename" ilike 'r%' or "filename" ilike 'd%') and "filename" ilike '%oms') then
	select substring("filename", 0, position('.' in "filename")) + '.xml' into "result";
else
	select "filename" into "result";
end if;

return;
end
$body$;