commit f297830750b07b3d7b64fe60dc7f0ef0fa2a210c Author: Rick Barrette Date: Thu Mar 5 08:40:23 2026 -0500 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e46becb --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.bundle +.config +.dockerrc +.vscode +Gemfile.lock 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/app/models/line_item.rb b/app/models/line_item.rb new file mode 100644 index 0000000..f83ea49 --- /dev/null +++ b/app/models/line_item.rb @@ -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 LineItem < ApplicationRecord + belongs_to :issue + + validates :description, presence: true + validates :quantity, numericality: { greater_than: 0 } + validates :unit_price, numericality: { greater_than_or_equal_to: 0 } +end \ No newline at end of file diff --git a/app/views/line_items/_issue_form.html.erb b/app/views/line_items/_issue_form.html.erb new file mode 100644 index 0000000..34a94ca --- /dev/null +++ b/app/views/line_items/_issue_form.html.erb @@ -0,0 +1,34 @@ +<% @issue.line_items.build if @issue.line_items.empty? %> + +
+

Line Items

+ + + + + + + + + + + + + <%= f.fields_for :line_items do |item_form| %> + <%= render "line_items/line_item_fields", f: item_form %> + <% end %> + +
DescriptionQuantityUnit Price
+ + + +

+ +

+
\ No newline at end of file diff --git a/app/views/line_items/_line_item_fields.html.erb b/app/views/line_items/_line_item_fields.html.erb new file mode 100644 index 0000000..96d56a3 --- /dev/null +++ b/app/views/line_items/_line_item_fields.html.erb @@ -0,0 +1,34 @@ + + <%= f.hidden_field :id %> + <%= f.hidden_field :_destroy %> + + + <%= f.text_field :description, + size: 50, + placeholder: "Description", + :no_label => true %> + + + + <%= f.number_field :quantity, + step: 1, + min: 1, + style: "width:90px;", + :no_label => true %> + + + + <%= f.number_field :unit_price, + step: 0.01, + style: "width:120px;", + :no_label => true %> + + + + + + \ No newline at end of file diff --git a/assets/javascripts/nested_form_controller.js b/assets/javascripts/nested_form_controller.js new file mode 100644 index 0000000..fdb3264 --- /dev/null +++ b/assets/javascripts/nested_form_controller.js @@ -0,0 +1,53 @@ +(function () { + function initNestedForms() { + document.querySelectorAll("[data-nested-form]").forEach(function (wrapper) { + if (wrapper.dataset.initialized === "true") return; + wrapper.dataset.initialized = "true"; + + const container = wrapper.querySelector("[data-nested-form-container]"); + const template = wrapper.querySelector("[data-nested-form-template]"); + + if (!container || !template) return; + + wrapper.addEventListener("click", function (event) { + const addButton = event.target.closest("[data-nested-form-add]"); + const removeButton = event.target.closest("[data-nested-form-remove]"); + + // ADD + if (addButton) { + event.preventDefault(); + + const content = template.innerHTML.replace( + /NEW_RECORD/g, + Date.now().toString() + ); + + container.insertAdjacentHTML("beforeend", content); + } + + // REMOVE + if (removeButton) { + event.preventDefault(); + + const lineItem = removeButton.closest(wrapper.dataset.wrapperSelector); + if (!lineItem) return; + + const destroyField = lineItem.querySelector("input[name*='_destroy']"); + + if (destroyField) { + destroyField.value = "1"; + lineItem.style.display = "none"; + } else { + lineItem.remove(); + } + } + }); + }); + } + + // Works for full load + document.addEventListener("DOMContentLoaded", initNestedForms); + + // Works for Turbo navigation + document.addEventListener("turbo:load", initNestedForms); +})(); \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..8147395 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,15 @@ +#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: + label_item: "Item" + \ No newline at end of file diff --git a/db/migrate/001_create_line_items.rb b/db/migrate/001_create_line_items.rb new file mode 100644 index 0000000..9d1d795 --- /dev/null +++ b/db/migrate/001_create_line_items.rb @@ -0,0 +1,42 @@ +#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 CreateLineItems < ActiveRecord::Migration[7.0] + def change + create_table :line_items do |t| + t.integer :issue_id, null: false + + t.text :description, null: false + + t.decimal :quantity, + precision: 15, + scale: 4, + null: false, + default: 0 + + t.decimal :unit_price, + precision: 15, + scale: 4, + null: false, + default: 0 + + t.decimal :line_total, + precision: 15, + scale: 4, + null: false, + default: 0 + + t.timestamps + end + + add_index :line_items, :issue_id + add_foreign_key :line_items, :issues + end +end \ No newline at end of file diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..2ee18f9 --- /dev/null +++ b/init.rb @@ -0,0 +1,40 @@ +#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_lineitems do + + # About + name 'Redmine QBO Line Items plugin' + author 'Rick Barrette' + description 'A plugin for Redmine to extend the capabilitys of the Redmine QuickBooks Online plugin to attach billable line items to an isuue' + version '2026.3.0' + url 'https://github.com/rickbarrette/redmine_qbo' + 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.3.0' + 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 :line_items_attributes + +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/redmine_qbo_line_items/hooks/view_hook_listener.rb b/lib/redmine_qbo_line_items/hooks/view_hook_listener.rb new file mode 100644 index 0000000..7b3ba96 --- /dev/null +++ b/lib/redmine_qbo_line_items/hooks/view_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 RedmineQboLineItems + module Hooks + + class ViewHookListener < Redmine::Hook::ViewListener + + # Load the javascript to support the autocomplete forms + def view_layouts_base_html_head(context = {}) + safe_join([ + javascript_include_tag( 'nested_form_controller.js', plugin: :redmine_qbo_lineitems) + ]) + end + + def view_issues_form_details_bottom(context = {}) + context[:controller].send(:render_to_string, { + partial: 'line_items/issue_form', + locals: { + f: context[:form] + } + } + ) + end + + + end + end +end \ No newline at end of file diff --git a/lib/redmine_qbo_line_items/patches/issue_patch.rb b/lib/redmine_qbo_line_items/patches/issue_patch.rb new file mode 100644 index 0000000..ccc155a --- /dev/null +++ b/lib/redmine_qbo_line_items/patches/issue_patch.rb @@ -0,0 +1,40 @@ +#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 RedmineQboLineItems + module Patches + module IssuePatch + + def self.included(base) + base.extend(ClassMethods) + base.send(:include, InstanceMethods) + + base.class_eval do + has_many :line_items, dependent: :destroy + accepts_nested_attributes_for :line_items, allow_destroy: true + end + + end + + module ClassMethods + + end + + module InstanceMethods + + end + + end + + Issue.send(:include, IssuePatch) + end +end \ No newline at end of file