mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 08:54:23 -05:00
Merge branch 'import'
This commit is contained in:
@@ -26,12 +26,18 @@ class QboCustomer < ActiveRecord::Base
|
|||||||
def self.update_all
|
def self.update_all
|
||||||
customers = get_base.service.all
|
customers = get_base.service.all
|
||||||
|
|
||||||
ids = customers.map {|i| i.id}
|
delete_all
|
||||||
display_names = customers.map {|i| i.display_name}
|
|
||||||
|
|
||||||
# Update the customer table
|
|
||||||
find_or_create_by(id: ids, name: display_names)
|
|
||||||
|
|
||||||
|
transaction do
|
||||||
|
# Update the customer table
|
||||||
|
customers.each { |customer|
|
||||||
|
qbo_customer = QboCustomer.find_or_create_by(id: customer.id)
|
||||||
|
qbo_customer.name = customer.display_name
|
||||||
|
qbo_customer.id = customer.id
|
||||||
|
qbo_customer.save!
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
#remove deleted customers
|
#remove deleted customers
|
||||||
where.not(customers.map(&:id)).destroy_all
|
where.not(customers.map(&:id)).destroy_all
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,12 +20,16 @@ class QboEmployee < ActiveRecord::Base
|
|||||||
|
|
||||||
def self.update_all
|
def self.update_all
|
||||||
employees = get_base.service.all
|
employees = get_base.service.all
|
||||||
|
|
||||||
ids = employees.map {|i| i.id}
|
|
||||||
display_names = employees.map {|i| i.display_name}
|
|
||||||
|
|
||||||
# Update the customer table
|
transaction do
|
||||||
find_or_create_by(id: ids, name: display_names)
|
# Update the item table
|
||||||
|
employees.each { |employee|
|
||||||
|
qbo_employee = find_or_create_by(id: employee.id)
|
||||||
|
qbo_employee.name = employee.display_name
|
||||||
|
qbo_employee.id = employee.id
|
||||||
|
qbo_employee.save!
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
#remove deleted employees
|
#remove deleted employees
|
||||||
where.not(employees.map(&:id)).destroy_all
|
where.not(employees.map(&:id)).destroy_all
|
||||||
|
|||||||
@@ -21,11 +21,15 @@ class QboEstimate < ActiveRecord::Base
|
|||||||
def self.update_all
|
def self.update_all
|
||||||
estimates = get_base.service.all
|
estimates = get_base.service.all
|
||||||
|
|
||||||
ids = estimates.map {|i| i.id}
|
# Update the item table
|
||||||
doc_numbers = estimates.map {|i| i.doc_number}
|
transaction do
|
||||||
|
estimates.each { |estimate|
|
||||||
# Update the invoice table
|
qbo_estimate = QboEstimate.find_or_create_by(id: estimate.id)
|
||||||
find_or_create_by(id: ids, doc_number: doc_numbers)
|
qbo_estimate.doc_number = estimate.doc_number
|
||||||
|
qbo_estimate.id = estimate.id
|
||||||
|
qbo_estimate.save!
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
#remove deleted estimates
|
#remove deleted estimates
|
||||||
where.not(estimates.map(&:id)).destroy_all
|
where.not(estimates.map(&:id)).destroy_all
|
||||||
|
|||||||
@@ -21,11 +21,16 @@ class QboInvoice < ActiveRecord::Base
|
|||||||
def self.update_all
|
def self.update_all
|
||||||
#Pull the invoices from the quickbooks server
|
#Pull the invoices from the quickbooks server
|
||||||
invoices = get_base.service.all
|
invoices = get_base.service.all
|
||||||
ids = invoices.map {|i| i.id}
|
|
||||||
doc_numbers = invoices.map {|i| i.doc_number}
|
|
||||||
|
|
||||||
# Update the invoice table
|
# Update the invoice table
|
||||||
find_or_create_by(id: ids, doc_number: doc_numbers)
|
transaction do
|
||||||
|
invoices.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!
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
#remove deleted invoices
|
#remove deleted invoices
|
||||||
where.not(invoices.map(&:id)).destroy_all
|
where.not(invoices.map(&:id)).destroy_all
|
||||||
|
|||||||
@@ -20,12 +20,16 @@ class QboItem < ActiveRecord::Base
|
|||||||
|
|
||||||
def self.update_all
|
def self.update_all
|
||||||
items = get_base.service.find_by(:type, "Service")
|
items = get_base.service.find_by(:type, "Service")
|
||||||
|
|
||||||
ids = items.map {|i| i.id}
|
transaction do
|
||||||
names = items.map {|i| i.name}
|
# Update the item table
|
||||||
|
items.each { |item|
|
||||||
# Update the invoice table
|
qbo_item = QboItem.find_or_create_by(id: item.id)
|
||||||
find_or_create_by(id: ids, name: names)
|
qbo_item.name = item.name
|
||||||
|
qbo_item.id = item.id
|
||||||
|
qbo_item.save!
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
#remove deleted items
|
#remove deleted items
|
||||||
where.not(items.map(&:id)).destroy_all
|
where.not(items.map(&:id)).destroy_all
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
|
|||||||
#QboEstimate.update_all
|
#QboEstimate.update_all
|
||||||
|
|
||||||
# Check to see if there is a quickbooks user attached to the issue
|
# Check to see if there is a quickbooks user attached to the issue
|
||||||
selected_customer = context[:issue].qbo_customer.id if context[:issue].qbo_customer
|
@selected_customer = context[:issue].qbo_customer ? context[:issue].qbo_customer.id : nil
|
||||||
selected_item = context[:issue].qbo_item.id if context[:issue].qbo_item
|
@selected_item = context[:issue].qbo_item ? context[:issue].qbo_item.id : nil
|
||||||
selected_invoice = context[:issue].qbo_invoice.id if context[:issue].qbo_invoice
|
@selected_invoice = context[:issue].qbo_invoice ? context[:issue].qbo_invoice.id : nil
|
||||||
selected_estimate = context[:issue].qbo_estimate.id if context[:issue].qbo_estimate
|
@selected_estimate = context[:issue].qbo_estimate ? context[:issue].qbo_estimate.id : nil
|
||||||
|
|
||||||
# Generate the drop down list of quickbooks customers
|
# Generate the drop down list of quickbooks customers
|
||||||
@select_customer = context[:form].select :qbo_customer_id, QboCustomer.all.pluck(:name, :id).sort, :selected => selected_customer, include_blank: true
|
@select_customer = context[:form].select :qbo_customer_id, QboCustomer.all.pluck(:name, :id).sort, :selected => selected_customer, include_blank: true
|
||||||
|
|||||||
@@ -21,21 +21,23 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
|
|||||||
issue = context[:issue]
|
issue = context[:issue]
|
||||||
|
|
||||||
# Check to see if there is a quickbooks user attached to the issue
|
# Check to see if there is a quickbooks user attached to the issue
|
||||||
@customer = issue.qbo_customer.name if issue.qbo_customer
|
@customer = issue.qbo_customer ? issue.qbo_customer.name : nil
|
||||||
|
|
||||||
# Check to see if there is a quickbooks item attached to the issue
|
# Check to see if there is a quickbooks item attached to the issue
|
||||||
@item = issue.qbo_item.name if issue.qbo_item
|
@item = issue.qbo_item ? issue.qbo_item.name : nil
|
||||||
|
|
||||||
|
@estimate = nil
|
||||||
|
@estimate_link = nil
|
||||||
# Estimate Number
|
# Estimate Number
|
||||||
if issue.qbo_estimate
|
if issue.qbo_estimate
|
||||||
QboEstimate.update(issue.qbo_estimate.id)
|
|
||||||
@estimate = issue.qbo_estimate.doc_number
|
@estimate = issue.qbo_estimate.doc_number
|
||||||
@estimate_link = link_to @estimate, "#{Redmine::Utils::relative_url_root }/qbo/estimate/#{issue.qbo_estimate.id}", :target => "_blank"
|
@estimate_link = link_to @estimate, "#{Redmine::Utils::relative_url_root }/qbo/estimate/#{issue.qbo_estimate.id}", :target => "_blank"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@invoice = nil
|
||||||
|
@invo = nil
|
||||||
# Invoice Number
|
# Invoice Number
|
||||||
if issue.qbo_invoice
|
if issue.qbo_invoice
|
||||||
QboInvoice.update(issue.qbo_invoice.id)
|
|
||||||
@invoice = issue.qbo_invoice.doc_number
|
@invoice = issue.qbo_invoice.doc_number
|
||||||
@invoice_link = link_to @invoice, "#{Redmine::Utils::relative_url_root }/qbo/invoice/#{issue.qbo_invoice.id}", :target => "_blank"
|
@invoice_link = link_to @invoice, "#{Redmine::Utils::relative_url_root }/qbo/invoice/#{issue.qbo_invoice.id}", :target => "_blank"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user