Customers page lists every customer, paged by Redmine instead of will_paginate

- The Customers page shows all customers without a search: a Redmine list with name, phone, mobile,
  issue count and last update, sortable by column, with Redmine's pagination and per-page choices
- Search works as before (best matches first, a single match opens the customer); clicking a column
  sorts the matches by it instead, and Clear goes back to everyone
- New Customer and Sync move to the page's action links
- will_paginate removed from the Gemfile and init.rb; redmine_qbo_vehicles 2026.11.3 no longer needs it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-01 17:47:19 -05:00
1 parent 64e4a149ab
commit 489edd97fa
6 files changed
+91 -41

No files matched your search

-1
View File
@@ -3,7 +3,6 @@ source 'https://rubygems.org'
gem 'quickbooks-ruby'
gem 'oauth2'
gem 'roxml'
gem 'will_paginate'
gem 'rexml'
gem 'combine_pdf'
+3 -1
View File
@@ -69,8 +69,10 @@ This ensures Time Activities are recorded under the correct employee in QuickBoo
The plugin provides basic Customer management:
* Create Customers directly from Redmine
* Browse every Customer on the **Customers** page: a Redmine list with phone numbers, issue counts and last update, sortable by column and paged with Redmine's own pagination (and its per-page choices)
* Search Customers by **name or phone number**
* Search Customers by **name or phone number**: the best matches come first (click a column to sort them instead), and a single match opens that Customer
* View and edit Customer information
+25 -16
View File
@@ -117,13 +117,33 @@ class CustomersController < ApplicationController
@filtered_invoices = Invoice.all.where(customer_id: params[:selected_customer])
end
# Most matches a search lists (best first)
SEARCH_LIMIT = 200
# Every customer, sortable and paged like Redmine's lists; a search narrows it to the best matches (a single
# match opens that customer). Sorting a search's results by a column replaces the best-first order.
def index
if params[:search]
@customers = CustomerSearchService.call(name: params[:search], limit: 200).paginate(page: params[:page])
if only_one_non_zero?(@customers)
redirect_to @customers.first
end
sort_init 'name', 'asc'
sort_update 'name' => "#{Customer.table_name}.name",
'phone' => "#{Customer.table_name}.phone_number",
'mobile' => "#{Customer.table_name}.mobile_phone_number",
'updated' => "#{Customer.table_name}.updated_at"
@search = params[:search].to_s.strip
if @search.present?
scope = CustomerSearchService.call(name: @search, limit: SEARCH_LIMIT)
@best_first = params[:sort].blank?
else
scope = Customer.all
end
scope = scope.reorder(sort_clause).order(:id) unless @best_first
@customer_count = scope.count
return redirect_to(scope.first) if @search.present? && @customer_count == 1
@customer_pages = Paginator.new @customer_count, per_page_option, params['page']
@customers = scope.limit(@customer_pages.per_page).offset(@customer_pages.offset).to_a
@issue_counts = Issue.where(customer_id: @customers.map(&:id)).group(:customer_id).count
end
def load_issue_data
@@ -157,17 +177,6 @@ class CustomersController < ApplicationController
end
end
def only_one_non_zero?(array)
found_non_zero = false
array.each do |val|
if val != 0
return false if found_non_zero
found_non_zero = true
end
end
found_non_zero
end
def share
issue = Issue.visible.find(params[:id])
token = issue.share_token
+61 -19
View File
@@ -1,24 +1,66 @@
<h2><%=t(:field_customers)%> <span style="float:right"> <%= render partial: 'customers/search' %> </span> </h2>
<% if @customers.present? %>
<br/>
<% @customers.each do |c| %>
<div class="row">
<div class="span6 columns">
<%= link_to c, customer_path(c.id) %>
</div>
</div>
<% html_title l(:label_customers) %>
<% phone = ->(digits) { digits.present? ? number_to_phone(digits.gsub(/\D/, '').to_i, area_code: true) : '' } %>
<div class="contextual">
<% if User.current.allowed_to?(:add_customers, nil, global: true) %>
<%= link_to sprite_icon('add', l(:label_new_customer)), new_customer_path, class: 'icon icon-add' %>
<% end %>
<% if User.current.admin? %>
<%= link_to sprite_icon('reload', l(:label_sync)), qbo_sync_path, class: 'icon icon-reload' %>
<% end %>
<p><%=t(:label_matching)%> <%= @customers.count %> <%=t(:field_customers)%> </p>
<div class="actions">
<%= will_paginate @customers %>
</div>
<% else %>
<p><%=t(:label_no_customers)%> <%= params[:search] %>.</p>
<h2><%= l(:label_customers) %></h2>
<%= form_tag(customers_path, method: :get, id: 'customer-search-form') do %>
<p class="qbo-customer-search">
<%= text_field_tag :search, @search, class: 'customer-name', size: 40, placeholder: t(:label_search_customers),
autocomplete: 'off', data: { autocomplete_url: '/customers/autocomplete' } %>
<%= submit_tag l(:label_search), name: nil %>
<% if @search.present? %>
<%= link_to sprite_icon('reload', l(:button_clear)), customers_path, class: 'icon icon-reload' %>
<% end %>
</p>
<% end %>
<div>
<%= render partial: 'qbo/stats' %>
</div>
<% if @customers.empty? %>
<p class="nodata"><%= @search.present? ? l(:label_no_customers, search: @search) : l(:label_no_data) %></p>
<% else %>
<% if @best_first %>
<p class="info"><%= l(:text_customers_best_match, count: @customer_count) %></p>
<% end %>
<div class="autoscroll">
<table class="list customers odd-even">
<thead>
<tr>
<%= sort_header_tag('name', caption: l(:field_name)) %>
<%= sort_header_tag('phone', caption: l(:label_primary_phone)) %>
<%= sort_header_tag('mobile', caption: l(:label_mobile_phone)) %>
<th><%= l(:label_issue_plural) %></th>
<%= sort_header_tag('updated', caption: l(:field_updated_on), default_order: 'desc') %>
</tr>
</thead>
<tbody>
<% @customers.each do |customer| %>
<tr class="<%= cycle('odd', 'even') %>">
<td class="name"><%= link_to customer.name, customer_path(customer.id) %></td>
<td class="phone"><%= phone.call(customer.phone_number) %></td>
<td class="phone"><%= phone.call(customer.mobile_phone_number) %></td>
<td class="issues"><%= @issue_counts[customer.id] || 0 %></td>
<td class="updated_on"><%= format_time(customer.updated_at) if customer.updated_at %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<span class="pagination"><%= pagination_links_full @customer_pages, @customer_count %></span>
<% end %>
<p class="qbo-customer-stats"><%= render partial: 'qbo/stats' %></p>
<style>
table.customers td.name { text-align: left; }
table.customers td.phone, table.customers td.updated_on { white-space: nowrap; }
table.customers td.issues { width: 1%; text-align: center; }
.qbo-customer-search input { vertical-align: middle; }
</style>
+2 -1
View File
@@ -65,7 +65,8 @@ en:
label_new_customer: "New Customer"
label_new_issue: "New Issue"
label_qbo_never_synced: "Never Synced"
label_no_customers: "There are no customers matching the search term(s)."
label_no_customers: "No customers match \"%{search}\"."
text_customers_best_match: "%{count} best matches, closest first. Click a column to sort them by it instead."
label_no_estimates: "No Estimates"
label_no_invoices: "No Invoices"
label_oauth2_refresh_token_expires_at: "Refresh Token Expires At"
-3
View File
@@ -27,9 +27,6 @@ Redmine::Plugin.register :redmine_qbo do
User.safe_attributes :employee_id
TimeEntry.safe_attributes :billed
# set per_page globally
WillPaginate.per_page = 20
# Global Permissions
# autocomplete and the filter_* actions feed the customer, estimate and invoice pickers on issue forms
permission :view_customers, { customers: [:index, :show, :autocomplete,