From 22311568738206cccb88d251cc1c8e7b256b96c4 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Mon, 14 Mar 2022 19:01:20 -0400 Subject: [PATCH 01/40] use estimate_doc_path not a hard coded path --- app/views/estimates/_search.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/estimates/_search.html.erb b/app/views/estimates/_search.html.erb index 4567ab7..2e4fba0 100644 --- a/app/views/estimates/_search.html.erb +++ b/app/views/estimates/_search.html.erb @@ -1,4 +1,4 @@ -<%= form_tag("/qbo/estimate/doc", :method => "get", id: "est-search-form") do %> +<%= form_tag(estimate_doc_path, :method => "get", id: "est-search-form") do %> <%= text_field_tag :search, params[:search], placeholder: t(:label_search_estimates), :autocomplete => "off" %> <%= submit_tag t(:label_search), :formtarget => "_blank" %> <% end %> From 0281d86f1ad49cf3721bae222b9a4c3cf8cee47e Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Mon, 14 Mar 2022 19:25:20 -0400 Subject: [PATCH 02/40] No id required --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 9134c3d..ee9844e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,7 @@ post 'qbo/webhook', :to => 'qbo#webhook' # Estimate & Invoice PDF get 'estimates/:id', :to => 'estimate#show', as: :estimate -get 'estimates/doc/:id', :to => 'estimate#doc', as: :estimate_doc +get 'estimates/doc/', :to => 'estimate#doc', as: :estimate_doc get 'invoices/:id', :to => 'invoice#show', as: :invoice #manual billing From b1a106d4d86154945de02104731477359c7d95f7 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Mon, 14 Mar 2022 19:27:31 -0400 Subject: [PATCH 03/40] No id required --- app/views/estimates/_search.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/estimates/_search.html.erb b/app/views/estimates/_search.html.erb index 2e4fba0..7a1a418 100644 --- a/app/views/estimates/_search.html.erb +++ b/app/views/estimates/_search.html.erb @@ -1,4 +1,4 @@ -<%= form_tag(estimate_doc_path, :method => "get", id: "est-search-form") do %> +<%= form_tag(estimate_doc_path, :method => "get") do %> <%= text_field_tag :search, params[:search], placeholder: t(:label_search_estimates), :autocomplete => "off" %> <%= submit_tag t(:label_search), :formtarget => "_blank" %> <% end %> From 7b7875991fdae656b5c9b3e26c20ebc3915dce02 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Mon, 14 Mar 2022 19:28:40 -0400 Subject: [PATCH 04/40] created get_estimate to remove redundant code --- app/controllers/estimate_controller.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/estimate_controller.rb b/app/controllers/estimate_controller.rb index cfab872..07b9816 100644 --- a/app/controllers/estimate_controller.rb +++ b/app/controllers/estimate_controller.rb @@ -14,16 +14,21 @@ class EstimateController < ApplicationController before_action :require_user, :unless => proc {|c| session[:token].nil? } skip_before_action :verify_authenticity_token, :check_if_login_required, :unless => proc {|c| session[:token].nil? } + + def get_estimate + estimate = Estimate.find_by_id(params[:id]) if params[:id] + estimate = Estimate.find_by_doc_number(params[:search]) if params[:search] + return estimate + end # # Downloads and forwards the estimate pdf # def show - e = Estimate.find_by_id(params[:id]) if params[:id] - e = Estimate.find_by_doc_number(params[:search]) if params[:search] + estimate = get_estimate begin - send_data e.pdf, filename: "estimate #{e.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf" + send_data estimate.pdf, filename: "estimate #{e.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf" rescue redirect_to :back, :flash => { :error => "Estimate not found" } end @@ -33,11 +38,10 @@ class EstimateController < ApplicationController # Downloads estimate by document number # def doc - e = Estimate.find_by_doc_number(params[:id]) if params[:id] - e = Estimate.find_by_doc_number(params[:search]) if params[:search] + estimate = get_estimate begin - send_data e.pdf, filename: "estimate #{e.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf" + send_data estimate.pdf, filename: "estimate #{e.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf" rescue redirect_to :back, :flash => { :error => "Estimate not found" } end From 3ea2cd14d1036777bba7f54bc25b4d9436dc0e15 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Mon, 14 Mar 2022 19:33:20 -0400 Subject: [PATCH 05/40] Fixed accidental removal of qbo prefix --- app/controllers/qbo_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/qbo_controller.rb b/app/controllers/qbo_controller.rb index fd9e625..4be1b46 100644 --- a/app/controllers/qbo_controller.rb +++ b/app/controllers/qbo_controller.rb @@ -55,7 +55,7 @@ class QboController < ApplicationController qbo.expire = 1.hour.from_now.utc if qbo.save! - redirect_to sync_path, :flash => { :notice => "Successfully connected to Quickbooks" } + redirect_to qbo_sync_path, :flash => { :notice => "Successfully connected to Quickbooks" } else redirect_to plugin_settings_path(:redmine_qbo), :flash => { :error => "Error" } end From b7e3ea9e3da799be1df3384dad3bc7b4eda8d525 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Mon, 14 Mar 2022 19:39:36 -0400 Subject: [PATCH 06/40] estimate not e --- app/controllers/estimate_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/estimate_controller.rb b/app/controllers/estimate_controller.rb index 07b9816..fd37dd0 100644 --- a/app/controllers/estimate_controller.rb +++ b/app/controllers/estimate_controller.rb @@ -28,7 +28,7 @@ class EstimateController < ApplicationController estimate = get_estimate begin - send_data estimate.pdf, filename: "estimate #{e.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf" + send_data estimate.pdf, filename: "estimate #{estimate.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf" rescue redirect_to :back, :flash => { :error => "Estimate not found" } end @@ -41,7 +41,7 @@ class EstimateController < ApplicationController estimate = get_estimate begin - send_data estimate.pdf, filename: "estimate #{e.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf" + send_data estimate.pdf, filename: "estimate #{estimate.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf" rescue redirect_to :back, :flash => { :error => "Estimate not found" } end From 0513763607a9363d554978d52619ce1e656d8c61 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Mon, 14 Mar 2022 19:41:53 -0400 Subject: [PATCH 07/40] Version 1.1.5 --- init.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.rb b/init.rb index 01dd0c9..45fd9e0 100644 --- a/init.rb +++ b/init.rb @@ -22,7 +22,7 @@ Redmine::Plugin.register :redmine_qbo do 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 '1.1.4' + version '1.1.5' url 'https://github.com/rickbarrette/redmine_qbo' author_url 'http://rickbarrette.org' settings :default => {'empty' => true}, :partial => 'qbo/settings' From 3622f8cad7e388a865da28399d54c0a0ed1c8339 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 19 Mar 2022 05:16:26 -0400 Subject: [PATCH 08/40] Added space --- lib/issue_patch.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/issue_patch.rb b/lib/issue_patch.rb index b7c1ecd..6aac525 100644 --- a/lib/issue_patch.rb +++ b/lib/issue_patch.rb @@ -79,7 +79,7 @@ module IssuePatch next if item.nil? # Create the new billable time entry and upload it - time_entry.description = "#{tracker} ##{id}: #{subject} #{"(Partial @ #{done_ratio}%)" if not closed?}" + time_entry.description = "#{tracker} ##{id} : #{subject} #{"(Partial @ #{done_ratio}%)" if not closed?}" time_entry.employee_id = assigned_to.employee_id time_entry.customer_id = customer_id time_entry.billable_status = "Billable" From 8e329b2dd250692d4ff4e26852e827ae73d55f52 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 19 Mar 2022 05:29:59 -0400 Subject: [PATCH 09/40] Fix broken invoice processing --- app/models/invoice.rb | 20 ++++++++++---------- lib/issue_patch.rb | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 1910dc4..8644e72 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -70,26 +70,26 @@ class Invoice < ActiveRecord::Base end # processes the invoice into the database - def self.process_invoice(invoice) - logger.info "Processing invoice #{invoice.id}" + def self.process_invoice(i) + logger.info "Processing invoice #{i.id}" # Load the invoice into the database - invoice = Invoice.find_or_create_by(id: invoice.id) - invoice.doc_number = invoice.doc_number - invoice.id = invoice.id - invoice.customer_id = invoice.customer_ref - invoice.txn_date = invoice.txn_date + invoice = Invoice.find_or_create_by(id: i.id) + invoice.doc_number = i.doc_number + invoice.id = i.id + invoice.customer_id = i.customer_ref + invoice.txn_date = i.txn_date invoice.save! # Scan the private notes for hashtags and attach to the applicable issues - if not invoice.private_note.nil? - invoice.private_note.scan(/#(\w+)/).flatten.each { |issue| + if not i.private_note.nil? + i.private_note.scan(/#(\w+)/).flatten.each { |issue| attach_to_issue(Issue.find_by_id(issue.to_i), invoice) } end # Scan the line items for hashtags and attach to the applicable issues - invoice.line_items.each { |line| + i.line_items.each { |line| if line.description line.description.scan(/#(\w+)/).flatten.each { |issue| attach_to_issue(Issue.find_by_id(issue.to_i), invoice) diff --git a/lib/issue_patch.rb b/lib/issue_patch.rb index 6aac525..b7c1ecd 100644 --- a/lib/issue_patch.rb +++ b/lib/issue_patch.rb @@ -79,7 +79,7 @@ module IssuePatch next if item.nil? # Create the new billable time entry and upload it - time_entry.description = "#{tracker} ##{id} : #{subject} #{"(Partial @ #{done_ratio}%)" if not closed?}" + time_entry.description = "#{tracker} ##{id}: #{subject} #{"(Partial @ #{done_ratio}%)" if not closed?}" time_entry.employee_id = assigned_to.employee_id time_entry.customer_id = customer_id time_entry.billable_status = "Billable" From d8d1942673e5dd29fd21f0ca1ed89294e2f1553a Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 19 Mar 2022 05:47:07 -0400 Subject: [PATCH 10/40] Version 1.1.6 --- init.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.rb b/init.rb index 45fd9e0..c79919d 100644 --- a/init.rb +++ b/init.rb @@ -22,7 +22,7 @@ Redmine::Plugin.register :redmine_qbo do 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 '1.1.5' + version '1.1.6' url 'https://github.com/rickbarrette/redmine_qbo' author_url 'http://rickbarrette.org' settings :default => {'empty' => true}, :partial => 'qbo/settings' From 3220ff728f59734679c6bf9d6250bfea9f9b2bfb Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 6 Apr 2022 12:45:40 -0400 Subject: [PATCH 11/40] Fixed process_estimate that I accidently broke --- app/models/estimate.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/estimate.rb b/app/models/estimate.rb index 4d9bf82..541f4bd 100644 --- a/app/models/estimate.rb +++ b/app/models/estimate.rb @@ -50,13 +50,13 @@ class Estimate < ActiveRecord::Base end # process an estimate into the database - def self.process_estimate(estimate) - logger.info "Processing estimate #{estimate.id}" - estimate = find_or_create_by(id: estimate.id) - estimate.doc_number = estimate.doc_number - estimate.customer_id = estimate.customer_ref.value - estimate.id = estimate.id - estimate.txn_date = estimate.txn_date + def self.process_estimate(qbo_estimate) + logger.info "Processing estimate #{qbo_estimate.id}" + estimate = find_or_create_by(id: qbo_estimate.id) + estimate.doc_number = qbo_estimate.doc_number + estimate.customer_id = qbo_estimate.customer_ref.value + estimate.id = qbo_estimate.id + estimate.txn_date = qbo_estimate.txn_date estimate.save! end From 6dbf84f4017f8a35757d4afa3d04230ad444f462 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 4 May 2022 12:37:31 -0400 Subject: [PATCH 12/40] Added nil check to address_to_s --- app/controllers/customers_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb index fcb7142..353e266 100644 --- a/app/controllers/customers_controller.rb +++ b/app/controllers/customers_controller.rb @@ -214,14 +214,14 @@ class CustomersController < ApplicationController # format a quickbooks address to a human readable string def address_to_s (address) return if address.nil? - string = address.line1 + string = address.line1 if address.line1 string << "\n" + address.line2 if address.line2 string << "\n" + address.line3 if address.line3 string << "\n" + address.line4 if address.line4 string << "\n" + address.line5 if address.line5 - string << " " + address.city - string << ", " + address.country_sub_division_code - string << " " + address.postal_code + string << " " + address.city if address.city + string << ", " + address.country_sub_division_code if address.country_sub_division_code + string << " " + address.postal_code if address.postal_code return string end From 26433c9020e436e13a3101217cd67365c597b4da Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 14 Jan 2023 06:38:48 -0500 Subject: [PATCH 13/40] Added hour totals to customer job history --- app/controllers/customers_controller.rb | 4 ++++ app/views/customers/show.html.erb | 4 ++-- config/locales/en.yml | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb index 353e266..e8b8ec4 100644 --- a/app/controllers/customers_controller.rb +++ b/app/controllers/customers_controller.rb @@ -93,6 +93,10 @@ class CustomersController < ApplicationController @billing_address = address_to_s(@customer.billing_address) @shipping_address = address_to_s(@customer.shipping_address) @closed_issues = (@issues - @issues.open) + @hours = 0 + @closed_hours = 0 + @issues.open.each { |i| @hours+= i.total_spent_hours } + @closed_issues.each { |i| @closed_hours+= i.total_spent_hours } rescue render_404 end diff --git a/app/views/customers/show.html.erb b/app/views/customers/show.html.erb index 2a7689f..af5d5b7 100644 --- a/app/views/customers/show.html.erb +++ b/app/views/customers/show.html.erb @@ -35,8 +35,8 @@
-

<%=@issues.open.count%> <%=t(:label_open_issues)%>:

+

<%=@issues.open.count%> <%=t(:label_open_issues)%> - <%=@hours.round(1)%> <%=t(:label_hours)%>

<%= render :partial => 'issues/list_simple', locals: {issues: @issues.open} %> -

<%=@closed_issues.count%> <%=t(:label_closed_issues)%>:

+

<%=@closed_issues.count%> <%=t(:label_closed_issues)%> - <%= @closed_hours.round(1)%> <%=t(:label_hours)%>

<%= render :partial => 'issues/list_simple', locals: {issues: @closed_issues} %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 48768cb..c93d22c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -87,4 +87,5 @@ en: label_billed_success: "Successfully Billed " label_billing_error: "Cannot bill without a customer assigned" label_qbo_sync_success: "Successfully synced to Quickbooks" + label_hours: "Hours" \ No newline at end of file From 3a0e58c3dab6398f198b15bcf4c6aa643f067d68 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Mon, 22 May 2023 07:34:18 -0400 Subject: [PATCH 14/40] Append last 4 of phone number to customers name --- app/models/customer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/customer.rb b/app/models/customer.rb index ce9ba02..accb7f8 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -23,7 +23,7 @@ class Customer < ActiveRecord::Base # returns a human readable string def to_s - return name + return "#{self[:name]} - #{phone_number.split(//).last(4).join unless phone_number.nil?}" end # Convenience Method From b3a809ab1cd445a3750d104a4ac7f496574b6a22 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Wed, 27 Dec 2023 15:03:08 -0500 Subject: [PATCH 15/40] Redmine 5.1 Update --- Gemfile | 2 +- init.rb | 8 ++++---- lib/pdf_patch.rb | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index 9924dce..baf0247 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' gem 'quickbooks-ruby' -gem 'oauth2', '1.4.7' +gem 'oauth2' gem 'roxml' gem 'nhtsa_vin' gem 'will_paginate' diff --git a/init.rb b/init.rb index c79919d..25795c2 100644 --- a/init.rb +++ b/init.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2022 rick barrette +#Copyright (c) 2023 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: # @@ -22,11 +22,11 @@ Redmine::Plugin.register :redmine_qbo do 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 '1.1.6' + version '1.2.0' url 'https://github.com/rickbarrette/redmine_qbo' - author_url 'http://rickbarrette.org' + author_url 'https://barrettefabrication.com' settings :default => {'empty' => true}, :partial => 'qbo/settings' - requires_redmine :version_or_higher => '4.0.0' + requires_redmine :version_or_higher => '5.1.0' # Add safe attributes for core models Issue.safe_attributes 'customer_id' diff --git a/lib/pdf_patch.rb b/lib/pdf_patch.rb index ed659b0..803f045 100644 --- a/lib/pdf_patch.rb +++ b/lib/pdf_patch.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2022 rick barrette +#Copyright (c) 2023 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: # @@ -11,7 +11,7 @@ require_dependency 'redmine/export/pdf' require_dependency 'redmine/export/pdf/issues_pdf_helper' -module IssuesPdfHelperPatch +module PdfPatch def self.included(base) base.send(:include, InstanceMethods) @@ -256,4 +256,4 @@ module IssuesPdfHelperPatch end end -Redmine::Export::PDF::IssuesPdfHelper.send(:include, IssuesPdfHelperPatch) +Redmine::Export::PDF::IssuesPdfHelper.send(:include, PdfPatch) From 78391161341248b0569b63321cf98877457b9349 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Wed, 27 Dec 2023 16:31:11 -0500 Subject: [PATCH 16/40] Version 2.0.0 --- README.md | 5 ++++- init.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 06e0968..51ae0a2 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,10 @@ The goal of this project is to allow Redmine to connect with Quickbooks Online t Note: Although the core functionality is complete, this project is still under development & the master branch may be unstable. Tags should be stable and are recommended -Use tags Version 1.0.0+ for Redmine 4+ and Version 0.8.1 for Redine 3 +Use tags for the following Redmine Versions +* Version 2.0.0+ for Redmine 5+ +* Version 1.0.0+ for Redmine 4+ +* Version 0.8.1 for Redine 3 #### Features * Issues can be assigned to a Customer via drop down in the edit Issue form diff --git a/init.rb b/init.rb index 25795c2..14be242 100644 --- a/init.rb +++ b/init.rb @@ -22,7 +22,7 @@ Redmine::Plugin.register :redmine_qbo do 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 '1.2.0' + version '2.0.0' url 'https://github.com/rickbarrette/redmine_qbo' author_url 'https://barrettefabrication.com' settings :default => {'empty' => true}, :partial => 'qbo/settings' From 8380dda25a53b40b692e938653c67ae996873563 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Fri, 29 Dec 2023 17:06:00 -0500 Subject: [PATCH 17/40] render 403 when forbidden --- app/helpers/auth_helper.rb | 6 +++--- app/views/public/401.html.erb | 1 - config/locales/en.yml | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) delete mode 100644 app/views/public/401.html.erb diff --git a/app/helpers/auth_helper.rb b/app/helpers/auth_helper.rb index 42b81a2..7959fec 100644 --- a/app/helpers/auth_helper.rb +++ b/app/helpers/auth_helper.rb @@ -13,7 +13,7 @@ module AuthHelper def require_user return unless session[:token].nil? if !User.current.logged? - render :file => "public/401.html.erb", :status => :unauthorized, :layout =>true + render_403 end end @@ -27,14 +27,14 @@ module AuthHelper def check_permission(permission) if !allowed_to?(permission) - render :file => "public/401.html.erb", :status => :unauthorized, :layout =>true + render_403 end end def global_check_permission(permission) if !globaly_allowed_to?(permission) - render :file => "public/401.html.erb", :status => :unauthorized, :layout =>true + render_403 end end diff --git a/app/views/public/401.html.erb b/app/views/public/401.html.erb deleted file mode 100644 index 50381b8..0000000 --- a/app/views/public/401.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= flash.now[:error] = t(:label_401) %> diff --git a/config/locales/en.yml b/config/locales/en.yml index c93d22c..5543f76 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -25,7 +25,6 @@ en: label_search_estimates: "Search Estimates" label_search: "Search" label_estimates: "Estimates" - label_401: "Not Authorized" warn_ru_sure: "You sure?" label_delete: "Delete" label_edit: "Edit" From 5b89d73c208c001431c798c54cf4062adb61b85d Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Fri, 29 Dec 2023 18:56:20 -0500 Subject: [PATCH 18/40] Remove QboItem.sync --- app/controllers/qbo_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/qbo_controller.rb b/app/controllers/qbo_controller.rb index 4be1b46..3d7c4cd 100644 --- a/app/controllers/qbo_controller.rb +++ b/app/controllers/qbo_controller.rb @@ -145,7 +145,6 @@ class QboController < ApplicationController if Qbo.exists? Customer.sync Invoice.sync - QboItem.sync Employee.sync Estimate.sync From b304c3a1759ad081aa082ea4abce920d0b9ebeea Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Fri, 29 Dec 2023 19:09:24 -0500 Subject: [PATCH 19/40] Fixed employee typo --- app/models/employee.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/models/employee.rb b/app/models/employee.rb index efc4a1f..3319558 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2022 rick barrette +#Copyright (c) 2023 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: # @@ -22,10 +22,11 @@ class Employee < ActiveRecord::Base transaction do # Update the item table - employees.each { |employee| - employee = find_or_create_by(id: employee.id) - employee.name = employee.display_name - employee.id = employee.id + employees.each { |e| + logger.info "Processing employee #{e.id}" + employee = find_or_create_by(id: e.id) + employee.name = e.display_name + employee.id = e.id employee.save! } end From 122063b1d59f414c360739f3bb7575b523b0b6e2 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Fri, 29 Dec 2023 19:14:38 -0500 Subject: [PATCH 20/40] Fixed customer typo --- app/models/customer.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/models/customer.rb b/app/models/customer.rb index accb7f8..6ace67b 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -147,16 +147,17 @@ class Customer < ActiveRecord::Base # customers = service.query(query) #end - customers.each do |customer| - customer = Customer.find_or_create_by(id: customer.id) - if customer.active? - if not customer.name.eql? customer.display_name - customer.name = customer.display_name - customer.id = customer.id + customers.each do |c| + logger.info "Processing customer #{c.id}" + customer = Customer.find_or_create_by(id: c.id) + if c.active? + if not customer.name.eql? c.display_name + customer.name = c.display_name + customer.id = c.id customer.save_without_push end else - if not customer.new_record? + if not c.new_record? customer.delete end end From 6760b2914852d84b1d9927a515afd94f2a537582 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Fri, 29 Dec 2023 19:20:31 -0500 Subject: [PATCH 21/40] Log the time stamp --- app/models/qbo.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/qbo.rb b/app/models/qbo.rb index 09f3515..337639e 100644 --- a/app/models/qbo.rb +++ b/app/models/qbo.rb @@ -87,8 +87,10 @@ class Qbo < ActiveRecord::Base # Updates last sync time stamp def self.update_time_stamp + date = DateTime.now + logger.info "Updating QBO timestamp to #{date}" qbo = Qbo.first - qbo.last_sync = DateTime.now + qbo.last_sync = date qbo.save end From 7d510e4028da2fddc33f7e2ef0609dd1495b1506 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Fri, 29 Dec 2023 20:06:15 -0500 Subject: [PATCH 22/40] Added notes to allowed params --- app/controllers/customers_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb index e8b8ec4..44ee4c8 100644 --- a/app/controllers/customers_controller.rb +++ b/app/controllers/customers_controller.rb @@ -36,7 +36,7 @@ class CustomersController < ApplicationController autocomplete :customer, :name, :full => true, :extra_data => [:id] def allowed_params - params.require(:customer).permit(:name, :email, :primary_phone, :mobile_phone, :phone_number) + params.require(:customer).permit(:name, :email, :primary_phone, :mobile_phone, :phone_number, :notes) end # getter method for a customer's vehicles From 96e4e9df6644624f69cacd111415d65b8f617198 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Fri, 29 Dec 2023 20:17:46 -0500 Subject: [PATCH 23/40] Fixed typo with params --- app/controllers/customers_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb index 44ee4c8..aca80bc 100644 --- a/app/controllers/customers_controller.rb +++ b/app/controllers/customers_controller.rb @@ -115,7 +115,7 @@ class CustomersController < ApplicationController def update begin @customer = Customer.find_by_id(params[:id]) - if @customer.update_attributes(allowed_params) + if @customer.update_attributes(params) flash[:notice] = "Customer updated" redirect_to @customer else From 47868051f897b8a6902722875bdaaaa491247b0a Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Fri, 29 Dec 2023 20:25:26 -0500 Subject: [PATCH 24/40] Rails 6.1 Deprecates update_attributes --- app/controllers/customers_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb index aca80bc..dae292c 100644 --- a/app/controllers/customers_controller.rb +++ b/app/controllers/customers_controller.rb @@ -115,7 +115,7 @@ class CustomersController < ApplicationController def update begin @customer = Customer.find_by_id(params[:id]) - if @customer.update_attributes(params) + if @customer.update(allowed_params) flash[:notice] = "Customer updated" redirect_to @customer else From 517a23948528f863dda5def6218d169091412ae6 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 30 Dec 2023 12:39:51 -0500 Subject: [PATCH 25/40] Started reworking Oauth token sorage --- app/controllers/qbo_controller.rb | 15 ++--- app/models/concerns/quickbooks_oauth.rb | 80 ++++++++++++++++++++++++ app/models/qbo.rb | 81 ++++++------------------- db/migrate/037_update_qbo_token.rb | 18 ++++++ 4 files changed, 122 insertions(+), 72 deletions(-) create mode 100644 app/models/concerns/quickbooks_oauth.rb create mode 100644 db/migrate/037_update_qbo_token.rb diff --git a/app/controllers/qbo_controller.rb b/app/controllers/qbo_controller.rb index 3d7c4cd..f6c8be1 100644 --- a/app/controllers/qbo_controller.rb +++ b/app/controllers/qbo_controller.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2022 rick barrette +#Copyright (c) 2023 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: # @@ -26,7 +26,7 @@ class QboController < ApplicationController # Called when the user requests that Redmine to connect to QBO # def authenticate - oauth2_client = Qbo.get_client + oauth2_client = Qbo.construct_oauth2_client callback = Setting.host_name + "/qbo/oauth_callback/" grant_url = oauth2_client.auth_code.authorize_url(redirect_uri: callback, response_type: "code", state: SecureRandom.hex(12), scope: "com.intuit.quickbooks.accounting") redirect_to grant_url @@ -37,7 +37,7 @@ class QboController < ApplicationController # def oauth_callback if params[:state].present? - oauth2_client = Qbo.get_client + oauth2_client = Qbo.construct_oauth2_client # use the state value to retrieve from your backend any information you need to identify the customer in your system redirect_uri = Setting.host_name + "/qbo/oauth_callback/" if resp = oauth2_client.auth_code.get_token(params[:code], redirect_uri: redirect_uri) @@ -47,12 +47,7 @@ class QboController < ApplicationController # Save the authentication information qbo = Qbo.new - qbo.company_id = params[:realmId] - - # Generate Access Token & Serialize it into the database - access_token = OAuth2::AccessToken.new(oauth2_client, resp.token, refresh_token: resp.refresh_token) - qbo.token = access_token.to_hash - qbo.expire = 1.hour.from_now.utc + qbo.update(access_token: resp.token, refresh_token: resp.refresh_token, realm_id: params[:realmId]) if qbo.save! redirect_to qbo_sync_path, :flash => { :notice => "Successfully connected to Quickbooks" } @@ -154,6 +149,6 @@ class QboController < ApplicationController ActiveRecord::Base.connection.close end - redirect_to :home, :flash => { :notice => "Successfully synced to Quickbooks" } + redirect_to :home, :flash => { :notice => "Syncing Quickbooks" } end end diff --git a/app/models/concerns/quickbooks_oauth.rb b/app/models/concerns/quickbooks_oauth.rb new file mode 100644 index 0000000..9e03a82 --- /dev/null +++ b/app/models/concerns/quickbooks_oauth.rb @@ -0,0 +1,80 @@ +#The MIT License (MIT) +# +#Copyright (c) 2023 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 QuickbooksOauth + extend ActiveSupport::Concern + + OAUTH_CONSUMER_KEY = Setting.plugin_redmine_qbo['settingsOAuthConsumerKey'] + OAUTH_CONSUMER_SECRET = Setting.plugin_redmine_qbo['settingsOAuthConsumerSecret'] + + #== Instance Methods + + def perform_authenticated_request(&block) + attempts = 0 + begin + yield oauth_access_token + rescue OAuth2::Error, Quickbooks::AuthorizationFailure => ex + Rails.logger.info("QuickbooksOauth.perform: #{ex.message}") + + # to prevent an infinite loop here keep a counter and bail out after N times... + attempts += 1 + + raise "QuickbooksOauth:ExceededAuthAttempts" if attempts >= 3 + + # check if its an invalid_grant first, but assume it is for now + refresh_token! + + retry + end + end + + def refresh_token! + t = oauth_access_token + refreshed = t.refresh! + + if refreshed.params['x_refresh_token_expires_in'].to_i > 0 + oauth2_refresh_token_expires_at = Time.now + refreshed.params['x_refresh_token_expires_in'].to_i.seconds + else + oauth2_refresh_token_expires_at = 100.days.from_now + end + + update!( + oauth2_access_token: refreshed.token, + oauth2_access_token_expires_at: Time.at(refreshed.expires_at), + oauth2_refresh_token: refreshed.refresh_token, + oauth2_refresh_token_expires_at: oauth2_refresh_token_expires_at + ) + end + + def oauth_client + self.class.construct_oauth2_client + end + + def oauth_access_token + OAuth2::AccessToken.new(oauth_client, oauth2_access_token, refresh_token: oauth2_refresh_token) + end + + def consumer + oauth_access_token + end + + module ClassMethods + + def construct_oauth2_client + options = { + site: "https://appcenter.intuit.com/connect/oauth2", + authorize_url: "https://appcenter.intuit.com/connect/oauth2", + token_url: "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer" + } + OAuth2::Client.new(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, options) + end + + end +end diff --git a/app/models/qbo.rb b/app/models/qbo.rb index 337639e..7cd9b97 100644 --- a/app/models/qbo.rb +++ b/app/models/qbo.rb @@ -10,31 +10,8 @@ class Qbo < ActiveRecord::Base unloadable - validates_presence_of :token, :company_id, :expire - serialize :token - - OAUTH_CONSUMER_KEY = Setting.plugin_redmine_qbo['settingsOAuthConsumerKey'] - OAUTH_CONSUMER_SECRET = Setting.plugin_redmine_qbo['settingsOAuthConsumerSecret'] - - # - # Getter for quickbooks OAuth2 client - # - def self.get_client - oauth_params = { - site: "https://appcenter.intuit.com/connect/oauth2", - authorize_url: "https://appcenter.intuit.com/connect/oauth2", - token_url: "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer" - } - return OAuth2::Client.new(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, oauth_params) - end - - # - # Getter for oauth consumer - # - def self.get_oauth_consumer - # Quickbooks Config Info - return $qb_oauth_consumer - end + + include QuickbooksOauth # # Get a quickbooks base service object for type @@ -42,47 +19,27 @@ class Qbo < ActiveRecord::Base # def self.get_base(type) # lets getnourbold access token from the database - oauth2_client = get_client + oauth2_client = construct_oauth2_client qbo = self.first - access_token = OAuth2::AccessToken.from_hash(oauth2_client, qbo.token) - # check to see if we need to refresh the acesstoken - if qbo.expire.to_time.utc.past? - puts "Updating access token" - new_access_token_object = access_token.refresh! - qbo.token = new_access_token_object.to_hash - qbo.expire = 1.hour.from_now.utc - qbo.save! - access_token = new_access_token_object - else - puts "Using current token" - end - - # build the reqiested service - case type - when :item - return Quickbooks::Service::Item.new(:company_id => qbo.company_id, :access_token => access_token) - when :time_activity - return Quickbooks::Service::TimeActivity.new(:company_id => qbo.company_id, :access_token => access_token) - when :customer - return Quickbooks::Service::Customer.new(:company_id => qbo.company_id, :access_token => access_token) - when :invoice - return Quickbooks::Service::Invoice.new(:company_id => qbo.company_id, :access_token => access_token) - when :estimate - return Quickbooks::Service::Estimate.new(:company_id => qbo.company_id, :access_token => access_token) - when :account - return Quickbooks::Service::Account.new(:company_id => qbo.company_id, :access_token => access_token) - when :employee - return Quickbooks::Service::Employee.new(:company_id => qbo.company_id, :access_token => access_token) - else - return access_token + qbo.perform_authenticated_request do |access_token| + # build the reqiested service + case type + when :time_activity + return Quickbooks::Service::TimeActivity.new(:company_id => qbo.company_id, :access_token => access_token) + when :customer + return Quickbooks::Service::Customer.new(:company_id => qbo.company_id, :access_token => access_token) + when :invoice + return Quickbooks::Service::Invoice.new(:company_id => qbo.company_id, :access_token => access_token) + when :estimate + return Quickbooks::Service::Estimate.new(:company_id => qbo.company_id, :access_token => access_token) + when :employee + return Quickbooks::Service::Employee.new(:company_id => qbo.company_id, :access_token => access_token) + else + return access_token + end end - end - - # Get the QBO account - def self.get_account - first end # Updates last sync time stamp diff --git a/db/migrate/037_update_qbo_token.rb b/db/migrate/037_update_qbo_token.rb new file mode 100644 index 0000000..71a3109 --- /dev/null +++ b/db/migrate/037_update_qbo_token.rb @@ -0,0 +1,18 @@ +#The MIT License (MIT) +# +#Copyright (c) 2023 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 UpdateQboToken < ActiveRecord::Migration[5.1] + def change + add_column :qbos, :oauth2_access_token, :text + add_column :qbos, :oauth2_access_token_expires_at, :datetime + add_column :qbos, :oauth2_refresh_token, :text + add_column :qbos, :oauth2_refresh_token_expires_at, :datetime + end +end From 84dfdd707a6b4e765971cfdff8c3ada77ca242ed Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 30 Dec 2023 12:46:52 -0500 Subject: [PATCH 26/40] fixed token names --- app/controllers/qbo_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/qbo_controller.rb b/app/controllers/qbo_controller.rb index f6c8be1..1ed482d 100644 --- a/app/controllers/qbo_controller.rb +++ b/app/controllers/qbo_controller.rb @@ -47,7 +47,7 @@ class QboController < ApplicationController # Save the authentication information qbo = Qbo.new - qbo.update(access_token: resp.token, refresh_token: resp.refresh_token, realm_id: params[:realmId]) + qbo.update(oauth2_access_token: resp.token, oauth2_refresh_token: resp.refresh_token, realm_id: params[:realmId]) if qbo.save! redirect_to qbo_sync_path, :flash => { :notice => "Successfully connected to Quickbooks" } From d6ec34cef9c87745a67ca6717513996c69d9c74b Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 30 Dec 2023 12:56:46 -0500 Subject: [PATCH 27/40] added realm_id --- db/migrate/037_update_qbo_token.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/db/migrate/037_update_qbo_token.rb b/db/migrate/037_update_qbo_token.rb index 71a3109..ba1dcce 100644 --- a/db/migrate/037_update_qbo_token.rb +++ b/db/migrate/037_update_qbo_token.rb @@ -14,5 +14,6 @@ class UpdateQboToken < ActiveRecord::Migration[5.1] add_column :qbos, :oauth2_access_token_expires_at, :datetime add_column :qbos, :oauth2_refresh_token, :text add_column :qbos, :oauth2_refresh_token_expires_at, :datetime + add_column :qbos, :realm_id, :text end end From 7a6b6882d273b0d878fe9b8a445591241db51f79 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 30 Dec 2023 18:53:01 -0500 Subject: [PATCH 28/40] Update get_base --- app/models/qbo.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/models/qbo.rb b/app/models/qbo.rb index 7cd9b97..7a3daf1 100644 --- a/app/models/qbo.rb +++ b/app/models/qbo.rb @@ -18,28 +18,27 @@ class Qbo < ActiveRecord::Base # @params type of base # def self.get_base(type) - # lets getnourbold access token from the database - oauth2_client = construct_oauth2_client qbo = self.first qbo.perform_authenticated_request do |access_token| # build the reqiested service case type when :time_activity - return Quickbooks::Service::TimeActivity.new(:company_id => qbo.company_id, :access_token => access_token) + base = Quickbooks::Service::TimeActivity.new(:company_id => qbo.company_id, :access_token => access_token) when :customer return Quickbooks::Service::Customer.new(:company_id => qbo.company_id, :access_token => access_token) when :invoice - return Quickbooks::Service::Invoice.new(:company_id => qbo.company_id, :access_token => access_token) + base = Quickbooks::Service::Invoice.new(:company_id => qbo.company_id, :access_token => access_token) when :estimate - return Quickbooks::Service::Estimate.new(:company_id => qbo.company_id, :access_token => access_token) + base = Quickbooks::Service::Estimate.new(:company_id => qbo.company_id, :access_token => access_token) when :employee - return Quickbooks::Service::Employee.new(:company_id => qbo.company_id, :access_token => access_token) + base = Quickbooks::Service::Employee.new(:company_id => qbo.company_id, :access_token => access_token) else - return access_token + base = access_token end end + return base end # Updates last sync time stamp From c3513427de2f13bc6ba1e0fce3c3fecf06842f5f Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 30 Dec 2023 19:13:08 -0500 Subject: [PATCH 29/40] Used realm_id not comany_id --- app/models/qbo.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/qbo.rb b/app/models/qbo.rb index 7a3daf1..8a665ff 100644 --- a/app/models/qbo.rb +++ b/app/models/qbo.rb @@ -24,15 +24,15 @@ class Qbo < ActiveRecord::Base # build the reqiested service case type when :time_activity - base = Quickbooks::Service::TimeActivity.new(:company_id => qbo.company_id, :access_token => access_token) + base = Quickbooks::Service::TimeActivity.new(:company_id => qbo.realm_id, :access_token => access_token) when :customer - return Quickbooks::Service::Customer.new(:company_id => qbo.company_id, :access_token => access_token) + return Quickbooks::Service::Customer.new(:company_id => qbo.realm_id, :access_token => access_token) when :invoice - base = Quickbooks::Service::Invoice.new(:company_id => qbo.company_id, :access_token => access_token) + base = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token) when :estimate - base = Quickbooks::Service::Estimate.new(:company_id => qbo.company_id, :access_token => access_token) + base = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token) when :employee - base = Quickbooks::Service::Employee.new(:company_id => qbo.company_id, :access_token => access_token) + base = Quickbooks::Service::Employee.new(:company_id => qbo.realm_id, :access_token => access_token) else base = access_token end From b13abe51bf7c536a468415ee525d0f9a38a8212e Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 30 Dec 2023 19:27:37 -0500 Subject: [PATCH 30/40] Display token expiration times --- app/views/qbo/_settings.html.erb | 6 ++++-- config/locales/en.yml | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/qbo/_settings.html.erb b/app/views/qbo/_settings.html.erb index 5a3a733..79c64fd 100644 --- a/app/views/qbo/_settings.html.erb +++ b/app/views/qbo/_settings.html.erb @@ -58,8 +58,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI - <%=t(:label_oauth_expires)%> - <%= if Qbo.exists? then Qbo.first.expire end %> + <%=t(:label_oauth_expires)%> + <%= if Qbo.exists? then Qbo.first.oauth2_access_token_expires_at end %> + <%=t(:label_oauth2_refresh_token_expires_at)%> + <%= if Qbo.exists? then Qbo.first.oauth2_refresh_token_expires_at end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 5543f76..8001ac6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -87,4 +87,5 @@ en: label_billing_error: "Cannot bill without a customer assigned" label_qbo_sync_success: "Successfully synced to Quickbooks" label_hours: "Hours" + label_oauth2_refresh_token_expires_at: "Refresh Token Expires At" \ No newline at end of file From 45056e8ff4153139ac3b2ec8aea5d874e9e54dc1 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 30 Dec 2023 19:28:04 -0500 Subject: [PATCH 31/40] Remove unsed columns --- db/migrate/037_update_qbo_token.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/migrate/037_update_qbo_token.rb b/db/migrate/037_update_qbo_token.rb index ba1dcce..b9bedc2 100644 --- a/db/migrate/037_update_qbo_token.rb +++ b/db/migrate/037_update_qbo_token.rb @@ -15,5 +15,8 @@ class UpdateQboToken < ActiveRecord::Migration[5.1] add_column :qbos, :oauth2_refresh_token, :text add_column :qbos, :oauth2_refresh_token_expires_at, :datetime add_column :qbos, :realm_id, :text + remove_column :qbos, :company_id + remove_column :qbos, :token + remove_column :qbos, :expire end end From 3e352f270d0e4bcade674177b59e2f440aa01655 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 30 Dec 2023 19:41:02 -0500 Subject: [PATCH 32/40] Added Item --- app/models/qbo.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/qbo.rb b/app/models/qbo.rb index 8a665ff..9d68f62 100644 --- a/app/models/qbo.rb +++ b/app/models/qbo.rb @@ -33,6 +33,8 @@ class Qbo < ActiveRecord::Base base = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token) when :employee base = Quickbooks::Service::Employee.new(:company_id => qbo.realm_id, :access_token => access_token) + when :item + base = Quickbooks::Service::Item.new(:company_id => qbo.realm_id, :access_token => access_token) else base = access_token end From 2e32d8f6e5f69208d13375a01a495b886dbc2027 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 30 Dec 2023 19:55:01 -0500 Subject: [PATCH 33/40] Fixed get_base --- app/models/qbo.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/models/qbo.rb b/app/models/qbo.rb index 9d68f62..66c9984 100644 --- a/app/models/qbo.rb +++ b/app/models/qbo.rb @@ -24,23 +24,21 @@ class Qbo < ActiveRecord::Base # build the reqiested service case type when :time_activity - base = Quickbooks::Service::TimeActivity.new(:company_id => qbo.realm_id, :access_token => access_token) + return Quickbooks::Service::TimeActivity.new(:company_id => qbo.realm_id, :access_token => access_token) when :customer return Quickbooks::Service::Customer.new(:company_id => qbo.realm_id, :access_token => access_token) when :invoice - base = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token) + return Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token) when :estimate - base = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token) + return Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token) when :employee - base = Quickbooks::Service::Employee.new(:company_id => qbo.realm_id, :access_token => access_token) + return Quickbooks::Service::Employee.new(:company_id => qbo.realm_id, :access_token => access_token) when :item - base = Quickbooks::Service::Item.new(:company_id => qbo.realm_id, :access_token => access_token) + return Quickbooks::Service::Item.new(:company_id => qbo.realm_id, :access_token => access_token) else - base = access_token + return nil end end - - return base end # Updates last sync time stamp From f094ef57ec7b1758d18444701dee64a2d3ac88c7 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 30 Dec 2023 20:08:36 -0500 Subject: [PATCH 34/40] Setter for notes --- app/models/customer.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/customer.rb b/app/models/customer.rb index 6ace67b..1314de8 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -87,6 +87,13 @@ class Customer < ActiveRecord::Base #update our locally stored number too update_mobile_phone_number end + + # Convenience Method + # Sets the notes + def notes=(s) + pull unless @details + @details.notes = s + end # update the localy stored phone number as a plain string with no special chars def update_phone_number From 81f322b616a4ef741ebc45b3099f3ca904948f7f Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 30 Dec 2023 20:26:30 -0500 Subject: [PATCH 35/40] Call refresh_token to set token time stamps --- Gemfile | 1 + app/controllers/qbo_controller.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/Gemfile b/Gemfile index baf0247..d6c7ed4 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,7 @@ gem 'nhtsa_vin' gem 'will_paginate' gem 'rails-jquery-autocomplete' gem 'jquery-ui-rails' +gem 'listen', '~> 3.3' group :assets do gem 'coffee-rails' diff --git a/app/controllers/qbo_controller.rb b/app/controllers/qbo_controller.rb index 1ed482d..b3446b7 100644 --- a/app/controllers/qbo_controller.rb +++ b/app/controllers/qbo_controller.rb @@ -48,6 +48,7 @@ class QboController < ApplicationController # Save the authentication information qbo = Qbo.new qbo.update(oauth2_access_token: resp.token, oauth2_refresh_token: resp.refresh_token, realm_id: params[:realmId]) + qbo.refresh_token! if qbo.save! redirect_to qbo_sync_path, :flash => { :notice => "Successfully connected to Quickbooks" } From f4e44a1975dc04b6efb54de7378ed9eb0c4a34ee Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 30 Dec 2023 20:29:20 -0500 Subject: [PATCH 36/40] Remove listen (was used for development env) --- Gemfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Gemfile b/Gemfile index d6c7ed4..baf0247 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,6 @@ gem 'nhtsa_vin' gem 'will_paginate' gem 'rails-jquery-autocomplete' gem 'jquery-ui-rails' -gem 'listen', '~> 3.3' group :assets do gem 'coffee-rails' From 275af9be82403885116b6985bee3897c9ad95826 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 30 Dec 2023 20:53:39 -0500 Subject: [PATCH 37/40] Fixed formatting --- app/views/qbo/_settings.html.erb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/qbo/_settings.html.erb b/app/views/qbo/_settings.html.erb index 79c64fd..753143a 100644 --- a/app/views/qbo/_settings.html.erb +++ b/app/views/qbo/_settings.html.erb @@ -60,6 +60,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI <%=t(:label_oauth_expires)%> <%= if Qbo.exists? then Qbo.first.oauth2_access_token_expires_at end %> + + + <%=t(:label_oauth2_refresh_token_expires_at)%> <%= if Qbo.exists? then Qbo.first.oauth2_refresh_token_expires_at end %> From 6d0abf865e10133f8a73ccb51554985de236255d Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 30 Dec 2023 20:54:40 -0500 Subject: [PATCH 38/40] 2023 --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 5ecf62e..ce662ac 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 - 2022 Rick Barrette +Copyright (c) 2016 - 2023 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 From b35974e455725445647b3e14d8e1c53011480e09 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 30 Dec 2023 20:55:58 -0500 Subject: [PATCH 39/40] 2.0.1 --- init.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.rb b/init.rb index 14be242..5430d9b 100644 --- a/init.rb +++ b/init.rb @@ -22,7 +22,7 @@ Redmine::Plugin.register :redmine_qbo do 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 '2.0.0' + version '2.0.1' url 'https://github.com/rickbarrette/redmine_qbo' author_url 'https://barrettefabrication.com' settings :default => {'empty' => true}, :partial => 'qbo/settings' From 04391f1c6e34d1eac7cd6514ca2a67ad8ff94851 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 30 Dec 2023 23:07:17 -0500 Subject: [PATCH 40/40] 2.0.2 --- init.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.rb b/init.rb index 5430d9b..dddcbb0 100644 --- a/init.rb +++ b/init.rb @@ -22,7 +22,7 @@ Redmine::Plugin.register :redmine_qbo do 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 '2.0.1' + version '2.0.2' url 'https://github.com/rickbarrette/redmine_qbo' author_url 'https://barrettefabrication.com' settings :default => {'empty' => true}, :partial => 'qbo/settings'