Update customer.rb

This commit is contained in:
2019-06-25 12:48:35 -04:00
committed by GitHub
parent b4f5112fc3
commit 65eac58f6c

View File

@@ -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