|
|
@ -34,8 +34,8 @@ class CaseLog < ApplicationRecord |
|
|
|
belongs_to :managing_organisation, class_name: "Organisation" |
|
|
|
belongs_to :managing_organisation, class_name: "Organisation" |
|
|
|
|
|
|
|
|
|
|
|
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, _user = nil) { where status: status } |
|
|
|
scope :filter_by_years, lambda { |years| |
|
|
|
scope :filter_by_years, lambda { |years, _user = nil| |
|
|
|
first_year = years.shift |
|
|
|
first_year = years.shift |
|
|
|
query = filter_by_year(first_year) |
|
|
|
query = filter_by_year(first_year) |
|
|
|
years.each { |year| query = query.or(filter_by_year(year)) } |
|
|
|
years.each { |year| query = query.or(filter_by_year(year)) } |
|
|
@ -43,6 +43,12 @@ class CaseLog < ApplicationRecord |
|
|
|
} |
|
|
|
} |
|
|
|
scope :filter_by_year, ->(year) { where(startdate: Time.utc(year.to_i, 4, 1)...Time.utc(year.to_i + 1, 4, 1)) } |
|
|
|
scope :filter_by_year, ->(year) { where(startdate: Time.utc(year.to_i, 4, 1)...Time.utc(year.to_i + 1, 4, 1)) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scope :filter_by_user, lambda { |selected_user, user| |
|
|
|
|
|
|
|
if !selected_user.include?("all") && user.present? |
|
|
|
|
|
|
|
where(id: PaperTrail::Version.where(item_type: "CaseLog", event: "create", whodunnit: user.to_global_id.uri.to_s).map(&:item_id)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
RENT_TYPE_MAPPING = { 0 => 1, 1 => 2, 2 => 2, 3 => 3, 4 => 3, 5 => 3 }.freeze |
|
|
|
RENT_TYPE_MAPPING = { 0 => 1, 1 => 2, 2 => 2, 3 => 3, 4 => 3, 5 => 3 }.freeze |
|
|
|