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

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

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
$procedure$;