commit 68c1ec01fad65305413cea6b8fa575324eaf1a0d Author: Rick Barrette Date: Mon Jan 26 23:24:10 2026 -0500 Inital Commit diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..f2df490 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gem 'nhtsa_vin' \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..526207b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..babc42d --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +# Redmine QuickBooks Online Vehicles + +A redmine plugin to compliment the Redmine QuickBooks Online Vehicles plug in. + +The goal of this project is to allow add vehicle tracking for customer vehicles. + +## Compatibility + +| Redmine QBO Plugin Version | Redmine Version | +| :--- | :--- | +| Version 2026.1.2+ | Redmine 6.1 | + +## Features + +Adds vehicles that are owned by customers that can be attached to issues. + +## 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 + ``` + +2. **Install dependencies:** *Crucial for Redmine 6 / Rails 7 compatibility.* + + Bash + + ``` + bundle install + ``` + +3. **Migrate your database:** + + 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. + +## Usage + +Simply add vehicles to customers via Customer view + +Once a customer is attached to the customer, they can be attached to an issue. + +## License + +> 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. \ No newline at end of file diff --git a/app/controllers/vehicles_controller.rb b/app/controllers/vehicles_controller.rb new file mode 100644 index 0000000..25fe322 --- /dev/null +++ b/app/controllers/vehicles_controller.rb @@ -0,0 +1,125 @@ +#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. + +# This controller class will handle map management +class VehiclesController < ApplicationController + + 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(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 diff --git a/app/models/vehicle.rb b/app/models/vehicle.rb new file mode 100644 index 0000000..9c638c2 --- /dev/null +++ b/app/models/vehicle.rb @@ -0,0 +1,96 @@ +#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 Vehicle < ActiveRecord::Base + + belongs_to :customer + has_many :issues + has_many :projects + validates_presence_of :customer + validates :vin, uniqueness: true + before_save :decode_vin + + # 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 diff --git a/app/views/customers/_show_hook.html.erb b/app/views/customers/_show_hook.html.erb new file mode 100644 index 0000000..718f81e --- /dev/null +++ b/app/views/customers/_show_hook.html.erb @@ -0,0 +1,5 @@ +

<%=t(:field_vehicles)%>:

+<%= render :partial => 'vehicles/list', :locals => { :vehicles => customer.vehicles.paginate(:page => params[:page]) } %> +
+ <%= button_to t(:button_new_vehice), new_customer_vehicle_path(customer), method: :get %> +
\ No newline at end of file diff --git a/app/views/issues/_form_hook_vehicles.html.erb b/app/views/issues/_form_hook_vehicles.html.erb new file mode 100644 index 0000000..56ad63c --- /dev/null +++ b/app/views/issues/_form_hook_vehicles.html.erb @@ -0,0 +1,3 @@ +

+ <%= vehicle %> +

\ No newline at end of file diff --git a/app/views/issues/_show_issue_view_right.html.erb b/app/views/issues/_show_issue_view_right.html.erb new file mode 100644 index 0000000..3133c02 --- /dev/null +++ b/app/views/issues/_show_issue_view_right.html.erb @@ -0,0 +1,18 @@ +
+
<%=t(:field_vehicle)%>:
+
<%= vehicle %>
+
+ +
+
<%=t(:field_vin)%>:
+
<%=split_vin[0] if split_vin%><%=split_vin[1] if split_vin%>
+
+ +
+
<%=t(:field_notes)%>:
+
+
+        <%=notes%>
+    
+
+
\ No newline at end of file diff --git a/app/views/vehicles/_details.html.erb b/app/views/vehicles/_details.html.erb new file mode 100644 index 0000000..d5aaa0a --- /dev/null +++ b/app/views/vehicles/_details.html.erb @@ -0,0 +1,53 @@ +
+
+
+

<%=t(:label_details)%>:

+ + + + + + + + + + + + + + + + + + + + + + + +
<%= t(:field_customer)%><%= link_to vehicle.customer.name, customer_path(vehicle.customer) %>
<%= t(:field_vehicle) %><%= vehicle.to_s %>
<%= t(:field_vin) %><%= @vin[0] if @vin %><%=@vin[1] if @vin%>
<%= t(:label_trim) %><%= vehicle.doors %> <%=t(:label_door) if vehicle.doors? %> <%= vehicle.trim %>
+ +
+ +
+ +

<%=t(:field_notes)%>:

+
+          <%= vehicle.notes %>
+        
+ + + + +
+
+
+ +
+ <%= 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)} %> +
diff --git a/app/views/vehicles/_form.html.erb b/app/views/vehicles/_form.html.erb new file mode 100644 index 0000000..8e85442 --- /dev/null +++ b/app/views/vehicles/_form.html.erb @@ -0,0 +1,56 @@ +
+
+
+ + <%= form_for @vehicle do |f| %> +
+ <%=t(:field_customer)%>: +
+ <%= 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 %> +
+
+ +
+ <%=t(:label_year)%>: +
+ <%= f.number_field :year, :autocomplete => "off" %> +
+
+ +
+ <%=t(:label_make)%>: +
+ <%= f.text_field :make, :autocomplete => "off" %> +
+
+ +
+ <%=t(:label_model)%>: +
+ <%= f.text_field :model, :autocomplete => "off" %> +
+
+ +
+ <%=t(:field_vin)%>: +
+ <%= f.text_field :vin , :autofocus => true %> +
+
+ +
+ <%=t(:field_notes)%>: +
+ <%= f.text_area :notes, :cols => 60, :rows => 10, :no_label => true %> +
+
+ +
+ <%= f.submit %> +
+ <% end %> + +
+
+
diff --git a/app/views/vehicles/_list.html.erb b/app/views/vehicles/_list.html.erb new file mode 100644 index 0000000..1a688ec --- /dev/null +++ b/app/views/vehicles/_list.html.erb @@ -0,0 +1,28 @@ +<% if vehicles.present? %> + + <% vehicles.each do |vehicle| %> +
+
+ <%= link_to "##{vehicle.id}", vehicle_path(vehicle) %> +
+ +
+ <%= vehicle.to_s %> +
+ <%= vehicle.customer %> +
+ <%= vehicle.vin.scan(/.{1,9}/)[0] if vehicle.vin %><%=vehicle.vin.scan(/.{1,9}/)[1] if vehicle.vin%> +
+
+
+ <% end %> + +
+ <%= will_paginate vehicles %> +
+ +

<%=t(:label_matching)%> <%=vehicles.count%> <%=t(:field_vehicles) %>

+ +<% else %> +

<%=t(:label_no_vehicles)%> <%= params[:search] %>.

+<% end %> diff --git a/app/views/vehicles/_search.html.erb b/app/views/vehicles/_search.html.erb new file mode 100644 index 0000000..ba79ae2 --- /dev/null +++ b/app/views/vehicles/_search.html.erb @@ -0,0 +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" %> + <%= submit_tag t(:label_search) %> +<% end %> diff --git a/app/views/vehicles/_vehicle.html.erb b/app/views/vehicles/_vehicle.html.erb new file mode 100644 index 0000000..bec180d --- /dev/null +++ b/app/views/vehicles/_vehicle.html.erb @@ -0,0 +1 @@ + diff --git a/app/views/vehicles/edit.html.erb b/app/views/vehicles/edit.html.erb new file mode 100644 index 0000000..9490f6b --- /dev/null +++ b/app/views/vehicles/edit.html.erb @@ -0,0 +1,3 @@ +

<%=t(:label_edit_customer_vehicle)%>

+
+<%= render :partial => 'vehicles/form' %> diff --git a/app/views/vehicles/index.html.erb b/app/views/vehicles/index.html.erb new file mode 100644 index 0000000..224e813 --- /dev/null +++ b/app/views/vehicles/index.html.erb @@ -0,0 +1,4 @@ +

<%=t(:label_cusomer_vehicles)%> <%= render :partial => 'vehicles/search' %>

+
+ +<%= render :partial => 'vehicles/list', locals: {vehicles: @vehicles} %> diff --git a/app/views/vehicles/new.html.erb b/app/views/vehicles/new.html.erb new file mode 100644 index 0000000..b99af4d --- /dev/null +++ b/app/views/vehicles/new.html.erb @@ -0,0 +1,3 @@ +

<%=t(:label_new_vehicle)%>

+
+<%= render :partial => 'vehicles/form' %> diff --git a/app/views/vehicles/show.html.erb b/app/views/vehicles/show.html.erb new file mode 100644 index 0000000..d440c20 --- /dev/null +++ b/app/views/vehicles/show.html.erb @@ -0,0 +1,11 @@ +

<%=t(:field_vehicle)%> #<%=@vehicle.id%>

+ +<%= render :partial => 'vehicles/details', locals: {vehicle: @vehicle} %> + +

<%=@issues.open.count%> <%=t(:label_open_issues)%>

+ +<%= render :partial => 'issues/list_simple', locals: {issues: @issues.open} %> + +

<%=@closed_issues.count%> <%=t(:label_closed_issues)%>

+ +<%= render :partial => 'issues/list_simple', locals: {issues: (@closed_issues)} %> diff --git a/assets/images/.gitkeep b/assets/images/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/assets/javascripts/.gitkeep b/assets/javascripts/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/assets/stylesheets/.gitkeep b/assets/stylesheets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..2950289 --- /dev/null +++ b/config/locales/en.yml @@ -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. + +# English strings go here for Rails i18n +# Usage I18n.t(:label) +en: + field_vehicles: "Vehicles" + field_vehicle: "Vehicle" + field_vin: "VIN" + 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_new_vehicle: "New Customer Vehicle" + button_new_vehice: "New Vehicle" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..0108a51 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,18 @@ +#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. + +# Nest Vehicles under customers +resources :customers do + resources :vehicles + get :autocomplete_customer_name, :on => :collection +end + +#allow for just vehicles too +resources :vehicles diff --git a/db/migrate/001_create_vehicles.rb b/db/migrate/001_create_vehicles.rb new file mode 100644 index 0000000..0bedd52 --- /dev/null +++ b/db/migrate/001_create_vehicles.rb @@ -0,0 +1,36 @@ +#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 CreateVehicles < ActiveRecord::Migration[5.1] + + def change + reversible do |direction| + direction.up { + + create_table :vehicles do |t| + t.integer :year + t.string :make + t.string :model + t.string :vin + t.text :notes + t.text :name + t.text :doors + t.text :trim + end + + 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" + end + end +end diff --git a/db/migrate/002_update_vehicles.rb b/db/migrate/002_update_vehicles.rb new file mode 100644 index 0000000..c91c66b --- /dev/null +++ b/db/migrate/002_update_vehicles.rb @@ -0,0 +1,23 @@ +#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 UpdateVehicles < ActiveRecord::Migration[5.1] + + def change + 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" + end + end +end diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..bcbaaca --- /dev/null +++ b/init.rb @@ -0,0 +1,47 @@ +#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. + +Redmine::Plugin.register :redmine_qbo_vehicles do + + # About + 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' + url 'https://github.com/rickbarrette/redmine_qbo_vehicles' + author_url 'https://barrettefabrication.com' + 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' + 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' + + # Permissions for security + 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? } + +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 \ No newline at end of file diff --git a/lib/vehicles/hooks/customer_show_hook_listener.rb b/lib/vehicles/hooks/customer_show_hook_listener.rb new file mode 100644 index 0000000..073fc60 --- /dev/null +++ b/lib/vehicles/hooks/customer_show_hook_listener.rb @@ -0,0 +1,28 @@ +#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 CustomerShowHookListener < Redmine::Hook::ViewListener + + include IssuesHelper + + 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] } + }) + + end + end + end +end \ No newline at end of file diff --git a/lib/vehicles/hooks/issues_form_hook_listener.rb b/lib/vehicles/hooks/issues_form_hook_listener.rb new file mode 100644 index 0000000..e0b4f39 --- /dev/null +++ b/lib/vehicles/hooks/issues_form_hook_listener.rb @@ -0,0 +1,57 @@ +#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 IssuesFormHookListener < Redmine::Hook::ViewListener + + 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 + context[:controller].send(:render_to_string, { + :partial => 'issues/form_hook_vehicles', + locals: { + vehicle: vehicle + } + }) + end + + end + end +end \ No newline at end of file diff --git a/lib/vehicles/hooks/issues_show_hook_listener.rb b/lib/vehicles/hooks/issues_show_hook_listener.rb new file mode 100644 index 0000000..4ef32b2 --- /dev/null +++ b/lib/vehicles/hooks/issues_show_hook_listener.rb @@ -0,0 +1,44 @@ +#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 IssuesShowHookListener < Redmine::Hook::ViewListener + + # View Issue + # Display the quickbooks contact in the issue + 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', + locals: { + vehicle: vehicle, + split_vin: split_vin, + notes: notes + } + }) + end + + end + end +end \ No newline at end of file diff --git a/lib/vehicles/hooks/pdf_hook_listener.rb b/lib/vehicles/hooks/pdf_hook_listener.rb new file mode 100644 index 0000000..8a1a661 --- /dev/null +++ b/lib/vehicles/hooks/pdf_hook_listener.rb @@ -0,0 +1,36 @@ +#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 PdfHookListener < Redmine::Hook::ViewListener + + include IssuesHelper + + # Edit Issue Form + # Here we build the required form components before passing them to a partial view formatting. + 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] + return output + end + + end + end +end \ No newline at end of file diff --git a/lib/vehicles/hooks/projects_form_hook_listener.rb b/lib/vehicles/hooks/projects_form_hook_listener.rb new file mode 100644 index 0000000..0a98010 --- /dev/null +++ b/lib/vehicles/hooks/projects_form_hook_listener.rb @@ -0,0 +1,45 @@ +#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 "

#{search_customer} #{customer_id}

#{vehicle}

" + end + end + end +end \ No newline at end of file diff --git a/lib/vehicles/patches/customer_patch.rb b/lib/vehicles/patches/customer_patch.rb new file mode 100644 index 0000000..54a4dc0 --- /dev/null +++ b/lib/vehicles/patches/customer_patch.rb @@ -0,0 +1,29 @@ +#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 Patches + + # Patches Redmine QBO Customer dynamically. + # Adds a relationship for vehicle ownership by customers + module CustomerPatch + + ActiveSupport.on_load(:active_record) do + + Customer.class_eval do + has_many :vehicles + end + + end + + end + + end +end \ No newline at end of file diff --git a/lib/vehicles/patches/issue_patch.rb b/lib/vehicles/patches/issue_patch.rb new file mode 100644 index 0000000..e40177b --- /dev/null +++ b/lib/vehicles/patches/issue_patch.rb @@ -0,0 +1,30 @@ +#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 'issue' + +module Vehicles + module Patches + + # Patches Redmine's Issues dynamically. + # Adds a relationship for attahcing a vehilce to an issue + module IssuePatch + + ActiveSupport.on_load(:active_record) do + + Issue.class_eval do + belongs_to :vehicle + end + + end + + end + end +end \ No newline at end of file diff --git a/lib/vehicles/patches/pdf_patch.rb b/lib/vehicles/patches/pdf_patch.rb new file mode 100644 index 0000000..5a6e8bc --- /dev/null +++ b/lib/vehicles/patches/pdf_patch.rb @@ -0,0 +1,271 @@ +#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 \ No newline at end of file diff --git a/lib/vehicles/patches/project_patch.rb b/lib/vehicles/patches/project_patch.rb new file mode 100644 index 0000000..6deeeae --- /dev/null +++ b/lib/vehicles/patches/project_patch.rb @@ -0,0 +1,29 @@ +#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 '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 + + end + end + end +end \ No newline at end of file