From 84f1f8dacc718e4006517a40982f259b0bc4190c Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Fri, 1 Jan 2016 10:36:43 -0500 Subject: [PATCH] Initial commit --- .gitignore | 3 + Gemfile | 5 ++ LICENSE | 9 +++ README.rdoc | 3 + app/controllers/qbo_controller.rb | 76 ++++++++++++++++++++++++++ app/helpers/qbo_helper.rb | 12 ++++ app/models/qbo.rb | 14 +++++ app/models/qbo_customers.rb | 15 +++++ app/views/qbo/_settings.html.erb | 58 ++++++++++++++++++++ app/views/qbo/authenticate.html.erb | 33 +++++++++++ app/views/qbo/index.html.erb | 17 ++++++ app/views/qbo/oauth_callback.html.erb | 13 +++++ app/views/qbo/sync.html.erb | 17 ++++++ assets/images/.gitkeep | 0 assets/javascripts/.gitkeep | 0 assets/stylesheets/.gitkeep | 0 config/initializers/.gitkeep | 0 config/locales/en.yml | 14 +++++ config/routes.rb | 18 ++++++ db/migrate/001_create_qbos.rb | 22 ++++++++ db/migrate/002_create_qbo_customers.rb | 17 ++++++ db/migrate/003_update_issues.rb | 15 +++++ init.rb | 15 +++++ lib/qbo_hook_listener.rb | 55 +++++++++++++++++++ lib/tasks/.gitkeep | 0 test/functional/qbo_controller_test.rb | 18 ++++++ test/integration/.gitkeep | 0 test/test_helper.rb | 2 + test/unit/qbo_customers_test.rb | 19 +++++++ test/unit/qbo_test.rb | 19 +++++++ 30 files changed, 489 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 LICENSE create mode 100644 README.rdoc create mode 100644 app/controllers/qbo_controller.rb create mode 100644 app/helpers/qbo_helper.rb create mode 100644 app/models/qbo.rb create mode 100644 app/models/qbo_customers.rb create mode 100644 app/views/qbo/_settings.html.erb create mode 100644 app/views/qbo/authenticate.html.erb create mode 100644 app/views/qbo/index.html.erb create mode 100644 app/views/qbo/oauth_callback.html.erb create mode 100644 app/views/qbo/sync.html.erb create mode 100644 assets/images/.gitkeep create mode 100644 assets/javascripts/.gitkeep create mode 100644 assets/stylesheets/.gitkeep create mode 100644 config/initializers/.gitkeep create mode 100644 config/locales/en.yml create mode 100644 config/routes.rb create mode 100644 db/migrate/001_create_qbos.rb create mode 100644 db/migrate/002_create_qbo_customers.rb create mode 100644 db/migrate/003_update_issues.rb create mode 100644 init.rb create mode 100644 lib/qbo_hook_listener.rb create mode 100644 lib/tasks/.gitkeep create mode 100644 test/functional/qbo_controller_test.rb create mode 100644 test/integration/.gitkeep create mode 100644 test/test_helper.rb create mode 100644 test/unit/qbo_customers_test.rb create mode 100644 test/unit/qbo_test.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e0a6208 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.bundle +.config +Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..6b47f65 --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source 'https://rubygems.org' + + +gem 'quickbooks-ruby'#, :git => 'https://github.com/ruckus/quickbooks-ruby.git' +gem 'oauth-plugin'#, '~> 0.5.1' diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1270896 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +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. diff --git a/README.rdoc b/README.rdoc new file mode 100644 index 0000000..f86dc23 --- /dev/null +++ b/README.rdoc @@ -0,0 +1,3 @@ += redmine_qbo + +Description goes here diff --git a/app/controllers/qbo_controller.rb b/app/controllers/qbo_controller.rb new file mode 100644 index 0000000..b9c7754 --- /dev/null +++ b/app/controllers/qbo_controller.rb @@ -0,0 +1,76 @@ +#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 QboController < ApplicationController + unloadable + + QB_KEY = Setting.plugin_redmine_qbo['settingsOAuthConsumerKey'] + QB_SECRET = Setting.plugin_redmine_qbo['settingsOAuthConsumerSecret'] + + $qb_oauth_consumer = OAuth::Consumer.new(QB_KEY, QB_SECRET, { + :site => "https://oauth.intuit.com", + :request_token_path => "/oauth/v1/get_request_token", + :authorize_url => "https://appcenter.intuit.com/Connect/Begin", + :access_token_path => "/oauth/v1/get_access_token" + }) + + + def index + end + + def authenticate + callback = "https://rickbarrette.org/redmine/oauth_callback" + token = $qb_oauth_consumer.get_request_token(:oauth_callback => callback) + session[:qb_request_token] = token + redirect_to("https://appcenter.intuit.com/Connect/Begin?oauth_token=#{token.token}") and return + end + + def oauth_callback + at = session[:qb_request_token].get_access_token(:oauth_verifier => params[:oauth_verifier]) + token = at.token + secret = at.secret + realm_id = params['realmId'] + + #There can only be one... + Qbo.destroy_all + + qbo = Qbo.new + qbo.token = token + qbo.secret = secret + qbo.token_expires_at = 6.months.from_now.utc + qbo.reconnect_token_at = 5.months.from_now.utc + qbo.realmId = realm_id + if qbo.save! + redirect_to plugin_settings_path(:redmine_qbo), :flash => { :notice => "Successfully connected to Quickbooks" } + else + redirect_to plugin_settings_path(:redmine_qbo), :flash => { :error => "Errorn_settings_path" } + end + + end + + def sync + if Qbo.exists? then + qbo = Qbo.first + oauth_client = OAuth::AccessToken.new($qb_oauth_consumer, qbo.token, qbo.secret) + service = Quickbooks::Service::Customer.new(:company_id => qbo.realmId, :access_token => oauth_client) + + customers = service.all + + #update the customer table + customers.each { |customer| + qbo_customer = QboCustomers.find_or_create_by(id: customer.id) + qbo_customer.name = customer.display_name + qbo_customer.save! + } + end + + redirect_to plugin_settings_path(:redmine_qbo), :flash => { :notice => "Successfully synced to Quickbooks" } + end +end diff --git a/app/helpers/qbo_helper.rb b/app/helpers/qbo_helper.rb new file mode 100644 index 0000000..f36c781 --- /dev/null +++ b/app/helpers/qbo_helper.rb @@ -0,0 +1,12 @@ +#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. + +module QboHelper +end diff --git a/app/models/qbo.rb b/app/models/qbo.rb new file mode 100644 index 0000000..f6fe9bf --- /dev/null +++ b/app/models/qbo.rb @@ -0,0 +1,14 @@ +#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 Qbo < ActiveRecord::Base + unloadable + validates_presence_of :token, :secret, :realmId, :token_expires_at, :reconnect_token_at +end diff --git a/app/models/qbo_customers.rb b/app/models/qbo_customers.rb new file mode 100644 index 0000000..a829ff8 --- /dev/null +++ b/app/models/qbo_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 QboCustomers < ActiveRecord::Base + unloadable + has_many :issues + attr_accessible :name +end diff --git a/app/views/qbo/_settings.html.erb b/app/views/qbo/_settings.html.erb new file mode 100644 index 0000000..8daa7d6 --- /dev/null +++ b/app/views/qbo/_settings.html.erb @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + +
OAuth Consumer Key + +
OAuth Consumer Secret + +
+ +
+ + + + + + + + + + + + + +
Token Expires At<%= if Qbo.exists? then Qbo.first.token_expires_at end %> +
Reconnect Token At<%= if Qbo.exists? then Qbo.first.reconnect_token_at end %> +
+ +
+Note: You need to authenticate after saving your key and secret above +
+ +<%= link_to "Authenticate", authenticate_path, :method => :get %> diff --git a/app/views/qbo/authenticate.html.erb b/app/views/qbo/authenticate.html.erb new file mode 100644 index 0000000..1d977a5 --- /dev/null +++ b/app/views/qbo/authenticate.html.erb @@ -0,0 +1,33 @@ + + +

QboController#authenticate

+ + + + <% unless session[:token] %> + + <% end %> + + <% if notice %> +
<%= notice %>
+ <% end %> + + <%= yield %> + + + + + + diff --git a/app/views/qbo/index.html.erb b/app/views/qbo/index.html.erb new file mode 100644 index 0000000..20e6aae --- /dev/null +++ b/app/views/qbo/index.html.erb @@ -0,0 +1,17 @@ + + + + +

QboController#index

+ + diff --git a/app/views/qbo/oauth_callback.html.erb b/app/views/qbo/oauth_callback.html.erb new file mode 100644 index 0000000..0dc8b09 --- /dev/null +++ b/app/views/qbo/oauth_callback.html.erb @@ -0,0 +1,13 @@ + + +

QboController#oauth_callback

diff --git a/app/views/qbo/sync.html.erb b/app/views/qbo/sync.html.erb new file mode 100644 index 0000000..75d4b14 --- /dev/null +++ b/app/views/qbo/sync.html.erb @@ -0,0 +1,17 @@ + + + + +

QboController#sync

+ + diff --git a/assets/images/.gitkeep b/assets/images/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/assets/javascripts/.gitkeep b/assets/javascripts/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/assets/stylesheets/.gitkeep b/assets/stylesheets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/config/initializers/.gitkeep b/config/initializers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..e8de451 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,14 @@ +#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. + +# English strings go here for Rails i18n +en: + # my_label: "My label" + field_qbo_customer: "Customer" diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..1e07f6c --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,18 @@ +#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. + +# Plugin's routes +# See: http://guides.rubyonrails.org/routing.html +# + +get 'authenticate', :to => 'qbo#authenticate' +get 'oauth_callback', :to => 'qbo#oauth_callback' + + get 'qbo_sync', :to => 'qbo#sync' diff --git a/db/migrate/001_create_qbos.rb b/db/migrate/001_create_qbos.rb new file mode 100644 index 0000000..a703cb3 --- /dev/null +++ b/db/migrate/001_create_qbos.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 CreateQbos < ActiveRecord::Migration + + def change + create_table :qbos do |t| + t.string :token + t.string :secret + t.string :realmId + t.datetime :token_expires_at + t.datetime :reconnect_token_at + end + end +end diff --git a/db/migrate/002_create_qbo_customers.rb b/db/migrate/002_create_qbo_customers.rb new file mode 100644 index 0000000..ab8cb32 --- /dev/null +++ b/db/migrate/002_create_qbo_customers.rb @@ -0,0 +1,17 @@ +#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 CreateQboCustomers < ActiveRecord::Migration + def change + create_table :qbo_customers do |t| + t.string :name + end + end +end diff --git a/db/migrate/003_update_issues.rb b/db/migrate/003_update_issues.rb new file mode 100644 index 0000000..1367e5f --- /dev/null +++ b/db/migrate/003_update_issues.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 UpdateIssues < ActiveRecord::Migration + def change + add_reference :issues, :qbo_customer, index: true + end +end diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..ee748da --- /dev/null +++ b/init.rb @@ -0,0 +1,15 @@ +Redmine::Plugin.register :redmine_qbo do + + require_dependency 'qbo_hook_listener' + + name 'Redmine Quickbooks Online plugin' + author 'Rick Barrette' + description 'This is a plugin for Redmine to intergrate with Quickbooks Online to allow for seamless intergration CRM and invoicing of completed issues' + version '0.0.1' + url 'http://example.com/path/to/plugin' + author_url 'http://rickbarrette.org' + settings :default => {'empty' => true}, :partial => 'qbo/settings' + + + Quickbooks.sandbox_mode = true +end diff --git a/lib/qbo_hook_listener.rb b/lib/qbo_hook_listener.rb new file mode 100644 index 0000000..52f7609 --- /dev/null +++ b/lib/qbo_hook_listener.rb @@ -0,0 +1,55 @@ +#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 QboHookListener < Redmine::Hook::ViewListener + + # Edit Issue Form + # Show a dropdown for quickbooks contacts + def view_issues_form_details_bottom(context={}) + selected = "" + + # Check to see if there is a quickbooks user attached to the issue + if not context[:issue].qbo_customer_id.nil? then + selected = QboCustomers.find_by_id(context[:issue].qbo_customer_id).name + end + + # Generate the drop down list of quickbooks contacts + select = context[:form].select :qbo_customer_id, QboCustomers.all.pluck(:name, :id), include_blank: true, selected: selected + return "

#{select}

" + + #TODO save selection to Issues.qbp_customer_id + end + + # View Issue + # Display the quickbooks contact in the issue + def view_issues_show_details_bottom(context={}) + value = "" + + # Check to see if there is a quickbooks user attached to the issue + if not context[:issue].qbo_customer_id.nil? then + value = QboCustomers.find_by_id(context[:issue].qbo_customer_id).name + end + + # Display the Customers name in the Issue attributes + return content_tag(:div, content_tag(:div, content_tag(:div, content_tag(:span,"Customer") + ":", class:"label") + content_tag(:div, value, class:"value") , class:"qbo_customer_id attribute"), class:"attributes") + end + + # New Issue Saved + def controller_issues_new_after_save(context={}) + issue = context[:issue] + #TODO check if closed then create new quickbooks billable time entery + end + + # Existing Issue updated + def controller_issues_edit_after_save (context={}) + issue = context[:issue] + #TODO check if closed then create new quickbooks billable time entery + end +end diff --git a/lib/tasks/.gitkeep b/lib/tasks/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/functional/qbo_controller_test.rb b/test/functional/qbo_controller_test.rb new file mode 100644 index 0000000..aa15958 --- /dev/null +++ b/test/functional/qbo_controller_test.rb @@ -0,0 +1,18 @@ +#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. + +require File.expand_path('../../test_helper', __FILE__) + +class QboControllerTest < ActionController::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end diff --git a/test/integration/.gitkeep b/test/integration/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..54685d3 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,2 @@ +# Load the Redmine helper +require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper') diff --git a/test/unit/qbo_customers_test.rb b/test/unit/qbo_customers_test.rb new file mode 100644 index 0000000..145aee5 --- /dev/null +++ b/test/unit/qbo_customers_test.rb @@ -0,0 +1,19 @@ +#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. + +require File.expand_path('../../test_helper', __FILE__) + +class QboCustomersTest < ActiveSupport::TestCase + + # Replace this with your real tests. + def test_truth + assert true + end +end diff --git a/test/unit/qbo_test.rb b/test/unit/qbo_test.rb new file mode 100644 index 0000000..4e26e0c --- /dev/null +++ b/test/unit/qbo_test.rb @@ -0,0 +1,19 @@ +#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. + +require File.expand_path('../../test_helper', __FILE__) + +class QboTest < ActiveSupport::TestCase + + # Replace this with your real tests. + def test_truth + assert true + end +end