Estimates are now attached to issues and displayed on the issue

This commit is contained in:
2016-01-12 21:45:56 -05:00
parent 98e94da39b
commit 135850b74d
4 changed files with 25 additions and 13 deletions

View File

@@ -69,6 +69,7 @@ class QboController < ApplicationController
QboCustomers.update_all
QboItem.update_all
QboEmployee.update_all
QboEstimate.update_all
end
redirect_to qbo_path(:redmine_qbo), :flash => { :notice => "Successfully synced to Quickbooks" }

View File

@@ -21,8 +21,8 @@ class QboEstimate < ActiveRecord::Base
def self.update_all
# Update the item table
get_base.service.all.each { |estimate|
qbo_estimate = QboItem.find_or_create_by(id: estimate.id)
qbo_estimate.name = estimate.doc_number
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!
}

View File

@@ -19,15 +19,20 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
unless Qbo.first.nil? and issue.qbo_customer_id.nil? and issue.qbo_item_id.nil? and employee_id.nil? then
# if this is a quote, lets create a new estimate based off estimated hours
if issue.tracker.name = "Quote" and issue.status.name = "New" and issue.custom_field_value(CustomField.find_by_name("Estimate").id).empty? then
if issue.tracker.name = "Quote" and issue.status.name = "New" and issue.qbo_estimate_id.nil? then
# Get QBO Services
item_service = QboItem.get_base.service
estimate_base = QboEstimate.get_base
estimate = Quickbooks::Model::Estimate .new
# Create the estimate
estimate = estimate_base.qr_model(:estimate)
estimate.customer_id = issue.qbo_customer_id
estimate.txn_date = Date.today
# Create the line item for labor
item = item_service.fetch_by_id issue.qbo_item_id
line_item = Quickbooks::Model::InvoiceLineItem.new
line_item.amount = item.unit_price * issue.estimated_hours
line_item.description = issue.subject
@@ -38,12 +43,11 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
detail.item_id = issue.qbo_item_id
end
# Add the line items to the estimate
estimate.line_items << line_item
service = Quickbooks::Service::Estimate.new(:company_id => Qbo.get_realm_id, :access_token => Qbo.get_auth_token)
created_estimate = service.create(estimate)
issue.custom_field_values = {CustomField.find_by_name("Estimate").id => created_estimate.doc_number}
# Save the etimate to the issue
issue.qbo_estimate_id = estimate_base.service.create(estimate).id
issue.save!
end
end

View File

@@ -13,6 +13,7 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
# View Issue
# Display the quickbooks contact in the issue
def view_issues_show_details_bottom(context={})
issue = context[:issue]
value = ""
# Check to see if there is a quickbooks user attached to the issue
@@ -25,7 +26,7 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
value = ""
# Check to see if there is a quickbooks item attached to the issue
if not context[:issue].qbo_customer_id.nil? then
if not issue.qbo_customer_id.nil? then
if not QboItem.find_by_id(context[:issue].qbo_item_id).nil? then
value = QboItem.find_by_id(context[:issue].qbo_item_id).name
end
@@ -33,6 +34,12 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
output << content_tag(:div, content_tag(:div, content_tag(:div, content_tag(:span,"Item") + ":", class:"label") + content_tag(:div, value, class:"value") , class:"qbo_item_id attribute"), class:"attributes")
# Estimate Number
unless (issue.qbo_estimate_id.nil?)
QboEstimate.update_all
output << content_tag(:div, content_tag(:div, content_tag(:div, content_tag(:span,"Estimate") + ":", class:"label") + content_tag(:div, QboEstimate.find_by_id(issue.qbo_estimate_id).doc_number, class:"value") , class:"qbo_item_id attribute"), class:"attributes")
end
# Display the Customers name in the Issue attributes
return output
end