Browse Source

implement filters functionality

pull/3063/head
Samuel 1 week ago
parent
commit
e0157752b8
  1. 7
      app/models/sales_log.rb
  2. 4
      app/models/user.rb

7
app/models/sales_log.rb

@ -45,6 +45,13 @@ class SalesLog < Log
query.all
}
scope :filter_by_purchaser_code, ->(purchid) { where("purchid ILIKE ?", "%#{purchid}%") }
scope :filter_by_salestype, ->(salestype) { where(ownershipsch: salestype) }
scope :filter_by_salestypes, lambda { |salestypes, _user = nil|
first_salestype = salestypes.shift
query = filter_by_salestype(first_salestype)
salestypes.each { |salestype| query = query.or(filter_by_salestype(salestype)) }
query.all
}
scope :search_by, lambda { |param|
sanitized_param = ActiveRecord::Base.sanitize_sql(param)
param_without_spaces = sanitized_param.delete(" ")

4
app/models/user.rb

@ -228,9 +228,9 @@ class User < ApplicationRecord
def logs_filters(specific_org: false)
if (support? && !specific_org) || organisation.has_managing_agents? || organisation.has_stock_owners?
%w[years status needstypes assigned_to user owning_organisation managing_organisation bulk_upload_id user_text_search owning_organisation_text_search managing_organisation_text_search]
%w[years status needstypes salestypes assigned_to user owning_organisation managing_organisation bulk_upload_id user_text_search owning_organisation_text_search managing_organisation_text_search]
else
%w[years status needstypes assigned_to user bulk_upload_id user_text_search]
%w[years status needstypes salestypes assigned_to user bulk_upload_id user_text_search]
end
end

Loading…
Cancel
Save