Compare commits

...

3 Commits

Author SHA1 Message Date
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
2 changed files with 28 additions and 37 deletions

View File

@@ -182,23 +182,9 @@ class Customer < ActiveRecord::Base
end end
def self.search(search) def self.search(search)
return all if search.blank? search = sanitize_sql_like(search)
customers = where("name LIKE ? OR phone_number LIKE ? OR mobile_phone_number LIKE ?", "%#{search}%", "%#{search}%", "%#{search}%")
# 1. Clean the input: Remove existing stars and special Boolean operators return customers.order(:name)
# to prevent "red**" or syntax errors from hyphens/plus signs.
clean_search = search.gsub(/[*+\-><()~]/, '')
# 2. Add a single trailing wildcard for partial matching
ft_query = "#{clean_search}*"
# 3. Use the exact column list from your migration
# Using a hybrid approach to ensure "Jonh" still finds "John"
where(
"MATCH(name, phone_number, mobile_phone_number) AGAINST(? IN BOOLEAN MODE) OR
SOUNDEX(SUBSTRING_INDEX(name, ' ', 1)) = SOUNDEX(?) OR
name LIKE ?",
ft_query, clean_search, "%#{sanitize_sql_like(clean_search)}%"
).order(Arel.sql("MATCH(name, phone_number, mobile_phone_number) AGAINST(#{connection.quote(clean_search)}) DESC"))
end end
# Override the defult redmine seach method to rank results by id # Override the defult redmine seach method to rank results by id
@@ -249,6 +235,30 @@ class Customer < ActiveRecord::Base
def to_s def to_s
return "#{self[:name]} - #{phone_number.split(//).last(4).join unless phone_number.nil?}" return "#{self[:name]} - #{phone_number.split(//).last(4).join unless phone_number.nil?}"
end 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.update(@details)
end
self.id = @details.id
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
private private
@@ -265,24 +275,5 @@ class Customer < ActiveRecord::Base
@details = Quickbooks::Model::Customer.new @details = Quickbooks::Model::Customer.new
end end
end 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.update(@details)
end
#raise "QBO Fault" if @details.fault?
self.id = @details.id
rescue Exception => e
errors.add(e.message)
end
save_without_push
end
alias_method :save_without_push, :save
alias_method :save, :save_with_push
end end

View File

@@ -14,7 +14,7 @@ Redmine::Plugin.register :redmine_qbo do
name 'Redmine QBO plugin' name 'Redmine QBO plugin'
author 'Rick Barrette' 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' 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.14' version '2026.2.15'
url 'https://github.com/rickbarrette/redmine_qbo' url 'https://github.com/rickbarrette/redmine_qbo'
author_url 'https://barrettefabrication.com' author_url 'https://barrettefabrication.com'
settings default: {empty: true}, partial: 'qbo/settings' settings default: {empty: true}, partial: 'qbo/settings'