Fixed Estiamte & Invoice Link

Added Estimate Drop down
Disabled Automatic Estimate Creation
Added Controllers for Estimates & Invoices
This commit is contained in:
2016-02-25 22:51:38 -05:00
parent e9038a56c1
commit 88b66c4b41
11 changed files with 78 additions and 28 deletions

View File

@@ -0,0 +1,22 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class EstimateController < ApplicationController
unloadable
#
# Downloads and forwards the estimate pdf
#
def show
base = QboEstimate.get_base.service
@pdf = base.pdf(base.fetch_by_id(params[:id]))
send_data @pdf, filename: "estimate.pdf", :disposition => 'inline', :type => "application/pdf"
end
end

View File

@@ -0,0 +1,21 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class InvoiceController < ApplicationController
unloadable
#
# Downloads and forwards the invoice pdf
#
def show
base = QboInvoice.get_base.service
@pdf = base.pdf(base.fetch_by_id(params[:id]))
send_data @pdf, filename: "invoice.pdf", :disposition => 'inline', :type => "application/pdf"
end
end

View File

@@ -76,23 +76,4 @@ class QboController < ApplicationController
redirect_to qbo_path(:redmine_qbo), :flash => { :notice => "Successfully synced to Quickbooks" } redirect_to qbo_path(:redmine_qbo), :flash => { :notice => "Successfully synced to Quickbooks" }
end end
#
# Downloads and forwards the estimate pdf
#
def estimate_pdf
base = QboEstimate.get_base.service
@pdf = base.pdf(base.fetch_by_id(params[:id]))
send_data @pdf, filename: "estimate.pdf", :disposition => 'inline', :type => "application/pdf"
end
#
# Downloads and forwards the invoice pdf
#
def invoice_pdf
base = QboInvoice.get_base.service
@pdf = base.pdf(base.fetch_by_id(params[:id]))
send_data @pdf, filename: "invoice.pdf", :disposition => 'inline', :type => "application/pdf"
end
end end

View File

@@ -0,0 +1,2 @@
module EstimateHelper
end

View File

@@ -0,0 +1,2 @@
module InvoiceHelper
end

View File

@@ -15,5 +15,5 @@ get 'qbo', :to=> 'qbo#index'
get 'qbo/authenticate', :to => 'qbo#authenticate' get 'qbo/authenticate', :to => 'qbo#authenticate'
get 'qbo/oauth_callback', :to => 'qbo#oauth_callback' get 'qbo/oauth_callback', :to => 'qbo#oauth_callback'
get 'qbo/sync', :to => 'qbo#sync' get 'qbo/sync', :to => 'qbo#sync'
get 'qbo/estimate/:id', :to => 'qbo#estimate_pdf', :as => :qbo_estimate_pdf get 'qbo/estimate/:id', :to => 'estimate#show', as: :estimate
get 'qbo/invoice/:id', :to => 'qbo#invoice_pdf', :as => :qbo_invoice_pdf get 'qbo/invoice/:id', :to => 'invoice#show', as: :invoice

View File

@@ -17,11 +17,13 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
QboCustomer.update_all QboCustomer.update_all
QboItem.update_all QboItem.update_all
QboInvoice.update_all QboInvoice.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.id if context[:issue].qbo_customer
@selected_item = context[:issue].qbo_item.id if context[:issue].qbo_item @selected_item = context[:issue].qbo_item.id if context[:issue].qbo_item
@selected_invoice = context[:issue].qbo_invoice.id if context[:issue].qbo_invoice @selected_invoice = context[:issue].qbo_invoice.id if context[:issue].qbo_invoice
@selected_estimate = context[:issue].qbo_estimate.id if context[:issue].qbo_estimate
# 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), :selected => @selected_customer, include_blank: true @select_customer = context[:form].select :qbo_customer_id, QboCustomer.all.pluck(:name, :id), :selected => @selected_customer, include_blank: true
@@ -32,6 +34,10 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
# Generate the drop down list of quickbooks invoices # Generate the drop down list of quickbooks invoices
@select_invoice = context[:form].select :qbo_invoice_id, QboInvoice.all.pluck(:doc_number, :id).sort! {|x, y| y <=> x}, :selected => @selected_invoice, include_blank: true @select_invoice = context[:form].select :qbo_invoice_id, QboInvoice.all.pluck(:doc_number, :id).sort! {|x, y| y <=> x}, :selected => @selected_invoice, include_blank: true
return "<p>#{@select_customer}</p> <p>#{@select_item}</p> <p>#{@select_invoice}</p>" # Generate the drop down list of quickbooks extimates
@select_estimate = context[:form].select :qbo_estimate_id, QboEstimate.all.pluck(:doc_number, :id).sort! {|x, y| y <=> x}, :selected => @selected_estimate, include_blank: true
return "<p>#{@select_customer}</p> <p>#{@select_item}</p> <p>#{@select_invoice}</p> <p>#{@select_estimate}</p>"
end end
end end

View File

@@ -18,7 +18,7 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
if Qbo.first && issue.qbo_customer && issue.qbo_item if Qbo.first && issue.qbo_customer && issue.qbo_item
# if this is a quote, lets create a new estimate based off estimated hours # if this is a quote, lets create a new estimate based off estimated hours
if issue.tracker.name = "Quote" && issue.status.name = "New" && !issue.qbo_estimate if issue.tracker.name = "Quote" && issue.status.name = "New" && issue.qbo_estimate
# Get QBO Services # Get QBO Services
item_service = QboItem.get_base.service item_service = QboItem.get_base.service
@@ -46,8 +46,8 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
estimate.line_items << line_item estimate.line_items << line_item
# Save the etimate to the issue # Save the etimate to the issue
issue.qbo_estimate_id = estimate_base.service.create(estimate).id #issue.qbo_estimate_id = estimate_base.service.create(estimate).id
issue.save! #issue.save!
end end
end end
end end

View File

@@ -30,14 +30,14 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
if issue.qbo_estimate if issue.qbo_estimate
QboEstimate.update(issue.qbo_estimate.id) QboEstimate.update(issue.qbo_estimate.id)
@estimate = issue.qbo_estimate.doc_number @estimate = issue.qbo_estimate.doc_number
@estimate_link = link_to @estimate, qbo_estimate_pdf_path(issue.qbo_estimate.id) @estimate_link = link_to @estimate, "#{Redmine::Utils::relative_url_root }/qbo/estimate/#{issue.qbo_estimate.id}", :target => "_blank"
end end
# Invoice Number # Invoice Number
if issue.qbo_invoice if issue.qbo_invoice
QboInvoice.update(issue.qbo_invoice.id) QboInvoice.update(issue.qbo_invoice.id)
@invoice = issue.qbo_invoice.doc_number @invoice = issue.qbo_invoice.doc_number
@invoice_link = link_to @invoice, qbo_invoice_pdf_path(issue.qbo_invoice.id) @invoice_link = link_to @invoice, "#{Redmine::Utils::relative_url_root }/qbo/invoice/#{issue.qbo_invoice.id}", :target => "_blank"
end end
return "<div class=\"attributes\"> return "<div class=\"attributes\">

View File

@@ -0,0 +1,8 @@
require File.expand_path('../../test_helper', __FILE__)
class EstimateControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end

View File

@@ -0,0 +1,8 @@
require File.expand_path('../../test_helper', __FILE__)
class InvoiceControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end