mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 17:04:23 -05:00
Compare commits
13 Commits
2.1.1
...
a5de879260
| Author | SHA1 | Date | |
|---|---|---|---|
| a5de879260 | |||
| 6464e1cbc6 | |||
| 7f3a94229a | |||
| 395e0117fb | |||
| e04d363e42 | |||
| 3b6c0d4a70 | |||
| d1f6ccd9cb | |||
| 74f7ba41df | |||
| 4fb424faa8 | |||
| 63218e7f42 | |||
| 7f0bb3cae7 | |||
| ad7417c233 | |||
| cf0be2336b |
@@ -16,12 +16,15 @@ class EstimateController < ApplicationController
|
|||||||
skip_before_action :verify_authenticity_token, :check_if_login_required, :unless => proc {|c| session[:token].nil? }
|
skip_before_action :verify_authenticity_token, :check_if_login_required, :unless => proc {|c| session[:token].nil? }
|
||||||
|
|
||||||
def get_estimate
|
def get_estimate
|
||||||
# Force sync for estimate by doc number
|
# Force sync for estimate by doc number if not found
|
||||||
begin
|
if Estimate.find_by_doc_number(params[:search]).nil?
|
||||||
Estimate.sync_by_doc_number(params[:search]) if params[:search]
|
begin
|
||||||
rescue
|
Estimate.sync_by_doc_number(params[:search]) if params[:search]
|
||||||
logger.info "Estimate.find_by_doc_number failed"
|
rescue
|
||||||
|
logger.info "Estimate.find_by_doc_number failed"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
estimate = Estimate.find_by_id(params[:id]) if params[:id]
|
estimate = Estimate.find_by_id(params[:id]) if params[:id]
|
||||||
estimate = Estimate.find_by_doc_number(params[:search]) if params[:search]
|
estimate = Estimate.find_by_doc_number(params[:search]) if params[:search]
|
||||||
return estimate
|
return estimate
|
||||||
|
|||||||
@@ -85,44 +85,46 @@ class QboController < ApplicationController
|
|||||||
|
|
||||||
# proceed if the request is good
|
# proceed if the request is good
|
||||||
if hash.eql? signature
|
if hash.eql? signature
|
||||||
if request.headers['content-type'] == 'application/json'
|
Thread.new do
|
||||||
data = JSON.parse(data)
|
if request.headers['content-type'] == 'application/json'
|
||||||
else
|
data = JSON.parse(data)
|
||||||
# application/x-www-form-urlencoded
|
|
||||||
data = params.as_json
|
|
||||||
end
|
|
||||||
# Process the information
|
|
||||||
entities = data['eventNotifications'][0]['dataChangeEvent']['entities']
|
|
||||||
entities.each do |entity|
|
|
||||||
id = entity['id'].to_i
|
|
||||||
name = entity['name']
|
|
||||||
|
|
||||||
logger.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
|
else
|
||||||
begin
|
# application/x-www-form-urlencoded
|
||||||
obj.sync_by_id(id)
|
data = params.as_json
|
||||||
rescue => e
|
end
|
||||||
logger.error "Failed to call sync_by_id on obj"
|
# Process the information
|
||||||
logger.error e.message
|
entities = data['eventNotifications'][0]['dataChangeEvent']['entities']
|
||||||
logger.error e.backtrace.join("\n")
|
entities.each do |entity|
|
||||||
|
id = entity['id'].to_i
|
||||||
|
name = entity['name']
|
||||||
|
|
||||||
|
logger.info "Casting #{name.constantize} to obj"
|
||||||
|
|
||||||
|
# Magicly initialize the correct class
|
||||||
|
obj = name.constantize
|
||||||
|
|
||||||
|
# for merge events
|
||||||
|
obj.destroy(entity['deletedId']) if entity['deletedId']
|
||||||
|
|
||||||
|
#Check to see if we are deleting a record
|
||||||
|
if entity['operation'].eql? "Delete"
|
||||||
|
obj.destroy(id)
|
||||||
|
#if not then update!
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
obj.sync_by_id(id)
|
||||||
|
rescue => e
|
||||||
|
logger.error "Failed to call sync_by_id on obj"
|
||||||
|
logger.error e.message
|
||||||
|
logger.error e.backtrace.join("\n")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Record that last time we updated
|
||||||
|
Qbo.update_time_stamp
|
||||||
|
ActiveRecord::Base.connection.close
|
||||||
end
|
end
|
||||||
|
|
||||||
# Record that last time we updated
|
|
||||||
Qbo.update_time_stamp
|
|
||||||
|
|
||||||
# The webhook doesn't require a response but let's make sure we don't send anything
|
# The webhook doesn't require a response but let's make sure we don't send anything
|
||||||
render :nothing => true, status: 200
|
render :nothing => true, status: 200
|
||||||
else
|
else
|
||||||
|
|||||||
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=#{@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%>
|
||||||
@@ -41,9 +41,6 @@
|
|||||||
<td><%= customer.notes %></td>
|
<td><%= customer.notes %></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<div style="float: right;">
|
|
||||||
<%= button_to t(:label_edit_customer), edit_customer_path(customer), method: :get%>
|
|
||||||
</div>
|
|
||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
|
|||||||
@@ -3,4 +3,3 @@
|
|||||||
<%= submit_tag t(:label_search) %>
|
<%= submit_tag t(:label_search) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= button_to t(:label_new_customer), new_customer_path, method: :get%>
|
<%= button_to t(:label_new_customer), new_customer_path, method: :get%>
|
||||||
<%= button_to(t(:label_sync), qbo_sync_path, method: :get) if User.current.admin?%>
|
|
||||||
|
|||||||
@@ -7,7 +7,22 @@
|
|||||||
|
|
||||||
<h4><%=t(:label_details)%>:</h4>
|
<h4><%=t(:label_details)%>:</h4>
|
||||||
|
|
||||||
<%= render :partial => 'customers/details', locals: {customer: @customer} %>
|
<!-- Customer Info -->
|
||||||
|
|
||||||
|
<div class="splitcontent">
|
||||||
|
<div class="splitcontentleft">
|
||||||
|
<h4><%=t(:label_customer)%>:</h4>
|
||||||
|
<%= render :partial => 'customers/details', locals: {customer: @customer} %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="splitcontentleft">
|
||||||
|
<h4><%=t(:label_actions)%>:</h4>
|
||||||
|
<%= render :partial => 'customers/actions', locals: {customer: @customer} %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- QBO Info -->
|
||||||
|
|
||||||
<div class="splitcontent">
|
<div class="splitcontent">
|
||||||
<div class="splitcontentleft">
|
<div class="splitcontentleft">
|
||||||
|
|||||||
@@ -89,4 +89,6 @@ en:
|
|||||||
label_hours: "Hours"
|
label_hours: "Hours"
|
||||||
label_oauth2_refresh_token_expires_at: "Refresh Token Expires At"
|
label_oauth2_refresh_token_expires_at: "Refresh Token Expires At"
|
||||||
label_name: "Name"
|
label_name: "Name"
|
||||||
|
label_appointment: "Add Appointment"
|
||||||
|
label_actions: "Actions"
|
||||||
|
label_create_estimate: "Create Estimate"
|
||||||
|
|||||||
Reference in New Issue
Block a user