Files
redmine_qbo/lib/redmine_qbo_billing/man_hours.rb
T
Claude 062ef9b8b3 Cache totals, man-hours and payments; add a business report
- Estimates now keep their total; estimates and invoices keep their man-hours: the quantities of the
  products/services set as "Replaced by imported time" (bundles included; the estimate item codes
  while that setting is blank). Filled in by the webhook and the sync.
- Payment model (QboBaseModel) caching each payment's customer, date, amount and unapplied amount,
  kept current by the webhook, the sync and the Receive payment page.
- Business report (View business reports permission, top menu): estimates written vs. invoices written
  vs. payments received, and estimated hours on estimates and issues vs. invoiced and spent hours, for
  a period, with a month-by-month breakdown.
- Fix two keyword arguments that defaulted to themselves (QboSyncDispatcher.enque_jobs, PdfService),
  which newer Ruby refuses to parse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
2026-10-31 07:54:28 -04:00

50 lines
2.5 KiB
Ruby

#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 RedmineQboBilling
# The man-hours on a QuickBooks estimate or invoice: the quantities of its lines whose product/service is set
# as "Replaced by imported time" (e.g. Labor), including lines inside bundles. While that setting is blank,
# lines matching the estimate item codes are counted instead (counting every line would include parts).
module ManHours
module_function
def hours(document, item_ids: InvoiceWriter.replaceable_item_ids, codes: nil)
return 0.0 if document.nil?
ids = Array(item_ids).map(&:to_s).reject(&:blank?)
codes ||= EstimateIssueBuilder.item_codes if ids.empty?
sum_lines(document.line_items, ids, codes).round(2)
end
def sum_lines(lines, ids, codes)
Array(lines).sum do |line|
group = line.respond_to?(:group_line_detail) ? line.group_line_detail : nil
next sum_lines(group.line_items, ids, codes) if group
detail = sales_detail(line)
next 0.0 unless detail&.item_ref && man_hour_item?(detail.item_ref, ids, codes)
detail.quantity.to_f
end
end
def sales_detail(line)
if line.respond_to?(:sales_line_item_detail) then line.sales_line_item_detail
elsif line.respond_to?(:sales_item_line_detail) then line.sales_item_line_detail
end
end
def man_hour_item?(ref, ids, codes)
return ids.include?(ref.value.to_s) if ids.any?
EstimateIssueBuilder.item_matches?(ref.name, codes)
end
end
end