|
|
|
@ -45,32 +45,34 @@ class LettingsLog < Log |
|
|
|
scope :filter_by_location_postcode, ->(postcode_full) { left_joins(:location).where("REPLACE(locations.postcode, ' ', '') ILIKE ?", "%#{postcode_full.delete(' ')}%") } |
|
|
|
scope :filter_by_location_postcode, ->(postcode_full) { left_joins(:location).where("REPLACE(locations.postcode, ' ', '') ILIKE ?", "%#{postcode_full.delete(' ')}%") } |
|
|
|
scope :search_by, lambda { |param| |
|
|
|
scope :search_by, lambda { |param| |
|
|
|
filter_by_location_postcode(param) |
|
|
|
filter_by_location_postcode(param) |
|
|
|
.or(filter_by_tenant_code(param)) |
|
|
|
.or(filter_by_tenant_code(param)) |
|
|
|
.or(filter_by_propcode(param)) |
|
|
|
.or(filter_by_propcode(param)) |
|
|
|
.or(filter_by_postcode(param)) |
|
|
|
.or(filter_by_postcode(param)) |
|
|
|
.or(filter_by_id(param)) |
|
|
|
.or(filter_by_id(param)) |
|
|
|
} |
|
|
|
} |
|
|
|
scope :after_date, ->(date) { where("lettings_logs.startdate >= ?", date) } |
|
|
|
scope :after_date, ->(date) { where("lettings_logs.startdate >= ?", date) } |
|
|
|
scope :unresolved, -> { where(unresolved: true) } |
|
|
|
scope :unresolved, -> { where(unresolved: true) } |
|
|
|
|
|
|
|
|
|
|
|
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) } |
|
|
|
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) } |
|
|
|
scope :filter_by_owning_organisation, ->(owning_organisation, _user = nil) { where(owning_organisation:) } |
|
|
|
scope :age1_answered, -> { where.not(age1: nil).or(where(age1_known: 1)) } |
|
|
|
scope :filter_by_managing_organisation, ->(managing_organisation, _user = nil) { where(managing_organisation:) } |
|
|
|
scope :tcharge_answered, -> { where.not(tcharge: nil).or(where(household_charge: 1)).or(where(is_carehome: 1)) } |
|
|
|
|
|
|
|
scope :chcharge_answered, -> { where.not(chcharge: nil).or(where(is_carehome: [nil, 0])) } |
|
|
|
|
|
|
|
scope :location_answered, ->(log) { where(location_id: log.location_id).or(where(needstype: 1)) } |
|
|
|
|
|
|
|
scope :postcode_answered, ->(log) { where(postcode_full: log.postcode_full).or(where(needstype: 2)) } |
|
|
|
scope :duplicate_logs, lambda { |log| |
|
|
|
scope :duplicate_logs, lambda { |log| |
|
|
|
visible |
|
|
|
visible |
|
|
|
.where(log.slice(*DUPLICATE_LOG_ATTRIBUTES)) |
|
|
|
.where(log.slice(*DUPLICATE_LOG_ATTRIBUTES)) |
|
|
|
.where.not(id: log.id) |
|
|
|
.where.not(id: log.id) |
|
|
|
.where.not(startdate: nil) |
|
|
|
.where.not(startdate: nil) |
|
|
|
.where.not(sex1: nil) |
|
|
|
.where.not(sex1: nil) |
|
|
|
.where.not(ecstat1: nil) |
|
|
|
.where.not(ecstat1: nil) |
|
|
|
.where.not(needstype: nil) |
|
|
|
.where.not(needstype: nil) |
|
|
|
.where("age1 IS NOT NULL OR age1_known = 1") |
|
|
|
.age1_answered |
|
|
|
.where("tcharge IS NOT NULL OR household_charge = 1 OR is_carehome = 1") |
|
|
|
.tcharge_answered |
|
|
|
.where("chcharge IS NOT NULL OR is_carehome IS NULL OR is_carehome = 0") |
|
|
|
.chcharge_answered |
|
|
|
.where("location_id = ? OR needstype = 1", log.location_id) |
|
|
|
.location_answered(log) |
|
|
|
.where("postcode_full = ? OR needstype = 2", log.postcode_full) |
|
|
|
.postcode_answered(log) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
scope :all_duplicates, -> { select(:id, :propcode, :tenancycode).group(:tenancycode, :propcode, :age1).having("count(*) > 1").size } |
|
|
|
|
|
|
|
|
|
|
|
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[tenancycode propcode chcharge].freeze |
|
|
|
OPTIONAL_FIELDS = %w[tenancycode propcode chcharge].freeze |
|
|
|
|