80 Commits

Author SHA1 Message Date
a5de879260 Fixed formatting 2024-08-26 08:41:56 -04:00
6464e1cbc6 Added actions 2024-08-26 07:58:40 -04:00
7f3a94229a Create Estimate 2024-08-26 07:58:05 -04:00
395e0117fb Update _actions.html.erb 2024-08-26 07:57:10 -04:00
e04d363e42 Added label for actions 2024-08-26 07:56:06 -04:00
3b6c0d4a70 Removed Action links 2024-08-26 07:52:27 -04:00
d1f6ccd9cb Create _actions.html.erb 2024-08-26 07:51:38 -04:00
74f7ba41df Add Appointment Link 2024-08-21 21:39:50 -04:00
4fb424faa8 Only sync by doc number if not in database 2024-08-20 07:14:37 -04:00
63218e7f42 Fixed formating 2024-08-19 23:28:54 -04:00
7f0bb3cae7 Removed extra end 2024-08-19 23:26:43 -04:00
ad7417c233 Moved work into thread to repsond quickly 2024-08-19 23:21:56 -04:00
cf0be2336b Removed sync button from sidebar 2024-08-19 23:12:20 -04:00
6e08746611 2.1.1 Force Estimate sync by Doc Number when searching 2024-08-19 22:51:53 -04:00
7eb26facaf Use the first result 2024-08-19 22:49:20 -04:00
9115cc662c Forgot params[:search] 2024-08-19 22:39:50 -04:00
9e7c1dbfb2 removed () 2024-08-19 22:38:16 -04:00
e99f5d2e52 Added webhook view 2024-08-19 22:36:44 -04:00
039d1ca993 Use Logger.info 2024-08-19 22:31:41 -04:00
dd9ac3c481 Added Estimate.sync_by_doc_number 2024-08-19 22:30:34 -04:00
4f789080e7 2.1.0 Bumped wrong versoin 2024-08-19 20:18:22 -04:00
80fc858a35 send back status 200 if request succeeded 2024-08-19 20:14:02 -04:00
6f8d280657 5.2.0 FIXED QBO Authentication 2024-08-19 20:06:13 -04:00
5782cbc166 Added https 2024-08-19 20:04:09 -04:00
0729d2ac41 added https to redirect_uri 2024-08-19 20:02:22 -04:00
6c6de0ba86 Added log 2024-08-19 19:59:26 -04:00
11dbcaf80c Use Setting.host_name & path 2024-08-19 19:53:51 -04:00
95592e542f Use qbo_oauth_callback_path 2024-08-19 19:30:51 -04:00
472bdec4fa Use qbo_authenticate_path 2024-08-19 19:17:45 -04:00
c7a313e9ed Add customer name to details 2024-04-03 11:47:38 -04:00
c14b590083 2024 Copy Right Update 2024-03-29 08:10:05 -04:00
040c920481 2.0.5 2024-03-29 07:58:26 -04:00
8c63817950 Use free_form_number 2024-03-28 14:13:39 -04:00
e2f43d398f Nil Checks 2024-03-28 14:01:18 -04:00
7ba4829066 Update Customer Phone Numbers On Sync 2024-03-28 13:51:29 -04:00
938999db91 Added quickbooks to customer's name 2024-03-28 12:54:36 -04:00
0b60a8e41b 2.0.4 2024-01-07 20:53:07 -05:00
817a43e849 Fixed update 2024-01-07 20:47:26 -05:00
047296329e 2.0.32.0.3 2023-12-31 16:42:47 -05:00
c8cb74f3d4 Merge branch 'redmine-5' 2023-12-31 16:35:26 -05:00
aceb6cb6b5 fixed typo 2023-12-31 16:26:02 -05:00
9fd1bc9dff Merge branch 'redmine-5' 2023-12-30 23:35:25 -05:00
04391f1c6e 2.0.2 2023-12-30 23:07:17 -05:00
e2bf42e66b Fixed invoice pdf 2023-12-30 23:04:43 -05:00
0c72ca9294 missed this authenticated_request 2023-12-30 23:01:32 -05:00
2985fad77c Fixed typo 2023-12-30 23:01:01 -05:00
02b5fb4d0e Fixed returned variable handling 2023-12-30 22:53:08 -05:00
bf417c163c Rework performing authenticated requests 2023-12-30 22:33:28 -05:00
b35974e455 2.0.1 2023-12-30 20:55:58 -05:00
6d0abf865e 2023 2023-12-30 20:54:40 -05:00
275af9be82 Fixed formatting 2023-12-30 20:53:39 -05:00
f4e44a1975 Remove listen (was used for development env) 2023-12-30 20:29:20 -05:00
81f322b616 Call refresh_token to set token time stamps 2023-12-30 20:26:30 -05:00
f094ef57ec Setter for notes 2023-12-30 20:08:36 -05:00
2e32d8f6e5 Fixed get_base 2023-12-30 19:55:01 -05:00
3e352f270d Added Item 2023-12-30 19:41:02 -05:00
45056e8ff4 Remove unsed columns 2023-12-30 19:28:04 -05:00
b13abe51bf Display token expiration times 2023-12-30 19:27:37 -05:00
c3513427de Used realm_id not comany_id 2023-12-30 19:13:08 -05:00
7a6b6882d2 Update get_base 2023-12-30 18:53:01 -05:00
d6ec34cef9 added realm_id 2023-12-30 12:56:46 -05:00
84dfdd707a fixed token names 2023-12-30 12:46:52 -05:00
517a239485 Started reworking Oauth token sorage 2023-12-30 12:39:51 -05:00
47868051f8 Rails 6.1 Deprecates update_attributes 2023-12-29 20:25:26 -05:00
96e4e9df66 Fixed typo with params 2023-12-29 20:17:46 -05:00
7d510e4028 Added notes to allowed params 2023-12-29 20:06:15 -05:00
6760b29148 Log the time stamp 2023-12-29 19:20:31 -05:00
122063b1d5 Fixed customer typo 2023-12-29 19:14:38 -05:00
b304c3a175 Fixed employee typo 2023-12-29 19:09:24 -05:00
5b89d73c20 Remove QboItem.sync 2023-12-29 18:56:20 -05:00
8380dda25a render 403 when forbidden 2023-12-29 17:06:00 -05:00
7839116134 Version 2.0.0 2023-12-27 16:31:11 -05:00
b3a809ab1c Redmine 5.1 Update 2023-12-27 15:03:08 -05:00
3a0e58c3da Append last 4 of phone number to customers name 2023-05-22 07:34:18 -04:00
26433c9020 Added hour totals to customer job history 2023-01-14 06:38:48 -05:00
6dbf84f401 Added nil check to address_to_s 2022-05-04 12:37:31 -04:00
3220ff728f Fixed process_estimate that I accidently broke 2022-04-06 12:45:40 -04:00
d8d1942673 Version 1.1.6 2022-03-19 05:47:07 -04:00
8e329b2dd2 Fix broken invoice processing 2022-03-19 05:29:59 -04:00
3622f8cad7 Added space 2022-03-19 05:16:26 -04:00
28 changed files with 480 additions and 303 deletions

View File

@@ -1,7 +1,7 @@
source 'https://rubygems.org' source 'https://rubygems.org'
gem 'quickbooks-ruby' gem 'quickbooks-ruby'
gem 'oauth2', '1.4.7' gem 'oauth2'
gem 'roxml' gem 'roxml'
gem 'nhtsa_vin' gem 'nhtsa_vin'
gem 'will_paginate' gem 'will_paginate'

View File

@@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 - 2022 Rick Barrette Copyright (c) 2016 - 2024 Rick Barrette
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@@ -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 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 #### Features
* Issues can be assigned to a Customer via drop down in the edit Issue form * Issues can be assigned to a Customer via drop down in the edit Issue form

View File

@@ -36,7 +36,7 @@ class CustomersController < ApplicationController
autocomplete :customer, :name, :full => true, :extra_data => [:id] autocomplete :customer, :name, :full => true, :extra_data => [:id]
def allowed_params 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 end
# getter method for a customer's vehicles # getter method for a customer's vehicles
@@ -93,6 +93,10 @@ class CustomersController < ApplicationController
@billing_address = address_to_s(@customer.billing_address) @billing_address = address_to_s(@customer.billing_address)
@shipping_address = address_to_s(@customer.shipping_address) @shipping_address = address_to_s(@customer.shipping_address)
@closed_issues = (@issues - @issues.open) @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 rescue
render_404 render_404
end end
@@ -111,7 +115,7 @@ class CustomersController < ApplicationController
def update def update
begin begin
@customer = Customer.find_by_id(params[:id]) @customer = Customer.find_by_id(params[:id])
if @customer.update_attributes(allowed_params) if @customer.update(allowed_params)
flash[:notice] = "Customer updated" flash[:notice] = "Customer updated"
redirect_to @customer redirect_to @customer
else else
@@ -138,7 +142,7 @@ class CustomersController < ApplicationController
def share def share
Thread.new do Thread.new do
logger.debug "Removing expired customer tokens" logger.info "Removing expired customer tokens"
CustomerToken.remove_expired_tokens CustomerToken.remove_expired_tokens
ActiveRecord::Base.connection.close ActiveRecord::Base.connection.close
end end
@@ -214,14 +218,14 @@ class CustomersController < ApplicationController
# format a quickbooks address to a human readable string # format a quickbooks address to a human readable string
def address_to_s (address) def address_to_s (address)
return if address.nil? return if address.nil?
string = address.line1 string = address.line1 if address.line1
string << "\n" + address.line2 if address.line2 string << "\n" + address.line2 if address.line2
string << "\n" + address.line3 if address.line3 string << "\n" + address.line3 if address.line3
string << "\n" + address.line4 if address.line4 string << "\n" + address.line4 if address.line4
string << "\n" + address.line5 if address.line5 string << "\n" + address.line5 if address.line5
string << " " + address.city string << " " + address.city if address.city
string << ", " + address.country_sub_division_code string << ", " + address.country_sub_division_code if address.country_sub_division_code
string << " " + address.postal_code string << " " + address.postal_code if address.postal_code
return string return string
end end

View File

@@ -16,6 +16,15 @@ class EstimateController < ApplicationController
skip_before_action :verify_authenticity_token, :check_if_login_required, :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 def get_estimate
# Force sync for estimate by doc number if not found
if Estimate.find_by_doc_number(params[:search]).nil?
begin
Estimate.sync_by_doc_number(params[:search]) if params[:search]
rescue
logger.info "Estimate.find_by_doc_number failed"
end
end
estimate = Estimate.find_by_id(params[:id]) if params[:id] estimate = Estimate.find_by_id(params[:id]) if params[:id]
estimate = Estimate.find_by_doc_number(params[:search]) if params[:search] estimate = Estimate.find_by_doc_number(params[:search]) if params[:search]
return estimate return estimate

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #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: #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:
# #
@@ -20,10 +20,13 @@ class InvoiceController < ApplicationController
# #
def show def show
begin begin
base = Invoice.get_base qbo = Qbo.first
invoice = base.fetch_by_id(params[:id]) qbo.perform_authenticated_request do |access_token|
@pdf = base.pdf(invoice) service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token)
send_data @pdf, filename: "invoice #{invoice.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf" invoice = service.fetch_by_id(params[:id])
@pdf = service.pdf(invoice)
send_data @pdf, filename: "invoice #{invoice.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf"
end
rescue rescue
redirect_to :back, :flash => { :error => "Invoice not found" } redirect_to :back, :flash => { :error => "Invoice not found" }
end end

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #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: #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,9 +26,10 @@ class QboController < ApplicationController
# Called when the user requests that Redmine to connect to QBO # Called when the user requests that Redmine to connect to QBO
# #
def authenticate def authenticate
oauth2_client = Qbo.get_client redirect_uri = "https://" + Setting.host_name + qbo_oauth_callback_path
callback = Setting.host_name + "/qbo/oauth_callback/" logger.info "redirect_uri: " + redirect_uri
grant_url = oauth2_client.auth_code.authorize_url(redirect_uri: callback, response_type: "code", state: SecureRandom.hex(12), scope: "com.intuit.quickbooks.accounting") oauth2_client = Qbo.construct_oauth2_client
grant_url = oauth2_client.auth_code.authorize_url(redirect_uri: redirect_uri, response_type: "code", state: SecureRandom.hex(12), scope: "com.intuit.quickbooks.accounting")
redirect_to grant_url redirect_to grant_url
end end
@@ -37,9 +38,9 @@ class QboController < ApplicationController
# #
def oauth_callback def oauth_callback
if params[:state].present? 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 # 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/" redirect_uri = "https://" + Setting.host_name + qbo_oauth_callback_path
if resp = oauth2_client.auth_code.get_token(params[:code], redirect_uri: redirect_uri) if resp = oauth2_client.auth_code.get_token(params[:code], redirect_uri: redirect_uri)
# Remove the last authentication information # Remove the last authentication information
@@ -47,12 +48,8 @@ class QboController < ApplicationController
# Save the authentication information # Save the authentication information
qbo = Qbo.new qbo = Qbo.new
qbo.company_id = params[:realmId] qbo.update(oauth2_access_token: resp.token, oauth2_refresh_token: resp.refresh_token, realm_id: params[:realmId])
qbo.refresh_token!
# 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
if qbo.save! if qbo.save!
redirect_to qbo_sync_path, :flash => { :notice => "Successfully connected to Quickbooks" } redirect_to qbo_sync_path, :flash => { :notice => "Successfully connected to Quickbooks" }
@@ -88,46 +85,48 @@ class QboController < ApplicationController
# proceed if the request is good # proceed if the request is good
if hash.eql? signature if hash.eql? signature
if request.headers['content-type'] == 'application/json' Thread.new do
data = JSON.parse(data) if request.headers['content-type'] == 'application/json'
else data = JSON.parse(data)
# application/x-www-form-urlencoded
data = params.as_json
end
# Process the information
entities = data['eventNotifications'][0]['dataChangeEvent']['entities']
entities.each do |entity|
id = entity['id'].to_i
name = entity['name']
logger.debug "Casting #{name.constantize} to obj"
# Magicly initialize the correct class
obj = name.constantize
# for merge events
obj.destroy(entity['deletedId']) if entity['deletedId']
#Check to see if we are deleting a record
if entity['operation'].eql? "Delete"
obj.destroy(id)
#if not then update!
else else
begin # application/x-www-form-urlencoded
obj.sync_by_id(id) data = params.as_json
rescue => e end
logger.error "Failed to call sync_by_id on obj" # Process the information
logger.error e.message entities = data['eventNotifications'][0]['dataChangeEvent']['entities']
logger.error e.backtrace.join("\n") entities.each do |entity|
id = entity['id'].to_i
name = entity['name']
logger.info "Casting #{name.constantize} to obj"
# Magicly initialize the correct class
obj = name.constantize
# for merge events
obj.destroy(entity['deletedId']) if entity['deletedId']
#Check to see if we are deleting a record
if entity['operation'].eql? "Delete"
obj.destroy(id)
#if not then update!
else
begin
obj.sync_by_id(id)
rescue => e
logger.error "Failed to call sync_by_id on obj"
logger.error e.message
logger.error e.backtrace.join("\n")
end
end end
end end
# Record that last time we updated
Qbo.update_time_stamp
ActiveRecord::Base.connection.close
end end
# Record that last time we updated
Qbo.update_time_stamp
# The webhook doesn't require a response but let's make sure we don't send anything # The webhook doesn't require a response but let's make sure we don't send anything
render :nothing => true render :nothing => true, status: 200
else else
render nothing: true, status: 400 render nothing: true, status: 400
end end
@@ -145,7 +144,6 @@ class QboController < ApplicationController
if Qbo.exists? if Qbo.exists?
Customer.sync Customer.sync
Invoice.sync Invoice.sync
QboItem.sync
Employee.sync Employee.sync
Estimate.sync Estimate.sync
@@ -155,6 +153,6 @@ class QboController < ApplicationController
ActiveRecord::Base.connection.close ActiveRecord::Base.connection.close
end end
redirect_to :home, :flash => { :notice => "Successfully synced to Quickbooks" } redirect_to :home, :flash => { :notice => "Syncing Quickbooks" }
end end
end end

View File

@@ -84,7 +84,7 @@ class VehiclesController < ApplicationController
@customer = params[:customer] @customer = params[:customer]
begin begin
@vehicle = Vehicle.find_by_id(params[:id]) @vehicle = Vehicle.find_by_id(params[:id])
if @vehicle.update_attributes(allowed_params) if @vehicle.update(allowed_params)
flash[:notice] = "Vehicle updated" flash[:notice] = "Vehicle updated"
redirect_to @vehicle redirect_to @vehicle
else else

View File

@@ -13,7 +13,7 @@ module AuthHelper
def require_user def require_user
return unless session[:token].nil? return unless session[:token].nil?
if !User.current.logged? if !User.current.logged?
render :file => "public/401.html.erb", :status => :unauthorized, :layout =>true render_403
end end
end end
@@ -27,14 +27,14 @@ module AuthHelper
def check_permission(permission) def check_permission(permission)
if !allowed_to?(permission) if !allowed_to?(permission)
render :file => "public/401.html.erb", :status => :unauthorized, :layout =>true render_403
end end
end end
def global_check_permission(permission) def global_check_permission(permission)
if !globaly_allowed_to?(permission) if !globaly_allowed_to?(permission)
render :file => "public/401.html.erb", :status => :unauthorized, :layout =>true render_403
end end
end end

View File

@@ -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

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #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: #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:
# #
@@ -23,7 +23,7 @@ class Customer < ActiveRecord::Base
# returns a human readable string # returns a human readable string
def to_s def to_s
return name return "#{self[:name]} - #{phone_number.split(//).last(4).join unless phone_number.nil?}"
end end
# Convenience Method # Convenience Method
@@ -87,6 +87,13 @@ class Customer < ActiveRecord::Base
#update our locally stored number too #update our locally stored number too
update_mobile_phone_number update_mobile_phone_number
end 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 # update the localy stored phone number as a plain string with no special chars
def update_phone_number def update_phone_number
@@ -135,28 +142,28 @@ class Customer < ActiveRecord::Base
# proforms a bruteforce sync operation # proforms a bruteforce sync operation
# This needs to be simplified # This needs to be simplified
def self.sync def self.sync
service = Qbo.get_base(:customer)
# Sync ALL customers if the database is empty # Sync ALL customers if the database is empty
#if count == 0 qbo = Qbo.first
customers = service.all customers = qbo.perform_authenticated_request do |access_token|
#else service = Quickbooks::Service::Customer.new(:company_id => qbo.realm_id, :access_token => access_token)
# last = Qbo.first.last_sync service.all
# query = "Select Id, DisplayName From Customer" end
# query << " Where Metadata.LastUpdatedTime >= '#{last.iso8601}' " if last
# customers = service.query(query)
#end
customers.each do |customer| return unless customers
customer = Customer.find_or_create_by(id: customer.id)
if customer.active? customers.each do |c|
if not customer.name.eql? customer.display_name logger.info "Processing customer #{c.id}"
customer.name = customer.display_name customer = Customer.find_or_create_by(id: c.id)
customer.id = customer.id if c.active?
#if not customer.name.eql? c.display_name
customer.name = c.display_name
customer.id = c.id
customer.phone_number = c.primary_phone.free_form_number.tr('^0-9', '') unless c.primary_phone.nil?
customer.mobile_phone_number = c.mobile_phone.free_form_number.tr('^0-9', '') unless c.mobile_phone.nil?
customer.save_without_push customer.save_without_push
end #end
else else
if not customer.new_record? if not c.new_record?
customer.delete customer.delete
end end
end end
@@ -172,16 +179,23 @@ class Customer < ActiveRecord::Base
# proforms a bruteforce sync operation # proforms a bruteforce sync operation
# This needs to be simplified # This needs to be simplified
def self.sync_by_id(id) def self.sync_by_id(id)
service = Qbo.get_base(:customer) qbo = Qbo.first
c = qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Customer.new(:company_id => qbo.realm_id, :access_token => access_token)
service.fetch_by_id(id)
end
customer = service.fetch_by_id(id) return unless c
customer = Customer.find_or_create_by(id: customer.id)
if customer.active? customer = Customer.find_or_create_by(id: c.id)
if not customer.name.eql? customer.display_name if c.active?
customer.name = customer.display_name #if not customer.name.eql? c.display_name
customer.id = customer.id customer.name = c.display_name
customer.id = c.id
customer.phone_number = c.primary_phone.free_form_number.tr('^0-9', '') unless c.primary_phone.nil?
customer.mobile_phone_number = c.mobile_phone.free_form_number.tr('^0-9', '') unless c.mobile_phone.nil?
customer.save_without_push customer.save_without_push
end #end
else else
if not customer.new_record? if not customer.new_record?
customer.delete customer.delete
@@ -192,7 +206,11 @@ class Customer < ActiveRecord::Base
# Push the updates # Push the updates
def save_with_push def save_with_push
begin begin
@details = Qbo.get_base(:customer).update(@details) qbo = Qbo.first
@details = qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Customer.new(:company_id => qbo.realm_id, :access_token => access_token)
service.update(@details)
end
#raise "QBO Fault" if @details.fault? #raise "QBO Fault" if @details.fault?
self.id = @details.id self.id = @details.id
rescue Exception => e rescue Exception => e
@@ -210,7 +228,11 @@ class Customer < ActiveRecord::Base
def pull def pull
begin begin
raise Exception unless self.id raise Exception unless self.id
@details = Qbo.get_base(:customer).fetch_by_id(self.id) qbo = Qbo.first
@details = qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Customer.new(:company_id => qbo.realm_id, :access_token => access_token)
service.fetch_by_id(self.id)
end
rescue Exception => e rescue Exception => e
@details = Quickbooks::Model::Customer.new @details = Quickbooks::Model::Customer.new
end end

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #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: #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:
# #
@@ -13,26 +13,35 @@ class Employee < ActiveRecord::Base
has_many :users has_many :users
validates_presence_of :id, :name validates_presence_of :id, :name
def self.get_base
Qbo.get_base(:employee)
end
def self.sync def self.sync
employees = get_base.all qbo = Qbo.first
employees = qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Employee.new(:company_id => qbo.realm_id, :access_token => access_token)
service.all
end
return unless employees
transaction do transaction do
# Update the item table # Update the item table
employees.each { |employee| employees.each { |e|
employee = find_or_create_by(id: employee.id) logger.info "Processing employee #{e.id}"
employee.name = employee.display_name employee = find_or_create_by(id: e.id)
employee.id = employee.id employee.name = e.display_name
employee.id = e.id
employee.save! employee.save!
} }
end end
end end
def self.sync_by_id(id) def self.sync_by_id(id)
employee = get_base.fetch_by_id(id) qbo = Qbo.first
employee = qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Employee.new(:company_id => qbo.realm_id, :access_token => access_token)
service.fetch_by_id(id)
end
return unless employee
employee = find_or_create_by(id: employee.id) employee = find_or_create_by(id: employee.id)
employee.name = employee.display_name employee.name = employee.display_name
employee.id = employee.id employee.id = employee.id

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #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: #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:
# #
@@ -16,15 +16,17 @@ class Estimate < ActiveRecord::Base
validates_presence_of :doc_number, :id validates_presence_of :doc_number, :id
self.primary_key = :id self.primary_key = :id
# return the QBO Estimate service
def self.get_base
Qbo.get_base(:estimate)
end
# sync all estimates # sync all estimates
def self.sync def self.sync
logger.debug "Syncing ALL estimates" logger.info "Syncing ALL estimates"
estimates = get_base.all qbo = Qbo.first
estimates = qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token)
service.all
end
return unless estimates
estimates.each { |estimate| estimates.each { |estimate|
process_estimate(estimate) process_estimate(estimate)
} }
@@ -35,36 +37,60 @@ class Estimate < ActiveRecord::Base
# sync only one estimate # sync only one estimate
def self.sync_by_id(id) def self.sync_by_id(id)
logger.debug "Syncing estimate #{id}" logger.info "Syncing estimate #{id}"
process_estimate(get_base.fetch_by_id(id)) qbo = Qbo.first
qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token)
process_estimate(service.fetch_by_id(id))
end
end
# sync only one estimate
def self.sync_by_doc_number(number)
logger.info "Syncing estimate by doc number #{number}"
qbo = Qbo.first
qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token)
process_estimate(service.find_by( :doc_number, number).first)
end
end end
# update an estimate # update an estimate
def self.update(id) def self.update(id)
# Update the item table # Update the item table
estimate = get_base.fetch_by_id(id) qbo = Qbo.first
estimate = find_or_create_by(id: id) estimate = qbo.perform_authenticated_request do |access_token|
estimate.doc_number = estimate.doc_number service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token)
estimate.txn_date = estimate.txn_date service.fetch_by_id(id)
estimate.save! end
return unless estimate
e = find_or_create_by(id: id)
e.doc_number = estimate.doc_number
e.txn_date = estimate.txn_date
e.save!
end end
# process an estimate into the database # process an estimate into the database
def self.process_estimate(estimate) def self.process_estimate(qbo_estimate)
logger.info "Processing estimate #{estimate.id}" logger.info "Processing estimate #{qbo_estimate.id}"
estimate = find_or_create_by(id: estimate.id) estimate = find_or_create_by(id: qbo_estimate.id)
estimate.doc_number = estimate.doc_number estimate.doc_number = qbo_estimate.doc_number
estimate.customer_id = estimate.customer_ref.value estimate.customer_id = qbo_estimate.customer_ref.value
estimate.id = estimate.id estimate.id = qbo_estimate.id
estimate.txn_date = estimate.txn_date estimate.txn_date = qbo_estimate.txn_date
estimate.save! estimate.save!
end end
# download the pdf from quickbooks # download the pdf from quickbooks
def pdf def pdf
base = Estimate.get_base qbo = Qbo.first
estimate = base.fetch_by_id(id) qbo.perform_authenticated_request do |access_token|
return base.pdf(estimate) service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token)
estimate = service.fetch_by_id(id)
service.pdf(estimate)
end
end end
# Magic Method # Magic Method
@@ -91,7 +117,11 @@ class Estimate < ActiveRecord::Base
def pull def pull
begin begin
raise Exception unless self.id raise Exception unless self.id
@details = Qbo.get_base(:estimate).fetch_by_id(self.id) qbo = Qbo.first
@details = qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token)
service(:estimate).fetch_by_id(self.id)
end
rescue Exception => e rescue Exception => e
@details = Quickbooks::Model::Estimate.new @details = Quickbooks::Model::Estimate.new
end end

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #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: #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:
# #
@@ -15,14 +15,9 @@ class Invoice < ActiveRecord::Base
validates_presence_of :doc_number, :id, :customer_id, :txn_date validates_presence_of :doc_number, :id, :customer_id, :txn_date
self.primary_key = :id self.primary_key = :id
# Get the quickbooks-ruby base for invoice
def self.get_base
Qbo.get_base(:invoice)
end
# sync ALL the invoices # sync ALL the invoices
def self.sync def self.sync
logger.debug "Syncing all invoices" logger.info "Syncing all invoices"
last = Qbo.first.last_sync last = Qbo.first.last_sync
query = "SELECT Id, DocNumber FROM Invoice" query = "SELECT Id, DocNumber FROM Invoice"
@@ -30,11 +25,13 @@ class Invoice < ActiveRecord::Base
# TODO actually do something with the above query # TODO actually do something with the above query
# .all() is never called since count is never initialized # .all() is never called since count is never initialized
if count == 0 qbo = Qbo.first
invoices = get_base.all invoices = qbo.perform_authenticated_request do |access_token|
else service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token)
invoices = get_base.query() service.all
end end
return unless invoices
invoices.each { | invoice | invoices.each { | invoice |
process_invoice invoice process_invoice invoice
@@ -43,9 +40,13 @@ class Invoice < ActiveRecord::Base
#sync by invoice ID #sync by invoice ID
def self.sync_by_id(id) def self.sync_by_id(id)
logger.debug "Syncing invoice #{id}" logger.info "Syncing invoice #{id}"
invoice = get_base.fetch_by_id(id) qbo = Qbo.first
process_invoice invoice qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token)
invoice = service.fetch_by_id(id)
process_invoice invoice
end
end end
private private
@@ -57,7 +58,7 @@ class Invoice < ActiveRecord::Base
# skip this issue if the issue customer is not the same as the invoice customer # skip this issue if the issue customer is not the same as the invoice customer
return if issue.customer_id != invoice.customer_ref.value.to_i return if issue.customer_id != invoice.customer_ref.value.to_i
logger.debug "Attaching invoice #{invoice.id} to issue #{issue.id}" logger.info "Attaching invoice #{invoice.id} to issue #{issue.id}"
invoice = Invoice.find_or_create_by(id: invoice.id) invoice = Invoice.find_or_create_by(id: invoice.id)
@@ -70,26 +71,26 @@ class Invoice < ActiveRecord::Base
end end
# processes the invoice into the database # processes the invoice into the database
def self.process_invoice(invoice) def self.process_invoice(i)
logger.info "Processing invoice #{invoice.id}" logger.info "Processing invoice #{i.id}"
# Load the invoice into the database # Load the invoice into the database
invoice = Invoice.find_or_create_by(id: invoice.id) invoice = Invoice.find_or_create_by(id: i.id)
invoice.doc_number = invoice.doc_number invoice.doc_number = i.doc_number
invoice.id = invoice.id invoice.id = i.id
invoice.customer_id = invoice.customer_ref invoice.customer_id = i.customer_ref
invoice.txn_date = invoice.txn_date invoice.txn_date = i.txn_date
invoice.save! invoice.save!
# Scan the private notes for hashtags and attach to the applicable issues # Scan the private notes for hashtags and attach to the applicable issues
if not invoice.private_note.nil? if not i.private_note.nil?
invoice.private_note.scan(/#(\w+)/).flatten.each { |issue| i.private_note.scan(/#(\w+)/).flatten.each { |issue|
attach_to_issue(Issue.find_by_id(issue.to_i), invoice) attach_to_issue(Issue.find_by_id(issue.to_i), invoice)
} }
end end
# Scan the line items for hashtags and attach to the applicable issues # 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 if line.description
line.description.scan(/#(\w+)/).flatten.each { |issue| line.description.scan(/#(\w+)/).flatten.each { |issue|
attach_to_issue(Issue.find_by_id(issue.to_i), invoice) attach_to_issue(Issue.find_by_id(issue.to_i), invoice)
@@ -104,7 +105,7 @@ class Invoice < ActiveRecord::Base
# this condions causes an infinite loop as the webhook is called when an invoice is updated # this condions causes an infinite loop as the webhook is called when an invoice is updated
# TODO maybe add a cf_sync_confict flag to invoices # TODO maybe add a cf_sync_confict flag to invoices
def self.compare_custom_fields(issue, invoice) def self.compare_custom_fields(issue, invoice)
logger.debug "Comparing custom fields" logger.info "Comparing custom fields"
# TODO break if Invoice.find(invoice.id).cf_sync_confict # TODO break if Invoice.find(invoice.id).cf_sync_confict
is_changed = false is_changed = false
@@ -119,12 +120,12 @@ class Invoice < ActiveRecord::Base
# Only update if blank to prevent infite loops # Only update if blank to prevent infite loops
# TODO check cf_sync_confict flag once implemented # TODO check cf_sync_confict flag once implemented
if cf.string_value.to_s.blank? if cf.string_value.to_s.blank?
logger.debug " VIN was blank, updating the invoice vin in quickbooks" logger.info " VIN was blank, updating the invoice vin in quickbooks"
vin = Vehicle.find(issue.vehicles_id).vin vin = Vehicle.find(issue.vehicles_id).vin
break if vin.nil? break if vin.nil?
if not cf.string_value.to_s.eql? vin if not cf.string_value.to_s.eql? vin
cf.string_value = vin.to_s cf.string_value = vin.to_s
logger.debug "VIN has changed" logger.info "VIN has changed"
is_changed = true is_changed = true
end end
@@ -154,8 +155,12 @@ class Invoice < ActiveRecord::Base
# Push updates # Push updates
begin begin
logger.debug "Trying to update invoice" logger.info "Trying to update invoice"
get_base.update(invoice) if is_changed qbo = Qbo.first
qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token)
service.update(invoice) if is_changed
end
rescue rescue
# Do nothing, probaly custome field sync confict on the invoice. # Do nothing, probaly custome field sync confict on the invoice.
# This is a problem with how it's billed # This is a problem with how it's billed
@@ -187,7 +192,11 @@ class Invoice < ActiveRecord::Base
def pull def pull
begin begin
raise Exception unless self.id raise Exception unless self.id
@details = Qbo.get_base(:invoice).fetch_by_id(self.id) qbo = Qbo.first
@details = qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token)
service.fetch_by_id(self.id)
end
rescue Exception => e rescue Exception => e
@details = Quickbooks::Model::Invoice.new @details = Quickbooks::Model::Invoice.new
end end

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #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: #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:
# #
@@ -10,85 +10,15 @@
class Qbo < ActiveRecord::Base class Qbo < ActiveRecord::Base
unloadable 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
#
# Get a quickbooks base service object for type
# @params type of base
#
def self.get_base(type)
# lets getnourbold access token from the database
oauth2_client = get_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 include QuickbooksOauth
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
end
end
# Get the QBO account
def self.get_account
first
end
# Updates last sync time stamp # Updates last sync time stamp
def self.update_time_stamp def self.update_time_stamp
date = DateTime.now
logger.info "Updating QBO timestamp to #{date}"
qbo = Qbo.first qbo = Qbo.first
qbo.last_sync = DateTime.now qbo.last_sync = date
qbo.save qbo.save
end end

View File

@@ -0,0 +1,11 @@
<%= link_to t(:label_appointment), "https://calendar.google.com/calendar/render?action=TEMPLATE&text=#{@customer.name}+-&details=#{@customer.primary_phone}&dates=#{Time.now.strftime("%Y%m%d")}T090000/#{Time.now.strftime("%Y%m%d")}T170000", target: :_blank %>
<br/>
<br/>
<%= link_to t(:label_create_estimate), "https://qbo.intuit.com/app/estimate?nameId=#{@customer.id}", target: :_blank %>
<br/>
<br/>
<%= button_to t(:label_edit_customer), edit_customer_path(@customer), method: :get%>

View File

@@ -1,5 +1,11 @@
<table> <table>
<tbody> <tbody>
<tr>
<th><%=t(:label_name)%></th>
<td><%= customer.name %></td>
</tr>
<tr> <tr>
<th><%=t(:label_email)%></th> <th><%=t(:label_email)%></th>
<td><%= customer.email %></td> <td><%= customer.email %></td>
@@ -35,9 +41,6 @@
<td><%= customer.notes %></td> <td><%= customer.notes %></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<div style="float: right;">
<%= button_to t(:label_edit_customer), edit_customer_path(customer), method: :get%>
</div>
<br/> <br/>
<br/> <br/>

View File

@@ -3,4 +3,3 @@
<%= submit_tag t(:label_search) %> <%= submit_tag t(:label_search) %>
<% end %> <% end %>
<%= button_to t(:label_new_customer), new_customer_path, method: :get%> <%= button_to t(:label_new_customer), new_customer_path, method: :get%>
<%= button_to(t(:label_sync), qbo_sync_path, method: :get) if User.current.admin?%>

View File

@@ -1,4 +1,4 @@
<h2><%=t(:field_customer)%> #<%= @customer.id %> - <%= @customer.name %> </h2> <h2><%=t(:field_customer)%> #<%= @customer.id %> - <%= link_to @customer.to_s, "https://app.qbo.intuit.com/app/customerdetail?nameId=#{@customer.id}", target: :_blank %> </h2>
<div class="issue"> <div class="issue">
<div class="splitcontent"> <div class="splitcontent">
@@ -7,7 +7,22 @@
<h4><%=t(:label_details)%>:</h4> <h4><%=t(:label_details)%>:</h4>
<%= render :partial => 'customers/details', locals: {customer: @customer} %> <!-- Customer Info -->
<div class="splitcontent">
<div class="splitcontentleft">
<h4><%=t(:label_customer)%>:</h4>
<%= render :partial => 'customers/details', locals: {customer: @customer} %>
</div>
<div class="splitcontentleft">
<h4><%=t(:label_actions)%>:</h4>
<%= render :partial => 'customers/actions', locals: {customer: @customer} %>
</div>
</div>
<!-- QBO Info -->
<div class="splitcontent"> <div class="splitcontent">
<div class="splitcontentleft"> <div class="splitcontentleft">
@@ -35,8 +50,8 @@
</div> </div>
<br/> <br/>
<h3><%=@issues.open.count%> <%=t(:label_open_issues)%>:</h3> <h3><%=@issues.open.count%> <%=t(:label_open_issues)%> - <%=@hours.round(1)%> <%=t(:label_hours)%></h3>
<%= render :partial => 'issues/list_simple', locals: {issues: @issues.open} %> <%= render :partial => 'issues/list_simple', locals: {issues: @issues.open} %>
<h3><%=@closed_issues.count%> <%=t(:label_closed_issues)%>:</h3> <h3><%=@closed_issues.count%> <%=t(:label_closed_issues)%> - <%= @closed_hours.round(1)%> <%=t(:label_hours)%></h3>
<%= render :partial => 'issues/list_simple', locals: {issues: @closed_issues} %> <%= render :partial => 'issues/list_simple', locals: {issues: @closed_issues} %>

View File

@@ -1 +0,0 @@
<%= flash.now[:error] = t(:label_401) %>

View File

@@ -15,7 +15,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
<!-- configure the Intuit object: 'grantUrl' is a URL in your application which kicks off the flow, see below --> <!-- configure the Intuit object: 'grantUrl' is a URL in your application which kicks off the flow, see below -->
<script> <script>
intuit.ipp.anywhere.setup({menuProxy: '/path/to/blue-dot', grantUrl: '<%= Setting.host_name %>/qbo/authenticate'}); intuit.ipp.anywhere.setup({menuProxy: '/path/to/blue-dot', grantUrl: '<%= qbo_authenticate_path %>'});
</script> </script>
<table > <table >
@@ -58,8 +58,13 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
</tr> </tr>
<tr> <tr>
<th><%=t(:label_oauth_expires)%></th> <th><%=t(:label_oauth_expires)%></th>
<td><%= if Qbo.exists? then Qbo.first.expire end %> <td><%= if Qbo.exists? then Qbo.first.oauth2_access_token_expires_at end %>
</tr>
<tr>
<th><%=t(:label_oauth2_refresh_token_expires_at)%></th>
<td><%= if Qbo.exists? then Qbo.first.oauth2_refresh_token_expires_at end %>
</tr> </tr>
</tbody> </tbody>

13
app/views/qbo/webhook.erb Normal file
View File

@@ -0,0 +1,13 @@
<!--
The MIT License (MIT)
Copyright (c) 2024 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.
-->
<h2>QboController#webhook</h2>

View File

@@ -25,7 +25,6 @@ en:
label_search_estimates: "Search Estimates" label_search_estimates: "Search Estimates"
label_search: "Search" label_search: "Search"
label_estimates: "Estimates" label_estimates: "Estimates"
label_401: "Not Authorized"
warn_ru_sure: "You sure?" warn_ru_sure: "You sure?"
label_delete: "Delete" label_delete: "Delete"
label_edit: "Edit" label_edit: "Edit"
@@ -87,4 +86,9 @@ en:
label_billed_success: "Successfully Billed " label_billed_success: "Successfully Billed "
label_billing_error: "Cannot bill without a customer assigned" label_billing_error: "Cannot bill without a customer assigned"
label_qbo_sync_success: "Successfully synced to Quickbooks" label_qbo_sync_success: "Successfully synced to Quickbooks"
label_hours: "Hours"
label_oauth2_refresh_token_expires_at: "Refresh Token Expires At"
label_name: "Name"
label_appointment: "Add Appointment"
label_actions: "Actions"
label_create_estimate: "Create Estimate"

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #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: #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,13 @@ class AddTxnDates < ActiveRecord::Migration[5.1]
say "Sync Invoices" say "Sync Invoices"
invoices = QboInvoice.get_base.all qbo = Qbo.first
invoices = qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token)
service.all
end
return unless invoices
invoices.each { |invoice| invoices.each { |invoice|
# Load the invoice into the database # Load the invoice into the database

View File

@@ -0,0 +1,22 @@
#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
add_column :qbos, :realm_id, :text
remove_column :qbos, :company_id
remove_column :qbos, :token
remove_column :qbos, :expire
end
end

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #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: #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' name 'Redmine Quickbooks Online plugin'
author 'Rick Barrette' 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' 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 '2.1.1'
url 'https://github.com/rickbarrette/redmine_qbo' url 'https://github.com/rickbarrette/redmine_qbo'
author_url 'http://rickbarrette.org' author_url 'https://barrettefabrication.com'
settings :default => {'empty' => true}, :partial => 'qbo/settings' 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 # Add safe attributes for core models
Issue.safe_attributes 'customer_id' Issue.safe_attributes 'customer_id'

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #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: #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:
# #
@@ -52,46 +52,49 @@ module IssuePatch
if spent_hours > 0 then if spent_hours > 0 then
# Prepare to create a new Time Activity # Prepare to create a new Time Activity
time_service = Qbo.get_base(:time_activity) qbo = Qbo.first
item_service = Qbo.get_base(:item) qbo.perform_authenticated_request do |access_token|
time_entry = Quickbooks::Model::TimeActivity.new time_service = Quickbooks::Service::TimeActivity.new(:company_id => qbo.realm_id, :access_token => access_token)
item_service = Quickbooks::Service::Item.new(:company_id => qbo.realm_id, :access_token => access_token)
time_entry = Quickbooks::Model::TimeActivity.new
# Lets total up each activity before billing. # Lets total up each activity before billing.
# This will simpify the invoicing with a single billable time entry per time activity # This will simpify the invoicing with a single billable time entry per time activity
h = Hash.new(0) h = Hash.new(0)
spent_time.each do |entry| spent_time.each do |entry|
h[entry.activity.name] += entry.hours h[entry.activity.name] += entry.hours
# update time entries billed status # update time entries billed status
entry.billed = true entry.billed = true
entry.save entry.save
end end
# Now letes upload our totals for each activity as their own billable time entry
h.each do |key, val|
# Convert float spent time to hours and minutes # Now letes upload our totals for each activity as their own billable time entry
hours = val.to_i h.each do |key, val|
minutesDecimal = (( val - hours) * 60)
minutes = minutesDecimal.to_i # Convert float spent time to hours and minutes
hours = val.to_i
minutesDecimal = (( val - hours) * 60)
minutes = minutesDecimal.to_i
# Lets match the activity to an qbo item # Lets match the activity to an qbo item
item = item_service.query("SELECT * FROM Item WHERE Name = '#{key}' ").first item = item_service.query("SELECT * FROM Item WHERE Name = '#{key}' ").first
next if item.nil? next if item.nil?
# Create the new billable time entry and upload it # 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.employee_id = assigned_to.employee_id
time_entry.customer_id = customer_id time_entry.customer_id = customer_id
time_entry.billable_status = "Billable" time_entry.billable_status = "Billable"
time_entry.hours = hours time_entry.hours = hours
time_entry.minutes = minutes time_entry.minutes = minutes
time_entry.name_of = "Employee" time_entry.name_of = "Employee"
time_entry.txn_date = Date.today time_entry.txn_date = Date.today
time_entry.hourly_rate = item.unit_price time_entry.hourly_rate = item.unit_price
time_entry.item_id = item.id time_entry.item_id = item.id
time_entry.start_time = start_date time_entry.start_time = start_date
time_entry.end_time = Time.now time_entry.end_time = Time.now
time_service.create(time_entry) time_service.create(time_entry)
end
end end
end end
end end

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #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: #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'
require_dependency 'redmine/export/pdf/issues_pdf_helper' require_dependency 'redmine/export/pdf/issues_pdf_helper'
module IssuesPdfHelperPatch module PdfPatch
def self.included(base) def self.included(base)
base.send(:include, InstanceMethods) base.send(:include, InstanceMethods)
@@ -256,4 +256,4 @@ module IssuesPdfHelperPatch
end end
end end
Redmine::Export::PDF::IssuesPdfHelper.send(:include, IssuesPdfHelperPatch) Redmine::Export::PDF::IssuesPdfHelper.send(:include, PdfPatch)