mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-10-04 01:00:44 -04:00
Compare commits
5
Commits
8ae82f1423
...
2026.8.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd91bd6fa2 | ||
|
|
04a0eede5f | ||
|
|
ba40496421 | ||
|
|
57dc8127b0 | ||
|
|
9dc4b79355 |
No files matched your search
@@ -8,7 +8,6 @@
|
|||||||
#
|
#
|
||||||
#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.
|
#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.
|
||||||
|
|
||||||
# This controller class will handle map management
|
|
||||||
class CustomersController < ApplicationController
|
class CustomersController < ApplicationController
|
||||||
|
|
||||||
include AuthHelper
|
include AuthHelper
|
||||||
@@ -26,8 +25,8 @@ class CustomersController < ApplicationController
|
|||||||
include SortHelper
|
include SortHelper
|
||||||
helper :timelog
|
helper :timelog
|
||||||
|
|
||||||
before_action :add_customer, only: :new
|
before_action :add_customer, only: [:new, :create]
|
||||||
before_action :view_customer, except: [:new, :view]
|
before_action :view_customer, except: [:new, :create, :view]
|
||||||
skip_before_action :verify_authenticity_token, :check_if_login_required, only: [:view]
|
skip_before_action :verify_authenticity_token, :check_if_login_required, only: [:view]
|
||||||
|
|
||||||
def address_to_s(address)
|
def address_to_s(address)
|
||||||
@@ -62,12 +61,43 @@ class CustomersController < ApplicationController
|
|||||||
|
|
||||||
# Used for autocomplete form
|
# Used for autocomplete form
|
||||||
def autocomplete
|
def autocomplete
|
||||||
term = ActiveRecord::Base.sanitize_sql_like(params[:q].to_s)
|
# Support both existing 'q' param and new 'name'/'phone' params
|
||||||
|
name_query = (params[:name] || params[:q] || params[:term]).to_s.strip
|
||||||
|
phone_query = params[:phone].to_s.gsub(/\D/, '')
|
||||||
|
|
||||||
items = Customer.where("name LIKE :t OR phone_number LIKE :t OR mobile_phone_number LIKE :t", t: "%#{term}%")
|
sql_matches = []
|
||||||
.order(:name)
|
|
||||||
.limit(20)
|
|
||||||
|
|
||||||
|
# 1. Check for phone number matches via SQL
|
||||||
|
if phone_query.present?
|
||||||
|
sql_matches += Customer.where("phone_number LIKE :p OR mobile_phone_number LIKE :p", p: "%#{phone_query}%")
|
||||||
|
end
|
||||||
|
|
||||||
|
# 2. Check for exact or partial name matches via SQL
|
||||||
|
if name_query.present?
|
||||||
|
safe_name = ActiveRecord::Base.sanitize_sql_like(name_query)
|
||||||
|
sql_matches += Customer.where("name LIKE :t", t: "%#{safe_name}%")
|
||||||
|
end
|
||||||
|
|
||||||
|
sql_matches = sql_matches.uniq
|
||||||
|
|
||||||
|
# 3. Handle spelling errors using built-in string distance
|
||||||
|
fuzzy_matches = []
|
||||||
|
if name_query.present?
|
||||||
|
require 'did_you_mean/jaro_winkler'
|
||||||
|
|
||||||
|
# Only scan records we haven't already matched
|
||||||
|
unmatched = Customer.all - sql_matches
|
||||||
|
|
||||||
|
fuzzy_matches = unmatched.select do |c|
|
||||||
|
# 0.6 is the threshold. 1.0 is an exact match.
|
||||||
|
DidYouMean::JaroWinkler.distance(c.name.to_s.downcase, name_query.downcase) > 0.6
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Combine results and limit to top 20
|
||||||
|
items = (sql_matches + fuzzy_matches).first(20)
|
||||||
|
|
||||||
|
# Return JSON formatted for both existing usage and new jQuery UI requirements
|
||||||
render json: items.map { |i|
|
render json: items.map { |i|
|
||||||
{ id: i.id, name: i.name, phone_number: i.phone_number, mobile_phone_number: i.mobile_phone_number }
|
{ id: i.id, name: i.name, phone_number: i.phone_number, mobile_phone_number: i.mobile_phone_number }
|
||||||
}
|
}
|
||||||
@@ -75,14 +105,28 @@ class CustomersController < ApplicationController
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
@customer = Customer.new(allowed_params)
|
@customer = Customer.new(allowed_params)
|
||||||
@customer.save
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @customer.save
|
||||||
log "Customer ##{@customer.id} created successfully."
|
log "Customer ##{@customer.id} created successfully."
|
||||||
flash[:notice] = t :notice_customer_created
|
format.html { redirect_to @customer, notice: l(:notice_successful_create) }
|
||||||
redirect_to @customer
|
format.json { render json: { id: @customer.id, name: @customer.name }, status: :created }
|
||||||
|
else
|
||||||
|
format.html { render :new }
|
||||||
|
format.json { render json: { errors: @customer.errors.full_messages }, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
log "Failed to create customer: #{e.message}"
|
log "Failed to create customer: #{e.message}"
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
flash[:error] = e.message
|
flash[:error] = e.message
|
||||||
redirect_to new_customer_path
|
redirect_to new_customer_path
|
||||||
|
}
|
||||||
|
format.json {
|
||||||
|
render json: { errors: [e.message] }, status: :internal_server_error
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@@ -136,6 +180,10 @@ class CustomersController < ApplicationController
|
|||||||
|
|
||||||
def new
|
def new
|
||||||
@customer = Customer.new
|
@customer = Customer.new
|
||||||
|
|
||||||
|
if request.xhr?
|
||||||
|
render partial: 'form', layout: false, locals: { hide_submit: true, hide_toolbar: true }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def only_one_non_zero?(array)
|
def only_one_non_zero?(array)
|
||||||
|
|||||||
@@ -33,23 +33,27 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="clearfix">
|
<div class="clearfix">
|
||||||
<%=t(:field_notes)%>:
|
<%= t(:field_notes) %>:
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<p>
|
<p>
|
||||||
<%= f.text_area :notes,
|
<%= f.text_area :notes,
|
||||||
rows: 8,
|
rows: 8,
|
||||||
class: 'wiki-edit',
|
class: 'wiki-edit',
|
||||||
style: 'width: 95%;',
|
style: 'width: 95%;',
|
||||||
id: 'customer_appointment_description' %>
|
id: 'customer_notes' %>
|
||||||
<%= wikitoolbar_for 'customer_appointment_description' %>
|
<% unless local_assigns[:hide_toolbar] %>
|
||||||
|
<%= wikitoolbar_for 'customer_notes' %>
|
||||||
|
<% end %>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% unless local_assigns[:hide_submit] %>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<%= f.submit %>
|
<%= f.submit %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -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.8.1'
|
version '2026.8.3'
|
||||||
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'
|
||||||
|
|||||||
@@ -29,6 +29,15 @@ module RedmineQbo
|
|||||||
RedmineQbo::Hooks::IssuesHookListener
|
RedmineQbo::Hooks::IssuesHookListener
|
||||||
RedmineQbo::Hooks::UsersShowHookListener
|
RedmineQbo::Hooks::UsersShowHookListener
|
||||||
RedmineQbo::Hooks::ViewHookListener
|
RedmineQbo::Hooks::ViewHookListener
|
||||||
|
|
||||||
|
# If the SubtaskFieldCopier plugin is installed, register our fields
|
||||||
|
if defined?(SubtaskFieldCopier)
|
||||||
|
SubtaskFieldCopier.registered_fields << :customer
|
||||||
|
SubtaskFieldCopier.registered_fields << :estimate
|
||||||
|
|
||||||
|
# Ensure there are no duplicates in case of hot-reloads in development mode
|
||||||
|
SubtaskFieldCopier.registered_fields.uniq!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.settings
|
def self.settings
|
||||||
|
|||||||
Reference in new issue
Block a user