From 781a1bfe61c0f46cfb28d91483720dd57fe9eac4 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Mon, 2 May 2016 10:57:30 -0400 Subject: [PATCH] Update customer.rb --- app/models/customer.rb | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/app/models/customer.rb b/app/models/customer.rb index 60b5205..21a923e 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -15,6 +15,8 @@ class Customer < ActiveRecord::Base has_many :qbo_purchases has_many :vehicles + before_save :qbo + attr_accessible :name validates_presence_of :id, :name @@ -50,6 +52,14 @@ class Customer < ActiveRecord::Base end end + # Updates the customer's primary phone number + def primary_phone=(n) + Quickbooks::Model::TelephoneNumber.new + pn.free_form_number = n + @details.primary_phone = pn + push + end + # returns the customer's mobile phone def mobile_phone begin @@ -59,6 +69,14 @@ class Customer < ActiveRecord::Base end end + # Updates the custome's mobile phone number + def mobile_phone=(n) + Quickbooks::Model::TelephoneNumber.new + pn.free_form_number = n + @details.mobile_phone = pn + push + end + # returns the customer's notes def notes return @details.notes if @details @@ -68,7 +86,7 @@ class Customer < ActiveRecord::Base def notes=(s) customer = get_customer(self.id) customer.notes = s - get_base.update(customer) + push end # returns the bases QBO service for customers @@ -105,6 +123,23 @@ class Customer < ActiveRecord::Base private + def push + begin + get_base.update(@details) + rescue + return nil + end + end + + def qbo + if new_record? + customer = Quickbooks::Model::Customer.new + customer.display_name = self.name + @details = get_base.create(customer) + self.id = @details.id + end + end + # init details def get_details t= Thread.new {