Calculating the user's balance for dashboard display

Extracted a queries.php into which a lot of these common pieces of
functionality can go.