use sql to better query for billable students

Before we were using the ruby select method to filter through all
the students who's latest payment was within a certain amount of
time. This created an n + 1 situation where we were querying for
students, then looping through and querying for each student's
payments. Not ideal. Now it's all done in one fairly complex SQL
statement.