diff --git a/app/models/customer.rb b/app/models/customer.rb index b3e1e0e..dd5f0fb 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -142,18 +142,18 @@ class Customer < ActiveRecord::Base # Searchs the database for a customer by name def self.search(search) - customers = where("name LIKE ?", "%#{search}%").order(:name) + customers = where("name LIKE ?", "%#{search}%") if customers.empty? service = Qbo.get_base(:customer).service - results = service.query("Select Id From Customer Where ((PrimaryPhone LIKE '%#{search}%') OR (Mobile LIKE '%#{search}%') Order By DisplayName") + results = service.query("Select Id From Customer Where PrimaryPhone LIKE '%#{search}%' OR Mobile LIKE '%#{search}%'") results.each do |customer| customers << Customer.find_by_id(customer.id) end end - return customers + return customers.order(:name) end # proforms a bruteforce sync operation