Compare commits
66 Commits
2026.3.0
...
50a02cc497
| Author | SHA1 | Date | |
|---|---|---|---|
| 50a02cc497 | |||
| b63e8f2a45 | |||
| 4b561ef4e3 | |||
| 1dadcf37b6 | |||
| ffaee10fef | |||
| 58994e3c7d | |||
| 6365fe6679 | |||
| 4d6c16373a | |||
| 20b7564c38 | |||
| 9820646857 | |||
| 647ce4c63a | |||
| 4367c77393 | |||
| 8c0ce8ce48 | |||
| 9fd1f4fb7d | |||
| cca822c570 | |||
| 795906b4f5 | |||
| d5e59c120c | |||
| e640e61648 | |||
| c968893f94 | |||
| 26f84bd221 | |||
| f59849e6e5 | |||
| 6bf5575f9c | |||
| 2703d6cc3e | |||
| 24e3e4ba82 | |||
| f81fe0ef87 | |||
| a2cc7a97fd | |||
| 7088550184 | |||
| 2302679c3a | |||
| ec1ef72267 | |||
| 564158722d | |||
| 60a7f769ce | |||
| 1367937614 | |||
| 62adcb11cd | |||
| 896813983c | |||
| 89e3048c29 | |||
| a7899fb6b3 | |||
| ef7570fb3b | |||
| 93ae77d9f6 | |||
| ac82d5cf90 | |||
| a52ff3b860 | |||
| 4f8e5d9b2c | |||
| bfdf6b3065 | |||
| 1febdc3e04 | |||
| d1f8f027c0 | |||
| c5dd50a369 | |||
| 92ecf171b9 | |||
| 70dc594cb2 | |||
| 9736f1ac96 | |||
| 3463698f8d | |||
| 3b51c961e3 | |||
| 1780896e84 | |||
| 91cdd86c12 | |||
| e58bbafda7 | |||
| c56aa5897f | |||
| 449910c941 | |||
| 42ea5dffc9 | |||
| ecbfa2620f | |||
| b4512f1a00 | |||
| 30b493e2f9 | |||
| 88b452b889 | |||
| 60fb4e197c | |||
| d3d039f191 | |||
| bb55c45b9b | |||
| 5039e2fcc7 | |||
| 151bbf2d7f | |||
| 67513c527e |
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 - 2026 Rick Barrette
|
||||
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
|
||||
|
||||
17
README.md
@@ -10,8 +10,6 @@ This plugin allows **billable line items** to be attached to a Redmine issue. Wh
|
||||
|
||||
* **Redmine:** 6.1+
|
||||
|
||||
* **Ruby:** 3.2+
|
||||
|
||||
* **Parent Plugin:** [Redmine QuickBooks Online](https://github.com/rickbarrette/redmine_qbo) (must be installed and configured)
|
||||
|
||||
|
||||
@@ -19,9 +17,9 @@ This plugin allows **billable line items** to be attached to a Redmine issue. Wh
|
||||
|
||||
## Compatibility
|
||||
|
||||
| Plugin Version | Redmine Version | Ruby Version |
|
||||
| Plugin Version | Redmine Version | Parent Plugin Version |
|
||||
| --- | --- | --- |
|
||||
| 2026.3.2+ | 6.1.x | 3.2+ |
|
||||
| 2026.3.8+ | 6.1.x | 2026.3.9+ |
|
||||
|
||||
---
|
||||
|
||||
@@ -87,9 +85,10 @@ Before using this plugin:
|
||||
1. Install and configure the parent plugin.
|
||||
|
||||
2. Ensure your **QuickBooks Online** company file is connected.
|
||||
|
||||
3. Verify that the products or services referenced in line items exist in QuickBooks.
|
||||
|
||||
|
||||
3. Sync Accounts & Items via plugin settings
|
||||
|
||||
4. Set default income account for new items via plugin settings
|
||||
|
||||
---
|
||||
|
||||
@@ -108,10 +107,10 @@ Before using this plugin:
|
||||
|
||||
> The MIT License (MIT)
|
||||
>
|
||||
> Copyright (c) 2016 - 2026 Rick Barrette
|
||||
> 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.
|
||||
> 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.
|
||||
|
||||
BIN
Screenshots/Form.png
Normal file
|
After Width: | Height: | Size: 193 KiB |
BIN
Screenshots/Issue View.png
Normal file
|
After Width: | Height: | Size: 337 KiB |
BIN
Screenshots/accounts.png
Normal file
|
After Width: | Height: | Size: 287 KiB |
BIN
Screenshots/edit item.png
Normal file
|
After Width: | Height: | Size: 170 KiB |
BIN
Screenshots/item.png
Normal file
|
After Width: | Height: | Size: 162 KiB |
BIN
Screenshots/items.png
Normal file
|
After Width: | Height: | Size: 368 KiB |
BIN
Screenshots/settings.png
Normal file
|
After Width: | Height: | Size: 166 KiB |
27
app/controllers/accounts_controller.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
#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.
|
||||
|
||||
class AccountsController < ApplicationController
|
||||
|
||||
def index
|
||||
@accounts = Account.where(classification: 'Revenue').order(:name)
|
||||
end
|
||||
|
||||
def set_default
|
||||
account = Account.find(params[:default_account_id])
|
||||
account.update(default: true)
|
||||
redirect_to accounts_path, notice: "Default account updated."
|
||||
end
|
||||
|
||||
def sync
|
||||
Account.sync
|
||||
redirect_to :home, flash: { notice: I18n.t(:label_syncing) }
|
||||
end
|
||||
end
|
||||
109
app/controllers/items_controller.rb
Normal file
@@ -0,0 +1,109 @@
|
||||
#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.
|
||||
|
||||
class ItemsController < ApplicationController
|
||||
before_action :require_login
|
||||
before_action :find_item, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# Used for autocomplete form
|
||||
def autocomplete
|
||||
term = ActiveRecord::Base.sanitize_sql_like(params[:q].to_s)
|
||||
|
||||
items = Item.where("description LIKE :t OR name LIKE :t OR sku LIKE :t", t: "%#{term}%")
|
||||
.where(active: true)
|
||||
.order(:description)
|
||||
.limit(20)
|
||||
|
||||
render json: items.map { |i|
|
||||
{ id: i.id, name: i.name, sku: i.sku, description: i.description, price: i.unit_price }
|
||||
}
|
||||
end
|
||||
|
||||
def create
|
||||
@item = Item.new(item_params)
|
||||
|
||||
if @item.save
|
||||
redirect_to item_path(@item), notice: l(:notice_successful_create)
|
||||
else
|
||||
render :new
|
||||
end
|
||||
rescue => e
|
||||
log "Unexpected error creating item: #{e.message}"
|
||||
|
||||
# Regex now matches across line breaks
|
||||
existing_id = e.message[/Duplicate Name Exists Error:[\s\S]*Id=(\d+)/, 1]&.to_i
|
||||
|
||||
if existing_id
|
||||
flash[:error] = "Name already exists. Redirecting to existing item."
|
||||
redirect_to item_path(existing_id)
|
||||
else
|
||||
flash[:error] = e.message
|
||||
redirect_to new_item_path
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@item.destroy
|
||||
redirect_to items_path, notice: l(:notice_successful_delete)
|
||||
end
|
||||
|
||||
def edit
|
||||
rescue => e
|
||||
log "Failed to edit item"
|
||||
flash[:error] = e.message
|
||||
render_404
|
||||
end
|
||||
|
||||
def index
|
||||
@items = Item.order(:name)
|
||||
end
|
||||
|
||||
def new
|
||||
@item = Item.new
|
||||
@item.taxable.nil? ? true : @item.taxable
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def sync
|
||||
Item.sync
|
||||
redirect_to :home, flash: { notice: I18n.t(:label_syncing) }
|
||||
end
|
||||
|
||||
def update
|
||||
if @item.update(item_params)
|
||||
redirect_to item_path(@item), notice: l(:notice_successful_update)
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_item
|
||||
@item = Item.find(params[:id])
|
||||
rescue => e
|
||||
log "Failed to find item"
|
||||
flash[:error] = e.message
|
||||
render_404
|
||||
end
|
||||
|
||||
def item_params
|
||||
params.require(:item).permit(:name, :description, :sku, :unit_price, :active, :account_id, :type, :taxable)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def log(msg)
|
||||
Rails.logger.info "[ItemsController] #{msg}"
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2016 - 2026 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -45,8 +45,10 @@ class BillLineItemsJob < ActiveJob::Base
|
||||
log "Creating Estimate records in QBO for #{issue.customer.name} from issue ##{issue.id}"
|
||||
|
||||
estimate = Quickbooks::Model::Estimate.new(customer_id: issue.customer.id)
|
||||
estimate_service = Quickbooks::Service::Estimate.new( company_id: qbo.realm_id, access_token: access_token)
|
||||
estimate.line_items << Quickbooks::Model::InvoiceLineItem.new(description: "Added from issue ##{issue.id} #{issue.subject}", detail_type: 'DescriptionOnly' )
|
||||
estimate_service = Quickbooks::Service::Estimate.new( company_id: qbo.realm_id, access_token: access_token)
|
||||
memo = "Added from: #{issue.tracker} ##{issue.id}: #{issue.subject}"
|
||||
estimate.private_note = memo
|
||||
estimate.line_items << Quickbooks::Model::InvoiceLineItem.new(description: memo, detail_type: 'DescriptionOnly' )
|
||||
|
||||
unbilled_entries.each do |item|
|
||||
log "Creating Line Item for #{item.description}"
|
||||
@@ -56,7 +58,10 @@ class BillLineItemsJob < ActiveJob::Base
|
||||
line.sales_item! do |detail|
|
||||
detail.unit_price = item.unit_price
|
||||
detail.quantity = item.quantity
|
||||
detail.tax_code_ref = Quickbooks::Model::BaseReference.new("TAX")
|
||||
# Assign "TAX" only if the item is taxable or unknown
|
||||
if item.item.nil? || item.item.taxable
|
||||
detail.tax_code_ref = Quickbooks::Model::BaseReference.new("TAX")
|
||||
end
|
||||
end
|
||||
|
||||
estimate.line_items << line
|
||||
@@ -66,8 +71,6 @@ class BillLineItemsJob < ActiveJob::Base
|
||||
log "Created estimate ##{e.doc_number}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def log(msg)
|
||||
Rails.logger.info "[BillLineItemsJob] #{msg}"
|
||||
end
|
||||
|
||||
41
app/models/account.rb
Normal file
@@ -0,0 +1,41 @@
|
||||
#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.
|
||||
|
||||
class Account < QboBaseModel
|
||||
has_many :items
|
||||
validates_presence_of :id, :name
|
||||
self.primary_key = :id
|
||||
qbo_sync push: false
|
||||
before_save :clear_other_defaults, if: :default?
|
||||
|
||||
# Returns the account marked as default
|
||||
def self.get_default
|
||||
find_by(default: true)
|
||||
end
|
||||
|
||||
# Returns QBO Refrence object for the account
|
||||
def ref
|
||||
r = Quickbooks::Model::BaseReference.new
|
||||
r.value = id
|
||||
r.name = name
|
||||
return r
|
||||
end
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def clear_other_defaults
|
||||
Account.where.not(id: id).update_all(default: false)
|
||||
end
|
||||
|
||||
end
|
||||
72
app/models/item.rb
Normal file
@@ -0,0 +1,72 @@
|
||||
#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.
|
||||
|
||||
class Item < QboBaseModel
|
||||
belongs_to :issue
|
||||
belongs_to :account
|
||||
|
||||
validates_presence_of :id, :description
|
||||
validates :unit_price, numericality: { greater_than_or_equal_to: 0 }
|
||||
self.primary_key = :id
|
||||
self.inheritance_column = :_type_disabled
|
||||
qbo_sync push: true
|
||||
after_initialize :set_defaults, if: :new_record?
|
||||
before_destroy :make_inactive
|
||||
|
||||
# Updates Both local & remote DB account ref
|
||||
def account_id=(id)
|
||||
details.income_account_ref = Account.find(id).ref
|
||||
super
|
||||
end
|
||||
|
||||
# Updates Both local & remote DB description
|
||||
def description=(s)
|
||||
details.description = s
|
||||
super
|
||||
end
|
||||
|
||||
# Updates Both local & remote DB name
|
||||
def name=(s)
|
||||
details.name = s
|
||||
super
|
||||
end
|
||||
|
||||
def make_inactive
|
||||
details.active = false
|
||||
push_to_qbo
|
||||
end
|
||||
|
||||
def ref
|
||||
Quickbooks::Model::BaseReference.new
|
||||
end
|
||||
|
||||
def set_defaults
|
||||
self.taxable = true if taxable.nil?
|
||||
end
|
||||
|
||||
# Updates Both local & remote DB sku
|
||||
def sku=(s)
|
||||
details.sku = s
|
||||
super
|
||||
end
|
||||
|
||||
# Updates Both local & remote DB type
|
||||
def type=(s)
|
||||
details.type = s.to_s
|
||||
super
|
||||
end
|
||||
|
||||
# Updates Both local & remote DB price
|
||||
def unit_price=(s)
|
||||
details.unit_price = s
|
||||
super
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2016 - 2026 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
class LineItem < ApplicationRecord
|
||||
belongs_to :issue
|
||||
belongs_to :item, optional: true
|
||||
|
||||
validates :description, presence: true
|
||||
validates :quantity, numericality: { greater_than: 0 }
|
||||
|
||||
23
app/services/account_sync_service.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.
|
||||
|
||||
class AccountSyncService < SyncServiceBase
|
||||
|
||||
private
|
||||
|
||||
# Specify the local model this service syncs
|
||||
def self.model_class
|
||||
Account
|
||||
end
|
||||
|
||||
map_attribute :active, :active?
|
||||
map_attributes :classification, :description, :id, :name
|
||||
|
||||
end
|
||||
20
app/services/item_service.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
#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.
|
||||
|
||||
class ItemService < ServiceBase
|
||||
|
||||
private
|
||||
|
||||
def build_qbo_remote
|
||||
log "Building new QBO Item"
|
||||
Quickbooks::Model::Item.new(type: Account.get_default&.ref)
|
||||
end
|
||||
|
||||
end
|
||||
32
app/services/item_sync_service.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
#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.
|
||||
|
||||
class ItemSyncService < SyncServiceBase
|
||||
|
||||
private
|
||||
|
||||
# Specify the local model this service syncs
|
||||
def self.model_class
|
||||
Item
|
||||
end
|
||||
|
||||
# Specify a page size of 20, as the API only returns 20 items at a time.
|
||||
def self.page_size
|
||||
20
|
||||
end
|
||||
|
||||
map_attribute :active, :active?
|
||||
map_attribute :taxable, :taxable?
|
||||
map_attribute :account do |remote|
|
||||
Account.find remote.income_account_ref.value.to_i
|
||||
end
|
||||
map_attributes :description, :id, :name, :sku, :type, :unit_price
|
||||
|
||||
end
|
||||
37
app/views/accounts/index.html.erb
Normal file
@@ -0,0 +1,37 @@
|
||||
<h2><%= l(:label_accounts) %></h2>
|
||||
|
||||
<%= form_tag set_default_accounts_path, method: :patch do %>
|
||||
<div class="autoscroll">
|
||||
<table class="list accounts">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:50px;"><%= l(:label_default) %></th>
|
||||
<th><%= l(:field_name) %></th>
|
||||
<th><%= l(:field_description) %></th>
|
||||
<th><%= l(:field_classification) %></th>
|
||||
<th class="center"><%= l(:field_active) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @accounts.each do |account| %>
|
||||
<tr class="<%= cycle("odd", "even") %>">
|
||||
<td class="center">
|
||||
<%= radio_button_tag "default_account_id", account.id, account.default %>
|
||||
</td>
|
||||
<td class="name"><strong><%= account.name %></strong></td>
|
||||
<td class="description"><%= truncate(account.description, length: 80) %></td>
|
||||
<td class="classification"><%= account.classification %></td>
|
||||
<td class="active center">
|
||||
<%= checked_image account.active %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<p class="buttons">
|
||||
<%= submit_tag l(:button_save), class: 'button-small' %>
|
||||
</p>
|
||||
<% end %>
|
||||
50
app/views/items/_form.html.erb
Normal file
@@ -0,0 +1,50 @@
|
||||
<%= labelled_form_for @item do |f| %>
|
||||
<%= error_messages_for 'item' %>
|
||||
|
||||
<div class="box tabular">
|
||||
<p>
|
||||
<%= f.text_field :name, required: true, size: 60 %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.text_field :sku, size: 30 %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.text_area :description, rows: 4, class: 'wiki-edit' %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.text_field :unit_price,
|
||||
class: "price-field",
|
||||
inputmode: "decimal",
|
||||
autocomplete: "off"%>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.check_box :taxable %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label :account_id, l(:label_account) %>
|
||||
<%= f.collection_select :account_id,
|
||||
Account.where(classification: 'Revenue').order(:name),
|
||||
:id,
|
||||
:name,
|
||||
{ selected: @item.account_id || Account.get_default&.id, include_blank: true } %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.select :type,
|
||||
Quickbooks::Model::Item::ITEM_TYPES.map { |t| [t, t] },
|
||||
{ selected: @item.type || Quickbooks::Model::Item::NON_INVENTORY_TYPE } %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.check_box :active %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<%= submit_tag l(:button_save) %>
|
||||
<%= link_to l(:button_cancel), items_path if controller.action_name == 'edit' %>
|
||||
<% end %>
|
||||
3
app/views/items/edit.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<h2><%=t(:label_edit_item)%></h2>
|
||||
|
||||
<%= render "form" %>
|
||||
56
app/views/items/index.html.erb
Normal file
@@ -0,0 +1,56 @@
|
||||
<div class="contextual">
|
||||
<%= link_to l(:label_item_new), new_item_path, class: 'icon icon-add' %>
|
||||
</div>
|
||||
|
||||
<h2><%= l(:label_items) %></h2>
|
||||
|
||||
<% if @items.any? %>
|
||||
<div class="autoscroll">
|
||||
<table class="list items">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= l(:field_name) %></th>
|
||||
<th><%= l(:field_sku) %></th>
|
||||
<th><%= l(:field_description) %></th>
|
||||
<th><%= l(:field_unit_price) %></th>
|
||||
<th class="center"><%= l(:field_taxable) %></th>
|
||||
<th class="center"><%= l(:field_active) %></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @items.each do |item| %>
|
||||
<tr class="<%= cycle("odd", "even") %>">
|
||||
<td class="name"><%= link_to item.name, item_path(item) %></td>
|
||||
<td class="sku"><%= item.sku %></td>
|
||||
<td class="description"><%= truncate(item.description, length: 60) %></td>
|
||||
<td class="unit_price"><%= number_to_currency(item.unit_price) %></td>
|
||||
<td class="taxable center">
|
||||
<% if item.taxable %>
|
||||
<span class="icon icon-ok" style="color: green;"><%=t(:yes)%></span>
|
||||
<% else %>
|
||||
<span class="icon icon-not-ok" style="color: #999;"><%=t(:no)%></span>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="active center">
|
||||
<% if item.active %>
|
||||
<span class="icon icon-ok" style="color: green;"><%=t(:yes)%></span>
|
||||
<% else %>
|
||||
<span class="icon icon-not-ok" style="color: #999;"><%=t(:no)%></span>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="buttons">
|
||||
<%= link_to l(:button_edit), edit_item_path(item), class: 'icon icon-edit' %>
|
||||
<%= link_to l(:button_delete), item_path(item),
|
||||
method: :delete,
|
||||
data: { confirm: l(:text_are_you_sure) },
|
||||
class: 'icon icon-del' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<% else %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
||||
5
app/views/items/new.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<h2><%=t(:label_item_new)%></h2>
|
||||
|
||||
<%= render "form" %>
|
||||
|
||||
<%= link_to t(:label_back), items_path %>
|
||||
44
app/views/items/show.html.erb
Normal file
@@ -0,0 +1,44 @@
|
||||
<div class="contextual">
|
||||
<%= link_to l(:button_edit), edit_item_path(@item), class: 'icon icon-edit' %>
|
||||
<%= link_to l(:button_back), items_path, class: 'icon icon-list' %>
|
||||
</div>
|
||||
|
||||
<h2><%= t(:item) %># <%= @item.id %> <%= @item.name %></h2>
|
||||
|
||||
<div class="issue details"> <div class="attributes">
|
||||
<div class="splitcontent">
|
||||
<div class="splitcontentleft">
|
||||
<p><strong><%=t(:field_sku)%>:</strong> <%= @item.sku.presence || "-" %></p>
|
||||
<p><strong><%=t(:label_type)%>:</strong> <%= @item.type.presence || "-" %></p>
|
||||
<p><strong><%=t(:field_unit_price)%>:</strong> <%= number_to_currency(@item.unit_price) %></p>
|
||||
</div>
|
||||
|
||||
<div class="splitcontentleft">
|
||||
<p><strong><%=t(:label_account)%>:</strong> <%= @item.account&.name || "-" %></p>
|
||||
<p>
|
||||
<strong><%=t(:field_taxable)%>:</strong>
|
||||
<% if @item.taxable %>
|
||||
<span class="icon icon-ok" style="color: green;"><%=t(:yes)%></span>
|
||||
<% else %>
|
||||
<span class="icon icon-not-ok" style="color: #999;"><%=t(:no)%></span>
|
||||
<% end %>
|
||||
</p>
|
||||
<p>
|
||||
<strong><%=t(:label_active)%>:</strong>
|
||||
<% if @item.active %>
|
||||
<span class="icon icon-ok" style="color: green;"><%=t(:yes)%></span>
|
||||
<% else %>
|
||||
<span class="icon icon-not-ok" style="color: #999;"><%=t(:no)%></span>
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
|
||||
<p><strong><%=t(:label_description)%>:</strong></p>
|
||||
<div class="wiki" style="padding-left: 20px;">
|
||||
<%= @item.description.presence || "<em>No description provided</em>".html_safe %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -6,14 +6,15 @@
|
||||
data-nested-form
|
||||
data-wrapper-selector=".line-item">
|
||||
|
||||
<p><strong><%= t :label_line_items %></strong></p>
|
||||
<strong><%= t :label_line_items %></strong>
|
||||
|
||||
<table class="list line-items-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= t :label_description %></th>
|
||||
<th style="width:120px;"><%= t :label_qty %></th>
|
||||
<th style="width:150px;"><%= t :label_price %></th>
|
||||
<th style="width:60%;"><%= t :label_description %></th>
|
||||
<th style="width:10%;"><%= t :label_qty %></th>
|
||||
<th style="width:10%;"><%= t :label_price %></th>
|
||||
<th style="width:10%;"><%= t :label_total %></th>
|
||||
<% unless readonly %>
|
||||
<th style="width:80px;"></th>
|
||||
<% end %>
|
||||
@@ -29,6 +30,11 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p class="line-items-grand-total">
|
||||
<strong><%= t :label_total %>:</strong>
|
||||
<span id="line-items-grand-total">0.00</span>
|
||||
</p>
|
||||
|
||||
<% unless readonly %>
|
||||
<template data-nested-form-template>
|
||||
<%= f.fields_for :line_items, LineItem.new, child_index: "NEW_RECORD" do |item_form| %>
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
<table class="list line-items-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= t :label_description %></th>
|
||||
<th style="width:120px;"><%= t :label_qty %></th>
|
||||
<th style="width:150px;"><%= t :label_price %></th>
|
||||
<th style="width:150px;"><%= t :label_total %></th>
|
||||
<th style="width:70%;"><%= t :label_description %></th>
|
||||
<th style="width:10%;"><%= t :label_qty %></th>
|
||||
<th style="width:10%;"><%= t :label_price %></th>
|
||||
<th style="width:10%;"><%= t :label_total %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
|
||||
@@ -1,37 +1,45 @@
|
||||
<tr class="line-item">
|
||||
<%= f.hidden_field :id %>
|
||||
<%= f.hidden_field :_destroy %>
|
||||
<%= f.hidden_field :item_id, class: "item-id-field" %>
|
||||
|
||||
<td>
|
||||
<td data-label="<%= t :label_description %>">
|
||||
<%= f.text_field :description,
|
||||
size: 50,
|
||||
placeholder: l(:label_description),
|
||||
class: "line-item-description",
|
||||
autocomplete: "off",
|
||||
no_label: true,
|
||||
disabled: readonly %>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<td data-label="<%= t :label_qty %>">
|
||||
<%= f.number_field :quantity,
|
||||
step: 1,
|
||||
min: 0,
|
||||
style: "width:90px;",
|
||||
min: 1,
|
||||
value: (f.object.quantity.to_i > 0) ? f.object.quantity : 1,
|
||||
class: "qty-field",
|
||||
no_label: true,
|
||||
disabled: readonly %>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<%= f.number_field :unit_price,
|
||||
step: 0.01,
|
||||
style: "width:120px;",
|
||||
<td data-label="<%= t :label_price %>">
|
||||
<%= f.text_field :unit_price,
|
||||
class: "price-field",
|
||||
inputmode: "decimal",
|
||||
autocomplete: "off",
|
||||
no_label: true,
|
||||
disabled: readonly %>
|
||||
</td>
|
||||
|
||||
<td class="line-total" data-label="<%= t :label_total %>">
|
||||
0.00
|
||||
</td>
|
||||
|
||||
<% unless readonly %>
|
||||
<td style="text-align:center;">
|
||||
<td class="actions">
|
||||
<button type="button"
|
||||
class="icon-only icon-del"
|
||||
title="<%=l(:label_remove)%>"
|
||||
title="<%= l(:label_remove) %>"
|
||||
data-nested-form-remove>
|
||||
</button>
|
||||
</td>
|
||||
|
||||
39
app/views/line_items/_settings.html.erb
Normal file
@@ -0,0 +1,39 @@
|
||||
<div class="box tabular">
|
||||
<p>
|
||||
<label><strong><%= t(:label_item_count) %></strong></label>
|
||||
<%= Item.count %>
|
||||
<em style="color: #777; font-size: 0.9em; margin-left: 8px;">
|
||||
(@ <%= Item.last_sync %>)
|
||||
</em>
|
||||
</p>
|
||||
<p>
|
||||
<label><strong><%= t(:label_account_count) %></strong></label>
|
||||
<%= Account.count %>
|
||||
<em style="color: #777; font-size: 0.9em; margin-left: 8px;">
|
||||
(@ <%= Account.last_sync %>)
|
||||
</em>
|
||||
</p>
|
||||
<p>
|
||||
<label><strong><%= t(:label_last_sync) %> (QBO)</strong></label>
|
||||
<%= Qbo.exists? ? Qbo.last_sync : 'Never synced' %>
|
||||
</p>
|
||||
<p>
|
||||
<label><strong><%= t(:label_default_account) %></strong></label>
|
||||
<%= Account.get_default %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<fieldset class="box">
|
||||
<legend>Management & Synchronization</legend>
|
||||
|
||||
<div style="margin-bottom: 15px;">
|
||||
<%= link_to t(:label_sync_now_items), sync_items_path, class: 'button icon icon-reload' %>
|
||||
<%= link_to t(:label_sync_now_accounts), sync_accounts_path, class: 'button icon icon-reload' %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= link_to t(:label_items), items_path, class: 'icon icon-list' %>
|
||||
<span style="margin: 0 10px; color: #ccc;">|</span>
|
||||
<%= link_to t(:label_accounts), accounts_path, class: 'icon icon-list' %>
|
||||
</div>
|
||||
</fieldset>
|
||||
93
assets/javascripts/autocomplete.js
Normal file
@@ -0,0 +1,93 @@
|
||||
(function () {
|
||||
|
||||
window.initLineItemAutocomplete = function(context) {
|
||||
let scope = context || document;
|
||||
|
||||
$(scope).find(".line-item-description").each(function() {
|
||||
if ($(this).data("autocomplete-initialized")) return;
|
||||
$(this).data("autocomplete-initialized", true);
|
||||
|
||||
let ac = $(this).autocomplete({
|
||||
appendTo: "body",
|
||||
minLength: 2,
|
||||
|
||||
source: function(request, response) {
|
||||
$.getJSON("/items/autocomplete", { q: request.term })
|
||||
.done(function(data) {
|
||||
|
||||
response(data.map(function(item) {
|
||||
return {
|
||||
label: item.description,
|
||||
value: item.description,
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
sku: item.sku,
|
||||
description: item.description,
|
||||
price: item.price || 0
|
||||
};
|
||||
}));
|
||||
|
||||
})
|
||||
.fail(function(err){
|
||||
console.error("Autocomplete error:", err);
|
||||
response([]);
|
||||
});
|
||||
},
|
||||
|
||||
select: function(event, ui) {
|
||||
let $input = $(this);
|
||||
let row = $input.closest(".line-item");
|
||||
|
||||
// set description into input
|
||||
$input.val(ui.item.description);
|
||||
|
||||
row.find(".item-id-field").val(ui.item.id);
|
||||
|
||||
if (ui.item.price !== undefined && row.find(".price-field").length) {
|
||||
row.find(".price-field").val(ui.item.price);
|
||||
}
|
||||
|
||||
updateLineItemTotals();
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
change: function(event, ui) {
|
||||
if (!ui.item) {
|
||||
let row = $(this).closest(".line-item");
|
||||
row.find(".item-id-field").val("");
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Custom rendering of autocomplete suggestions
|
||||
ac.autocomplete("instance")._renderItem = function(ul, item) {
|
||||
return $("<li>")
|
||||
.append(
|
||||
"<div class='autocomplete-item'>" +
|
||||
"<div class='item-name'>" + item.name + "</div>" +
|
||||
"<div class='item-sku'>" + item.sku + "</div>" +
|
||||
"<div class='item-description'>" + item.description + "</div>" +
|
||||
"</div>"
|
||||
)
|
||||
.appendTo(ul);
|
||||
};
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
// Clear item_id when user types manually
|
||||
$(document).on("input", ".line-item-description", function(){
|
||||
let row = $(this).closest(".line-item");
|
||||
row.find(".item-id-field").val("");
|
||||
});
|
||||
|
||||
function initializeAutocomplete() {
|
||||
window.initLineItemAutocomplete(document);
|
||||
}
|
||||
|
||||
$(document).ready(initializeAutocomplete);
|
||||
document.addEventListener("turbo:load", initializeAutocomplete);
|
||||
|
||||
})();
|
||||
33
assets/javascripts/blur.js
Normal file
@@ -0,0 +1,33 @@
|
||||
function evaluateMathExpression(expr) {
|
||||
if (!expr) return null;
|
||||
|
||||
// allow only digits, decimal, operators, parentheses, spaces
|
||||
if (!/^[0-9+\-*/().\s]+$/.test(expr)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return Function('"use strict"; return (' + expr + ')')();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("blur", function(e) {
|
||||
|
||||
if (!e.target.classList.contains("price-field")) return;
|
||||
|
||||
const field = e.target;
|
||||
const value = field.value.trim();
|
||||
|
||||
const result = evaluateMathExpression(value);
|
||||
|
||||
if (result !== null && !isNaN(result)) {
|
||||
field.value = Number(result).toFixed(2);
|
||||
}
|
||||
|
||||
if (typeof updateLineItemTotals === "function") {
|
||||
updateLineItemTotals();
|
||||
}
|
||||
|
||||
}, true);
|
||||
58
assets/javascripts/line_items.js
Normal file
@@ -0,0 +1,58 @@
|
||||
function updateLineItemTotals() {
|
||||
let grandTotal = 0;
|
||||
|
||||
document.querySelectorAll(".line-item").forEach(function(row){
|
||||
|
||||
// 1. Look for the Rails _destroy hidden field
|
||||
let destroyInput = row.querySelector("input[name*='[_destroy]']");
|
||||
let isDestroyed = destroyInput && (destroyInput.value === "1" || destroyInput.value === "true");
|
||||
|
||||
// 2. Safely check if the row is hidden via CSS, without relying on physical layout
|
||||
let isHidden = row.style.display === "none" || window.getComputedStyle(row).display === "none";
|
||||
|
||||
// If it's deleted or explicitly hidden, skip calculating it
|
||||
if (isDestroyed || isHidden) {
|
||||
return;
|
||||
}
|
||||
|
||||
let qty = parseFloat(row.querySelector(".qty-field")?.value || 0);
|
||||
let price = parseFloat(row.querySelector(".price-field")?.value || 0);
|
||||
|
||||
let total = qty * price;
|
||||
|
||||
row.querySelector(".line-total").textContent =
|
||||
total.toLocaleString(undefined,{minimumFractionDigits:2,maximumFractionDigits:2});
|
||||
|
||||
grandTotal += total;
|
||||
|
||||
});
|
||||
|
||||
let grand = document.getElementById("line-items-grand-total");
|
||||
|
||||
if(grand){
|
||||
grand.textContent =
|
||||
grandTotal.toLocaleString(undefined,{minimumFractionDigits:2,maximumFractionDigits:2});
|
||||
}
|
||||
}
|
||||
|
||||
// Recalculate on input changes
|
||||
document.addEventListener("input", function(e){
|
||||
if(e.target.classList.contains("qty-field") ||
|
||||
e.target.classList.contains("price-field")){
|
||||
updateLineItemTotals();
|
||||
}
|
||||
});
|
||||
|
||||
// Recalculate when the remove button is clicked
|
||||
document.addEventListener("click", function(e){
|
||||
let removeBtn = e.target.closest("[data-nested-form-remove]");
|
||||
|
||||
if(removeBtn){
|
||||
setTimeout(updateLineItemTotals, 10);
|
||||
}
|
||||
});
|
||||
|
||||
// Initial calculation on load
|
||||
document.addEventListener("DOMContentLoaded", function(){
|
||||
updateLineItemTotals();
|
||||
});
|
||||
@@ -1,3 +1,9 @@
|
||||
let lastKeyWasTab = false;
|
||||
|
||||
document.addEventListener("keydown", function (e) {
|
||||
lastKeyWasTab = (e.key === "Tab");
|
||||
});
|
||||
|
||||
(function () {
|
||||
function initNestedForms() {
|
||||
document.querySelectorAll("[data-nested-form]").forEach(function (wrapper) {
|
||||
@@ -23,6 +29,27 @@
|
||||
);
|
||||
|
||||
container.insertAdjacentHTML("beforeend", content);
|
||||
|
||||
const newRow = container.lastElementChild;
|
||||
|
||||
// Ensure clean state
|
||||
newRow.dataset.autoAdded = "false";
|
||||
|
||||
// Reset defaults
|
||||
const qty = newRow.querySelector(".qty-field");
|
||||
if (qty && !qty.value) qty.value = 1;
|
||||
|
||||
const price = newRow.querySelector(".price-field");
|
||||
if (price) price.value = "";
|
||||
|
||||
// initialize autocomplete
|
||||
initLineItemAutocomplete(newRow);
|
||||
|
||||
// Only focus if NOT tabbing
|
||||
if (!lastKeyWasTab) {
|
||||
const desc = newRow.querySelector(".line-item-description");
|
||||
if (desc) desc.focus();
|
||||
}
|
||||
}
|
||||
|
||||
// REMOVE
|
||||
@@ -50,4 +77,79 @@
|
||||
|
||||
// Works for Turbo navigation
|
||||
document.addEventListener("turbo:load", initNestedForms);
|
||||
})();
|
||||
})();
|
||||
|
||||
|
||||
// Keep your existing behavior
|
||||
$(document).on("input", ".line-item-description", function () {
|
||||
let row = $(this).closest(".line-item");
|
||||
row.find(".item-id-field").val("");
|
||||
});
|
||||
|
||||
|
||||
// -------------------------------
|
||||
// AUTO-ADD NEW ROW LOGIC
|
||||
// -------------------------------
|
||||
|
||||
// Reset autoAdded flag if cleared
|
||||
document.addEventListener("input", function (e) {
|
||||
if (!e.target.classList.contains("line-item-description")) return;
|
||||
|
||||
const row = e.target.closest(".line-item");
|
||||
if (!row) return;
|
||||
|
||||
if (e.target.value.trim() === "") {
|
||||
row.dataset.autoAdded = "false";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Add row when leaving last description (without breaking TAB flow)
|
||||
document.addEventListener("blur", function (e) {
|
||||
if (!e.target.classList.contains("line-item-description")) return;
|
||||
|
||||
const input = e.target;
|
||||
const row = input.closest(".line-item");
|
||||
if (!row) return;
|
||||
|
||||
const wrapper = input.closest("[data-nested-form]");
|
||||
if (!wrapper) return;
|
||||
|
||||
const container = wrapper.querySelector("[data-nested-form-container]");
|
||||
if (!container) return;
|
||||
|
||||
// Active (visible + not destroyed) rows only
|
||||
const rows = Array.from(
|
||||
container.querySelectorAll(wrapper.dataset.wrapperSelector)
|
||||
).filter(r => {
|
||||
const destroy = r.querySelector("input[name*='[_destroy]']");
|
||||
const hidden = window.getComputedStyle(r).display === "none";
|
||||
return !(destroy && destroy.value === "1") && !hidden;
|
||||
});
|
||||
|
||||
const lastRow = rows[rows.length - 1];
|
||||
|
||||
// Only last row
|
||||
if (row !== lastRow) return;
|
||||
|
||||
// Must have content
|
||||
if (input.value.trim() === "") return;
|
||||
|
||||
// Prevent duplicate firing
|
||||
if (row.dataset.autoAdded === "true") return;
|
||||
|
||||
// If TAB, ensure user is leaving the row entirely
|
||||
if (lastKeyWasTab) {
|
||||
const next = document.activeElement;
|
||||
|
||||
if (row.contains(next)) {
|
||||
return; // still inside row → allow normal tabbing
|
||||
}
|
||||
}
|
||||
|
||||
row.dataset.autoAdded = "true";
|
||||
|
||||
const addButton = wrapper.querySelector("[data-nested-form-add]");
|
||||
if (addButton) addButton.click();
|
||||
|
||||
}, true); // capture phase required for blur
|
||||
76
assets/stylesheets/line_items.css
Normal file
@@ -0,0 +1,76 @@
|
||||
.line-items-table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.line-items-table input {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.qty-field {
|
||||
max-width: 90px;
|
||||
}
|
||||
|
||||
.price-field {
|
||||
max-width: 120px;
|
||||
}
|
||||
|
||||
.autocomplete-item {
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.item-name {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.item-sku {
|
||||
font-size: 0.75em;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.item-description {
|
||||
font-size: 0.70em;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* MOBILE MODE */
|
||||
@media screen and (max-width: 700px) {
|
||||
|
||||
.line-items-table thead {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.line-items-table,
|
||||
.line-items-table tbody,
|
||||
.line-items-table tr,
|
||||
.line-items-table td {
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.line-items-table tr {
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 6px;
|
||||
padding: 10px;
|
||||
margin-bottom: 10px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.line-items-table td {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 6px 0;
|
||||
}
|
||||
|
||||
.line-items-table td::before {
|
||||
content: attr(data-label);
|
||||
font-weight: bold;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.line-items-table td.actions {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2016 - 2026 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -11,11 +11,33 @@
|
||||
# English strings go here for Rails i18n
|
||||
# Usage I18n.t(:label)
|
||||
en:
|
||||
field_classification: "Classification"
|
||||
field_sku: "SKU"
|
||||
field_taxable: "Taxable"
|
||||
field_unit_price: "Unit Price"
|
||||
|
||||
label_active: "Activie"
|
||||
label_account: "Account"
|
||||
label_accounts: "Accounts"
|
||||
label_back: "Back"
|
||||
label_account_count: "Number of Accounts:"
|
||||
label_default_account: "Default Item Income Account"
|
||||
label_description: "Description"
|
||||
label_edit_item: "Edit Item"
|
||||
label_item: "Item"
|
||||
label_item_count: "Item Count:"
|
||||
label_items: "Items"
|
||||
label_line_items: "Line Items"
|
||||
label_price: "Unit Price"
|
||||
label_item_new: "New Item"
|
||||
label_no: "No"
|
||||
label_qty: "Quantity"
|
||||
label_remove: "Remove"
|
||||
label_sync_now_accounts: "Sync Accounts"
|
||||
label_sync_now_items: "Sync Items"
|
||||
label_type: "Type"
|
||||
label_total: "Total"
|
||||
label_yes: "Yes"
|
||||
|
||||
notice_added_from: "Added from issue #"
|
||||
|
||||
23
config/routes.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.
|
||||
|
||||
resources :items do
|
||||
collection do
|
||||
get :autocomplete
|
||||
get :sync
|
||||
end
|
||||
end
|
||||
|
||||
resources :accounts do
|
||||
collection do
|
||||
patch :set_default
|
||||
get :sync
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2016 - 2026 rick barrette
|
||||
#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:
|
||||
#
|
||||
|
||||
26
db/migrate/002_create_items.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
#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.
|
||||
|
||||
class CreateItems < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :items do |t|
|
||||
t.text :description, null: false
|
||||
t.decimal :unit_price,
|
||||
precision: 15,
|
||||
scale: 4,
|
||||
null: false,
|
||||
default: 0
|
||||
t.boolean :active, default: true, null: false
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_reference :line_items, :item, foreign_key: true
|
||||
end
|
||||
end
|
||||
16
db/migrate/003_update_items.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
#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.
|
||||
|
||||
class UpdateItems < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :items, :name, :string, null: false
|
||||
add_column :items, :sku, :string
|
||||
end
|
||||
end
|
||||
26
db/migrate/004_create_accounts.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
#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.
|
||||
|
||||
class CreateAccounts < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :accounts do |t|
|
||||
t.text :name, null: false
|
||||
t.text :description
|
||||
t.boolean :active, default: true, null: false
|
||||
t.boolean :default, default: false, null: false
|
||||
t.text :classification
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_reference :items, :account, foreign_key: true
|
||||
add_column :items, :type, :string
|
||||
add_column :items, :taxable, :boolean, null: true
|
||||
end
|
||||
end
|
||||
24
init.rb
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2016 - 2026 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -14,27 +14,29 @@ Redmine::Plugin.register :redmine_qbo_lineitems do
|
||||
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'
|
||||
version '2026.3.12'
|
||||
url 'https://github.com/rickbarrette/redmine_qbo_lineitems'
|
||||
author_url 'https://barrettefabrication.com'
|
||||
requires_redmine version_or_higher: '6.1.0'
|
||||
settings partial: 'line_items/settings'
|
||||
|
||||
# Ensure redmine_qbo is installed
|
||||
begin
|
||||
requires_redmine_plugin :redmine_qbo, version_or_higher: '2026.3.0'
|
||||
requires_redmine_plugin :redmine_qbo, version_or_higher: '2026.3.9'
|
||||
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')
|
||||
# Administration menu extension
|
||||
Redmine::MenuManager.map :admin_menu do |menu|
|
||||
menu.push :redmine_qbo_lineitems, { controller: 'items', action: 'index' },
|
||||
icon: 'list',
|
||||
caption: :label_items,
|
||||
html: { class: 'icon icon-list' }
|
||||
end
|
||||
|
||||
# '**' looks inside subdirectories, '*.rb' matches Ruby files
|
||||
Dir.glob(File.join(base_dir, '**', '*.rb')).sort.each do |file|
|
||||
require file
|
||||
end
|
||||
RedmineQboLineItems.setup
|
||||
@@ -8,10 +8,10 @@
|
||||
#
|
||||
#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 LineItems
|
||||
module Hooks
|
||||
|
||||
class IssuesSaveHookListener < Redmine::Hook::ViewListener
|
||||
class IssuesSaveHookListener < Redmine::Hook::Listener
|
||||
|
||||
# Called After Issue Saved
|
||||
def controller_issues_edit_after_save(context={})
|
||||
36
lib/line_items/hooks/qbo_hook_listener.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
#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 LineItems
|
||||
module Hooks
|
||||
|
||||
class QboHookListener < Redmine::Hook::Listener
|
||||
|
||||
# Called by WebhookProcessJob
|
||||
def qbo_additional_entities(context={})
|
||||
log "Added QBO Item to allowed webook entities"
|
||||
return ["Item", "Account"]
|
||||
end
|
||||
|
||||
# Called by the QboSyncDispatcher
|
||||
def qbo_full_sync (context={})
|
||||
log "Adding Item to QBO sync dispatcher"
|
||||
return [Item, Account]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def log(msg)
|
||||
Rails.logger.info "[QboHookListener] #{msg}"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2016 - 2026 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -8,7 +8,7 @@
|
||||
#
|
||||
#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 LineItems
|
||||
module Hooks
|
||||
|
||||
class ViewHookListener < Redmine::Hook::ViewListener
|
||||
@@ -16,11 +16,16 @@ module RedmineQboLineItems
|
||||
# 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)
|
||||
javascript_include_tag( 'nested_form_controller', plugin: :redmine_qbo_lineitems),
|
||||
javascript_include_tag("line_items", plugin: :redmine_qbo_lineitems),
|
||||
javascript_include_tag("autocomplete", plugin: :redmine_qbo_lineitems),
|
||||
javascript_include_tag("blur", plugin: :redmine_qbo_lineitems),
|
||||
stylesheet_link_tag("line_items", plugin: :redmine_qbo_lineitems)
|
||||
])
|
||||
end
|
||||
|
||||
def view_issues_form_details_bottom(context = {})
|
||||
def view_issues_edit_notes_bottom(context = {})
|
||||
return if context[:issue].closed?
|
||||
context[:controller].send(:render_to_string, {
|
||||
partial: 'line_items/issue_form',
|
||||
locals: {
|
||||
@@ -1,6 +1,6 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2016 - 2026 rick barrette
|
||||
#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:
|
||||
#
|
||||
@@ -8,35 +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 'issue'
|
||||
|
||||
module RedmineQboLineItems
|
||||
module LineItems
|
||||
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,
|
||||
reject_if: proc { |attrs| attrs['description'].blank? }
|
||||
end
|
||||
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
prepended do
|
||||
has_many :line_items, dependent: :destroy
|
||||
accepts_nested_attributes_for :line_items,
|
||||
allow_destroy: true,
|
||||
reject_if: proc { |attrs| attrs['description'].blank? }
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Issue.send(:include, IssuePatch)
|
||||
end
|
||||
end
|
||||
21
lib/redmine_qbo_line_items.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
#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 RedmineQboLineItems
|
||||
|
||||
def self.setup
|
||||
unless Issue.ancestors.include?(LineItems::Patches::IssuePatch)
|
||||
Issue.prepend LineItems::Patches::IssuePatch
|
||||
LineItems::Hooks::IssuesSaveHookListener
|
||||
LineItems::Hooks::QboHookListener
|
||||
LineItems::Hooks::ViewHookListener
|
||||
end
|
||||
end
|
||||
end
|
||||