8 Commits

56 changed files with 186 additions and 830 deletions

View File

@@ -3,11 +3,9 @@ source 'https://rubygems.org'
gem 'quickbooks-ruby' gem 'quickbooks-ruby'
gem 'oauth2' gem 'oauth2'
gem 'roxml' gem 'roxml'
gem 'nhtsa_vin'
gem 'will_paginate' gem 'will_paginate'
gem 'rails-jquery-autocomplete' gem 'rails-jquery-autocomplete'
gem 'jquery-ui-rails' gem 'jquery-ui-rails'
gem 'rexml'
group :assets do group :assets do
gem 'coffee-rails' gem 'coffee-rails'

View File

@@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 - 2024 Rick Barrette Copyright (c) 2016 - 2023 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

@@ -65,7 +65,6 @@ Note: After the inital synchronization, this plugin will recieve push notificati
## TODO ## TODO
* Add Setting for Sandbox Mode * Add Setting for Sandbox Mode
* Seperate Vehicles into a seperate plugin (I use redmine for my automotive shop management 😉)
* MORE Stuff as I make it up... * MORE Stuff as I make it up...
## License ## License

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2024 rick barrette #Copyright (c) 2022 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,6 +10,7 @@
# This controller class will handle map management # This controller class will handle map management
class CustomersController < ApplicationController class CustomersController < ApplicationController
unloadable
include AuthHelper include AuthHelper
helper :issues helper :issues
@@ -38,12 +39,6 @@ class CustomersController < ApplicationController
params.require(:customer).permit(:name, :email, :primary_phone, :mobile_phone, :phone_number, :notes) params.require(:customer).permit(:name, :email, :primary_phone, :mobile_phone, :phone_number, :notes)
end end
# getter method for a customer's vehicles
# used for customer autocomplete field / issue form
def filter_vehicles_by_customer
@filtered_vehicles = Vehicle.all.where(customer_id: params[:selected_customer])
end
# getter method for a customer's invoices # getter method for a customer's invoices
# used for customer autocomplete field / issue form # used for customer autocomplete field / issue form
def filter_invoices_by_customer def filter_invoices_by_customer
@@ -87,7 +82,6 @@ class CustomersController < ApplicationController
def show def show
begin begin
@customer = Customer.find_by_id(params[:id]) @customer = Customer.find_by_id(params[:id])
@vehicles = @customer.vehicles.paginate(:page => params[:page])
@issues = @customer.issues.order(id: :desc) @issues = @customer.issues.order(id: :desc)
@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)
@@ -141,7 +135,7 @@ class CustomersController < ApplicationController
def share def share
Thread.new do Thread.new do
logger.info "Removing expired customer tokens" logger.debug "Removing expired customer tokens"
CustomerToken.remove_expired_tokens CustomerToken.remove_expired_tokens
ActiveRecord::Base.connection.close ActiveRecord::Base.connection.close
end end

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2024 rick barrette #Copyright (c) 2022 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:
# #
@@ -8,6 +8,7 @@
# #
#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. #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class EstimateController < ApplicationController class EstimateController < ApplicationController
unloadable
include AuthHelper include AuthHelper
@@ -15,15 +16,6 @@ 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) 2024 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:
# #
@@ -8,6 +8,7 @@
# #
#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. #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class InvoiceController < ApplicationController class InvoiceController < ApplicationController
unloadable
include AuthHelper include AuthHelper

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2016 - 2025 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:
# #
@@ -9,6 +9,7 @@
#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. #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class QboController < ApplicationController class QboController < ApplicationController
unloadable
require 'openssl' require 'openssl'
@@ -25,10 +26,9 @@ 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
redirect_uri = "#{Setting.protocol}://#{Setting.host_name + qbo_oauth_callback_path}"
logger.info "redirect_uri: #{redirect_uri}"
oauth2_client = Qbo.construct_oauth2_client 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") 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 redirect_to grant_url
end end
@@ -39,7 +39,7 @@ class QboController < ApplicationController
if params[:state].present? if params[:state].present?
oauth2_client = Qbo.construct_oauth2_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.protocol}://#{Setting.host_name + qbo_oauth_callback_path}" redirect_uri = Setting.host_name + "/qbo/oauth_callback/"
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
@@ -51,9 +51,9 @@ class QboController < ApplicationController
qbo.refresh_token! qbo.refresh_token!
if qbo.save! if qbo.save!
redirect_to qbo_sync_path, :flash => { :notice => I18n.t(:label_connected) } redirect_to qbo_sync_path, :flash => { :notice => "Successfully connected to Quickbooks" }
else else
redirect_to plugin_settings_path(:redmine_qbo), :flash => { :error => I18n.t(:label_error) } redirect_to plugin_settings_path(:redmine_qbo), :flash => { :error => "Error" }
end end
end end
@@ -65,9 +65,9 @@ class QboController < ApplicationController
i = Issue.find_by_id params[:id] i = Issue.find_by_id params[:id]
if i.customer if i.customer
i.bill_time i.bill_time
redirect_to i, :flash => { :notice => I18n.t(:label_billed_success) + i.customer.name } redirect_to i, :flash => { :notice => "Successfully Billed #{i.customer.name}" }
else else
redirect_to i, :flash => { :error => I18n.t(:label_billing_error) } redirect_to i, :flash => { :error => "Cannot bill without a customer assigned" }
end end
end end
@@ -84,48 +84,46 @@ class QboController < ApplicationController
# proceed if the request is good # proceed if the request is good
if hash.eql? signature if hash.eql? signature
Thread.new do if request.headers['content-type'] == 'application/json'
if request.headers['content-type'] == 'application/json' data = JSON.parse(data)
data = JSON.parse(data) else
else # application/x-www-form-urlencoded
# application/x-www-form-urlencoded data = params.as_json
data = params.as_json end
end # Process the information
# Process the information entities = data['eventNotifications'][0]['dataChangeEvent']['entities']
entities = data['eventNotifications'][0]['dataChangeEvent']['entities'] entities.each do |entity|
entities.each do |entity| id = entity['id'].to_i
id = entity['id'].to_i name = entity['name']
name = entity['name']
logger.info "Casting #{name.constantize} to obj" logger.debug "Casting #{name.constantize} to obj"
# Magicly initialize the correct class # Magicly initialize the correct class
obj = name.constantize obj = name.constantize
# for merge events # for merge events
obj.destroy(entity['deletedId']) if entity['deletedId'] obj.destroy(entity['deletedId']) if entity['deletedId']
#Check to see if we are deleting a record #Check to see if we are deleting a record
if entity['operation'].eql? "Delete" if entity['operation'].eql? "Delete"
obj.destroy(id) obj.destroy(id)
#if not then update! #if not then update!
else else
begin begin
obj.sync_by_id(id) obj.sync_by_id(id)
rescue => e rescue => e
logger.error "Failed to call sync_by_id on obj" logger.error "Failed to call sync_by_id on obj"
logger.error e.message logger.error e.message
logger.error e.backtrace.join("\n") 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, status: 200 render :nothing => true
else else
render nothing: true, status: 400 render nothing: true, status: 400
end end
@@ -152,6 +150,6 @@ class QboController < ApplicationController
ActiveRecord::Base.connection.close ActiveRecord::Base.connection.close
end end
redirect_to :home, :flash => { :notice => I18n.t(:label_syncing) } redirect_to :home, :flash => { :notice => "Syncing Quickbooks" }
end end
end end

View File

@@ -1,125 +0,0 @@
#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.
# This controller class will handle map management
class VehiclesController < ApplicationController
include AuthHelper
before_action :require_user
def allowed_params
params.require(:vehicle).permit(:year, :make, :model, :customer_id, :notes, :vin)
end
# display a list of all vehicles
def index
if params[:customer_id]
begin
@vehicles = Customer.find_by_id(params[:customer_id]).vehicles.paginate(:page => params[:page])
rescue ActiveRecord::RecordNotFound
render_404
end
end
# search for a vehicle by vin
if params[:search]
@vehicles = Vehicle.search(params[:search]).paginate(:page => params[:page])
if only_one_non_zero?(@vehicles)
redirect_to @vehicles.first
end
end
end
# return an HTML form for creating a new vehicle
def new
@vehicle = Vehicle.new
@customer = Customer.find_by_id(params[:customer_id]) if params[:customer_id]
end
# create a new vehicle
def create
@vehicle = Vehicle.new(allowed_params)
if @vehicle.save
flash[:notice] = "New Vehicle Created"
redirect_to @vehicle
else
flash[:error] = @vehicle.errors.full_messages.to_sentence
redirect_to Vehicle.find_by_vin @vehicle.vin
end
end
# display a specific vehicle
def show
begin
@vehicle = Vehicle.find_by_id(params[:id])
@vin = @vehicle.vin.scan(/.{1,9}/) if @vehicle.vin
@issues = @vehicle.issues.order(id: :desc)
@closed_issues = (@issues - @issues.open)
rescue
render_404
end
end
# return an HTML form for editing a vehicle
def edit
begin
@vehicle = Vehicle.find_by_id(params[:id])
@customer = @vehicle.customer
rescue
render_404
end
end
# update a specific vehicle
def update
@customer = params[:customer]
begin
@vehicle = Vehicle.find_by_id(params[:id])
if @vehicle.update(allowed_params)
flash[:notice] = "Vehicle updated"
redirect_to @vehicle
else
redirect_to edit_vehicle_path
end
#show any errors anyways
flash[:error] = @vehicle.errors.full_messages.to_sentence unless @vehicle.errors.empty?
rescue
render_404
end
end
# delete a specific vehicle
def destroy
begin
Vehicle.find_by_id(params[:id]).destroy
flash[:notice] = "Vehicle deleted successfully"
redirect_to action: :index
rescue
render_404
end
end
private
# checks to see if there is only one item in an array
# @return true if array only has one item
def only_one_non_zero?( array )
found_non_zero = false
array.each do |val|
if val!=0
return false if found_non_zero
found_non_zero = true
end
end
found_non_zero
end
end

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2016 - 2025 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,6 +11,9 @@
module QuickbooksOauth module QuickbooksOauth
extend ActiveSupport::Concern extend ActiveSupport::Concern
OAUTH_CONSUMER_KEY = Setting.plugin_redmine_qbo['settingsOAuthConsumerKey']
OAUTH_CONSUMER_SECRET = Setting.plugin_redmine_qbo['settingsOAuthConsumerSecret']
#== Instance Methods #== Instance Methods
def perform_authenticated_request(&block) def perform_authenticated_request(&block)
@@ -18,7 +21,7 @@ module QuickbooksOauth
begin begin
yield oauth_access_token yield oauth_access_token
rescue OAuth2::Error, Quickbooks::AuthorizationFailure => ex rescue OAuth2::Error, Quickbooks::AuthorizationFailure => ex
Rails.logger.error("QuickbooksOauth.perform: #{ex.message}") Rails.logger.info("QuickbooksOauth.perform: #{ex.message}")
# to prevent an infinite loop here keep a counter and bail out after N times... # to prevent an infinite loop here keep a counter and bail out after N times...
attempts += 1 attempts += 1
@@ -33,7 +36,6 @@ module QuickbooksOauth
end end
def refresh_token! def refresh_token!
Rails.logger.info("QuickbooksOauth.refresh_token!")
t = oauth_access_token t = oauth_access_token
refreshed = t.refresh! refreshed = t.refresh!
@@ -43,8 +45,6 @@ module QuickbooksOauth
oauth2_refresh_token_expires_at = 100.days.from_now oauth2_refresh_token_expires_at = 100.days.from_now
end end
Rails.logger.info("QuickbooksOauth.refresh_token!: #{oauth2_refresh_token_expires_at}")
update!( update!(
oauth2_access_token: refreshed.token, oauth2_access_token: refreshed.token,
oauth2_access_token_expires_at: Time.at(refreshed.expires_at), oauth2_access_token_expires_at: Time.at(refreshed.expires_at),
@@ -68,16 +68,12 @@ module QuickbooksOauth
module ClassMethods module ClassMethods
def construct_oauth2_client def construct_oauth2_client
oauth_consumer_key = Setting.plugin_redmine_qbo['settingsOAuthConsumerKey']
oauth_consumer_secret = Setting.plugin_redmine_qbo['settingsOAuthConsumerSecret']
options = { options = {
site: "https://appcenter.intuit.com/connect/oauth2", site: "https://appcenter.intuit.com/connect/oauth2",
authorize_url: "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" token_url: "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer"
} }
OAuth2::Client.new(oauth_consumer_key, oauth_consumer_secret, options) OAuth2::Client.new(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, options)
end end
end end

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2016 - 2025 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:
# #
@@ -9,11 +9,12 @@
#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. #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 Customer < ActiveRecord::Base class Customer < ActiveRecord::Base
unloadable
has_many :issues has_many :issues
has_many :purchases
has_many :invoices has_many :invoices
has_many :estimates has_many :estimates
has_many :vehicles
validates_presence_of :id, :name validates_presence_of :id, :name
@@ -153,13 +154,11 @@ class Customer < ActiveRecord::Base
logger.info "Processing customer #{c.id}" logger.info "Processing customer #{c.id}"
customer = Customer.find_or_create_by(id: c.id) customer = Customer.find_or_create_by(id: c.id)
if c.active? if c.active?
#if not customer.name.eql? c.display_name if not customer.name.eql? c.display_name
customer.name = c.display_name customer.name = c.display_name
customer.id = c.id 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 c.new_record? if not c.new_record?
customer.delete customer.delete
@@ -178,22 +177,20 @@ class Customer < ActiveRecord::Base
# This needs to be simplified # This needs to be simplified
def self.sync_by_id(id) def self.sync_by_id(id)
qbo = Qbo.first qbo = Qbo.first
c = qbo.perform_authenticated_request do |access_token| customer = qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Customer.new(:company_id => qbo.realm_id, :access_token => access_token) service = Quickbooks::Service::Customer.new(:company_id => qbo.realm_id, :access_token => access_token)
service.fetch_by_id(id) service.fetch_by_id(id)
end end
return unless c return unless customer
customer = Customer.find_or_create_by(id: c.id) customer = Customer.find_or_create_by(id: customer.id)
if c.active? if customer.active?
#if not customer.name.eql? c.display_name if not customer.name.eql? customer.display_name
customer.name = c.display_name customer.name = customer.display_name
customer.id = c.id customer.id = customer.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
@@ -207,7 +204,7 @@ class Customer < ActiveRecord::Base
qbo = Qbo.first qbo = Qbo.first
@details = qbo.perform_authenticated_request do |access_token| @details = qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Customer.new(:company_id => qbo.realm_id, :access_token => access_token) service = Quickbooks::Service::Customer.new(:company_id => qbo.realm_id, :access_token => access_token)
service.update(@details) serivce.update(@details)
end end
#raise "QBO Fault" if @details.fault? #raise "QBO Fault" if @details.fault?
self.id = @details.id self.id = @details.id

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2024 rick barrette #Copyright (c) 2022 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:
# #
@@ -9,7 +9,7 @@
#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. #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 CustomerToken < ActiveRecord::Base class CustomerToken < ActiveRecord::Base
unloadable
has_many :issues has_many :issues
validates_presence_of :issue_id validates_presence_of :issue_id
before_create :generate_token, :generate_expire_date before_create :generate_token, :generate_expire_date

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2024 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:
# #
@@ -9,7 +9,7 @@
#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. #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 Employee < ActiveRecord::Base class Employee < ActiveRecord::Base
unloadable
has_many :users has_many :users
validates_presence_of :id, :name validates_presence_of :id, :name

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2024 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:
# #
@@ -9,6 +9,7 @@
#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. #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 Estimate < ActiveRecord::Base class Estimate < ActiveRecord::Base
unloadable
has_and_belongs_to_many :issues has_and_belongs_to_many :issues
belongs_to :customer belongs_to :customer
@@ -17,7 +18,7 @@ class Estimate < ActiveRecord::Base
# sync all estimates # sync all estimates
def self.sync def self.sync
logger.info "Syncing ALL estimates" logger.debug "Syncing ALL estimates"
qbo = Qbo.first qbo = Qbo.first
estimates = qbo.perform_authenticated_request do |access_token| estimates = qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token) service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token)
@@ -36,7 +37,7 @@ 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.info "Syncing estimate #{id}" logger.debug "Syncing estimate #{id}"
qbo = Qbo.first qbo = Qbo.first
qbo.perform_authenticated_request do |access_token| qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token) service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token)
@@ -44,16 +45,6 @@ class Estimate < ActiveRecord::Base
end end
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
# update an estimate # update an estimate
def self.update(id) def self.update(id)
# Update the item table # Update the item table

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2024 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:
# #
@@ -9,7 +9,7 @@
#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. #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 Invoice < ActiveRecord::Base class Invoice < ActiveRecord::Base
unloadable
has_and_belongs_to_many :issues has_and_belongs_to_many :issues
belongs_to :customer belongs_to :customer
validates_presence_of :doc_number, :id, :customer_id, :txn_date validates_presence_of :doc_number, :id, :customer_id, :txn_date
@@ -17,7 +17,7 @@ class Invoice < ActiveRecord::Base
# sync ALL the invoices # sync ALL the invoices
def self.sync def self.sync
logger.info "Syncing all invoices" logger.debug "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"
@@ -40,7 +40,7 @@ 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.info "Syncing invoice #{id}" logger.debug "Syncing invoice #{id}"
qbo = Qbo.first qbo = Qbo.first
qbo.perform_authenticated_request do |access_token| qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token) service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token)
@@ -58,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.info "Attaching invoice #{invoice.id} to issue #{issue.id}" logger.debug "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)
@@ -105,57 +105,42 @@ 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.info "Comparing custom fields"
logger.debug "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
# update the invoive custom fields with infomation from the issue if available logger.debug "Calling :process_invoice_custom_fields hook"
invoice.custom_fields.each { |cf| context = Redmine::Hook.call_hook :process_invoice_custom_fields, { issue: issue, invoice: invoice }
# VIN from the attached vehicle unless context.nil?
# TODO move this into seperate plugin logger.debug "We have a context!"
# TODO create hook for seperate plugin context= context.first
begin issue = context[:issue]
if cf.name.eql? "VIN" invoice = context[:invoice]
# Only update if blank to prevent infite loops is_changed = context[:is_changed]
# TODO check cf_sync_confict flag once implemented end
if cf.string_value.to_s.blank?
logger.info " VIN was blank, updating the invoice vin in quickbooks"
vin = Vehicle.find(issue.vehicles_id).vin
break if vin.nil?
if not cf.string_value.to_s.eql? vin
cf.string_value = vin.to_s
logger.info "VIN has changed"
is_changed = true
end
end # Custom Values
begin
value = issue.custom_values.find_by(custom_field_id: CustomField.find_by_name(cf.name).id)
# Check to see if the value is blank...
if not value.value.to_s.blank?
# Check to see if the value is diffrent
if not cf.string_value.to_s.eql? value.value.to_s
# update the custom field on the invoice
cf.string_value = value.value.to_s
is_changed = true
end end
rescue
#do nothing
end end
rescue
# Custom Values # Nothing to do here, there is no match
begin end
value = issue.custom_values.find_by(custom_field_id: CustomField.find_by_name(cf.name).id)
# Check to see if the value is blank...
if not value.value.to_s.blank?
# Check to see if the value is diffrent
if not cf.string_value.to_s.eql? value.value.to_s
# update the custom field on the invoice
cf.string_value = value.value.to_s
is_changed = true
end
end
rescue
# Nothing to do here, there is no match
end
}
# Push updates # Push updates
begin begin
logger.info "Trying to update invoice" logger.debug "Trying to update invoice"
qbo = Qbo.first qbo = Qbo.first
qbo.perform_authenticated_request do |access_token| qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token) service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token)

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2016 - 2025 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:
# #
@@ -9,9 +9,9 @@
#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. #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class Qbo < ActiveRecord::Base class Qbo < ActiveRecord::Base
unloadable
include QuickbooksOauth include QuickbooksOauth
include Redmine::I18n
# Updates last sync time stamp # Updates last sync time stamp
def self.update_time_stamp def self.update_time_stamp

View File

@@ -1,98 +0,0 @@
#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.
class Vehicle < ActiveRecord::Base
belongs_to :customer
has_many :issues, :foreign_key => 'vehicles_id'
validates_presence_of :customer
validates :vin, uniqueness: true
before_save :decode_vin
self.primary_key = :id
# returns a human readable string
def to_s
if year.nil? or make.nil? or model.nil?
return "#{vin}"
else
split_vin = vin.scan(/.{1,9}/)
return "#{year} #{make} #{model} - #{split_vin[1]}"
end
end
# returns the raw JSON details from NHTSA
def details
get_details if @details.nil?
return @details
end
# Force Upper Case for make numbers
def make=(val)
# The to_s is in case you get nil/non-string
write_attribute(:make, val.to_s.titleize)
end
# Force Upper Case for model numbers
def model=(val)
# The to_s is in case you get nil/non-string
write_attribute(:model, val.to_s.titleize)
end
# Force Upper Case & strip VIN of all illegal chars (for barcode scanner)
def vin=(val)
val = val.to_s.upcase.gsub(/[^A-HJ-NPR-Za-hj-npr-z\d]+/,"")
write_attribute(:vin, val)
end
# search for a vin
def self.search(search)
where("vin LIKE ?", "%#{search}%")
end
# decodes a vin and updates self
def decode_vin
get_details
if @details
begin
self.year = @details.year unless @details.year.nil?
self.make = @details.make unless @details.make.nil?
self.model = @details.model unless @details.model.nil?
self.doors = @details.doors unless @details.doors.nil?
self.trim = @details.trim unless @details.trim.nil?
rescue Exception => e
errors.add(:vin, e.message)
end
end
self.name = to_s
end
private
# init method to pull JSON details from NHTSA
def get_details
if self.vin?
#validate the vin before calling a remote server
validation = NhtsaVin.validate(self.vin)
begin
#if the vin validation failed, raise an exception and exit
raise RuntimeError, validation.error unless validation.valid?
# query NHTSA for details on the vin
query = NhtsaVin.get(self.vin)
raise RuntimeError, query.error unless query.valid?
@details = query.response
rescue Exception => e
errors.add(:vin, e.message)
end
end
end
end

View File

@@ -1,11 +0,0 @@
<%= link_to t(:label_appointment), "https://calendar.google.com/calendar/render?action=TEMPLATE&text=#{@customer.name}+-&details=#{ link_to "Customer Details", "https://#{Setting.host_name}#{customer_path @customer.id}"}%0A#{@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,11 +1,5 @@
<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>
@@ -42,5 +36,8 @@
</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,3 +3,4 @@
<%= 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 +0,0 @@
$('select#issue_vehicles_id').html('<%= j content_tag(:option,'',:value=>"")+options_from_collection_for_select(@filtered_vehicles, :id, :to_s) %>');

View File

@@ -1,4 +1,4 @@
<h2><%=t(:field_customer)%> #<%= @customer.id %> - <%= link_to @customer.to_s, "https://app.qbo.intuit.com/app/customerdetail?nameId=#{@customer.id}", target: :_blank %> </h2> <h2><%=t(:field_customer)%> #<%= @customer.id %> - <%= @customer.name %> </h2>
<div class="issue"> <div class="issue">
<div class="splitcontent"> <div class="splitcontent">
@@ -7,22 +7,7 @@
<h4><%=t(:label_details)%>:</h4> <h4><%=t(:label_details)%>:</h4>
<!-- Customer Info --> <%= render :partial => 'customers/details', locals: {customer: @customer} %>
<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">
@@ -39,11 +24,7 @@
</div> </div>
<div class="splitcontentleft"> <div class="splitcontentleft">
<h4><%=t(:field_vehicles)%>:</h4> <% call_hook :show_customer_view_right %>
<%= render :partial => 'vehicles/list' %>
<div style="float: right;">
<%= button_to "New Vehicle", new_customer_vehicle_path(@customer), method: :get %>
</div>
</div> </div>
</div> </div>

View File

@@ -1,6 +1,6 @@
<% if @customer.present? %> <% if @customer.present? %>
<% @customer.estimates.order(id: :desc).each do |estimate| %> <% @customer.estimates.order(doc_number: :desc).each do |estimate| %>
<div class="row"> <div class="row">
<b><%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %></b> <%= estimate.txn_date %> <b><%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %></b> <%= estimate.txn_date %>
</div> </div>

View File

@@ -1,6 +1,6 @@
<% if @customer.present? %> <% if @customer.present? %>
<% @customer.invoices.order(id: :desc).each do |invoice| %> <% @customer.invoices.order(doc_number: :desc).each do |invoice| %>
<div class="row"> <div class="row">
<b><%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %></b> <%= invoice.txn_date %> <b><%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %></b> <%= invoice.txn_date %>
</div> </div>

View File

@@ -9,6 +9,7 @@
<%= select_estimate %> <%= select_estimate %>
</p> </p>
<p>
<%= vehicle %> <%# <p> %>
</p> <%# <%= call_hook here %> %>
<%# </p> %>

View File

@@ -17,19 +17,6 @@
</div> </div>
<div class="splitcontentleft"> <div class="splitcontentleft">
<div class="vehicle attribute"> <%# call_hook here %>
<div class="label"><span><%=t(:field_vehicle)%></span>:</div>
<div class="value"><%= vehicle %></div>
</div>
<div class="vehicle_vin attribute">
<div class="label"><span><%=t(:field_vin)%></span>:</div>
<div class="value"><%=split_vin[0] if split_vin%><b><%=split_vin[1] if split_vin%></b></div>
</div>
<div class="vehicle_notes attribute">
<div class="label"><span><%=t(:field_notes)%></span>:</div>
<div class="value"><%=notes%></div>
</div>
</div> </div>
</div> </div>

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: '<%= qbo_authenticate_path %>'}); intuit.ipp.anywhere.setup({menuProxy: '/path/to/blue-dot', grantUrl: '<%= Setting.host_name %>/qbo/authenticate'});
</script> </script>
<table > <table >

View File

@@ -1,13 +0,0 @@
<!--
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

@@ -1,45 +0,0 @@
<div class="issue">
<div class="splitcontent">
<div class="splitcontentleft">
<h4><%=t(:label_details)%>:</h4>
<table>
<tbody>
<tr>
<th><%= t(:field_customer)%></th>
<td><%= link_to vehicle.customer.name, customer_path(vehicle.customer) %></td>
</tr>
<tr>
<th><%= t(:field_vehicle) %></th>
<td><%= vehicle.to_s %></td>
</tr>
<tr>
<th><%= t(:field_vin) %></th>
<td><%= @vin[0] if @vin %><b><%=@vin[1] if @vin%></b></td>
</tr>
<th><%= t(:label_trim) %></th>
<td><%= vehicle.doors %> <%=t(:label_door) if vehicle.doors? %> <%= vehicle.trim %></td>
</tr>
</tbody>
</table>
</div>
<div class="splitcontentleft">
<h4><%=t(:field_notes)%>:</h4>
<td><%= vehicle.notes %></td>
</tr>
</div>
</div>
</div>
<div style="float: right;">
<%= button_to t(:label_edit), edit_vehicle_path(vehicle), method: :get%>
<%= button_to t(:label_delete), vehicle, method: :delete, data: {confirm: t(:warn_ru_sure)} %>
</div>

View File

@@ -1,56 +0,0 @@
<div class="row">
<div class="span6 columns">
<fieldset>
<%= form_for @vehicle do |f| %>
<div class="clearfix">
<%=t(:field_customer)%>:
<div class="input">
<%= f.autocomplete_field :customer, autocomplete_customer_name_customers_path, :value => @customer.name, :update_elements => {:id => '#customer_id', :value => '#issue_customer'}, :required => true %>
<%= f.hidden_field :customer_id, :id => "customer_id", :value => @customer.id %>
</div>
</div>
<div class="clearfix">
<%=t(:label_year)%>:
<div class="input">
<%= f.number_field :year, :autocomplete => "off" %>
</div>
</div>
<div class="clearfix">
<%=t(:label_make)%>:
<div class="input">
<%= f.text_field :make, :autocomplete => "off" %>
</div>
</div>
<div class="clearfix">
<%=t(:label_model)%>:
<div class="input">
<%= f.text_field :model, :autocomplete => "off" %>
</div>
</div>
<div class="clearfix">
<%=t(:field_vin)%>:
<div class="input">
<%= f.text_field :vin , :autofocus => true %>
</div>
</div>
<div class="clearfix">
<%=t(:field_notes)%>:
<div class="input">
<%= f.text_area :notes, :cols => 60, :rows => 10, :no_label => true %>
</div>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
</fieldset>
</div>
</div>

View File

@@ -1,28 +0,0 @@
<% if @vehicles.present? %>
<% @vehicles.each do |vehicle| %>
<div class="row">
<div>
<b><%= link_to "##{vehicle.id}", vehicle_path(vehicle) %> </b>
</div>
<div>
<%= vehicle.to_s %>
<br/>
<%= vehicle.customer %>
<br/>
<%= vehicle.vin.scan(/.{1,9}/)[0] if vehicle.vin %><b><%=vehicle.vin.scan(/.{1,9}/)[1] if vehicle.vin%></b>
</div>
</div>
<br/>
<% end %>
<div class="actions">
<%= will_paginate @vehicles %>
</div>
<p><%=t(:label_matching)%> <%=@vehicles.count%> <%=t(:field_vehicles) %> </p>
<% else %>
<p><%=t(:label_no_vehicles)%> <%= params[:search] %>.</p>
<% end %>

View File

@@ -1,4 +0,0 @@
<%= form_tag(vehicles_path, :method => "get", id: "search-form") do %>
<%= text_field_tag :search, params[:search], placeholder: t(:label_search_vin), :autocomplete => "off" %>
<%= submit_tag t(:label_search) %>
<% end %>

View File

@@ -1 +0,0 @@
<option value="<%= vehicle.id %>"><%= vehicle.to_s.titleize %></option>

View File

@@ -1,3 +0,0 @@
<h1><%=t(:label_edit_customer_vehicle)%></h1>
<br/>
<%= render :partial => 'vehicles/form' %>

View File

@@ -1,4 +0,0 @@
<h2><%=t(:label_cusomer_vehicles)%> <span style="float:right"> <%= render :partial => 'vehicles/search' %> </span> </h2>
<br/>
<%= render :partial => 'vehicles/list' %>

View File

@@ -1,3 +0,0 @@
<h2><%=t(:label_new_vehicle)%></h2>
<br/>
<%= render :partial => 'vehicles/form' %>

View File

@@ -1,11 +0,0 @@
<h2><%=t(:field_vehicle)%> #<%=@vehicle.id%></h2>
<%= render :partial => 'vehicles/details', locals: {vehicle: @vehicle} %>
<h3><%=@issues.open.count%> <%=t(:label_open_issues)%></h3>
<%= render :partial => 'issues/list_simple', locals: {issues: @issues.open} %>
<h3><%=@closed_issues.count%> <%=t(:label_closed_issues)%></h3>
<%= render :partial => 'issues/list_simple', locals: {issues: (@closed_issues)} %>

View File

@@ -1,10 +1,5 @@
$(function() { $(function() {
$("input#issue_customer_id").on("change", function() { $("input#issue_customer_id").on("change", function() {
$.ajax({
url: "/filter_vehicles_by_customer",
type: "GET",
data: { selected_customer: $("input#issue_customer_id").val() }
});
$.ajax({ $.ajax({
url: "/filter_estimates_by_customer", url: "/filter_estimates_by_customer",
@@ -13,11 +8,4 @@ $(function() {
}); });
}); });
$("input#project_customer_id").on("change", function() {
$.ajax({
url: "/filter_vehicles_by_customer",
type: "GET",
data: { selected_customer: $("input#project_customer_id").val() }
});
});
}); });

View File

@@ -16,9 +16,6 @@ en:
field_employee: "Employee" field_employee: "Employee"
field_invoice: "Invoice" field_invoice: "Invoice"
field_estimate: "Estimate" field_estimate: "Estimate"
field_vehicles: "Vehicles"
field_vehicle: "Vehicle"
field_vin: "VIN"
field_notes: "Notes" field_notes: "Notes"
field_billed: "Billed" field_billed: "Billed"
label_week: "Week" label_week: "Week"
@@ -31,13 +28,8 @@ en:
label_year: "Year" label_year: "Year"
label_make: " Make" label_make: " Make"
label_model: "Model" label_model: "Model"
label_no_vehicles: "There are no vehicles containing the term(s)"
label_no_customers: "There are no customers containing the term(s)" label_no_customers: "There are no customers containing the term(s)"
label_matching: "Matching " label_matching: "Matching "
label_search_vin: "Search Vehicles by VIN"
label_edit_customer_vehicle: "Edit Customer Vehicle"
label_cusomer_vehicles: "Customer Vehicles"
label_new_vehicle: "New Customer Vehicle"
label_open_issues: "Open Issues" label_open_issues: "Open Issues"
label_closed_issues: "Closed Issues" label_closed_issues: "Closed Issues"
label_sync: "Sync" label_sync: "Sync"
@@ -88,8 +80,4 @@ en:
label_qbo_sync_success: "Successfully synced to Quickbooks" label_qbo_sync_success: "Successfully synced to Quickbooks"
label_hours: "Hours" label_hours: "Hours"
label_oauth2_refresh_token_expires_at: "Refresh Token Expires At" 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"
label_syncing: "Syncing Quickbooks"

View File

@@ -31,15 +31,9 @@ get 'customers/view/:token', :to => 'customers#view', as: :view
get 'customers/share/:id', :to => 'customers#share', as: :share get 'customers/share/:id', :to => 'customers#share', as: :share
#java script routes #java script routes
get 'filter_vehicles_by_customer' => 'customers#filter_vehicles_by_customer'
get 'filter_estimates_by_customer' => 'customers#filter_estimates_by_customer' get 'filter_estimates_by_customer' => 'customers#filter_estimates_by_customer'
get 'filter_invoices_by_customer' => 'customers#filter_invoices_by_customer' get 'filter_invoices_by_customer' => 'customers#filter_invoices_by_customer'
# Nest Vehicles under customers
resources :customers do resources :customers do
resources :vehicles
get :autocomplete_customer_name, :on => :collection get :autocomplete_customer_name, :on => :collection
end end
#allow for just vehicles too
resources :vehicles

View File

@@ -1,24 +0,0 @@
#The MIT License (MIT)
#
#Copyright (c) 2022 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 CreateVehicles < ActiveRecord::Migration[5.1]
def change
create_table :vehicles do |t|
t.integer :year
t.string :make
t.string :model
t.string :vin
t.text :notes
end
add_reference :vehicles, :qbo_customer, index: true
end
end

View File

@@ -1,15 +0,0 @@
#The MIT License (MIT)
#
#Copyright (c) 2022 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 UpdateIssuesWithVehicles < ActiveRecord::Migration[5.1]
def change
add_reference :issues, :vehicles, index: true
end
end

View File

@@ -1,15 +0,0 @@
#The MIT License (MIT)
#
#Copyright (c) 2022 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 UpdateVehicles < ActiveRecord::Migration[5.1]
def change
add_column :vehicles, :name, :text
end
end

View File

@@ -12,6 +12,5 @@ class QbocustomersToCustomers< ActiveRecord::Migration[5.1]
def change def change
rename_table :qbo_customers, :customers rename_table :qbo_customers, :customers
rename_column :issues, :qbo_customer_id, :customer_id rename_column :issues, :qbo_customer_id, :customer_id
rename_column :vehicles, :qbo_customer_id, :customer_id
end end
end end

View File

@@ -11,6 +11,5 @@
class UpdateProjects < ActiveRecord::Migration[5.1] class UpdateProjects < ActiveRecord::Migration[5.1]
def change def change
add_reference :projects, :customer, index: true add_reference :projects, :customer, index: true
add_reference :projects, :vehicle, index: true
end end
end end

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2024 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:
# #
@@ -9,46 +9,41 @@
#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. #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 AddTxnDates < ActiveRecord::Migration[5.1] class AddTxnDates < ActiveRecord::Migration[5.1]
def change def change
begin add_column :qbo_invoices, :txn_date, :date
add_column :qbo_invoices, :txn_date, :date add_column :qbo_estimates, :txn_date, :date
add_column :qbo_estimates, :txn_date, :date
reversible do |direction| reversible do |direction|
direction.up { direction.up {
break unless Qbo.first break unless Qbo.first
QboEstimate.reset_column_information QboEstimate.reset_column_information
QboInvoice.reset_column_information QboInvoice.reset_column_information
say "Sync Estimates" say "Sync Estimates"
QboEstimate.sync QboEstimate.sync
say "Sync Invoices" say "Sync Invoices"
qbo = Qbo.first qbo = Qbo.first
invoices = qbo.perform_authenticated_request do |access_token| invoices = qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token) service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token)
service.all service.all
end end
return unless invoices return unless invoices
invoices.each { |invoice| invoices.each { |invoice|
# Load the invoice into the database # Load the invoice into the database
qbo_invoice = QboInvoice.find_or_create_by(id: invoice.id) qbo_invoice = QboInvoice.find_or_create_by(id: invoice.id)
qbo_invoice.doc_number = invoice.doc_number qbo_invoice.doc_number = invoice.doc_number
qbo_invoice.id = invoice.id qbo_invoice.id = invoice.id
qbo_invoice.customer_id = invoice.customer_ref qbo_invoice.customer_id = invoice.customer_ref
qbo_invoice.txn_date = invoice.txn_date qbo_invoice.txn_date = invoice.txn_date
qbo_invoice.save! qbo_invoice.save!
}
} }
end }
rescue
logger.error "AddTxnDates Failed"
end end
end end

View File

@@ -1,33 +0,0 @@
#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.
class UpdateVehiclesTrim < ActiveRecord::Migration[5.1]
def change
begin
add_column :vehicles, :doors, :text
add_column :vehicles, :trim, :text
reversible do |direction|
direction.up {
# Update local vehicle database by forcing a save, look at before_save
vehicles = Vehicle.all
vehicles.each { |vehicle|
vehicle.save!
}
}
end
rescue
logger.error "Failed to update vehicles"
end
end
end

View File

@@ -22,7 +22,7 @@ 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 '2.1.1' version '2.0.2'
url 'https://github.com/rickbarrette/redmine_qbo' url 'https://github.com/rickbarrette/redmine_qbo'
author_url 'https://barrettefabrication.com' author_url 'https://barrettefabrication.com'
settings :default => {'empty' => true}, :partial => 'qbo/settings' settings :default => {'empty' => true}, :partial => 'qbo/settings'
@@ -33,11 +33,9 @@ Redmine::Plugin.register :redmine_qbo do
Issue.safe_attributes 'item_id' Issue.safe_attributes 'item_id'
Issue.safe_attributes 'estimate_id' Issue.safe_attributes 'estimate_id'
Issue.safe_attributes 'invoice_id' Issue.safe_attributes 'invoice_id'
Issue.safe_attributes 'vehicles_id'
User.safe_attributes 'employee_id' User.safe_attributes 'employee_id'
TimeEntry.safe_attributes 'billed' TimeEntry.safe_attributes 'billed'
Project.safe_attributes 'customer_id' Project.safe_attributes 'customer_id'
Project.safe_attributes 'vehicle_id'
# We are playing in the sandbox # We are playing in the sandbox
#Quickbooks.sandbox_mode = true #Quickbooks.sandbox_mode = true
@@ -48,10 +46,8 @@ Redmine::Plugin.register :redmine_qbo do
# Permissions for security # Permissions for security
permission :view_customers, :customers => :index, :public => false permission :view_customers, :customers => :index, :public => false
permission :add_customers, :customers => :new, :public => false permission :add_customers, :customers => :new, :public => false
permission :view_vehicles, :vehicles => :new, :public => false
# Register top menu items # Register top menu items
menu :top_menu, :customers, { :controller => :customers, :action => :index }, :caption => 'Customers', :if => Proc.new {User.current.logged?} menu :top_menu, :customers, { :controller => :customers, :action => :index }, :caption => 'Customers', :if => Proc.new {User.current.logged?}
menu :top_menu, :vehicles, { :controller => :vehicles, :action => :index }, :caption => 'Vehicles', :if => Proc.new { User.current.logged? }
end end

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2024 rick barrette #Copyright (c) 2022 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,6 +15,7 @@ module AttachmentsControllerPatch
def self.included(base) def self.included(base)
base.class_eval do base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
# check if login is globally required to access the application # check if login is globally required to access the application
def check_if_login_required def check_if_login_required

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2024 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:
# #
@@ -21,11 +21,11 @@ module IssuePatch
# Same as typing in the class # Same as typing in the class
base.class_eval do base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
belongs_to :customer, primary_key: :id belongs_to :customer, primary_key: :id
belongs_to :customer_token, primary_key: :id belongs_to :customer_token, primary_key: :id
belongs_to :estimate, primary_key: :id belongs_to :estimate, primary_key: :id
has_and_belongs_to_many :invoices has_and_belongs_to_many :invoices
belongs_to :vehicle, primary_key: :id
end end
end end

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2024 rick barrette #Copyright (c) 2022 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,6 +23,7 @@ module IssuesControllerPatch
def self.included(base) def self.included(base)
base.class_eval do base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
helper Helper helper Helper
end end

View File

@@ -26,13 +26,11 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
# This is done to preload customer information if the entire project is dedicated to a customer # This is done to preload customer information if the entire project is dedicated to a customer
if context[:project] if context[:project]
selected_customer = context[:project].customer ? context[:project].customer.id : nil selected_customer = context[:project].customer ? context[:project].customer.id : nil
selected_vehicle = context[:project].vehicle ? context[:project].vehicle.id : nil
end end
# Check to see if the issue already belongs to a customer # Check to see if the issue already belongs to a customer
selected_customer = context[:issue].customer ? context[:issue].customer.id : nil selected_customer = context[:issue].customer ? context[:issue].customer.id : nil
selected_estimate = context[:issue].estimate ? context[:issue].estimate.id : nil selected_estimate = context[:issue].estimate ? context[:issue].estimate.id : nil
selected_vehicle = context[:issue].vehicles_id ? context[:issue].vehicles_id : nil
# Load customer information # Load customer information
customer = Customer.find_by_id(selected_customer) if selected_customer customer = Customer.find_by_id(selected_customer) if selected_customer
@@ -52,22 +50,15 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
:id => "issue_customer_id", :id => "issue_customer_id",
:onchange => "updateIssueFrom('/issues/#{context[:issue].id}/edit.js', this)" :onchange => "updateIssueFrom('/issues/#{context[:issue].id}/edit.js', this)"
# Load estimates & vehicles # Load estimates
if context[:issue].customer if context[:issue].customer
if customer.vehicles
vehicles = customer.vehicles.pluck(:name, :id)
else
vehicles = [nil].compact
end
estimates = customer.estimates.pluck(:doc_number, :id).sort! {|x, y| y <=> x} estimates = customer.estimates.pluck(:doc_number, :id).sort! {|x, y| y <=> x}
else else
vehicles = [nil].compact
estimates = [nil].compact estimates = [nil].compact
end end
# Generate the drop down list of quickbooks estimates & vehicles # Generate the drop down list of quickbooks estimates
select_estimate = f.select :estimate_id, estimates, :selected => selected_estimate, include_blank: true select_estimate = f.select :estimate_id, estimates, :selected => selected_estimate, include_blank: true
vehicle = f.select :vehicles_id, vehicles, :selected => selected_vehicle, include_blank: true
# Pass all prebuilt form components to our partial # Pass all prebuilt form components to our partial
context[:controller].send(:render_to_string, { context[:controller].send(:render_to_string, {
@@ -77,7 +68,6 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
customer_id: customer_id, customer_id: customer_id,
context: context, context: context,
select_estimate: select_estimate, select_estimate: select_estimate,
vehicle: vehicle
} }
} }
) )

View File

@@ -36,26 +36,12 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
end end
end end
begin
v = Vehicle.find(issue.vehicles_id)
vehicle = link_to v.to_s, vehicle_path( v.id )
vin = v.vin
notes = v.notes
rescue
#do nothing
end
split_vin = vin.scan(/.{1,9}/) if vin
context[:controller].send(:render_to_string, { context[:controller].send(:render_to_string, {
:partial => 'issues/show_details', :partial => 'issues/show_details',
locals: { locals: {
customer: customer, customer: customer,
estimate_link: estimate_link, estimate_link: estimate_link,
invoice_link: invoice_link, invoice_link: invoice_link
vehicle: vehicle,
split_vin: split_vin,
notes: notes
} }
}) })
end end

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2024 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,8 +16,10 @@ module PdfPatch
def self.included(base) def self.included(base)
base.send(:include, InstanceMethods) base.send(:include, InstanceMethods)
base.class_eval do base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
alias_method :issue_to_pdf, :issue_to_pdf_with_patch alias_method :issue_to_pdf, :issue_to_pdf_with_patch
alias_method :issue_to_pdf_with_patch, :issue_to_pdf alias_method :issue_to_pdf_with_patch, :issue_to_pdf
end end
end end
@@ -53,16 +55,10 @@ module PdfPatch
left << [l(:field_priority), issue.priority] left << [l(:field_priority), issue.priority]
left << [l(:field_customer), customer] left << [l(:field_customer), customer]
left << [l(:field_assigned_to), issue.assigned_to] unless issue.disabled_core_fields.include?('assigned_to_id') left << [l(:field_assigned_to), issue.assigned_to] unless issue.disabled_core_fields.include?('assigned_to_id')
#left << [l(:field_category), issue.category] unless issue.disabled_core_fields.include?('category_id')
#left << [l(:field_fixed_version), issue.fixed_version] unless issue.disabled_core_fields.include?('fixed_version_id')
v = Vehicle.find_by_id(issue.vehicles_id) logger.debug "Calling :pdf_left hook"
vehicle = v ? v.to_s : nil context = Redmine::Hook.call_hook :pdf_left, { array: left, issue: issue }
vin = v ? v.vin : nil left = left + context.first unless context.nil?
notes = v ? v.notes : nil
left << [l(:field_vehicles), vehicle]
left << [l(:field_vin), vin ? vin.gsub(/(.{9})/, '\1 ') : nil]
#left << [l(:field_notes), notes]
right = [] right = []
right << [l(:field_start_date), format_date(issue.start_date)] unless issue.disabled_core_fields.include?('start_date') right << [l(:field_start_date), format_date(issue.start_date)] unless issue.disabled_core_fields.include?('start_date')
@@ -70,7 +66,10 @@ module PdfPatch
right << [l(:field_done_ratio), "#{issue.done_ratio}%"] unless issue.disabled_core_fields.include?('done_ratio') right << [l(:field_done_ratio), "#{issue.done_ratio}%"] unless issue.disabled_core_fields.include?('done_ratio')
right << [l(:field_estimated_hours), l_hours(issue.estimated_hours)] unless issue.disabled_core_fields.include?('estimated_hours') right << [l(:field_estimated_hours), l_hours(issue.estimated_hours)] unless issue.disabled_core_fields.include?('estimated_hours')
right << [l(:label_spent_time), l_hours(issue.total_spent_hours)] if User.current.allowed_to?(:view_time_entries, issue.project) right << [l(:label_spent_time), l_hours(issue.total_spent_hours)] if User.current.allowed_to?(:view_time_entries, issue.project)
right << [l(:field_notes), notes]
logger.debug "Calling :pdf_right hook"
context = Redmine::Hook.call_hook :pdf_right, { array: right, issue: issue }
right = right + context.first unless context.nil?
rows = left.size > right.size ? left.size : right.size rows = left.size > right.size ? left.size : right.size
while left.size < rows while left.size < rows

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2024 rick barrette #Copyright (c) 2017 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:
# #
@@ -21,8 +21,8 @@ module ProjectPatch
# Same as typing in the class # Same as typing in the class
base.class_eval do base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
belongs_to :customer, primary_key: :id belongs_to :customer, primary_key: :id
belongs_to :vehicle, primary_key: :id
end end
end end
end end

View File

@@ -16,21 +16,12 @@ class ProjectsFormHookListener < Redmine::Hook::ViewListener
# Check to see if there is a quickbooks user attached to the issue # Check to see if there is a quickbooks user attached to the issue
selected_customer = context[:project].customer ? context[:project].customer : nil selected_customer = context[:project].customer ? context[:project].customer : nil
selected_vehicle = context[:project].vehicle_id ? context[:project].vehicle_id : nil
# Load customer information # Load customer information
customer = Customer.find_by_id(selected_customer) if selected_customer customer = Customer.find_by_id(selected_customer) if selected_customer
search_customer = f.autocomplete_field :customer, autocomplete_customer_name_customers_path, :selected => selected_customer, :update_elements => {:id => '#project_customer_id', :value => '#project_customer'} search_customer = f.autocomplete_field :customer, autocomplete_customer_name_customers_path, :selected => selected_customer, :update_elements => {:id => '#project_customer_id', :value => '#project_customer'}
customer_id = f.hidden_field :customer_id, :id => "project_customer_id" customer_id = f.hidden_field :customer_id, :id => "project_customer_id"
if context[:project].customer return "<p><label for=\"project_customer\">Customer</label>#{search_customer} #{customer_id}</p>"
vehicles = customer.vehicles.pluck(:name, :id).sort!
else
vehicles = [nil].compact
end
vehicle = f.select :vehicle_id, vehicles, :selected => selected_vehicle, include_blank: true
return "<p><label for=\"project_customer\">Customer</label>#{search_customer} #{customer_id}</p> <p>#{vehicle}</p>"
end end
end end

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2024 rick barrette #Copyright (c) 2022 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,6 +20,7 @@ module UserPatch
# Same as typing in the class # Same as typing in the class
base.class_eval do base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
belongs_to :employee, primary_key: :id belongs_to :employee, primary_key: :id
end end
end end