mirror of
https://github.com/rickbarrette/redmine_qbo_lineitems.git
synced 2026-04-02 15:11:58 -04:00
Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ This plugin allows **billable line items** to be attached to a Redmine issue. Wh
|
|||||||
|
|
||||||
| Plugin Version | Redmine Version | Ruby Version |
|
| Plugin Version | Redmine Version | Ruby Version |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| 2026.3.2+ | 6.1.x | 3.2+ |
|
| 2026.3.5+ | 6.1.x | 3.2+ |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ Before using this plugin:
|
|||||||
|
|
||||||
> The MIT License (MIT)
|
> 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:
|
> 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:
|
||||||
>
|
>
|
||||||
|
|||||||
79
app/controllers/items_controller.rb
Normal file
79
app/controllers/items_controller.rb
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
#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]
|
||||||
|
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@item.destroy
|
||||||
|
redirect_to items_path, notice: l(:notice_successful_delete)
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def index
|
||||||
|
@items = Item.order(:name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@item = Item.new
|
||||||
|
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])
|
||||||
|
end
|
||||||
|
|
||||||
|
def item_params
|
||||||
|
params.require(:item).permit(:name, :description, :sku, :unit_price, :active)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#The MIT License (MIT)
|
#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:
|
#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:
|
||||||
#
|
#
|
||||||
@@ -46,7 +46,7 @@ class BillLineItemsJob < ActiveJob::Base
|
|||||||
|
|
||||||
estimate = Quickbooks::Model::Estimate.new(customer_id: issue.customer.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_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.line_items << Quickbooks::Model::InvoiceLineItem.new(description: "#{I18n.t(:notice_added_from)}#{issue.id} #{issue.subject}", detail_type: 'DescriptionOnly' )
|
||||||
|
|
||||||
unbilled_entries.each do |item|
|
unbilled_entries.each do |item|
|
||||||
log "Creating Line Item for #{item.description}"
|
log "Creating Line Item for #{item.description}"
|
||||||
|
|||||||
36
app/jobs/item_sync_job.rb
Normal file
36
app/jobs/item_sync_job.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.
|
||||||
|
|
||||||
|
class ItemSyncJob < ApplicationJob
|
||||||
|
queue_as :default
|
||||||
|
retry_on StandardError, wait: 5.minutes, attempts: 5
|
||||||
|
|
||||||
|
# Performs a sync of items from QuickBooks Online.
|
||||||
|
def perform(full_sync: false, id: nil)
|
||||||
|
qbo = QboConnectionService.current!
|
||||||
|
raise "No QBO configuration found" unless qbo
|
||||||
|
|
||||||
|
log "Starting #{full_sync ? 'full' : 'incremental'} sync for item ##{id || 'all'}..."
|
||||||
|
|
||||||
|
service = ItemSyncService.new(qbo: qbo)
|
||||||
|
|
||||||
|
if id.present?
|
||||||
|
service.sync_by_id(id)
|
||||||
|
else
|
||||||
|
service.sync(full_sync: full_sync)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def log(msg)
|
||||||
|
Rails.logger.info "[ItemSyncJob] #{msg}"
|
||||||
|
end
|
||||||
|
end
|
||||||
115
app/models/item.rb
Normal file
115
app/models/item.rb
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
#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 < ApplicationRecord
|
||||||
|
belongs_to :issue
|
||||||
|
|
||||||
|
validates_presence_of :id, :description
|
||||||
|
validates :unit_price, numericality: { greater_than_or_equal_to: 0 }
|
||||||
|
self.primary_key = :id
|
||||||
|
|
||||||
|
# Returns the details of the item. If the details have already been fetched, it returns the cached version. Otherwise, it fetches the details from QuickBooks Online and caches them for future use. This method is used to access the item's information in a way that minimizes unnecessary API calls to QBO, improving performance and reducing latency.
|
||||||
|
def details
|
||||||
|
@details ||= begin
|
||||||
|
xml = Rails.cache.fetch(details_cache_key, expires_in: 10.minutes) do
|
||||||
|
fetch_details.to_xml_ns
|
||||||
|
end
|
||||||
|
Quickbooks::Model::Item.from_xml(xml)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Generates a unique cache key for storing this customer's QBO details.
|
||||||
|
def details_cache_key
|
||||||
|
"item:#{id}:qbo_details:#{updated_at.to_i}"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# Updates Both local & remote DB description
|
||||||
|
def description=(s)
|
||||||
|
details
|
||||||
|
@details.description = s
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the last sync time formatted for display. If no sync has occurred, returns a default message.
|
||||||
|
def self.last_sync
|
||||||
|
return I18n.t(:label_qbo_never_synced) unless maximum(:updated_at)
|
||||||
|
format_time(maximum(:updated_at))
|
||||||
|
end
|
||||||
|
|
||||||
|
# Magic Method
|
||||||
|
# Maps Get/Set methods to QBO item object
|
||||||
|
def method_missing(method_name, *args, &block)
|
||||||
|
if Quickbooks::Model::Item.method_defined?(method_name)
|
||||||
|
details
|
||||||
|
@details.public_send(method_name, *args, &block)
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Updates Both local & remote DB name
|
||||||
|
def name=(s)
|
||||||
|
details
|
||||||
|
@details.name = s
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
# Updates Both local & remote DB sku
|
||||||
|
def sku=(s)
|
||||||
|
details
|
||||||
|
@details.sku = s
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
# Sync all items, typically triggered by a scheduled task or manual sync request
|
||||||
|
def self.sync
|
||||||
|
ItemSyncJob.perform_later(full_sync: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Sync a single items by ID, typically triggered by a webhook notification or manual sync request
|
||||||
|
def self.sync_by_id(id)
|
||||||
|
ItemSyncJob.perform_later(id: id)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Push the updates
|
||||||
|
def save_with_push
|
||||||
|
log "Starting push for item ##{self.id}..."
|
||||||
|
qbo = QboConnectionService.current!
|
||||||
|
ItemService.new(qbo: qbo, item: self).push()
|
||||||
|
Rails.cache.delete(details_cache_key)
|
||||||
|
save_without_push
|
||||||
|
end
|
||||||
|
|
||||||
|
alias_method :save_without_push, :save
|
||||||
|
alias_method :save, :save_with_push
|
||||||
|
|
||||||
|
# Updates Both local & remote DB price
|
||||||
|
def unit_price=(s)
|
||||||
|
details
|
||||||
|
@details.unit_price = s
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def log(msg)
|
||||||
|
Rails.logger.info "[Item] #{msg}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Fetches the item's details from QuickBooks Online.
|
||||||
|
def fetch_details
|
||||||
|
log "Fetching details for item ##{id} from QBO..."
|
||||||
|
qbo = QboConnectionService.current!
|
||||||
|
ItemService.new(qbo: qbo, item: self).pull()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#The MIT License (MIT)
|
#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:
|
#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
|
class LineItem < ApplicationRecord
|
||||||
belongs_to :issue
|
belongs_to :issue
|
||||||
|
belongs_to :item, optional: true
|
||||||
|
|
||||||
validates :description, presence: true
|
validates :description, presence: true
|
||||||
validates :quantity, numericality: { greater_than: 0 }
|
validates :quantity, numericality: { greater_than: 0 }
|
||||||
|
|||||||
93
app/services/item_service.rb
Normal file
93
app/services/item_service.rb
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
#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
|
||||||
|
|
||||||
|
# Initializes the service with a QBO client and an optional item record. The QBO client is used to communicate with QuickBooks Online, while the item record contains the data that needs to be pushed to QBO. If no item is provided, the service will not perform any operations.
|
||||||
|
def initialize(qbo:, item: nil)
|
||||||
|
raise "No QBO configuration found" unless qbo
|
||||||
|
raise "Item record is required for push operation" unless item
|
||||||
|
@qbo = qbo
|
||||||
|
@item = item
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_qbo_item
|
||||||
|
log "Building new QBO Item"
|
||||||
|
account = default_income_account
|
||||||
|
log "Account: #{account.id} - #{account.name}"
|
||||||
|
income = Quickbooks::Model::BaseReference.new
|
||||||
|
income.value = account.id
|
||||||
|
income.name = account.name
|
||||||
|
|
||||||
|
Quickbooks::Model::Item.new(
|
||||||
|
type: Quickbooks::Model::Item::NON_INVENTORY_TYPE,
|
||||||
|
income_account_ref: income
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_income_account
|
||||||
|
log "Looking up sales income account"
|
||||||
|
qbo = QboConnectionService.current!
|
||||||
|
qbo.perform_authenticated_request do |token|
|
||||||
|
service = Quickbooks::Service::Account.new(
|
||||||
|
company_id: qbo.realm_id,
|
||||||
|
access_token: token
|
||||||
|
)
|
||||||
|
service.query("SELECT * FROM Account WHERE AccountType='Income' AND Name LIKE '%Sales%'").first
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Pulls the Item data from QuickBooks Online.
|
||||||
|
def pull
|
||||||
|
return Quickbooks::Model::Item.new unless @item.present?
|
||||||
|
return build_qbo_item unless @item.id
|
||||||
|
log "Fetching details for item ##{@item.id} from QBO..."
|
||||||
|
qbo = QboConnectionService.current!
|
||||||
|
qbo.perform_authenticated_request do |access_token|
|
||||||
|
service = Quickbooks::Service::Item.new(
|
||||||
|
company_id: qbo.realm_id,
|
||||||
|
access_token: access_token
|
||||||
|
)
|
||||||
|
service.fetch_by_id(@item.id)
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
log "Fetch failed for #{@item.id}: #{e.message}"
|
||||||
|
build_qbo_item
|
||||||
|
end
|
||||||
|
|
||||||
|
# Pushes the Item data to QuickBooks Online. This method handles the communication with QBO, including authentication and error handling. It uses the QBO client to send the item data and logs the process for monitoring and debugging purposes. If the push is successful, it returns the item record; otherwise, it logs the error and returns false.
|
||||||
|
def push
|
||||||
|
log "Pushing item ##{@item.id} to QBO..."
|
||||||
|
|
||||||
|
item = @qbo.perform_authenticated_request do |access_token|
|
||||||
|
service = Quickbooks::Service::Item.new(
|
||||||
|
company_id: @qbo.realm_id,
|
||||||
|
access_token: access_token
|
||||||
|
)
|
||||||
|
if @item.id.present?
|
||||||
|
service.update(@item.details)
|
||||||
|
else
|
||||||
|
service.create(@item.details)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@item.id = item.id unless @item.persisted?
|
||||||
|
log "Push for item ##{@item.id} completed."
|
||||||
|
return @item
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Log messages with the entity type for better traceability
|
||||||
|
def log(msg)
|
||||||
|
Rails.logger.info "[ItemService] #{msg}"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
40
app/services/item_sync_service.rb
Normal file
40
app/services/item_sync_service.rb
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#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 relevant attributes from the QBO Employee to the local Employee model
|
||||||
|
def process_attributes(local, remote)
|
||||||
|
log "Processing Item ##{remote.id}"
|
||||||
|
local.id = remote.id
|
||||||
|
local.description = remote.description
|
||||||
|
local.unit_price = remote.unit_price
|
||||||
|
local.active = remote.active?
|
||||||
|
local.name = remote.name
|
||||||
|
local.sku = remote.sku
|
||||||
|
end
|
||||||
|
|
||||||
|
def log(msg)
|
||||||
|
Rails.logger.info "[ItemSyncService] #{msg}"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
43
app/views/items/_form.html.erb
Normal file
43
app/views/items/_form.html.erb
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<%= form_with model: @item, local: true do |f| %>
|
||||||
|
|
||||||
|
<% if @item.errors.any? %>
|
||||||
|
<div id="errorExplanation">
|
||||||
|
<h2><%= pluralize(@item.errors.count, "error") %></h2>
|
||||||
|
<ul>
|
||||||
|
<% @item.errors.full_messages.each do |msg| %>
|
||||||
|
<li><%= msg %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= f.label :name %><br>
|
||||||
|
<%= f.text_field :name, required: true %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= f.label :sku %><br>
|
||||||
|
<%= f.text_field :sku %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= f.label :description %><br>
|
||||||
|
<%= f.text_area :description, rows: 3 %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= f.label :unit_price %><br>
|
||||||
|
<%= f.number_field :unit_price, step: 0.01 %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= f.label :active %>
|
||||||
|
<%= f.check_box :active %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= f.submit %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
5
app/views/items/edit.html.erb
Normal file
5
app/views/items/edit.html.erb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<h2>Edit Item</h2>
|
||||||
|
|
||||||
|
<%= render "form" %>
|
||||||
|
|
||||||
|
<%= link_to "Back", items_path %>
|
||||||
37
app/views/items/index.html.erb
Normal file
37
app/views/items/index.html.erb
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<h2>Items</h2>
|
||||||
|
|
||||||
|
<div class="contextual">
|
||||||
|
<%= link_to "New Item", new_item_path, class: "icon icon-add" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table class="list items">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>SKU</th>
|
||||||
|
<th>Description</th>
|
||||||
|
<th>Price</th>
|
||||||
|
<th>Active</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
<% @items.each do |item| %>
|
||||||
|
<tr>
|
||||||
|
<td><%= link_to item.name, item_path(item) %></td>
|
||||||
|
<td><%= item.sku %></td>
|
||||||
|
<td><%= item.description %></td>
|
||||||
|
<td><%= number_to_currency(item.unit_price) %></td>
|
||||||
|
<td><%= item.active ? "Yes" : "No" %></td>
|
||||||
|
<td>
|
||||||
|
<%= link_to "Edit", edit_item_path(item), class: "icon icon-edit" %>
|
||||||
|
<%= link_to "Delete", item_path(item),
|
||||||
|
method: :delete,
|
||||||
|
data: { confirm: "Are you sure?" },
|
||||||
|
class: "icon icon-del" %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
5
app/views/items/new.html.erb
Normal file
5
app/views/items/new.html.erb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<h2>New Item</h2>
|
||||||
|
|
||||||
|
<%= render "form" %>
|
||||||
|
|
||||||
|
<%= link_to "Back", items_path %>
|
||||||
26
app/views/items/show.html.erb
Normal file
26
app/views/items/show.html.erb
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<h2><%= @item.name %></h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>SKU:</strong>
|
||||||
|
<%= @item.sku %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Description:</strong>
|
||||||
|
<%= @item.description %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Unit Price:</strong>
|
||||||
|
<%= number_to_currency(@item.unit_price) %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Active:</strong>
|
||||||
|
<%= @item.active ? "Yes" : "No" %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= link_to "Edit", edit_item_path(@item), class: "icon icon-edit" %>
|
||||||
|
<%= link_to "Back", items_path %>
|
||||||
|
</p>
|
||||||
@@ -6,14 +6,15 @@
|
|||||||
data-nested-form
|
data-nested-form
|
||||||
data-wrapper-selector=".line-item">
|
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">
|
<table class="list line-items-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th><%= t :label_description %></th>
|
<th style="width:60%;"><%= t :label_description %></th>
|
||||||
<th style="width:120px;"><%= t :label_qty %></th>
|
<th style="width:10%;"><%= t :label_qty %></th>
|
||||||
<th style="width:150px;"><%= t :label_price %></th>
|
<th style="width:10%;"><%= t :label_price %></th>
|
||||||
|
<th style="width:10%;"><%= t :label_total %></th>
|
||||||
<% unless readonly %>
|
<% unless readonly %>
|
||||||
<th style="width:80px;"></th>
|
<th style="width:80px;"></th>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -29,6 +30,11 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<p class="line-items-grand-total">
|
||||||
|
<strong><%= t :label_total %>:</strong>
|
||||||
|
<span id="line-items-grand-total">0.00</span>
|
||||||
|
</p>
|
||||||
|
|
||||||
<% unless readonly %>
|
<% unless readonly %>
|
||||||
<template data-nested-form-template>
|
<template data-nested-form-template>
|
||||||
<%= f.fields_for :line_items, LineItem.new, child_index: "NEW_RECORD" do |item_form| %>
|
<%= f.fields_for :line_items, LineItem.new, child_index: "NEW_RECORD" do |item_form| %>
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
<table class="list line-items-table">
|
<table class="list line-items-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th><%= t :label_description %></th>
|
<th style="width:70%;"><%= t :label_description %></th>
|
||||||
<th style="width:120px;"><%= t :label_qty %></th>
|
<th style="width:10%;"><%= t :label_qty %></th>
|
||||||
<th style="width:150px;"><%= t :label_price %></th>
|
<th style="width:10%;"><%= t :label_price %></th>
|
||||||
<th style="width:150px;"><%= t :label_total %></th>
|
<th style="width:10%;"><%= t :label_total %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
|
|||||||
@@ -1,37 +1,45 @@
|
|||||||
<tr class="line-item">
|
<tr class="line-item">
|
||||||
<%= f.hidden_field :id %>
|
<%= f.hidden_field :id %>
|
||||||
<%= f.hidden_field :_destroy %>
|
<%= f.hidden_field :_destroy %>
|
||||||
|
<%= f.hidden_field :item_id, class: "item-id-field" %>
|
||||||
|
|
||||||
<td>
|
<td data-label="<%= t :label_description %>">
|
||||||
<%= f.text_field :description,
|
<%= f.text_field :description,
|
||||||
size: 50,
|
|
||||||
placeholder: l(:label_description),
|
placeholder: l(:label_description),
|
||||||
|
class: "line-item-description",
|
||||||
|
autocomplete: "off",
|
||||||
no_label: true,
|
no_label: true,
|
||||||
disabled: readonly %>
|
disabled: readonly %>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td>
|
<td data-label="<%= t :label_qty %>">
|
||||||
<%= f.number_field :quantity,
|
<%= f.number_field :quantity,
|
||||||
step: 1,
|
step: 1,
|
||||||
min: 0,
|
min: 1,
|
||||||
style: "width:90px;",
|
value: (f.object.quantity.to_i > 0) ? f.object.quantity : 1,
|
||||||
|
class: "qty-field",
|
||||||
no_label: true,
|
no_label: true,
|
||||||
disabled: readonly %>
|
disabled: readonly %>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td>
|
<td data-label="<%= t :label_price %>">
|
||||||
<%= f.number_field :unit_price,
|
<%= f.text_field :unit_price,
|
||||||
step: 0.01,
|
class: "price-field",
|
||||||
style: "width:120px;",
|
inputmode: "decimal",
|
||||||
|
autocomplete: "off",
|
||||||
no_label: true,
|
no_label: true,
|
||||||
disabled: readonly %>
|
disabled: readonly %>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
<td class="line-total" data-label="<%= t :label_total %>">
|
||||||
|
0.00
|
||||||
|
</td>
|
||||||
|
|
||||||
<% unless readonly %>
|
<% unless readonly %>
|
||||||
<td style="text-align:center;">
|
<td class="actions">
|
||||||
<button type="button"
|
<button type="button"
|
||||||
class="icon-only icon-del"
|
class="icon-only icon-del"
|
||||||
title="<%=l(:label_remove)%>"
|
title="<%= l(:label_remove) %>"
|
||||||
data-nested-form-remove>
|
data-nested-form-remove>
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
6
app/views/line_items/_settings.html.erb
Normal file
6
app/views/line_items/_settings.html.erb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<div>
|
||||||
|
<b><%=t(:label_item_count)%></b> <%= Item.count %> @ <%= Item.last_sync %>
|
||||||
|
<br/>
|
||||||
|
<%=t(:label_last_sync)%> </b> <%= Qbo.last_sync if Qbo.exists? %>
|
||||||
|
</div>
|
||||||
|
<%= link_to t(:label_sync_now), sync_items_path %>
|
||||||
93
assets/javascripts/autocomplete.js
Normal file
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
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
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();
|
||||||
|
});
|
||||||
@@ -22,7 +22,11 @@
|
|||||||
Date.now().toString()
|
Date.now().toString()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//container.insertAdjacentHTML("beforeend", content);
|
||||||
container.insertAdjacentHTML("beforeend", content);
|
container.insertAdjacentHTML("beforeend", content);
|
||||||
|
|
||||||
|
// initialize autocomplete on the new row
|
||||||
|
initLineItemAutocomplete(container.lastElementChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
// REMOVE
|
// REMOVE
|
||||||
@@ -50,4 +54,11 @@
|
|||||||
|
|
||||||
// Works for Turbo navigation
|
// Works for Turbo navigation
|
||||||
document.addEventListener("turbo:load", initNestedForms);
|
document.addEventListener("turbo:load", initNestedForms);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
$(document).on("input", ".line-item-description", function(){
|
||||||
|
|
||||||
|
let row = $(this).closest(".line-item");
|
||||||
|
row.find(".item-id-field").val("");
|
||||||
|
|
||||||
|
});
|
||||||
76
assets/stylesheets/line_items.css
Normal file
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)
|
#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:
|
#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:
|
||||||
#
|
#
|
||||||
@@ -13,9 +13,11 @@
|
|||||||
en:
|
en:
|
||||||
label_description: "Description"
|
label_description: "Description"
|
||||||
label_item: "Item"
|
label_item: "Item"
|
||||||
|
label_item_count: "Item Count:"
|
||||||
label_line_items: "Line Items"
|
label_line_items: "Line Items"
|
||||||
label_price: "Unit Price"
|
label_price: "Unit Price"
|
||||||
label_qty: "Quantity"
|
label_qty: "Quantity"
|
||||||
label_remove: "Remove"
|
label_remove: "Remove"
|
||||||
label_total: "Total"
|
label_total: "Total"
|
||||||
|
notice_added_from: "Added from issue #"
|
||||||
|
|
||||||
16
config/routes.rb
Normal file
16
config/routes.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.
|
||||||
|
|
||||||
|
resources :items do
|
||||||
|
collection do
|
||||||
|
get :autocomplete
|
||||||
|
get :sync
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#The MIT License (MIT)
|
#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:
|
#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
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
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
|
||||||
10
init.rb
10
init.rb
@@ -1,6 +1,6 @@
|
|||||||
#The MIT License (MIT)
|
#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:
|
#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,21 +14,21 @@ Redmine::Plugin.register :redmine_qbo_lineitems do
|
|||||||
name 'Redmine QBO Line Items plugin'
|
name 'Redmine QBO Line Items plugin'
|
||||||
author 'Rick Barrette'
|
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'
|
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'
|
version '2026.3.6'
|
||||||
url 'https://github.com/rickbarrette/redmine_qbo'
|
url 'https://github.com/rickbarrette/redmine_qbo_lineitems'
|
||||||
author_url 'https://barrettefabrication.com'
|
author_url 'https://barrettefabrication.com'
|
||||||
requires_redmine version_or_higher: '6.1.0'
|
requires_redmine version_or_higher: '6.1.0'
|
||||||
|
settings partial: 'line_items/settings'
|
||||||
|
|
||||||
# Ensure redmine_qbo is installed
|
# Ensure redmine_qbo is installed
|
||||||
begin
|
begin
|
||||||
requires_redmine_plugin :redmine_qbo, version_or_higher: '2026.3.0'
|
requires_redmine_plugin :redmine_qbo, version_or_higher: '2026.3.5'
|
||||||
rescue Redmine::PluginNotFound
|
rescue Redmine::PluginNotFound
|
||||||
raise 'Please install the redmine_qbo plugin (https://github.com/rickbarrette/redmine_qbo)'
|
raise 'Please install the redmine_qbo plugin (https://github.com/rickbarrette/redmine_qbo)'
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add safe attributes for core models
|
# Add safe attributes for core models
|
||||||
Issue.safe_attributes :line_items_attributes
|
Issue.safe_attributes :line_items_attributes
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Dynamically load all Hooks & Patches recursively
|
# Dynamically load all Hooks & Patches recursively
|
||||||
|
|||||||
36
lib/redmine_qbo_line_items/hooks/qbo_hook_listener.rb
Normal file
36
lib/redmine_qbo_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 RedmineQboLineItems
|
||||||
|
module Hooks
|
||||||
|
|
||||||
|
class QboHookListener < Redmine::Hook::ViewListener
|
||||||
|
|
||||||
|
# Called by WebhookProcessJob
|
||||||
|
def qbo_additional_entities(context={})
|
||||||
|
log "Added QBO Item to allowed webook entities"
|
||||||
|
return "Item"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Called by the QboSyncDispatcher
|
||||||
|
def qbo_full_sync (context={})
|
||||||
|
log "Adding ItemSyncJob to QBO sync dispatcher"
|
||||||
|
return ItemSyncJob
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def log(msg)
|
||||||
|
Rails.logger.info "[QboHookListener] #{msg}"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#The MIT License (MIT)
|
#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:
|
#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:
|
||||||
#
|
#
|
||||||
@@ -16,11 +16,15 @@ module RedmineQboLineItems
|
|||||||
# 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([
|
||||||
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
|
end
|
||||||
|
|
||||||
def view_issues_form_details_bottom(context = {})
|
def view_issues_edit_notes_bottom(context = {})
|
||||||
context[:controller].send(:render_to_string, {
|
context[:controller].send(:render_to_string, {
|
||||||
partial: 'line_items/issue_form',
|
partial: 'line_items/issue_form',
|
||||||
locals: {
|
locals: {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#The MIT License (MIT)
|
#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:
|
#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:
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user