From c666f41d686d454d5f158ee8976bd58d42676e7a Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Thu, 7 Jan 2016 15:52:52 -0500 Subject: [PATCH] Added sync functionality to Item and Employee --- app/controllers/qbo_controller.rb | 4 ++++ app/models/qbo_employee.rb | 14 ++++++++++++++ app/models/qbo_item.rb | 13 +++++++++++++ app/views/qbo/index.html.erb | 5 +++-- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/app/controllers/qbo_controller.rb b/app/controllers/qbo_controller.rb index 6500afb..9e11235 100644 --- a/app/controllers/qbo_controller.rb +++ b/app/controllers/qbo_controller.rb @@ -16,6 +16,8 @@ class QboController < ApplicationController # def index @qbo_customer_count = QboCustomers.count + @qbo_item_count = QboItem.count + @qbo_employee_count = QboEmployee.count end # @@ -61,6 +63,8 @@ class QboController < ApplicationController def sync if Qbo.exists? then QboCustomers.update_all + QboItem.update_all + QboEmployee.update_all end redirect_to qbo_path(:redmine_qbo), :flash => { :notice => "Successfully synced to Quickbooks" } diff --git a/app/models/qbo_employee.rb b/app/models/qbo_employee.rb index e6e06e2..758b26c 100644 --- a/app/models/qbo_employee.rb +++ b/app/models/qbo_employee.rb @@ -1,3 +1,17 @@ class QboEmployee < ActiveRecord::Base unloadable + attr_accessible :name + + def self.update_all + qbo = Qbo.first + service = Quickbooks::Service::Employee.new(:company_id => qbo.realmId, :access_token => Qbo.get_auth_token) + + # Update the item table + service.all.each { |employee| + qbo_employee = QboEmployee.find_or_create_by(id: employee.id) + qbo_employee.name = employee.display_name + qbo_employee.save! + } + end + end diff --git a/app/models/qbo_item.rb b/app/models/qbo_item.rb index 3c0afa8..0863e60 100644 --- a/app/models/qbo_item.rb +++ b/app/models/qbo_item.rb @@ -1,3 +1,16 @@ class QboItem < ActiveRecord::Base unloadable + attr_accessible :name + + def self.update_all + qbo = Qbo.first + service = Quickbooks::Service::Item.new(:company_id => qbo.realmId, :access_token => Qbo.get_auth_token) + + # Update the item table + service.all.each { |item| + qbo_item = QboItem.find_or_create_by(id: item.id) + qbo_item.name = item.name + qbo_item.save! + } + end end diff --git a/app/views/qbo/index.html.erb b/app/views/qbo/index.html.erb index 7d65bad..8fc4227 100644 --- a/app/views/qbo/index.html.erb +++ b/app/views/qbo/index.html.erb @@ -14,8 +14,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI

Redmine Quickbooks

- Customer Count: <%= @qbo_customer_count %> - + Customer Count: <%= @qbo_customer_count %> + Item Count: <%= @qbo_item_count %> + Employee Count: <%= @qbo_employee_count %>

<%= link_to "Sync", qbo_sync_path %>