mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 17:04:23 -05:00
Compare commits
82 Commits
dev
...
9779437c00
| Author | SHA1 | Date | |
|---|---|---|---|
| 9779437c00 | |||
| 1a37926628 | |||
| dac9a7c756 | |||
| 9ac1261ed0 | |||
| 9b69d3f728 | |||
| a5de879260 | |||
| 6464e1cbc6 | |||
| 7f3a94229a | |||
| 395e0117fb | |||
| e04d363e42 | |||
| 3b6c0d4a70 | |||
| d1f6ccd9cb | |||
| 74f7ba41df | |||
| 4fb424faa8 | |||
| 63218e7f42 | |||
| 7f0bb3cae7 | |||
| ad7417c233 | |||
| cf0be2336b | |||
| 6e08746611 | |||
| 7eb26facaf | |||
| 9115cc662c | |||
| 9e7c1dbfb2 | |||
| e99f5d2e52 | |||
| 039d1ca993 | |||
| dd9ac3c481 | |||
| 4f789080e7 | |||
| 80fc858a35 | |||
| 6f8d280657 | |||
| 5782cbc166 | |||
| 0729d2ac41 | |||
| 6c6de0ba86 | |||
| 11dbcaf80c | |||
| 95592e542f | |||
| 472bdec4fa | |||
| c7a313e9ed | |||
| c14b590083 | |||
| 040c920481 | |||
| 8c63817950 | |||
| e2f43d398f | |||
| 7ba4829066 | |||
| 938999db91 | |||
| 0b60a8e41b | |||
| 817a43e849 | |||
| 047296329e | |||
| c8cb74f3d4 | |||
| aceb6cb6b5 | |||
| 9fd1bc9dff | |||
| 04391f1c6e | |||
| e2bf42e66b | |||
| 0c72ca9294 | |||
| 2985fad77c | |||
| 02b5fb4d0e | |||
| bf417c163c | |||
| b35974e455 | |||
| 6d0abf865e | |||
| 275af9be82 | |||
| f4e44a1975 | |||
| 81f322b616 | |||
| f094ef57ec | |||
| 2e32d8f6e5 | |||
| 3e352f270d | |||
| 45056e8ff4 | |||
| b13abe51bf | |||
| c3513427de | |||
| 7a6b6882d2 | |||
| d6ec34cef9 | |||
| 84dfdd707a | |||
| 517a239485 | |||
| 47868051f8 | |||
| 96e4e9df66 | |||
| 7d510e4028 | |||
| 6760b29148 | |||
| 122063b1d5 | |||
| b304c3a175 | |||
| 5b89d73c20 | |||
| 8380dda25a | |||
| 7839116134 | |||
| b3a809ab1c | |||
| 3a0e58c3da | |||
| 26433c9020 | |||
| 6dbf84f401 | |||
| 3220ff728f |
3
Gemfile
3
Gemfile
@@ -1,8 +1,9 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'quickbooks-ruby'
|
||||
gem 'oauth2', '1.4.7'
|
||||
gem 'oauth2'
|
||||
gem 'roxml'
|
||||
gem 'nhtsa_vin'
|
||||
gem 'will_paginate'
|
||||
gem 'rails-jquery-autocomplete'
|
||||
gem 'jquery-ui-rails'
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
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
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -8,7 +8,10 @@ The goal of this project is to allow Redmine to connect with Quickbooks Online t
|
||||
|
||||
Note: Although the core functionality is complete, this project is still under development & the master branch may be unstable. Tags should be stable and are recommended
|
||||
|
||||
Use tags Version 1.0.0+ for Redmine 4+ and Version 0.8.1 for Redine 3
|
||||
Use tags for the following Redmine Versions
|
||||
* Version 2.0.0+ for Redmine 5+
|
||||
* Version 1.0.0+ for Redmine 4+
|
||||
* Version 0.8.1 for Redine 3
|
||||
|
||||
#### Features
|
||||
* Issues can be assigned to a Customer via drop down in the edit Issue form
|
||||
@@ -62,6 +65,7 @@ Note: After the inital synchronization, this plugin will recieve push notificati
|
||||
|
||||
## TODO
|
||||
* 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...
|
||||
|
||||
## License
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
# This controller class will handle map management
|
||||
class CustomersController < ApplicationController
|
||||
unloadable
|
||||
|
||||
include AuthHelper
|
||||
helper :issues
|
||||
@@ -36,7 +35,13 @@ class CustomersController < ApplicationController
|
||||
autocomplete :customer, :name, :full => true, :extra_data => [:id]
|
||||
|
||||
def allowed_params
|
||||
params.require(:customer).permit(:name, :email, :primary_phone, :mobile_phone, :phone_number)
|
||||
params.require(:customer).permit(:name, :email, :primary_phone, :mobile_phone, :phone_number, :notes)
|
||||
end
|
||||
|
||||
# getter method for a customer's vehicles
|
||||
# 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
|
||||
@@ -82,6 +87,7 @@ class CustomersController < ApplicationController
|
||||
def show
|
||||
begin
|
||||
@customer = Customer.find_by_id(params[:id])
|
||||
@vehicles = @customer.vehicles.paginate(:page => params[:page])
|
||||
@issues = @customer.issues.order(id: :desc)
|
||||
@billing_address = address_to_s(@customer.billing_address)
|
||||
@shipping_address = address_to_s(@customer.shipping_address)
|
||||
@@ -108,7 +114,7 @@ class CustomersController < ApplicationController
|
||||
def update
|
||||
begin
|
||||
@customer = Customer.find_by_id(params[:id])
|
||||
if @customer.update_attributes(allowed_params)
|
||||
if @customer.update(allowed_params)
|
||||
flash[:notice] = "Customer updated"
|
||||
redirect_to @customer
|
||||
else
|
||||
@@ -135,7 +141,7 @@ class CustomersController < ApplicationController
|
||||
def share
|
||||
|
||||
Thread.new do
|
||||
logger.debug "Removing expired customer tokens"
|
||||
logger.info "Removing expired customer tokens"
|
||||
CustomerToken.remove_expired_tokens
|
||||
ActiveRecord::Base.connection.close
|
||||
end
|
||||
@@ -211,14 +217,14 @@ class CustomersController < ApplicationController
|
||||
# format a quickbooks address to a human readable string
|
||||
def address_to_s (address)
|
||||
return if address.nil?
|
||||
string = address.line1
|
||||
string = address.line1 if address.line1
|
||||
string << "\n" + address.line2 if address.line2
|
||||
string << "\n" + address.line3 if address.line3
|
||||
string << "\n" + address.line4 if address.line4
|
||||
string << "\n" + address.line5 if address.line5
|
||||
string << " " + address.city
|
||||
string << ", " + address.country_sub_division_code
|
||||
string << " " + address.postal_code
|
||||
string << " " + address.city if address.city
|
||||
string << ", " + address.country_sub_division_code if address.country_sub_division_code
|
||||
string << " " + address.postal_code if address.postal_code
|
||||
return string
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -8,7 +8,6 @@
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
class EstimateController < ApplicationController
|
||||
unloadable
|
||||
|
||||
include AuthHelper
|
||||
|
||||
@@ -16,6 +15,15 @@ class EstimateController < ApplicationController
|
||||
skip_before_action :verify_authenticity_token, :check_if_login_required, :unless => proc {|c| session[:token].nil? }
|
||||
|
||||
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_doc_number(params[:search]) if params[:search]
|
||||
return estimate
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -8,7 +8,6 @@
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
class InvoiceController < ApplicationController
|
||||
unloadable
|
||||
|
||||
include AuthHelper
|
||||
|
||||
@@ -20,10 +19,13 @@ class InvoiceController < ApplicationController
|
||||
#
|
||||
def show
|
||||
begin
|
||||
base = Invoice.get_base
|
||||
invoice = base.fetch_by_id(params[:id])
|
||||
@pdf = base.pdf(invoice)
|
||||
send_data @pdf, filename: "invoice #{invoice.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf"
|
||||
qbo = Qbo.first
|
||||
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(params[:id])
|
||||
@pdf = service.pdf(invoice)
|
||||
send_data @pdf, filename: "invoice #{invoice.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf"
|
||||
end
|
||||
rescue
|
||||
redirect_to :back, :flash => { :error => "Invoice not found" }
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -9,7 +9,6 @@
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
class QboController < ApplicationController
|
||||
unloadable
|
||||
|
||||
require 'openssl'
|
||||
|
||||
@@ -26,9 +25,10 @@ class QboController < ApplicationController
|
||||
# Called when the user requests that Redmine to connect to QBO
|
||||
#
|
||||
def authenticate
|
||||
oauth2_client = Qbo.get_client
|
||||
callback = Setting.host_name + "/qbo/oauth_callback/"
|
||||
grant_url = oauth2_client.auth_code.authorize_url(redirect_uri: callback, response_type: "code", state: SecureRandom.hex(12), scope: "com.intuit.quickbooks.accounting")
|
||||
redirect_uri = "https://" + Setting.host_name + qbo_oauth_callback_path
|
||||
logger.info "redirect_uri: " + redirect_uri
|
||||
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
|
||||
end
|
||||
|
||||
@@ -37,9 +37,9 @@ class QboController < ApplicationController
|
||||
#
|
||||
def oauth_callback
|
||||
if params[:state].present?
|
||||
oauth2_client = Qbo.get_client
|
||||
oauth2_client = Qbo.construct_oauth2_client
|
||||
# use the state value to retrieve from your backend any information you need to identify the customer in your system
|
||||
redirect_uri = Setting.host_name + "/qbo/oauth_callback/"
|
||||
redirect_uri = "https://" + Setting.host_name + qbo_oauth_callback_path
|
||||
if resp = oauth2_client.auth_code.get_token(params[:code], redirect_uri: redirect_uri)
|
||||
|
||||
# Remove the last authentication information
|
||||
@@ -47,12 +47,8 @@ class QboController < ApplicationController
|
||||
|
||||
# Save the authentication information
|
||||
qbo = Qbo.new
|
||||
qbo.company_id = params[:realmId]
|
||||
|
||||
# Generate Access Token & Serialize it into the database
|
||||
access_token = OAuth2::AccessToken.new(oauth2_client, resp.token, refresh_token: resp.refresh_token)
|
||||
qbo.token = access_token.to_hash
|
||||
qbo.expire = 1.hour.from_now.utc
|
||||
qbo.update(oauth2_access_token: resp.token, oauth2_refresh_token: resp.refresh_token, realm_id: params[:realmId])
|
||||
qbo.refresh_token!
|
||||
|
||||
if qbo.save!
|
||||
redirect_to qbo_sync_path, :flash => { :notice => "Successfully connected to Quickbooks" }
|
||||
@@ -88,46 +84,48 @@ class QboController < ApplicationController
|
||||
|
||||
# proceed if the request is good
|
||||
if hash.eql? signature
|
||||
if request.headers['content-type'] == 'application/json'
|
||||
data = JSON.parse(data)
|
||||
else
|
||||
# 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!
|
||||
Thread.new do
|
||||
if request.headers['content-type'] == 'application/json'
|
||||
data = JSON.parse(data)
|
||||
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")
|
||||
# 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.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
|
||||
|
||||
# Record that last time we updated
|
||||
Qbo.update_time_stamp
|
||||
ActiveRecord::Base.connection.close
|
||||
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
|
||||
render :nothing => true
|
||||
render :nothing => true, status: 200
|
||||
else
|
||||
render nothing: true, status: 400
|
||||
end
|
||||
@@ -145,7 +143,6 @@ class QboController < ApplicationController
|
||||
if Qbo.exists?
|
||||
Customer.sync
|
||||
Invoice.sync
|
||||
QboItem.sync
|
||||
Employee.sync
|
||||
Estimate.sync
|
||||
|
||||
@@ -155,6 +152,6 @@ class QboController < ApplicationController
|
||||
ActiveRecord::Base.connection.close
|
||||
end
|
||||
|
||||
redirect_to :home, :flash => { :notice => "Successfully synced to Quickbooks" }
|
||||
redirect_to :home, :flash => { :notice => "Syncing Quickbooks" }
|
||||
end
|
||||
end
|
||||
|
||||
125
app/controllers/vehicles_controller.rb
Normal file
125
app/controllers/vehicles_controller.rb
Normal file
@@ -0,0 +1,125 @@
|
||||
#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
|
||||
@@ -13,7 +13,7 @@ module AuthHelper
|
||||
def require_user
|
||||
return unless session[:token].nil?
|
||||
if !User.current.logged?
|
||||
render :file => "public/401.html.erb", :status => :unauthorized, :layout =>true
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,14 +27,14 @@ module AuthHelper
|
||||
|
||||
def check_permission(permission)
|
||||
if !allowed_to?(permission)
|
||||
render :file => "public/401.html.erb", :status => :unauthorized, :layout =>true
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def global_check_permission(permission)
|
||||
if !globaly_allowed_to?(permission)
|
||||
render :file => "public/401.html.erb", :status => :unauthorized, :layout =>true
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
83
app/models/concerns/quickbooks_oauth.rb
Normal file
83
app/models/concerns/quickbooks_oauth.rb
Normal file
@@ -0,0 +1,83 @@
|
||||
#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.error("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!
|
||||
Rails.logger.info("QuickbooksOauth.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
|
||||
|
||||
Rails.logger.info("QuickbooksOauth.refresh_token!: #{oauth2_refresh_token_expires_at}")
|
||||
|
||||
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
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -9,20 +9,20 @@
|
||||
#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
|
||||
unloadable
|
||||
|
||||
has_many :issues
|
||||
has_many :purchases
|
||||
has_many :invoices
|
||||
has_many :estimates
|
||||
|
||||
has_many :vehicles
|
||||
|
||||
validates_presence_of :id, :name
|
||||
|
||||
self.primary_key = :id
|
||||
|
||||
# returns a human readable string
|
||||
def to_s
|
||||
return name
|
||||
return "#{self[:name]} - #{phone_number.split(//).last(4).join unless phone_number.nil?}"
|
||||
end
|
||||
|
||||
# Convenience Method
|
||||
@@ -86,6 +86,13 @@ class Customer < ActiveRecord::Base
|
||||
#update our locally stored number too
|
||||
update_mobile_phone_number
|
||||
end
|
||||
|
||||
# Convenience Method
|
||||
# Sets the notes
|
||||
def notes=(s)
|
||||
pull unless @details
|
||||
@details.notes = s
|
||||
end
|
||||
|
||||
# update the localy stored phone number as a plain string with no special chars
|
||||
def update_phone_number
|
||||
@@ -134,28 +141,28 @@ class Customer < ActiveRecord::Base
|
||||
# proforms a bruteforce sync operation
|
||||
# This needs to be simplified
|
||||
def self.sync
|
||||
service = Qbo.get_base(:customer)
|
||||
|
||||
# Sync ALL customers if the database is empty
|
||||
#if count == 0
|
||||
customers = service.all
|
||||
#else
|
||||
# last = Qbo.first.last_sync
|
||||
# query = "Select Id, DisplayName From Customer"
|
||||
# query << " Where Metadata.LastUpdatedTime >= '#{last.iso8601}' " if last
|
||||
# customers = service.query(query)
|
||||
#end
|
||||
qbo = Qbo.first
|
||||
customers = qbo.perform_authenticated_request do |access_token|
|
||||
service = Quickbooks::Service::Customer.new(:company_id => qbo.realm_id, :access_token => access_token)
|
||||
service.all
|
||||
end
|
||||
|
||||
customers.each do |customer|
|
||||
customer = Customer.find_or_create_by(id: customer.id)
|
||||
if customer.active?
|
||||
if not customer.name.eql? customer.display_name
|
||||
customer.name = customer.display_name
|
||||
customer.id = customer.id
|
||||
return unless customers
|
||||
|
||||
customers.each do |c|
|
||||
logger.info "Processing customer #{c.id}"
|
||||
customer = Customer.find_or_create_by(id: c.id)
|
||||
if c.active?
|
||||
#if not customer.name.eql? c.display_name
|
||||
customer.name = c.display_name
|
||||
customer.id = c.id
|
||||
customer.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
|
||||
end
|
||||
#end
|
||||
else
|
||||
if not customer.new_record?
|
||||
if not c.new_record?
|
||||
customer.delete
|
||||
end
|
||||
end
|
||||
@@ -171,16 +178,23 @@ class Customer < ActiveRecord::Base
|
||||
# proforms a bruteforce sync operation
|
||||
# This needs to be simplified
|
||||
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)
|
||||
customer = Customer.find_or_create_by(id: customer.id)
|
||||
if customer.active?
|
||||
if not customer.name.eql? customer.display_name
|
||||
customer.name = customer.display_name
|
||||
customer.id = customer.id
|
||||
return unless c
|
||||
|
||||
customer = Customer.find_or_create_by(id: c.id)
|
||||
if c.active?
|
||||
#if not customer.name.eql? c.display_name
|
||||
customer.name = c.display_name
|
||||
customer.id = c.id
|
||||
customer.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
|
||||
end
|
||||
#end
|
||||
else
|
||||
if not customer.new_record?
|
||||
customer.delete
|
||||
@@ -191,7 +205,11 @@ class Customer < ActiveRecord::Base
|
||||
# Push the updates
|
||||
def save_with_push
|
||||
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?
|
||||
self.id = @details.id
|
||||
rescue Exception => e
|
||||
@@ -209,7 +227,11 @@ class Customer < ActiveRecord::Base
|
||||
def pull
|
||||
begin
|
||||
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
|
||||
@details = Quickbooks::Model::Customer.new
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -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.
|
||||
|
||||
class CustomerToken < ActiveRecord::Base
|
||||
unloadable
|
||||
|
||||
has_many :issues
|
||||
validates_presence_of :issue_id
|
||||
before_create :generate_token, :generate_expire_date
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -9,30 +9,39 @@
|
||||
#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
|
||||
unloadable
|
||||
|
||||
has_many :users
|
||||
validates_presence_of :id, :name
|
||||
|
||||
def self.get_base
|
||||
Qbo.get_base(:employee)
|
||||
end
|
||||
|
||||
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
|
||||
# Update the item table
|
||||
employees.each { |employee|
|
||||
employee = find_or_create_by(id: employee.id)
|
||||
employee.name = employee.display_name
|
||||
employee.id = employee.id
|
||||
employees.each { |e|
|
||||
logger.info "Processing employee #{e.id}"
|
||||
employee = find_or_create_by(id: e.id)
|
||||
employee.name = e.display_name
|
||||
employee.id = e.id
|
||||
employee.save!
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
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.name = employee.display_name
|
||||
employee.id = employee.id
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -9,22 +9,23 @@
|
||||
#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
|
||||
unloadable
|
||||
|
||||
has_and_belongs_to_many :issues
|
||||
belongs_to :customer
|
||||
validates_presence_of :doc_number, :id
|
||||
self.primary_key = :id
|
||||
|
||||
# return the QBO Estimate service
|
||||
def self.get_base
|
||||
Qbo.get_base(:estimate)
|
||||
end
|
||||
|
||||
# sync all estimates
|
||||
def self.sync
|
||||
logger.debug "Syncing ALL estimates"
|
||||
estimates = get_base.all
|
||||
logger.info "Syncing ALL estimates"
|
||||
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|
|
||||
process_estimate(estimate)
|
||||
}
|
||||
@@ -35,36 +36,60 @@ class Estimate < ActiveRecord::Base
|
||||
|
||||
# sync only one estimate
|
||||
def self.sync_by_id(id)
|
||||
logger.debug "Syncing estimate #{id}"
|
||||
process_estimate(get_base.fetch_by_id(id))
|
||||
logger.info "Syncing estimate #{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
|
||||
|
||||
# update an estimate
|
||||
def self.update(id)
|
||||
# Update the item table
|
||||
estimate = get_base.fetch_by_id(id)
|
||||
estimate = find_or_create_by(id: id)
|
||||
estimate.doc_number = estimate.doc_number
|
||||
estimate.txn_date = estimate.txn_date
|
||||
estimate.save!
|
||||
qbo = Qbo.first
|
||||
estimate = qbo.perform_authenticated_request do |access_token|
|
||||
service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token)
|
||||
service.fetch_by_id(id)
|
||||
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
|
||||
|
||||
# process an estimate into the database
|
||||
def self.process_estimate(estimate)
|
||||
logger.info "Processing estimate #{estimate.id}"
|
||||
estimate = find_or_create_by(id: estimate.id)
|
||||
estimate.doc_number = estimate.doc_number
|
||||
estimate.customer_id = estimate.customer_ref.value
|
||||
estimate.id = estimate.id
|
||||
estimate.txn_date = estimate.txn_date
|
||||
def self.process_estimate(qbo_estimate)
|
||||
logger.info "Processing estimate #{qbo_estimate.id}"
|
||||
estimate = find_or_create_by(id: qbo_estimate.id)
|
||||
estimate.doc_number = qbo_estimate.doc_number
|
||||
estimate.customer_id = qbo_estimate.customer_ref.value
|
||||
estimate.id = qbo_estimate.id
|
||||
estimate.txn_date = qbo_estimate.txn_date
|
||||
estimate.save!
|
||||
end
|
||||
|
||||
# download the pdf from quickbooks
|
||||
def pdf
|
||||
base = Estimate.get_base
|
||||
estimate = base.fetch_by_id(id)
|
||||
return base.pdf(estimate)
|
||||
qbo = Qbo.first
|
||||
qbo.perform_authenticated_request do |access_token|
|
||||
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
|
||||
|
||||
# Magic Method
|
||||
@@ -91,7 +116,11 @@ class Estimate < ActiveRecord::Base
|
||||
def pull
|
||||
begin
|
||||
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
|
||||
@details = Quickbooks::Model::Estimate.new
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -9,20 +9,15 @@
|
||||
#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
|
||||
unloadable
|
||||
|
||||
has_and_belongs_to_many :issues
|
||||
belongs_to :customer
|
||||
validates_presence_of :doc_number, :id, :customer_id, :txn_date
|
||||
self.primary_key = :id
|
||||
|
||||
# Get the quickbooks-ruby base for invoice
|
||||
def self.get_base
|
||||
Qbo.get_base(:invoice)
|
||||
end
|
||||
|
||||
# sync ALL the invoices
|
||||
def self.sync
|
||||
logger.debug "Syncing all invoices"
|
||||
logger.info "Syncing all invoices"
|
||||
last = Qbo.first.last_sync
|
||||
|
||||
query = "SELECT Id, DocNumber FROM Invoice"
|
||||
@@ -30,11 +25,13 @@ class Invoice < ActiveRecord::Base
|
||||
|
||||
# TODO actually do something with the above query
|
||||
# .all() is never called since count is never initialized
|
||||
if count == 0
|
||||
invoices = get_base.all
|
||||
else
|
||||
invoices = get_base.query()
|
||||
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 |
|
||||
process_invoice invoice
|
||||
@@ -43,9 +40,13 @@ class Invoice < ActiveRecord::Base
|
||||
|
||||
#sync by invoice ID
|
||||
def self.sync_by_id(id)
|
||||
logger.debug "Syncing invoice #{id}"
|
||||
invoice = get_base.fetch_by_id(id)
|
||||
process_invoice invoice
|
||||
logger.info "Syncing invoice #{id}"
|
||||
qbo = Qbo.first
|
||||
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
|
||||
|
||||
private
|
||||
@@ -57,7 +58,7 @@ class Invoice < ActiveRecord::Base
|
||||
# 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
|
||||
|
||||
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)
|
||||
|
||||
@@ -104,43 +105,62 @@ class Invoice < ActiveRecord::Base
|
||||
# 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
|
||||
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
|
||||
is_changed = false
|
||||
|
||||
logger.debug "Calling :process_invoice_custom_fields hook"
|
||||
context = Redmine::Hook.call_hook :process_invoice_custom_fields, { issue: issue, invoice: invoice }
|
||||
|
||||
unless context.nil?
|
||||
logger.debug "We have a context!"
|
||||
context= context.first
|
||||
issue = context[:issue]
|
||||
invoice = context[:invoice]
|
||||
is_changed = context[:is_changed]
|
||||
end
|
||||
|
||||
# update the invoive custom fields with infomation from the issue if available
|
||||
invoice.custom_fields.each { |cf|
|
||||
|
||||
# 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
|
||||
# VIN from the attached vehicle
|
||||
# TODO move this into seperate plugin
|
||||
# TODO create hook for seperate plugin
|
||||
begin
|
||||
if cf.name.eql? "VIN"
|
||||
# Only update if blank to prevent infite loops
|
||||
# TODO check cf_sync_confict flag once implemented
|
||||
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
|
||||
end
|
||||
rescue
|
||||
#do nothing
|
||||
end
|
||||
rescue
|
||||
# Nothing to do here, there is no match
|
||||
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
|
||||
# Nothing to do here, there is no match
|
||||
end
|
||||
}
|
||||
|
||||
# Push updates
|
||||
begin
|
||||
logger.debug "Trying to update invoice"
|
||||
get_base.update(invoice) if is_changed
|
||||
logger.info "Trying to update invoice"
|
||||
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
|
||||
# Do nothing, probaly custome field sync confict on the invoice.
|
||||
# This is a problem with how it's billed
|
||||
@@ -172,7 +192,11 @@ class Invoice < ActiveRecord::Base
|
||||
def pull
|
||||
begin
|
||||
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
|
||||
@details = Quickbooks::Model::Invoice.new
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -9,86 +9,15 @@
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
class Qbo < ActiveRecord::Base
|
||||
unloadable
|
||||
validates_presence_of :token, :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
|
||||
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
|
||||
include QuickbooksOauth
|
||||
|
||||
# Updates last sync time stamp
|
||||
def self.update_time_stamp
|
||||
date = DateTime.now
|
||||
logger.info "Updating QBO timestamp to #{date}"
|
||||
qbo = Qbo.first
|
||||
qbo.last_sync = DateTime.now
|
||||
qbo.last_sync = date
|
||||
qbo.save
|
||||
end
|
||||
|
||||
|
||||
98
app/models/vehicle.rb
Normal file
98
app/models/vehicle.rb
Normal file
@@ -0,0 +1,98 @@
|
||||
#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
|
||||
11
app/views/customers/_actions.html.erb
Normal file
11
app/views/customers/_actions.html.erb
Normal file
@@ -0,0 +1,11 @@
|
||||
<%= 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%>
|
||||
@@ -1,5 +1,11 @@
|
||||
<table>
|
||||
<tbody>
|
||||
|
||||
<tr>
|
||||
<th><%=t(:label_name)%></th>
|
||||
<td><%= customer.name %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><%=t(:label_email)%></th>
|
||||
<td><%= customer.email %></td>
|
||||
@@ -35,9 +41,6 @@
|
||||
<td><%= customer.notes %></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div style="float: right;">
|
||||
<%= button_to t(:label_edit_customer), edit_customer_path(customer), method: :get%>
|
||||
</div>
|
||||
</table>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
@@ -3,4 +3,3 @@
|
||||
<%= submit_tag t(:label_search) %>
|
||||
<% end %>
|
||||
<%= 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?%>
|
||||
|
||||
1
app/views/customers/filter_vehicles_by_customer.js.erb
Normal file
1
app/views/customers/filter_vehicles_by_customer.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$('select#issue_vehicles_id').html('<%= j content_tag(:option,'',:value=>"")+options_from_collection_for_select(@filtered_vehicles, :id, :to_s) %>');
|
||||
@@ -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="splitcontent">
|
||||
@@ -7,7 +7,22 @@
|
||||
|
||||
<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="splitcontentleft">
|
||||
@@ -24,7 +39,11 @@
|
||||
</div>
|
||||
|
||||
<div class="splitcontentleft">
|
||||
<%= call_hook :show_customer_view_right, {customer: @customer} %>
|
||||
<h4><%=t(:field_vehicles)%>:</h4>
|
||||
<%= render :partial => 'vehicles/list' %>
|
||||
<div style="float: right;">
|
||||
<%= button_to "New Vehicle", new_customer_vehicle_path(@customer), method: :get %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<% if @customer.present? %>
|
||||
|
||||
<% @customer.estimates.order(doc_number: :desc).each do |estimate| %>
|
||||
<% @customer.estimates.order(id: :desc).each do |estimate| %>
|
||||
<div class="row">
|
||||
<b><%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %></b> <%= estimate.txn_date %>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<% if @customer.present? %>
|
||||
|
||||
<% @customer.invoices.order(doc_number: :desc).each do |invoice| %>
|
||||
<% @customer.invoices.order(id: :desc).each do |invoice| %>
|
||||
<div class="row">
|
||||
<b><%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %></b> <%= invoice.txn_date %>
|
||||
</div>
|
||||
|
||||
@@ -8,3 +8,7 @@
|
||||
<p>
|
||||
<%= select_estimate %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= vehicle %>
|
||||
</p>
|
||||
@@ -17,6 +17,19 @@
|
||||
</div>
|
||||
|
||||
<div class="splitcontentleft">
|
||||
<%= call_hook :show_issue_view_right, {issue: issue} %>
|
||||
<div class="vehicle attribute">
|
||||
<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>
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
<%= flash.now[:error] = t(:label_401) %>
|
||||
@@ -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 -->
|
||||
<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>
|
||||
|
||||
<table >
|
||||
@@ -58,8 +58,13 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><%=t(:label_oauth_expires)%></th>
|
||||
<td><%= if Qbo.exists? then Qbo.first.expire end %>
|
||||
<th><%=t(:label_oauth_expires)%></th>
|
||||
<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>
|
||||
|
||||
</tbody>
|
||||
|
||||
13
app/views/qbo/webhook.erb
Normal file
13
app/views/qbo/webhook.erb
Normal 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>
|
||||
45
app/views/vehicles/_details.html.erb
Normal file
45
app/views/vehicles/_details.html.erb
Normal file
@@ -0,0 +1,45 @@
|
||||
<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>
|
||||
56
app/views/vehicles/_form.html.erb
Normal file
56
app/views/vehicles/_form.html.erb
Normal file
@@ -0,0 +1,56 @@
|
||||
<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>
|
||||
28
app/views/vehicles/_list.html.erb
Normal file
28
app/views/vehicles/_list.html.erb
Normal file
@@ -0,0 +1,28 @@
|
||||
<% 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 %>
|
||||
4
app/views/vehicles/_search.html.erb
Normal file
4
app/views/vehicles/_search.html.erb
Normal file
@@ -0,0 +1,4 @@
|
||||
<%= 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 %>
|
||||
1
app/views/vehicles/_vehicle.html.erb
Normal file
1
app/views/vehicles/_vehicle.html.erb
Normal file
@@ -0,0 +1 @@
|
||||
<option value="<%= vehicle.id %>"><%= vehicle.to_s.titleize %></option>
|
||||
3
app/views/vehicles/edit.html.erb
Normal file
3
app/views/vehicles/edit.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<h1><%=t(:label_edit_customer_vehicle)%></h1>
|
||||
<br/>
|
||||
<%= render :partial => 'vehicles/form' %>
|
||||
4
app/views/vehicles/index.html.erb
Normal file
4
app/views/vehicles/index.html.erb
Normal file
@@ -0,0 +1,4 @@
|
||||
<h2><%=t(:label_cusomer_vehicles)%> <span style="float:right"> <%= render :partial => 'vehicles/search' %> </span> </h2>
|
||||
<br/>
|
||||
|
||||
<%= render :partial => 'vehicles/list' %>
|
||||
3
app/views/vehicles/new.html.erb
Normal file
3
app/views/vehicles/new.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<h2><%=t(:label_new_vehicle)%></h2>
|
||||
<br/>
|
||||
<%= render :partial => 'vehicles/form' %>
|
||||
11
app/views/vehicles/show.html.erb
Normal file
11
app/views/vehicles/show.html.erb
Normal file
@@ -0,0 +1,11 @@
|
||||
<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)} %>
|
||||
@@ -1,5 +1,10 @@
|
||||
$(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({
|
||||
url: "/filter_estimates_by_customer",
|
||||
@@ -8,4 +13,11 @@ $(function() {
|
||||
});
|
||||
});
|
||||
|
||||
$("input#project_customer_id").on("change", function() {
|
||||
$.ajax({
|
||||
url: "/filter_vehicles_by_customer",
|
||||
type: "GET",
|
||||
data: { selected_customer: $("input#project_customer_id").val() }
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,21 +16,28 @@ en:
|
||||
field_employee: "Employee"
|
||||
field_invoice: "Invoice"
|
||||
field_estimate: "Estimate"
|
||||
field_vehicles: "Vehicles"
|
||||
field_vehicle: "Vehicle"
|
||||
field_vin: "VIN"
|
||||
field_notes: "Notes"
|
||||
field_billed: "Billed"
|
||||
label_week: "Week"
|
||||
label_search_estimates: "Search Estimates"
|
||||
label_search: "Search"
|
||||
label_estimates: "Estimates"
|
||||
label_401: "Not Authorized"
|
||||
warn_ru_sure: "You sure?"
|
||||
label_delete: "Delete"
|
||||
label_edit: "Edit"
|
||||
label_year: "Year"
|
||||
label_make: " Make"
|
||||
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_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_closed_issues: "Closed Issues"
|
||||
label_sync: "Sync"
|
||||
@@ -80,4 +87,8 @@ en:
|
||||
label_billing_error: "Cannot bill without a customer assigned"
|
||||
label_qbo_sync_success: "Successfully synced to Quickbooks"
|
||||
label_hours: "Hours"
|
||||
|
||||
label_oauth2_refresh_token_expires_at: "Refresh Token Expires At"
|
||||
label_name: "Name"
|
||||
label_appointment: "Add Appointment"
|
||||
label_actions: "Actions"
|
||||
label_create_estimate: "Create Estimate"
|
||||
|
||||
@@ -31,9 +31,15 @@ get 'customers/view/:token', :to => 'customers#view', as: :view
|
||||
get 'customers/share/:id', :to => 'customers#share', as: :share
|
||||
|
||||
#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_invoices_by_customer' => 'customers#filter_invoices_by_customer'
|
||||
|
||||
# Nest Vehicles under customers
|
||||
resources :customers do
|
||||
resources :vehicles
|
||||
get :autocomplete_customer_name, :on => :collection
|
||||
end
|
||||
|
||||
#allow for just vehicles too
|
||||
resources :vehicles
|
||||
|
||||
24
db/migrate/016_create_vehicles.rb
Normal file
24
db/migrate/016_create_vehicles.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
#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
|
||||
15
db/migrate/017_update_issues_with_vehicles.rb
Normal file
15
db/migrate/017_update_issues_with_vehicles.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
#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
|
||||
15
db/migrate/018_update_vehicles.rb
Normal file
15
db/migrate/018_update_vehicles.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
#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
|
||||
@@ -12,5 +12,6 @@ class QbocustomersToCustomers< ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
rename_table :qbo_customers, :customers
|
||||
rename_column :issues, :qbo_customer_id, :customer_id
|
||||
rename_column :vehicles, :qbo_customer_id, :customer_id
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,5 +11,6 @@
|
||||
class UpdateProjects < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
add_reference :projects, :customer, index: true
|
||||
add_reference :projects, :vehicle, index: true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -9,35 +9,46 @@
|
||||
#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]
|
||||
|
||||
def change
|
||||
add_column :qbo_invoices, :txn_date, :date
|
||||
add_column :qbo_estimates, :txn_date, :date
|
||||
begin
|
||||
add_column :qbo_invoices, :txn_date, :date
|
||||
add_column :qbo_estimates, :txn_date, :date
|
||||
|
||||
reversible do |direction|
|
||||
direction.up {
|
||||
break unless Qbo.first
|
||||
reversible do |direction|
|
||||
direction.up {
|
||||
break unless Qbo.first
|
||||
|
||||
QboEstimate.reset_column_information
|
||||
QboInvoice.reset_column_information
|
||||
QboEstimate.reset_column_information
|
||||
QboInvoice.reset_column_information
|
||||
|
||||
say "Sync Estimates"
|
||||
say "Sync Estimates"
|
||||
|
||||
QboEstimate.sync
|
||||
QboEstimate.sync
|
||||
|
||||
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
|
||||
|
||||
invoices.each { |invoice|
|
||||
# Load the invoice into the database
|
||||
qbo_invoice = QboInvoice.find_or_create_by(id: invoice.id)
|
||||
qbo_invoice.doc_number = invoice.doc_number
|
||||
qbo_invoice.id = invoice.id
|
||||
qbo_invoice.customer_id = invoice.customer_ref
|
||||
qbo_invoice.txn_date = invoice.txn_date
|
||||
qbo_invoice.save!
|
||||
return unless invoices
|
||||
|
||||
invoices.each { |invoice|
|
||||
# Load the invoice into the database
|
||||
qbo_invoice = QboInvoice.find_or_create_by(id: invoice.id)
|
||||
qbo_invoice.doc_number = invoice.doc_number
|
||||
qbo_invoice.id = invoice.id
|
||||
qbo_invoice.customer_id = invoice.customer_ref
|
||||
qbo_invoice.txn_date = invoice.txn_date
|
||||
qbo_invoice.save!
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
rescue
|
||||
logger.error "AddTxnDates Failed"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
33
db/migrate/033_update_vehicles_trim.rb
Normal file
33
db/migrate/033_update_vehicles_trim.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
#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
|
||||
22
db/migrate/037_update_qbo_token.rb
Normal file
22
db/migrate/037_update_qbo_token.rb
Normal 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
|
||||
22
init.rb
22
init.rb
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#Copyright (c) 2023 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
@@ -19,26 +19,28 @@ end
|
||||
Redmine::Plugin.register :redmine_qbo do
|
||||
|
||||
# About
|
||||
name 'Redmine QBO DEVELOPMENT plugin'
|
||||
name 'Redmine Quickbooks Online plugin'
|
||||
author 'Rick Barrette'
|
||||
description 'This is a plugin for Redmine to integrate with QuickBooks Online to allow for seamless integration CRM and invoicing of completed issues'
|
||||
version '1.1.6'
|
||||
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'
|
||||
url 'https://github.com/rickbarrette/redmine_qbo'
|
||||
author_url 'http://rickbarrette.org'
|
||||
author_url 'https://barrettefabrication.com'
|
||||
settings :default => {'empty' => true}, :partial => 'qbo/settings'
|
||||
requires_redmine :version_or_higher => '6.0.0'
|
||||
requires_redmine :version_or_higher => '5.1.0'
|
||||
|
||||
# Add safe attributes for core models
|
||||
Issue.safe_attributes 'customer_id'
|
||||
Issue.safe_attributes 'item_id'
|
||||
Issue.safe_attributes 'estimate_id'
|
||||
Issue.safe_attributes 'invoice_id'
|
||||
Issue.safe_attributes 'vehicles_id'
|
||||
User.safe_attributes 'employee_id'
|
||||
TimeEntry.safe_attributes 'billed'
|
||||
Project.safe_attributes 'customer_id'
|
||||
|
||||
Project.safe_attributes 'vehicle_id'
|
||||
|
||||
# We are playing in the sandbox
|
||||
Quickbooks.sandbox_mode = true
|
||||
#Quickbooks.sandbox_mode = true
|
||||
|
||||
# set per_page globally
|
||||
WillPaginate.per_page = 20
|
||||
@@ -46,8 +48,10 @@ Redmine::Plugin.register :redmine_qbo do
|
||||
# Permissions for security
|
||||
permission :view_customers, :customers => :index, :public => false
|
||||
permission :add_customers, :customers => :new, :public => false
|
||||
|
||||
permission :view_vehicles, :vehicles => :new, :public => false
|
||||
|
||||
# Register top menu items
|
||||
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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -15,7 +15,6 @@ module AttachmentsControllerPatch
|
||||
def self.included(base)
|
||||
|
||||
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
|
||||
def check_if_login_required
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -21,11 +21,11 @@ module IssuePatch
|
||||
|
||||
# Same as typing in the class
|
||||
base.class_eval do
|
||||
unloadable # Send unloadable so it will not be unloaded in development
|
||||
belongs_to :customer, primary_key: :id
|
||||
belongs_to :customer_token, primary_key: :id
|
||||
belongs_to :estimate, primary_key: :id
|
||||
has_and_belongs_to_many :invoices
|
||||
belongs_to :vehicle, primary_key: :id
|
||||
end
|
||||
|
||||
end
|
||||
@@ -51,46 +51,49 @@ module IssuePatch
|
||||
if spent_hours > 0 then
|
||||
|
||||
# Prepare to create a new Time Activity
|
||||
time_service = Qbo.get_base(:time_activity)
|
||||
item_service = Qbo.get_base(:item)
|
||||
time_entry = Quickbooks::Model::TimeActivity.new
|
||||
qbo = Qbo.first
|
||||
qbo.perform_authenticated_request do |access_token|
|
||||
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.
|
||||
# This will simpify the invoicing with a single billable time entry per time activity
|
||||
h = Hash.new(0)
|
||||
spent_time.each do |entry|
|
||||
h[entry.activity.name] += entry.hours
|
||||
# update time entries billed status
|
||||
entry.billed = true
|
||||
entry.save
|
||||
end
|
||||
|
||||
# Now letes upload our totals for each activity as their own billable time entry
|
||||
h.each do |key, val|
|
||||
# Lets total up each activity before billing.
|
||||
# This will simpify the invoicing with a single billable time entry per time activity
|
||||
h = Hash.new(0)
|
||||
spent_time.each do |entry|
|
||||
h[entry.activity.name] += entry.hours
|
||||
# update time entries billed status
|
||||
entry.billed = true
|
||||
entry.save
|
||||
end
|
||||
|
||||
# Convert float spent time to hours and minutes
|
||||
hours = val.to_i
|
||||
minutesDecimal = (( val - hours) * 60)
|
||||
minutes = minutesDecimal.to_i
|
||||
# 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
|
||||
hours = val.to_i
|
||||
minutesDecimal = (( val - hours) * 60)
|
||||
minutes = minutesDecimal.to_i
|
||||
|
||||
# Lets match the activity to an qbo item
|
||||
item = item_service.query("SELECT * FROM Item WHERE Name = '#{key}' ").first
|
||||
next if item.nil?
|
||||
|
||||
# Create the new billable time entry and upload it
|
||||
time_entry.description = "#{tracker} ##{id}: #{subject} #{"(Partial @ #{done_ratio}%)" if not closed?}"
|
||||
time_entry.employee_id = assigned_to.employee_id
|
||||
time_entry.customer_id = customer_id
|
||||
time_entry.billable_status = "Billable"
|
||||
time_entry.hours = hours
|
||||
time_entry.minutes = minutes
|
||||
time_entry.name_of = "Employee"
|
||||
time_entry.txn_date = Date.today
|
||||
time_entry.hourly_rate = item.unit_price
|
||||
time_entry.item_id = item.id
|
||||
time_entry.start_time = start_date
|
||||
time_entry.end_time = Time.now
|
||||
time_service.create(time_entry)
|
||||
# Lets match the activity to an qbo item
|
||||
item = item_service.query("SELECT * FROM Item WHERE Name = '#{key}' ").first
|
||||
next if item.nil?
|
||||
|
||||
# Create the new billable time entry and upload it
|
||||
time_entry.description = "#{tracker} ##{id}: #{subject} #{"(Partial @ #{done_ratio}%)" if not closed?}"
|
||||
time_entry.employee_id = assigned_to.employee_id
|
||||
time_entry.customer_id = customer_id
|
||||
time_entry.billable_status = "Billable"
|
||||
time_entry.hours = hours
|
||||
time_entry.minutes = minutes
|
||||
time_entry.name_of = "Employee"
|
||||
time_entry.txn_date = Date.today
|
||||
time_entry.hourly_rate = item.unit_price
|
||||
time_entry.item_id = item.id
|
||||
time_entry.start_time = start_date
|
||||
time_entry.end_time = Time.now
|
||||
time_service.create(time_entry)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -23,7 +23,6 @@ module IssuesControllerPatch
|
||||
def self.included(base)
|
||||
|
||||
base.class_eval do
|
||||
unloadable # Send unloadable so it will not be unloaded in development
|
||||
helper Helper
|
||||
end
|
||||
|
||||
|
||||
@@ -26,11 +26,13 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
|
||||
# This is done to preload customer information if the entire project is dedicated to a customer
|
||||
if context[:project]
|
||||
selected_customer = context[:project].customer ? context[:project].customer.id : nil
|
||||
selected_vehicle = context[:project].vehicle ? context[:project].vehicle.id : nil
|
||||
end
|
||||
|
||||
# Check to see if the issue already belongs to a customer
|
||||
selected_customer = context[:issue].customer ? context[:issue].customer.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
|
||||
customer = Customer.find_by_id(selected_customer) if selected_customer
|
||||
@@ -50,15 +52,22 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
|
||||
:id => "issue_customer_id",
|
||||
:onchange => "updateIssueFrom('/issues/#{context[:issue].id}/edit.js', this)"
|
||||
|
||||
# Load estimates
|
||||
# Load estimates & vehicles
|
||||
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}
|
||||
else
|
||||
vehicles = [nil].compact
|
||||
estimates = [nil].compact
|
||||
end
|
||||
|
||||
# Generate the drop down list of quickbooks estimates
|
||||
# Generate the drop down list of quickbooks estimates & vehicles
|
||||
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
|
||||
context[:controller].send(:render_to_string, {
|
||||
@@ -68,6 +77,7 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
|
||||
customer_id: customer_id,
|
||||
context: context,
|
||||
select_estimate: select_estimate,
|
||||
vehicle: vehicle
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -35,14 +35,27 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
|
||||
invoice_link = invoice_link.html_safe
|
||||
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, {
|
||||
:partial => 'issues/show_details',
|
||||
locals: {
|
||||
issue: issue,
|
||||
customer: customer,
|
||||
estimate_link: estimate_link,
|
||||
invoice_link: invoice_link
|
||||
invoice_link: invoice_link,
|
||||
vehicle: vehicle,
|
||||
split_vin: split_vin,
|
||||
notes: notes
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -11,15 +11,13 @@
|
||||
require_dependency 'redmine/export/pdf'
|
||||
require_dependency 'redmine/export/pdf/issues_pdf_helper'
|
||||
|
||||
module IssuesPdfHelperPatch
|
||||
module PdfPatch
|
||||
|
||||
def self.included(base)
|
||||
base.send(:include, InstanceMethods)
|
||||
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_with_patch, :issue_to_pdf
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -55,10 +53,16 @@ module IssuesPdfHelperPatch
|
||||
left << [l(:field_priority), issue.priority]
|
||||
left << [l(:field_customer), customer]
|
||||
left << [l(:field_assigned_to), issue.assigned_to] unless issue.disabled_core_fields.include?('assigned_to_id')
|
||||
|
||||
logger.debug "Calling :pdf_left hook"
|
||||
context = Redmine::Hook.call_hook :pdf_left, { array: left, issue: issue }
|
||||
left = left + context.first unless context.nil?
|
||||
#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)
|
||||
vehicle = v ? v.to_s : nil
|
||||
vin = v ? v.vin : 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 << [l(:field_start_date), format_date(issue.start_date)] unless issue.disabled_core_fields.include?('start_date')
|
||||
@@ -66,10 +70,7 @@ module IssuesPdfHelperPatch
|
||||
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(:label_spent_time), l_hours(issue.total_spent_hours)] if User.current.allowed_to?(:view_time_entries, issue.project)
|
||||
|
||||
logger.debug "Calling :pdf_right hook"
|
||||
context = Redmine::Hook.call_hook :pdf_right, { array: right, issue: issue }
|
||||
right = right + context.first unless context.nil?
|
||||
right << [l(:field_notes), notes]
|
||||
|
||||
rows = left.size > right.size ? left.size : right.size
|
||||
while left.size < rows
|
||||
@@ -253,4 +254,4 @@ module IssuesPdfHelperPatch
|
||||
end
|
||||
end
|
||||
|
||||
Redmine::Export::PDF::IssuesPdfHelper.send(:include, IssuesPdfHelperPatch)
|
||||
Redmine::Export::PDF::IssuesPdfHelper.send(:include, PdfPatch)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2017 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -21,8 +21,8 @@ module ProjectPatch
|
||||
|
||||
# Same as typing in the class
|
||||
base.class_eval do
|
||||
unloadable # Send unloadable so it will not be unloaded in development
|
||||
belongs_to :customer, primary_key: :id
|
||||
belongs_to :vehicle, primary_key: :id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,12 +16,21 @@ class ProjectsFormHookListener < Redmine::Hook::ViewListener
|
||||
|
||||
# Check to see if there is a quickbooks user attached to the issue
|
||||
selected_customer = context[:project].customer ? context[:project].customer : nil
|
||||
selected_vehicle = context[:project].vehicle_id ? context[:project].vehicle_id : nil
|
||||
|
||||
# Load customer information
|
||||
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'}
|
||||
customer_id = f.hidden_field :customer_id, :id => "project_customer_id"
|
||||
|
||||
return "<p><label for=\"project_customer\">Customer</label>#{search_customer} #{customer_id}</p>"
|
||||
if context[:project].customer
|
||||
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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -20,7 +20,6 @@ module UserPatch
|
||||
|
||||
# Same as typing in the class
|
||||
base.class_eval do
|
||||
unloadable # Send unloadable so it will not be unloaded in development
|
||||
belongs_to :employee, primary_key: :id
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user