====== #126 — An employee on the "Commission" salary type has their earnings calculated from gross payments collected, with refunds never subt (Resolved) ====== [[wiki:manara:bugs|← Back to Manara Bugs]] · [[https://mantis.matrixdn.net/view.php?id=126|View issue #126 in MantisBT]] ---- **Reported by:** Nour aboulhosn on 2026-07-28T11:11:40+01:00\\ **Assigned to:** Claude\\ **Resolved by:** Claude on 2026-07-28T12:03:16+01:00\\ **Severity:** major\\ **Priority:** normal\\ **Reproducibility:** have not tried\\ **Category:** General **Description:** Employees can be set to a "Commission" salary type, where Payroll computes what they have earned as a percentage of amounts collected on invoices naming them as "Referred By." As noted under Bug 2, the collected-amount half of this calculation is implemented correctly and scales properly with partial payments. The defect is that the calculation uses **gross** payments and never nets off refunds. I created a fresh employee on a 10% commission rate, a fresh customer, and a $400.00 invoice referred by that employee, then collected the full $400.00 — Payroll correctly showed **Earned $40.00**. I then recorded a **$200.00 refund** against that invoice, bringing the net amount actually collected down to $200.00, at which point the employee's earnings should have fallen to $20.00. Payroll continued to show **Earned $40.00** and, critically, **Remaining $40.00** — meaning the full pre-refund amount is still presented as payable, with the "Pay" button sitting directly beside it. The business could therefore hand the employee $40.00 of commission on $200.00 of net revenue. The fix is to change the collected figure this formula reads from gross payments to net collections, i.e. sum of payments minus sum of refunds on those referred invoices, recalculated whenever a refund is recorded — this is the same "payments minus refunds" definition the main Dashboard already uses correctly for its Total Paid figure, so the correct expression already exists in the codebase and simply needs applying here. Because the same underlying flaw affects reseller commissions on refund (Bug 3), both should be fixed together against one shared definition of "net collected," so the two commission systems cannot drift apart again. **Steps to Reproduce:** 1. Go to **Employees → Add Employee**. Create an employee with **Salary Type = Commission** and the percentage field set to **10**. 2. Go to **Customers → + Add Customer** and create a new customer. 3. Go to **Billing → Create**, select that customer, set **Referred By** to the new employee, create the invoice, add a **$400.00** line item, then set its status to **Issued**. 4. Go to **Payroll** and confirm the employee shows **Earned $0.00** (correct — nothing collected yet). 5. Go to **Payments** and record a full **$400.00** payment against the invoice. 6. Return to **Payroll** and confirm the employee now shows **Earned $40.00** (correct — 10% of $400 collected). 7. Go to **Refunds & Credits** and record a **$200.00** refund against that same invoice. 8. Return to **Payroll** — the employee still shows **Earned $40.00** and **Remaining $40.00**, despite only $200.00 net having been collected. The expected figure is $20.00. **Resolution:** FIXED. What: an employee on the Commission salary type had Payroll compute earnings from GROSS payments, never netting off refunds - 400 collected then 200 refunded still showed Earned 40 (should be 20). Where: app/classes/Billing/Invoice.php (commissionOwedByEmployee()). Fix: the collected figure is now NET (amount_paid - refunds) per referred invoice - the same 'payments - refunds' definition the dashboard's Total Paid uses, and the same net-collected basis the reseller-commission redesign uses (#120), so the two commission systems stay in step. Recalculated whenever a refund is recorded. Verified live (transaction, rolled back): 400 collected @10% -> Earned 40.00; then a 200 refund -> Earned 20.00. ===== Activity / Notes ===== * **2026-07-28T12:03:13+01:00 - Claude:** FIXED. What: an employee on the Commission salary type had Payroll compute earnings from GROSS payments, never netting off refunds - 400 collected then 200 refunded still showed Earned 40 (should be 20). Where: app/classes/Billing/Invoice.php (commissionOwedByEmployee()). Fix: the collected figure is now NET (amount_paid - refunds) per referred invoice - the same 'payments - refunds' definition the dashboard's Total Paid uses, and the same net-collected basis the reseller-commission redesign uses (#120), so the two commission systems stay in step. Recalculated whenever a refund is recorded. Verified live (transaction, rolled back): 400 collected @10% -> Earned 40.00; then a 200 refund -> Earned 20.00. ===== Full History ===== ^ Date ^ User ^ Field ^ Change ^ | 2026-07-28T11:11:40+01:00 | Nour aboulhosn | issue-new | New Issue | | 2026-07-28T12:03:09+01:00 | Claude | Assigned To | => Claudine | | 2026-07-28T12:03:12+01:00 | Claude | tag-added | Tag Attached: done-by-claude | | 2026-07-28T12:03:13+01:00 | Claude | note-added | Note Added: 0000085 | | 2026-07-28T12:03:16+01:00 | Claude | Status | new => resolved | ---- Synced automatically from MantisBT issue #126.