|
|
@ -21,9 +21,9 @@ class Location < ApplicationRecord |
|
|
|
scope :search_by_postcode, ->(postcode) { where("REPLACE(postcode, ' ', '') ILIKE ?", "%#{postcode.delete(' ')}%") } |
|
|
|
scope :search_by_postcode, ->(postcode) { where("REPLACE(postcode, ' ', '') ILIKE ?", "%#{postcode.delete(' ')}%") } |
|
|
|
scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") } |
|
|
|
scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") } |
|
|
|
scope :search_by, ->(param) { search_by_name(param).or(search_by_postcode(param)) } |
|
|
|
scope :search_by, ->(param) { search_by_name(param).or(search_by_postcode(param)) } |
|
|
|
scope :started, -> { where("startdate <= ?", Time.zone.today).or(where(startdate: nil)) } |
|
|
|
scope :started, -> { where("locations.startdate <= ?", Time.zone.today).or(where(startdate: nil)) } |
|
|
|
scope :active, -> { where(confirmed: true).and(started) } |
|
|
|
scope :active, -> { where(confirmed: true).and(started) } |
|
|
|
scope :started_in_2_weeks, -> { where("startdate <= ?", Time.zone.today + 2.weeks).or(where(startdate: nil)) } |
|
|
|
scope :started_in_2_weeks, -> { where("locations.startdate <= ?", Time.zone.today + 2.weeks).or(where(startdate: nil)) } |
|
|
|
scope :active_in_2_weeks, -> { where(confirmed: true).and(started_in_2_weeks) } |
|
|
|
scope :active_in_2_weeks, -> { where(confirmed: true).and(started_in_2_weeks) } |
|
|
|
scope :confirmed, -> { where(confirmed: true) } |
|
|
|
scope :confirmed, -> { where(confirmed: true) } |
|
|
|
scope :unconfirmed, -> { where.not(confirmed: true) } |
|
|
|
scope :unconfirmed, -> { where.not(confirmed: true) } |
|
|
@ -122,7 +122,7 @@ class Location < ApplicationRecord |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def available_from |
|
|
|
def available_from |
|
|
|
[merge_date, startdate].compact.max || FormHandler.instance.earliest_open_collection_start_date(now: created_at) |
|
|
|
startdate || FormHandler.instance.earliest_open_collection_start_date(now: created_at) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def open_deactivation |
|
|
|
def open_deactivation |
|
|
|