Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/controllers/family_merchants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ def index
@breadcrumbs = [ [ t("breadcrumbs.home"), root_path ], [ t("breadcrumbs.merchants"), nil ] ]

# Show all merchants for this family
@family_merchants = Current.family.merchants.alphabetically
@provider_merchants = Current.family.assigned_merchants_for(Current.user).where(type: "ProviderMerchant").alphabetically
@all_family_merchants = Current.family.merchants.alphabetically
@all_provider_merchants = Current.family.assigned_merchants_for(Current.user).where(type: "ProviderMerchant").alphabetically

# Show recently unlinked ProviderMerchants (within last 30 days)
# Exclude merchants that are already assigned to transactions (they appear in provider_merchants)
recently_unlinked_ids = FamilyMerchantAssociation
.where(family: Current.family)
.recently_unlinked
.pluck(:merchant_id)
assigned_ids = @provider_merchants.pluck(:id)
assigned_ids = @all_provider_merchants.pluck(:id)
@unlinked_merchants = ProviderMerchant.where(id: recently_unlinked_ids - assigned_ids).alphabetically

@enhanceable_count = @provider_merchants.where(website_url: [ nil, "" ]).count
@enhanceable_count = @all_provider_merchants.where(website_url: [ nil, "" ]).count
@llm_available = Provider::Registry.get_provider(:openai).present?

@pagy_family_merchants, @family_merchants = pagy(@all_family_merchants, page_param: :family_page, limit: safe_per_page)
@pagy_provider_merchants, @provider_merchants = pagy(@all_provider_merchants, page_param: :provider_page, limit: safe_per_page)

render layout: "settings"
end

Expand Down
16 changes: 12 additions & 4 deletions app/views/family_merchants/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
<div class="flex items-center gap-1.5 px-4 py-2 text-xs font-medium text-secondary uppercase">
<p><%= t(".family_title", moniker: family_moniker) %></p>
<span class="text-subdued">&middot;</span>
<p><%= @family_merchants.count %></p>
<p><%= @all_family_merchants.count %></p>
</div>

<% if @family_merchants.any? %>
<% if @all_family_merchants.any? %>
<div class="rounded-xl bg-container-inset space-y-1 p-1">
<div class="bg-container rounded-lg shadow-border-xs overflow-x-auto">
<table class="w-full">
Expand Down Expand Up @@ -52,13 +52,17 @@
</div>
</div>
<% end %>

<div class="pt-4">
<%= render "shared/pagination", pagy: @pagy_family_merchants %>
</div>
</section>

<section class="space-y-3">
<div class="flex items-center gap-1.5 px-4 py-2 text-xs font-medium text-secondary uppercase">
<p><%= t(".provider_title") %></p>
<span class="text-subdued">&middot;</span>
<p><%= @provider_merchants.count %></p>
<p><%= @all_provider_merchants.count %></p>
</div>

<div class="p-4 bg-container-inset border border-secondary rounded-lg">
Expand All @@ -84,7 +88,7 @@
</div>
<% end %>

<% if @provider_merchants.any? %>
<% if @all_provider_merchants.any? %>
<div class="rounded-xl bg-container-inset space-y-1 p-1">
<div class="bg-container rounded-lg shadow-border-xs overflow-x-auto">
<table class="w-full">
Expand All @@ -106,6 +110,10 @@
<p class="text-secondary text-sm text-center"><%= t(".provider_empty", moniker: family_moniker_downcase) %></p>
</div>
<% end %>

<div class="pt-4">
<%= render "shared/pagination", pagy: @pagy_provider_merchants %>
</div>
</section>

<% if @unlinked_merchants.any? %>
Expand Down
Loading