@ -44,23 +44,23 @@ class LettingsLog < Log
scope :filter_by_propcode , - > ( propcode ) { where ( " propcode ILIKE ? " , " % #{ propcode } % " ) }
scope :filter_by_location_postcode , - > ( postcode_full ) { left_joins ( :location ) . where ( " REPLACE(locations.postcode, ' ', '') ILIKE ? " , " % #{ postcode_full . delete ( ' ' ) } % " ) }
scope :search_by , lambda { | param |
filter_by_location_postcode ( param )
. or ( filter_by_tenant_code ( param ) )
. or ( filter_by_propcode ( param ) )
. or ( filter_by_postcode ( param ) )
. or ( filter_by_id ( param ) )
}
filter_by_location_postcode ( param )
. or ( filter_by_tenant_code ( param ) )
. or ( filter_by_propcode ( param ) )
. or ( filter_by_postcode ( param ) )
. or ( filter_by_id ( param ) )
}
scope :filter_by_before_startdate , - > ( date ) { where ( " lettings_logs.startdate >= ? " , date ) }
scope :unresolved , - > { where ( unresolved : true ) }
scope :filter_by_organisation , - > ( org , _user = nil ) { where ( owning_organisation : org ) . or ( where ( managing_organisation : org ) ) }
scope :duplicate_logs , lambda { | log |
attrs_to_check = %w[ tenancycode propcode startdate age1 sex1 ecstat1 tcharge postcode_full ]
where ( log . slice ( * attrs_to_check ) )
. where . not ( id : log . id )
. where . not ( status : " deleted " )
. where . not ( " startdate IS NULL OR age1 IS NULL OR sex1 IS NULL OR ecstat1 IS NULL OR tcharge IS NULL OR postcode_full IS NULL OR propcode IS NULL OR needstype IS NULL " )
. where ( " location_id = ? OR needstype = 1 " , log . location_id )
}
attrs_to_check = %w[ tenancycode propcode startdate age1 sex1 ecstat1 tcharge postcode_full ]
where ( log . slice ( * attrs_to_check ) )
. where . not ( id : log . id )
. where . not ( status : " deleted " )
. where . not ( " startdate IS NULL OR age1 IS NULL OR sex1 IS NULL OR ecstat1 IS NULL OR tcharge IS NULL OR postcode_full IS NULL OR propcode IS NULL OR needstype IS NULL " )
. where ( " location_id = ? OR needstype = 1 " , log . location_id )
}
scope :duplicate_logs_for_organisation , - > ( org , log ) { filter_by_organisation ( org ) . duplicate_logs ( log ) }
AUTOGENERATED_FIELDS = %w[ id status created_at updated_at discarded_at ] . freeze