diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb index 043874b21..27ae70f2d 100644 --- a/app/helpers/filters_helper.rb +++ b/app/helpers/filters_helper.rb @@ -70,6 +70,14 @@ module FiltersHelper }.freeze end + def salestype_filters + { + "1" => "Shared ownership", + "2" => "Discounted ownership", + "3" => "Outright or other sale", + }.freeze + end + def location_status_filters { "incomplete" => "Incomplete", @@ -210,6 +218,13 @@ module FiltersHelper [1, 2].all? { |needstype| current_user.lettings_logs.visible.where(needstype:).count.positive? } end + def logs_for_multiple_salestypes_present?(organisation) + return true if current_user.support? && organisation.blank? + return [1, 2, 3].count { |ownershipsch| organisation.sales_logs.visible.where(ownershipsch:).count.positive? } > 1 if current_user.support? + + [1, 2, 3].count { |ownershipsch| current_user.sales_logs.visible.where(ownershipsch:).count.positive? } > 1 + end + def non_support_with_multiple_owning_orgs? return true if current_user.organisation.stock_owners.count > 1 return true if current_user.organisation.stock_owners.count.positive? && current_user.organisation.holds_own_stock? @@ -229,6 +244,10 @@ module FiltersHelper request.path.include?("/lettings-logs") end + def user_or_org_sales_path? + request.path.include?("/sales-logs") + end + def specific_organisation_path? request.path.include?("/organisations") end diff --git a/app/views/logs/_log_filters.html.erb b/app/views/logs/_log_filters.html.erb index 3beab4b6b..902d6d00b 100644 --- a/app/views/logs/_log_filters.html.erb +++ b/app/views/logs/_log_filters.html.erb @@ -55,6 +55,17 @@ size: "s", } %> <% end %> + + <% if logs_for_multiple_salestypes_present?(@organisation) && user_or_org_sales_path? %> + <%= render partial: "filters/checkbox_filter", + locals: { + f:, + options: salestype_filters, + label: "Sales type", + category: "salestypes", + size: "s", + } %> + <% end %> <% end %> <%= render partial: "filters/radio_filter",