mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 17:04:23 -05:00
Added sync functionality to Item and Employee
This commit is contained in:
@@ -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" }
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -15,7 +15,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
<h1> Redmine Quickbooks</h1>
|
||||
|
||||
Customer Count: <%= @qbo_customer_count %>
|
||||
|
||||
Item Count: <%= @qbo_item_count %>
|
||||
Employee Count: <%= @qbo_employee_count %>
|
||||
<br/>
|
||||
<br/>
|
||||
<%= link_to "Sync", qbo_sync_path %>
|
||||
|
||||
Reference in New Issue
Block a user