Files
redmine_qbo_bonus/app/helpers/tech_bonuses_helper.rb
rickyandClaude Opus 5.5 a2ecb74c1d 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>
2026-11-16 12:13:30 -05:00

45 lines
2.2 KiB
Ruby
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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 TechBonusesHelper
def bonus_hours(hours)
RedmineQboBonus.format_hours(hours)
end
def bonus_money(amount)
RedmineQboBonus.format_money(amount)
end
# "2026-47 (11/15/2026 – 11/21/2026)"
def bonus_week_title(week)
"#{week.label} (#{format_date(week.start_date)} – #{format_date(week.end_date)})"
end
def credit_memo_url(credit)
host = RedmineQbo.respond_to?(:sandbox_mode?) && RedmineQbo.sandbox_mode? ? 'sandbox' : 'app'
"https://#{host}.qbo.intuit.com/app/creditmemo?txnId=#{credit.credit_memo_id}"
end
def credit_memo_link(credit)
return '' unless credit&.credited?
label = credit.doc_number.present? ? "##{credit.doc_number}" : l(:label_tech_bonus_credit_memo)
safe_join([link_to(label, credit_memo_url(credit), target: '_blank', rel: 'noopener'),
link_to('PDF', tech_bonus_credit_pdf_path(credit), target: '_blank', rel: 'noopener')], ' · ')
end
def bonus_status_tag(credit)
return '' unless credit
css = { 'emailed' => 'tech-bonus-ok', 'created' => 'tech-bonus-ok', 'failed' => 'tech-bonus-error' }
content_tag(:span, credit.status_name, class: "tech-bonus-status #{css[credit.status]}")
end
end