mirror of
https://github.com/rickbarrette/redmine_qbo_vehicles.git
synced 2026-04-02 07:01:59 -04:00
Compare commits
77 Commits
2026.1.0
...
c38bced329
| Author | SHA1 | Date | |
|---|---|---|---|
| c38bced329 | |||
| 8503c48944 | |||
| 44bfb69e22 | |||
| 89dc3cd5f4 | |||
| 030340b35e | |||
| 097276e558 | |||
| ea73878c71 | |||
| 8ec60c8cd7 | |||
| 9cb38cfbb1 | |||
| 9a1678d353 | |||
| 28957c5dff | |||
| a67b75671e | |||
| 492ff000bf | |||
| e0fc07141c | |||
| 3e6c2672e0 | |||
| 71bde3a249 | |||
| 4f2ae19460 | |||
| 9ee792cbd8 | |||
| ae7ccbf4b0 | |||
| 550601b5c9 | |||
| 85cd02b16a | |||
| 4b8b3c3495 | |||
| b2c1bebea3 | |||
| 2bd13a819b | |||
| d6138843f8 | |||
| 452568e8b3 | |||
| a709fecd0c | |||
| 6db87dd551 | |||
| a73b6cd438 | |||
| f163f6518b | |||
| a89f9881a6 | |||
| ed38584ab2 | |||
| dba8381913 | |||
| d4fa314011 | |||
| be2effb1b4 | |||
| 4bcccbd2f1 | |||
| 92cc7222fb | |||
| c5318a3528 | |||
| 9315433cb1 | |||
| 82e25314f3 | |||
| 5cad4a6856 | |||
| 12fb8b47ef | |||
| b02a40827d | |||
| 5165bc20b4 | |||
| f30d735e52 | |||
| a30d8f56d8 | |||
| d22fcd4f66 | |||
| f649d4e902 | |||
| 2db17f3675 | |||
| d37933fe82 | |||
| 3efc545f0a | |||
| adcc116841 | |||
| 8bb98d2408 | |||
| 88b0ffcd6b | |||
| 48deb3b7c8 | |||
| e2ea22afdf | |||
| 717a61b024 | |||
| a932551b96 | |||
| e09990cd42 | |||
| ad8aa8e2e8 | |||
| 707abc00a9 | |||
| 1199af0886 | |||
| 5a2832b751 | |||
| 6fc2db5d73 | |||
| 634fd96e82 | |||
| ce624f178f | |||
| 808b84a346 | |||
| e4d2df889d | |||
| 715c412668 | |||
| e0a23bac20 | |||
| fa72b1c837 | |||
| 2f960c65f0 | |||
| db3c8be03d | |||
| 8eecdc0ddd | |||
| c477f7a37e | |||
| 2f49a21fed | |||
| 896d5a64ba |
57
README.md
57
README.md
@@ -1,53 +1,54 @@
|
||||
# Redmine QuickBooks Online Vehicles
|
||||
|
||||
A redmine plugin to compliment the Redmine QuickBooks Online Vehicles plug in.
|
||||
A Redmine plugin to complement the [Redmine QuickBooks Online](https://github.com/rickbarrette/redmine_qbo) plugin.
|
||||
|
||||
The goal of this project is to allow add vehicle tracking for customer vehicles.
|
||||
The goal of this project is to enable vehicle tracking for customer vehicles within Redmine.
|
||||
|
||||
## Requirements
|
||||
|
||||
* **Redmine:** 6.1+
|
||||
* **Parent Plugin:** [Redmine QuickBooks Online](https://github.com/rickbarrette/redmine_qbo)
|
||||
|
||||
## Compatibility
|
||||
|
||||
| Redmine QBO Plugin Version | Redmine Version |
|
||||
| :--- | :--- |
|
||||
| Version 2026.1.2+ | Redmine 6.1 |
|
||||
| Plugin Version | Redmine Version | Ruby Version |
|
||||
| :--- | :--- | :--- |
|
||||
| 2026.1.2+ | Redmine 6.1 | 3.2+ |
|
||||
|
||||
## Features
|
||||
|
||||
Adds vehicles that are owned by customers that can be attached to issues.
|
||||
* **Asset Tracking:** Adds vehicles owned by customers to the system.
|
||||
* **Issue Association:** Allows these vehicles to be attached directly to Redmine issues for better service tracking.
|
||||
|
||||
## Installation
|
||||
|
||||
1. **Clone the plugin:**
|
||||
Clone this repo into your plugin folder and checkout a tagged version.
|
||||
```bash
|
||||
cd path/to/redmine/plugins
|
||||
git clone git@github.com:rickbarrette/redmine_qbo_vehicles.git
|
||||
cd redmine_qbo
|
||||
git checkout <tag>
|
||||
```
|
||||
|
||||
2. **Install dependencies:** *Crucial for Redmine 6 / Rails 7 compatibility.*
|
||||
|
||||
Bash
|
||||
|
||||
1. **Clone the plugin:**
|
||||
Navigate to your Redmine plugins directory and clone the repository.
|
||||
```bash
|
||||
cd path/to/redmine/plugins
|
||||
git clone git@github.com:rickbarrette/redmine_qbo_vehicles.git
|
||||
cd redmine_qbo_vehicles
|
||||
git checkout <tag>
|
||||
```
|
||||
*(Note: Replace `<tag>` with the specific release version you wish to use, or omit the last line to use the main branch.)*
|
||||
|
||||
2. **Install dependencies:**
|
||||
*Crucial for Redmine 6 / Rails 7 compatibility.*
|
||||
```bash
|
||||
bundle install
|
||||
```
|
||||
|
||||
3. **Migrate your database:**
|
||||
|
||||
Bash
|
||||
|
||||
```
|
||||
```bash
|
||||
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
|
||||
```
|
||||
|
||||
4. **Restart Redmine:** You must restart your Redmine server instance for the plugin and hooks to load.
|
||||
4. **Restart Redmine:**
|
||||
You must restart your Redmine server instance (e.g., Puma, Passenger, Unicorn) for the plugin and hooks to load correctly.
|
||||
|
||||
## Usage
|
||||
|
||||
Simply add vehicles to customers via Customer view
|
||||
|
||||
Once a customer is attached to the customer, they can be attached to an issue.
|
||||
1. **Add a Vehicle:** Navigate to a Customer Profile. You will see a new option to add vehicles to that customer.
|
||||
2. **Link to Issue:** Once a vehicle is added to a customer, it can be selected and attached to an Issue relevant to that customer.
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -23,15 +23,16 @@ class VehiclesController < ApplicationController
|
||||
def index
|
||||
if params[:customer_id]
|
||||
begin
|
||||
@vehicles = Customer.find_by_id(params[:customer_id]).vehicles.paginate(:page => params[:page])
|
||||
@vehicles = Customer.find_by_id(params[:customer_id]).vehicles.paginate(page: params[:page])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
flash[:error] = t :alert_vehicle_not_found
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
# search for a vehicle by vin
|
||||
if params[:search]
|
||||
@vehicles = Vehicle.search(params[:search]).paginate(:page => params[:page])
|
||||
@vehicles = Vehicle.search(params[:search]).paginate(page: params[:page])
|
||||
if only_one_non_zero?(@vehicles)
|
||||
redirect_to @vehicles.first
|
||||
end
|
||||
@@ -48,7 +49,7 @@ class VehiclesController < ApplicationController
|
||||
def create
|
||||
@vehicle = Vehicle.new(allowed_params)
|
||||
if @vehicle.save
|
||||
flash[:notice] = "New Vehicle Created"
|
||||
flash[:notice] = t :notice_vehicle_created
|
||||
redirect_to @vehicle
|
||||
else
|
||||
flash[:error] = @vehicle.errors.full_messages.to_sentence
|
||||
@@ -59,21 +60,46 @@ class VehiclesController < ApplicationController
|
||||
# display a specific vehicle
|
||||
def show
|
||||
begin
|
||||
@vehicle = Vehicle.find_by_id(params[:id])
|
||||
@vehicle = Vehicle.includes(issues: [:estimate, :invoices]).find(params[:id])
|
||||
@vin = @vehicle.vin.scan(/.{1,9}/) if @vehicle.vin
|
||||
@issues = @vehicle.issues.order(id: :desc)
|
||||
@closed_issues = (@issues - @issues.open)
|
||||
@issues = @vehicle.issues
|
||||
.joins(:status)
|
||||
.includes(:estimate, :invoices, :status, :project, :tracker, :priority)
|
||||
.order(id: :desc)
|
||||
@open_issues = @issues.select { |i| !i.status.is_closed }
|
||||
@closed_issues = @issues.select { |i| i.status.is_closed }
|
||||
|
||||
flash[:error] = t :alert_no_customer if @vehicle.customer.nil?
|
||||
rescue
|
||||
flash[:error] = t :alert_vehicle_not_found
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
# used by the polling JS in vehicle#show
|
||||
def status
|
||||
vehicle = Vehicle.find(params[:id])
|
||||
|
||||
# decode the vin if it hasn't been done for some reason
|
||||
unless vehicle.vin_decoded
|
||||
if vehicle.error.nil?
|
||||
VehicleVinDecodeJob.perform_later(vehicle)
|
||||
end
|
||||
end
|
||||
|
||||
render json: {
|
||||
decoded: vehicle.vin_decoded,
|
||||
error: vehicle.error
|
||||
}
|
||||
end
|
||||
|
||||
# return an HTML form for editing a vehicle
|
||||
def edit
|
||||
begin
|
||||
@vehicle = Vehicle.find_by_id(params[:id])
|
||||
@customer = @vehicle.customer
|
||||
rescue
|
||||
flash[:error] = t :alert_vehicle_not_found
|
||||
render_404
|
||||
end
|
||||
end
|
||||
@@ -84,7 +110,7 @@ class VehiclesController < ApplicationController
|
||||
begin
|
||||
@vehicle = Vehicle.find_by_id(params[:id])
|
||||
if @vehicle.update(allowed_params)
|
||||
flash[:notice] = "Vehicle updated"
|
||||
flash[:notice] = t :notice_vehicle_updated
|
||||
redirect_to @vehicle
|
||||
else
|
||||
redirect_to edit_vehicle_path
|
||||
@@ -92,6 +118,7 @@ class VehiclesController < ApplicationController
|
||||
#show any errors anyways
|
||||
flash[:error] = @vehicle.errors.full_messages.to_sentence unless @vehicle.errors.empty?
|
||||
rescue
|
||||
flash[:error] = t :alert_vehicle_not_updated
|
||||
render_404
|
||||
end
|
||||
end
|
||||
@@ -100,9 +127,10 @@ class VehiclesController < ApplicationController
|
||||
def destroy
|
||||
begin
|
||||
Vehicle.find_by_id(params[:id]).destroy
|
||||
flash[:notice] = "Vehicle deleted successfully"
|
||||
flash[:notice] = t :notice_vehicle_deleted
|
||||
redirect_to action: :index
|
||||
rescue
|
||||
flash[:error] = t :alert_vehicle_not_deleted
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
46
app/jobs/vehicle_vin_decode_job.rb
Normal file
46
app/jobs/vehicle_vin_decode_job.rb
Normal file
@@ -0,0 +1,46 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2016 - 2026 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 VehicleVinDecodeJob < ApplicationJob
|
||||
queue_as :default
|
||||
retry_on StandardError, wait: 5.minutes, attempts: 5
|
||||
|
||||
def perform(vehicle_id)
|
||||
log "Looking up VIN for vehicle ##{vehicle_id}"
|
||||
vehicle = Vehicle.find_by(id: vehicle_id)
|
||||
return unless vehicle&.vin.present?
|
||||
result = VinDecoder.call(vehicle.vin)
|
||||
|
||||
unless result.success?
|
||||
log "Failed to decode vin"
|
||||
vehicle.update(vin_decoded: false, error: result.error)
|
||||
return
|
||||
end
|
||||
|
||||
details = result.data
|
||||
|
||||
vehicle.update(
|
||||
year: details.year.presence || vehicle.year,
|
||||
make: details.make.presence || vehicle.make,
|
||||
model: details.model.presence || vehicle.model,
|
||||
doors: details.doors.presence || vehicle.doors,
|
||||
trim: details.trim.presence || vehicle.trim,
|
||||
name: vehicle.to_s,
|
||||
vin_decoded: true,
|
||||
error: nil
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def log(msg)
|
||||
Rails.logger.info "[VehicleVinDecodeJob] #{msg}"
|
||||
end
|
||||
end
|
||||
@@ -8,89 +8,79 @@
|
||||
#
|
||||
#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
|
||||
class Vehicle < ApplicationRecord
|
||||
include Redmine::Acts::Searchable
|
||||
include Redmine::Acts::Event
|
||||
|
||||
belongs_to :customer
|
||||
has_many :issues
|
||||
has_many :projects
|
||||
validates_presence_of :customer
|
||||
validates :vin, uniqueness: true
|
||||
before_save :decode_vin
|
||||
validates :customer, presence: true
|
||||
validates :vin, presence: true, uniqueness: true
|
||||
before_validation :normalize_vin
|
||||
after_commit :enqueue_vin_decode, if: :saved_change_to_vin?
|
||||
acts_as_searchable columns: %w[vin make model year], scope: ->(_context) { all }, date_column: :updated_at
|
||||
acts_as_event :title => Proc.new {|o| "#{o.to_s}"},
|
||||
:url => Proc.new {|o| { :controller => 'vehicles', :action => 'show', :id => o.id} },
|
||||
:type => :to_s,
|
||||
:description => Proc.new {|o| "#{o.vin} - #{o.customer}"},
|
||||
:datetime => Proc.new {|o| o.updated_at || o.created_at}
|
||||
|
||||
# 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
|
||||
def estimates
|
||||
issues.includes(:estimate).flat_map(&:estimate).uniq.compact
|
||||
end
|
||||
|
||||
# returns the raw JSON details from NHTSA
|
||||
def details
|
||||
get_details if @details.nil?
|
||||
return @details
|
||||
def invoices
|
||||
issues.includes(:invoices).flat_map(&:invoices).uniq.compact
|
||||
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)
|
||||
super(val.to_s.strip)
|
||||
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)
|
||||
super(val.to_s.strip)
|
||||
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)
|
||||
# Redmine compatibility shim
|
||||
def project
|
||||
nil
|
||||
end
|
||||
|
||||
# search for a vin
|
||||
def self.search(search)
|
||||
where("vin LIKE ?", "%#{search}%")
|
||||
def self.search(query)
|
||||
q = "%#{sanitize_sql_like(query)}%"
|
||||
where( "vin LIKE :q OR make LIKE :q OR model LIKE :q OR year LIKE :q", q: q)
|
||||
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
|
||||
# Override the defult redmine seach method to rank results by id
|
||||
def self.search_result_ranks_and_ids(tokens, user, project = nil, options = {})
|
||||
return {} if tokens.blank?
|
||||
scope = self.all
|
||||
tokens.each do |token|
|
||||
scope = scope.search(token)
|
||||
end
|
||||
self.name = to_s
|
||||
ids = scope.distinct.limit(options[:limit] || 100).pluck(:id)
|
||||
ids.index_with { |id| id }
|
||||
end
|
||||
|
||||
def to_s
|
||||
return vin if year.blank? || make.blank? || model.blank?
|
||||
suffix = vin.to_s[9..] || vin
|
||||
"#{year} #{make} #{model} - #{suffix}"
|
||||
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
|
||||
def enqueue_vin_decode
|
||||
VehicleVinDecodeJob.perform_later(id)
|
||||
end
|
||||
|
||||
def normalize_vin
|
||||
return if vin.blank?
|
||||
cleaned = vin.to_s.upcase.gsub(/[^A-HJ-NPR-Z\d]/, "")
|
||||
self.vin = cleaned
|
||||
end
|
||||
|
||||
def log(msg)
|
||||
Rails.logger.info "[Vehicle] #{msg}"
|
||||
end
|
||||
end
|
||||
49
app/services/vin_decoder.rb
Normal file
49
app/services/vin_decoder.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2016 - 2026 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 VinDecoder
|
||||
Result = Struct.new(:success?, :data, :error)
|
||||
|
||||
def self.call(vin)
|
||||
new(vin).call
|
||||
end
|
||||
|
||||
def initialize(vin)
|
||||
@vin = vin
|
||||
end
|
||||
|
||||
def call
|
||||
log "Decoding VIN"
|
||||
validation = NhtsaVin.validate(@vin)
|
||||
return failure(validation.error) unless validation.valid?
|
||||
|
||||
query = NhtsaVin.get(@vin)
|
||||
return failure(query.error) unless query.valid?
|
||||
|
||||
success(query.response)
|
||||
rescue StandardError => e
|
||||
failure(e.message)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def success(data)
|
||||
Result.new(true, data, nil)
|
||||
end
|
||||
|
||||
def failure(error)
|
||||
log "VIN decode failed for #{@vin}: #{error}"
|
||||
Result.new(false, nil, error)
|
||||
end
|
||||
|
||||
def log(msg)
|
||||
Rails.logger.info "[VinDecoder] #{msg}"
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
<h4><%=t(:field_vehicles)%>:</h4>
|
||||
<%= render :partial => 'vehicles/list', :locals => { :vehicles => customer.vehicles.paginate(:page => params[:page]) } %>
|
||||
<%= render partial: 'vehicles/list', locals: { vehicles: customer.vehicles.paginate(page: params[:page]), show_customer: false, show_checkbox: true } %>
|
||||
<div style="float: right;">
|
||||
<%= button_to t(:button_new_vehice), new_customer_vehicle_path(customer), method: :get %>
|
||||
<%= button_to t(:button_new_vehicle), new_customer_vehicle_path(customer), method: :get %>
|
||||
</div>
|
||||
@@ -1,18 +1,17 @@
|
||||
<div class="vehicle attribute">
|
||||
<div class="label"><span><%=t(:field_vehicle)%></span>:</div>
|
||||
<div class="label"><%=t(:field_vehicle)%>:</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 class="label"><%=t(:field_vin)%>:</div>
|
||||
<div class="value" id="vin">
|
||||
<div id="copyLink" onclick="handleCopy(event)"><%=split_vin[0] if split_vin%><b><%=split_vin[1] if split_vin%></b></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="vehicle_notes attribute">
|
||||
<div class="label"><span><%=t(:field_notes)%></span>:</div>
|
||||
<div class="value">
|
||||
<pre id="note-display" style="text-align: left; white-space: pre-wrap; font-family: inherit; ">
|
||||
<%=notes%>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="label"><%=t(:field_notes)%>:</div>
|
||||
<pre class="value" id="note-display" style="text-align: left; white-space: pre-wrap; font-family: inherit; "><%=notes%></pre>
|
||||
</div>
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<tr>
|
||||
<th><%= t(:field_customer)%></th>
|
||||
<td><%= link_to vehicle.customer.name, customer_path(vehicle.customer) %></td>
|
||||
<td><%= vehicle.customer ? link_to(vehicle.customer.name, customer_path(vehicle.customer)) : t(:no_customer) %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
@@ -18,7 +18,9 @@
|
||||
|
||||
<tr>
|
||||
<th><%= t(:field_vin) %></th>
|
||||
<td><%= @vin[0] if @vin %><b><%=@vin[1] if @vin%></b></td>
|
||||
<td>
|
||||
<div onclick="handleCopy(event)"><%= @vin[0] if @vin %><b><%=@vin[1] if @vin%></b></div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<th><%= t(:label_trim) %></th>
|
||||
|
||||
@@ -6,43 +6,43 @@
|
||||
<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 %>
|
||||
<%= f.text_field :customer, class: "customer-name", autocomplete: "off", value: @customer.name, required: true,data: { autocomplete_url: "/customers/autocomplete" } %>
|
||||
<%= 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" %>
|
||||
<%= f.number_field :year, autocomplete: "off" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clearfix">
|
||||
<%=t(:label_make)%>:
|
||||
<div class="input">
|
||||
<%= f.text_field :make, :autocomplete => "off" %>
|
||||
<%= f.text_field :make, autocomplete: "off" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clearfix">
|
||||
<%=t(:label_model)%>:
|
||||
<div class="input">
|
||||
<%= f.text_field :model, :autocomplete => "off" %>
|
||||
<%= f.text_field :model, autocomplete: "off" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clearfix">
|
||||
<%=t(:field_vin)%>:
|
||||
<div class="input">
|
||||
<%= f.text_field :vin , :autofocus => true %>
|
||||
<%= 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 %>
|
||||
<%= f.text_area :notes, cols: 60, rows: 10, no_label: true %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -2,26 +2,37 @@
|
||||
|
||||
<% 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 class="container">
|
||||
|
||||
<% if show_checkbox %>
|
||||
<%= check_box_tag "vehicle_ids[]", vehicle.id, false, onchange: "updateLink()", data: { url: vehicle_path(vehicle).html_safe, text: vehicle.to_s }, class: "appointment checkbox" %>
|
||||
<% else %>
|
||||
<div class='checkbox'>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class='label-main'>
|
||||
<%= link_to vehicle.to_s, vehicle_path(vehicle) %>
|
||||
</div>
|
||||
|
||||
<div class="label-sub">
|
||||
<div onclick="handleCopy(event)"><%= vehicle.vin.scan(/.{1,9}/)[0] if vehicle.vin %><b><%=vehicle.vin.scan(/.{1,9}/)[1] if vehicle.vin%></b></div>
|
||||
<% if show_customer %>
|
||||
<%= vehicle.customer %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<br/>
|
||||
</div>
|
||||
<br/>
|
||||
<% end %>
|
||||
|
||||
<div class="actions">
|
||||
<%= will_paginate vehicles %>
|
||||
</div>
|
||||
|
||||
<p><%=t(:label_matching)%> <%=vehicles.count%> <%=t(:field_vehicles) %> </p>
|
||||
<%=t(:label_matching)%> <%=vehicles.count%> <%=t(:field_vehicles) %>
|
||||
|
||||
<% else %>
|
||||
<p><%=t(:label_no_vehicles)%> <%= params[:search] %>.</p>
|
||||
|
||||
@@ -1,4 +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" %>
|
||||
<%= form_tag(vehicles_path, method: "get", id: "vehicles-search-form") do %>
|
||||
<%= text_field_tag :search, params[:search], placeholder: t(:label_search_vehicles), autocomplete: "off" %>
|
||||
<%= submit_tag t(:label_search) %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<h1><%=t(:label_edit_customer_vehicle)%></h1>
|
||||
<br/>
|
||||
<%= render :partial => 'vehicles/form' %>
|
||||
<%= render partial: 'vehicles/form' %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<h2><%=t(:label_cusomer_vehicles)%> <span style="float:right"> <%= render :partial => 'vehicles/search' %> </span> </h2>
|
||||
<h2><%=t(:label_customer_vehicles)%> <span style="float:right"> <%= render partial: 'vehicles/search' %> </span> </h2>
|
||||
<br/>
|
||||
|
||||
<%= render :partial => 'vehicles/list', locals: {vehicles: @vehicles} %>
|
||||
<%= render partial: 'vehicles/list', locals: {vehicles: @vehicles, show_customer: true, show_checkbox: false} %>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<h2><%=t(:label_new_vehicle)%></h2>
|
||||
<br/>
|
||||
<%= render :partial => 'vehicles/form' %>
|
||||
<%= render partial: 'vehicles/form' %>
|
||||
|
||||
@@ -1,11 +1,104 @@
|
||||
<h2><%=t(:field_vehicle)%> #<%=@vehicle.id%></h2>
|
||||
|
||||
<%= render :partial => 'vehicles/details', locals: {vehicle: @vehicle} %>
|
||||
<% unless @vehicle.vin_decoded? %>
|
||||
<div id="vin-status" class="flash <%= @vehicle.error ? "error" : "notice" %>">
|
||||
<% if @vehicle.error%>
|
||||
<%= @vehicle.error %>
|
||||
<% else %>
|
||||
<%= t :notice_decoding_vin %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<h3><%=@issues.open.count%> <%=t(:label_open_issues)%></h3>
|
||||
<%= render partial: 'vehicles/details', locals: {vehicle: @vehicle} %>
|
||||
|
||||
<%= render :partial => 'issues/list_simple', locals: {issues: @issues.open} %>
|
||||
<div class="splitcontent">
|
||||
<div class="splitcontentleft">
|
||||
<h4><%=t(:estimates)%>:</h4>
|
||||
<%= render partial: 'estimates/list', locals: {estimates: @vehicle.estimates} %>
|
||||
</div>
|
||||
|
||||
<div class="splitcontentleft">
|
||||
<h4><%=t(:label_invoices)%>:</h4>
|
||||
<%= render partial: 'invoices/list', locals: {invoices: @vehicle.invoices} %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3><%=@open_issues.count%> <%=t(:label_open_issues)%></h3>
|
||||
|
||||
<%= render partial: 'issues/list_simple', locals: {issues: @open_issues} %>
|
||||
|
||||
<h3><%=@closed_issues.count%> <%=t(:label_closed_issues)%></h3>
|
||||
|
||||
<%= render :partial => 'issues/list_simple', locals: {issues: (@closed_issues)} %>
|
||||
<%= render partial: 'issues/list_simple', locals: {issues: (@closed_issues)} %>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
const vehicleId = <%= @vehicle.id %>;
|
||||
const alreadyDecoded = <%= @vehicle.vin_decoded? ? 'true' : 'false' %>;
|
||||
|
||||
if (alreadyDecoded) return;
|
||||
|
||||
const interval = 3000;
|
||||
let attempts = 0;
|
||||
const maxAttempts = 40;
|
||||
|
||||
const statusEl = document.getElementById("vin-status");
|
||||
|
||||
const checkStatus = () => {
|
||||
fetch(`/vehicles/${vehicleId}/status`, {
|
||||
headers: { 'Accept': 'application/json' }
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
|
||||
// SUCCESS → reload
|
||||
if (data.decoded) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
// ERROR → stop + show message
|
||||
if (data.error) {
|
||||
clearInterval(timer);
|
||||
|
||||
if (statusEl) {
|
||||
statusEl.classList.remove("notice");
|
||||
statusEl.classList.add("error");
|
||||
statusEl.textContent = data.error;
|
||||
}
|
||||
|
||||
console.warn("VIN decode failed:", data.error);
|
||||
return;
|
||||
}
|
||||
|
||||
// continue polling
|
||||
attempts++;
|
||||
if (attempts >= maxAttempts) {
|
||||
clearInterval(timer);
|
||||
|
||||
if (statusEl) {
|
||||
statusEl.classList.remove("notice");
|
||||
statusEl.classList.add("warning");
|
||||
statusEl.textContent = "VIN decode timed out. Please refresh or try again.";
|
||||
}
|
||||
|
||||
console.warn("VIN decode polling timed out");
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
clearInterval(timer);
|
||||
|
||||
if (statusEl) {
|
||||
statusEl.classList.remove("notice");
|
||||
statusEl.classList.add("error");
|
||||
statusEl.textContent = "Error checking VIN status.";
|
||||
}
|
||||
|
||||
console.error("Polling error:", err);
|
||||
});
|
||||
};
|
||||
|
||||
const timer = setInterval(checkStatus, interval);
|
||||
})();
|
||||
</script>
|
||||
45
assets/javascripts/copy.js
Normal file
45
assets/javascripts/copy.js
Normal file
@@ -0,0 +1,45 @@
|
||||
async function handleCopy(event) {
|
||||
console.log("Copy link clicked");
|
||||
|
||||
let text;
|
||||
let link;
|
||||
// Grab the text from our clicked link
|
||||
if(event.target.tagName.toLowerCase() === 'b'){
|
||||
text = event.target.parentElement.innerText;
|
||||
link = event.target.parentElement;
|
||||
} else {
|
||||
text = event.target.innerText;
|
||||
link = event.target;
|
||||
}
|
||||
|
||||
// If the text is already "Copied!", don't do anything
|
||||
if (text == "Copied!") {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Write to clipboard
|
||||
await navigator.clipboard.writeText(text);
|
||||
|
||||
// Update the UI to show it worked
|
||||
const originalText = link.innerText;
|
||||
link.innerHTML = "<b>Copied!</b>";
|
||||
link.style.color = "#4CAF50"; // Turn green
|
||||
|
||||
// Reset after 2 seconds
|
||||
setTimeout(() => {
|
||||
// Check if the text is long enough to prevent errors
|
||||
if (originalText.length >= 8) {
|
||||
const firstPart = originalText.slice(0, -8);
|
||||
const lastEight = originalText.slice(-8);
|
||||
link.innerHTML = `${firstPart}<b>${lastEight}</b>`;
|
||||
} else {
|
||||
link.innerText = originalText;
|
||||
}
|
||||
link.style.color = "";
|
||||
}, 2000);
|
||||
|
||||
} catch (err) {
|
||||
console.error('Unable to copy', err);
|
||||
}
|
||||
}
|
||||
23
assets/stylesheets/style.css
Normal file
23
assets/stylesheets/style.css
Normal file
@@ -0,0 +1,23 @@
|
||||
.container {
|
||||
display: grid;
|
||||
/* Column 1 for checkbox, Column 2 for text */
|
||||
grid-template-columns: auto 1fr;
|
||||
/* Row 1 for 'Vehicle', Row 2 for 'VIN' */
|
||||
grid-template-rows: auto auto;
|
||||
align-items: center;
|
||||
gap: 0 10px; /* Adjust spacing between checkbox and text */
|
||||
}
|
||||
|
||||
.checkbox {
|
||||
/* This makes the checkbox take up both rows */
|
||||
grid-row: span 2;
|
||||
}
|
||||
|
||||
.label-main {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.label-sub {
|
||||
font-size: 0.85em;
|
||||
color: #666;
|
||||
}
|
||||
@@ -10,18 +10,28 @@
|
||||
|
||||
# English strings go here for Rails i18n
|
||||
# Usage I18n.t(:label)
|
||||
|
||||
en:
|
||||
field_vehicles: "Vehicles"
|
||||
alert_no_customer: "Customer no longer exists, check for merged customers or deleted customers in QuickBooks Online."
|
||||
alert_vehicle_not_created: "Vehicle could not be created."
|
||||
alert_vehicle_not_deleted: "Vehicle could not be deleted."
|
||||
alert_vehicle_not_found: "Vehicle not found."
|
||||
alert_vehicle_not_updated: "Vehicle could not be updated."
|
||||
button_new_vehicle: "New Vehicle"
|
||||
field_vehicle: "Vehicle"
|
||||
field_vehicles: "Vehicles"
|
||||
field_vin: "VIN"
|
||||
label_customer_vehicles: "Customer Vehicles"
|
||||
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_search_vin: "Search Vehicles by VIN"
|
||||
label_edit_customer_vehicle: "Edit Customer Vehicle"
|
||||
label_cusomer_vehicles: "Customer Vehicles"
|
||||
label_make: "Make"
|
||||
label_model: "Model"
|
||||
label_new_vehicle: "New Customer Vehicle"
|
||||
button_new_vehice: "New Vehicle"
|
||||
label_no_vehicles: "There are no vehicles containing the term(s)"
|
||||
label_search_vehicles: "Search Vehicles"
|
||||
label_year: "Year"
|
||||
no_customer: "Customer no longer exists"
|
||||
notice_decoding_vin: "Decoding VIN… this page will update automatically."
|
||||
notice_vehicle_created: "Vehicle was successfully created."
|
||||
notice_vehicle_deleted: "Vehicle was successfully deleted."
|
||||
notice_vehicle_updated: "Vehicle was successfully updated."
|
||||
@@ -11,8 +11,12 @@
|
||||
# Nest Vehicles under customers
|
||||
resources :customers do
|
||||
resources :vehicles
|
||||
get :autocomplete_customer_name, :on => :collection
|
||||
get :autocomplete_customer_name, on: :collection
|
||||
end
|
||||
|
||||
#allow for just vehicles too
|
||||
resources :vehicles
|
||||
resources :vehicles do
|
||||
member do
|
||||
get :status
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,10 +27,9 @@ class CreateVehicles < ActiveRecord::Migration[5.1]
|
||||
|
||||
add_reference :vehicles, :customers, index: true
|
||||
add_reference :issues, :vehicle, index: true
|
||||
add_reference :projects, :vehicle, index: true
|
||||
}
|
||||
rescue
|
||||
logger.error "Failed to create vehicles & refrences"
|
||||
Rails.logger.error "Failed to create vehicles & refrences"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,10 +14,9 @@ class UpdateVehicles < ActiveRecord::Migration[5.1]
|
||||
reversible do |direction|
|
||||
direction.up {
|
||||
rename_column :issues, :vehicles_id, :vehicle_id
|
||||
rename_column :projects, :vehicles_id, :vehicle_id
|
||||
}
|
||||
rescue
|
||||
logger.error "Failed to update to use vehicle_id"
|
||||
Rails.logger.error "Failed to update to use vehicle_id"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
17
db/migrate/003_add_timestamp.rb
Normal file
17
db/migrate/003_add_timestamp.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2016 - 2026 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 AddTimestamp < ActiveRecord::Migration[7.0]
|
||||
|
||||
def change
|
||||
add_timestamps(:vehicles, null: true)
|
||||
end
|
||||
|
||||
end
|
||||
27
db/migrate/004_add_polling_and_indexes.rb
Normal file
27
db/migrate/004_add_polling_and_indexes.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2016 - 2026 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 AddPollingAndIndexes < ActiveRecord::Migration[7.0]
|
||||
|
||||
def change
|
||||
add_column :vehicles, :vin_decoded, :boolean, default: false, null: false
|
||||
add_column :vehicles, :error, :string
|
||||
add_index :vehicles, :vin_decoded
|
||||
add_index :vehicles, :vin, unique: true
|
||||
add_index :vehicles, :make
|
||||
add_index :vehicles, :model
|
||||
add_index :vehicles, :year
|
||||
|
||||
Vehicle.all.each do |v|
|
||||
VehicleVinDecodeJob.perform_later(v.id)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
25
init.rb
25
init.rb
@@ -14,34 +14,31 @@ Redmine::Plugin.register :redmine_qbo_vehicles do
|
||||
name 'Redmine QBO Vehicles plugin'
|
||||
author 'Rick Barrette'
|
||||
description 'This is a plugin for Redmine to intergrate with the redmine_qbo plugin to provide vehicle data tracking'
|
||||
version '2026.1.0'
|
||||
version '2026.3.2'
|
||||
url 'https://github.com/rickbarrette/redmine_qbo_vehicles'
|
||||
author_url 'https://barrettefabrication.com'
|
||||
requires_redmine :version_or_higher => '6.1.0'
|
||||
requires_redmine version_or_higher: '6.1.0'
|
||||
|
||||
# Ensure redmine_qbo is installed
|
||||
begin
|
||||
requires_redmine_plugin :redmine_qbo, version_or_higher: '2026.1.2'
|
||||
requires_redmine_plugin :redmine_qbo, version_or_higher: '2026.3.13'
|
||||
rescue Redmine::PluginNotFound
|
||||
raise 'Please install the redmine_qbo plugin (https://github.com/rickbarrette/redmine_qbo)'
|
||||
end
|
||||
|
||||
# Add safe attributes for core models
|
||||
Issue.safe_attributes 'vehicle_id'
|
||||
Project.safe_attributes 'vehicle_id'
|
||||
Issue.safe_attributes :vehicle_id
|
||||
|
||||
# Permissions for security
|
||||
permission :view_vehicles, :vehicles => :new, :public => false
|
||||
permission :view_vehicles, vehicles: :new, public: false
|
||||
|
||||
# Register top menu items
|
||||
menu :top_menu, :vehicles, { :controller => :vehicles, :action => :index }, :caption => 'Vehicles', :if => Proc.new { User.current.logged? }
|
||||
menu :top_menu, :vehicles, { controller: :vehicles, action: :index }, caption: :field_vehicles, if: Proc.new { User.current.logged? }
|
||||
|
||||
Redmine::Search.map do |search|
|
||||
search.register :vehicles
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Dynamically load all Hooks & Patches recursively
|
||||
base_dir = File.join(File.dirname(__FILE__), 'lib')
|
||||
|
||||
# '**' looks inside subdirectories, '*.rb' matches Ruby files
|
||||
Dir.glob(File.join(base_dir, '**', '*.rb')).sort.each do |file|
|
||||
require file
|
||||
end
|
||||
RedmineQboVehicles.setup
|
||||
23
lib/redmine_qbo_vehicles.rb
Normal file
23
lib/redmine_qbo_vehicles.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 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 RedmineQboVehicles
|
||||
def self.setup
|
||||
Issue.prepend Vehicles::Patches::IssuePatch
|
||||
Customer.prepend Vehicles::Patches::CustomerPatch
|
||||
|
||||
Vehicles::Hooks::CustomerShowHookListener
|
||||
Vehicles::Hooks::InvoiceHookListener
|
||||
Vehicles::Hooks::IssuesFormHookListener
|
||||
Vehicles::Hooks::IssuesShowHookListener
|
||||
Vehicles::Hooks::PdfHookListener
|
||||
Vehicles::Hooks::ViewHookListener
|
||||
end
|
||||
end
|
||||
@@ -13,13 +13,13 @@ module Vehicles
|
||||
|
||||
class CustomerShowHookListener < Redmine::Hook::ViewListener
|
||||
|
||||
include IssuesHelper
|
||||
include IssuesHelper
|
||||
|
||||
# Display vehicle information on the customer show view (right side)
|
||||
def show_customer_view_right(context={})
|
||||
|
||||
# Pass all prebuilt form components to our partial
|
||||
context[:controller].send(:render_to_string, {
|
||||
:partial => 'customers/show_hook', locals: { customer: context[:customer] }
|
||||
partial: 'customers/show_hook', locals: { customer: context[:customer] }
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
69
lib/vehicles/hooks/invoice_hook_listener.rb
Normal file
69
lib/vehicles/hooks/invoice_hook_listener.rb
Normal file
@@ -0,0 +1,69 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2016 - 2026 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 Vehicles
|
||||
module Hooks
|
||||
|
||||
class InvoiceHookListener < Redmine::Hook::ViewListener
|
||||
|
||||
include IssuesHelper
|
||||
|
||||
# Called by Redmine QBO Invoice
|
||||
def process_invoice_custom_fields(context={})
|
||||
log "Processing invoice custom fields for invoice ##{context[:invoice].id}"
|
||||
issue = context[:issue]
|
||||
|
||||
# update the invoive custom fields with infomation from the issue if available
|
||||
context[:invoice].custom_fields.each do |cf|
|
||||
|
||||
log "Checking invoice custom field: #{cf.name}"
|
||||
|
||||
# VIN from the attached vehicle
|
||||
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?
|
||||
|
||||
log "VIN was blank, updating the invoice vin in quickbooks"
|
||||
vin = context[:issue].vehicle.vin
|
||||
break if vin.nil?
|
||||
|
||||
if not cf.string_value.to_s.eql? vin
|
||||
cf.string_value = vin.to_s
|
||||
log "VIN has changed"
|
||||
context[:is_changed] = true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
rescue
|
||||
#do nothing
|
||||
log "redmine_qbo_vehicles.process_invoice_custom_fields failed, skipping"
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
return context if context[:is_changed]
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def log(msg)
|
||||
Rails.logger.info "[InvoiceHookListener] #{msg}"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -13,43 +13,21 @@ module Vehicles
|
||||
|
||||
class IssuesFormHookListener < Redmine::Hook::ViewListener
|
||||
|
||||
include IssuesHelper
|
||||
include IssuesHelper
|
||||
|
||||
# Edit Issue Form
|
||||
# Here we build the required form components before passing them to a partial view formatting.
|
||||
def view_issues_form_details_bottom(context={})
|
||||
f = context[:form]
|
||||
issue = context[:issue]
|
||||
|
||||
# check project level vehicle ownership first
|
||||
# if context[:project]
|
||||
# selected_vehicle = context[:project].vehicle.id unless context[:project].vehicle.nil?
|
||||
# end
|
||||
|
||||
# Check to see if the issue already belongs to a customer
|
||||
selected_vehicle = issue.vehicle.id unless issue.vehicle.nil?
|
||||
|
||||
# Load customer's vehicles
|
||||
if issue.customer
|
||||
if issue.customer.vehicles
|
||||
vehicles = issue.customer.vehicles.pluck(:name, :id)
|
||||
else
|
||||
vehicles = [nil].compact
|
||||
end
|
||||
else
|
||||
vehicles = [nil].compact
|
||||
end
|
||||
|
||||
# Generate the drop down list of vehicles
|
||||
vehicle = f.select :vehicle_id, vehicles, :selected => selected_vehicle, include_blank: true
|
||||
|
||||
# Pass all prebuilt form components to our partial
|
||||
# Load the customer's vehicles for selection in the issue form.
|
||||
context[:controller].send(:render_to_string, {
|
||||
:partial => 'issues/form_hook_vehicles',
|
||||
locals: {
|
||||
vehicle: vehicle
|
||||
}
|
||||
})
|
||||
partial: 'issues/form_hook_vehicles',
|
||||
locals: {
|
||||
vehicle: context[:form].select( :vehicle_id,
|
||||
context[:issue].customer ? context[:issue].customer.vehicles.pluck(:name, :id) : [],
|
||||
selected: context[:issue].vehicle ? context[:issue].vehicle.id : nil,
|
||||
include_blank: true )
|
||||
}
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -13,28 +13,15 @@ module Vehicles
|
||||
|
||||
class IssuesShowHookListener < Redmine::Hook::ViewListener
|
||||
|
||||
# View Issue
|
||||
# Display the quickbooks contact in the issue
|
||||
# Display vehicle information on the issue view page.
|
||||
def show_issue_view_right(context={})
|
||||
issue = context[:issue]
|
||||
|
||||
begin
|
||||
v = issue.vehicle
|
||||
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_issue_view_right',
|
||||
partial: 'issues/show_issue_view_right',
|
||||
locals: {
|
||||
vehicle: vehicle,
|
||||
split_vin: split_vin,
|
||||
notes: notes
|
||||
vehicle: context[:issue].vehicle ? link_to(context[:issue].vehicle) : nil,
|
||||
split_vin: context[:issue].vehicle ? context[:issue].vehicle.vin.to_s.scan(/.{1,9}/) : nil,
|
||||
notes: context[:issue].vehicle ? context[:issue].vehicle.notes : nil
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
@@ -16,18 +16,12 @@ module Vehicles
|
||||
|
||||
include IssuesHelper
|
||||
|
||||
# Edit Issue Form
|
||||
# Here we build the required form components before passing them to a partial view formatting.
|
||||
# Add vehicle information to the left column of the issue PDF
|
||||
def pdf_left(context={})
|
||||
issue = context[:issue]
|
||||
output = []
|
||||
v = issue.vehicle
|
||||
vehicle = v ? v.to_s : nil
|
||||
vin = v ? v.vin : nil
|
||||
notes = v ? v.notes : nil
|
||||
output << [l(:field_vehicles), vehicle]
|
||||
output << [l(:field_vin), vin ? vin.gsub(/(.{9})/, '\1 ') : nil]
|
||||
output << [l(:field_notes), notes]
|
||||
output << [l(:field_vehicles), context[:issue].vehicle ? context[:issue].vehicle.to_s : nil]
|
||||
output << [l(:field_vin), context[:issue].vehicle ? context[:issue].vehicle.vin.gsub(/(.{9})/, '\1 ') : nil]
|
||||
output << [l(:field_notes), context[:issue].vehicle ? context[:issue].vehicle.notes : nil]
|
||||
return output
|
||||
end
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2016 - 2026 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 Vehicles
|
||||
module Hooks
|
||||
|
||||
class ProjectsFormHookListener < Redmine::Hook::ViewListener
|
||||
|
||||
# Edit Project Form
|
||||
def view_projects_form(context={})
|
||||
f = context[:form]
|
||||
|
||||
# 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>"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -8,22 +8,17 @@
|
||||
#
|
||||
#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.
|
||||
|
||||
require_dependency 'project'
|
||||
|
||||
module Vehicles
|
||||
module Patches
|
||||
|
||||
# Patches Redmine's Projects dynamically.
|
||||
# Adds a relationships
|
||||
module ProjectPatch
|
||||
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
|
||||
Project.class_eval do
|
||||
belongs_to :vehicle
|
||||
end
|
||||
module Hooks
|
||||
class ViewHookListener < Redmine::Hook::ViewListener
|
||||
|
||||
def view_layouts_base_html_head(context = {})
|
||||
safe_join([
|
||||
stylesheet_link_tag('style', plugin: :redmine_qbo_vehicles, media: :all),
|
||||
javascript_include_tag('copy', plugin: :redmine_qbo_vehicles)
|
||||
])
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -14,16 +14,12 @@ module Vehicles
|
||||
# Patches Redmine QBO Customer dynamically.
|
||||
# Adds a relationship for vehicle ownership by customers
|
||||
module CustomerPatch
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
|
||||
Customer.class_eval do
|
||||
has_many :vehicles
|
||||
end
|
||||
|
||||
prepended do
|
||||
has_many :vehicles
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -8,21 +8,16 @@
|
||||
#
|
||||
#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.
|
||||
|
||||
require_dependency 'issue'
|
||||
|
||||
module Vehicles
|
||||
module Patches
|
||||
|
||||
# Patches Redmine's Issues dynamically.
|
||||
# Adds a relationship for attahcing a vehilce to an issue
|
||||
module IssuePatch
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
|
||||
Issue.class_eval do
|
||||
belongs_to :vehicle
|
||||
end
|
||||
|
||||
prepended do
|
||||
belongs_to :vehicle
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,271 +0,0 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2016 - 2026 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.
|
||||
|
||||
require_dependency 'redmine/export/pdf'
|
||||
require_dependency 'redmine/export/pdf/issues_pdf_helper'
|
||||
|
||||
module Vehicles
|
||||
module Patches
|
||||
|
||||
module PdfPatch
|
||||
|
||||
def self.included(base)
|
||||
base.send(:include, InstanceMethods)
|
||||
base.class_eval do
|
||||
alias_method :issue_to_pdf, :issue_to_pdf_with_patch
|
||||
alias_method :issue_to_pdf_with_patch, :issue_to_pdf
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def issue_to_pdf_with_patch(issue, assoc={})
|
||||
pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language)
|
||||
pdf.set_title("#{issue.project} - #{issue.tracker} ##{issue.id}")
|
||||
pdf.alias_nb_pages
|
||||
pdf.footer_date = format_date(Date.today)
|
||||
pdf.add_page
|
||||
pdf.SetFontStyle('B',11)
|
||||
buf = "#{issue.project} - #{issue.tracker} ##{issue.id}"
|
||||
pdf.RDMMultiCell(190, 5, buf)
|
||||
pdf.SetFontStyle('',8)
|
||||
base_x = pdf.get_x
|
||||
i = 1
|
||||
issue.ancestors.visible.each do |ancestor|
|
||||
pdf.set_x(base_x + i)
|
||||
buf = "#{ancestor.tracker} # #{ancestor.id} (#{ancestor.status.to_s}): #{ancestor.subject}"
|
||||
pdf.RDMMultiCell(190 - i, 5, buf)
|
||||
i += 1 if i < 35
|
||||
end
|
||||
pdf.SetFontStyle('B',11)
|
||||
pdf.RDMMultiCell(190 - i, 5, issue.subject.to_s)
|
||||
pdf.SetFontStyle('',8)
|
||||
pdf.RDMMultiCell(190, 5, "#{format_time(issue.created_on)} - #{issue.author}")
|
||||
pdf.ln
|
||||
|
||||
customer = issue.customer.name if issue.customer
|
||||
left = []
|
||||
left << [l(:field_status), issue.status]
|
||||
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]
|
||||
|
||||
right = []
|
||||
right << [l(:field_start_date), format_date(issue.start_date)] unless issue.disabled_core_fields.include?('start_date')
|
||||
right << [l(:field_due_date), format_date(issue.due_date)] unless issue.disabled_core_fields.include?('due_date')
|
||||
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]
|
||||
|
||||
rows = left.size > right.size ? left.size : right.size
|
||||
while left.size < rows
|
||||
left << nil
|
||||
end
|
||||
while right.size < rows
|
||||
right << nil
|
||||
end
|
||||
|
||||
half = (issue.visible_custom_field_values.size / 2.0).ceil
|
||||
issue.visible_custom_field_values.each_with_index do |custom_value, i|
|
||||
(i < half ? left : right) << [custom_value.custom_field.name, show_value(custom_value, false)]
|
||||
end
|
||||
|
||||
if pdf.get_rtl
|
||||
border_first_top = 'RT'
|
||||
border_last_top = 'LT'
|
||||
border_first = 'R'
|
||||
border_last = 'L'
|
||||
else
|
||||
border_first_top = 'LT'
|
||||
border_last_top = 'RT'
|
||||
border_first = 'L'
|
||||
border_last = 'R'
|
||||
end
|
||||
|
||||
rows = left.size > right.size ? left.size : right.size
|
||||
rows.times do |i|
|
||||
heights = []
|
||||
pdf.SetFontStyle('B',9)
|
||||
item = left[i]
|
||||
heights << pdf.get_string_height(35, item ? "#{item.first}:" : "")
|
||||
item = right[i]
|
||||
heights << pdf.get_string_height(35, item ? "#{item.first}:" : "")
|
||||
pdf.SetFontStyle('',9)
|
||||
item = left[i]
|
||||
heights << pdf.get_string_height(60, item ? item.last.to_s : "")
|
||||
item = right[i]
|
||||
heights << pdf.get_string_height(60, item ? item.last.to_s : "")
|
||||
height = heights.max
|
||||
|
||||
item = left[i]
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMMultiCell(35, height, item ? "#{item.first}:" : "", (i == 0 ? border_first_top : border_first), '', 0, 0)
|
||||
pdf.SetFontStyle('',9)
|
||||
pdf.RDMMultiCell(60, height, item ? item.last.to_s : "", (i == 0 ? border_last_top : border_last), '', 0, 0)
|
||||
|
||||
item = right[i]
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMMultiCell(35, height, item ? "#{item.first}:" : "", (i == 0 ? border_first_top : border_first), '', 0, 0)
|
||||
pdf.SetFontStyle('',9)
|
||||
pdf.RDMMultiCell(60, height, item ? item.last.to_s : "", (i == 0 ? border_last_top : border_last), '', 0, 2)
|
||||
|
||||
pdf.set_x(base_x)
|
||||
end
|
||||
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMCell(35+155, 5, l(:field_description), "LRT", 1)
|
||||
pdf.SetFontStyle('',9)
|
||||
|
||||
# Set resize image scale
|
||||
pdf.set_image_scale(1.6)
|
||||
text = textilizable(issue, :description,
|
||||
:only_path => false,
|
||||
:edit_section_links => false,
|
||||
:headings => false,
|
||||
:inline_attachments => false
|
||||
)
|
||||
pdf.RDMwriteFormattedCell(35+155, 5, '', '', text, issue.attachments, "LRB")
|
||||
|
||||
unless issue.leaf?
|
||||
truncate_length = (!is_cjk? ? 90 : 65)
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMCell(35+155,5, l(:label_subtask_plural) + ":", "LTR")
|
||||
pdf.ln
|
||||
issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level|
|
||||
buf = "#{child.tracker} # #{child.id}: #{child.subject}".
|
||||
truncate(truncate_length)
|
||||
level = 10 if level >= 10
|
||||
pdf.SetFontStyle('',8)
|
||||
pdf.RDMCell(35+135,5, (level >=1 ? " " * level : "") + buf, border_first)
|
||||
pdf.SetFontStyle('B',8)
|
||||
pdf.RDMCell(20,5, child.status.to_s, border_last)
|
||||
pdf.ln
|
||||
end
|
||||
end
|
||||
|
||||
relations = issue.relations.select { |r| r.other_issue(issue).visible? }
|
||||
unless relations.empty?
|
||||
truncate_length = (!is_cjk? ? 80 : 60)
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMCell(35+155,5, l(:label_related_issues) + ":", "LTR")
|
||||
pdf.ln
|
||||
relations.each do |relation|
|
||||
buf = relation.to_s(issue) {|other|
|
||||
text = ""
|
||||
if Setting.cross_project_issue_relations?
|
||||
text += "#{relation.other_issue(issue).project} - "
|
||||
end
|
||||
text += "#{other.tracker} ##{other.id}: #{other.subject}"
|
||||
text
|
||||
}
|
||||
buf = buf.truncate(truncate_length)
|
||||
pdf.SetFontStyle('', 8)
|
||||
pdf.RDMCell(35+155-60, 5, buf, border_first)
|
||||
pdf.SetFontStyle('B',8)
|
||||
pdf.RDMCell(20,5, relation.other_issue(issue).status.to_s, "")
|
||||
pdf.RDMCell(20,5, format_date(relation.other_issue(issue).start_date), "")
|
||||
pdf.RDMCell(20,5, format_date(relation.other_issue(issue).due_date), border_last)
|
||||
pdf.ln
|
||||
end
|
||||
end
|
||||
pdf.RDMCell(190,5, "", "T")
|
||||
pdf.ln
|
||||
|
||||
if issue.changesets.any? &&
|
||||
User.current.allowed_to?(:view_changesets, issue.project)
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMCell(190,5, l(:label_associated_revisions), "B")
|
||||
pdf.ln
|
||||
for changeset in issue.changesets
|
||||
pdf.SetFontStyle('B',8)
|
||||
csstr = "#{l(:label_revision)} #{changeset.format_identifier} - "
|
||||
csstr += format_time(changeset.committed_on) + " - " + changeset.author.to_s
|
||||
pdf.RDMCell(190, 5, csstr)
|
||||
pdf.ln
|
||||
unless changeset.comments.blank?
|
||||
pdf.SetFontStyle('',8)
|
||||
pdf.RDMwriteHTMLCell(190,5,'','',
|
||||
changeset.comments.to_s, issue.attachments, "")
|
||||
end
|
||||
pdf.ln
|
||||
end
|
||||
end
|
||||
|
||||
if assoc[:journals].present?
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMCell(190,5, l(:label_history), "B")
|
||||
pdf.ln
|
||||
assoc[:journals].each do |journal|
|
||||
pdf.SetFontStyle('B',8)
|
||||
title = "##{journal.indice} - #{format_time(journal.created_on)} - #{journal.user}"
|
||||
title << " (#{l(:field_private_notes)})" if journal.private_notes?
|
||||
pdf.RDMCell(190,5, title)
|
||||
pdf.ln
|
||||
pdf.SetFontStyle('I',8)
|
||||
details_to_strings(journal.visible_details, true).each do |string|
|
||||
pdf.RDMMultiCell(190,5, "- " + string)
|
||||
end
|
||||
if journal.notes?
|
||||
pdf.ln unless journal.details.empty?
|
||||
pdf.SetFontStyle('',8)
|
||||
text = textilizable(journal, :notes,
|
||||
:only_path => false,
|
||||
:edit_section_links => false,
|
||||
:headings => false,
|
||||
:inline_attachments => false
|
||||
)
|
||||
pdf.RDMwriteFormattedCell(190,5,'','', text, issue.attachments, "")
|
||||
end
|
||||
pdf.ln
|
||||
end
|
||||
end
|
||||
|
||||
if issue.attachments.any?
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMCell(190,5, l(:label_attachment_plural), "B")
|
||||
pdf.ln
|
||||
for attachment in issue.attachments
|
||||
pdf.SetFontStyle('',8)
|
||||
pdf.RDMCell(80,5, attachment.filename)
|
||||
pdf.RDMCell(20,5, number_to_human_size(attachment.filesize),0,0,"R")
|
||||
pdf.RDMCell(25,5, format_date(attachment.created_on),0,0,"R")
|
||||
pdf.RDMCell(65,5, attachment.author.name,0,0,"R")
|
||||
pdf.ln
|
||||
end
|
||||
end
|
||||
|
||||
# Check to see if there is an estimate attached, then combine them
|
||||
if issue.estimate
|
||||
pdf = CombinePDF.parse(pdf.output, allow_optional_content: true)
|
||||
pdf << CombinePDF.parse(issue.estimate.pdf)
|
||||
return pdf.to_pdf
|
||||
end
|
||||
|
||||
return pdf.output
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Redmine::Export::PDF::IssuesPdfHelper.send(:include, PdfPatch)
|
||||
|
||||
end
|
||||
end
|
||||
BIN
screenshots/customer_details.png
Normal file
BIN
screenshots/customer_details.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 564 KiB |
BIN
screenshots/issue.png
Normal file
BIN
screenshots/issue.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 724 KiB |
BIN
screenshots/issue_form.png
Normal file
BIN
screenshots/issue_form.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 534 KiB |
BIN
screenshots/vehicle_details.png
Normal file
BIN
screenshots/vehicle_details.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 540 KiB |
Reference in New Issue
Block a user