mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 08:54:23 -05:00
Compare commits
13 Commits
19733c3f8c
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| f0a3b0193c | |||
| a531ef4f87 | |||
| 1fae647381 | |||
| d1764e2203 | |||
| f830881883 | |||
| fb87e8a33a | |||
| 8bdec410c4 | |||
| dec9eee90b | |||
| 2745ecf242 | |||
| 13472c3b3a | |||
| b686110145 | |||
| d91e7892c3 | |||
| f26224de56 |
1
Gemfile
1
Gemfile
@@ -3,7 +3,6 @@ source 'https://rubygems.org'
|
||||
gem 'quickbooks-ruby'
|
||||
gem 'oauth2', '1.4.7'
|
||||
gem 'roxml'
|
||||
gem 'nhtsa_vin'
|
||||
gem 'will_paginate'
|
||||
gem 'rails-jquery-autocomplete'
|
||||
gem 'jquery-ui-rails'
|
||||
|
||||
@@ -62,7 +62,6 @@ 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
|
||||
|
||||
@@ -39,12 +39,6 @@ class CustomersController < ApplicationController
|
||||
params.require(:customer).permit(:name, :email, :primary_phone, :mobile_phone, :phone_number)
|
||||
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
|
||||
# used for customer autocomplete field / issue form
|
||||
def filter_invoices_by_customer
|
||||
@@ -88,11 +82,14 @@ 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)
|
||||
@closed_issues = (@issues - @issues.open)
|
||||
@hours = 0
|
||||
@closed_hours = 0
|
||||
@issues.open.each { |i| @hours+= i.total_spent_hours }
|
||||
@closed_issues.each { |i| @closed_hours+= i.total_spent_hours }
|
||||
rescue
|
||||
render_404
|
||||
end
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
# This controller class will handle map management
|
||||
class VehiclesController < ApplicationController
|
||||
unloadable
|
||||
|
||||
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_attributes(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
|
||||
@@ -15,7 +15,6 @@ class Customer < ActiveRecord::Base
|
||||
has_many :purchases
|
||||
has_many :invoices
|
||||
has_many :estimates
|
||||
has_many :vehicles
|
||||
|
||||
validates_presence_of :id, :name
|
||||
|
||||
|
||||
@@ -104,53 +104,38 @@ 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"
|
||||
# TODO break if Invoice.find(invoice.id).cf_sync_confict
|
||||
is_changed = false
|
||||
|
||||
# update the invoive custom fields with infomation from the issue if available
|
||||
invoice.custom_fields.each { |cf|
|
||||
logger.debug "Calling :process_invoice_custom_fields hook"
|
||||
context = Redmine::Hook.call_hook :process_invoice_custom_fields, { issue: issue, invoice: invoice }
|
||||
|
||||
# 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.debug " 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"
|
||||
is_changed = true
|
||||
end
|
||||
unless context.nil?
|
||||
logger.debug "We have a context!"
|
||||
context= context.first
|
||||
issue = context[:issue]
|
||||
invoice = context[:invoice]
|
||||
is_changed = context[:is_changed]
|
||||
end
|
||||
|
||||
end
|
||||
# Custom Values
|
||||
begin
|
||||
value = issue.custom_values.find_by(custom_field_id: CustomField.find_by_name(cf.name).id)
|
||||
|
||||
# Check to see if the value is blank...
|
||||
if not value.value.to_s.blank?
|
||||
# Check to see if the value is diffrent
|
||||
if not cf.string_value.to_s.eql? value.value.to_s
|
||||
# update the custom field on the invoice
|
||||
cf.string_value = value.value.to_s
|
||||
is_changed = true
|
||||
end
|
||||
rescue
|
||||
#do nothing
|
||||
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
|
||||
}
|
||||
rescue
|
||||
# Nothing to do here, there is no match
|
||||
end
|
||||
|
||||
# Push updates
|
||||
begin
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
class Vehicle < ActiveRecord::Base
|
||||
|
||||
unloadable
|
||||
|
||||
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
|
||||
@@ -1 +0,0 @@
|
||||
$('select#issue_vehicles_id').html('<%= j content_tag(:option,'',:value=>"")+options_from_collection_for_select(@filtered_vehicles, :id, :to_s) %>');
|
||||
@@ -24,19 +24,15 @@
|
||||
</div>
|
||||
|
||||
<div class="splitcontentleft">
|
||||
<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>
|
||||
<%= call_hook :show_customer_view_right, {customer: @customer} %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
<h3><%=@issues.open.count%> <%=t(:label_open_issues)%>:</h3>
|
||||
<h3><%=@issues.open.count%> <%=t(:label_open_issues)%> - <%=@hours.round(1)%> <%=t(:label_hours)%></h3>
|
||||
<%= render :partial => 'issues/list_simple', locals: {issues: @issues.open} %>
|
||||
|
||||
<h3><%=@closed_issues.count%> <%=t(:label_closed_issues)%>:</h3>
|
||||
<h3><%=@closed_issues.count%> <%=t(:label_closed_issues)%> - <%= @closed_hours.round(1)%> <%=t(:label_hours)%></h3>
|
||||
<%= render :partial => 'issues/list_simple', locals: {issues: @closed_issues} %>
|
||||
|
||||
@@ -8,7 +8,3 @@
|
||||
<p>
|
||||
<%= select_estimate %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= vehicle %>
|
||||
</p>
|
||||
@@ -17,19 +17,6 @@
|
||||
</div>
|
||||
|
||||
<div class="splitcontentleft">
|
||||
<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>
|
||||
<%= call_hook :show_issue_view_right, {issue: issue} %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
<div class="issue">
|
||||
<div class="splitcontent">
|
||||
<div class="splitcontentleft">
|
||||
<h4><%=t(:label_details)%>:</h4>
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
|
||||
<tr>
|
||||
<th><%= t(:field_customer)%></th>
|
||||
<td><%= link_to vehicle.customer.name, customer_path(vehicle.customer) %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><%= t(:field_vehicle) %></th>
|
||||
<td><%= vehicle.to_s %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><%= t(:field_vin) %></th>
|
||||
<td><%= @vin[0] if @vin %><b><%=@vin[1] if @vin%></b></td>
|
||||
</tr>
|
||||
|
||||
<th><%= t(:label_trim) %></th>
|
||||
<td><%= vehicle.doors %> <%=t(:label_door) if vehicle.doors? %> <%= vehicle.trim %></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="splitcontentleft">
|
||||
|
||||
<h4><%=t(:field_notes)%>:</h4>
|
||||
<td><%= vehicle.notes %></td>
|
||||
</tr>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="float: right;">
|
||||
<%= button_to t(:label_edit), edit_vehicle_path(vehicle), method: :get%>
|
||||
<%= button_to t(:label_delete), vehicle, method: :delete, data: {confirm: t(:warn_ru_sure)} %>
|
||||
</div>
|
||||
@@ -1,56 +0,0 @@
|
||||
<div class="row">
|
||||
<div class="span6 columns">
|
||||
<fieldset>
|
||||
|
||||
<%= form_for @vehicle do |f| %>
|
||||
<div class="clearfix">
|
||||
<%=t(:field_customer)%>:
|
||||
<div class="input">
|
||||
<%= f.autocomplete_field :customer, autocomplete_customer_name_customers_path, :value => @customer.name, :update_elements => {:id => '#customer_id', :value => '#issue_customer'}, :required => true %>
|
||||
<%= f.hidden_field :customer_id, :id => "customer_id", :value => @customer.id %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clearfix">
|
||||
<%=t(:label_year)%>:
|
||||
<div class="input">
|
||||
<%= f.number_field :year, :autocomplete => "off" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clearfix">
|
||||
<%=t(:label_make)%>:
|
||||
<div class="input">
|
||||
<%= f.text_field :make, :autocomplete => "off" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clearfix">
|
||||
<%=t(:label_model)%>:
|
||||
<div class="input">
|
||||
<%= f.text_field :model, :autocomplete => "off" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clearfix">
|
||||
<%=t(:field_vin)%>:
|
||||
<div class="input">
|
||||
<%= f.text_field :vin , :autofocus => true %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clearfix">
|
||||
<%=t(:field_notes)%>:
|
||||
<div class="input">
|
||||
<%= f.text_area :notes, :cols => 60, :rows => 10, :no_label => true %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= f.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,28 +0,0 @@
|
||||
<% if @vehicles.present? %>
|
||||
|
||||
<% @vehicles.each do |vehicle| %>
|
||||
<div class="row">
|
||||
<div>
|
||||
<b><%= link_to "##{vehicle.id}", vehicle_path(vehicle) %> </b>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= vehicle.to_s %>
|
||||
<br/>
|
||||
<%= vehicle.customer %>
|
||||
<br/>
|
||||
<%= vehicle.vin.scan(/.{1,9}/)[0] if vehicle.vin %><b><%=vehicle.vin.scan(/.{1,9}/)[1] if vehicle.vin%></b>
|
||||
</div>
|
||||
</div>
|
||||
<br/>
|
||||
<% end %>
|
||||
|
||||
<div class="actions">
|
||||
<%= will_paginate @vehicles %>
|
||||
</div>
|
||||
|
||||
<p><%=t(:label_matching)%> <%=@vehicles.count%> <%=t(:field_vehicles) %> </p>
|
||||
|
||||
<% else %>
|
||||
<p><%=t(:label_no_vehicles)%> <%= params[:search] %>.</p>
|
||||
<% end %>
|
||||
@@ -1,4 +0,0 @@
|
||||
<%= form_tag(vehicles_path, :method => "get", id: "search-form") do %>
|
||||
<%= text_field_tag :search, params[:search], placeholder: t(:label_search_vin), :autocomplete => "off" %>
|
||||
<%= submit_tag t(:label_search) %>
|
||||
<% end %>
|
||||
@@ -1 +0,0 @@
|
||||
<option value="<%= vehicle.id %>"><%= vehicle.to_s.titleize %></option>
|
||||
@@ -1,3 +0,0 @@
|
||||
<h1><%=t(:label_edit_customer_vehicle)%></h1>
|
||||
<br/>
|
||||
<%= render :partial => 'vehicles/form' %>
|
||||
@@ -1,4 +0,0 @@
|
||||
<h2><%=t(:label_cusomer_vehicles)%> <span style="float:right"> <%= render :partial => 'vehicles/search' %> </span> </h2>
|
||||
<br/>
|
||||
|
||||
<%= render :partial => 'vehicles/list' %>
|
||||
@@ -1,3 +0,0 @@
|
||||
<h2><%=t(:label_new_vehicle)%></h2>
|
||||
<br/>
|
||||
<%= render :partial => 'vehicles/form' %>
|
||||
@@ -1,11 +0,0 @@
|
||||
<h2><%=t(:field_vehicle)%> #<%=@vehicle.id%></h2>
|
||||
|
||||
<%= render :partial => 'vehicles/details', locals: {vehicle: @vehicle} %>
|
||||
|
||||
<h3><%=@issues.open.count%> <%=t(:label_open_issues)%></h3>
|
||||
|
||||
<%= render :partial => 'issues/list_simple', locals: {issues: @issues.open} %>
|
||||
|
||||
<h3><%=@closed_issues.count%> <%=t(:label_closed_issues)%></h3>
|
||||
|
||||
<%= render :partial => 'issues/list_simple', locals: {issues: (@closed_issues)} %>
|
||||
@@ -1,10 +1,5 @@
|
||||
$(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",
|
||||
@@ -13,11 +8,4 @@ $(function() {
|
||||
});
|
||||
});
|
||||
|
||||
$("input#project_customer_id").on("change", function() {
|
||||
$.ajax({
|
||||
url: "/filter_vehicles_by_customer",
|
||||
type: "GET",
|
||||
data: { selected_customer: $("input#project_customer_id").val() }
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,9 +16,6 @@ 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"
|
||||
@@ -32,13 +29,8 @@ en:
|
||||
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"
|
||||
@@ -87,4 +79,5 @@ en:
|
||||
label_billed_success: "Successfully Billed "
|
||||
label_billing_error: "Cannot bill without a customer assigned"
|
||||
label_qbo_sync_success: "Successfully synced to Quickbooks"
|
||||
label_hours: "Hours"
|
||||
|
||||
@@ -31,15 +31,9 @@ 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
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
class CreateVehicles < ActiveRecord::Migration[5.1]
|
||||
|
||||
def change
|
||||
create_table :vehicles do |t|
|
||||
t.integer :year
|
||||
t.string :make
|
||||
t.string :model
|
||||
t.string :vin
|
||||
t.text :notes
|
||||
end
|
||||
|
||||
add_reference :vehicles, :qbo_customer, index: true
|
||||
end
|
||||
end
|
||||
@@ -1,15 +0,0 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
class UpdateIssuesWithVehicles < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
add_reference :issues, :vehicles, index: true
|
||||
end
|
||||
end
|
||||
@@ -1,15 +0,0 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
class UpdateVehicles < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
add_column :vehicles, :name, :text
|
||||
end
|
||||
end
|
||||
@@ -12,6 +12,5 @@ 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,6 +11,5 @@
|
||||
class UpdateProjects < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
add_reference :projects, :customer, index: true
|
||||
add_reference :projects, :vehicle, index: true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2022 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
class UpdateVehiclesTrim < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
12
init.rb
12
init.rb
@@ -19,28 +19,26 @@ end
|
||||
Redmine::Plugin.register :redmine_qbo do
|
||||
|
||||
# About
|
||||
name 'Redmine Quickbooks Online plugin'
|
||||
name 'Redmine QBO DEVELOPMENT 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'
|
||||
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'
|
||||
url 'https://github.com/rickbarrette/redmine_qbo'
|
||||
author_url 'http://rickbarrette.org'
|
||||
settings :default => {'empty' => true}, :partial => 'qbo/settings'
|
||||
requires_redmine :version_or_higher => '4.0.0'
|
||||
requires_redmine :version_or_higher => '6.0.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
|
||||
@@ -48,10 +46,8 @@ 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
|
||||
|
||||
@@ -26,7 +26,6 @@ module IssuePatch
|
||||
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
|
||||
|
||||
@@ -26,13 +26,11 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
|
||||
# This is done to preload customer information if the entire project is dedicated to a customer
|
||||
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
|
||||
@@ -52,22 +50,15 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
|
||||
:id => "issue_customer_id",
|
||||
:onchange => "updateIssueFrom('/issues/#{context[:issue].id}/edit.js', this)"
|
||||
|
||||
# Load estimates & vehicles
|
||||
# Load estimates
|
||||
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 & vehicles
|
||||
# Generate the drop down list of quickbooks estimates
|
||||
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, {
|
||||
@@ -77,7 +68,6 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
|
||||
customer_id: customer_id,
|
||||
context: context,
|
||||
select_estimate: select_estimate,
|
||||
vehicle: vehicle
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -36,26 +36,13 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
|
||||
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,
|
||||
vehicle: vehicle,
|
||||
split_vin: split_vin,
|
||||
notes: notes
|
||||
invoice_link: invoice_link
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
@@ -55,16 +55,10 @@ 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')
|
||||
#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]
|
||||
logger.debug "Calling :pdf_left hook"
|
||||
context = Redmine::Hook.call_hook :pdf_left, { array: left, issue: issue }
|
||||
left = left + context.first unless context.nil?
|
||||
|
||||
right = []
|
||||
right << [l(:field_start_date), format_date(issue.start_date)] unless issue.disabled_core_fields.include?('start_date')
|
||||
@@ -72,7 +66,10 @@ 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)
|
||||
right << [l(:field_notes), notes]
|
||||
|
||||
logger.debug "Calling :pdf_right hook"
|
||||
context = Redmine::Hook.call_hook :pdf_right, { array: right, issue: issue }
|
||||
right = right + context.first unless context.nil?
|
||||
|
||||
rows = left.size > right.size ? left.size : right.size
|
||||
while left.size < rows
|
||||
|
||||
@@ -23,7 +23,6 @@ module ProjectPatch
|
||||
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,21 +16,12 @@ 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"
|
||||
|
||||
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>"
|
||||
return "<p><label for=\"project_customer\">Customer</label>#{search_customer} #{customer_id}</p>"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user