Initial line item idea

This commit is contained in:
2026-03-01 15:04:25 -05:00
parent b95a3b6623
commit eb6beea5fa
12 changed files with 2716 additions and 28 deletions

View File

7
app/models/line_item.rb Normal file
View File

@@ -0,0 +1,7 @@
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

View File

@@ -7,3 +7,6 @@
<p> <p>
<%= select_estimate %> <%= select_estimate %>
</p> </p>
<%= render "line_items/issue_form" %>

View File

@@ -0,0 +1,13 @@
<div class="line-item">
<%= f.hidden_field :id %>
<%= f.text_field :description, placeholder: "Description" %>
<%= f.number_field :quantity, step: 1 ,placeholder: "Quantity"%>
<%= f.number_field :unit_price, step: 0.01, placeholder: "Unit Price" %>
<%= f.hidden_field :_destroy %>
<button type="button" data-action="nested-form#remove">
Remove
</button>
</div>

View File

@@ -0,0 +1,31 @@
<%= form_with model: @issue do |f| %>
<!-- Existing issue fields -->
<h3>Invoice Line Items</h3>
<div
data-controller="nested-form"
data-nested-form-wrapper-selector-value=".line-item"
>
<div data-nested-form-target="container">
<%= f.fields_for :invoice_line_items do |item_form| %>
<%= render "line_items/invoice_line_item_fields", f: item_form %>
<% end %>
</div>
<template data-nested-form-target="template">
<%= f.fields_for :invoice_line_items,
LineItem.new,
child_index: "NEW_RECORD" do |item_form| %>
<%= render "line_items/invoice_line_item_fields", f: item_form %>
<% end %>
</template>
<button type="button" data-action="nested-form#add">
Add Line Item
</button>
</div>
<%= f.submit %>
<% end %>

View File

@@ -0,0 +1,9 @@
document.addEventListener("DOMContentLoaded", () => {
if (typeof Stimulus === "undefined") {
console.error("Stimulus is not loaded. Make sure the UMD script is included first.");
return;
}
const application = Stimulus.Application.start();
application.register("nested-form", window.NestedFormController);
});

View File

@@ -0,0 +1,19 @@
(function() {
class NestedFormController extends Stimulus.Controller {
static targets = ["container", "template"]
add(event) {
event.preventDefault();
const content = this.templateTarget.innerHTML.replace(/NEW_RECORD/g, new Date().getTime());
this.containerTarget.insertAdjacentHTML("beforeend", content);
}
remove(event) {
event.preventDefault();
event.target.closest(".nested-fields").remove();
}
}
// Expose globally so index.js can access it
window.NestedFormController = NestedFormController;
})();

File diff suppressed because it is too large Load Diff

View File

@@ -1,26 +0,0 @@
#The License
#
#Copyright (c) 2016 - 2026 Rick Barrette - All Rights Reserved
#
#Unauthorized copying of this software and associated documentation files (the "Software"), via any medium is strictly prohibited.
#
#Proprietary and confidential
#
#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[5.1]
def change
create_table :line_items do |t|
t.integer :item_id
t.float :amount
t.string :description
t.float :unit_price
t.float :quantity
t.boolean :billed
end
add_reference :line_items, :issues, index: true
end
end

View File

@@ -12,6 +12,5 @@ class RemoveQboItems < ActiveRecord::Migration[5.1]
def change def change
drop_table :qbo_items drop_table :qbo_items
drop_table :qbo_purchases drop_table :qbo_purchases
drop_table :line_items
end end
end end

View File

@@ -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

View File

@@ -16,9 +16,12 @@ module RedmineQbo
# Load the javascript to support the autocomplete forms # Load the javascript to support the autocomplete forms
def view_layouts_base_html_head(context = {}) def view_layouts_base_html_head(context = {})
safe_join([ safe_join([
'<script src="https://unpkg.com/@hotwired/stimulus/dist/stimulus.umd.js"></script>'.html_safe,
javascript_include_tag( 'application.js', plugin: :redmine_qbo), javascript_include_tag( 'application.js', plugin: :redmine_qbo),
javascript_include_tag( 'autocomplete-rails.js', plugin: :redmine_qbo), javascript_include_tag( 'autocomplete-rails.js', plugin: :redmine_qbo),
javascript_include_tag( 'checkbox_controller.js', plugin: :redmine_qbo) javascript_include_tag( 'checkbox_controller.js', plugin: :redmine_qbo),
javascript_include_tag( 'index.js', plugin: :redmine_qbo),
javascript_include_tag( 'nested_form_controller.js', plugin: :redmine_qbo)
]) ])
end end