Added removal for deleted entery while syncing

Added Invoices & Estimates to QBO#Index
This commit is contained in:
2016-02-28 12:07:58 -05:00
parent 82a273c0c2
commit ad4ce232b5
7 changed files with 78 additions and 9 deletions

View File

@@ -19,9 +19,8 @@ class QboController < ApplicationController
@qbo_customer_count = QboCustomer.count
@qbo_item_count = QboItem.count
@qbo_employee_count = QboEmployee.count
@selected_customer
@selected_item
@selected_employee
@qbo_invoice_count = QboInvoice.count
@qbo_estimate_count = QboEstimate.count
end
#

View File

@@ -24,12 +24,24 @@ class QboCustomer < ActiveRecord::Base
end
def self.update_all
service = get_base.service
# Update the customer table
get_base.service.all.each { |customer|
service.all.each { |customer|
qbo_customer = QboCustomer.find_or_create_by(id: customer.id)
qbo_customer.id = customer.id
qbo_customer.name = customer.display_name
qbo_customer.save!
}
#remove deleted customers
all.each { |customer|
begin
service.fetch_by_id(customer.id)
rescue
delete_all(id: customer.id)
end
}
end
end

View File

@@ -19,12 +19,23 @@ class QboEmployee < ActiveRecord::Base
end
def self.update_all
service = get_base.service
# Update the item table
get_base.service.all.each { |employee|
service.all.each { |employee|
qbo_employee = QboEmployee.find_or_create_by(id: employee.id)
qbo_employee.name = employee.display_name
qbo_employee.id = employee.id
qbo_employee.save!
}
#remove deleted employees
all.each { |employee|
begin
service.fetch_by_id(employee.id)
rescue
delete_all(id: employee.id)
end
}
end
end

View File

@@ -19,13 +19,24 @@ class QboEstimate < ActiveRecord::Base
end
def self.update_all
service = get_base.service
# Update the item table
get_base.service.all.each { |estimate|
service.all.each { |estimate|
qbo_estimate = QboEstimate.find_or_create_by(id: estimate.id)
qbo_estimate.doc_number = estimate.doc_number
qbo_estimate.id = estimate.id
qbo_estimate.save!
}
#remove deleted estimates
all.each { |estimate|
begin
service.fetch_by_id(estimate.id)
rescue
delete_all(id: estimate.id)
end
}
end
def self.update(id)

View File

@@ -19,13 +19,25 @@ class QboInvoice < ActiveRecord::Base
end
def self.update_all
service = get_base.service
# Update the item table
get_base.service.all.each { |invoice|
service.all.each { |invoice|
qbo_invoice = find_or_create_by(id: invoice.id)
qbo_invoice.doc_number = invoice.doc_number
qbo_invoice.id = invoice.id
qbo_invoice.save!
}
#remove deleted invoices
all.each { |invoice|
begin
service.fetch_by_id(invoice.id)
rescue
delete_all(id: invoice.id)
end
}
end
def self.update(id)

View File

@@ -19,12 +19,23 @@ class QboItem < ActiveRecord::Base
end
def self.update_all
service = get_base.service
# Update the item table
get_base.service.find_by(:type, "Service").each { |item|
service.find_by(:type, "Service").each { |item|
qbo_item = QboItem.find_or_create_by(id: item.id)
qbo_item.name = item.name
qbo_item.id = item.id
qbo_item.save!
}
#remove deleted items
all.each { |item|
begin
service.fetch_by_id(item.id)
rescue
delete_all(id: item.id)
end
}
end
end

View File

@@ -34,8 +34,21 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
<br/>
<%= f.select :qbo_employee_id, QboEmployee.all.pluck(:name, :id), :selected => @selected_employee, include_blank: true %>
</div>
<% end %>
<p>
<%= f.label "Invoice Count: "+@qbo_invoice_count.to_s %>
<br/>
<%=f.select :qbo_invoice_id, QboInvoice.all.pluck(:doc_number, :id).sort! {|x, y| y <=> x}, :selected => @selected_invoice, include_blank: true%>
</p>
<p>
<%= f.label "Estimate Count: "+@qbo_estimate_count.to_s %>
<br/>
<%=f.select :qbo_estimate_id, QboEstimate.all.pluck(:doc_number, :id).sort! {|x, y| y <=> x}, :selected => @selected_estimate, include_blank: true%>
</p>
<% end %>
<br/>
<br/>
<%= link_to "Sync", qbo_sync_path %>