====== #41 — Payroll dashboard doesn't update when expense is deleted (Resolved) ====== [[wiki:manara:bugs|← Back to Manara Bugs]] · [[https://mantis.matrixdn.net/view.php?id=41|View issue #41 in MantisBT]] ---- **Reported by:** Khaled Tarabay on 2026-07-25T11:43:56+01:00\\ **Assigned to:** Claude\\ **Resolved by:** Claude on 2026-07-25T13:25:38+01:00\\ **Severity:** major\\ **Priority:** normal\\ **Reproducibility:** always\\ **Category:** General **Description:** creating the salary of an employee then pay this salary then the dashboard is updated to to the amount of the salary, then delete the expense of this salary in the expenses tab then dashboard doesn't update **Steps to Reproduce:** pay salary delete the expense track the dashboard **Resolution:** FIXED. What: paying an employee's salary correctly increased the Payroll dashboard figure, but deleting the linked expense afterward (from the Expenses tab) did NOT reduce it back down — Total Expenses correctly dropped, but Payroll stayed exactly the same. Where: app/classes/Hr/PayrollEntry.php (record()/dashboardSummary()), app/classes/Finance/Transaction.php (delete()), database/schema.sql (payroll_entries.transaction_id FK). Why: paying a salary writes TWO linked rows in one transaction — a payroll_entries row (what the Payroll dashboard sums) and a transactions row (the expense, what Total Expenses sums), joined by payroll_entries.transaction_id (FK, ON DELETE SET NULL). PayrollEntry's own dashboard/sheet queries sum payroll_entries directly and never join transactions — so deleting the expense only nulled the FK and left the payroll_entries row (and its amount) completely untouched, while Total Expenses correctly dropped. Two tables meant to represent the same event fell out of sync. (Confirmed NOT a double-payment risk — the salary-cap enforcement also reads payroll_entries directly, so it stayed correct throughout.) Fix: Transaction::delete() now also deletes the linked payroll_entries row (there's no separate "delete a payroll entry" UI, so this makes deleting its expense the real undo path instead of leaving a stale ledger row behind). Verified live against the local database: paid a $300 salary (dashboard 520 -> 820), deleted the linked expense, dashboard correctly dropped back to 520, and confirmed the orphaned payroll_entries row was actually removed, not just left with a null transaction_id. ===== Activity / Notes ===== * **2026-07-25T13:25:34+01:00 - Claude:** FIXED. What: paying an employee's salary correctly increased the Payroll dashboard figure, but deleting the linked expense afterward (from the Expenses tab) did NOT reduce it back down — Total Expenses correctly dropped, but Payroll stayed exactly the same. Where: app/classes/Hr/PayrollEntry.php (record()/dashboardSummary()), app/classes/Finance/Transaction.php (delete()), database/schema.sql (payroll_entries.transaction_id FK). Why: paying a salary writes TWO linked rows in one transaction — a payroll_entries row (what the Payroll dashboard sums) and a transactions row (the expense, what Total Expenses sums), joined by payroll_entries.transaction_id (FK, ON DELETE SET NULL). PayrollEntry's own dashboard/sheet queries sum payroll_entries directly and never join transactions — so deleting the expense only nulled the FK and left the payroll_entries row (and its amount) completely untouched, while Total Expenses correctly dropped. Two tables meant to represent the same event fell out of sync. (Confirmed NOT a double-payment risk — the salary-cap enforcement also reads payroll_entries directly, so it stayed correct throughout.) Fix: Transaction::delete() now also deletes the linked payroll_entries row (there's no separate "delete a payroll entry" UI, so this makes deleting its expense the real undo path instead of leaving a stale ledger row behind). Verified live against the local database: paid a $300 salary (dashboard 520 -> 820), deleted the linked expense, dashboard correctly dropped back to 520, and confirmed the orphaned payroll_entries row was actually removed, not just left with a null transaction_id. ===== Full History ===== ^ Date ^ User ^ Field ^ Change ^ | 2026-07-25T11:43:56+01:00 | Khaled Tarabay | issue-new | New Issue | | 2026-07-25T13:25:28+01:00 | Claude | Assigned To | => Claudine | | 2026-07-25T13:25:32+01:00 | Claude | tag-added | Tag Attached: done-by-claude | | 2026-07-25T13:25:34+01:00 | Claude | note-added | Note Added: 0000006 | | 2026-07-25T13:25:38+01:00 | Claude | Status | new => resolved | ---- Synced automatically from MantisBT issue #41.