﻿CREATE PROCEDURE [employer_financial].[GetAccountBalance_ByAccountIds]
	@accountIds [employer_financial].[AccountIds] Readonly
AS
	select 
		tl.AccountId,
		Sum(Amount) Balance 
	from 
		[employer_financial].TransactionLine tl
	inner join 
		@accountIds acc on acc.AccountId = tl.AccountId
	Group by tl.AccountId


﻿CREATE PROCEDURE [employer_financial].[GetAccountBalance_ByAccountIds]
	@accountIds [employer_financial].[AccountIds] Readonly
AS
	select 
		tl.AccountId,
		Sum(Amount) Balance ,
		MAX(dervx.IsLevyPayer) IsLevyPayer
	from 
		[employer_financial].TransactionLine tl
	inner join 
	(	select 
			case when SUM(LevyDueYTD) > 0 then 1 
			else 0 end as IsLevyPayer, 
			AccountId 
		from employer_financial.LevyDeclaration group by accountid
	) dervx on dervx.AccountId = tl.AccountId
	inner join 
		@accountIds acc on acc.AccountId = tl.AccountId
	Group by tl.AccountId


Update stored procedure for Getting Balances
Update stored procedure for Getting Balances

Added new value to be returned to say whether or not the user has paid
any levy. New join on the levydeclaration table which then sums the
Levy for that account, if its greater than 0 we say they have paid levy
