Queries to find certain sets of nonprofits

This commit is contained in:
Eric Schultz 2018-04-30 14:07:18 -05:00 committed by Eric Schultz
parent adc4ee2d74
commit ea22a24e9a

View file

@ -101,4 +101,17 @@ module QueryNonprofits
return expr.execute
end
def self.find_nonprofits_with_no_payments()
Nonprofit.includes(:payments).where('payments.nonprofit_id IS NULL')
end
def self.find_nonprofits_with_payments_in_last_n_days(days)
Payment.where("date >= ?", Time.now - days.days).pluck('nonprofit_id').to_a.uniq
end
def self.find_nonprofits_with_payments_but_not_in_last_n_days(days)
recent_nonprofits = find_nonprofits_with_payments_in_last_n_days(days)
Payment.where("date < ?", Time.now - days.days).pluck('nonprofit_id').to_a.uniq.select{|i| !recent_nonprofits.include?(i)}
end
end