New plugin: weekly technician bonus credit memos (SOP-OPS-012)

Totals the shop's billable hours for a Sunday-Saturday week (picked
projects, trackers and users) against the SOP-OPS-012 target, and
credits each qualifying technician's QuickBooks customer account with a
credit memo: a "Tech Bonus <week> <total>/<goal> hours (total/goal)"
line, plus a separate tier line for every full 15 hours over the goal.
Credit memos are emailed through QuickBooks.

- Bonus technicians (admin): user, QuickBooks customer, role
  (technician/foreman), probation end
- Tech bonuses (global "Run tech bonuses" permission): week preview,
  attendance check, run, PDF and email again; re-running a week never
  credits anyone twice

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-16 12:13:30 -05:00
commit a2ecb74c1d
37 files changed
+2274

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
#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 TechBonusWeek < ApplicationRecord
belongs_to :run_by, class_name: 'User', optional: true
has_many :credits, class_name: 'TechBonusCredit', dependent: :destroy
validates :week_start, presence: true, uniqueness: true
scope :recent, -> { order(week_start: :desc) }
def self.for(week)
find_by(week_start: week.start_date)
end
def week
RedmineQboBonus::Week.new(week_start)
end
def goal_met?
total_hours >= goal_hours
end
# Each user's hours, as { user_id => BigDecimal }
def hours_by_user
JSON.parse(self[:hours_by_user].presence || '{}').to_h { |id, hours| [id.to_i, BigDecimal(hours.to_s)] }
rescue JSON::ParserError
{}
end
def hours_by_user=(hours)
self[:hours_by_user] = hours.to_h { |id, value| [id.to_s, value.to_d.round(2).to_s('F')] }.to_json
end
def credited_total
credits.select(&:credited?).sum(&:amount)
end
end