Queries to find certain sets of nonprofits
This commit is contained in:
parent
adc4ee2d74
commit
ea22a24e9a
1 changed files with 13 additions and 0 deletions
|
@ -101,4 +101,17 @@ module QueryNonprofits
|
||||||
|
|
||||||
return expr.execute
|
return expr.execute
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue