38 Commits

Author SHA1 Message Date
a5de879260 Fixed formatting 2024-08-26 08:41:56 -04:00
6464e1cbc6 Added actions 2024-08-26 07:58:40 -04:00
7f3a94229a Create Estimate 2024-08-26 07:58:05 -04:00
395e0117fb Update _actions.html.erb 2024-08-26 07:57:10 -04:00
e04d363e42 Added label for actions 2024-08-26 07:56:06 -04:00
3b6c0d4a70 Removed Action links 2024-08-26 07:52:27 -04:00
d1f6ccd9cb Create _actions.html.erb 2024-08-26 07:51:38 -04:00
74f7ba41df Add Appointment Link 2024-08-21 21:39:50 -04:00
4fb424faa8 Only sync by doc number if not in database 2024-08-20 07:14:37 -04:00
63218e7f42 Fixed formating 2024-08-19 23:28:54 -04:00
7f0bb3cae7 Removed extra end 2024-08-19 23:26:43 -04:00
ad7417c233 Moved work into thread to repsond quickly 2024-08-19 23:21:56 -04:00
cf0be2336b Removed sync button from sidebar 2024-08-19 23:12:20 -04:00
6e08746611 2.1.1 Force Estimate sync by Doc Number when searching 2024-08-19 22:51:53 -04:00
7eb26facaf Use the first result 2024-08-19 22:49:20 -04:00
9115cc662c Forgot params[:search] 2024-08-19 22:39:50 -04:00
9e7c1dbfb2 removed () 2024-08-19 22:38:16 -04:00
e99f5d2e52 Added webhook view 2024-08-19 22:36:44 -04:00
039d1ca993 Use Logger.info 2024-08-19 22:31:41 -04:00
dd9ac3c481 Added Estimate.sync_by_doc_number 2024-08-19 22:30:34 -04:00
4f789080e7 2.1.0 Bumped wrong versoin 2024-08-19 20:18:22 -04:00
80fc858a35 send back status 200 if request succeeded 2024-08-19 20:14:02 -04:00
6f8d280657 5.2.0 FIXED QBO Authentication 2024-08-19 20:06:13 -04:00
5782cbc166 Added https 2024-08-19 20:04:09 -04:00
0729d2ac41 added https to redirect_uri 2024-08-19 20:02:22 -04:00
6c6de0ba86 Added log 2024-08-19 19:59:26 -04:00
11dbcaf80c Use Setting.host_name & path 2024-08-19 19:53:51 -04:00
95592e542f Use qbo_oauth_callback_path 2024-08-19 19:30:51 -04:00
472bdec4fa Use qbo_authenticate_path 2024-08-19 19:17:45 -04:00
c7a313e9ed Add customer name to details 2024-04-03 11:47:38 -04:00
c14b590083 2024 Copy Right Update 2024-03-29 08:10:05 -04:00
040c920481 2.0.5 2024-03-29 07:58:26 -04:00
8c63817950 Use free_form_number 2024-03-28 14:13:39 -04:00
e2f43d398f Nil Checks 2024-03-28 14:01:18 -04:00
7ba4829066 Update Customer Phone Numbers On Sync 2024-03-28 13:51:29 -04:00
938999db91 Added quickbooks to customer's name 2024-03-28 12:54:36 -04:00
0b60a8e41b 2.0.4 2024-01-07 20:53:07 -05:00
817a43e849 Fixed update 2024-01-07 20:47:26 -05:00
16 changed files with 140 additions and 70 deletions

View File

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

View File

@@ -142,7 +142,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

View File

@@ -16,6 +16,15 @@ class EstimateController < ApplicationController
skip_before_action :verify_authenticity_token, :check_if_login_required, :unless => proc {|c| session[:token].nil? }
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

View File

@@ -26,9 +26,10 @@ class QboController < ApplicationController
# Called when the user requests that Redmine to connect to QBO
#
def authenticate
redirect_uri = "https://" + Setting.host_name + qbo_oauth_callback_path
logger.info "redirect_uri: " + redirect_uri
oauth2_client = Qbo.construct_oauth2_client
callback = Setting.host_name + "/qbo/oauth_callback/"
grant_url = oauth2_client.auth_code.authorize_url(redirect_uri: callback, response_type: "code", state: SecureRandom.hex(12), scope: "com.intuit.quickbooks.accounting")
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
@@ -39,7 +40,7 @@ class QboController < ApplicationController
if params[:state].present?
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
@@ -84,46 +85,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

View File

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

View File

@@ -155,11 +155,13 @@ class Customer < ActiveRecord::Base
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
#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 c.new_record?
customer.delete
@@ -178,20 +180,22 @@ class Customer < ActiveRecord::Base
# This needs to be simplified
def self.sync_by_id(id)
qbo = Qbo.first
customer = qbo.perform_authenticated_request do |access_token|
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
return unless customer
return unless c
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
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

View File

@@ -18,7 +18,7 @@ class Estimate < ActiveRecord::Base
# sync all estimates
def self.sync
logger.debug "Syncing ALL estimates"
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)
@@ -37,13 +37,23 @@ class Estimate < ActiveRecord::Base
# sync only one estimate
def self.sync_by_id(id)
logger.debug "Syncing estimate #{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)

View File

@@ -17,7 +17,7 @@ class Invoice < ActiveRecord::Base
# 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"
@@ -40,7 +40,7 @@ class Invoice < ActiveRecord::Base
#sync by invoice ID
def self.sync_by_id(id)
logger.debug "Syncing invoice #{id}"
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)
@@ -58,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)
@@ -105,7 +105,7 @@ 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
@@ -120,12 +120,12 @@ class Invoice < ActiveRecord::Base
# Only update if blank to prevent infite loops
# TODO check cf_sync_confict flag once implemented
if cf.string_value.to_s.blank?
logger.debug " VIN was blank, updating the invoice vin in quickbooks"
logger.info " VIN was blank, updating the invoice vin in quickbooks"
vin = Vehicle.find(issue.vehicles_id).vin
break if vin.nil?
if not cf.string_value.to_s.eql? vin
cf.string_value = vin.to_s
logger.debug "VIN has changed"
logger.info "VIN has changed"
is_changed = true
end
@@ -155,7 +155,7 @@ class Invoice < ActiveRecord::Base
# Push updates
begin
logger.debug "Trying to update invoice"
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)

View File

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

View File

@@ -1,5 +1,11 @@
<table>
<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/>

View File

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

View File

@@ -1,4 +1,4 @@
<h2><%=t(:field_customer)%> #<%= @customer.id %> - <%= @customer.name %> </h2>
<h2><%=t(:field_customer)%> #<%= @customer.id %> - <%= link_to @customer.to_s, "https://app.qbo.intuit.com/app/customerdetail?nameId=#{@customer.id}", target: :_blank %> </h2>
<div class="issue">
<div class="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">

View File

@@ -15,7 +15,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
<!-- configure the Intuit object: 'grantUrl' is a URL in your application which kicks off the flow, see below -->
<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 >

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

@@ -0,0 +1,13 @@
<!--
The MIT License (MIT)
Copyright (c) 2024 rick barrette
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<h2>QboController#webhook</h2>

View File

@@ -88,4 +88,7 @@ en:
label_qbo_sync_success: "Successfully synced to Quickbooks"
label_hours: "Hours"
label_oauth2_refresh_token_expires_at: "Refresh Token Expires At"
label_name: "Name"
label_appointment: "Add Appointment"
label_actions: "Actions"
label_create_estimate: "Create Estimate"

View File

@@ -22,7 +22,7 @@ Redmine::Plugin.register :redmine_qbo do
name 'Redmine Quickbooks Online plugin'
author 'Rick Barrette'
description 'This is a plugin for Redmine to intergrate with Quickbooks Online to allow for seamless intergration CRM and invoicing of completed issues'
version '2.0.3'
version '2.1.1'
url 'https://github.com/rickbarrette/redmine_qbo'
author_url 'https://barrettefabrication.com'
settings :default => {'empty' => true}, :partial => 'qbo/settings'