Files
redmine_qbo_commission/app/models/commission_rep.rb
T
rickyandClaude Opus 5.5 6fcd5f9b64 New plugin: monthly sales commission (SOP-OPS-013)
Reads the month's paid sales from QuickBooks Online (invoices paid in
full that month, sales receipts), deducts refund receipts, credit memos
and adjustments, works out the commission pool with the threshold and
marginal brackets, and records each sales rep's payout once the month
is approved for payroll.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 18:53:25 -05:00

37 lines
1.9 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.
# A sales rep who earns the monthly commission (SOP-OPS-013 §2)
class CommissionRep < ApplicationRecord
belongs_to :user
validates :user_id, presence: true, uniqueness: true
scope :active, -> { where(active: true) }
scope :sorted, -> { includes(:user).order(Arel.sql('users.firstname, users.lastname')).references(:users) }
def name
user&.name.to_s
end
# In the 90-day probation on any day of the month (no commission that month)
def on_probation?(month)
probation_until.present? && probation_until >= month.start_date
end
# Why the rep isn't paid for the month, or nil
def ineligible_reason(month)
return I18n.t(:text_sales_commission_inactive) unless active?
return I18n.t(:text_sales_commission_probation, date: I18n.l(probation_until)) if on_probation?(month)
nil
end
end