From 88b66c4b4111825fb563b35464c30c8a0f44a58b Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Thu, 25 Feb 2016 22:51:38 -0500 Subject: [PATCH] Fixed Estiamte & Invoice Link Added Estimate Drop down Disabled Automatic Estimate Creation Added Controllers for Estimates & Invoices --- app/controllers/estimate_controller.rb | 22 +++++++++++++++++++++ app/controllers/invoice_controller.rb | 21 ++++++++++++++++++++ app/controllers/qbo_controller.rb | 21 +------------------- app/helpers/estimate_helper.rb | 2 ++ app/helpers/invoice_helper.rb | 2 ++ config/routes.rb | 4 ++-- lib/issues_form_hook_listener.rb | 8 +++++++- lib/issues_save_hook_listener.rb | 6 +++--- lib/issues_show_hook_listener.rb | 4 ++-- test/functional/estimate_controller_test.rb | 8 ++++++++ test/functional/invoice_controller_test.rb | 8 ++++++++ 11 files changed, 78 insertions(+), 28 deletions(-) create mode 100644 app/controllers/estimate_controller.rb create mode 100644 app/controllers/invoice_controller.rb create mode 100644 app/helpers/estimate_helper.rb create mode 100644 app/helpers/invoice_helper.rb create mode 100644 test/functional/estimate_controller_test.rb create mode 100644 test/functional/invoice_controller_test.rb diff --git a/app/controllers/estimate_controller.rb b/app/controllers/estimate_controller.rb new file mode 100644 index 0000000..a244b7f --- /dev/null +++ b/app/controllers/estimate_controller.rb @@ -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 diff --git a/app/controllers/invoice_controller.rb b/app/controllers/invoice_controller.rb new file mode 100644 index 0000000..d0a188e --- /dev/null +++ b/app/controllers/invoice_controller.rb @@ -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 diff --git a/app/controllers/qbo_controller.rb b/app/controllers/qbo_controller.rb index 49dd3f2..f114aa2 100644 --- a/app/controllers/qbo_controller.rb +++ b/app/controllers/qbo_controller.rb @@ -76,23 +76,4 @@ class QboController < ApplicationController redirect_to qbo_path(:redmine_qbo), :flash => { :notice => "Successfully synced to Quickbooks" } 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 \ No newline at end of file diff --git a/app/helpers/estimate_helper.rb b/app/helpers/estimate_helper.rb new file mode 100644 index 0000000..2c593e1 --- /dev/null +++ b/app/helpers/estimate_helper.rb @@ -0,0 +1,2 @@ +module EstimateHelper +end diff --git a/app/helpers/invoice_helper.rb b/app/helpers/invoice_helper.rb new file mode 100644 index 0000000..e168436 --- /dev/null +++ b/app/helpers/invoice_helper.rb @@ -0,0 +1,2 @@ +module InvoiceHelper +end diff --git a/config/routes.rb b/config/routes.rb index 18c2b64..4a6af82 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,5 +15,5 @@ get 'qbo', :to=> 'qbo#index' get 'qbo/authenticate', :to => 'qbo#authenticate' get 'qbo/oauth_callback', :to => 'qbo#oauth_callback' get 'qbo/sync', :to => 'qbo#sync' -get 'qbo/estimate/:id', :to => 'qbo#estimate_pdf', :as => :qbo_estimate_pdf -get 'qbo/invoice/:id', :to => 'qbo#invoice_pdf', :as => :qbo_invoice_pdf \ No newline at end of file +get 'qbo/estimate/:id', :to => 'estimate#show', as: :estimate +get 'qbo/invoice/:id', :to => 'invoice#show', as: :invoice \ No newline at end of file diff --git a/lib/issues_form_hook_listener.rb b/lib/issues_form_hook_listener.rb index 090a0ff..d57a9bb 100644 --- a/lib/issues_form_hook_listener.rb +++ b/lib/issues_form_hook_listener.rb @@ -17,11 +17,13 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener QboCustomer.update_all QboItem.update_all QboInvoice.update_all + QboEstimate.update_all # 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_item = context[:issue].qbo_item.id if context[:issue].qbo_item @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 @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 @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 "

#{@select_customer}

#{@select_item}

#{@select_invoice}

" + # 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 "

#{@select_customer}

#{@select_item}

#{@select_invoice}

#{@select_estimate}

" end end diff --git a/lib/issues_save_hook_listener.rb b/lib/issues_save_hook_listener.rb index ef6f891..2de5bb9 100644 --- a/lib/issues_save_hook_listener.rb +++ b/lib/issues_save_hook_listener.rb @@ -18,7 +18,7 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener if Qbo.first && issue.qbo_customer && issue.qbo_item # 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 item_service = QboItem.get_base.service @@ -46,8 +46,8 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener estimate.line_items << line_item # Save the etimate to the issue - issue.qbo_estimate_id = estimate_base.service.create(estimate).id - issue.save! + #issue.qbo_estimate_id = estimate_base.service.create(estimate).id + #issue.save! end end end diff --git a/lib/issues_show_hook_listener.rb b/lib/issues_show_hook_listener.rb index cc140a3..921eae1 100644 --- a/lib/issues_show_hook_listener.rb +++ b/lib/issues_show_hook_listener.rb @@ -30,14 +30,14 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener if issue.qbo_estimate QboEstimate.update(issue.qbo_estimate.id) @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 # Invoice Number if issue.qbo_invoice QboInvoice.update(issue.qbo_invoice.id) @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 return "
diff --git a/test/functional/estimate_controller_test.rb b/test/functional/estimate_controller_test.rb new file mode 100644 index 0000000..988b75c --- /dev/null +++ b/test/functional/estimate_controller_test.rb @@ -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 diff --git a/test/functional/invoice_controller_test.rb b/test/functional/invoice_controller_test.rb new file mode 100644 index 0000000..02a9dc0 --- /dev/null +++ b/test/functional/invoice_controller_test.rb @@ -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