diff --git a/app/models/customer.rb b/app/models/customer.rb index 65ba699..ed60c6f 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -85,6 +85,8 @@ class Customer < ActiveRecord::Base pn = Quickbooks::Model::TelephoneNumber.new pn.free_form_number = n @details.mobile_phone = pn + #update our locally stored number too + update_mobile_phone_number end # update the localy stored phone number as a plain string with no special chars @@ -96,6 +98,15 @@ class Customer < ActiveRecord::Base end end + # update the localy stored phone number as a plain string with no special chars + def update_mobile_phone_number + begin + self.mobile_phone_number = self.mobile_phone.tr('^0-9', '') + rescue + return nil + end + end + # Convenience Method # Updates Both local DB name & QBO display_name def name=(s) @@ -155,7 +166,7 @@ class Customer < ActiveRecord::Base # Searchs the database for a customer by name or phone number with out special chars def self.search(search) - customers = where("name LIKE ? OR phone_number LIKE ?", "%#{search}%", "%#{search}%") + customers = where("name LIKE ? OR phone_number LIKE ? OR mobile_phone_number LIKE ?", "%#{search}%", "%#{search}%", "%#{search}%") return customers.order(:name) end