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>
This commit is contained in:
commit
6fcd5f9b64
44 files changed
+2661
No files matched your search
@@ -0,0 +1,23 @@
|
||||
#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 CreateCommissionReps < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
# A sales rep who earns the monthly commission
|
||||
create_table :commission_reps do |t|
|
||||
t.integer :user_id, null: false
|
||||
# No commission for a month that starts on or before this day (90-day probation)
|
||||
t.date :probation_until
|
||||
t.boolean :active, null: false, default: true
|
||||
t.timestamps
|
||||
end
|
||||
add_index :commission_reps, :user_id, unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,37 @@
|
||||
#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 CreateCommissionMonths < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
# A commission month: the approver's choices while it's open, and its totals once it's approved
|
||||
create_table :commission_months do |t|
|
||||
# The month's first day
|
||||
t.date :month_start, null: false
|
||||
# open or approved
|
||||
t.string :status, null: false, default: 'open'
|
||||
# The deductions (["credit_memo:123"]) and reps (user ids) the approver unticked, as JSON
|
||||
t.text :excluded_keys
|
||||
t.text :unpaid_user_ids
|
||||
t.text :notes
|
||||
# As approved: sales without tax, deductions, the sales the commission is on, each rep's commission
|
||||
t.decimal :gross_sales, precision: 15, scale: 2
|
||||
t.decimal :deductions, precision: 15, scale: 2
|
||||
t.decimal :net_sales, precision: 15, scale: 2
|
||||
t.decimal :pool, precision: 15, scale: 2
|
||||
# The threshold and brackets it was approved with ([[limit, rate]], as JSON)
|
||||
t.decimal :threshold, precision: 15, scale: 2
|
||||
t.text :brackets
|
||||
t.integer :approved_by_id
|
||||
t.datetime :approved_at
|
||||
t.timestamps
|
||||
end
|
||||
add_index :commission_months, :month_start, unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,30 @@
|
||||
#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 CreateCommissionLines < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
# A QuickBooks transaction as it counted toward an approved month
|
||||
create_table :commission_lines do |t|
|
||||
t.integer :commission_month_id, null: false
|
||||
# invoice, sales_receipt, refund_receipt or credit_memo
|
||||
t.string :kind, null: false
|
||||
t.string :txn_id, null: false
|
||||
t.string :doc_number
|
||||
t.string :customer_name
|
||||
# The day an invoice was paid in full, or the transaction's date
|
||||
t.date :txn_date
|
||||
t.decimal :total, precision: 15, scale: 2, null: false, default: 0
|
||||
t.decimal :tax, precision: 15, scale: 2, null: false, default: 0
|
||||
# Whether a deduction was ticked (sales always count)
|
||||
t.boolean :included, null: false, default: true
|
||||
end
|
||||
add_index :commission_lines, :commission_month_id
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,23 @@
|
||||
#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 CreateCommissionAdjustments < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
# A deduction added by hand (negative: sales added back)
|
||||
create_table :commission_adjustments do |t|
|
||||
t.integer :commission_month_id, null: false
|
||||
t.string :description, null: false
|
||||
t.decimal :amount, precision: 15, scale: 2, null: false
|
||||
t.integer :author_id
|
||||
t.timestamps
|
||||
end
|
||||
add_index :commission_adjustments, :commission_month_id
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,24 @@
|
||||
#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 CreateCommissionPayouts < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
# A rep's commission for an approved month, or why they weren't paid
|
||||
create_table :commission_payouts do |t|
|
||||
t.integer :commission_month_id, null: false
|
||||
t.integer :user_id, null: false
|
||||
t.decimal :amount, precision: 15, scale: 2, null: false, default: 0
|
||||
t.boolean :eligible, null: false, default: true
|
||||
t.string :reason
|
||||
t.timestamps
|
||||
end
|
||||
add_index :commission_payouts, [:commission_month_id, :user_id], unique: true
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user