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,68 @@
|
||||
#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.
|
||||
|
||||
# Administration » Bonus technicians: who earns the weekly bonus, their role and their QuickBooks customer account
|
||||
class BonusTechniciansController < ApplicationController
|
||||
layout 'admin'
|
||||
self.main_menu = false
|
||||
menu_item :bonus_technicians
|
||||
|
||||
before_action :require_admin
|
||||
before_action :find_technician, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@technicians = BonusTechnician.sorted.includes(:customer).to_a
|
||||
end
|
||||
|
||||
def new
|
||||
@technician = BonusTechnician.new
|
||||
end
|
||||
|
||||
def create
|
||||
@technician = BonusTechnician.new(technician_params)
|
||||
if @technician.save
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
redirect_to bonus_technicians_path
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def edit; end
|
||||
|
||||
def update
|
||||
if @technician.update(technician_params)
|
||||
flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to bonus_technicians_path
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@technician.destroy
|
||||
flash[:notice] = l(:notice_successful_delete)
|
||||
redirect_to bonus_technicians_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_technician
|
||||
@technician = BonusTechnician.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def technician_params
|
||||
permitted = params.require(:bonus_technician).permit(:user_id, :customer_id, :role, :probation_until, :active)
|
||||
permitted[:customer_id] = permitted[:customer_id].presence if permitted.key?(:customer_id)
|
||||
permitted
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
@@ -0,0 +1,44 @@
|
||||
#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
|
||||
@@ -0,0 +1,67 @@
|
||||
#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 BonusTechnician < ApplicationRecord
|
||||
# The SOP's roles, by their bonus amounts (RedmineQboBonus::Settings.amount)
|
||||
ROLES = %w[technician foreman].freeze
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :customer, optional: true
|
||||
has_many :credits, class_name: 'TechBonusCredit', foreign_key: :user_id, primary_key: :user_id
|
||||
|
||||
validates :user_id, presence: true, uniqueness: true
|
||||
validates :role, inclusion: { in: ROLES }
|
||||
validate :customer_exists
|
||||
|
||||
scope :active, -> { where(active: true) }
|
||||
scope :sorted, -> { includes(:user).order(Arel.sql('users.firstname, users.lastname')).references(:users) }
|
||||
|
||||
def self.role_options
|
||||
ROLES.map { |role| [I18n.t("label_bonus_role_#{role}"), role] }
|
||||
end
|
||||
|
||||
def role_name
|
||||
I18n.t("label_bonus_role_#{role}")
|
||||
end
|
||||
|
||||
def name
|
||||
user&.name.to_s
|
||||
end
|
||||
|
||||
# In the 90-day probation during the week (no bonus that week)
|
||||
def on_probation?(week)
|
||||
probation_until.present? && probation_until >= week.start_date
|
||||
end
|
||||
|
||||
# Why the technician can't get a bonus for the week (attendance aside), or nil
|
||||
def ineligible_reason(week)
|
||||
return I18n.t(:text_tech_bonus_inactive) unless active?
|
||||
return I18n.t(:text_tech_bonus_probation, date: I18n.l(probation_until)) if on_probation?(week)
|
||||
return I18n.t(:text_tech_bonus_no_customer) if customer.nil?
|
||||
|
||||
nil
|
||||
end
|
||||
|
||||
def base_amount
|
||||
RedmineQboBonus::Settings.amount(role)
|
||||
end
|
||||
|
||||
def tier_amount
|
||||
RedmineQboBonus::Settings.tier_amount(role)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def customer_exists
|
||||
return if customer_id.blank?
|
||||
|
||||
errors.add(:customer_id, :invalid) unless Customer.exists?(id: customer_id)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,33 @@
|
||||
#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 TechBonusCredit < ApplicationRecord
|
||||
STATUSES = %w[created emailed skipped failed].freeze
|
||||
|
||||
belongs_to :tech_bonus_week
|
||||
belongs_to :user
|
||||
belongs_to :customer, optional: true
|
||||
|
||||
validates :user_id, uniqueness: { scope: :tech_bonus_week_id }
|
||||
validates :status, inclusion: { in: STATUSES }
|
||||
|
||||
# A credit memo was made in QuickBooks (whether or not it was emailed)
|
||||
def credited?
|
||||
credit_memo_id.present?
|
||||
end
|
||||
|
||||
def amount
|
||||
base_amount.to_d + tier_amount.to_d
|
||||
end
|
||||
|
||||
def status_name
|
||||
I18n.t("label_tech_bonus_status_#{status}")
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
@@ -0,0 +1,32 @@
|
||||
<%= error_messages_for @technician %>
|
||||
<% taken = BonusTechnician.where.not(id: @technician.id).pluck(:user_id) %>
|
||||
<% users = User.active.sorted.where.not(id: taken).to_a %>
|
||||
<% users << @technician.user if @technician.user && !users.include?(@technician.user) %>
|
||||
<div class="box tabular">
|
||||
<p>
|
||||
<%= f.select :user_id, users.map { |user| [user.name, user.id] }, { include_blank: true, required: true, label: :field_user },
|
||||
{ disabled: @technician.persisted? } %>
|
||||
</p>
|
||||
<p>
|
||||
<label for="bonus_technician_customer_name"><%= l(:label_bonus_technician_customer) %></label>
|
||||
<%= text_field_tag 'customer_name', @technician.customer&.name, id: 'bonus_technician_customer_name',
|
||||
class: 'customer-name', autocomplete: 'off', size: 40, placeholder: l(:label_choose_a_customer),
|
||||
data: { autocomplete_url: '/customers/autocomplete' } %>
|
||||
<%= f.hidden_field :customer_id, id: 'customer_id' %>
|
||||
<em class="info"><%= l(:text_bonus_technician_customer) %></em>
|
||||
</p>
|
||||
<p><%= f.select :role, BonusTechnician.role_options, required: true %></p>
|
||||
<p>
|
||||
<%= f.date_field :probation_until, label: :field_bonus_technician_probation_until %>
|
||||
<em class="info"><%= l(:text_bonus_technician_probation) %></em>
|
||||
</p>
|
||||
<p><%= f.check_box :active %></p>
|
||||
</div>
|
||||
<%= javascript_tag do %>
|
||||
$(function() {
|
||||
if (window.initCustomerAutocomplete) { window.initCustomerAutocomplete(document); }
|
||||
$('#bonus_technician_customer_name').on('input', function() {
|
||||
if (!$(this).val()) { $('#customer_id').val(''); }
|
||||
});
|
||||
});
|
||||
<% end %>
|
||||
@@ -0,0 +1,8 @@
|
||||
<h2><%= link_to l(:label_bonus_technician_plural), bonus_technicians_path %> » <%= @technician.name %></h2>
|
||||
|
||||
<%= labelled_form_for @technician, url: bonus_technician_path(@technician), method: :patch do |f| %>
|
||||
<%= render partial: 'bonus_technicians/form', locals: { f: f } %>
|
||||
<%= submit_tag l(:button_save) %>
|
||||
<% end %>
|
||||
|
||||
<% html_title @technician.name %>
|
||||
@@ -0,0 +1,45 @@
|
||||
<div class="contextual">
|
||||
<%= link_to sprite_icon('add', l(:label_bonus_technician_new)), new_bonus_technician_path, class: 'icon icon-add' %>
|
||||
<%= link_to sprite_icon('settings', l(:label_settings)), plugin_settings_path('redmine_qbo_bonus'), class: 'icon icon-settings' %>
|
||||
</div>
|
||||
|
||||
<h2><%= l(:label_bonus_technician_plural) %></h2>
|
||||
|
||||
<p><em class="info"><%= l(:text_bonus_technicians) %></em></p>
|
||||
|
||||
<% if @technicians.empty? %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% else %>
|
||||
<div class="autoscroll">
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= l(:label_user) %></th>
|
||||
<th><%= l(:field_role) %></th>
|
||||
<th><%= l(:label_bonus_technician_customer) %></th>
|
||||
<th><%= l(:field_bonus_technician_probation_until) %></th>
|
||||
<th><%= l(:field_active) %></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @technicians.each do |tech| %>
|
||||
<tr>
|
||||
<td class="name"><%= link_to_user tech.user %></td>
|
||||
<td><%= tech.role_name %></td>
|
||||
<td><%= tech.customer ? link_to(tech.customer.name, customer_path(tech.customer)) : content_tag(:span, l(:text_tech_bonus_no_customer), class: 'tech-bonus-error') %></td>
|
||||
<td><%= format_date(tech.probation_until) %></td>
|
||||
<td><%= checked_image tech.active? %></td>
|
||||
<td class="buttons">
|
||||
<%= link_to sprite_icon('edit', l(:button_edit)), edit_bonus_technician_path(tech), class: 'icon icon-edit' %>
|
||||
<%= link_to sprite_icon('del', l(:button_delete)), bonus_technician_path(tech), method: :delete,
|
||||
data: { confirm: l(:text_are_you_sure) }, class: 'icon icon-del' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% html_title l(:label_bonus_technician_plural) %>
|
||||
@@ -0,0 +1,8 @@
|
||||
<h2><%= link_to l(:label_bonus_technician_plural), bonus_technicians_path %> » <%= l(:label_bonus_technician_new) %></h2>
|
||||
|
||||
<%= labelled_form_for @technician, url: bonus_technicians_path do |f| %>
|
||||
<%= render partial: 'bonus_technicians/form', locals: { f: f } %>
|
||||
<%= submit_tag l(:button_create) %>
|
||||
<% end %>
|
||||
|
||||
<% html_title l(:label_bonus_technician_new) %>
|
||||
@@ -0,0 +1,84 @@
|
||||
<%# Settings for redmine_qbo_bonus (Administration » Plugins » Configure) %>
|
||||
<% s = RedmineQboBonus::Settings %>
|
||||
<% field = ->(key) { "settings[#{key}]" } %>
|
||||
|
||||
<p>
|
||||
<%= link_to sprite_icon('user', l(:label_bonus_technician_plural)), bonus_technicians_path, class: 'icon icon-user' %>
|
||||
<%= link_to sprite_icon('time', l(:label_tech_bonus_plural)), tech_bonuses_path, class: 'icon icon-time' %>
|
||||
</p>
|
||||
|
||||
<fieldset class="box tabular">
|
||||
<legend><%= l(:label_tech_bonus_hours_counted) %></legend>
|
||||
<p>
|
||||
<label for="qbo_bonus_projects"><%= l(:label_project_plural) %></label>
|
||||
<%= hidden_field_tag "#{field.call('project_ids')}[]", '', id: nil %>
|
||||
<%= select_tag "#{field.call('project_ids')}[]",
|
||||
project_tree_options_for_select(Project.active.sorted.to_a, selected: Project.where(id: s.project_ids).to_a),
|
||||
multiple: true, size: 8, id: 'qbo_bonus_projects' %>
|
||||
<em class="info"><%= l(:text_tech_bonus_projects) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="qbo_bonus_subprojects"><%= l(:label_tech_bonus_include_subprojects) %></label>
|
||||
<%= hidden_field_tag field.call('include_subprojects'), '0', id: nil %>
|
||||
<%= check_box_tag field.call('include_subprojects'), '1', s.include_subprojects?, id: 'qbo_bonus_subprojects' %>
|
||||
</p>
|
||||
<p>
|
||||
<label for="qbo_bonus_trackers"><%= l(:label_tracker_plural) %></label>
|
||||
<%= select_tag field.call('tracker_mode'),
|
||||
options_for_select([[l(:label_tech_bonus_trackers_exclude), 'exclude'], [l(:label_tech_bonus_trackers_include), 'include']], s.tracker_mode),
|
||||
id: 'qbo_bonus_tracker_mode' %><br>
|
||||
<%= hidden_field_tag "#{field.call('tracker_ids')}[]", '', id: nil %>
|
||||
<%= select_tag "#{field.call('tracker_ids')}[]", options_from_collection_for_select(Tracker.sorted, :id, :name, s.tracker_ids),
|
||||
multiple: true, size: 8, id: 'qbo_bonus_trackers' %>
|
||||
<em class="info"><%= l(:text_tech_bonus_trackers) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="qbo_bonus_users"><%= l(:label_tech_bonus_users) %></label>
|
||||
<%= hidden_field_tag "#{field.call('user_ids')}[]", '', id: nil %>
|
||||
<%= select_tag "#{field.call('user_ids')}[]", options_from_collection_for_select(User.active.sorted, :id, :name, s.user_ids),
|
||||
multiple: true, size: 8, id: 'qbo_bonus_users' %>
|
||||
<em class="info"><%= l(:text_tech_bonus_users) %></em>
|
||||
</p>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="box tabular">
|
||||
<legend><%= l(:label_tech_bonus_target) %></legend>
|
||||
<p>
|
||||
<label for="qbo_bonus_goal"><%= l(:label_tech_bonus_goal_hours) %></label>
|
||||
<%= number_field_tag field.call('goal_hours'), RedmineQboBonus.format_hours(s.goal_hours), id: 'qbo_bonus_goal', min: 0, step: 0.25, style: 'width: 6em' %>
|
||||
<em class="info"><%= l(:text_tech_bonus_goal) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="qbo_bonus_tier"><%= l(:label_tech_bonus_tier_hours) %></label>
|
||||
<%= number_field_tag field.call('tier_hours'), RedmineQboBonus.format_hours(s.tier_hours), id: 'qbo_bonus_tier', min: 0.25, step: 0.25, style: 'width: 6em' %>
|
||||
<em class="info"><%= l(:text_tech_bonus_tier) %></em>
|
||||
</p>
|
||||
<% BonusTechnician::ROLES.each do |role| %>
|
||||
<p>
|
||||
<label for="qbo_bonus_<%= role %>_amount"><%= l("label_bonus_role_#{role}") %></label>
|
||||
<%= number_field_tag field.call("#{role}_amount"), RedmineQboBonus.format_hours(s.amount(role)), id: "qbo_bonus_#{role}_amount", min: 0, step: 0.01, style: 'width: 6em' %>
|
||||
<%= l(:label_tech_bonus_per_tier) %>
|
||||
<%= number_field_tag field.call("#{role}_tier_amount"), RedmineQboBonus.format_hours(s.tier_amount(role)), id: "qbo_bonus_#{role}_tier_amount", min: 0, step: 0.01, style: 'width: 6em' %>
|
||||
</p>
|
||||
<% end %>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="box tabular">
|
||||
<legend><%= l(:label_tech_bonus_credit_memo) %></legend>
|
||||
<p>
|
||||
<label for="qbo_bonus_item"><%= l(:label_tech_bonus_item) %><span class="required"> *</span></label>
|
||||
<%= select_tag field.call('item_id'), options_from_collection_for_select(Item.sellable.order(:name), :id, :name, s.item_id),
|
||||
include_blank: true, id: 'qbo_bonus_item' %>
|
||||
<em class="info"><%= l(:text_tech_bonus_item) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="qbo_bonus_memo"><%= l(:label_tech_bonus_customer_memo) %></label>
|
||||
<%= text_area_tag field.call('customer_memo'), s.customer_memo, id: 'qbo_bonus_memo', rows: 2, cols: 60 %>
|
||||
</p>
|
||||
<p>
|
||||
<label for="qbo_bonus_email"><%= l(:label_tech_bonus_email_credits) %></label>
|
||||
<%= hidden_field_tag field.call('email_credits'), '0', id: nil %>
|
||||
<%= check_box_tag field.call('email_credits'), '1', s.email_credits?, id: 'qbo_bonus_email' %>
|
||||
<em class="info"><%= l(:text_tech_bonus_email_credits) %></em>
|
||||
</p>
|
||||
</fieldset>
|
||||
@@ -0,0 +1,3 @@
|
||||
<% content_for :header_tags do %>
|
||||
<%= stylesheet_link_tag 'qbo_bonus', plugin: 'redmine_qbo_bonus' %>
|
||||
<% end %>
|
||||
@@ -0,0 +1,57 @@
|
||||
<%= render partial: 'tech_bonuses/styles' %>
|
||||
|
||||
<div class="contextual">
|
||||
<% if User.current.admin? %>
|
||||
<%= link_to sprite_icon('user', l(:label_bonus_technician_plural)), bonus_technicians_path, class: 'icon icon-user' %>
|
||||
<%= link_to sprite_icon('settings', l(:label_settings)), plugin_settings_path('redmine_qbo_bonus'), class: 'icon icon-settings' %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<h2><%= l(:label_tech_bonus_plural) %></h2>
|
||||
|
||||
<%= form_tag(tech_bonuses_path, method: :get, id: 'tech-bonus-week-picker', class: 'tech-bonus-picker') do %>
|
||||
<label for="tech_bonus_week"><%= l(:label_tech_bonus_week) %></label>
|
||||
<%= select_tag 'week', options_for_select(@weeks.map { |week| [bonus_week_title(week), week.to_param] }, @week.to_param),
|
||||
id: 'tech_bonus_week' %>
|
||||
<%= submit_tag l(:button_tech_bonus_preview), name: nil %>
|
||||
<% end %>
|
||||
|
||||
<h3><%= l(:label_tech_bonus_history) %></h3>
|
||||
<% if @bonus_weeks.empty? %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% else %>
|
||||
<div class="autoscroll">
|
||||
<table class="list tech-bonus-weeks">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= l(:label_tech_bonus_week) %></th>
|
||||
<th><%= l(:label_tech_bonus_hours_total_goal) %></th>
|
||||
<th><%= l(:label_tech_bonus_tiers) %></th>
|
||||
<th><%= l(:label_tech_bonus_credits) %></th>
|
||||
<th><%= l(:label_tech_bonus_amount) %></th>
|
||||
<th><%= l(:label_tech_bonus_run_by) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @bonus_weeks.each do |bonus_week| %>
|
||||
<tr>
|
||||
<td><%= link_to bonus_week_title(bonus_week.week), tech_bonus_week_path(bonus_week.week.to_param) %></td>
|
||||
<td class="<%= bonus_week.goal_met? ? 'tech-bonus-ok' : 'tech-bonus-miss' %>">
|
||||
<%= bonus_hours(bonus_week.total_hours) %>/<%= bonus_hours(bonus_week.goal_hours) %>
|
||||
</td>
|
||||
<td><%= bonus_week.tiers %></td>
|
||||
<td>
|
||||
<%= bonus_week.credits.count(&:credited?) %>
|
||||
<% failed = bonus_week.credits.count { |credit| credit.status == 'failed' } %>
|
||||
<% if failed.positive? %><span class="tech-bonus-error">(<%= l(:label_tech_bonus_failed_count, count: failed) %>)</span><% end %>
|
||||
</td>
|
||||
<td><%= bonus_money(bonus_week.credited_total) %></td>
|
||||
<td><%= bonus_week.run_by ? link_to_user(bonus_week.run_by) : '' %> <%= format_time(bonus_week.updated_at) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% html_title l(:label_tech_bonus_plural) %>
|
||||
@@ -0,0 +1,153 @@
|
||||
<%= render partial: 'tech_bonuses/styles' %>
|
||||
<% report = @report %>
|
||||
<% previous_week = @week - 1 %>
|
||||
<% next_week = @week + 1 %>
|
||||
|
||||
<div class="contextual">
|
||||
<%= link_to "« #{previous_week.label}", tech_bonus_week_path(previous_week.to_param) %>
|
||||
<% if next_week.start_date <= Date.current %>
|
||||
| <%= link_to "#{next_week.label} »", tech_bonus_week_path(next_week.to_param) %>
|
||||
<% end %>
|
||||
| <%= link_to sprite_icon('time', l(:label_tech_bonus_time_report)), report_time_entries_path(report.redmine_report_params), class: 'icon icon-time' %>
|
||||
</div>
|
||||
|
||||
<h2><%= link_to l(:label_tech_bonus_plural), tech_bonuses_path %> » <%= bonus_week_title(@week) %></h2>
|
||||
|
||||
<div class="tech-bonus-summary">
|
||||
<div class="box">
|
||||
<%= l(:label_tech_bonus_total_hours) %>
|
||||
<span class="value <%= report.goal_met? ? 'tech-bonus-ok' : 'tech-bonus-miss' %>"><%= bonus_hours(report.total_hours) %></span>
|
||||
</div>
|
||||
<div class="box">
|
||||
<%= l(:label_tech_bonus_goal_hours) %>
|
||||
<span class="value"><%= bonus_hours(report.goal_hours) %></span>
|
||||
</div>
|
||||
<div class="box">
|
||||
<%= l(:label_tech_bonus_tiers) %>
|
||||
<span class="value"><%= report.tiers %></span>
|
||||
<%= l(:text_tech_bonus_tier_every, hours: bonus_hours(report.tier_hours)) %>
|
||||
</div>
|
||||
<div class="box">
|
||||
<% if report.goal_met? %>
|
||||
<%= l(:label_tech_bonus_next_tier) %>
|
||||
<% else %>
|
||||
<%= l(:label_tech_bonus_short_of_goal) %>
|
||||
<% end %>
|
||||
<span class="value"><%= bonus_hours(report.hours_to_next_tier) %></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% unless @week.completed? %>
|
||||
<p class="warning"><%= l(:text_tech_bonus_week_in_progress, date: format_date(@week.end_date)) %></p>
|
||||
<% end %>
|
||||
|
||||
<h3><%= l(:label_tech_bonus_technicians) %></h3>
|
||||
<% if report.lines.empty? %>
|
||||
<p class="nodata"><%= l(:text_tech_bonus_no_technicians) %>
|
||||
<% if User.current.admin? %><%= link_to l(:label_bonus_technician_new), new_bonus_technician_path %><% end %></p>
|
||||
<% else %>
|
||||
<%= form_tag tech_bonus_week_path(@week.to_param), method: :post, id: 'tech-bonus-run' do %>
|
||||
<div class="autoscroll">
|
||||
<table class="list tech-bonus-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= l(:label_user) %></th>
|
||||
<th><%= l(:field_role) %></th>
|
||||
<th><%= l(:label_tech_bonus_hours) %></th>
|
||||
<th title="<%= l(:text_tech_bonus_attendance) %>"><%= l(:label_tech_bonus_attended) %></th>
|
||||
<th><%= l(:label_tech_bonus_base) %></th>
|
||||
<th><%= l(:label_tech_bonus_tier_bonus) %></th>
|
||||
<th><%= l(:label_tech_bonus_amount) %></th>
|
||||
<th><%= l(:label_tech_bonus_credit_memo) %></th>
|
||||
<th><%= l(:field_status) %></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% report.lines.each do |line| %>
|
||||
<% tech = line.technician %>
|
||||
<% credit = @credits[tech.user_id] %>
|
||||
<% credited = credit&.credited? %>
|
||||
<tr class="<%= 'ineligible' unless line.eligible? %>">
|
||||
<td class="name"><%= link_to_user tech.user %><br><small><%= tech.customer&.name || l(:text_tech_bonus_no_customer) %></small></td>
|
||||
<td><%= tech.role_name %></td>
|
||||
<td><%= bonus_hours(line.hours) %></td>
|
||||
<td>
|
||||
<% if credited %>
|
||||
<%= sprite_icon('checked', l(:general_text_Yes)) %>
|
||||
<% elsif line.eligible? %>
|
||||
<%= check_box_tag 'attended[]', tech.user_id, credit.nil? || credit.message != l(:text_tech_bonus_missed_shift),
|
||||
id: "attended_#{tech.user_id}", disabled: !report.goal_met? %>
|
||||
<% end %>
|
||||
</td>
|
||||
<% if credited %>
|
||||
<td><%= bonus_money(credit.base_amount) %></td>
|
||||
<td><%= bonus_money(credit.tier_amount) %></td>
|
||||
<td><%= bonus_money(credit.amount) %></td>
|
||||
<% else %>
|
||||
<td><%= bonus_money(line.base_amount) %></td>
|
||||
<td><%= bonus_money(line.tier_amount) %></td>
|
||||
<td><%= bonus_money(line.amount) %></td>
|
||||
<% end %>
|
||||
<td><%= credit_memo_link(credit) %></td>
|
||||
<td class="message">
|
||||
<%= bonus_status_tag(credit) %>
|
||||
<% message = credit&.message.presence || line.ineligible_reason %>
|
||||
<% if credit&.emailed_to.present? %><br><small><%= credit.emailed_to %></small><% end %>
|
||||
<% if message %><br><small><%= message %></small><% end %>
|
||||
</td>
|
||||
<td>
|
||||
<% if credited %>
|
||||
<%= link_to sprite_icon('email', l(:button_tech_bonus_resend)), resend_tech_bonus_credit_path(credit),
|
||||
method: :post, class: 'icon icon-email',
|
||||
data: { confirm: l(:text_tech_bonus_resend_confirm) } %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p><em class="info"><%= l(:text_tech_bonus_attendance) %></em></p>
|
||||
|
||||
<% if @week.completed? %>
|
||||
<p>
|
||||
<% label = report.goal_met? ? l(:button_tech_bonus_run) : l(:button_tech_bonus_record) %>
|
||||
<%= submit_tag label, data: { confirm: report.goal_met? ? l(:text_tech_bonus_run_confirm) : nil } %>
|
||||
<% if @bonus_week %>
|
||||
<em class="info"><%= l(:text_tech_bonus_already_run, user: @bonus_week.run_by&.name, time: format_time(@bonus_week.updated_at)) %></em>
|
||||
<% end %>
|
||||
</p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<h3><%= l(:label_tech_bonus_shop_hours) %></h3>
|
||||
<% if report.hours_by_user.empty? %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% else %>
|
||||
<% tech_ids = report.technicians.map(&:user_id) %>
|
||||
<div class="autoscroll">
|
||||
<table class="list tech-bonus-table">
|
||||
<thead>
|
||||
<tr><th><%= l(:label_user) %></th><th><%= l(:label_tech_bonus_hours) %></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% report.hours_by_user.each do |user_id, hours| %>
|
||||
<tr>
|
||||
<td class="name">
|
||||
<%= report.users[user_id] ? link_to_user(report.users[user_id]) : "##{user_id}" %>
|
||||
<% unless tech_ids.include?(user_id) %><small>(<%= l(:text_tech_bonus_helping) %>)</small><% end %>
|
||||
</td>
|
||||
<td><%= bonus_hours(hours) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr><td class="name"><%= l(:label_total_time) %></td><td><%= bonus_hours(report.total_hours) %></td></tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% html_title "#{l(:label_tech_bonus_plural)} #{@week.label}" %>
|
||||
Reference in new issue
Block a user