drop view if exists public.runbal;

create view public.runbal 
as 
select
	acct.acct_bank_name as account_bank_name
	, acct.acct_type as account_type
	, acct.acct_number as account_number
	, acct.acct_friendly_name as account_friendly_name
	, trx.trx_date as transaction_date
	, trx.trx_description as transaction_description
	, trx.trx_amount::numeric(8,2) as transaction_amount
	, to_char(trx.trx_date, 'day') transaction_day_of_week
	, sum(trx.trx_amount) 
			over( 
				partition by trx.acct_id 
				order by
					trx.trx_date
					, trx.trx_amount desc rows unbounded preceding
				) running_bal 
from
	public.budgetdetails trx
	join public.accounts acct using (acct_id)
