mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 17:04:23 -05:00
Merge branch 'dev' of github.com:rickbarrette/redmine_qbo into dev
This commit is contained in:
@@ -39,6 +39,14 @@ class CustomersController < ApplicationController
|
|||||||
@filtered_vehicles = Vehicle.all.where(customer_id: params[:selected_customer])
|
@filtered_vehicles = Vehicle.all.where(customer_id: params[:selected_customer])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def filter_invoices_by_customer
|
||||||
|
@filtered_invoices = QboInvoice.all.where(customer_id: params[:selected_customer])
|
||||||
|
end
|
||||||
|
|
||||||
|
def filter_estimates_by_customer
|
||||||
|
@filtered_estimates = QboEstimate.all.where(customer_id: params[:selected_customer])
|
||||||
|
end
|
||||||
|
|
||||||
# display a list of all customers
|
# display a list of all customers
|
||||||
def index
|
def index
|
||||||
if params[:search]
|
if params[:search]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#The MIT License (MIT)
|
#The MIT License (MIT)
|
||||||
#
|
#
|
||||||
#Copyright (c) 2016 rick barrette
|
#Copyright (c) 2017 rick barrette
|
||||||
#
|
#
|
||||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
#
|
#
|
||||||
@@ -10,47 +10,49 @@
|
|||||||
|
|
||||||
class QboEstimate < ActiveRecord::Base
|
class QboEstimate < ActiveRecord::Base
|
||||||
unloadable
|
unloadable
|
||||||
has_many :issues
|
|
||||||
belongs_to :customer
|
|
||||||
attr_accessible :doc_number
|
|
||||||
validates_presence_of :id, :doc_number, :customer_id
|
|
||||||
|
|
||||||
|
has_and_belongs_to_many :issues
|
||||||
|
belongs_to :customer
|
||||||
|
attr_accessible :doc_number, :id
|
||||||
|
validates_presence_of :doc_number, :id
|
||||||
|
self.primary_key = :id
|
||||||
|
|
||||||
|
# return the QBO Estimate service
|
||||||
def self.get_base
|
def self.get_base
|
||||||
Qbo.get_base(:estimate)
|
Qbo.get_base(:estimate).service
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# sync all estimates
|
||||||
def self.sync
|
def self.sync
|
||||||
estimates = get_base.service.all
|
estimates = get_base.all
|
||||||
|
estimates.each { |estimate|
|
||||||
# Update the item table
|
process_estimate(estimate)
|
||||||
transaction do
|
}
|
||||||
estimates.each { |estimate|
|
|
||||||
qbo_estimate = QboEstimate.find_or_create_by(id: estimate.id)
|
|
||||||
qbo_estimate.doc_number = estimate.doc_number
|
|
||||||
qbo_estimate.customer_id = estimate.customer_ref.value
|
|
||||||
qbo_estimate.id = estimate.id
|
|
||||||
qbo_estimate.save!
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
#remove deleted estimates
|
#remove deleted estimates
|
||||||
where.not(estimates.map(&:id)).destroy_all
|
where.not(estimates.map(&:id)).destroy_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# sync only one estimate
|
||||||
def self.sync_by_id(id)
|
def self.sync_by_id(id)
|
||||||
estimate = get_base.service.fetch_by_id(id)
|
process_estimate(get_base.fetch_by_id(id))
|
||||||
qbo_estimate = QboEstimate.find_or_create_by(id: estimate.id)
|
end
|
||||||
|
|
||||||
|
# update an estimate
|
||||||
|
def self.update(id)
|
||||||
|
# Update the item table
|
||||||
|
estimate = get_base.fetch_by_id(id)
|
||||||
|
qbo_estimate = find_or_create_by(id: id)
|
||||||
|
qbo_estimate.doc_number = estimate.doc_number
|
||||||
|
qbo_estimate.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
# process an estimate into the database
|
||||||
|
def process_estimate(estimate)
|
||||||
|
qbo_estimate = find_or_create_by(id: estimate.id)
|
||||||
qbo_estimate.doc_number = estimate.doc_number
|
qbo_estimate.doc_number = estimate.doc_number
|
||||||
qbo_estimate.customer_id = estimate.customer_ref.value
|
qbo_estimate.customer_id = estimate.customer_ref.value
|
||||||
qbo_estimate.id = estimate.id
|
qbo_estimate.id = estimate.id
|
||||||
qbo_estimate.save!
|
qbo_estimate.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.update(id)
|
|
||||||
# Update the item table
|
|
||||||
estimate = get_base.service.fetch_by_id(id)
|
|
||||||
qbo_estimate = QboEstimate.find_or_create_by(id: id)
|
|
||||||
qbo_estimate.doc_number = estimate.doc_number
|
|
||||||
qbo_estimate.save!
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
1
app/views/customers/filter_estimates_by_customer.js.erb
Normal file
1
app/views/customers/filter_estimates_by_customer.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
$('select#issue_qbo_estimate_id').html('<%= j options_from_collection_for_select(@filtered_estimates, :id, :to_s) %>');
|
||||||
@@ -5,5 +5,11 @@ $(function() {
|
|||||||
type: "GET",
|
type: "GET",
|
||||||
data: { selected_customer: $("input#issue_customer_id").val() }
|
data: { selected_customer: $("input#issue_customer_id").val() }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "/filter_estimates_by_customer",
|
||||||
|
type: "GET",
|
||||||
|
data: { selected_customer: $("input#issue_customer_id").val() }
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -34,14 +34,15 @@ resources :payments
|
|||||||
#webhook
|
#webhook
|
||||||
post 'qbo/webhook', :to => 'qbo#qbo_webhook'
|
post 'qbo/webhook', :to => 'qbo#qbo_webhook'
|
||||||
|
|
||||||
#ajax
|
#java script routes
|
||||||
get 'filter_vehicles_by_customer' => 'customers#filter_vehicles_by_customer'
|
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
|
# Nest Vehicles under customers
|
||||||
resources :customers do
|
resources :customers do
|
||||||
resources :vehicles
|
resources :vehicles
|
||||||
get :autocomplete_customer_name, :on => :collection
|
get :autocomplete_customer_name, :on => :collection
|
||||||
get :autocomplete_customer_vehicles, :on => :collection
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#allow for just vehicles too
|
#allow for just vehicles too
|
||||||
|
|||||||
@@ -32,15 +32,17 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
|
|||||||
search_customer = f.autocomplete_field :customer, autocomplete_customer_name_customers_path, :selected => selected_customer, :update_elements => {:id => '#issue_customer_id', :value => '#issue_customer'}
|
search_customer = f.autocomplete_field :customer, autocomplete_customer_name_customers_path, :selected => selected_customer, :update_elements => {:id => '#issue_customer_id', :value => '#issue_customer'}
|
||||||
customer_id = f.hidden_field :customer_id, :id => "issue_customer_id"
|
customer_id = f.hidden_field :customer_id, :id => "issue_customer_id"
|
||||||
|
|
||||||
# Generate the drop down list of quickbooks extimates
|
|
||||||
select_estimate = f.select :qbo_estimate_id, QboEstimate.all.pluck(:doc_number, :id).sort! {|x, y| y <=> x}, :selected => selected_estimate, include_blank: true
|
|
||||||
|
|
||||||
if context[:issue].customer
|
if context[:issue].customer
|
||||||
vehicles = customer.vehicles.pluck(:name, :id).sort!
|
vehicles = customer.vehicles.pluck(:name, :id).sort!
|
||||||
|
estimates = customer.qbo_estimates.pluck(:doc_number, :id).sort! {|x, y| y <=> x}
|
||||||
else
|
else
|
||||||
vehicles = [nil].compact
|
vehicles = [nil].compact
|
||||||
|
estimates = [nil].compact
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Generate the drop down list of quickbooks extimates
|
||||||
|
select_estimate = f.select :qbo_estimate_id, estimates, :selected => selected_estimate, include_blank: true
|
||||||
|
|
||||||
vehicle = f.select :vehicles_id, vehicles, :selected => selected_vehicle, include_blank: true
|
vehicle = f.select :vehicles_id, vehicles, :selected => selected_vehicle, include_blank: true
|
||||||
|
|
||||||
return "<p><label for=\"issue_customer\">Customer</label>#{search_customer} #{customer_id}</p> <p>#{select_estimate}</p> <p>#{vehicle}</p>"
|
return "<p><label for=\"issue_customer\">Customer</label>#{search_customer} #{customer_id}</p> <p>#{select_estimate}</p> <p>#{vehicle}</p>"
|
||||||
|
|||||||
Reference in New Issue
Block a user