drop function if exists public.get_transactions_for_period;

create or replace function public.get_transactions_for_period(
	p_account_name text
	, p_start date 
	, p_end date
)
returns table (
	bank_name text
	, account_type text
	, account_number text
	, account_friendly_name text
	, transaction_date date
	, transaction_description text
	, transaction_amount numeric(8,2)
	, transaction_day_of_week text
	, running_bal numeric
)
LANGUAGE plpgsql
AS $$
begin
	
raise notice 'FUNCTION: get_transactions';
-- E'\n' is new line
raise notice 'INPUT: % p_start = %; % p_end = %;', E'\n', p_start, E'\n', p_end;

return query 
	select 
		bl.account_bank_name, bl.account_type, bl.account_number, bl.account_friendly_name
		, bl.transaction_date, bl.transaction_description, bl.transaction_amount
		, bl.transaction_day_of_week, bl.running_bal
	from public.runbal bl
	where
		lower(bl.account_friendly_name) = trim(lower(p_account_name))
		and bl.transaction_date between p_start and p_end;
end;
$$;

GRANT EXECUTE ON function public.get_transactions_for_period(text, date, date) TO acedanger;
GRANT EXECUTE ON function public.get_transactions_for_period(text, date, date) TO budgetuser;
