From e65d78bb2502f64eec726090852f5927b2055444 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Mon, 25 Jan 2016 12:31:26 -0500 Subject: [PATCH 01/16] Create qbo_purchase.rb Initial & untested commit for billable-purchases. TODO: Create database table Add relationships Attach to Issues --- app/models/qbo_purchase.rb | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 app/models/qbo_purchase.rb diff --git a/app/models/qbo_purchase.rb b/app/models/qbo_purchase.rb new file mode 100644 index 0000000..387f952 --- /dev/null +++ b/app/models/qbo_purchase.rb @@ -0,0 +1,47 @@ +#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 QboPurchase < ActiveRecord::Base + unloadable + belongs_to :issues, :customer + attr_accessible :description + validates_presence_of :id, :line_id, :description, :customer_id + + def self.get_base + Qbo.get_base(:purchase) + end + + def self.get_purchase(id) + get_base.service.find_by_id(id) + end + + def self.update_all + QboPurchases.get_base.service.all.each { |purchase| + + purchase.line_items.all.each { |line_item| + + detail = line_item.account_based_expense_line_detail if line_item.detail_type = :account_based_expense_line_detail + detail = line_item.item_based_expense_line_detail if line_item.detail_type = :item_based_expense_line_detail + + if detail.billable_status = "Billable" + qbo_purchase = find_or_create_by(id: purchase.id) + qbo_purchase.line_id = line_item.id + qbo_purchase.description = line_item.description + qbo_purchase.customer_id = detail.customer_ref + + #TODO attach to issues + #qbo_purchase.issue_id = Issue.find_by_invoice() + + qbo_purchase.save! + end + } + } + end +end From 6bcf210f79d9e96e3f40fb22f39649f6ead8d653 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Tue, 26 Jan 2016 12:24:48 -0500 Subject: [PATCH 02/16] Create 013_create_qbo_purchases.rb --- db/migrate/013_create_qbo_purchases.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 db/migrate/013_create_qbo_purchases.rb diff --git a/db/migrate/013_create_qbo_purchases.rb b/db/migrate/013_create_qbo_purchases.rb new file mode 100644 index 0000000..5f2064e --- /dev/null +++ b/db/migrate/013_create_qbo_purchases.rb @@ -0,0 +1,20 @@ +#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 CreateQboPurchases< ActiveRecord::Migration + def change + create_table :qbo_purchases, id: false do |t| + t.integer :id, :options => 'PRIMARY KEY' + t.integer :line_id + t.string :description + t.integer :customer_id + t.integer :issue_id + end +end From d79daa7a287c5205c6fb6660b53acd78226f2fb7 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Tue, 26 Jan 2016 12:32:49 -0500 Subject: [PATCH 03/16] Fixed migration for purchases --- db/migrate/013_create_qbo_purchases.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/db/migrate/013_create_qbo_purchases.rb b/db/migrate/013_create_qbo_purchases.rb index 5f2064e..4b269d1 100644 --- a/db/migrate/013_create_qbo_purchases.rb +++ b/db/migrate/013_create_qbo_purchases.rb @@ -16,5 +16,6 @@ class CreateQboPurchases< ActiveRecord::Migration t.string :description t.integer :customer_id t.integer :issue_id + end end end From 798bfde516af361b1d113f6c4c252530bbb17413 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 27 Jan 2016 09:21:28 -0500 Subject: [PATCH 04/16] Update qbo_controller.rb Added Purchases to sync --- app/controllers/qbo_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/qbo_controller.rb b/app/controllers/qbo_controller.rb index e849f81..49dd3f2 100644 --- a/app/controllers/qbo_controller.rb +++ b/app/controllers/qbo_controller.rb @@ -71,6 +71,7 @@ class QboController < ApplicationController QboEmployee.update_all QboEstimate.update_all QboInvoice.update_all + QboPurchase.update_all end redirect_to qbo_path(:redmine_qbo), :flash => { :notice => "Successfully synced to Quickbooks" } From 5155c0bc681faf2dd69518e64158aed1b62e953a Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 27 Jan 2016 09:31:51 -0500 Subject: [PATCH 05/16] Create 014_update_customers.rb Added reference to customers for purchases --- db/migrate/014_update_customers.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 db/migrate/014_update_customers.rb diff --git a/db/migrate/014_update_customers.rb b/db/migrate/014_update_customers.rb new file mode 100644 index 0000000..c81dcf8 --- /dev/null +++ b/db/migrate/014_update_customers.rb @@ -0,0 +1,15 @@ +#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 UpdateCustomers < ActiveRecord::Migration + def change + add_reference :qbo_customers, :qbo_purchase, index: true + end +end From d529139a9f5a4c7f12bc9abe8a95f4eef01ac1aa Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 27 Jan 2016 09:52:04 -0500 Subject: [PATCH 06/16] Update qbo_customer.rb --- app/models/qbo_customer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/qbo_customer.rb b/app/models/qbo_customer.rb index 24e6812..6f79ca6 100644 --- a/app/models/qbo_customer.rb +++ b/app/models/qbo_customer.rb @@ -10,7 +10,7 @@ class QboCustomer < ActiveRecord::Base unloadable - has_many :issues + has_many :issues, :qbo_purchases attr_accessible :name validates_presence_of :id, :name From b28e9b5a5b22ab02c3629ac5b034d2609cd9037e Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 27 Jan 2016 12:29:10 -0500 Subject: [PATCH 07/16] Update qbo_purchase.rb Fixed typo for QBO Customer --- app/models/qbo_purchase.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/qbo_purchase.rb b/app/models/qbo_purchase.rb index 387f952..5b0d11c 100644 --- a/app/models/qbo_purchase.rb +++ b/app/models/qbo_purchase.rb @@ -10,7 +10,7 @@ class QboPurchase < ActiveRecord::Base unloadable - belongs_to :issues, :customer + belongs_to :issues, :qbo_customer attr_accessible :description validates_presence_of :id, :line_id, :description, :customer_id From 89498c95597022ee5447577a866a09fe23b4a480 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 27 Jan 2016 12:31:33 -0500 Subject: [PATCH 08/16] Update qbo_purchase.rb Added seprate belongs_to line for customer --- app/models/qbo_purchase.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/qbo_purchase.rb b/app/models/qbo_purchase.rb index 5b0d11c..cad1ed8 100644 --- a/app/models/qbo_purchase.rb +++ b/app/models/qbo_purchase.rb @@ -10,7 +10,8 @@ class QboPurchase < ActiveRecord::Base unloadable - belongs_to :issues, :qbo_customer + belongs_to :issues + belongs_to :qbo_customer attr_accessible :description validates_presence_of :id, :line_id, :description, :customer_id From def5b72aa36e6aceb7dbf0f3b7c5d2775e0c6293 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 27 Jan 2016 12:32:18 -0500 Subject: [PATCH 09/16] Update qbo_customer.rb Added a separate has_many line for purchases --- app/models/qbo_customer.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/qbo_customer.rb b/app/models/qbo_customer.rb index 6f79ca6..e6d817d 100644 --- a/app/models/qbo_customer.rb +++ b/app/models/qbo_customer.rb @@ -10,7 +10,8 @@ class QboCustomer < ActiveRecord::Base unloadable - has_many :issues, :qbo_purchases + has_many :issues + has_many :qbo_purchases attr_accessible :name validates_presence_of :id, :name From baf251e2112636a44f1321c216f53f2a8eae59cc Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 27 Jan 2016 12:33:32 -0500 Subject: [PATCH 10/16] Update qbo_purchase.rb Fixed Typo --- app/models/qbo_purchase.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/qbo_purchase.rb b/app/models/qbo_purchase.rb index cad1ed8..24b9b5e 100644 --- a/app/models/qbo_purchase.rb +++ b/app/models/qbo_purchase.rb @@ -24,7 +24,7 @@ class QboPurchase < ActiveRecord::Base end def self.update_all - QboPurchases.get_base.service.all.each { |purchase| + QboPurchase.get_base.service.all.each { |purchase| purchase.line_items.all.each { |line_item| From 3d2176c5bd78dbbddd519925c2f21bb8422b6e7a Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 27 Jan 2016 12:42:56 -0500 Subject: [PATCH 11/16] Update qbo_purchase.rb WIP Fixing Purchase Sync Methods --- app/models/qbo_purchase.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/models/qbo_purchase.rb b/app/models/qbo_purchase.rb index 24b9b5e..518fe45 100644 --- a/app/models/qbo_purchase.rb +++ b/app/models/qbo_purchase.rb @@ -26,22 +26,24 @@ class QboPurchase < ActiveRecord::Base def self.update_all QboPurchase.get_base.service.all.each { |purchase| - purchase.line_items.all.each { |line_item| + purchase.line_items.all? { |line_item| detail = line_item.account_based_expense_line_detail if line_item.detail_type = :account_based_expense_line_detail detail = line_item.item_based_expense_line_detail if line_item.detail_type = :item_based_expense_line_detail - if detail.billable_status = "Billable" - qbo_purchase = find_or_create_by(id: purchase.id) - qbo_purchase.line_id = line_item.id - qbo_purchase.description = line_item.description - qbo_purchase.customer_id = detail.customer_ref + if detail + if detail.billable_status = "Billable" + qbo_purchase = find_or_create_by(id: purchase.id) + qbo_purchase.line_id = line_item.id + qbo_purchase.description = line_item.description + qbo_purchase.customer_id = detail.customer_ref - #TODO attach to issues - #qbo_purchase.issue_id = Issue.find_by_invoice() + #TODO attach to issues + #qbo_purchase.issue_id = Issue.find_by_invoice() - qbo_purchase.save! - end + qbo_purchase.save! + end + end } } end From 970a2fa681c64874d5d656a1273589cca3241c04 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 27 Jan 2016 14:14:31 -0500 Subject: [PATCH 12/16] Update qbo_purchase.rb Simplified line item detail logic... untested --- app/models/qbo_purchase.rb | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/app/models/qbo_purchase.rb b/app/models/qbo_purchase.rb index 518fe45..cedc15d 100644 --- a/app/models/qbo_purchase.rb +++ b/app/models/qbo_purchase.rb @@ -25,25 +25,22 @@ class QboPurchase < ActiveRecord::Base def self.update_all QboPurchase.get_base.service.all.each { |purchase| - + purchase.line_items.all? { |line_item| - - detail = line_item.account_based_expense_line_detail if line_item.detail_type = :account_based_expense_line_detail - detail = line_item.item_based_expense_line_detail if line_item.detail_type = :item_based_expense_line_detail - - if detail - if detail.billable_status = "Billable" + + detail = line_item.account_based_expense_line_detail ? line_item.account_based_expense_line_detail : line_item.item_based_expense_line_detail + + if detail.billable_status = "Billable" qbo_purchase = find_or_create_by(id: purchase.id) qbo_purchase.line_id = line_item.id qbo_purchase.description = line_item.description qbo_purchase.customer_id = detail.customer_ref - + #TODO attach to issues #qbo_purchase.issue_id = Issue.find_by_invoice() - + qbo_purchase.save! - end - end + end } } end From b57d51d80a69a77cbf0209c1a3b1053bb1477d62 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 27 Jan 2016 14:32:44 -0500 Subject: [PATCH 13/16] Create 015_update_qbo_purchases.rb --- db/migrate/015_update_qbo_purchases.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 db/migrate/015_update_qbo_purchases.rb diff --git a/db/migrate/015_update_qbo_purchases.rb b/db/migrate/015_update_qbo_purchases.rb new file mode 100644 index 0000000..4b5a747 --- /dev/null +++ b/db/migrate/015_update_qbo_purchases.rb @@ -0,0 +1,15 @@ +#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 UpdateQboPurchases < ActiveRecord::Migration + def change + rename_column :qbo_purchases, :customer_id, :qbo_customer_id + end +end From f2df6b51282f82e28d394081fa59ac6dad0ad23e Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 27 Jan 2016 14:33:27 -0500 Subject: [PATCH 14/16] Update qbo_purchase.rb Updated to use qbo_customer_id --- app/models/qbo_purchase.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/qbo_purchase.rb b/app/models/qbo_purchase.rb index cedc15d..1e2faec 100644 --- a/app/models/qbo_purchase.rb +++ b/app/models/qbo_purchase.rb @@ -13,7 +13,7 @@ class QboPurchase < ActiveRecord::Base belongs_to :issues belongs_to :qbo_customer attr_accessible :description - validates_presence_of :id, :line_id, :description, :customer_id + validates_presence_of :id, :line_id, :description, :qbo_customer_id def self.get_base Qbo.get_base(:purchase) @@ -34,7 +34,7 @@ class QboPurchase < ActiveRecord::Base qbo_purchase = find_or_create_by(id: purchase.id) qbo_purchase.line_id = line_item.id qbo_purchase.description = line_item.description - qbo_purchase.customer_id = detail.customer_ref + qbo_purchase.qbo_customer_id = detail.customer_ref #TODO attach to issues #qbo_purchase.issue_id = Issue.find_by_invoice() From e9038a56c10662362d818255e4b3c17c5a5f18a3 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Thu, 25 Feb 2016 20:54:20 -0500 Subject: [PATCH 15/16] Updated locale with Estimate --- app/models/qbo_purchase.rb | 2 +- config/locales/en.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/qbo_purchase.rb b/app/models/qbo_purchase.rb index 1e2faec..250d470 100644 --- a/app/models/qbo_purchase.rb +++ b/app/models/qbo_purchase.rb @@ -39,7 +39,7 @@ class QboPurchase < ActiveRecord::Base #TODO attach to issues #qbo_purchase.issue_id = Issue.find_by_invoice() - qbo_purchase.save! + qbo_purchase.save end } } diff --git a/config/locales/en.yml b/config/locales/en.yml index 39135e9..2277739 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -14,4 +14,5 @@ en: field_qbo_customer: "Customer" field_qbo_item: "Item" field_qbo_employee: "Employee" - field_qbo_invoice: "Invoice" \ No newline at end of file + field_qbo_invoice: "Invoice" + field_qbo_estimate: "Estimate" From 88b66c4b4111825fb563b35464c30c8a0f44a58b Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Thu, 25 Feb 2016 22:51:38 -0500 Subject: [PATCH 16/16] 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