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:
commit
a2ecb74c1d
37 files changed
+2274
No files matched your search
@@ -0,0 +1,97 @@
|
||||
#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.
|
||||
|
||||
# Weekly billable hours bonus (SOP-OPS-012): the weeks run so far, a week's hours and bonuses, and running it
|
||||
class TechBonusesController < ApplicationController
|
||||
self.main_menu = false
|
||||
menu_item :tech_bonuses
|
||||
|
||||
before_action :authorize_global
|
||||
before_action :find_week, only: [:show, :create]
|
||||
|
||||
helper :tech_bonuses
|
||||
|
||||
WEEKS_TO_PICK = 12
|
||||
|
||||
def index
|
||||
# The week picker
|
||||
week = RedmineQboBonus::Week.parse(params[:week]) if params[:week].present?
|
||||
return redirect_to(tech_bonus_week_path(week.to_param)) if week
|
||||
|
||||
@bonus_weeks = TechBonusWeek.recent.includes(:credits, :run_by).limit(52).to_a
|
||||
@weeks = (0...WEEKS_TO_PICK).map { |n| RedmineQboBonus::Week.last_completed - n }
|
||||
@week = RedmineQboBonus::Week.last_completed
|
||||
end
|
||||
|
||||
def show
|
||||
@report = RedmineQboBonus::WeekReport.new(@week)
|
||||
@bonus_week = TechBonusWeek.for(@week)
|
||||
@credits = @bonus_week ? @bonus_week.credits.index_by(&:user_id) : {}
|
||||
end
|
||||
|
||||
def create
|
||||
runner = RedmineQboBonus::Runner.new(@week, attended_user_ids: Array(params[:attended]))
|
||||
bonus_week = runner.run
|
||||
credits = bonus_week.credits.to_a
|
||||
if !bonus_week.goal_met?
|
||||
flash[:warning] = l(:notice_tech_bonus_goal_not_met, week: @week.label)
|
||||
elsif credits.any? { |credit| credit.status == 'failed' }
|
||||
flash[:error] = l(:notice_tech_bonus_some_failed)
|
||||
else
|
||||
flash[:notice] = l(:notice_tech_bonus_run, count: credits.count(&:credited?), week: @week.label)
|
||||
end
|
||||
redirect_to tech_bonus_week_path(@week.to_param)
|
||||
rescue RedmineQboBonus::Runner::Error => e
|
||||
flash[:error] = e.message
|
||||
redirect_to tech_bonus_week_path(@week.to_param)
|
||||
end
|
||||
|
||||
# Emails a credit memo again (e.g. after fixing the technician's email in QuickBooks)
|
||||
def resend
|
||||
credit = TechBonusCredit.find(params[:id])
|
||||
week = credit.tech_bonus_week.week
|
||||
unless credit.credited?
|
||||
render_404
|
||||
return
|
||||
end
|
||||
Rails.cache.delete(credit.customer.details_cache_key) if credit.customer
|
||||
email = RedmineQboBonus::Runner.customer_email(credit.customer)
|
||||
if RedmineQboBonus::Runner.email(credit, email)
|
||||
flash[:notice] = l(:notice_tech_bonus_emailed, email: email)
|
||||
else
|
||||
flash[:error] = credit.message
|
||||
end
|
||||
redirect_to tech_bonus_week_path(week.to_param)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# The credit memo as QuickBooks prints it
|
||||
def pdf
|
||||
credit = TechBonusCredit.find(params[:id])
|
||||
return render_404 unless credit.credited?
|
||||
|
||||
pdf = RedmineQboBonus::CreditMemoWriter.pdf(credit.credit_memo_id)
|
||||
send_data pdf, filename: "credit-memo-#{credit.doc_number.presence || credit.credit_memo_id}.pdf",
|
||||
type: 'application/pdf', disposition: 'inline'
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
rescue StandardError => e
|
||||
flash[:error] = e.message
|
||||
redirect_to tech_bonuses_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_week
|
||||
@week = RedmineQboBonus::Week.parse(params[:week])
|
||||
render_404 unless @week
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user