Compare commits

...

19 Commits

Author SHA1 Message Date
5d858ae186 Enhance customer search functionality by ordering results and refining search method 2026-02-25 22:05:52 -05:00
b38f850df3 2026.2.15 2026-02-25 21:13:55 -05:00
138e55933b Fixed creation of new customers. 2026-02-25 15:32:45 -05:00
5fbc169ade Restored old search 2026-02-25 08:08:02 -05:00
d6737a6747 2026.2.14 2026-02-22 19:11:14 -05:00
65db8f00a8 Improve customer search with Full-Text index and phonetic matching 2026-02-22 19:07:20 -05:00
0197dc2a30 removed unused method 2026-02-22 13:34:23 -05:00
cd1caa502d Merge branch 'master' into dev 2026-02-22 13:32:01 -05:00
4b45d24a75 Enhance Customer model with redmine's built in searchable and event capabilities 2026-02-22 13:31:28 -05:00
64a4526aa4 2026.2.13 2026-02-21 19:08:32 -05:00
3514401808 Add unique IDs to search forms for customers and estimates 2026-02-21 19:07:40 -05:00
3deafd8a6d Fixed search event_url 2026-02-21 11:35:15 -05:00
a54de28db5 Extending customers to Redmine's built in search 2026-02-21 11:20:20 -05:00
6434eea906 2026.2.12 2026-02-21 08:24:36 -05:00
9b656534ae Sanitize search, no little bobby tables 2026-02-21 08:23:58 -05:00
659a1fbcf0 2026.2.11 2026-02-20 19:11:31 -05:00
4dc1f5d0bd Enhance billing functionality in IssuePatch with detailed logging and self-references 2026-02-20 09:47:47 -05:00
02f34582f4 2026.2.10
Addressed the Bullet (the N+1 query detector) warning to include customers
2026-02-16 18:56:09 -05:00
2f9ef6304f scope.includes(:customer) 2026-02-16 18:53:29 -05:00
9 changed files with 116 additions and 31 deletions

View File

@@ -30,8 +30,6 @@ class CustomersController < ApplicationController
before_action :view_customer, except: [:new, :view]
skip_before_action :verify_authenticity_token, :check_if_login_required, only: [:view]
default_search_scope :names
autocomplete :customer, :name, full: true, extra_data: [:id]
def allowed_params
@@ -53,7 +51,7 @@ class CustomersController < ApplicationController
# display a list of all customers
def index
if params[:search]
@customers = Customer.search(params[:search]).paginate(page: params[:page])
@customers = Customer.search(params[:search]).order(:name).paginate(page: params[:page])
if only_one_non_zero?(@customers)
redirect_to @customers.first
end

View File

@@ -9,6 +9,9 @@
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class Customer < ActiveRecord::Base
include Redmine::Acts::Searchable
include Redmine::Acts::Event
has_many :issues
has_many :invoices
@@ -17,11 +20,18 @@ class Customer < ActiveRecord::Base
validates_presence_of :id, :name
self.primary_key = :id
# returns a human readable string
def to_s
return "#{self[:name]} - #{phone_number.split(//).last(4).join unless phone_number.nil?}"
end
acts_as_searchable columns: %w[name phone_number mobile_phone_number ],
scope: ->(_context) { left_joins(:project) },
date_column: :updated_at
acts_as_event :title => Proc.new {|o| "#{o}"},
:url => Proc.new {|o| { :controller => 'customers', :action => 'show', :id => o.id} },
:type => :to_s,
:description => Proc.new {|o| "#{I18n.t :label_primary_phone}: #{o.phone_number} #{I18n.t:label_mobile_phone}: #{o.mobile_phone_number}"},
:datetime => Proc.new {|o| o.updated_at || o.created_at}
#default_scope { order(name: :asc) }
# Convenience Method
# returns the customer's email
@@ -40,7 +50,7 @@ class Customer < ActiveRecord::Base
pull unless @details
@details.email_address = s
end
# Convenience Method
# returns the customer's primary phone
def primary_phone
@@ -62,7 +72,13 @@ class Customer < ActiveRecord::Base
#update our locally stored number too
update_phone_number
end
# Customers are not bound by a project
# but we need to implement this method for the Redmine::Acts::Searchable interface
def project
nil
end
# Convenience Method
# returns the customer's mobile phone
def mobile_phone
@@ -166,11 +182,25 @@ class Customer < ActiveRecord::Base
end
end
end
# Searchs the database for a customer by name or phone number with out special chars
# Seach for customers by name or phone number
def self.search(search)
customers = where("name LIKE ? OR phone_number LIKE ? OR mobile_phone_number LIKE ?", "%#{search}%", "%#{search}%", "%#{search}%")
return customers.order(:name)
search = sanitize_sql_like(search)
where("name LIKE ? OR phone_number LIKE ? OR mobile_phone_number LIKE ?", "%#{search}%", "%#{search}%", "%#{search}%")
end
# Override the defult redmine seach method to rank results by id
def self.search_result_ranks_and_ids(tokens, user, project = nil, options = {})
return {} if tokens.blank?
scope = self.all
tokens.each do |token|
scope = scope.search(token)
end
ids = scope.distinct.limit(options[:limit] || 100).pluck(:id)
ids.index_with { |id| id }
end
# proforms a bruteforce sync operation
@@ -200,22 +230,32 @@ class Customer < ActiveRecord::Base
end
end
# returns a human readable string
def to_s
return "#{self[:name]} - #{phone_number.split(//).last(4).join unless phone_number.nil?}"
end
# Push the updates
def save_with_push
begin
qbo = Qbo.first
@details = qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Customer.new(company_id: qbo.realm_id, access_token: access_token)
service = Quickbooks::Service::Customer.new(
company_id: qbo.realm_id,
access_token: access_token
)
service.update(@details)
end
#raise "QBO Fault" if @details.fault?
self.id = @details.id
rescue Exception => e
errors.add(e.message)
rescue => e
errors.add(:base, e.message)
return false
end
save_without_push
end
alias_method :save_without_push, :save
alias_method :save, :save_with_push

View File

@@ -1,4 +1,4 @@
<%= form_tag(customers_path, method: "get", id: "search-form") do %>
<%= form_tag(customers_path, method: "get", id: "customer-search-form") do %>
<%= text_field_tag :search, params[:search], placeholder: t(:label_search_customers), autocomplete: "off" %>
<%= submit_tag t(:label_search) %>
<% end %>

View File

@@ -1,4 +1,4 @@
<%= form_tag(estimate_doc_path, method: "get") do %>
<%= form_tag(estimate_doc_path, method: "get", id: "estimate-search-form") do %>
<%= text_field_tag :search, params[:search], placeholder: t(:label_search_estimates), autocomplete: "off" %>
<%= submit_tag t(:label_search), formtarget: "_blank" %>
<% end %>

View File

@@ -0,0 +1,15 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 - 2026 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class AddCustomersTimestamp < ActiveRecord::Migration[5.1]
def change
add_timestamps(:customers, null: true)
end
end

View File

@@ -0,0 +1,16 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 - 2026 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class AddFullTextIndexToCustomers < ActiveRecord::Migration[7.0]
def change
# This creates a combined index for name and phone fields
add_index :customers, [:name, :phone_number, :mobile_phone_number], type: :fulltext, name: 'ft_search_idx'
end
end

View File

@@ -14,7 +14,7 @@ Redmine::Plugin.register :redmine_qbo do
name 'Redmine QBO plugin'
author 'Rick Barrette'
description 'A pluging for Redmine to connect with QuickBooks Online to create Time Activity Entries for billable hours logged when an Issue is closed'
version '2026.2.9'
version '2026.2.15'
url 'https://github.com/rickbarrette/redmine_qbo'
author_url 'https://barrettefabrication.com'
settings default: {empty: true}, partial: 'qbo/settings'
@@ -37,6 +37,10 @@ Redmine::Plugin.register :redmine_qbo do
# Register top menu items
menu :top_menu, :customers, { controller: :customers, action: :index }, caption: :label_customers, if: Proc.new {User.current.logged?}
Redmine::Search.map do |search|
search.register :customers
end
end
# Dynamically load all Hooks & Patches recursively

View File

@@ -43,14 +43,18 @@ module RedmineQbo
# Create billable time entries
def bill_time
logger.debug "QBO: Billing time for issue ##{id}"
return false if assigned_to.nil?
logger.debug "QBO: Billing time for issue ##{self.id}"
logger.debug "Issue is closed? #{self.closed?}"
return false if self.assigned_to.nil?
return false unless Qbo.first
return false unless customer
return false unless self.customer
Thread.new do
spent_time = time_entries.where(billed: [false, nil])
spent_time = self.time_entries.where(billed: [false, nil])
spent_hours ||= spent_time.sum(:hours) || 0
logger.debug "Issue has spent hours: #{spent_hours}"
if spent_hours > 0 then
@@ -73,20 +77,23 @@ module RedmineQbo
# Now letes upload our totals for each activity as their own billable time entry
h.each do |key, val|
logger.debug "Processing activity '#{key}' with #{val.to_i} hours for issue ##{self.id}"
# Convert float spent time to hours and minutes
hours = val.to_i
minutesDecimal = (( val - hours) * 60)
minutes = minutesDecimal.to_i
logger.debug "Converted #{val.to_i} hours to #{hours} hours and #{minutes} minutes"
# Lets match the activity to an qbo item
item = item_service.query("SELECT * FROM Item WHERE Name = '#{key}' ").first
next if item.nil?
# Create the new billable time entry and upload it
time_entry.description = "#{tracker} ##{id}: #{subject} #{"(Partial @ #{done_ratio}%)" if not closed?}"
time_entry.employee_id = assigned_to.employee_id
time_entry.customer_id = customer_id
time_entry.description = "#{self.tracker} ##{self.id}: #{self.subject} #{"(Partial @ #{self.done_ratio}%)" unless self.closed?}"
time_entry.employee_id = self.assigned_to.employee_id
time_entry.customer_id = self.customer_id
time_entry.billable_status = "Billable"
time_entry.hours = hours
time_entry.minutes = minutes

View File

@@ -16,12 +16,17 @@ module RedmineQbo
def base_scope
scope = super
if filters['customer_name'].present?
scope = scope.left_outer_joins(:customer)
end
if has_column?(:customer) || filters['customer_name'].present?
scope = scope.includes(:customer)
end
scope
end
# Add qbo options to the aviable columns
def available_columns