|
|
@ -35,15 +35,14 @@ class CaseLog < ApplicationRecord |
|
|
|
|
|
|
|
|
|
|
|
scope :for_organisation, ->(org) { where(owning_organisation: org).or(where(managing_organisation: org)) } |
|
|
|
scope :for_organisation, ->(org) { where(owning_organisation: org).or(where(managing_organisation: org)) } |
|
|
|
scope :filter_by_status, ->(status) { where status: status } |
|
|
|
scope :filter_by_status, ->(status) { where status: status } |
|
|
|
scope :filter_by_year, lambda { |year_s| |
|
|
|
scope :filter_by_years, lambda { |years| |
|
|
|
years = Array(year_s) |
|
|
|
|
|
|
|
first_year = years.shift |
|
|
|
first_year = years.shift |
|
|
|
query = where("startdate >= ?", Time.utc(first_year.to_i, 4, 1)).where("startdate <= ?", Time.utc(first_year.to_i + 1, 3, 31).end_of_day) |
|
|
|
query = filter_by_year(first_year) |
|
|
|
years.each do |year| |
|
|
|
years.each { |year| query = query.or(filter_by_year(year)) } |
|
|
|
query = query.or(where("startdate >= ?", Time.utc(year.to_i, 4, 1)).where("startdate <= ?", Time.utc(year.to_i + 1, 3, 31).end_of_day)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
query.all |
|
|
|
query.all |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
scope :filter_by_year, ->(year) { where(startdate: Time.utc(year.to_i, 4, 1)...Time.utc(year.to_i + 1, 4, 1)) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze |
|
|
|
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze |
|
|
|
OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing tenant_code propcode].freeze |
|
|
|
OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing tenant_code propcode].freeze |
|
|
|